· 4 years ago · Jun 16, 2021, 10:06 AM
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2021 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22
23/******/ (() => { // webpackBootstrap
24/******/ "use strict";
25/******/ var __webpack_modules__ = ([
26/* 0 */,
27/* 1 */
28/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
29
30
31
32Object.defineProperty(exports, "__esModule", ({
33 value: true
34}));
35exports.OptionKind = exports.AppOptions = void 0;
36
37var _viewer_compatibility = __webpack_require__(2);
38
39const OptionKind = {
40 VIEWER: 0x02,
41 API: 0x04,
42 WORKER: 0x08,
43 PREFERENCE: 0x80
44};
45exports.OptionKind = OptionKind;
46const defaultOptions = {
47 cursorToolOnLoad: {
48 value: 0,
49 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
50 },
51 defaultUrl: {
52 value: "compressed.tracemonkey-pldi-09.pdf",
53 kind: OptionKind.VIEWER
54 },
55 defaultZoomValue: {
56 value: "",
57 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
58 },
59 disableHistory: {
60 value: false,
61 kind: OptionKind.VIEWER
62 },
63 disablePageLabels: {
64 value: false,
65 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
66 },
67 enablePermissions: {
68 value: false,
69 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
70 },
71 enablePrintAutoRotate: {
72 value: true,
73 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
74 },
75 enableScripting: {
76 value: true,
77 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
78 },
79 enableWebGL: {
80 value: false,
81 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
82 },
83 externalLinkRel: {
84 value: "noopener noreferrer nofollow",
85 kind: OptionKind.VIEWER
86 },
87 externalLinkTarget: {
88 value: 0,
89 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
90 },
91 historyUpdateUrl: {
92 value: false,
93 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
94 },
95 ignoreDestinationZoom: {
96 value: false,
97 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
98 },
99 imageResourcesPath: {
100 value: "./images/",
101 kind: OptionKind.VIEWER
102 },
103 maxCanvasPixels: {
104 value: 16777216,
105 compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
106 kind: OptionKind.VIEWER
107 },
108 pdfBugEnabled: {
109 value: false,
110 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
111 },
112 printResolution: {
113 value: 150,
114 kind: OptionKind.VIEWER
115 },
116 renderer: {
117 value: "canvas",
118 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
119 },
120 renderInteractiveForms: {
121 value: true,
122 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
123 },
124 sidebarViewOnLoad: {
125 value: -1,
126 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
127 },
128 scrollModeOnLoad: {
129 value: -1,
130 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
131 },
132 spreadModeOnLoad: {
133 value: -1,
134 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
135 },
136 textLayerMode: {
137 value: 1,
138 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
139 },
140 useOnlyCssZoom: {
141 value: false,
142 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
143 },
144 viewerCssTheme: {
145 value: 0,
146 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
147 },
148 viewOnLoad: {
149 value: 0,
150 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
151 },
152 cMapPacked: {
153 value: true,
154 kind: OptionKind.API
155 },
156 cMapUrl: {
157 value: "../web/cmaps/",
158 kind: OptionKind.API
159 },
160 disableAutoFetch: {
161 value: false,
162 kind: OptionKind.API + OptionKind.PREFERENCE
163 },
164 disableFontFace: {
165 value: false,
166 kind: OptionKind.API + OptionKind.PREFERENCE
167 },
168 disableRange: {
169 value: false,
170 kind: OptionKind.API + OptionKind.PREFERENCE
171 },
172 disableStream: {
173 value: false,
174 kind: OptionKind.API + OptionKind.PREFERENCE
175 },
176 docBaseUrl: {
177 value: "",
178 kind: OptionKind.API
179 },
180 enableXfa: {
181 value: false,
182 kind: OptionKind.API
183 },
184 fontExtraProperties: {
185 value: false,
186 kind: OptionKind.API
187 },
188 isEvalSupported: {
189 value: true,
190 kind: OptionKind.API
191 },
192 maxImageSize: {
193 value: -1,
194 kind: OptionKind.API
195 },
196 pdfBug: {
197 value: false,
198 kind: OptionKind.API
199 },
200 verbosity: {
201 value: 1,
202 kind: OptionKind.API
203 },
204 workerPort: {
205 value: null,
206 kind: OptionKind.WORKER
207 },
208 workerSrc: {
209 value: "../build/pdf.worker.js",
210 kind: OptionKind.WORKER
211 }
212};
213{
214 defaultOptions.disablePreferences = {
215 value: false,
216 kind: OptionKind.VIEWER
217 };
218 defaultOptions.locale = {
219 value: typeof navigator !== "undefined" ? navigator.language : "en-US",
220 kind: OptionKind.VIEWER
221 };
222 defaultOptions.sandboxBundleSrc = {
223 value: "../build/pdf.sandbox.js",
224 kind: OptionKind.VIEWER
225 };
226}
227const userOptions = Object.create(null);
228
229class AppOptions {
230 constructor() {
231 throw new Error("Cannot initialize AppOptions.");
232 }
233
234 static get(name) {
235 const userOption = userOptions[name];
236
237 if (userOption !== undefined) {
238 return userOption;
239 }
240
241 const defaultOption = defaultOptions[name];
242
243 if (defaultOption !== undefined) {
244 return defaultOption.compatibility ?? defaultOption.value;
245 }
246
247 return undefined;
248 }
249
250 static getAll(kind = null) {
251 const options = Object.create(null);
252
253 for (const name in defaultOptions) {
254 const defaultOption = defaultOptions[name];
255
256 if (kind) {
257 if ((kind & defaultOption.kind) === 0) {
258 continue;
259 }
260
261 if (kind === OptionKind.PREFERENCE) {
262 const value = defaultOption.value,
263 valueType = typeof value;
264
265 if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
266 options[name] = value;
267 continue;
268 }
269
270 throw new Error(`Invalid type for preference: ${name}`);
271 }
272 }
273
274 const userOption = userOptions[name];
275 options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
276 }
277
278 return options;
279 }
280
281 static set(name, value) {
282 userOptions[name] = value;
283 }
284
285 static setAll(options) {
286 for (const name in options) {
287 userOptions[name] = options[name];
288 }
289 }
290
291 static remove(name) {
292 delete userOptions[name];
293 }
294
295}
296
297exports.AppOptions = AppOptions;
298
299/***/ }),
300/* 2 */
301/***/ ((__unused_webpack_module, exports) => {
302
303
304
305Object.defineProperty(exports, "__esModule", ({
306 value: true
307}));
308exports.viewerCompatibilityParams = void 0;
309const compatibilityParams = Object.create(null);
310{
311 const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
312 const platform = typeof navigator !== "undefined" && navigator.platform || "";
313 const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
314 const isAndroid = /Android/.test(userAgent);
315 const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
316 const isIOSChrome = /CriOS/.test(userAgent);
317
318 (function checkOnBlobSupport() {
319 if (isIOSChrome) {
320 compatibilityParams.disableCreateObjectURL = true;
321 }
322 })();
323
324 (function checkCanvasSizeLimitation() {
325 if (isIOS || isAndroid) {
326 compatibilityParams.maxCanvasPixels = 5242880;
327 }
328 })();
329}
330const viewerCompatibilityParams = Object.freeze(compatibilityParams);
331exports.viewerCompatibilityParams = viewerCompatibilityParams;
332
333/***/ }),
334/* 3 */
335/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
336
337
338
339Object.defineProperty(exports, "__esModule", ({
340 value: true
341}));
342exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
343
344var _ui_utils = __webpack_require__(4);
345
346var _app_options = __webpack_require__(1);
347
348var _pdfjsLib = __webpack_require__(5);
349
350var _pdf_cursor_tools = __webpack_require__(6);
351
352var _pdf_rendering_queue = __webpack_require__(8);
353
354var _overlay_manager = __webpack_require__(9);
355
356var _password_prompt = __webpack_require__(10);
357
358var _pdf_attachment_viewer = __webpack_require__(11);
359
360var _pdf_document_properties = __webpack_require__(13);
361
362var _pdf_find_bar = __webpack_require__(14);
363
364var _pdf_find_controller = __webpack_require__(15);
365
366var _pdf_history = __webpack_require__(17);
367
368var _pdf_layer_viewer = __webpack_require__(18);
369
370var _pdf_link_service = __webpack_require__(19);
371
372var _pdf_outline_viewer = __webpack_require__(20);
373
374var _pdf_presentation_mode = __webpack_require__(21);
375
376var _pdf_scripting_manager = __webpack_require__(22);
377
378var _pdf_sidebar = __webpack_require__(23);
379
380var _pdf_sidebar_resizer = __webpack_require__(24);
381
382var _pdf_thumbnail_viewer = __webpack_require__(25);
383
384var _pdf_viewer = __webpack_require__(27);
385
386var _secondary_toolbar = __webpack_require__(34);
387
388var _toolbar = __webpack_require__(36);
389
390var _viewer_compatibility = __webpack_require__(2);
391
392var _view_history = __webpack_require__(37);
393
394const DEFAULT_SCALE_DELTA = 1.1;
395const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
396const FORCE_PAGES_LOADED_TIMEOUT = 10000;
397const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
398const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
399const ViewOnLoad = {
400 UNKNOWN: -1,
401 PREVIOUS: 0,
402 INITIAL: 1
403};
404const ViewerCssTheme = {
405 AUTOMATIC: 0,
406 LIGHT: 1,
407 DARK: 2
408};
409const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
410const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
411
412class DefaultExternalServices {
413 constructor() {
414 throw new Error("Cannot initialize DefaultExternalServices.");
415 }
416
417 static updateFindControlState(data) {}
418
419 static updateFindMatchesCount(data) {}
420
421 static initPassiveLoading(callbacks) {}
422
423 static async fallback(data) {}
424
425 static reportTelemetry(data) {}
426
427 static createDownloadManager(options) {
428 throw new Error("Not implemented: createDownloadManager");
429 }
430
431 static createPreferences() {
432 throw new Error("Not implemented: createPreferences");
433 }
434
435 static createL10n(options) {
436 throw new Error("Not implemented: createL10n");
437 }
438
439 static createScripting(options) {
440 throw new Error("Not implemented: createScripting");
441 }
442
443 static get supportsIntegratedFind() {
444 return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
445 }
446
447 static get supportsDocumentFonts() {
448 return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
449 }
450
451 static get supportedMouseWheelZoomModifierKeys() {
452 return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
453 ctrlKey: true,
454 metaKey: true
455 });
456 }
457
458 static get isInAutomation() {
459 return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
460 }
461
462}
463
464exports.DefaultExternalServices = DefaultExternalServices;
465const PDFViewerApplication = {
466 initialBookmark: document.location.hash.substring(1),
467 _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
468 fellback: false,
469 appConfig: null,
470 pdfDocument: null,
471 pdfLoadingTask: null,
472 printService: null,
473 pdfViewer: null,
474 pdfThumbnailViewer: null,
475 pdfRenderingQueue: null,
476 pdfPresentationMode: null,
477 pdfDocumentProperties: null,
478 pdfLinkService: null,
479 pdfHistory: null,
480 pdfSidebar: null,
481 pdfSidebarResizer: null,
482 pdfOutlineViewer: null,
483 pdfAttachmentViewer: null,
484 pdfLayerViewer: null,
485 pdfCursorTools: null,
486 pdfScriptingManager: null,
487 store: null,
488 downloadManager: null,
489 overlayManager: null,
490 preferences: null,
491 toolbar: null,
492 secondaryToolbar: null,
493 eventBus: null,
494 l10n: null,
495 isInitialViewSet: false,
496 downloadComplete: false,
497 isViewerEmbedded: window.parent !== window,
498 url: "",
499 baseUrl: "",
500 externalServices: DefaultExternalServices,
501 _boundEvents: Object.create(null),
502 documentInfo: null,
503 metadata: null,
504 _contentDispositionFilename: null,
505 _contentLength: null,
506 triggerDelayedFallback: null,
507 _saveInProgress: false,
508 _wheelUnusedTicks: 0,
509 _idleCallbacks: new Set(),
510
511 async initialize(appConfig) {
512 this.preferences = this.externalServices.createPreferences();
513 this.appConfig = appConfig;
514 await this._readPreferences();
515 await this._parseHashParameters();
516
517 this._forceCssTheme();
518
519 await this._initializeL10n();
520
521 if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
522 _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
523 }
524
525 await this._initializeViewerComponents();
526 this.bindEvents();
527 this.bindWindowEvents();
528 const appContainer = appConfig.appContainer || document.documentElement;
529 this.l10n.translate(appContainer).then(() => {
530 this.eventBus.dispatch("localized", {
531 source: this
532 });
533 });
534
535 this._initializedCapability.resolve();
536 },
537
538 async _readPreferences() {
539 if (_app_options.AppOptions.get("disablePreferences")) {
540 return;
541 }
542
543 try {
544 _app_options.AppOptions.setAll(await this.preferences.getAll());
545 } catch (reason) {
546 console.error(`_readPreferences: "${reason?.message}".`);
547 }
548 },
549
550 async _parseHashParameters() {
551 if (!_app_options.AppOptions.get("pdfBugEnabled")) {
552 return undefined;
553 }
554
555 const hash = document.location.hash.substring(1);
556
557 if (!hash) {
558 return undefined;
559 }
560
561 const hashParams = (0, _ui_utils.parseQueryString)(hash),
562 waitOn = [];
563
564 if ("disableworker" in hashParams && hashParams.disableworker === "true") {
565 waitOn.push(loadFakeWorker());
566 }
567
568 if ("disablerange" in hashParams) {
569 _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
570 }
571
572 if ("disablestream" in hashParams) {
573 _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
574 }
575
576 if ("disableautofetch" in hashParams) {
577 _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
578 }
579
580 if ("disablefontface" in hashParams) {
581 _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
582 }
583
584 if ("disablehistory" in hashParams) {
585 _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
586 }
587
588 if ("webgl" in hashParams) {
589 _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true");
590 }
591
592 if ("verbosity" in hashParams) {
593 _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
594 }
595
596 if ("textlayer" in hashParams) {
597 switch (hashParams.textlayer) {
598 case "off":
599 _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
600
601 break;
602
603 case "visible":
604 case "shadow":
605 case "hover":
606 const viewer = this.appConfig.viewerContainer;
607 viewer.classList.add("textLayer-" + hashParams.textlayer);
608 break;
609 }
610 }
611
612 if ("pdfbug" in hashParams) {
613 _app_options.AppOptions.set("pdfBug", true);
614
615 _app_options.AppOptions.set("fontExtraProperties", true);
616
617 const enabled = hashParams.pdfbug.split(",");
618 waitOn.push(loadAndEnablePDFBug(enabled));
619 }
620
621 if ("locale" in hashParams) {
622 _app_options.AppOptions.set("locale", hashParams.locale);
623 }
624
625 if (waitOn.length === 0) {
626 return undefined;
627 }
628
629 return Promise.all(waitOn).catch(reason => {
630 console.error(`_parseHashParameters: "${reason.message}".`);
631 });
632 },
633
634 async _initializeL10n() {
635 this.l10n = this.externalServices.createL10n({
636 locale: _app_options.AppOptions.get("locale")
637 });
638 const dir = await this.l10n.getDirection();
639 document.getElementsByTagName("html")[0].dir = dir;
640 },
641
642 _forceCssTheme() {
643 const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
644
645 if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
646 return;
647 }
648
649 try {
650 const styleSheet = document.styleSheets[0];
651 const cssRules = styleSheet?.cssRules || [];
652
653 for (let i = 0, ii = cssRules.length; i < ii; i++) {
654 const rule = cssRules[i];
655
656 if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
657 if (cssTheme === ViewerCssTheme.LIGHT) {
658 styleSheet.deleteRule(i);
659 return;
660 }
661
662 const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
663
664 if (darkRules?.[1]) {
665 styleSheet.deleteRule(i);
666 styleSheet.insertRule(darkRules[1], i);
667 }
668
669 return;
670 }
671 }
672 } catch (reason) {
673 console.error(`_forceCssTheme: "${reason?.message}".`);
674 }
675 },
676
677 async _initializeViewerComponents() {
678 const appConfig = this.appConfig;
679 const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
680 isInAutomation: this.externalServices.isInAutomation
681 });
682 this.eventBus = eventBus;
683 this.overlayManager = new _overlay_manager.OverlayManager();
684 const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
685 pdfRenderingQueue.onIdle = this._cleanup.bind(this);
686 this.pdfRenderingQueue = pdfRenderingQueue;
687 const pdfLinkService = new _pdf_link_service.PDFLinkService({
688 eventBus,
689 externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
690 externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
691 ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
692 });
693 this.pdfLinkService = pdfLinkService;
694 const downloadManager = this.externalServices.createDownloadManager();
695 this.downloadManager = downloadManager;
696 const findController = new _pdf_find_controller.PDFFindController({
697 linkService: pdfLinkService,
698 eventBus
699 });
700 this.findController = findController;
701 const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
702 eventBus,
703 sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
704 scriptingFactory: this.externalServices,
705 docPropertiesLookup: this._scriptingDocProperties.bind(this)
706 });
707 this.pdfScriptingManager = pdfScriptingManager;
708 const container = appConfig.mainContainer;
709 const viewer = appConfig.viewerContainer;
710 this.pdfViewer = new _pdf_viewer.PDFViewer({
711 container,
712 viewer,
713 eventBus,
714 renderingQueue: pdfRenderingQueue,
715 linkService: pdfLinkService,
716 downloadManager,
717 findController,
718 scriptingManager: pdfScriptingManager,
719 renderer: _app_options.AppOptions.get("renderer"),
720 enableWebGL: _app_options.AppOptions.get("enableWebGL"),
721 l10n: this.l10n,
722 textLayerMode: _app_options.AppOptions.get("textLayerMode"),
723 imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
724 renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
725 enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
726 useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
727 maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
728 enableScripting: _app_options.AppOptions.get("enableScripting")
729 });
730 pdfRenderingQueue.setViewer(this.pdfViewer);
731 pdfLinkService.setViewer(this.pdfViewer);
732 pdfScriptingManager.setViewer(this.pdfViewer);
733 this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
734 container: appConfig.sidebar.thumbnailView,
735 eventBus,
736 renderingQueue: pdfRenderingQueue,
737 linkService: pdfLinkService,
738 l10n: this.l10n
739 });
740 pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
741 this.pdfHistory = new _pdf_history.PDFHistory({
742 linkService: pdfLinkService,
743 eventBus
744 });
745 pdfLinkService.setHistory(this.pdfHistory);
746
747 if (!this.supportsIntegratedFind) {
748 this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
749 }
750
751 this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
752 this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
753 container,
754 eventBus,
755 cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
756 });
757 this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
758 this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
759
760 if (this.supportsFullscreen) {
761 this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
762 container,
763 pdfViewer: this.pdfViewer,
764 eventBus
765 });
766 }
767
768 this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
769 this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
770 container: appConfig.sidebar.outlineView,
771 eventBus,
772 linkService: pdfLinkService
773 });
774 this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
775 container: appConfig.sidebar.attachmentsView,
776 eventBus,
777 downloadManager
778 });
779 this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
780 container: appConfig.sidebar.layersView,
781 eventBus,
782 l10n: this.l10n
783 });
784 this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
785 elements: appConfig.sidebar,
786 pdfViewer: this.pdfViewer,
787 pdfThumbnailViewer: this.pdfThumbnailViewer,
788 eventBus,
789 l10n: this.l10n
790 });
791 this.pdfSidebar.onToggled = this.forceRendering.bind(this);
792 this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
793 },
794
795 run(config) {
796 this.initialize(config).then(webViewerInitialized);
797 },
798
799 get initialized() {
800 return this._initializedCapability.settled;
801 },
802
803 get initializedPromise() {
804 return this._initializedCapability.promise;
805 },
806
807 zoomIn(ticks) {
808 if (this.pdfViewer.isInPresentationMode) {
809 return;
810 }
811
812 let newScale = this.pdfViewer.currentScale;
813
814 do {
815 newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
816 newScale = Math.ceil(newScale * 10) / 10;
817 newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
818 } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
819
820 this.pdfViewer.currentScaleValue = newScale;
821 },
822
823 zoomOut(ticks) {
824 if (this.pdfViewer.isInPresentationMode) {
825 return;
826 }
827
828 let newScale = this.pdfViewer.currentScale;
829
830 do {
831 newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
832 newScale = Math.floor(newScale * 10) / 10;
833 newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
834 } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
835
836 this.pdfViewer.currentScaleValue = newScale;
837 },
838
839 zoomReset() {
840 if (this.pdfViewer.isInPresentationMode) {
841 return;
842 }
843
844 this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
845 },
846
847 get pagesCount() {
848 return this.pdfDocument ? this.pdfDocument.numPages : 0;
849 },
850
851 get page() {
852 return this.pdfViewer.currentPageNumber;
853 },
854
855 set page(val) {
856 this.pdfViewer.currentPageNumber = val;
857 },
858
859 get supportsPrinting() {
860 return PDFPrintServiceFactory.instance.supportsPrinting;
861 },
862
863 get supportsFullscreen() {
864 const doc = document.documentElement;
865 let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
866
867 if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
868 support = false;
869 }
870
871 return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
872 },
873
874 get supportsIntegratedFind() {
875 return this.externalServices.supportsIntegratedFind;
876 },
877
878 get supportsDocumentFonts() {
879 return this.externalServices.supportsDocumentFonts;
880 },
881
882 get loadingBar() {
883 const bar = new _ui_utils.ProgressBar("#loadingBar");
884 return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
885 },
886
887 get supportedMouseWheelZoomModifierKeys() {
888 return this.externalServices.supportedMouseWheelZoomModifierKeys;
889 },
890
891 initPassiveLoading() {
892 throw new Error("Not implemented: initPassiveLoading");
893 },
894
895 setTitleUsingUrl(url = "") {
896 this.url = url;
897 this.baseUrl = url.split("#")[0];
898 let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
899
900 if (!title) {
901 try {
902 title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
903 } catch (ex) {
904 title = url;
905 }
906 }
907
908 this.setTitle(title);
909 },
910
911 setTitle(title) {
912 if (this.isViewerEmbedded) {
913 return;
914 }
915
916 document.title = title;
917 },
918
919 get _docFilename() {
920 return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
921 },
922
923 _cancelIdleCallbacks() {
924 if (!this._idleCallbacks.size) {
925 return;
926 }
927
928 for (const callback of this._idleCallbacks) {
929 window.cancelIdleCallback(callback);
930 }
931
932 this._idleCallbacks.clear();
933 },
934
935 async close() {
936 this._unblockDocumentLoadEvent();
937
938 const {
939 container
940 } = this.appConfig.errorWrapper;
941 container.hidden = true;
942
943 if (!this.pdfLoadingTask) {
944 return;
945 }
946
947 if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
948 try {
949 await this.save({
950 sourceEventType: "save"
951 });
952 } catch (reason) {}
953 }
954
955 const promises = [];
956 promises.push(this.pdfLoadingTask.destroy());
957 this.pdfLoadingTask = null;
958
959 if (this.pdfDocument) {
960 this.pdfDocument = null;
961 this.pdfThumbnailViewer.setDocument(null);
962 this.pdfViewer.setDocument(null);
963 this.pdfLinkService.setDocument(null);
964 this.pdfDocumentProperties.setDocument(null);
965 }
966
967 webViewerResetPermissions();
968 this.store = null;
969 this.isInitialViewSet = false;
970 this.downloadComplete = false;
971 this.url = "";
972 this.baseUrl = "";
973 this.documentInfo = null;
974 this.metadata = null;
975 this._contentDispositionFilename = null;
976 this._contentLength = null;
977 this.triggerDelayedFallback = null;
978 this._saveInProgress = false;
979
980 this._cancelIdleCallbacks();
981
982 promises.push(this.pdfScriptingManager.destroyPromise);
983 this.pdfSidebar.reset();
984 this.pdfOutlineViewer.reset();
985 this.pdfAttachmentViewer.reset();
986 this.pdfLayerViewer.reset();
987
988 if (this.pdfHistory) {
989 this.pdfHistory.reset();
990 }
991
992 if (this.findBar) {
993 this.findBar.reset();
994 }
995
996 this.toolbar.reset();
997 this.secondaryToolbar.reset();
998
999 if (typeof PDFBug !== "undefined") {
1000 PDFBug.cleanup();
1001 }
1002
1003 await Promise.all(promises);
1004 },
1005
1006 async open(file, args) {
1007 if (this.pdfLoadingTask) {
1008 await this.close();
1009 }
1010
1011 const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
1012
1013 for (const key in workerParameters) {
1014 _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
1015 }
1016
1017 const parameters = Object.create(null);
1018
1019 if (typeof file === "string") {
1020 this.setTitleUsingUrl(file);
1021 parameters.url = file;
1022 } else if (file && "byteLength" in file) {
1023 parameters.data = file;
1024 } else if (file.url && file.originalUrl) {
1025 this.setTitleUsingUrl(file.originalUrl);
1026 parameters.url = file.url;
1027 }
1028
1029 const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
1030
1031 for (const key in apiParameters) {
1032 let value = apiParameters[key];
1033
1034 if (key === "docBaseUrl" && !value) {}
1035
1036 parameters[key] = value;
1037 }
1038
1039 if (args) {
1040 for (const key in args) {
1041 parameters[key] = args[key];
1042 }
1043 }
1044
1045 const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
1046 this.pdfLoadingTask = loadingTask;
1047
1048 loadingTask.onPassword = (updateCallback, reason) => {
1049 this.pdfLinkService.externalLinkEnabled = false;
1050 this.passwordPrompt.setUpdateCallback(updateCallback, reason);
1051 this.passwordPrompt.open();
1052 };
1053
1054 loadingTask.onProgress = ({
1055 loaded,
1056 total
1057 }) => {
1058 this.progress(loaded / total);
1059 };
1060
1061 loadingTask.onUnsupportedFeature = this.fallback.bind(this);
1062 return loadingTask.promise.then(pdfDocument => {
1063 this.load(pdfDocument);
1064 }, exception => {
1065 if (loadingTask !== this.pdfLoadingTask) {
1066 return undefined;
1067 }
1068
1069 let key = "loading_error";
1070
1071 if (exception instanceof _pdfjsLib.InvalidPDFException) {
1072 key = "invalid_file_error";
1073 } else if (exception instanceof _pdfjsLib.MissingPDFException) {
1074 key = "missing_file_error";
1075 } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
1076 key = "unexpected_response_error";
1077 }
1078
1079 return this.l10n.get(key).then(msg => {
1080 this._documentError(msg, {
1081 message: exception?.message
1082 });
1083
1084 throw exception;
1085 });
1086 });
1087 },
1088
1089 _ensureDownloadComplete() {
1090 if (this.pdfDocument && this.downloadComplete) {
1091 return;
1092 }
1093
1094 throw new Error("PDF document not downloaded.");
1095 },
1096
1097 async download({
1098 sourceEventType = "download"
1099 } = {}) {
1100 const url = this.baseUrl,
1101 filename = this._docFilename;
1102
1103 try {
1104 this._ensureDownloadComplete();
1105
1106 const data = await this.pdfDocument.getData();
1107 const blob = new Blob([data], {
1108 type: "application/pdf"
1109 });
1110 await this.downloadManager.download(blob, url, filename, sourceEventType);
1111 } catch (reason) {
1112 await this.downloadManager.downloadUrl(url, filename);
1113 }
1114 },
1115
1116 async save({
1117 sourceEventType = "download"
1118 } = {}) {
1119 if (this._saveInProgress) {
1120 return;
1121 }
1122
1123 this._saveInProgress = true;
1124 await this.pdfScriptingManager.dispatchWillSave();
1125 const url = this.baseUrl,
1126 filename = this._docFilename;
1127
1128 try {
1129 this._ensureDownloadComplete();
1130
1131 const data = await this.pdfDocument.saveDocument(this.pdfDocument.annotationStorage);
1132 const blob = new Blob([data], {
1133 type: "application/pdf"
1134 });
1135 await this.downloadManager.download(blob, url, filename, sourceEventType);
1136 } catch (reason) {
1137 await this.download({
1138 sourceEventType
1139 });
1140 } finally {
1141 await this.pdfScriptingManager.dispatchDidSave();
1142 this._saveInProgress = false;
1143 }
1144 },
1145
1146 downloadOrSave(options) {
1147 if (this.pdfDocument?.annotationStorage.size > 0) {
1148 this.save(options);
1149 } else {
1150 this.download(options);
1151 }
1152 },
1153
1154 _delayedFallback(featureId) {
1155 this.externalServices.reportTelemetry({
1156 type: "unsupportedFeature",
1157 featureId
1158 });
1159
1160 if (!this.triggerDelayedFallback) {
1161 this.triggerDelayedFallback = () => {
1162 this.fallback(featureId);
1163 this.triggerDelayedFallback = null;
1164 };
1165 }
1166 },
1167
1168 fallback(featureId) {
1169 this.externalServices.reportTelemetry({
1170 type: "unsupportedFeature",
1171 featureId
1172 });
1173
1174 switch (featureId) {
1175 case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontLoadNative:
1176 case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontMissing:
1177 return;
1178 }
1179
1180 if (this.fellback) {
1181 return;
1182 }
1183
1184 this.fellback = true;
1185 this.externalServices.fallback({
1186 featureId,
1187 url: this.baseUrl
1188 }).then(download => {
1189 if (!download) {
1190 return;
1191 }
1192
1193 this.download({
1194 sourceEventType: "download"
1195 });
1196 });
1197 },
1198
1199 _documentError(message, moreInfo = null) {
1200 this._unblockDocumentLoadEvent();
1201
1202 this._otherError(message, moreInfo);
1203 },
1204
1205 _otherError(message, moreInfo = null) {
1206 const moreInfoText = [this.l10n.get("error_version_info", {
1207 version: _pdfjsLib.version || "?",
1208 build: _pdfjsLib.build || "?"
1209 })];
1210
1211 if (moreInfo) {
1212 moreInfoText.push(this.l10n.get("error_message", {
1213 message: moreInfo.message
1214 }));
1215
1216 if (moreInfo.stack) {
1217 moreInfoText.push(this.l10n.get("error_stack", {
1218 stack: moreInfo.stack
1219 }));
1220 } else {
1221 if (moreInfo.filename) {
1222 moreInfoText.push(this.l10n.get("error_file", {
1223 file: moreInfo.filename
1224 }));
1225 }
1226
1227 if (moreInfo.lineNumber) {
1228 moreInfoText.push(this.l10n.get("error_line", {
1229 line: moreInfo.lineNumber
1230 }));
1231 }
1232 }
1233 }
1234
1235 const errorWrapperConfig = this.appConfig.errorWrapper;
1236 const errorWrapper = errorWrapperConfig.container;
1237 errorWrapper.hidden = false;
1238 const errorMessage = errorWrapperConfig.errorMessage;
1239 errorMessage.textContent = message;
1240 const closeButton = errorWrapperConfig.closeButton;
1241
1242 closeButton.onclick = function () {
1243 errorWrapper.hidden = true;
1244 };
1245
1246 const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
1247 const moreInfoButton = errorWrapperConfig.moreInfoButton;
1248 const lessInfoButton = errorWrapperConfig.lessInfoButton;
1249
1250 moreInfoButton.onclick = function () {
1251 errorMoreInfo.hidden = false;
1252 moreInfoButton.hidden = true;
1253 lessInfoButton.hidden = false;
1254 errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
1255 };
1256
1257 lessInfoButton.onclick = function () {
1258 errorMoreInfo.hidden = true;
1259 moreInfoButton.hidden = false;
1260 lessInfoButton.hidden = true;
1261 };
1262
1263 moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
1264 lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
1265 closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
1266 moreInfoButton.hidden = false;
1267 lessInfoButton.hidden = true;
1268 Promise.all(moreInfoText).then(parts => {
1269 errorMoreInfo.value = parts.join("\n");
1270 });
1271 },
1272
1273 progress(level) {
1274 if (this.downloadComplete) {
1275 return;
1276 }
1277
1278 const percent = Math.round(level * 100);
1279
1280 if (percent > this.loadingBar.percent || isNaN(percent)) {
1281 this.loadingBar.percent = percent;
1282 const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
1283
1284 if (disableAutoFetch && percent) {
1285 if (this.disableAutoFetchLoadingBarTimeout) {
1286 clearTimeout(this.disableAutoFetchLoadingBarTimeout);
1287 this.disableAutoFetchLoadingBarTimeout = null;
1288 }
1289
1290 this.loadingBar.show();
1291 this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
1292 this.loadingBar.hide();
1293 this.disableAutoFetchLoadingBarTimeout = null;
1294 }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
1295 }
1296 }
1297 },
1298
1299 load(pdfDocument) {
1300 this.pdfDocument = pdfDocument;
1301 pdfDocument.getDownloadInfo().then(({
1302 length
1303 }) => {
1304 this._contentLength = length;
1305 this.downloadComplete = true;
1306 this.loadingBar.hide();
1307 firstPagePromise.then(() => {
1308 this.eventBus.dispatch("documentloaded", {
1309 source: this
1310 });
1311 });
1312 });
1313 const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
1314 const pageModePromise = pdfDocument.getPageMode().catch(function () {});
1315 const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
1316 this.toolbar.setPagesCount(pdfDocument.numPages, false);
1317 this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
1318 let baseDocumentUrl;
1319 baseDocumentUrl = null;
1320 this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
1321 this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
1322 const pdfViewer = this.pdfViewer;
1323 pdfViewer.setDocument(pdfDocument);
1324 const {
1325 firstPagePromise,
1326 onePageRendered,
1327 pagesPromise
1328 } = pdfViewer;
1329 const pdfThumbnailViewer = this.pdfThumbnailViewer;
1330 pdfThumbnailViewer.setDocument(pdfDocument);
1331 const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
1332 page: null,
1333 zoom: _ui_utils.DEFAULT_SCALE_VALUE,
1334 scrollLeft: "0",
1335 scrollTop: "0",
1336 rotation: null,
1337 sidebarView: _ui_utils.SidebarView.UNKNOWN,
1338 scrollMode: _ui_utils.ScrollMode.UNKNOWN,
1339 spreadMode: _ui_utils.SpreadMode.UNKNOWN
1340 }).catch(() => {
1341 return Object.create(null);
1342 });
1343 firstPagePromise.then(pdfPage => {
1344 this.loadingBar.setWidth(this.appConfig.viewerContainer);
1345
1346 this._initializeAnnotationStorageCallbacks(pdfDocument);
1347
1348 Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
1349 const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
1350
1351 this._initializePdfHistory({
1352 fingerprint: pdfDocument.fingerprint,
1353 viewOnLoad,
1354 initialDest: openAction?.dest
1355 });
1356
1357 const initialBookmark = this.initialBookmark;
1358
1359 const zoom = _app_options.AppOptions.get("defaultZoomValue");
1360
1361 let hash = zoom ? `zoom=${zoom}` : null;
1362 let rotation = null;
1363
1364 let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
1365
1366 let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
1367
1368 let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
1369
1370 if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
1371 hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
1372 rotation = parseInt(stored.rotation, 10);
1373
1374 if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
1375 sidebarView = stored.sidebarView | 0;
1376 }
1377
1378 if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
1379 scrollMode = stored.scrollMode | 0;
1380 }
1381
1382 if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
1383 spreadMode = stored.spreadMode | 0;
1384 }
1385 }
1386
1387 if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
1388 sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
1389 }
1390
1391 if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
1392 spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
1393 }
1394
1395 this.setInitialView(hash, {
1396 rotation,
1397 sidebarView,
1398 scrollMode,
1399 spreadMode
1400 });
1401 this.eventBus.dispatch("documentinit", {
1402 source: this
1403 });
1404
1405 if (!this.isViewerEmbedded) {
1406 pdfViewer.focus();
1407 }
1408
1409 this._initializePermissions(pdfDocument);
1410
1411 await Promise.race([pagesPromise, new Promise(resolve => {
1412 setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
1413 })]);
1414
1415 if (!initialBookmark && !hash) {
1416 return;
1417 }
1418
1419 if (pdfViewer.hasEqualPageSizes) {
1420 return;
1421 }
1422
1423 this.initialBookmark = initialBookmark;
1424 pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
1425 this.setInitialView(hash);
1426 }).catch(() => {
1427 this.setInitialView();
1428 }).then(function () {
1429 pdfViewer.update();
1430 });
1431 });
1432 pagesPromise.then(() => {
1433 this._unblockDocumentLoadEvent();
1434
1435 this._initializeAutoPrint(pdfDocument, openActionPromise);
1436 });
1437 onePageRendered.then(() => {
1438 pdfDocument.getOutline().then(outline => {
1439 this.pdfOutlineViewer.render({
1440 outline,
1441 pdfDocument
1442 });
1443 });
1444 pdfDocument.getAttachments().then(attachments => {
1445 this.pdfAttachmentViewer.render({
1446 attachments
1447 });
1448 });
1449 pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
1450 this.pdfLayerViewer.render({
1451 optionalContentConfig,
1452 pdfDocument
1453 });
1454 });
1455
1456 if ("requestIdleCallback" in window) {
1457 const callback = window.requestIdleCallback(() => {
1458 this._collectTelemetry(pdfDocument);
1459
1460 this._idleCallbacks.delete(callback);
1461 }, {
1462 timeout: 1000
1463 });
1464
1465 this._idleCallbacks.add(callback);
1466 }
1467 });
1468
1469 this._initializePageLabels(pdfDocument);
1470
1471 this._initializeMetadata(pdfDocument);
1472 },
1473
1474 async _scriptingDocProperties(pdfDocument) {
1475 if (!this.documentInfo) {
1476 await new Promise(resolve => {
1477 this.eventBus._on("metadataloaded", resolve, {
1478 once: true
1479 });
1480 });
1481
1482 if (pdfDocument !== this.pdfDocument) {
1483 return null;
1484 }
1485 }
1486
1487 if (!this._contentLength) {
1488 await new Promise(resolve => {
1489 this.eventBus._on("documentloaded", resolve, {
1490 once: true
1491 });
1492 });
1493
1494 if (pdfDocument !== this.pdfDocument) {
1495 return null;
1496 }
1497 }
1498
1499 return { ...this.documentInfo,
1500 baseURL: this.baseUrl,
1501 filesize: this._contentLength,
1502 filename: this._docFilename,
1503 metadata: this.metadata?.getRaw(),
1504 authors: this.metadata?.get("dc:creator"),
1505 numPages: this.pagesCount,
1506 URL: this.url
1507 };
1508 },
1509
1510 async _collectTelemetry(pdfDocument) {
1511 const markInfo = await this.pdfDocument.getMarkInfo();
1512
1513 if (pdfDocument !== this.pdfDocument) {
1514 return;
1515 }
1516
1517 const tagged = markInfo?.Marked || false;
1518 this.externalServices.reportTelemetry({
1519 type: "tagged",
1520 tagged
1521 });
1522 },
1523
1524 async _initializeAutoPrint(pdfDocument, openActionPromise) {
1525 const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
1526
1527 if (pdfDocument !== this.pdfDocument) {
1528 return;
1529 }
1530
1531 let triggerAutoPrint = false;
1532
1533 if (openAction?.action === "Print") {
1534 triggerAutoPrint = true;
1535 }
1536
1537 if (javaScript) {
1538 javaScript.some(js => {
1539 if (!js) {
1540 return false;
1541 }
1542
1543 console.warn("Warning: JavaScript is not supported");
1544
1545 this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
1546
1547 return true;
1548 });
1549
1550 if (!triggerAutoPrint) {
1551 for (const js of javaScript) {
1552 if (js && _ui_utils.AutoPrintRegExp.test(js)) {
1553 triggerAutoPrint = true;
1554 break;
1555 }
1556 }
1557 }
1558 }
1559
1560 if (triggerAutoPrint) {
1561 this.triggerPrinting();
1562 }
1563 },
1564
1565 async _initializeMetadata(pdfDocument) {
1566 const {
1567 info,
1568 metadata,
1569 contentDispositionFilename,
1570 contentLength
1571 } = await pdfDocument.getMetadata();
1572
1573 if (pdfDocument !== this.pdfDocument) {
1574 return;
1575 }
1576
1577 this.documentInfo = info;
1578 this.metadata = metadata;
1579 this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
1580 this._contentLength ?? (this._contentLength = contentLength);
1581 console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
1582 let pdfTitle = info?.Title;
1583 const metadataTitle = metadata?.get("dc:title");
1584
1585 if (metadataTitle) {
1586 if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
1587 pdfTitle = metadataTitle;
1588 }
1589 }
1590
1591 if (pdfTitle) {
1592 this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
1593 } else if (contentDispositionFilename) {
1594 this.setTitle(contentDispositionFilename);
1595 }
1596
1597 if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
1598 console.warn("Warning: XFA is not supported");
1599
1600 this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
1601 } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
1602 console.warn("Warning: Interactive form support is not enabled");
1603
1604 this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
1605 }
1606
1607 let versionId = "other";
1608
1609 if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
1610 versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
1611 }
1612
1613 let generatorId = "other";
1614
1615 if (info.Producer) {
1616 const producer = info.Producer.toLowerCase();
1617 KNOWN_GENERATORS.some(function (generator) {
1618 if (!producer.includes(generator)) {
1619 return false;
1620 }
1621
1622 generatorId = generator.replace(/[ .-]/g, "_");
1623 return true;
1624 });
1625 }
1626
1627 let formType = null;
1628
1629 if (info.IsXFAPresent) {
1630 formType = "xfa";
1631 } else if (info.IsAcroFormPresent) {
1632 formType = "acroform";
1633 }
1634
1635 this.externalServices.reportTelemetry({
1636 type: "documentInfo",
1637 version: versionId,
1638 generator: generatorId,
1639 formType
1640 });
1641 this.eventBus.dispatch("metadataloaded", {
1642 source: this
1643 });
1644 },
1645
1646 async _initializePageLabels(pdfDocument) {
1647 const labels = await pdfDocument.getPageLabels();
1648
1649 if (pdfDocument !== this.pdfDocument) {
1650 return;
1651 }
1652
1653 if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
1654 return;
1655 }
1656
1657 const numLabels = labels.length;
1658
1659 if (numLabels !== this.pagesCount) {
1660 console.error("The number of Page Labels does not match the number of pages in the document.");
1661 return;
1662 }
1663
1664 let i = 0;
1665
1666 while (i < numLabels && labels[i] === (i + 1).toString()) {
1667 i++;
1668 }
1669
1670 if (i === numLabels) {
1671 return;
1672 }
1673
1674 const {
1675 pdfViewer,
1676 pdfThumbnailViewer,
1677 toolbar
1678 } = this;
1679 pdfViewer.setPageLabels(labels);
1680 pdfThumbnailViewer.setPageLabels(labels);
1681 toolbar.setPagesCount(numLabels, true);
1682 toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
1683 },
1684
1685 _initializePdfHistory({
1686 fingerprint,
1687 viewOnLoad,
1688 initialDest = null
1689 }) {
1690 if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
1691 return;
1692 }
1693
1694 this.pdfHistory.initialize({
1695 fingerprint,
1696 resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
1697 updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
1698 });
1699
1700 if (this.pdfHistory.initialBookmark) {
1701 this.initialBookmark = this.pdfHistory.initialBookmark;
1702 this.initialRotation = this.pdfHistory.initialRotation;
1703 }
1704
1705 if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
1706 this.initialBookmark = JSON.stringify(initialDest);
1707 this.pdfHistory.push({
1708 explicitDest: initialDest,
1709 pageNumber: null
1710 });
1711 }
1712 },
1713
1714 async _initializePermissions(pdfDocument) {
1715 const permissions = await pdfDocument.getPermissions();
1716
1717 if (pdfDocument !== this.pdfDocument) {
1718 return;
1719 }
1720
1721 if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
1722 return;
1723 }
1724
1725 if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
1726 this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
1727 }
1728 },
1729
1730 _initializeAnnotationStorageCallbacks(pdfDocument) {
1731 if (pdfDocument !== this.pdfDocument) {
1732 return;
1733 }
1734
1735 const {
1736 annotationStorage
1737 } = pdfDocument;
1738
1739 annotationStorage.onSetModified = () => {
1740 window.addEventListener("beforeunload", beforeUnload);
1741 this._annotationStorageModified = true;
1742 };
1743
1744 annotationStorage.onResetModified = () => {
1745 window.removeEventListener("beforeunload", beforeUnload);
1746 delete this._annotationStorageModified;
1747 };
1748 },
1749
1750 setInitialView(storedHash, {
1751 rotation,
1752 sidebarView,
1753 scrollMode,
1754 spreadMode
1755 } = {}) {
1756 const setRotation = angle => {
1757 if ((0, _ui_utils.isValidRotation)(angle)) {
1758 this.pdfViewer.pagesRotation = angle;
1759 }
1760 };
1761
1762 const setViewerModes = (scroll, spread) => {
1763 if ((0, _ui_utils.isValidScrollMode)(scroll)) {
1764 this.pdfViewer.scrollMode = scroll;
1765 }
1766
1767 if ((0, _ui_utils.isValidSpreadMode)(spread)) {
1768 this.pdfViewer.spreadMode = spread;
1769 }
1770 };
1771
1772 this.isInitialViewSet = true;
1773 this.pdfSidebar.setInitialView(sidebarView);
1774 setViewerModes(scrollMode, spreadMode);
1775
1776 if (this.initialBookmark) {
1777 setRotation(this.initialRotation);
1778 delete this.initialRotation;
1779 this.pdfLinkService.setHash(this.initialBookmark);
1780 this.initialBookmark = null;
1781 } else if (storedHash) {
1782 setRotation(rotation);
1783 this.pdfLinkService.setHash(storedHash);
1784 }
1785
1786 this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
1787 this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
1788
1789 if (!this.pdfViewer.currentScaleValue) {
1790 this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
1791 }
1792 },
1793
1794 _cleanup() {
1795 if (!this.pdfDocument) {
1796 return;
1797 }
1798
1799 this.pdfViewer.cleanup();
1800 this.pdfThumbnailViewer.cleanup();
1801 this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
1802 },
1803
1804 forceRendering() {
1805 this.pdfRenderingQueue.printing = !!this.printService;
1806 this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
1807 this.pdfRenderingQueue.renderHighestPriority();
1808 },
1809
1810 beforePrint() {
1811 this.pdfScriptingManager.dispatchWillPrint();
1812
1813 if (this.printService) {
1814 return;
1815 }
1816
1817 if (!this.supportsPrinting) {
1818 this.l10n.get("printing_not_supported").then(msg => {
1819 this._otherError(msg);
1820 });
1821 return;
1822 }
1823
1824 if (!this.pdfViewer.pageViewsReady) {
1825 this.l10n.get("printing_not_ready").then(msg => {
1826 window.alert(msg);
1827 });
1828 return;
1829 }
1830
1831 const pagesOverview = this.pdfViewer.getPagesOverview();
1832 const printContainer = this.appConfig.printContainer;
1833
1834 const printResolution = _app_options.AppOptions.get("printResolution");
1835
1836 const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
1837 const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
1838 this.printService = printService;
1839 this.forceRendering();
1840 printService.layout();
1841 this.externalServices.reportTelemetry({
1842 type: "print"
1843 });
1844 },
1845
1846 afterPrint() {
1847 this.pdfScriptingManager.dispatchDidPrint();
1848
1849 if (this.printService) {
1850 this.printService.destroy();
1851 this.printService = null;
1852
1853 if (this.pdfDocument) {
1854 this.pdfDocument.annotationStorage.resetModified();
1855 }
1856 }
1857
1858 this.forceRendering();
1859 },
1860
1861 rotatePages(delta) {
1862 this.pdfViewer.pagesRotation += delta;
1863 },
1864
1865 requestPresentationMode() {
1866 if (!this.pdfPresentationMode) {
1867 return;
1868 }
1869
1870 this.pdfPresentationMode.request();
1871 },
1872
1873 triggerPrinting() {
1874 if (!this.supportsPrinting) {
1875 return;
1876 }
1877
1878 window.print();
1879 },
1880
1881 bindEvents() {
1882 const {
1883 eventBus,
1884 _boundEvents
1885 } = this;
1886 _boundEvents.beforePrint = this.beforePrint.bind(this);
1887 _boundEvents.afterPrint = this.afterPrint.bind(this);
1888
1889 eventBus._on("resize", webViewerResize);
1890
1891 eventBus._on("hashchange", webViewerHashchange);
1892
1893 eventBus._on("beforeprint", _boundEvents.beforePrint);
1894
1895 eventBus._on("afterprint", _boundEvents.afterPrint);
1896
1897 eventBus._on("pagerendered", webViewerPageRendered);
1898
1899 eventBus._on("updateviewarea", webViewerUpdateViewarea);
1900
1901 eventBus._on("pagechanging", webViewerPageChanging);
1902
1903 eventBus._on("scalechanging", webViewerScaleChanging);
1904
1905 eventBus._on("rotationchanging", webViewerRotationChanging);
1906
1907 eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
1908
1909 eventBus._on("pagemode", webViewerPageMode);
1910
1911 eventBus._on("namedaction", webViewerNamedAction);
1912
1913 eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
1914
1915 eventBus._on("presentationmode", webViewerPresentationMode);
1916
1917 eventBus._on("print", webViewerPrint);
1918
1919 eventBus._on("download", webViewerDownload);
1920
1921 eventBus._on("save", webViewerSave);
1922
1923 eventBus._on("firstpage", webViewerFirstPage);
1924
1925 eventBus._on("lastpage", webViewerLastPage);
1926
1927 eventBus._on("nextpage", webViewerNextPage);
1928
1929 eventBus._on("previouspage", webViewerPreviousPage);
1930
1931 eventBus._on("zoomin", webViewerZoomIn);
1932
1933 eventBus._on("zoomout", webViewerZoomOut);
1934
1935 eventBus._on("zoomreset", webViewerZoomReset);
1936
1937 eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
1938
1939 eventBus._on("scalechanged", webViewerScaleChanged);
1940
1941 eventBus._on("rotatecw", webViewerRotateCw);
1942
1943 eventBus._on("rotateccw", webViewerRotateCcw);
1944
1945 eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
1946
1947 eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
1948
1949 eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
1950
1951 eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
1952
1953 eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
1954
1955 eventBus._on("documentproperties", webViewerDocumentProperties);
1956
1957 eventBus._on("find", webViewerFind);
1958
1959 eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
1960
1961 eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
1962
1963 eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
1964
1965 if (_app_options.AppOptions.get("pdfBug")) {
1966 _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
1967
1968 eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
1969
1970 eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
1971 }
1972
1973 eventBus._on("fileinputchange", webViewerFileInputChange);
1974
1975 eventBus._on("openfile", webViewerOpenFile);
1976 },
1977
1978 bindWindowEvents() {
1979 const {
1980 eventBus,
1981 _boundEvents
1982 } = this;
1983
1984 _boundEvents.windowResize = () => {
1985 eventBus.dispatch("resize", {
1986 source: window
1987 });
1988 };
1989
1990 _boundEvents.windowHashChange = () => {
1991 eventBus.dispatch("hashchange", {
1992 source: window,
1993 hash: document.location.hash.substring(1)
1994 });
1995 };
1996
1997 _boundEvents.windowBeforePrint = () => {
1998 eventBus.dispatch("beforeprint", {
1999 source: window
2000 });
2001 };
2002
2003 _boundEvents.windowAfterPrint = () => {
2004 eventBus.dispatch("afterprint", {
2005 source: window
2006 });
2007 };
2008
2009 _boundEvents.windowUpdateFromSandbox = event => {
2010 eventBus.dispatch("updatefromsandbox", {
2011 source: window,
2012 detail: event.detail
2013 });
2014 };
2015
2016 window.addEventListener("visibilitychange", webViewerVisibilityChange);
2017 window.addEventListener("wheel", webViewerWheel, {
2018 passive: false
2019 });
2020 window.addEventListener("touchstart", webViewerTouchStart, {
2021 passive: false
2022 });
2023 window.addEventListener("click", webViewerClick);
2024 window.addEventListener("keydown", webViewerKeyDown);
2025 window.addEventListener("keyup", webViewerKeyUp);
2026 window.addEventListener("resize", _boundEvents.windowResize);
2027 window.addEventListener("hashchange", _boundEvents.windowHashChange);
2028 window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
2029 window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
2030 window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
2031 },
2032
2033 unbindEvents() {
2034 const {
2035 eventBus,
2036 _boundEvents
2037 } = this;
2038
2039 eventBus._off("resize", webViewerResize);
2040
2041 eventBus._off("hashchange", webViewerHashchange);
2042
2043 eventBus._off("beforeprint", _boundEvents.beforePrint);
2044
2045 eventBus._off("afterprint", _boundEvents.afterPrint);
2046
2047 eventBus._off("pagerendered", webViewerPageRendered);
2048
2049 eventBus._off("updateviewarea", webViewerUpdateViewarea);
2050
2051 eventBus._off("pagechanging", webViewerPageChanging);
2052
2053 eventBus._off("scalechanging", webViewerScaleChanging);
2054
2055 eventBus._off("rotationchanging", webViewerRotationChanging);
2056
2057 eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
2058
2059 eventBus._off("pagemode", webViewerPageMode);
2060
2061 eventBus._off("namedaction", webViewerNamedAction);
2062
2063 eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
2064
2065 eventBus._off("presentationmode", webViewerPresentationMode);
2066
2067 eventBus._off("print", webViewerPrint);
2068
2069 eventBus._off("download", webViewerDownload);
2070
2071 eventBus._off("save", webViewerSave);
2072
2073 eventBus._off("firstpage", webViewerFirstPage);
2074
2075 eventBus._off("lastpage", webViewerLastPage);
2076
2077 eventBus._off("nextpage", webViewerNextPage);
2078
2079 eventBus._off("previouspage", webViewerPreviousPage);
2080
2081 eventBus._off("zoomin", webViewerZoomIn);
2082
2083 eventBus._off("zoomout", webViewerZoomOut);
2084
2085 eventBus._off("zoomreset", webViewerZoomReset);
2086
2087 eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
2088
2089 eventBus._off("scalechanged", webViewerScaleChanged);
2090
2091 eventBus._off("rotatecw", webViewerRotateCw);
2092
2093 eventBus._off("rotateccw", webViewerRotateCcw);
2094
2095 eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
2096
2097 eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
2098
2099 eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
2100
2101 eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
2102
2103 eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
2104
2105 eventBus._off("documentproperties", webViewerDocumentProperties);
2106
2107 eventBus._off("find", webViewerFind);
2108
2109 eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
2110
2111 eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
2112
2113 eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
2114
2115 if (_boundEvents.reportPageStatsPDFBug) {
2116 eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
2117
2118 eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
2119
2120 _boundEvents.reportPageStatsPDFBug = null;
2121 }
2122
2123 eventBus._off("fileinputchange", webViewerFileInputChange);
2124
2125 eventBus._off("openfile", webViewerOpenFile);
2126
2127 _boundEvents.beforePrint = null;
2128 _boundEvents.afterPrint = null;
2129 },
2130
2131 unbindWindowEvents() {
2132 const {
2133 _boundEvents
2134 } = this;
2135 window.removeEventListener("visibilitychange", webViewerVisibilityChange);
2136 window.removeEventListener("wheel", webViewerWheel, {
2137 passive: false
2138 });
2139 window.removeEventListener("touchstart", webViewerTouchStart, {
2140 passive: false
2141 });
2142 window.removeEventListener("click", webViewerClick);
2143 window.removeEventListener("keydown", webViewerKeyDown);
2144 window.removeEventListener("keyup", webViewerKeyUp);
2145 window.removeEventListener("resize", _boundEvents.windowResize);
2146 window.removeEventListener("hashchange", _boundEvents.windowHashChange);
2147 window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
2148 window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
2149 window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
2150 _boundEvents.windowResize = null;
2151 _boundEvents.windowHashChange = null;
2152 _boundEvents.windowBeforePrint = null;
2153 _boundEvents.windowAfterPrint = null;
2154 _boundEvents.windowUpdateFromSandbox = null;
2155 },
2156
2157 accumulateWheelTicks(ticks) {
2158 if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
2159 this._wheelUnusedTicks = 0;
2160 }
2161
2162 this._wheelUnusedTicks += ticks;
2163 const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
2164 this._wheelUnusedTicks -= wholeTicks;
2165 return wholeTicks;
2166 },
2167
2168 _unblockDocumentLoadEvent() {
2169 if (document.blockUnblockOnload) {
2170 document.blockUnblockOnload(false);
2171 }
2172
2173 this._unblockDocumentLoadEvent = () => {};
2174 },
2175
2176 get scriptingReady() {
2177 return this.pdfScriptingManager.ready;
2178 }
2179
2180};
2181exports.PDFViewerApplication = PDFViewerApplication;
2182let validateFileURL;
2183{
2184 const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
2185
2186 validateFileURL = function (file) {
2187 if (file === undefined) {
2188 return;
2189 }
2190
2191 try {
2192 const viewerOrigin = new URL(window.location.href).origin || "null";
2193
2194 if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
2195 return;
2196 }
2197
2198 const {
2199 origin,
2200 protocol
2201 } = new URL(file, window.location.href);
2202
2203 if (origin !== viewerOrigin && protocol !== "blob:") {
2204 throw new Error("file origin does not match viewer's");
2205 }
2206 } catch (ex) {
2207 PDFViewerApplication.l10n.get("loading_error").then(msg => {
2208 PDFViewerApplication._documentError(msg, {
2209 message: ex?.message
2210 });
2211 });
2212 throw ex;
2213 }
2214 };
2215}
2216
2217async function loadFakeWorker() {
2218 if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
2219 _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
2220 }
2221
2222 return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
2223}
2224
2225function loadAndEnablePDFBug(enabledTabs) {
2226 const appConfig = PDFViewerApplication.appConfig;
2227 return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
2228 PDFBug.enable(enabledTabs);
2229 PDFBug.init({
2230 OPS: _pdfjsLib.OPS
2231 }, appConfig.mainContainer);
2232 });
2233}
2234
2235function reportPageStatsPDFBug({
2236 pageNumber
2237}) {
2238 if (typeof Stats === "undefined" || !Stats.enabled) {
2239 return;
2240 }
2241
2242 const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
2243 const pageStats = pageView?.pdfPage?.stats;
2244
2245 if (!pageStats) {
2246 return;
2247 }
2248
2249 Stats.add(pageNumber, pageStats);
2250}
2251
2252function webViewerInitialized() {
2253 const appConfig = PDFViewerApplication.appConfig;
2254 let file;
2255 const queryString = document.location.search.substring(1);
2256 const params = (0, _ui_utils.parseQueryString)(queryString);
2257 file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
2258 validateFileURL(file);
2259 const fileInput = document.createElement("input");
2260 fileInput.id = appConfig.openFileInputName;
2261 fileInput.className = "fileInput";
2262 fileInput.setAttribute("type", "file");
2263 fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
2264 document.body.appendChild(fileInput);
2265
2266 if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
2267 appConfig.toolbar.openFile.hidden = true;
2268 appConfig.secondaryToolbar.openFileButton.hidden = true;
2269 } else {
2270 fileInput.value = null;
2271 }
2272
2273 fileInput.addEventListener("change", function (evt) {
2274 const files = evt.target.files;
2275
2276 if (!files || files.length === 0) {
2277 return;
2278 }
2279
2280 PDFViewerApplication.eventBus.dispatch("fileinputchange", {
2281 source: this,
2282 fileInput: evt.target
2283 });
2284 });
2285 appConfig.mainContainer.addEventListener("dragover", function (evt) {
2286 evt.preventDefault();
2287 evt.dataTransfer.dropEffect = "move";
2288 });
2289 appConfig.mainContainer.addEventListener("drop", function (evt) {
2290 evt.preventDefault();
2291 const files = evt.dataTransfer.files;
2292
2293 if (!files || files.length === 0) {
2294 return;
2295 }
2296
2297 PDFViewerApplication.eventBus.dispatch("fileinputchange", {
2298 source: this,
2299 fileInput: evt.dataTransfer
2300 });
2301 });
2302
2303 if (!PDFViewerApplication.supportsDocumentFonts) {
2304 _app_options.AppOptions.set("disableFontFace", true);
2305
2306 PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
2307 console.warn(msg);
2308 });
2309 }
2310
2311 if (!PDFViewerApplication.supportsPrinting) {
2312 appConfig.toolbar.print.classList.add("hidden");
2313 appConfig.secondaryToolbar.printButton.classList.add("hidden");
2314 }
2315
2316 if (!PDFViewerApplication.supportsFullscreen) {
2317 appConfig.toolbar.presentationModeButton.classList.add("hidden");
2318 appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
2319 }
2320
2321 if (PDFViewerApplication.supportsIntegratedFind) {
2322 appConfig.toolbar.viewFind.classList.add("hidden");
2323 }
2324
2325 appConfig.mainContainer.addEventListener("transitionend", function (evt) {
2326 if (evt.target === this) {
2327 PDFViewerApplication.eventBus.dispatch("resize", {
2328 source: this
2329 });
2330 }
2331 }, true);
2332
2333 try {
2334 webViewerOpenFileViaURL(file);
2335 } catch (reason) {
2336 PDFViewerApplication.l10n.get("loading_error").then(msg => {
2337 PDFViewerApplication._documentError(msg, reason);
2338 });
2339 }
2340}
2341
2342function webViewerOpenFileViaURL(file) {
2343 if (file) {
2344 PDFViewerApplication.open(file);
2345 }
2346}
2347
2348function webViewerResetPermissions() {
2349 const {
2350 appConfig
2351 } = PDFViewerApplication;
2352
2353 if (!appConfig) {
2354 return;
2355 }
2356
2357 appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
2358}
2359
2360function webViewerPageRendered({
2361 pageNumber,
2362 timestamp,
2363 error
2364}) {
2365 if (pageNumber === PDFViewerApplication.page) {
2366 PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
2367 }
2368
2369 if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
2370 const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
2371 const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
2372
2373 if (pageView && thumbnailView) {
2374 thumbnailView.setImage(pageView);
2375 }
2376 }
2377
2378 if (error) {
2379 PDFViewerApplication.l10n.get("rendering_error").then(msg => {
2380 PDFViewerApplication._otherError(msg, error);
2381 });
2382 }
2383
2384 PDFViewerApplication.externalServices.reportTelemetry({
2385 type: "pageInfo",
2386 timestamp
2387 });
2388 PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
2389 PDFViewerApplication.externalServices.reportTelemetry({
2390 type: "documentStats",
2391 stats
2392 });
2393 });
2394}
2395
2396function webViewerPageMode({
2397 mode
2398}) {
2399 let view;
2400
2401 switch (mode) {
2402 case "thumbs":
2403 view = _ui_utils.SidebarView.THUMBS;
2404 break;
2405
2406 case "bookmarks":
2407 case "outline":
2408 view = _ui_utils.SidebarView.OUTLINE;
2409 break;
2410
2411 case "attachments":
2412 view = _ui_utils.SidebarView.ATTACHMENTS;
2413 break;
2414
2415 case "layers":
2416 view = _ui_utils.SidebarView.LAYERS;
2417 break;
2418
2419 case "none":
2420 view = _ui_utils.SidebarView.NONE;
2421 break;
2422
2423 default:
2424 console.error('Invalid "pagemode" hash parameter: ' + mode);
2425 return;
2426 }
2427
2428 PDFViewerApplication.pdfSidebar.switchView(view, true);
2429}
2430
2431function webViewerNamedAction(evt) {
2432 switch (evt.action) {
2433 case "GoToPage":
2434 PDFViewerApplication.appConfig.toolbar.pageNumber.select();
2435 break;
2436
2437 case "Find":
2438 if (!PDFViewerApplication.supportsIntegratedFind) {
2439 PDFViewerApplication.findBar.toggle();
2440 }
2441
2442 break;
2443
2444 case "Print":
2445 PDFViewerApplication.triggerPrinting();
2446 break;
2447
2448 case "SaveAs":
2449 webViewerSave();
2450 break;
2451 }
2452}
2453
2454function webViewerPresentationModeChanged(evt) {
2455 PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
2456}
2457
2458function webViewerSidebarViewChanged(evt) {
2459 PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
2460 const store = PDFViewerApplication.store;
2461
2462 if (store && PDFViewerApplication.isInitialViewSet) {
2463 store.set("sidebarView", evt.view).catch(function () {});
2464 }
2465}
2466
2467function webViewerUpdateViewarea(evt) {
2468 const location = evt.location,
2469 store = PDFViewerApplication.store;
2470
2471 if (store && PDFViewerApplication.isInitialViewSet) {
2472 store.setMultiple({
2473 page: location.pageNumber,
2474 zoom: location.scale,
2475 scrollLeft: location.left,
2476 scrollTop: location.top,
2477 rotation: location.rotation
2478 }).catch(function () {});
2479 }
2480
2481 const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
2482 PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
2483 PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
2484 const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
2485 const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
2486 PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
2487}
2488
2489function webViewerScrollModeChanged(evt) {
2490 const store = PDFViewerApplication.store;
2491
2492 if (store && PDFViewerApplication.isInitialViewSet) {
2493 store.set("scrollMode", evt.mode).catch(function () {});
2494 }
2495}
2496
2497function webViewerSpreadModeChanged(evt) {
2498 const store = PDFViewerApplication.store;
2499
2500 if (store && PDFViewerApplication.isInitialViewSet) {
2501 store.set("spreadMode", evt.mode).catch(function () {});
2502 }
2503}
2504
2505function webViewerResize() {
2506 const {
2507 pdfDocument,
2508 pdfViewer
2509 } = PDFViewerApplication;
2510
2511 if (!pdfDocument) {
2512 return;
2513 }
2514
2515 const currentScaleValue = pdfViewer.currentScaleValue;
2516
2517 if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
2518 pdfViewer.currentScaleValue = currentScaleValue;
2519 }
2520
2521 pdfViewer.update();
2522}
2523
2524function webViewerHashchange(evt) {
2525 const hash = evt.hash;
2526
2527 if (!hash) {
2528 return;
2529 }
2530
2531 if (!PDFViewerApplication.isInitialViewSet) {
2532 PDFViewerApplication.initialBookmark = hash;
2533 } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
2534 PDFViewerApplication.pdfLinkService.setHash(hash);
2535 }
2536}
2537
2538let webViewerFileInputChange, webViewerOpenFile;
2539{
2540 webViewerFileInputChange = function (evt) {
2541 if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
2542 return;
2543 }
2544
2545 const file = evt.fileInput.files[0];
2546
2547 if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
2548 let url = URL.createObjectURL(file);
2549
2550 if (file.name) {
2551 url = {
2552 url,
2553 originalUrl: file.name
2554 };
2555 }
2556
2557 PDFViewerApplication.open(url);
2558 } else {
2559 PDFViewerApplication.setTitleUsingUrl(file.name);
2560 const fileReader = new FileReader();
2561
2562 fileReader.onload = function webViewerChangeFileReaderOnload(event) {
2563 const buffer = event.target.result;
2564 PDFViewerApplication.open(new Uint8Array(buffer));
2565 };
2566
2567 fileReader.readAsArrayBuffer(file);
2568 }
2569
2570 const appConfig = PDFViewerApplication.appConfig;
2571 appConfig.toolbar.viewBookmark.hidden = true;
2572 appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
2573 appConfig.toolbar.download.hidden = true;
2574 appConfig.secondaryToolbar.downloadButton.hidden = true;
2575 };
2576
2577 webViewerOpenFile = function (evt) {
2578 const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
2579 document.getElementById(openFileInputName).click();
2580 };
2581}
2582
2583function webViewerPresentationMode() {
2584 PDFViewerApplication.requestPresentationMode();
2585}
2586
2587function webViewerPrint() {
2588 PDFViewerApplication.triggerPrinting();
2589}
2590
2591function webViewerDownload() {
2592 PDFViewerApplication.downloadOrSave({
2593 sourceEventType: "download"
2594 });
2595}
2596
2597function webViewerSave() {
2598 PDFViewerApplication.downloadOrSave({
2599 sourceEventType: "save"
2600 });
2601}
2602
2603function webViewerFirstPage() {
2604 if (PDFViewerApplication.pdfDocument) {
2605 PDFViewerApplication.page = 1;
2606 }
2607}
2608
2609function webViewerLastPage() {
2610 if (PDFViewerApplication.pdfDocument) {
2611 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
2612 }
2613}
2614
2615function webViewerNextPage() {
2616 PDFViewerApplication.pdfViewer.nextPage();
2617}
2618
2619function webViewerPreviousPage() {
2620 PDFViewerApplication.pdfViewer.previousPage();
2621}
2622
2623function webViewerZoomIn() {
2624 PDFViewerApplication.zoomIn();
2625}
2626
2627function webViewerZoomOut() {
2628 PDFViewerApplication.zoomOut();
2629}
2630
2631function webViewerZoomReset() {
2632 PDFViewerApplication.zoomReset();
2633}
2634
2635function webViewerPageNumberChanged(evt) {
2636 const pdfViewer = PDFViewerApplication.pdfViewer;
2637
2638 if (evt.value !== "") {
2639 PDFViewerApplication.pdfLinkService.goToPage(evt.value);
2640 }
2641
2642 if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
2643 PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
2644 }
2645}
2646
2647function webViewerScaleChanged(evt) {
2648 PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
2649}
2650
2651function webViewerRotateCw() {
2652 PDFViewerApplication.rotatePages(90);
2653}
2654
2655function webViewerRotateCcw() {
2656 PDFViewerApplication.rotatePages(-90);
2657}
2658
2659function webViewerOptionalContentConfig(evt) {
2660 PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
2661}
2662
2663function webViewerSwitchScrollMode(evt) {
2664 PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
2665}
2666
2667function webViewerSwitchSpreadMode(evt) {
2668 PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
2669}
2670
2671function webViewerDocumentProperties() {
2672 PDFViewerApplication.pdfDocumentProperties.open();
2673}
2674
2675function webViewerFind(evt) {
2676 PDFViewerApplication.findController.executeCommand("find" + evt.type, {
2677 query: evt.query,
2678 phraseSearch: evt.phraseSearch,
2679 caseSensitive: evt.caseSensitive,
2680 entireWord: evt.entireWord,
2681 highlightAll: evt.highlightAll,
2682 findPrevious: evt.findPrevious
2683 });
2684}
2685
2686function webViewerFindFromUrlHash(evt) {
2687 PDFViewerApplication.findController.executeCommand("find", {
2688 query: evt.query,
2689 phraseSearch: evt.phraseSearch,
2690 caseSensitive: false,
2691 entireWord: false,
2692 highlightAll: true,
2693 findPrevious: false
2694 });
2695}
2696
2697function webViewerUpdateFindMatchesCount({
2698 matchesCount
2699}) {
2700 if (PDFViewerApplication.supportsIntegratedFind) {
2701 PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
2702 } else {
2703 PDFViewerApplication.findBar.updateResultsCount(matchesCount);
2704 }
2705}
2706
2707function webViewerUpdateFindControlState({
2708 state,
2709 previous,
2710 matchesCount,
2711 rawQuery
2712}) {
2713 if (PDFViewerApplication.supportsIntegratedFind) {
2714 PDFViewerApplication.externalServices.updateFindControlState({
2715 result: state,
2716 findPrevious: previous,
2717 matchesCount,
2718 rawQuery
2719 });
2720 } else {
2721 PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
2722 }
2723}
2724
2725function webViewerScaleChanging(evt) {
2726 PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
2727 PDFViewerApplication.pdfViewer.update();
2728}
2729
2730function webViewerRotationChanging(evt) {
2731 PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
2732 PDFViewerApplication.forceRendering();
2733 PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
2734}
2735
2736function webViewerPageChanging({
2737 pageNumber,
2738 pageLabel
2739}) {
2740 PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
2741 PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
2742
2743 if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
2744 PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
2745 }
2746}
2747
2748function webViewerVisibilityChange(evt) {
2749 if (document.visibilityState === "visible") {
2750 setZoomDisabledTimeout();
2751 }
2752}
2753
2754let zoomDisabledTimeout = null;
2755
2756function setZoomDisabledTimeout() {
2757 if (zoomDisabledTimeout) {
2758 clearTimeout(zoomDisabledTimeout);
2759 }
2760
2761 zoomDisabledTimeout = setTimeout(function () {
2762 zoomDisabledTimeout = null;
2763 }, WHEEL_ZOOM_DISABLED_TIMEOUT);
2764}
2765
2766function webViewerWheel(evt) {
2767 const {
2768 pdfViewer,
2769 supportedMouseWheelZoomModifierKeys
2770 } = PDFViewerApplication;
2771
2772 if (pdfViewer.isInPresentationMode) {
2773 return;
2774 }
2775
2776 if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
2777 evt.preventDefault();
2778
2779 if (zoomDisabledTimeout || document.visibilityState === "hidden") {
2780 return;
2781 }
2782
2783 const previousScale = pdfViewer.currentScale;
2784 const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
2785 let ticks = 0;
2786
2787 if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
2788 if (Math.abs(delta) >= 1) {
2789 ticks = Math.sign(delta);
2790 } else {
2791 ticks = PDFViewerApplication.accumulateWheelTicks(delta);
2792 }
2793 } else {
2794 const PIXELS_PER_LINE_SCALE = 30;
2795 ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
2796 }
2797
2798 if (ticks < 0) {
2799 PDFViewerApplication.zoomOut(-ticks);
2800 } else if (ticks > 0) {
2801 PDFViewerApplication.zoomIn(ticks);
2802 }
2803
2804 const currentScale = pdfViewer.currentScale;
2805
2806 if (previousScale !== currentScale) {
2807 const scaleCorrectionFactor = currentScale / previousScale - 1;
2808 const rect = pdfViewer.container.getBoundingClientRect();
2809 const dx = evt.clientX - rect.left;
2810 const dy = evt.clientY - rect.top;
2811 pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
2812 pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
2813 }
2814 } else {
2815 setZoomDisabledTimeout();
2816 }
2817}
2818
2819function webViewerTouchStart(evt) {
2820 if (evt.touches.length > 1) {
2821 evt.preventDefault();
2822 }
2823}
2824
2825function webViewerClick(evt) {
2826 if (PDFViewerApplication.triggerDelayedFallback && PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
2827 PDFViewerApplication.triggerDelayedFallback();
2828 }
2829
2830 if (!PDFViewerApplication.secondaryToolbar.isOpen) {
2831 return;
2832 }
2833
2834 const appConfig = PDFViewerApplication.appConfig;
2835
2836 if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
2837 PDFViewerApplication.secondaryToolbar.close();
2838 }
2839}
2840
2841function webViewerKeyUp(evt) {
2842 if (evt.keyCode === 9) {
2843 if (PDFViewerApplication.triggerDelayedFallback) {
2844 PDFViewerApplication.triggerDelayedFallback();
2845 }
2846 }
2847}
2848
2849function webViewerKeyDown(evt) {
2850 if (PDFViewerApplication.overlayManager.active) {
2851 return;
2852 }
2853
2854 let handled = false,
2855 ensureViewerFocused = false;
2856 const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
2857 const pdfViewer = PDFViewerApplication.pdfViewer;
2858 const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
2859
2860 if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
2861 switch (evt.keyCode) {
2862 case 70:
2863 if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
2864 PDFViewerApplication.findBar.open();
2865 handled = true;
2866 }
2867
2868 break;
2869
2870 case 71:
2871 if (!PDFViewerApplication.supportsIntegratedFind) {
2872 const findState = PDFViewerApplication.findController.state;
2873
2874 if (findState) {
2875 PDFViewerApplication.findController.executeCommand("findagain", {
2876 query: findState.query,
2877 phraseSearch: findState.phraseSearch,
2878 caseSensitive: findState.caseSensitive,
2879 entireWord: findState.entireWord,
2880 highlightAll: findState.highlightAll,
2881 findPrevious: cmd === 5 || cmd === 12
2882 });
2883 }
2884
2885 handled = true;
2886 }
2887
2888 break;
2889
2890 case 61:
2891 case 107:
2892 case 187:
2893 case 171:
2894 if (!isViewerInPresentationMode) {
2895 PDFViewerApplication.zoomIn();
2896 }
2897
2898 handled = true;
2899 break;
2900
2901 case 173:
2902 case 109:
2903 case 189:
2904 if (!isViewerInPresentationMode) {
2905 PDFViewerApplication.zoomOut();
2906 }
2907
2908 handled = true;
2909 break;
2910
2911 case 48:
2912 case 96:
2913 if (!isViewerInPresentationMode) {
2914 setTimeout(function () {
2915 PDFViewerApplication.zoomReset();
2916 });
2917 handled = false;
2918 }
2919
2920 break;
2921
2922 case 38:
2923 if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
2924 PDFViewerApplication.page = 1;
2925 handled = true;
2926 ensureViewerFocused = true;
2927 }
2928
2929 break;
2930
2931 case 40:
2932 if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
2933 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
2934 handled = true;
2935 ensureViewerFocused = true;
2936 }
2937
2938 break;
2939 }
2940 }
2941
2942 const {
2943 eventBus
2944 } = PDFViewerApplication;
2945
2946 if (cmd === 1 || cmd === 8) {
2947 switch (evt.keyCode) {
2948 case 83:
2949 eventBus.dispatch("download", {
2950 source: window
2951 });
2952 handled = true;
2953 break;
2954
2955 case 79:
2956 {
2957 eventBus.dispatch("openfile", {
2958 source: window
2959 });
2960 handled = true;
2961 }
2962 break;
2963 }
2964 }
2965
2966 if (cmd === 3 || cmd === 10) {
2967 switch (evt.keyCode) {
2968 case 80:
2969 PDFViewerApplication.requestPresentationMode();
2970 handled = true;
2971 break;
2972
2973 case 71:
2974 PDFViewerApplication.appConfig.toolbar.pageNumber.select();
2975 handled = true;
2976 break;
2977 }
2978 }
2979
2980 if (handled) {
2981 if (ensureViewerFocused && !isViewerInPresentationMode) {
2982 pdfViewer.focus();
2983 }
2984
2985 evt.preventDefault();
2986 return;
2987 }
2988
2989 const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
2990 const curElementTagName = curElement?.tagName.toUpperCase();
2991
2992 if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
2993 if (evt.keyCode !== 27) {
2994 return;
2995 }
2996 }
2997
2998 if (cmd === 0) {
2999 let turnPage = 0,
3000 turnOnlyIfPageFit = false;
3001
3002 switch (evt.keyCode) {
3003 case 38:
3004 case 33:
3005 if (pdfViewer.isVerticalScrollbarEnabled) {
3006 turnOnlyIfPageFit = true;
3007 }
3008
3009 turnPage = -1;
3010 break;
3011
3012 case 8:
3013 if (!isViewerInPresentationMode) {
3014 turnOnlyIfPageFit = true;
3015 }
3016
3017 turnPage = -1;
3018 break;
3019
3020 case 37:
3021 if (pdfViewer.isHorizontalScrollbarEnabled) {
3022 turnOnlyIfPageFit = true;
3023 }
3024
3025 case 75:
3026 case 80:
3027 turnPage = -1;
3028 break;
3029
3030 case 27:
3031 if (PDFViewerApplication.secondaryToolbar.isOpen) {
3032 PDFViewerApplication.secondaryToolbar.close();
3033 handled = true;
3034 }
3035
3036 if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
3037 PDFViewerApplication.findBar.close();
3038 handled = true;
3039 }
3040
3041 break;
3042
3043 case 40:
3044 case 34:
3045 if (pdfViewer.isVerticalScrollbarEnabled) {
3046 turnOnlyIfPageFit = true;
3047 }
3048
3049 turnPage = 1;
3050 break;
3051
3052 case 13:
3053 case 32:
3054 if (!isViewerInPresentationMode) {
3055 turnOnlyIfPageFit = true;
3056 }
3057
3058 turnPage = 1;
3059 break;
3060
3061 case 39:
3062 if (pdfViewer.isHorizontalScrollbarEnabled) {
3063 turnOnlyIfPageFit = true;
3064 }
3065
3066 case 74:
3067 case 78:
3068 turnPage = 1;
3069 break;
3070
3071 case 36:
3072 if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
3073 PDFViewerApplication.page = 1;
3074 handled = true;
3075 ensureViewerFocused = true;
3076 }
3077
3078 break;
3079
3080 case 35:
3081 if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
3082 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
3083 handled = true;
3084 ensureViewerFocused = true;
3085 }
3086
3087 break;
3088
3089 case 83:
3090 PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
3091 break;
3092
3093 case 72:
3094 PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
3095 break;
3096
3097 case 82:
3098 PDFViewerApplication.rotatePages(90);
3099 break;
3100
3101 case 115:
3102 PDFViewerApplication.pdfSidebar.toggle();
3103 break;
3104 }
3105
3106 if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
3107 if (turnPage > 0) {
3108 pdfViewer.nextPage();
3109 } else {
3110 pdfViewer.previousPage();
3111 }
3112
3113 handled = true;
3114 }
3115 }
3116
3117 if (cmd === 4) {
3118 switch (evt.keyCode) {
3119 case 13:
3120 case 32:
3121 if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
3122 break;
3123 }
3124
3125 if (PDFViewerApplication.page > 1) {
3126 PDFViewerApplication.page--;
3127 }
3128
3129 handled = true;
3130 break;
3131
3132 case 82:
3133 PDFViewerApplication.rotatePages(-90);
3134 break;
3135 }
3136 }
3137
3138 if (!handled && !isViewerInPresentationMode) {
3139 if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
3140 ensureViewerFocused = true;
3141 }
3142 }
3143
3144 if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
3145 pdfViewer.focus();
3146 }
3147
3148 if (handled) {
3149 evt.preventDefault();
3150 }
3151}
3152
3153function beforeUnload(evt) {
3154 evt.preventDefault();
3155 evt.returnValue = "";
3156 return false;
3157}
3158
3159const PDFPrintServiceFactory = {
3160 instance: {
3161 supportsPrinting: false,
3162
3163 createPrintService() {
3164 throw new Error("Not implemented: createPrintService");
3165 }
3166
3167 }
3168};
3169exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
3170
3171/***/ }),
3172/* 4 */
3173/***/ ((__unused_webpack_module, exports) => {
3174
3175
3176
3177Object.defineProperty(exports, "__esModule", ({
3178 value: true
3179}));
3180exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
3181exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
3182exports.approximateFraction = approximateFraction;
3183exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
3184exports.binarySearchFirstItem = binarySearchFirstItem;
3185exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
3186exports.getOutputScale = getOutputScale;
3187exports.getPageSizeInches = getPageSizeInches;
3188exports.getVisibleElements = getVisibleElements;
3189exports.isPortraitOrientation = isPortraitOrientation;
3190exports.isValidRotation = isValidRotation;
3191exports.isValidScrollMode = isValidScrollMode;
3192exports.isValidSpreadMode = isValidSpreadMode;
3193exports.moveToEndOfArray = moveToEndOfArray;
3194exports.noContextMenuHandler = noContextMenuHandler;
3195exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
3196exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
3197exports.parseQueryString = parseQueryString;
3198exports.roundToDivide = roundToDivide;
3199exports.scrollIntoView = scrollIntoView;
3200exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
3201exports.watchScroll = watchScroll;
3202exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
3203const CSS_UNITS = 96.0 / 72.0;
3204exports.CSS_UNITS = CSS_UNITS;
3205const DEFAULT_SCALE_VALUE = "auto";
3206exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
3207const DEFAULT_SCALE = 1.0;
3208exports.DEFAULT_SCALE = DEFAULT_SCALE;
3209const MIN_SCALE = 0.1;
3210exports.MIN_SCALE = MIN_SCALE;
3211const MAX_SCALE = 10.0;
3212exports.MAX_SCALE = MAX_SCALE;
3213const UNKNOWN_SCALE = 0;
3214exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
3215const MAX_AUTO_SCALE = 1.25;
3216exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
3217const SCROLLBAR_PADDING = 40;
3218exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
3219const VERTICAL_PADDING = 5;
3220exports.VERTICAL_PADDING = VERTICAL_PADDING;
3221const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
3222const PresentationModeState = {
3223 UNKNOWN: 0,
3224 NORMAL: 1,
3225 CHANGING: 2,
3226 FULLSCREEN: 3
3227};
3228exports.PresentationModeState = PresentationModeState;
3229const SidebarView = {
3230 UNKNOWN: -1,
3231 NONE: 0,
3232 THUMBS: 1,
3233 OUTLINE: 2,
3234 ATTACHMENTS: 3,
3235 LAYERS: 4
3236};
3237exports.SidebarView = SidebarView;
3238const RendererType = {
3239 CANVAS: "canvas",
3240 SVG: "svg"
3241};
3242exports.RendererType = RendererType;
3243const TextLayerMode = {
3244 DISABLE: 0,
3245 ENABLE: 1,
3246 ENABLE_ENHANCE: 2
3247};
3248exports.TextLayerMode = TextLayerMode;
3249const ScrollMode = {
3250 UNKNOWN: -1,
3251 VERTICAL: 0,
3252 HORIZONTAL: 1,
3253 WRAPPED: 2
3254};
3255exports.ScrollMode = ScrollMode;
3256const SpreadMode = {
3257 UNKNOWN: -1,
3258 NONE: 0,
3259 ODD: 1,
3260 EVEN: 2
3261};
3262exports.SpreadMode = SpreadMode;
3263const AutoPrintRegExp = /\bprint\s*\(/;
3264exports.AutoPrintRegExp = AutoPrintRegExp;
3265
3266function getOutputScale(ctx) {
3267 const devicePixelRatio = window.devicePixelRatio || 1;
3268 const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
3269 const pixelRatio = devicePixelRatio / backingStoreRatio;
3270 return {
3271 sx: pixelRatio,
3272 sy: pixelRatio,
3273 scaled: pixelRatio !== 1
3274 };
3275}
3276
3277function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
3278 let parent = element.offsetParent;
3279
3280 if (!parent) {
3281 console.error("offsetParent is not set -- cannot scroll");
3282 return;
3283 }
3284
3285 let offsetY = element.offsetTop + element.clientTop;
3286 let offsetX = element.offsetLeft + element.clientLeft;
3287
3288 while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
3289 if (parent.dataset._scaleY) {
3290 offsetY /= parent.dataset._scaleY;
3291 offsetX /= parent.dataset._scaleX;
3292 }
3293
3294 offsetY += parent.offsetTop;
3295 offsetX += parent.offsetLeft;
3296 parent = parent.offsetParent;
3297
3298 if (!parent) {
3299 return;
3300 }
3301 }
3302
3303 if (spot) {
3304 if (spot.top !== undefined) {
3305 offsetY += spot.top;
3306 }
3307
3308 if (spot.left !== undefined) {
3309 offsetX += spot.left;
3310 parent.scrollLeft = offsetX;
3311 }
3312 }
3313
3314 parent.scrollTop = offsetY;
3315}
3316
3317function watchScroll(viewAreaElement, callback) {
3318 const debounceScroll = function (evt) {
3319 if (rAF) {
3320 return;
3321 }
3322
3323 rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
3324 rAF = null;
3325 const currentX = viewAreaElement.scrollLeft;
3326 const lastX = state.lastX;
3327
3328 if (currentX !== lastX) {
3329 state.right = currentX > lastX;
3330 }
3331
3332 state.lastX = currentX;
3333 const currentY = viewAreaElement.scrollTop;
3334 const lastY = state.lastY;
3335
3336 if (currentY !== lastY) {
3337 state.down = currentY > lastY;
3338 }
3339
3340 state.lastY = currentY;
3341 callback(state);
3342 });
3343 };
3344
3345 const state = {
3346 right: true,
3347 down: true,
3348 lastX: viewAreaElement.scrollLeft,
3349 lastY: viewAreaElement.scrollTop,
3350 _eventHandler: debounceScroll
3351 };
3352 let rAF = null;
3353 viewAreaElement.addEventListener("scroll", debounceScroll, true);
3354 return state;
3355}
3356
3357function parseQueryString(query) {
3358 const parts = query.split("&");
3359 const params = Object.create(null);
3360
3361 for (let i = 0, ii = parts.length; i < ii; ++i) {
3362 const param = parts[i].split("=");
3363 const key = param[0].toLowerCase();
3364 const value = param.length > 1 ? param[1] : null;
3365 params[decodeURIComponent(key)] = decodeURIComponent(value);
3366 }
3367
3368 return params;
3369}
3370
3371function binarySearchFirstItem(items, condition) {
3372 let minIndex = 0;
3373 let maxIndex = items.length - 1;
3374
3375 if (maxIndex < 0 || !condition(items[maxIndex])) {
3376 return items.length;
3377 }
3378
3379 if (condition(items[minIndex])) {
3380 return minIndex;
3381 }
3382
3383 while (minIndex < maxIndex) {
3384 const currentIndex = minIndex + maxIndex >> 1;
3385 const currentItem = items[currentIndex];
3386
3387 if (condition(currentItem)) {
3388 maxIndex = currentIndex;
3389 } else {
3390 minIndex = currentIndex + 1;
3391 }
3392 }
3393
3394 return minIndex;
3395}
3396
3397function approximateFraction(x) {
3398 if (Math.floor(x) === x) {
3399 return [x, 1];
3400 }
3401
3402 const xinv = 1 / x;
3403 const limit = 8;
3404
3405 if (xinv > limit) {
3406 return [1, limit];
3407 } else if (Math.floor(xinv) === xinv) {
3408 return [1, xinv];
3409 }
3410
3411 const x_ = x > 1 ? xinv : x;
3412 let a = 0,
3413 b = 1,
3414 c = 1,
3415 d = 1;
3416
3417 while (true) {
3418 const p = a + c,
3419 q = b + d;
3420
3421 if (q > limit) {
3422 break;
3423 }
3424
3425 if (x_ <= p / q) {
3426 c = p;
3427 d = q;
3428 } else {
3429 a = p;
3430 b = q;
3431 }
3432 }
3433
3434 let result;
3435
3436 if (x_ - a / b < c / d - x_) {
3437 result = x_ === x ? [a, b] : [b, a];
3438 } else {
3439 result = x_ === x ? [c, d] : [d, c];
3440 }
3441
3442 return result;
3443}
3444
3445function roundToDivide(x, div) {
3446 const r = x % div;
3447 return r === 0 ? x : Math.round(x - r + div);
3448}
3449
3450function getPageSizeInches({
3451 view,
3452 userUnit,
3453 rotate
3454}) {
3455 const [x1, y1, x2, y2] = view;
3456 const changeOrientation = rotate % 180 !== 0;
3457 const width = (x2 - x1) / 72 * userUnit;
3458 const height = (y2 - y1) / 72 * userUnit;
3459 return {
3460 width: changeOrientation ? height : width,
3461 height: changeOrientation ? width : height
3462 };
3463}
3464
3465function backtrackBeforeAllVisibleElements(index, views, top) {
3466 if (index < 2) {
3467 return index;
3468 }
3469
3470 let elt = views[index].div;
3471 let pageTop = elt.offsetTop + elt.clientTop;
3472
3473 if (pageTop >= top) {
3474 elt = views[index - 1].div;
3475 pageTop = elt.offsetTop + elt.clientTop;
3476 }
3477
3478 for (let i = index - 2; i >= 0; --i) {
3479 elt = views[i].div;
3480
3481 if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
3482 break;
3483 }
3484
3485 index = i;
3486 }
3487
3488 return index;
3489}
3490
3491function getVisibleElements({
3492 scrollEl,
3493 views,
3494 sortByVisibility = false,
3495 horizontal = false,
3496 rtl = false
3497}) {
3498 const top = scrollEl.scrollTop,
3499 bottom = top + scrollEl.clientHeight;
3500 const left = scrollEl.scrollLeft,
3501 right = left + scrollEl.clientWidth;
3502
3503 function isElementBottomAfterViewTop(view) {
3504 const element = view.div;
3505 const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
3506 return elementBottom > top;
3507 }
3508
3509 function isElementNextAfterViewHorizontally(view) {
3510 const element = view.div;
3511 const elementLeft = element.offsetLeft + element.clientLeft;
3512 const elementRight = elementLeft + element.clientWidth;
3513 return rtl ? elementLeft < right : elementRight > left;
3514 }
3515
3516 const visible = [],
3517 numViews = views.length;
3518 let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
3519
3520 if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
3521 firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
3522 }
3523
3524 let lastEdge = horizontal ? right : -1;
3525
3526 for (let i = firstVisibleElementInd; i < numViews; i++) {
3527 const view = views[i],
3528 element = view.div;
3529 const currentWidth = element.offsetLeft + element.clientLeft;
3530 const currentHeight = element.offsetTop + element.clientTop;
3531 const viewWidth = element.clientWidth,
3532 viewHeight = element.clientHeight;
3533 const viewRight = currentWidth + viewWidth;
3534 const viewBottom = currentHeight + viewHeight;
3535
3536 if (lastEdge === -1) {
3537 if (viewBottom >= bottom) {
3538 lastEdge = viewBottom;
3539 }
3540 } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
3541 break;
3542 }
3543
3544 if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
3545 continue;
3546 }
3547
3548 const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
3549 const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
3550 const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
3551 fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
3552 const percent = fractionHeight * fractionWidth * 100 | 0;
3553 visible.push({
3554 id: view.id,
3555 x: currentWidth,
3556 y: currentHeight,
3557 view,
3558 percent,
3559 widthPercent: fractionWidth * 100 | 0
3560 });
3561 }
3562
3563 const first = visible[0],
3564 last = visible[visible.length - 1];
3565
3566 if (sortByVisibility) {
3567 visible.sort(function (a, b) {
3568 const pc = a.percent - b.percent;
3569
3570 if (Math.abs(pc) > 0.001) {
3571 return -pc;
3572 }
3573
3574 return a.id - b.id;
3575 });
3576 }
3577
3578 return {
3579 first,
3580 last,
3581 views: visible
3582 };
3583}
3584
3585function noContextMenuHandler(evt) {
3586 evt.preventDefault();
3587}
3588
3589function normalizeWheelEventDirection(evt) {
3590 let delta = Math.hypot(evt.deltaX, evt.deltaY);
3591 const angle = Math.atan2(evt.deltaY, evt.deltaX);
3592
3593 if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
3594 delta = -delta;
3595 }
3596
3597 return delta;
3598}
3599
3600function normalizeWheelEventDelta(evt) {
3601 let delta = normalizeWheelEventDirection(evt);
3602 const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
3603 const MOUSE_DOM_DELTA_LINE_MODE = 1;
3604 const MOUSE_PIXELS_PER_LINE = 30;
3605 const MOUSE_LINES_PER_PAGE = 30;
3606
3607 if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
3608 delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
3609 } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
3610 delta /= MOUSE_LINES_PER_PAGE;
3611 }
3612
3613 return delta;
3614}
3615
3616function isValidRotation(angle) {
3617 return Number.isInteger(angle) && angle % 90 === 0;
3618}
3619
3620function isValidScrollMode(mode) {
3621 return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
3622}
3623
3624function isValidSpreadMode(mode) {
3625 return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
3626}
3627
3628function isPortraitOrientation(size) {
3629 return size.width <= size.height;
3630}
3631
3632const WaitOnType = {
3633 EVENT: "event",
3634 TIMEOUT: "timeout"
3635};
3636exports.WaitOnType = WaitOnType;
3637
3638function waitOnEventOrTimeout({
3639 target,
3640 name,
3641 delay = 0
3642}) {
3643 return new Promise(function (resolve, reject) {
3644 if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
3645 throw new Error("waitOnEventOrTimeout - invalid parameters.");
3646 }
3647
3648 function handler(type) {
3649 if (target instanceof EventBus) {
3650 target._off(name, eventHandler);
3651 } else {
3652 target.removeEventListener(name, eventHandler);
3653 }
3654
3655 if (timeout) {
3656 clearTimeout(timeout);
3657 }
3658
3659 resolve(type);
3660 }
3661
3662 const eventHandler = handler.bind(null, WaitOnType.EVENT);
3663
3664 if (target instanceof EventBus) {
3665 target._on(name, eventHandler);
3666 } else {
3667 target.addEventListener(name, eventHandler);
3668 }
3669
3670 const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
3671 const timeout = setTimeout(timeoutHandler, delay);
3672 });
3673}
3674
3675const animationStarted = new Promise(function (resolve) {
3676 window.requestAnimationFrame(resolve);
3677});
3678exports.animationStarted = animationStarted;
3679
3680function dispatchDOMEvent(eventName, args = null) {
3681 throw new Error("Not implemented: dispatchDOMEvent");
3682}
3683
3684class EventBus {
3685 constructor(options) {
3686 this._listeners = Object.create(null);
3687 }
3688
3689 on(eventName, listener, options = null) {
3690 this._on(eventName, listener, {
3691 external: true,
3692 once: options?.once
3693 });
3694 }
3695
3696 off(eventName, listener, options = null) {
3697 this._off(eventName, listener, {
3698 external: true,
3699 once: options?.once
3700 });
3701 }
3702
3703 dispatch(eventName) {
3704 const eventListeners = this._listeners[eventName];
3705
3706 if (!eventListeners || eventListeners.length === 0) {
3707 return;
3708 }
3709
3710 const args = Array.prototype.slice.call(arguments, 1);
3711 let externalListeners;
3712 eventListeners.slice(0).forEach(({
3713 listener,
3714 external,
3715 once
3716 }) => {
3717 if (once) {
3718 this._off(eventName, listener);
3719 }
3720
3721 if (external) {
3722 (externalListeners || (externalListeners = [])).push(listener);
3723 return;
3724 }
3725
3726 listener.apply(null, args);
3727 });
3728
3729 if (externalListeners) {
3730 externalListeners.forEach(listener => {
3731 listener.apply(null, args);
3732 });
3733 externalListeners = null;
3734 }
3735 }
3736
3737 _on(eventName, listener, options = null) {
3738 var _this$_listeners;
3739
3740 const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
3741 eventListeners.push({
3742 listener,
3743 external: options?.external === true,
3744 once: options?.once === true
3745 });
3746 }
3747
3748 _off(eventName, listener, options = null) {
3749 const eventListeners = this._listeners[eventName];
3750
3751 if (!eventListeners) {
3752 return;
3753 }
3754
3755 for (let i = 0, ii = eventListeners.length; i < ii; i++) {
3756 if (eventListeners[i].listener === listener) {
3757 eventListeners.splice(i, 1);
3758 return;
3759 }
3760 }
3761 }
3762
3763}
3764
3765exports.EventBus = EventBus;
3766
3767function clamp(v, min, max) {
3768 return Math.min(Math.max(v, min), max);
3769}
3770
3771class ProgressBar {
3772 constructor(id, {
3773 height,
3774 width,
3775 units
3776 } = {}) {
3777 this.visible = true;
3778 this.div = document.querySelector(id + " .progress");
3779 this.bar = this.div.parentNode;
3780 this.height = height || 100;
3781 this.width = width || 100;
3782 this.units = units || "%";
3783 this.div.style.height = this.height + this.units;
3784 this.percent = 0;
3785 }
3786
3787 _updateBar() {
3788 if (this._indeterminate) {
3789 this.div.classList.add("indeterminate");
3790 this.div.style.width = this.width + this.units;
3791 return;
3792 }
3793
3794 this.div.classList.remove("indeterminate");
3795 const progressSize = this.width * this._percent / 100;
3796 this.div.style.width = progressSize + this.units;
3797 }
3798
3799 get percent() {
3800 return this._percent;
3801 }
3802
3803 set percent(val) {
3804 this._indeterminate = isNaN(val);
3805 this._percent = clamp(val, 0, 100);
3806
3807 this._updateBar();
3808 }
3809
3810 setWidth(viewer) {
3811 if (!viewer) {
3812 return;
3813 }
3814
3815 const container = viewer.parentNode;
3816 const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
3817
3818 if (scrollbarWidth > 0) {
3819 const doc = document.documentElement;
3820 doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
3821 }
3822 }
3823
3824 hide() {
3825 if (!this.visible) {
3826 return;
3827 }
3828
3829 this.visible = false;
3830 this.bar.classList.add("hidden");
3831 }
3832
3833 show() {
3834 if (this.visible) {
3835 return;
3836 }
3837
3838 this.visible = true;
3839 this.bar.classList.remove("hidden");
3840 }
3841
3842}
3843
3844exports.ProgressBar = ProgressBar;
3845
3846function moveToEndOfArray(arr, condition) {
3847 const moved = [],
3848 len = arr.length;
3849 let write = 0;
3850
3851 for (let read = 0; read < len; ++read) {
3852 if (condition(arr[read])) {
3853 moved.push(arr[read]);
3854 } else {
3855 arr[write] = arr[read];
3856 ++write;
3857 }
3858 }
3859
3860 for (let read = 0; write < len; ++read, ++write) {
3861 arr[write] = moved[read];
3862 }
3863}
3864
3865function getActiveOrFocusedElement() {
3866 let curRoot = document;
3867 let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
3868
3869 while (curActiveOrFocused?.shadowRoot) {
3870 curRoot = curActiveOrFocused.shadowRoot;
3871 curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
3872 }
3873
3874 return curActiveOrFocused;
3875}
3876
3877function apiPageLayoutToSpreadMode(layout) {
3878 switch (layout) {
3879 case "SinglePage":
3880 case "OneColumn":
3881 return SpreadMode.NONE;
3882
3883 case "TwoColumnLeft":
3884 case "TwoPageLeft":
3885 return SpreadMode.ODD;
3886
3887 case "TwoColumnRight":
3888 case "TwoPageRight":
3889 return SpreadMode.EVEN;
3890 }
3891
3892 return SpreadMode.NONE;
3893}
3894
3895function apiPageModeToSidebarView(mode) {
3896 switch (mode) {
3897 case "UseNone":
3898 return SidebarView.NONE;
3899
3900 case "UseThumbs":
3901 return SidebarView.THUMBS;
3902
3903 case "UseOutlines":
3904 return SidebarView.OUTLINE;
3905
3906 case "UseAttachments":
3907 return SidebarView.ATTACHMENTS;
3908
3909 case "UseOC":
3910 return SidebarView.LAYERS;
3911 }
3912
3913 return SidebarView.NONE;
3914}
3915
3916/***/ }),
3917/* 5 */
3918/***/ ((module) => {
3919
3920
3921
3922let pdfjsLib;
3923
3924if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
3925 pdfjsLib = window["pdfjs-dist/build/pdf"];
3926} else {
3927 pdfjsLib = require("../build/pdf.js");
3928}
3929
3930module.exports = pdfjsLib;
3931
3932/***/ }),
3933/* 6 */
3934/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3935
3936
3937
3938Object.defineProperty(exports, "__esModule", ({
3939 value: true
3940}));
3941exports.PDFCursorTools = exports.CursorTool = void 0;
3942
3943var _grab_to_pan = __webpack_require__(7);
3944
3945var _ui_utils = __webpack_require__(4);
3946
3947const CursorTool = {
3948 SELECT: 0,
3949 HAND: 1,
3950 ZOOM: 2
3951};
3952exports.CursorTool = CursorTool;
3953
3954class PDFCursorTools {
3955 constructor({
3956 container,
3957 eventBus,
3958 cursorToolOnLoad = CursorTool.SELECT
3959 }) {
3960 this.container = container;
3961 this.eventBus = eventBus;
3962 this.active = CursorTool.SELECT;
3963 this.activeBeforePresentationMode = null;
3964 this.handTool = new _grab_to_pan.GrabToPan({
3965 element: this.container
3966 });
3967
3968 this._addEventListeners();
3969
3970 Promise.resolve().then(() => {
3971 this.switchTool(cursorToolOnLoad);
3972 });
3973 }
3974
3975 get activeTool() {
3976 return this.active;
3977 }
3978
3979 switchTool(tool) {
3980 if (this.activeBeforePresentationMode !== null) {
3981 return;
3982 }
3983
3984 if (tool === this.active) {
3985 return;
3986 }
3987
3988 const disableActiveTool = () => {
3989 switch (this.active) {
3990 case CursorTool.SELECT:
3991 break;
3992
3993 case CursorTool.HAND:
3994 this.handTool.deactivate();
3995 break;
3996
3997 case CursorTool.ZOOM:
3998 }
3999 };
4000
4001 switch (tool) {
4002 case CursorTool.SELECT:
4003 disableActiveTool();
4004 break;
4005
4006 case CursorTool.HAND:
4007 disableActiveTool();
4008 this.handTool.activate();
4009 break;
4010
4011 case CursorTool.ZOOM:
4012 default:
4013 console.error(`switchTool: "${tool}" is an unsupported value.`);
4014 return;
4015 }
4016
4017 this.active = tool;
4018
4019 this._dispatchEvent();
4020 }
4021
4022 _dispatchEvent() {
4023 this.eventBus.dispatch("cursortoolchanged", {
4024 source: this,
4025 tool: this.active
4026 });
4027 }
4028
4029 _addEventListeners() {
4030 this.eventBus._on("switchcursortool", evt => {
4031 this.switchTool(evt.tool);
4032 });
4033
4034 this.eventBus._on("presentationmodechanged", evt => {
4035 switch (evt.state) {
4036 case _ui_utils.PresentationModeState.FULLSCREEN:
4037 {
4038 const previouslyActive = this.active;
4039 this.switchTool(CursorTool.SELECT);
4040 this.activeBeforePresentationMode = previouslyActive;
4041 break;
4042 }
4043
4044 case _ui_utils.PresentationModeState.NORMAL:
4045 {
4046 const previouslyActive = this.activeBeforePresentationMode;
4047 this.activeBeforePresentationMode = null;
4048 this.switchTool(previouslyActive);
4049 break;
4050 }
4051 }
4052 });
4053 }
4054
4055}
4056
4057exports.PDFCursorTools = PDFCursorTools;
4058
4059/***/ }),
4060/* 7 */
4061/***/ ((__unused_webpack_module, exports) => {
4062
4063
4064
4065Object.defineProperty(exports, "__esModule", ({
4066 value: true
4067}));
4068exports.GrabToPan = GrabToPan;
4069
4070function GrabToPan(options) {
4071 this.element = options.element;
4072 this.document = options.element.ownerDocument;
4073
4074 if (typeof options.ignoreTarget === "function") {
4075 this.ignoreTarget = options.ignoreTarget;
4076 }
4077
4078 this.onActiveChanged = options.onActiveChanged;
4079 this.activate = this.activate.bind(this);
4080 this.deactivate = this.deactivate.bind(this);
4081 this.toggle = this.toggle.bind(this);
4082 this._onmousedown = this._onmousedown.bind(this);
4083 this._onmousemove = this._onmousemove.bind(this);
4084 this._endPan = this._endPan.bind(this);
4085 const overlay = this.overlay = document.createElement("div");
4086 overlay.className = "grab-to-pan-grabbing";
4087}
4088
4089GrabToPan.prototype = {
4090 CSS_CLASS_GRAB: "grab-to-pan-grab",
4091 activate: function GrabToPan_activate() {
4092 if (!this.active) {
4093 this.active = true;
4094 this.element.addEventListener("mousedown", this._onmousedown, true);
4095 this.element.classList.add(this.CSS_CLASS_GRAB);
4096
4097 if (this.onActiveChanged) {
4098 this.onActiveChanged(true);
4099 }
4100 }
4101 },
4102 deactivate: function GrabToPan_deactivate() {
4103 if (this.active) {
4104 this.active = false;
4105 this.element.removeEventListener("mousedown", this._onmousedown, true);
4106
4107 this._endPan();
4108
4109 this.element.classList.remove(this.CSS_CLASS_GRAB);
4110
4111 if (this.onActiveChanged) {
4112 this.onActiveChanged(false);
4113 }
4114 }
4115 },
4116 toggle: function GrabToPan_toggle() {
4117 if (this.active) {
4118 this.deactivate();
4119 } else {
4120 this.activate();
4121 }
4122 },
4123 ignoreTarget: function GrabToPan_ignoreTarget(node) {
4124 return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
4125 },
4126 _onmousedown: function GrabToPan__onmousedown(event) {
4127 if (event.button !== 0 || this.ignoreTarget(event.target)) {
4128 return;
4129 }
4130
4131 if (event.originalTarget) {
4132 try {
4133 event.originalTarget.tagName;
4134 } catch (e) {
4135 return;
4136 }
4137 }
4138
4139 this.scrollLeftStart = this.element.scrollLeft;
4140 this.scrollTopStart = this.element.scrollTop;
4141 this.clientXStart = event.clientX;
4142 this.clientYStart = event.clientY;
4143 this.document.addEventListener("mousemove", this._onmousemove, true);
4144 this.document.addEventListener("mouseup", this._endPan, true);
4145 this.element.addEventListener("scroll", this._endPan, true);
4146 event.preventDefault();
4147 event.stopPropagation();
4148 const focusedElement = document.activeElement;
4149
4150 if (focusedElement && !focusedElement.contains(event.target)) {
4151 focusedElement.blur();
4152 }
4153 },
4154 _onmousemove: function GrabToPan__onmousemove(event) {
4155 this.element.removeEventListener("scroll", this._endPan, true);
4156
4157 if (isLeftMouseReleased(event)) {
4158 this._endPan();
4159
4160 return;
4161 }
4162
4163 const xDiff = event.clientX - this.clientXStart;
4164 const yDiff = event.clientY - this.clientYStart;
4165 const scrollTop = this.scrollTopStart - yDiff;
4166 const scrollLeft = this.scrollLeftStart - xDiff;
4167
4168 if (this.element.scrollTo) {
4169 this.element.scrollTo({
4170 top: scrollTop,
4171 left: scrollLeft,
4172 behavior: "instant"
4173 });
4174 } else {
4175 this.element.scrollTop = scrollTop;
4176 this.element.scrollLeft = scrollLeft;
4177 }
4178
4179 if (!this.overlay.parentNode) {
4180 document.body.appendChild(this.overlay);
4181 }
4182 },
4183 _endPan: function GrabToPan__endPan() {
4184 this.element.removeEventListener("scroll", this._endPan, true);
4185 this.document.removeEventListener("mousemove", this._onmousemove, true);
4186 this.document.removeEventListener("mouseup", this._endPan, true);
4187 this.overlay.remove();
4188 }
4189};
4190
4191function isLeftMouseReleased(event) {
4192 if ("buttons" in event) {
4193 return !(event.buttons & 1);
4194 }
4195
4196 const chrome = window.chrome;
4197 const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
4198 const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
4199
4200 if (isChrome15OrOpera15plus || isSafari6plus) {
4201 return event.which === 0;
4202 }
4203
4204 return false;
4205}
4206
4207/***/ }),
4208/* 8 */
4209/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4210
4211
4212
4213Object.defineProperty(exports, "__esModule", ({
4214 value: true
4215}));
4216exports.RenderingStates = exports.PDFRenderingQueue = void 0;
4217
4218var _pdfjsLib = __webpack_require__(5);
4219
4220const CLEANUP_TIMEOUT = 30000;
4221const RenderingStates = {
4222 INITIAL: 0,
4223 RUNNING: 1,
4224 PAUSED: 2,
4225 FINISHED: 3
4226};
4227exports.RenderingStates = RenderingStates;
4228
4229class PDFRenderingQueue {
4230 constructor() {
4231 this.pdfViewer = null;
4232 this.pdfThumbnailViewer = null;
4233 this.onIdle = null;
4234 this.highestPriorityPage = null;
4235 this.idleTimeout = null;
4236 this.printing = false;
4237 this.isThumbnailViewEnabled = false;
4238 }
4239
4240 setViewer(pdfViewer) {
4241 this.pdfViewer = pdfViewer;
4242 }
4243
4244 setThumbnailViewer(pdfThumbnailViewer) {
4245 this.pdfThumbnailViewer = pdfThumbnailViewer;
4246 }
4247
4248 isHighestPriority(view) {
4249 return this.highestPriorityPage === view.renderingId;
4250 }
4251
4252 renderHighestPriority(currentlyVisiblePages) {
4253 if (this.idleTimeout) {
4254 clearTimeout(this.idleTimeout);
4255 this.idleTimeout = null;
4256 }
4257
4258 if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
4259 return;
4260 }
4261
4262 if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
4263 if (this.pdfThumbnailViewer.forceRendering()) {
4264 return;
4265 }
4266 }
4267
4268 if (this.printing) {
4269 return;
4270 }
4271
4272 if (this.onIdle) {
4273 this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
4274 }
4275 }
4276
4277 getHighestPriority(visible, views, scrolledDown) {
4278 const visibleViews = visible.views;
4279 const numVisible = visibleViews.length;
4280
4281 if (numVisible === 0) {
4282 return null;
4283 }
4284
4285 for (let i = 0; i < numVisible; ++i) {
4286 const view = visibleViews[i].view;
4287
4288 if (!this.isViewFinished(view)) {
4289 return view;
4290 }
4291 }
4292
4293 if (scrolledDown) {
4294 const nextPageIndex = visible.last.id;
4295
4296 if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
4297 return views[nextPageIndex];
4298 }
4299 } else {
4300 const previousPageIndex = visible.first.id - 2;
4301
4302 if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
4303 return views[previousPageIndex];
4304 }
4305 }
4306
4307 return null;
4308 }
4309
4310 isViewFinished(view) {
4311 return view.renderingState === RenderingStates.FINISHED;
4312 }
4313
4314 renderView(view) {
4315 switch (view.renderingState) {
4316 case RenderingStates.FINISHED:
4317 return false;
4318
4319 case RenderingStates.PAUSED:
4320 this.highestPriorityPage = view.renderingId;
4321 view.resume();
4322 break;
4323
4324 case RenderingStates.RUNNING:
4325 this.highestPriorityPage = view.renderingId;
4326 break;
4327
4328 case RenderingStates.INITIAL:
4329 this.highestPriorityPage = view.renderingId;
4330 view.draw().finally(() => {
4331 this.renderHighestPriority();
4332 }).catch(reason => {
4333 if (reason instanceof _pdfjsLib.RenderingCancelledException) {
4334 return;
4335 }
4336
4337 console.error(`renderView: "${reason}"`);
4338 });
4339 break;
4340 }
4341
4342 return true;
4343 }
4344
4345}
4346
4347exports.PDFRenderingQueue = PDFRenderingQueue;
4348
4349/***/ }),
4350/* 9 */
4351/***/ ((__unused_webpack_module, exports) => {
4352
4353
4354
4355Object.defineProperty(exports, "__esModule", ({
4356 value: true
4357}));
4358exports.OverlayManager = void 0;
4359
4360class OverlayManager {
4361 constructor() {
4362 this._overlays = {};
4363 this._active = null;
4364 this._keyDownBound = this._keyDown.bind(this);
4365 }
4366
4367 get active() {
4368 return this._active;
4369 }
4370
4371 async register(name, element, callerCloseMethod = null, canForceClose = false) {
4372 let container;
4373
4374 if (!name || !element || !(container = element.parentNode)) {
4375 throw new Error("Not enough parameters.");
4376 } else if (this._overlays[name]) {
4377 throw new Error("The overlay is already registered.");
4378 }
4379
4380 this._overlays[name] = {
4381 element,
4382 container,
4383 callerCloseMethod,
4384 canForceClose
4385 };
4386 }
4387
4388 async unregister(name) {
4389 if (!this._overlays[name]) {
4390 throw new Error("The overlay does not exist.");
4391 } else if (this._active === name) {
4392 throw new Error("The overlay cannot be removed while it is active.");
4393 }
4394
4395 delete this._overlays[name];
4396 }
4397
4398 async open(name) {
4399 if (!this._overlays[name]) {
4400 throw new Error("The overlay does not exist.");
4401 } else if (this._active) {
4402 if (this._overlays[name].canForceClose) {
4403 this._closeThroughCaller();
4404 } else if (this._active === name) {
4405 throw new Error("The overlay is already active.");
4406 } else {
4407 throw new Error("Another overlay is currently active.");
4408 }
4409 }
4410
4411 this._active = name;
4412
4413 this._overlays[this._active].element.classList.remove("hidden");
4414
4415 this._overlays[this._active].container.classList.remove("hidden");
4416
4417 window.addEventListener("keydown", this._keyDownBound);
4418 }
4419
4420 async close(name) {
4421 if (!this._overlays[name]) {
4422 throw new Error("The overlay does not exist.");
4423 } else if (!this._active) {
4424 throw new Error("The overlay is currently not active.");
4425 } else if (this._active !== name) {
4426 throw new Error("Another overlay is currently active.");
4427 }
4428
4429 this._overlays[this._active].container.classList.add("hidden");
4430
4431 this._overlays[this._active].element.classList.add("hidden");
4432
4433 this._active = null;
4434 window.removeEventListener("keydown", this._keyDownBound);
4435 }
4436
4437 _keyDown(evt) {
4438 if (this._active && evt.keyCode === 27) {
4439 this._closeThroughCaller();
4440
4441 evt.preventDefault();
4442 }
4443 }
4444
4445 _closeThroughCaller() {
4446 if (this._overlays[this._active].callerCloseMethod) {
4447 this._overlays[this._active].callerCloseMethod();
4448 }
4449
4450 if (this._active) {
4451 this.close(this._active);
4452 }
4453 }
4454
4455}
4456
4457exports.OverlayManager = OverlayManager;
4458
4459/***/ }),
4460/* 10 */
4461/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4462
4463
4464
4465Object.defineProperty(exports, "__esModule", ({
4466 value: true
4467}));
4468exports.PasswordPrompt = void 0;
4469
4470var _pdfjsLib = __webpack_require__(5);
4471
4472class PasswordPrompt {
4473 constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
4474 this.overlayName = options.overlayName;
4475 this.container = options.container;
4476 this.label = options.label;
4477 this.input = options.input;
4478 this.submitButton = options.submitButton;
4479 this.cancelButton = options.cancelButton;
4480 this.overlayManager = overlayManager;
4481 this.l10n = l10n;
4482 this._isViewerEmbedded = isViewerEmbedded;
4483 this.updateCallback = null;
4484 this.reason = null;
4485 this.submitButton.addEventListener("click", this.verify.bind(this));
4486 this.cancelButton.addEventListener("click", this.close.bind(this));
4487 this.input.addEventListener("keydown", e => {
4488 if (e.keyCode === 13) {
4489 this.verify();
4490 }
4491 });
4492 this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
4493 }
4494
4495 async open() {
4496 await this.overlayManager.open(this.overlayName);
4497 const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
4498
4499 if (!this._isViewerEmbedded || passwordIncorrect) {
4500 this.input.focus();
4501 }
4502
4503 this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
4504 }
4505
4506 close() {
4507 this.overlayManager.close(this.overlayName).then(() => {
4508 this.input.value = "";
4509 });
4510 }
4511
4512 verify() {
4513 const password = this.input.value;
4514
4515 if (password?.length > 0) {
4516 this.close();
4517 this.updateCallback(password);
4518 }
4519 }
4520
4521 setUpdateCallback(updateCallback, reason) {
4522 this.updateCallback = updateCallback;
4523 this.reason = reason;
4524 }
4525
4526}
4527
4528exports.PasswordPrompt = PasswordPrompt;
4529
4530/***/ }),
4531/* 11 */
4532/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4533
4534
4535
4536Object.defineProperty(exports, "__esModule", ({
4537 value: true
4538}));
4539exports.PDFAttachmentViewer = void 0;
4540
4541var _pdfjsLib = __webpack_require__(5);
4542
4543var _base_tree_viewer = __webpack_require__(12);
4544
4545class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
4546 constructor(options) {
4547 super(options);
4548 this.downloadManager = options.downloadManager;
4549
4550 this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
4551 }
4552
4553 reset(keepRenderedCapability = false) {
4554 super.reset();
4555 this._attachments = null;
4556
4557 if (!keepRenderedCapability) {
4558 this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
4559 }
4560
4561 if (this._pendingDispatchEvent) {
4562 clearTimeout(this._pendingDispatchEvent);
4563 }
4564
4565 this._pendingDispatchEvent = null;
4566 }
4567
4568 _dispatchEvent(attachmentsCount) {
4569 this._renderedCapability.resolve();
4570
4571 if (this._pendingDispatchEvent) {
4572 clearTimeout(this._pendingDispatchEvent);
4573 this._pendingDispatchEvent = null;
4574 }
4575
4576 if (attachmentsCount === 0) {
4577 this._pendingDispatchEvent = setTimeout(() => {
4578 this.eventBus.dispatch("attachmentsloaded", {
4579 source: this,
4580 attachmentsCount: 0
4581 });
4582 this._pendingDispatchEvent = null;
4583 });
4584 return;
4585 }
4586
4587 this.eventBus.dispatch("attachmentsloaded", {
4588 source: this,
4589 attachmentsCount
4590 });
4591 }
4592
4593 _bindLink(element, {
4594 content,
4595 filename
4596 }) {
4597 element.onclick = () => {
4598 this.downloadManager.openOrDownloadData(element, content, filename);
4599 return false;
4600 };
4601 }
4602
4603 render({
4604 attachments,
4605 keepRenderedCapability = false
4606 }) {
4607 if (this._attachments) {
4608 this.reset(keepRenderedCapability);
4609 }
4610
4611 this._attachments = attachments || null;
4612
4613 if (!attachments) {
4614 this._dispatchEvent(0);
4615
4616 return;
4617 }
4618
4619 const names = Object.keys(attachments).sort(function (a, b) {
4620 return a.toLowerCase().localeCompare(b.toLowerCase());
4621 });
4622 const fragment = document.createDocumentFragment();
4623 let attachmentsCount = 0;
4624
4625 for (const name of names) {
4626 const item = attachments[name];
4627 const content = item.content,
4628 filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
4629 const div = document.createElement("div");
4630 div.className = "treeItem";
4631 const element = document.createElement("a");
4632
4633 this._bindLink(element, {
4634 content,
4635 filename
4636 });
4637
4638 element.textContent = this._normalizeTextContent(filename);
4639 div.appendChild(element);
4640 fragment.appendChild(div);
4641 attachmentsCount++;
4642 }
4643
4644 this._finishRendering(fragment, attachmentsCount);
4645 }
4646
4647 _appendAttachment({
4648 id,
4649 filename,
4650 content
4651 }) {
4652 const renderedPromise = this._renderedCapability.promise;
4653 renderedPromise.then(() => {
4654 if (renderedPromise !== this._renderedCapability.promise) {
4655 return;
4656 }
4657
4658 let attachments = this._attachments;
4659
4660 if (!attachments) {
4661 attachments = Object.create(null);
4662 } else {
4663 for (const name in attachments) {
4664 if (id === name) {
4665 return;
4666 }
4667 }
4668 }
4669
4670 attachments[id] = {
4671 filename,
4672 content
4673 };
4674 this.render({
4675 attachments,
4676 keepRenderedCapability: true
4677 });
4678 });
4679 }
4680
4681}
4682
4683exports.PDFAttachmentViewer = PDFAttachmentViewer;
4684
4685/***/ }),
4686/* 12 */
4687/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4688
4689
4690
4691Object.defineProperty(exports, "__esModule", ({
4692 value: true
4693}));
4694exports.BaseTreeViewer = void 0;
4695
4696var _pdfjsLib = __webpack_require__(5);
4697
4698const TREEITEM_OFFSET_TOP = -100;
4699const TREEITEM_SELECTED_CLASS = "selected";
4700
4701class BaseTreeViewer {
4702 constructor(options) {
4703 if (this.constructor === BaseTreeViewer) {
4704 throw new Error("Cannot initialize BaseTreeViewer.");
4705 }
4706
4707 this.container = options.container;
4708 this.eventBus = options.eventBus;
4709 this.reset();
4710 }
4711
4712 reset() {
4713 this._pdfDocument = null;
4714 this._lastToggleIsShow = true;
4715 this._currentTreeItem = null;
4716 this.container.textContent = "";
4717 this.container.classList.remove("treeWithDeepNesting");
4718 }
4719
4720 _dispatchEvent(count) {
4721 throw new Error("Not implemented: _dispatchEvent");
4722 }
4723
4724 _bindLink(element, params) {
4725 throw new Error("Not implemented: _bindLink");
4726 }
4727
4728 _normalizeTextContent(str) {
4729 return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
4730 }
4731
4732 _addToggleButton(div, hidden = false) {
4733 const toggler = document.createElement("div");
4734 toggler.className = "treeItemToggler";
4735
4736 if (hidden) {
4737 toggler.classList.add("treeItemsHidden");
4738 }
4739
4740 toggler.onclick = evt => {
4741 evt.stopPropagation();
4742 toggler.classList.toggle("treeItemsHidden");
4743
4744 if (evt.shiftKey) {
4745 const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
4746
4747 this._toggleTreeItem(div, shouldShowAll);
4748 }
4749 };
4750
4751 div.insertBefore(toggler, div.firstChild);
4752 }
4753
4754 _toggleTreeItem(root, show = false) {
4755 this._lastToggleIsShow = show;
4756
4757 for (const toggler of root.querySelectorAll(".treeItemToggler")) {
4758 toggler.classList.toggle("treeItemsHidden", !show);
4759 }
4760 }
4761
4762 _toggleAllTreeItems() {
4763 this._toggleTreeItem(this.container, !this._lastToggleIsShow);
4764 }
4765
4766 _finishRendering(fragment, count, hasAnyNesting = false) {
4767 if (hasAnyNesting) {
4768 this.container.classList.add("treeWithDeepNesting");
4769 this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
4770 }
4771
4772 this.container.appendChild(fragment);
4773
4774 this._dispatchEvent(count);
4775 }
4776
4777 render(params) {
4778 throw new Error("Not implemented: render");
4779 }
4780
4781 _updateCurrentTreeItem(treeItem = null) {
4782 if (this._currentTreeItem) {
4783 this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
4784
4785 this._currentTreeItem = null;
4786 }
4787
4788 if (treeItem) {
4789 treeItem.classList.add(TREEITEM_SELECTED_CLASS);
4790 this._currentTreeItem = treeItem;
4791 }
4792 }
4793
4794 _scrollToCurrentTreeItem(treeItem) {
4795 if (!treeItem) {
4796 return;
4797 }
4798
4799 let currentNode = treeItem.parentNode;
4800
4801 while (currentNode && currentNode !== this.container) {
4802 if (currentNode.classList.contains("treeItem")) {
4803 const toggler = currentNode.firstElementChild;
4804 toggler?.classList.remove("treeItemsHidden");
4805 }
4806
4807 currentNode = currentNode.parentNode;
4808 }
4809
4810 this._updateCurrentTreeItem(treeItem);
4811
4812 this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
4813 }
4814
4815}
4816
4817exports.BaseTreeViewer = BaseTreeViewer;
4818
4819/***/ }),
4820/* 13 */
4821/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4822
4823
4824
4825Object.defineProperty(exports, "__esModule", ({
4826 value: true
4827}));
4828exports.PDFDocumentProperties = void 0;
4829
4830var _pdfjsLib = __webpack_require__(5);
4831
4832var _ui_utils = __webpack_require__(4);
4833
4834const DEFAULT_FIELD_CONTENT = "-";
4835const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
4836const US_PAGE_NAMES = {
4837 "8.5x11": "Letter",
4838 "8.5x14": "Legal"
4839};
4840const METRIC_PAGE_NAMES = {
4841 "297x420": "A3",
4842 "210x297": "A4"
4843};
4844
4845function getPageName(size, isPortrait, pageNames) {
4846 const width = isPortrait ? size.width : size.height;
4847 const height = isPortrait ? size.height : size.width;
4848 return pageNames[`${width}x${height}`];
4849}
4850
4851class PDFDocumentProperties {
4852 constructor({
4853 overlayName,
4854 fields,
4855 container,
4856 closeButton
4857 }, overlayManager, eventBus, l10n) {
4858 this.overlayName = overlayName;
4859 this.fields = fields;
4860 this.container = container;
4861 this.overlayManager = overlayManager;
4862 this.l10n = l10n;
4863
4864 this._reset();
4865
4866 closeButton.addEventListener("click", this.close.bind(this));
4867 this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
4868
4869 eventBus._on("pagechanging", evt => {
4870 this._currentPageNumber = evt.pageNumber;
4871 });
4872
4873 eventBus._on("rotationchanging", evt => {
4874 this._pagesRotation = evt.pagesRotation;
4875 });
4876
4877 this._isNonMetricLocale = true;
4878 l10n.getLanguage().then(locale => {
4879 this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
4880 });
4881 }
4882
4883 async open() {
4884 const freezeFieldData = data => {
4885 Object.defineProperty(this, "fieldData", {
4886 value: Object.freeze(data),
4887 writable: false,
4888 enumerable: true,
4889 configurable: true
4890 });
4891 };
4892
4893 await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
4894 const currentPageNumber = this._currentPageNumber;
4895 const pagesRotation = this._pagesRotation;
4896
4897 if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
4898 this._updateUI();
4899
4900 return;
4901 }
4902
4903 const {
4904 info,
4905 contentDispositionFilename,
4906 contentLength
4907 } = await this.pdfDocument.getMetadata();
4908 const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url), this._parseFileSize(contentLength), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
4909 return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
4910 }), this._parseLinearization(info.IsLinearized)]);
4911 freezeFieldData({
4912 fileName,
4913 fileSize,
4914 title: info.Title,
4915 author: info.Author,
4916 subject: info.Subject,
4917 keywords: info.Keywords,
4918 creationDate,
4919 modificationDate,
4920 creator: info.Creator,
4921 producer: info.Producer,
4922 version: info.PDFFormatVersion,
4923 pageCount: this.pdfDocument.numPages,
4924 pageSize,
4925 linearized: isLinearized,
4926 _currentPageNumber: currentPageNumber,
4927 _pagesRotation: pagesRotation
4928 });
4929
4930 this._updateUI();
4931
4932 const {
4933 length
4934 } = await this.pdfDocument.getDownloadInfo();
4935
4936 if (contentLength === length) {
4937 return;
4938 }
4939
4940 const data = Object.assign(Object.create(null), this.fieldData);
4941 data.fileSize = await this._parseFileSize(length);
4942 freezeFieldData(data);
4943
4944 this._updateUI();
4945 }
4946
4947 close() {
4948 this.overlayManager.close(this.overlayName);
4949 }
4950
4951 setDocument(pdfDocument, url = null) {
4952 if (this.pdfDocument) {
4953 this._reset();
4954
4955 this._updateUI(true);
4956 }
4957
4958 if (!pdfDocument) {
4959 return;
4960 }
4961
4962 this.pdfDocument = pdfDocument;
4963 this.url = url;
4964
4965 this._dataAvailableCapability.resolve();
4966 }
4967
4968 _reset() {
4969 this.pdfDocument = null;
4970 this.url = null;
4971 delete this.fieldData;
4972 this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
4973 this._currentPageNumber = 1;
4974 this._pagesRotation = 0;
4975 }
4976
4977 _updateUI(reset = false) {
4978 if (reset || !this.fieldData) {
4979 for (const id in this.fields) {
4980 this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
4981 }
4982
4983 return;
4984 }
4985
4986 if (this.overlayManager.active !== this.overlayName) {
4987 return;
4988 }
4989
4990 for (const id in this.fields) {
4991 const content = this.fieldData[id];
4992 this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
4993 }
4994 }
4995
4996 async _parseFileSize(fileSize = 0) {
4997 const kb = fileSize / 1024,
4998 mb = kb / 1024;
4999
5000 if (!kb) {
5001 return undefined;
5002 }
5003
5004 return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
5005 size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
5006 size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
5007 size_b: fileSize.toLocaleString()
5008 });
5009 }
5010
5011 async _parsePageSize(pageSizeInches, pagesRotation) {
5012 if (!pageSizeInches) {
5013 return undefined;
5014 }
5015
5016 if (pagesRotation % 180 !== 0) {
5017 pageSizeInches = {
5018 width: pageSizeInches.height,
5019 height: pageSizeInches.width
5020 };
5021 }
5022
5023 const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
5024 let sizeInches = {
5025 width: Math.round(pageSizeInches.width * 100) / 100,
5026 height: Math.round(pageSizeInches.height * 100) / 100
5027 };
5028 let sizeMillimeters = {
5029 width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
5030 height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
5031 };
5032 let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
5033
5034 if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
5035 const exactMillimeters = {
5036 width: pageSizeInches.width * 25.4,
5037 height: pageSizeInches.height * 25.4
5038 };
5039 const intMillimeters = {
5040 width: Math.round(sizeMillimeters.width),
5041 height: Math.round(sizeMillimeters.height)
5042 };
5043
5044 if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
5045 rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
5046
5047 if (rawName) {
5048 sizeInches = {
5049 width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
5050 height: Math.round(intMillimeters.height / 25.4 * 100) / 100
5051 };
5052 sizeMillimeters = intMillimeters;
5053 }
5054 }
5055 }
5056
5057 const [{
5058 width,
5059 height
5060 }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
5061 return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
5062 width: width.toLocaleString(),
5063 height: height.toLocaleString(),
5064 unit,
5065 name,
5066 orientation
5067 });
5068 }
5069
5070 async _parseDate(inputDate) {
5071 const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
5072
5073 if (!dateObject) {
5074 return undefined;
5075 }
5076
5077 return this.l10n.get("document_properties_date_string", {
5078 date: dateObject.toLocaleDateString(),
5079 time: dateObject.toLocaleTimeString()
5080 });
5081 }
5082
5083 _parseLinearization(isLinearized) {
5084 return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
5085 }
5086
5087}
5088
5089exports.PDFDocumentProperties = PDFDocumentProperties;
5090
5091/***/ }),
5092/* 14 */
5093/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
5094
5095
5096
5097Object.defineProperty(exports, "__esModule", ({
5098 value: true
5099}));
5100exports.PDFFindBar = void 0;
5101
5102var _pdf_find_controller = __webpack_require__(15);
5103
5104const MATCHES_COUNT_LIMIT = 1000;
5105
5106class PDFFindBar {
5107 constructor(options, eventBus, l10n) {
5108 this.opened = false;
5109 this.bar = options.bar;
5110 this.toggleButton = options.toggleButton;
5111 this.findField = options.findField;
5112 this.highlightAll = options.highlightAllCheckbox;
5113 this.caseSensitive = options.caseSensitiveCheckbox;
5114 this.entireWord = options.entireWordCheckbox;
5115 this.findMsg = options.findMsg;
5116 this.findResultsCount = options.findResultsCount;
5117 this.findPreviousButton = options.findPreviousButton;
5118 this.findNextButton = options.findNextButton;
5119 this.eventBus = eventBus;
5120 this.l10n = l10n;
5121 this.toggleButton.addEventListener("click", () => {
5122 this.toggle();
5123 });
5124 this.findField.addEventListener("input", () => {
5125 this.dispatchEvent("");
5126 });
5127 this.bar.addEventListener("keydown", e => {
5128 switch (e.keyCode) {
5129 case 13:
5130 if (e.target === this.findField) {
5131 this.dispatchEvent("again", e.shiftKey);
5132 }
5133
5134 break;
5135
5136 case 27:
5137 this.close();
5138 break;
5139 }
5140 });
5141 this.findPreviousButton.addEventListener("click", () => {
5142 this.dispatchEvent("again", true);
5143 });
5144 this.findNextButton.addEventListener("click", () => {
5145 this.dispatchEvent("again", false);
5146 });
5147 this.highlightAll.addEventListener("click", () => {
5148 this.dispatchEvent("highlightallchange");
5149 });
5150 this.caseSensitive.addEventListener("click", () => {
5151 this.dispatchEvent("casesensitivitychange");
5152 });
5153 this.entireWord.addEventListener("click", () => {
5154 this.dispatchEvent("entirewordchange");
5155 });
5156
5157 this.eventBus._on("resize", this._adjustWidth.bind(this));
5158 }
5159
5160 reset() {
5161 this.updateUIState();
5162 }
5163
5164 dispatchEvent(type, findPrev) {
5165 this.eventBus.dispatch("find", {
5166 source: this,
5167 type,
5168 query: this.findField.value,
5169 phraseSearch: true,
5170 caseSensitive: this.caseSensitive.checked,
5171 entireWord: this.entireWord.checked,
5172 highlightAll: this.highlightAll.checked,
5173 findPrevious: findPrev
5174 });
5175 }
5176
5177 updateUIState(state, previous, matchesCount) {
5178 let findMsg = Promise.resolve("");
5179 let status = "";
5180
5181 switch (state) {
5182 case _pdf_find_controller.FindState.FOUND:
5183 break;
5184
5185 case _pdf_find_controller.FindState.PENDING:
5186 status = "pending";
5187 break;
5188
5189 case _pdf_find_controller.FindState.NOT_FOUND:
5190 findMsg = this.l10n.get("find_not_found");
5191 status = "notFound";
5192 break;
5193
5194 case _pdf_find_controller.FindState.WRAPPED:
5195 findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
5196 break;
5197 }
5198
5199 this.findField.setAttribute("data-status", status);
5200 findMsg.then(msg => {
5201 this.findMsg.textContent = msg;
5202
5203 this._adjustWidth();
5204 });
5205 this.updateResultsCount(matchesCount);
5206 }
5207
5208 updateResultsCount({
5209 current = 0,
5210 total = 0
5211 } = {}) {
5212 const limit = MATCHES_COUNT_LIMIT;
5213 let matchCountMsg = Promise.resolve("");
5214
5215 if (total > 0) {
5216 if (total > limit) {
5217 let key = "find_match_count_limit";
5218 matchCountMsg = this.l10n.get(key, {
5219 limit
5220 });
5221 } else {
5222 let key = "find_match_count";
5223 matchCountMsg = this.l10n.get(key, {
5224 current,
5225 total
5226 });
5227 }
5228 }
5229
5230 matchCountMsg.then(msg => {
5231 this.findResultsCount.textContent = msg;
5232 this.findResultsCount.classList.toggle("hidden", !total);
5233
5234 this._adjustWidth();
5235 });
5236 }
5237
5238 open() {
5239 if (!this.opened) {
5240 this.opened = true;
5241 this.toggleButton.classList.add("toggled");
5242 this.toggleButton.setAttribute("aria-expanded", "true");
5243 this.bar.classList.remove("hidden");
5244 }
5245
5246 this.findField.select();
5247 this.findField.focus();
5248
5249 this._adjustWidth();
5250 }
5251
5252 close() {
5253 if (!this.opened) {
5254 return;
5255 }
5256
5257 this.opened = false;
5258 this.toggleButton.classList.remove("toggled");
5259 this.toggleButton.setAttribute("aria-expanded", "false");
5260 this.bar.classList.add("hidden");
5261 this.eventBus.dispatch("findbarclose", {
5262 source: this
5263 });
5264 }
5265
5266 toggle() {
5267 if (this.opened) {
5268 this.close();
5269 } else {
5270 this.open();
5271 }
5272 }
5273
5274 _adjustWidth() {
5275 if (!this.opened) {
5276 return;
5277 }
5278
5279 this.bar.classList.remove("wrapContainers");
5280 const findbarHeight = this.bar.clientHeight;
5281 const inputContainerHeight = this.bar.firstElementChild.clientHeight;
5282
5283 if (findbarHeight > inputContainerHeight) {
5284 this.bar.classList.add("wrapContainers");
5285 }
5286 }
5287
5288}
5289
5290exports.PDFFindBar = PDFFindBar;
5291
5292/***/ }),
5293/* 15 */
5294/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
5295
5296
5297
5298Object.defineProperty(exports, "__esModule", ({
5299 value: true
5300}));
5301exports.PDFFindController = exports.FindState = void 0;
5302
5303var _pdfjsLib = __webpack_require__(5);
5304
5305var _pdf_find_utils = __webpack_require__(16);
5306
5307var _ui_utils = __webpack_require__(4);
5308
5309const FindState = {
5310 FOUND: 0,
5311 NOT_FOUND: 1,
5312 WRAPPED: 2,
5313 PENDING: 3
5314};
5315exports.FindState = FindState;
5316const FIND_TIMEOUT = 250;
5317const MATCH_SCROLL_OFFSET_TOP = -50;
5318const MATCH_SCROLL_OFFSET_LEFT = -400;
5319const CHARACTERS_TO_NORMALIZE = {
5320 "\u2018": "'",
5321 "\u2019": "'",
5322 "\u201A": "'",
5323 "\u201B": "'",
5324 "\u201C": '"',
5325 "\u201D": '"',
5326 "\u201E": '"',
5327 "\u201F": '"',
5328 "\u00BC": "1/4",
5329 "\u00BD": "1/2",
5330 "\u00BE": "3/4"
5331};
5332let normalizationRegex = null;
5333
5334function normalize(text) {
5335 if (!normalizationRegex) {
5336 const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
5337 normalizationRegex = new RegExp(`[${replace}]`, "g");
5338 }
5339
5340 let diffs = null;
5341 const normalizedText = text.replace(normalizationRegex, function (ch, index) {
5342 const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
5343 diff = normalizedCh.length - ch.length;
5344
5345 if (diff !== 0) {
5346 (diffs || (diffs = [])).push([index, diff]);
5347 }
5348
5349 return normalizedCh;
5350 });
5351 return [normalizedText, diffs];
5352}
5353
5354function getOriginalIndex(matchIndex, diffs = null) {
5355 if (!diffs) {
5356 return matchIndex;
5357 }
5358
5359 let totalDiff = 0;
5360
5361 for (const [index, diff] of diffs) {
5362 const currentIndex = index + totalDiff;
5363
5364 if (currentIndex >= matchIndex) {
5365 break;
5366 }
5367
5368 if (currentIndex + diff > matchIndex) {
5369 totalDiff += matchIndex - currentIndex;
5370 break;
5371 }
5372
5373 totalDiff += diff;
5374 }
5375
5376 return matchIndex - totalDiff;
5377}
5378
5379class PDFFindController {
5380 constructor({
5381 linkService,
5382 eventBus
5383 }) {
5384 this._linkService = linkService;
5385 this._eventBus = eventBus;
5386
5387 this._reset();
5388
5389 eventBus._on("findbarclose", this._onFindBarClose.bind(this));
5390 }
5391
5392 get highlightMatches() {
5393 return this._highlightMatches;
5394 }
5395
5396 get pageMatches() {
5397 return this._pageMatches;
5398 }
5399
5400 get pageMatchesLength() {
5401 return this._pageMatchesLength;
5402 }
5403
5404 get selected() {
5405 return this._selected;
5406 }
5407
5408 get state() {
5409 return this._state;
5410 }
5411
5412 setDocument(pdfDocument) {
5413 if (this._pdfDocument) {
5414 this._reset();
5415 }
5416
5417 if (!pdfDocument) {
5418 return;
5419 }
5420
5421 this._pdfDocument = pdfDocument;
5422
5423 this._firstPageCapability.resolve();
5424 }
5425
5426 executeCommand(cmd, state) {
5427 if (!state) {
5428 return;
5429 }
5430
5431 const pdfDocument = this._pdfDocument;
5432
5433 if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
5434 this._dirtyMatch = true;
5435 }
5436
5437 this._state = state;
5438
5439 if (cmd !== "findhighlightallchange") {
5440 this._updateUIState(FindState.PENDING);
5441 }
5442
5443 this._firstPageCapability.promise.then(() => {
5444 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
5445 return;
5446 }
5447
5448 this._extractText();
5449
5450 const findbarClosed = !this._highlightMatches;
5451 const pendingTimeout = !!this._findTimeout;
5452
5453 if (this._findTimeout) {
5454 clearTimeout(this._findTimeout);
5455 this._findTimeout = null;
5456 }
5457
5458 if (cmd === "find") {
5459 this._findTimeout = setTimeout(() => {
5460 this._nextMatch();
5461
5462 this._findTimeout = null;
5463 }, FIND_TIMEOUT);
5464 } else if (this._dirtyMatch) {
5465 this._nextMatch();
5466 } else if (cmd === "findagain") {
5467 this._nextMatch();
5468
5469 if (findbarClosed && this._state.highlightAll) {
5470 this._updateAllPages();
5471 }
5472 } else if (cmd === "findhighlightallchange") {
5473 if (pendingTimeout) {
5474 this._nextMatch();
5475 } else {
5476 this._highlightMatches = true;
5477 }
5478
5479 this._updateAllPages();
5480 } else {
5481 this._nextMatch();
5482 }
5483 });
5484 }
5485
5486 scrollMatchIntoView({
5487 element = null,
5488 pageIndex = -1,
5489 matchIndex = -1
5490 }) {
5491 if (!this._scrollMatches || !element) {
5492 return;
5493 } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
5494 return;
5495 } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
5496 return;
5497 }
5498
5499 this._scrollMatches = false;
5500 const spot = {
5501 top: MATCH_SCROLL_OFFSET_TOP,
5502 left: MATCH_SCROLL_OFFSET_LEFT
5503 };
5504 (0, _ui_utils.scrollIntoView)(element, spot, true);
5505 }
5506
5507 _reset() {
5508 this._highlightMatches = false;
5509 this._scrollMatches = false;
5510 this._pdfDocument = null;
5511 this._pageMatches = [];
5512 this._pageMatchesLength = [];
5513 this._state = null;
5514 this._selected = {
5515 pageIdx: -1,
5516 matchIdx: -1
5517 };
5518 this._offset = {
5519 pageIdx: null,
5520 matchIdx: null,
5521 wrapped: false
5522 };
5523 this._extractTextPromises = [];
5524 this._pageContents = [];
5525 this._pageDiffs = [];
5526 this._matchesCountTotal = 0;
5527 this._pagesToSearch = null;
5528 this._pendingFindMatches = Object.create(null);
5529 this._resumePageIdx = null;
5530 this._dirtyMatch = false;
5531 clearTimeout(this._findTimeout);
5532 this._findTimeout = null;
5533 this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
5534 }
5535
5536 get _query() {
5537 if (this._state.query !== this._rawQuery) {
5538 this._rawQuery = this._state.query;
5539 [this._normalizedQuery] = normalize(this._state.query);
5540 }
5541
5542 return this._normalizedQuery;
5543 }
5544
5545 _shouldDirtyMatch(cmd, state) {
5546 if (state.query !== this._state.query) {
5547 return true;
5548 }
5549
5550 switch (cmd) {
5551 case "findagain":
5552 const pageNumber = this._selected.pageIdx + 1;
5553 const linkService = this._linkService;
5554
5555 if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
5556 return true;
5557 }
5558
5559 return false;
5560
5561 case "findhighlightallchange":
5562 return false;
5563 }
5564
5565 return true;
5566 }
5567
5568 _prepareMatches(matchesWithLength, matches, matchesLength) {
5569 function isSubTerm(currentIndex) {
5570 const currentElem = matchesWithLength[currentIndex];
5571 const nextElem = matchesWithLength[currentIndex + 1];
5572
5573 if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
5574 currentElem.skipped = true;
5575 return true;
5576 }
5577
5578 for (let i = currentIndex - 1; i >= 0; i--) {
5579 const prevElem = matchesWithLength[i];
5580
5581 if (prevElem.skipped) {
5582 continue;
5583 }
5584
5585 if (prevElem.match + prevElem.matchLength < currentElem.match) {
5586 break;
5587 }
5588
5589 if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
5590 currentElem.skipped = true;
5591 return true;
5592 }
5593 }
5594
5595 return false;
5596 }
5597
5598 matchesWithLength.sort(function (a, b) {
5599 return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
5600 });
5601
5602 for (let i = 0, len = matchesWithLength.length; i < len; i++) {
5603 if (isSubTerm(i)) {
5604 continue;
5605 }
5606
5607 matches.push(matchesWithLength[i].match);
5608 matchesLength.push(matchesWithLength[i].matchLength);
5609 }
5610 }
5611
5612 _isEntireWord(content, startIdx, length) {
5613 if (startIdx > 0) {
5614 const first = content.charCodeAt(startIdx);
5615 const limit = content.charCodeAt(startIdx - 1);
5616
5617 if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
5618 return false;
5619 }
5620 }
5621
5622 const endIdx = startIdx + length - 1;
5623
5624 if (endIdx < content.length - 1) {
5625 const last = content.charCodeAt(endIdx);
5626 const limit = content.charCodeAt(endIdx + 1);
5627
5628 if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
5629 return false;
5630 }
5631 }
5632
5633 return true;
5634 }
5635
5636 _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
5637 const matches = [],
5638 matchesLength = [];
5639 const queryLen = query.length;
5640 let matchIdx = -queryLen;
5641
5642 while (true) {
5643 matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
5644
5645 if (matchIdx === -1) {
5646 break;
5647 }
5648
5649 if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
5650 continue;
5651 }
5652
5653 const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
5654 matchEnd = matchIdx + queryLen - 1,
5655 originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
5656 matches.push(originalMatchIdx);
5657 matchesLength.push(originalQueryLen);
5658 }
5659
5660 this._pageMatches[pageIndex] = matches;
5661 this._pageMatchesLength[pageIndex] = matchesLength;
5662 }
5663
5664 _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
5665 const matchesWithLength = [];
5666 const queryArray = query.match(/\S+/g);
5667
5668 for (let i = 0, len = queryArray.length; i < len; i++) {
5669 const subquery = queryArray[i];
5670 const subqueryLen = subquery.length;
5671 let matchIdx = -subqueryLen;
5672
5673 while (true) {
5674 matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
5675
5676 if (matchIdx === -1) {
5677 break;
5678 }
5679
5680 if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
5681 continue;
5682 }
5683
5684 const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
5685 matchEnd = matchIdx + subqueryLen - 1,
5686 originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
5687 matchesWithLength.push({
5688 match: originalMatchIdx,
5689 matchLength: originalQueryLen,
5690 skipped: false
5691 });
5692 }
5693 }
5694
5695 this._pageMatchesLength[pageIndex] = [];
5696 this._pageMatches[pageIndex] = [];
5697
5698 this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
5699 }
5700
5701 _calculateMatch(pageIndex) {
5702 let pageContent = this._pageContents[pageIndex];
5703 const pageDiffs = this._pageDiffs[pageIndex];
5704 let query = this._query;
5705 const {
5706 caseSensitive,
5707 entireWord,
5708 phraseSearch
5709 } = this._state;
5710
5711 if (query.length === 0) {
5712 return;
5713 }
5714
5715 if (!caseSensitive) {
5716 pageContent = pageContent.toLowerCase();
5717 query = query.toLowerCase();
5718 }
5719
5720 if (phraseSearch) {
5721 this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
5722 } else {
5723 this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
5724 }
5725
5726 if (this._state.highlightAll) {
5727 this._updatePage(pageIndex);
5728 }
5729
5730 if (this._resumePageIdx === pageIndex) {
5731 this._resumePageIdx = null;
5732
5733 this._nextPageMatch();
5734 }
5735
5736 const pageMatchesCount = this._pageMatches[pageIndex].length;
5737
5738 if (pageMatchesCount > 0) {
5739 this._matchesCountTotal += pageMatchesCount;
5740
5741 this._updateUIResultsCount();
5742 }
5743 }
5744
5745 _extractText() {
5746 if (this._extractTextPromises.length > 0) {
5747 return;
5748 }
5749
5750 let promise = Promise.resolve();
5751
5752 for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
5753 const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
5754 this._extractTextPromises[i] = extractTextCapability.promise;
5755 promise = promise.then(() => {
5756 return this._pdfDocument.getPage(i + 1).then(pdfPage => {
5757 return pdfPage.getTextContent({
5758 normalizeWhitespace: true
5759 });
5760 }).then(textContent => {
5761 const textItems = textContent.items;
5762 const strBuf = [];
5763
5764 for (let j = 0, jj = textItems.length; j < jj; j++) {
5765 strBuf.push(textItems[j].str);
5766 }
5767
5768 [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
5769 extractTextCapability.resolve(i);
5770 }, reason => {
5771 console.error(`Unable to get text content for page ${i + 1}`, reason);
5772 this._pageContents[i] = "";
5773 this._pageDiffs[i] = null;
5774 extractTextCapability.resolve(i);
5775 });
5776 });
5777 }
5778 }
5779
5780 _updatePage(index) {
5781 if (this._scrollMatches && this._selected.pageIdx === index) {
5782 this._linkService.page = index + 1;
5783 }
5784
5785 this._eventBus.dispatch("updatetextlayermatches", {
5786 source: this,
5787 pageIndex: index
5788 });
5789 }
5790
5791 _updateAllPages() {
5792 this._eventBus.dispatch("updatetextlayermatches", {
5793 source: this,
5794 pageIndex: -1
5795 });
5796 }
5797
5798 _nextMatch() {
5799 const previous = this._state.findPrevious;
5800 const currentPageIndex = this._linkService.page - 1;
5801 const numPages = this._linkService.pagesCount;
5802 this._highlightMatches = true;
5803
5804 if (this._dirtyMatch) {
5805 this._dirtyMatch = false;
5806 this._selected.pageIdx = this._selected.matchIdx = -1;
5807 this._offset.pageIdx = currentPageIndex;
5808 this._offset.matchIdx = null;
5809 this._offset.wrapped = false;
5810 this._resumePageIdx = null;
5811 this._pageMatches.length = 0;
5812 this._pageMatchesLength.length = 0;
5813 this._matchesCountTotal = 0;
5814
5815 this._updateAllPages();
5816
5817 for (let i = 0; i < numPages; i++) {
5818 if (this._pendingFindMatches[i] === true) {
5819 continue;
5820 }
5821
5822 this._pendingFindMatches[i] = true;
5823
5824 this._extractTextPromises[i].then(pageIdx => {
5825 delete this._pendingFindMatches[pageIdx];
5826
5827 this._calculateMatch(pageIdx);
5828 });
5829 }
5830 }
5831
5832 if (this._query === "") {
5833 this._updateUIState(FindState.FOUND);
5834
5835 return;
5836 }
5837
5838 if (this._resumePageIdx) {
5839 return;
5840 }
5841
5842 const offset = this._offset;
5843 this._pagesToSearch = numPages;
5844
5845 if (offset.matchIdx !== null) {
5846 const numPageMatches = this._pageMatches[offset.pageIdx].length;
5847
5848 if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
5849 offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
5850
5851 this._updateMatch(true);
5852
5853 return;
5854 }
5855
5856 this._advanceOffsetPage(previous);
5857 }
5858
5859 this._nextPageMatch();
5860 }
5861
5862 _matchesReady(matches) {
5863 const offset = this._offset;
5864 const numMatches = matches.length;
5865 const previous = this._state.findPrevious;
5866
5867 if (numMatches) {
5868 offset.matchIdx = previous ? numMatches - 1 : 0;
5869
5870 this._updateMatch(true);
5871
5872 return true;
5873 }
5874
5875 this._advanceOffsetPage(previous);
5876
5877 if (offset.wrapped) {
5878 offset.matchIdx = null;
5879
5880 if (this._pagesToSearch < 0) {
5881 this._updateMatch(false);
5882
5883 return true;
5884 }
5885 }
5886
5887 return false;
5888 }
5889
5890 _nextPageMatch() {
5891 if (this._resumePageIdx !== null) {
5892 console.error("There can only be one pending page.");
5893 }
5894
5895 let matches = null;
5896
5897 do {
5898 const pageIdx = this._offset.pageIdx;
5899 matches = this._pageMatches[pageIdx];
5900
5901 if (!matches) {
5902 this._resumePageIdx = pageIdx;
5903 break;
5904 }
5905 } while (!this._matchesReady(matches));
5906 }
5907
5908 _advanceOffsetPage(previous) {
5909 const offset = this._offset;
5910 const numPages = this._linkService.pagesCount;
5911 offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
5912 offset.matchIdx = null;
5913 this._pagesToSearch--;
5914
5915 if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
5916 offset.pageIdx = previous ? numPages - 1 : 0;
5917 offset.wrapped = true;
5918 }
5919 }
5920
5921 _updateMatch(found = false) {
5922 let state = FindState.NOT_FOUND;
5923 const wrapped = this._offset.wrapped;
5924 this._offset.wrapped = false;
5925
5926 if (found) {
5927 const previousPage = this._selected.pageIdx;
5928 this._selected.pageIdx = this._offset.pageIdx;
5929 this._selected.matchIdx = this._offset.matchIdx;
5930 state = wrapped ? FindState.WRAPPED : FindState.FOUND;
5931
5932 if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
5933 this._updatePage(previousPage);
5934 }
5935 }
5936
5937 this._updateUIState(state, this._state.findPrevious);
5938
5939 if (this._selected.pageIdx !== -1) {
5940 this._scrollMatches = true;
5941
5942 this._updatePage(this._selected.pageIdx);
5943 }
5944 }
5945
5946 _onFindBarClose(evt) {
5947 const pdfDocument = this._pdfDocument;
5948
5949 this._firstPageCapability.promise.then(() => {
5950 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
5951 return;
5952 }
5953
5954 if (this._findTimeout) {
5955 clearTimeout(this._findTimeout);
5956 this._findTimeout = null;
5957 }
5958
5959 if (this._resumePageIdx) {
5960 this._resumePageIdx = null;
5961 this._dirtyMatch = true;
5962 }
5963
5964 this._updateUIState(FindState.FOUND);
5965
5966 this._highlightMatches = false;
5967
5968 this._updateAllPages();
5969 });
5970 }
5971
5972 _requestMatchesCount() {
5973 const {
5974 pageIdx,
5975 matchIdx
5976 } = this._selected;
5977 let current = 0,
5978 total = this._matchesCountTotal;
5979
5980 if (matchIdx !== -1) {
5981 for (let i = 0; i < pageIdx; i++) {
5982 current += this._pageMatches[i]?.length || 0;
5983 }
5984
5985 current += matchIdx + 1;
5986 }
5987
5988 if (current < 1 || current > total) {
5989 current = total = 0;
5990 }
5991
5992 return {
5993 current,
5994 total
5995 };
5996 }
5997
5998 _updateUIResultsCount() {
5999 this._eventBus.dispatch("updatefindmatchescount", {
6000 source: this,
6001 matchesCount: this._requestMatchesCount()
6002 });
6003 }
6004
6005 _updateUIState(state, previous) {
6006 this._eventBus.dispatch("updatefindcontrolstate", {
6007 source: this,
6008 state,
6009 previous,
6010 matchesCount: this._requestMatchesCount(),
6011 rawQuery: this._state?.query ?? null
6012 });
6013 }
6014
6015}
6016
6017exports.PDFFindController = PDFFindController;
6018
6019/***/ }),
6020/* 16 */
6021/***/ ((__unused_webpack_module, exports) => {
6022
6023
6024
6025Object.defineProperty(exports, "__esModule", ({
6026 value: true
6027}));
6028exports.getCharacterType = getCharacterType;
6029exports.CharacterType = void 0;
6030const CharacterType = {
6031 SPACE: 0,
6032 ALPHA_LETTER: 1,
6033 PUNCT: 2,
6034 HAN_LETTER: 3,
6035 KATAKANA_LETTER: 4,
6036 HIRAGANA_LETTER: 5,
6037 HALFWIDTH_KATAKANA_LETTER: 6,
6038 THAI_LETTER: 7
6039};
6040exports.CharacterType = CharacterType;
6041
6042function isAlphabeticalScript(charCode) {
6043 return charCode < 0x2e80;
6044}
6045
6046function isAscii(charCode) {
6047 return (charCode & 0xff80) === 0;
6048}
6049
6050function isAsciiAlpha(charCode) {
6051 return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
6052}
6053
6054function isAsciiDigit(charCode) {
6055 return charCode >= 0x30 && charCode <= 0x39;
6056}
6057
6058function isAsciiSpace(charCode) {
6059 return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
6060}
6061
6062function isHan(charCode) {
6063 return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
6064}
6065
6066function isKatakana(charCode) {
6067 return charCode >= 0x30a0 && charCode <= 0x30ff;
6068}
6069
6070function isHiragana(charCode) {
6071 return charCode >= 0x3040 && charCode <= 0x309f;
6072}
6073
6074function isHalfwidthKatakana(charCode) {
6075 return charCode >= 0xff60 && charCode <= 0xff9f;
6076}
6077
6078function isThai(charCode) {
6079 return (charCode & 0xff80) === 0x0e00;
6080}
6081
6082function getCharacterType(charCode) {
6083 if (isAlphabeticalScript(charCode)) {
6084 if (isAscii(charCode)) {
6085 if (isAsciiSpace(charCode)) {
6086 return CharacterType.SPACE;
6087 } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
6088 return CharacterType.ALPHA_LETTER;
6089 }
6090
6091 return CharacterType.PUNCT;
6092 } else if (isThai(charCode)) {
6093 return CharacterType.THAI_LETTER;
6094 } else if (charCode === 0xa0) {
6095 return CharacterType.SPACE;
6096 }
6097
6098 return CharacterType.ALPHA_LETTER;
6099 }
6100
6101 if (isHan(charCode)) {
6102 return CharacterType.HAN_LETTER;
6103 } else if (isKatakana(charCode)) {
6104 return CharacterType.KATAKANA_LETTER;
6105 } else if (isHiragana(charCode)) {
6106 return CharacterType.HIRAGANA_LETTER;
6107 } else if (isHalfwidthKatakana(charCode)) {
6108 return CharacterType.HALFWIDTH_KATAKANA_LETTER;
6109 }
6110
6111 return CharacterType.ALPHA_LETTER;
6112}
6113
6114/***/ }),
6115/* 17 */
6116/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
6117
6118
6119
6120Object.defineProperty(exports, "__esModule", ({
6121 value: true
6122}));
6123exports.isDestArraysEqual = isDestArraysEqual;
6124exports.isDestHashesEqual = isDestHashesEqual;
6125exports.PDFHistory = void 0;
6126
6127var _ui_utils = __webpack_require__(4);
6128
6129const HASH_CHANGE_TIMEOUT = 1000;
6130const POSITION_UPDATED_THRESHOLD = 50;
6131const UPDATE_VIEWAREA_TIMEOUT = 1000;
6132
6133function getCurrentHash() {
6134 return document.location.hash;
6135}
6136
6137class PDFHistory {
6138 constructor({
6139 linkService,
6140 eventBus
6141 }) {
6142 this.linkService = linkService;
6143 this.eventBus = eventBus;
6144 this._initialized = false;
6145 this._fingerprint = "";
6146 this.reset();
6147 this._boundEvents = null;
6148 this._isViewerInPresentationMode = false;
6149
6150 this.eventBus._on("presentationmodechanged", evt => {
6151 this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
6152 });
6153
6154 this.eventBus._on("pagesinit", () => {
6155 this._isPagesLoaded = false;
6156
6157 this.eventBus._on("pagesloaded", evt => {
6158 this._isPagesLoaded = !!evt.pagesCount;
6159 }, {
6160 once: true
6161 });
6162 });
6163 }
6164
6165 initialize({
6166 fingerprint,
6167 resetHistory = false,
6168 updateUrl = false
6169 }) {
6170 if (!fingerprint || typeof fingerprint !== "string") {
6171 console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
6172 return;
6173 }
6174
6175 if (this._initialized) {
6176 this.reset();
6177 }
6178
6179 const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
6180 this._fingerprint = fingerprint;
6181 this._updateUrl = updateUrl === true;
6182 this._initialized = true;
6183
6184 this._bindEvents();
6185
6186 const state = window.history.state;
6187 this._popStateInProgress = false;
6188 this._blockHashChange = 0;
6189 this._currentHash = getCurrentHash();
6190 this._numPositionUpdates = 0;
6191 this._uid = this._maxUid = 0;
6192 this._destination = null;
6193 this._position = null;
6194
6195 if (!this._isValidState(state, true) || resetHistory) {
6196 const {
6197 hash,
6198 page,
6199 rotation
6200 } = this._parseCurrentHash(true);
6201
6202 if (!hash || reInitialized || resetHistory) {
6203 this._pushOrReplaceState(null, true);
6204
6205 return;
6206 }
6207
6208 this._pushOrReplaceState({
6209 hash,
6210 page,
6211 rotation
6212 }, true);
6213
6214 return;
6215 }
6216
6217 const destination = state.destination;
6218
6219 this._updateInternalState(destination, state.uid, true);
6220
6221 if (destination.rotation !== undefined) {
6222 this._initialRotation = destination.rotation;
6223 }
6224
6225 if (destination.dest) {
6226 this._initialBookmark = JSON.stringify(destination.dest);
6227 this._destination.page = null;
6228 } else if (destination.hash) {
6229 this._initialBookmark = destination.hash;
6230 } else if (destination.page) {
6231 this._initialBookmark = `page=${destination.page}`;
6232 }
6233 }
6234
6235 reset() {
6236 if (this._initialized) {
6237 this._pageHide();
6238
6239 this._initialized = false;
6240
6241 this._unbindEvents();
6242 }
6243
6244 if (this._updateViewareaTimeout) {
6245 clearTimeout(this._updateViewareaTimeout);
6246 this._updateViewareaTimeout = null;
6247 }
6248
6249 this._initialBookmark = null;
6250 this._initialRotation = null;
6251 }
6252
6253 push({
6254 namedDest = null,
6255 explicitDest,
6256 pageNumber
6257 }) {
6258 if (!this._initialized) {
6259 return;
6260 }
6261
6262 if (namedDest && typeof namedDest !== "string") {
6263 console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
6264 return;
6265 } else if (!Array.isArray(explicitDest)) {
6266 console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
6267 return;
6268 } else if (!this._isValidPage(pageNumber)) {
6269 if (pageNumber !== null || this._destination) {
6270 console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
6271 return;
6272 }
6273 }
6274
6275 const hash = namedDest || JSON.stringify(explicitDest);
6276
6277 if (!hash) {
6278 return;
6279 }
6280
6281 let forceReplace = false;
6282
6283 if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
6284 if (this._destination.page) {
6285 return;
6286 }
6287
6288 forceReplace = true;
6289 }
6290
6291 if (this._popStateInProgress && !forceReplace) {
6292 return;
6293 }
6294
6295 this._pushOrReplaceState({
6296 dest: explicitDest,
6297 hash,
6298 page: pageNumber,
6299 rotation: this.linkService.rotation
6300 }, forceReplace);
6301
6302 if (!this._popStateInProgress) {
6303 this._popStateInProgress = true;
6304 Promise.resolve().then(() => {
6305 this._popStateInProgress = false;
6306 });
6307 }
6308 }
6309
6310 pushPage(pageNumber) {
6311 if (!this._initialized) {
6312 return;
6313 }
6314
6315 if (!this._isValidPage(pageNumber)) {
6316 console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
6317 return;
6318 }
6319
6320 if (this._destination?.page === pageNumber) {
6321 return;
6322 }
6323
6324 if (this._popStateInProgress) {
6325 return;
6326 }
6327
6328 this._pushOrReplaceState({
6329 dest: null,
6330 hash: `page=${pageNumber}`,
6331 page: pageNumber,
6332 rotation: this.linkService.rotation
6333 });
6334
6335 if (!this._popStateInProgress) {
6336 this._popStateInProgress = true;
6337 Promise.resolve().then(() => {
6338 this._popStateInProgress = false;
6339 });
6340 }
6341 }
6342
6343 pushCurrentPosition() {
6344 if (!this._initialized || this._popStateInProgress) {
6345 return;
6346 }
6347
6348 this._tryPushCurrentPosition();
6349 }
6350
6351 back() {
6352 if (!this._initialized || this._popStateInProgress) {
6353 return;
6354 }
6355
6356 const state = window.history.state;
6357
6358 if (this._isValidState(state) && state.uid > 0) {
6359 window.history.back();
6360 }
6361 }
6362
6363 forward() {
6364 if (!this._initialized || this._popStateInProgress) {
6365 return;
6366 }
6367
6368 const state = window.history.state;
6369
6370 if (this._isValidState(state) && state.uid < this._maxUid) {
6371 window.history.forward();
6372 }
6373 }
6374
6375 get popStateInProgress() {
6376 return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
6377 }
6378
6379 get initialBookmark() {
6380 return this._initialized ? this._initialBookmark : null;
6381 }
6382
6383 get initialRotation() {
6384 return this._initialized ? this._initialRotation : null;
6385 }
6386
6387 _pushOrReplaceState(destination, forceReplace = false) {
6388 const shouldReplace = forceReplace || !this._destination;
6389 const newState = {
6390 fingerprint: this._fingerprint,
6391 uid: shouldReplace ? this._uid : this._uid + 1,
6392 destination
6393 };
6394
6395 this._updateInternalState(destination, newState.uid);
6396
6397 let newUrl;
6398
6399 if (this._updateUrl && destination?.hash) {
6400 const baseUrl = document.location.href.split("#")[0];
6401
6402 if (!baseUrl.startsWith("file://")) {
6403 newUrl = `${baseUrl}#${destination.hash}`;
6404 }
6405 }
6406
6407 if (shouldReplace) {
6408 window.history.replaceState(newState, "", newUrl);
6409 } else {
6410 window.history.pushState(newState, "", newUrl);
6411 }
6412 }
6413
6414 _tryPushCurrentPosition(temporary = false) {
6415 if (!this._position) {
6416 return;
6417 }
6418
6419 let position = this._position;
6420
6421 if (temporary) {
6422 position = Object.assign(Object.create(null), this._position);
6423 position.temporary = true;
6424 }
6425
6426 if (!this._destination) {
6427 this._pushOrReplaceState(position);
6428
6429 return;
6430 }
6431
6432 if (this._destination.temporary) {
6433 this._pushOrReplaceState(position, true);
6434
6435 return;
6436 }
6437
6438 if (this._destination.hash === position.hash) {
6439 return;
6440 }
6441
6442 if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
6443 return;
6444 }
6445
6446 let forceReplace = false;
6447
6448 if (this._destination.page >= position.first && this._destination.page <= position.page) {
6449 if (this._destination.dest !== undefined || !this._destination.first) {
6450 return;
6451 }
6452
6453 forceReplace = true;
6454 }
6455
6456 this._pushOrReplaceState(position, forceReplace);
6457 }
6458
6459 _isValidPage(val) {
6460 return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
6461 }
6462
6463 _isValidState(state, checkReload = false) {
6464 if (!state) {
6465 return false;
6466 }
6467
6468 if (state.fingerprint !== this._fingerprint) {
6469 if (checkReload) {
6470 if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
6471 return false;
6472 }
6473
6474 const [perfEntry] = performance.getEntriesByType("navigation");
6475
6476 if (perfEntry?.type !== "reload") {
6477 return false;
6478 }
6479 } else {
6480 return false;
6481 }
6482 }
6483
6484 if (!Number.isInteger(state.uid) || state.uid < 0) {
6485 return false;
6486 }
6487
6488 if (state.destination === null || typeof state.destination !== "object") {
6489 return false;
6490 }
6491
6492 return true;
6493 }
6494
6495 _updateInternalState(destination, uid, removeTemporary = false) {
6496 if (this._updateViewareaTimeout) {
6497 clearTimeout(this._updateViewareaTimeout);
6498 this._updateViewareaTimeout = null;
6499 }
6500
6501 if (removeTemporary && destination?.temporary) {
6502 delete destination.temporary;
6503 }
6504
6505 this._destination = destination;
6506 this._uid = uid;
6507 this._maxUid = Math.max(this._maxUid, uid);
6508 this._numPositionUpdates = 0;
6509 }
6510
6511 _parseCurrentHash(checkNameddest = false) {
6512 const hash = unescape(getCurrentHash()).substring(1);
6513 const params = (0, _ui_utils.parseQueryString)(hash);
6514 const nameddest = params.nameddest || "";
6515 let page = params.page | 0;
6516
6517 if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
6518 page = null;
6519 }
6520
6521 return {
6522 hash,
6523 page,
6524 rotation: this.linkService.rotation
6525 };
6526 }
6527
6528 _updateViewarea({
6529 location
6530 }) {
6531 if (this._updateViewareaTimeout) {
6532 clearTimeout(this._updateViewareaTimeout);
6533 this._updateViewareaTimeout = null;
6534 }
6535
6536 this._position = {
6537 hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
6538 page: this.linkService.page,
6539 first: location.pageNumber,
6540 rotation: location.rotation
6541 };
6542
6543 if (this._popStateInProgress) {
6544 return;
6545 }
6546
6547 if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
6548 this._numPositionUpdates++;
6549 }
6550
6551 if (UPDATE_VIEWAREA_TIMEOUT > 0) {
6552 this._updateViewareaTimeout = setTimeout(() => {
6553 if (!this._popStateInProgress) {
6554 this._tryPushCurrentPosition(true);
6555 }
6556
6557 this._updateViewareaTimeout = null;
6558 }, UPDATE_VIEWAREA_TIMEOUT);
6559 }
6560 }
6561
6562 _popState({
6563 state
6564 }) {
6565 const newHash = getCurrentHash(),
6566 hashChanged = this._currentHash !== newHash;
6567 this._currentHash = newHash;
6568
6569 if (!state) {
6570 this._uid++;
6571
6572 const {
6573 hash,
6574 page,
6575 rotation
6576 } = this._parseCurrentHash();
6577
6578 this._pushOrReplaceState({
6579 hash,
6580 page,
6581 rotation
6582 }, true);
6583
6584 return;
6585 }
6586
6587 if (!this._isValidState(state)) {
6588 return;
6589 }
6590
6591 this._popStateInProgress = true;
6592
6593 if (hashChanged) {
6594 this._blockHashChange++;
6595 (0, _ui_utils.waitOnEventOrTimeout)({
6596 target: window,
6597 name: "hashchange",
6598 delay: HASH_CHANGE_TIMEOUT
6599 }).then(() => {
6600 this._blockHashChange--;
6601 });
6602 }
6603
6604 const destination = state.destination;
6605
6606 this._updateInternalState(destination, state.uid, true);
6607
6608 if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
6609 this.linkService.rotation = destination.rotation;
6610 }
6611
6612 if (destination.dest) {
6613 this.linkService.goToDestination(destination.dest);
6614 } else if (destination.hash) {
6615 this.linkService.setHash(destination.hash);
6616 } else if (destination.page) {
6617 this.linkService.page = destination.page;
6618 }
6619
6620 Promise.resolve().then(() => {
6621 this._popStateInProgress = false;
6622 });
6623 }
6624
6625 _pageHide() {
6626 if (!this._destination || this._destination.temporary) {
6627 this._tryPushCurrentPosition();
6628 }
6629 }
6630
6631 _bindEvents() {
6632 if (this._boundEvents) {
6633 return;
6634 }
6635
6636 this._boundEvents = {
6637 updateViewarea: this._updateViewarea.bind(this),
6638 popState: this._popState.bind(this),
6639 pageHide: this._pageHide.bind(this)
6640 };
6641
6642 this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
6643
6644 window.addEventListener("popstate", this._boundEvents.popState);
6645 window.addEventListener("pagehide", this._boundEvents.pageHide);
6646 }
6647
6648 _unbindEvents() {
6649 if (!this._boundEvents) {
6650 return;
6651 }
6652
6653 this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
6654
6655 window.removeEventListener("popstate", this._boundEvents.popState);
6656 window.removeEventListener("pagehide", this._boundEvents.pageHide);
6657 this._boundEvents = null;
6658 }
6659
6660}
6661
6662exports.PDFHistory = PDFHistory;
6663
6664function isDestHashesEqual(destHash, pushHash) {
6665 if (typeof destHash !== "string" || typeof pushHash !== "string") {
6666 return false;
6667 }
6668
6669 if (destHash === pushHash) {
6670 return true;
6671 }
6672
6673 const {
6674 nameddest
6675 } = (0, _ui_utils.parseQueryString)(destHash);
6676
6677 if (nameddest === pushHash) {
6678 return true;
6679 }
6680
6681 return false;
6682}
6683
6684function isDestArraysEqual(firstDest, secondDest) {
6685 function isEntryEqual(first, second) {
6686 if (typeof first !== typeof second) {
6687 return false;
6688 }
6689
6690 if (Array.isArray(first) || Array.isArray(second)) {
6691 return false;
6692 }
6693
6694 if (first !== null && typeof first === "object" && second !== null) {
6695 if (Object.keys(first).length !== Object.keys(second).length) {
6696 return false;
6697 }
6698
6699 for (const key in first) {
6700 if (!isEntryEqual(first[key], second[key])) {
6701 return false;
6702 }
6703 }
6704
6705 return true;
6706 }
6707
6708 return first === second || Number.isNaN(first) && Number.isNaN(second);
6709 }
6710
6711 if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
6712 return false;
6713 }
6714
6715 if (firstDest.length !== secondDest.length) {
6716 return false;
6717 }
6718
6719 for (let i = 0, ii = firstDest.length; i < ii; i++) {
6720 if (!isEntryEqual(firstDest[i], secondDest[i])) {
6721 return false;
6722 }
6723 }
6724
6725 return true;
6726}
6727
6728/***/ }),
6729/* 18 */
6730/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
6731
6732
6733
6734Object.defineProperty(exports, "__esModule", ({
6735 value: true
6736}));
6737exports.PDFLayerViewer = void 0;
6738
6739var _base_tree_viewer = __webpack_require__(12);
6740
6741class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
6742 constructor(options) {
6743 super(options);
6744 this.l10n = options.l10n;
6745
6746 this.eventBus._on("resetlayers", this._resetLayers.bind(this));
6747
6748 this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
6749 }
6750
6751 reset() {
6752 super.reset();
6753 this._optionalContentConfig = null;
6754 }
6755
6756 _dispatchEvent(layersCount) {
6757 this.eventBus.dispatch("layersloaded", {
6758 source: this,
6759 layersCount
6760 });
6761 }
6762
6763 _bindLink(element, {
6764 groupId,
6765 input
6766 }) {
6767 const setVisibility = () => {
6768 this._optionalContentConfig.setVisibility(groupId, input.checked);
6769
6770 this.eventBus.dispatch("optionalcontentconfig", {
6771 source: this,
6772 promise: Promise.resolve(this._optionalContentConfig)
6773 });
6774 };
6775
6776 element.onclick = evt => {
6777 if (evt.target === input) {
6778 setVisibility();
6779 return true;
6780 } else if (evt.target !== element) {
6781 return true;
6782 }
6783
6784 input.checked = !input.checked;
6785 setVisibility();
6786 return false;
6787 };
6788 }
6789
6790 async _setNestedName(element, {
6791 name = null
6792 }) {
6793 if (typeof name === "string") {
6794 element.textContent = this._normalizeTextContent(name);
6795 return;
6796 }
6797
6798 element.textContent = await this.l10n.get("additional_layers");
6799 element.style.fontStyle = "italic";
6800 }
6801
6802 _addToggleButton(div, {
6803 name = null
6804 }) {
6805 super._addToggleButton(div, name === null);
6806 }
6807
6808 _toggleAllTreeItems() {
6809 if (!this._optionalContentConfig) {
6810 return;
6811 }
6812
6813 super._toggleAllTreeItems();
6814 }
6815
6816 render({
6817 optionalContentConfig,
6818 pdfDocument
6819 }) {
6820 if (this._optionalContentConfig) {
6821 this.reset();
6822 }
6823
6824 this._optionalContentConfig = optionalContentConfig || null;
6825 this._pdfDocument = pdfDocument || null;
6826 const groups = optionalContentConfig?.getOrder();
6827
6828 if (!groups) {
6829 this._dispatchEvent(0);
6830
6831 return;
6832 }
6833
6834 const fragment = document.createDocumentFragment(),
6835 queue = [{
6836 parent: fragment,
6837 groups
6838 }];
6839 let layersCount = 0,
6840 hasAnyNesting = false;
6841
6842 while (queue.length > 0) {
6843 const levelData = queue.shift();
6844
6845 for (const groupId of levelData.groups) {
6846 const div = document.createElement("div");
6847 div.className = "treeItem";
6848 const element = document.createElement("a");
6849 div.appendChild(element);
6850
6851 if (typeof groupId === "object") {
6852 hasAnyNesting = true;
6853
6854 this._addToggleButton(div, groupId);
6855
6856 this._setNestedName(element, groupId);
6857
6858 const itemsDiv = document.createElement("div");
6859 itemsDiv.className = "treeItems";
6860 div.appendChild(itemsDiv);
6861 queue.push({
6862 parent: itemsDiv,
6863 groups: groupId.order
6864 });
6865 } else {
6866 const group = optionalContentConfig.getGroup(groupId);
6867 const input = document.createElement("input");
6868
6869 this._bindLink(element, {
6870 groupId,
6871 input
6872 });
6873
6874 input.type = "checkbox";
6875 input.id = groupId;
6876 input.checked = group.visible;
6877 const label = document.createElement("label");
6878 label.setAttribute("for", groupId);
6879 label.textContent = this._normalizeTextContent(group.name);
6880 element.appendChild(input);
6881 element.appendChild(label);
6882 layersCount++;
6883 }
6884
6885 levelData.parent.appendChild(div);
6886 }
6887 }
6888
6889 this._finishRendering(fragment, layersCount, hasAnyNesting);
6890 }
6891
6892 async _resetLayers() {
6893 if (!this._optionalContentConfig) {
6894 return;
6895 }
6896
6897 const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
6898 this.eventBus.dispatch("optionalcontentconfig", {
6899 source: this,
6900 promise: Promise.resolve(optionalContentConfig)
6901 });
6902 this.render({
6903 optionalContentConfig,
6904 pdfDocument: this._pdfDocument
6905 });
6906 }
6907
6908}
6909
6910exports.PDFLayerViewer = PDFLayerViewer;
6911
6912/***/ }),
6913/* 19 */
6914/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
6915
6916
6917
6918Object.defineProperty(exports, "__esModule", ({
6919 value: true
6920}));
6921exports.SimpleLinkService = exports.PDFLinkService = void 0;
6922
6923var _ui_utils = __webpack_require__(4);
6924
6925class PDFLinkService {
6926 constructor({
6927 eventBus,
6928 externalLinkTarget = null,
6929 externalLinkRel = null,
6930 externalLinkEnabled = true,
6931 ignoreDestinationZoom = false
6932 } = {}) {
6933 this.eventBus = eventBus;
6934 this.externalLinkTarget = externalLinkTarget;
6935 this.externalLinkRel = externalLinkRel;
6936 this.externalLinkEnabled = externalLinkEnabled;
6937 this._ignoreDestinationZoom = ignoreDestinationZoom;
6938 this.baseUrl = null;
6939 this.pdfDocument = null;
6940 this.pdfViewer = null;
6941 this.pdfHistory = null;
6942 this._pagesRefCache = null;
6943 }
6944
6945 setDocument(pdfDocument, baseUrl = null) {
6946 this.baseUrl = baseUrl;
6947 this.pdfDocument = pdfDocument;
6948 this._pagesRefCache = Object.create(null);
6949 }
6950
6951 setViewer(pdfViewer) {
6952 this.pdfViewer = pdfViewer;
6953 }
6954
6955 setHistory(pdfHistory) {
6956 this.pdfHistory = pdfHistory;
6957 }
6958
6959 get pagesCount() {
6960 return this.pdfDocument ? this.pdfDocument.numPages : 0;
6961 }
6962
6963 get page() {
6964 return this.pdfViewer.currentPageNumber;
6965 }
6966
6967 set page(value) {
6968 this.pdfViewer.currentPageNumber = value;
6969 }
6970
6971 get rotation() {
6972 return this.pdfViewer.pagesRotation;
6973 }
6974
6975 set rotation(value) {
6976 this.pdfViewer.pagesRotation = value;
6977 }
6978
6979 navigateTo(dest) {
6980 console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
6981 this.goToDestination(dest);
6982 }
6983
6984 _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
6985 const destRef = explicitDest[0];
6986 let pageNumber;
6987
6988 if (destRef instanceof Object) {
6989 pageNumber = this._cachedPageNumber(destRef);
6990
6991 if (pageNumber === null) {
6992 this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
6993 this.cachePageRef(pageIndex + 1, destRef);
6994
6995 this._goToDestinationHelper(rawDest, namedDest, explicitDest);
6996 }).catch(() => {
6997 console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
6998 });
6999 return;
7000 }
7001 } else if (Number.isInteger(destRef)) {
7002 pageNumber = destRef + 1;
7003 } else {
7004 console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
7005 return;
7006 }
7007
7008 if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
7009 console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
7010 return;
7011 }
7012
7013 if (this.pdfHistory) {
7014 this.pdfHistory.pushCurrentPosition();
7015 this.pdfHistory.push({
7016 namedDest,
7017 explicitDest,
7018 pageNumber
7019 });
7020 }
7021
7022 this.pdfViewer.scrollPageIntoView({
7023 pageNumber,
7024 destArray: explicitDest,
7025 ignoreDestinationZoom: this._ignoreDestinationZoom
7026 });
7027 }
7028
7029 async goToDestination(dest) {
7030 if (!this.pdfDocument) {
7031 return;
7032 }
7033
7034 let namedDest, explicitDest;
7035
7036 if (typeof dest === "string") {
7037 namedDest = dest;
7038 explicitDest = await this.pdfDocument.getDestination(dest);
7039 } else {
7040 namedDest = null;
7041 explicitDest = await dest;
7042 }
7043
7044 if (!Array.isArray(explicitDest)) {
7045 console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
7046 return;
7047 }
7048
7049 this._goToDestinationHelper(dest, namedDest, explicitDest);
7050 }
7051
7052 goToPage(val) {
7053 if (!this.pdfDocument) {
7054 return;
7055 }
7056
7057 const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
7058
7059 if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
7060 console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
7061 return;
7062 }
7063
7064 if (this.pdfHistory) {
7065 this.pdfHistory.pushCurrentPosition();
7066 this.pdfHistory.pushPage(pageNumber);
7067 }
7068
7069 this.pdfViewer.scrollPageIntoView({
7070 pageNumber
7071 });
7072 }
7073
7074 getDestinationHash(dest) {
7075 if (typeof dest === "string") {
7076 if (dest.length > 0) {
7077 return this.getAnchorUrl("#" + escape(dest));
7078 }
7079 } else if (Array.isArray(dest)) {
7080 const str = JSON.stringify(dest);
7081
7082 if (str.length > 0) {
7083 return this.getAnchorUrl("#" + escape(str));
7084 }
7085 }
7086
7087 return this.getAnchorUrl("");
7088 }
7089
7090 getAnchorUrl(anchor) {
7091 return (this.baseUrl || "") + anchor;
7092 }
7093
7094 setHash(hash) {
7095 if (!this.pdfDocument) {
7096 return;
7097 }
7098
7099 let pageNumber, dest;
7100
7101 if (hash.includes("=")) {
7102 const params = (0, _ui_utils.parseQueryString)(hash);
7103
7104 if ("search" in params) {
7105 this.eventBus.dispatch("findfromurlhash", {
7106 source: this,
7107 query: params.search.replace(/"/g, ""),
7108 phraseSearch: params.phrase === "true"
7109 });
7110 }
7111
7112 if ("page" in params) {
7113 pageNumber = params.page | 0 || 1;
7114 }
7115
7116 if ("zoom" in params) {
7117 const zoomArgs = params.zoom.split(",");
7118 const zoomArg = zoomArgs[0];
7119 const zoomArgNumber = parseFloat(zoomArg);
7120
7121 if (!zoomArg.includes("Fit")) {
7122 dest = [null, {
7123 name: "XYZ"
7124 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
7125 } else {
7126 if (zoomArg === "Fit" || zoomArg === "FitB") {
7127 dest = [null, {
7128 name: zoomArg
7129 }];
7130 } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
7131 dest = [null, {
7132 name: zoomArg
7133 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
7134 } else if (zoomArg === "FitR") {
7135 if (zoomArgs.length !== 5) {
7136 console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
7137 } else {
7138 dest = [null, {
7139 name: zoomArg
7140 }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
7141 }
7142 } else {
7143 console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
7144 }
7145 }
7146 }
7147
7148 if (dest) {
7149 this.pdfViewer.scrollPageIntoView({
7150 pageNumber: pageNumber || this.page,
7151 destArray: dest,
7152 allowNegativeOffset: true
7153 });
7154 } else if (pageNumber) {
7155 this.page = pageNumber;
7156 }
7157
7158 if ("pagemode" in params) {
7159 this.eventBus.dispatch("pagemode", {
7160 source: this,
7161 mode: params.pagemode
7162 });
7163 }
7164
7165 if ("nameddest" in params) {
7166 this.goToDestination(params.nameddest);
7167 }
7168 } else {
7169 dest = unescape(hash);
7170
7171 try {
7172 dest = JSON.parse(dest);
7173
7174 if (!Array.isArray(dest)) {
7175 dest = dest.toString();
7176 }
7177 } catch (ex) {}
7178
7179 if (typeof dest === "string" || isValidExplicitDestination(dest)) {
7180 this.goToDestination(dest);
7181 return;
7182 }
7183
7184 console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
7185 }
7186 }
7187
7188 executeNamedAction(action) {
7189 switch (action) {
7190 case "GoBack":
7191 if (this.pdfHistory) {
7192 this.pdfHistory.back();
7193 }
7194
7195 break;
7196
7197 case "GoForward":
7198 if (this.pdfHistory) {
7199 this.pdfHistory.forward();
7200 }
7201
7202 break;
7203
7204 case "NextPage":
7205 this.pdfViewer.nextPage();
7206 break;
7207
7208 case "PrevPage":
7209 this.pdfViewer.previousPage();
7210 break;
7211
7212 case "LastPage":
7213 this.page = this.pagesCount;
7214 break;
7215
7216 case "FirstPage":
7217 this.page = 1;
7218 break;
7219
7220 default:
7221 break;
7222 }
7223
7224 this.eventBus.dispatch("namedaction", {
7225 source: this,
7226 action
7227 });
7228 }
7229
7230 cachePageRef(pageNum, pageRef) {
7231 if (!pageRef) {
7232 return;
7233 }
7234
7235 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
7236 this._pagesRefCache[refStr] = pageNum;
7237 }
7238
7239 _cachedPageNumber(pageRef) {
7240 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
7241 return this._pagesRefCache?.[refStr] || null;
7242 }
7243
7244 isPageVisible(pageNumber) {
7245 return this.pdfViewer.isPageVisible(pageNumber);
7246 }
7247
7248 isPageCached(pageNumber) {
7249 return this.pdfViewer.isPageCached(pageNumber);
7250 }
7251
7252}
7253
7254exports.PDFLinkService = PDFLinkService;
7255
7256function isValidExplicitDestination(dest) {
7257 if (!Array.isArray(dest)) {
7258 return false;
7259 }
7260
7261 const destLength = dest.length;
7262
7263 if (destLength < 2) {
7264 return false;
7265 }
7266
7267 const page = dest[0];
7268
7269 if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
7270 return false;
7271 }
7272
7273 const zoom = dest[1];
7274
7275 if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
7276 return false;
7277 }
7278
7279 let allowNull = true;
7280
7281 switch (zoom.name) {
7282 case "XYZ":
7283 if (destLength !== 5) {
7284 return false;
7285 }
7286
7287 break;
7288
7289 case "Fit":
7290 case "FitB":
7291 return destLength === 2;
7292
7293 case "FitH":
7294 case "FitBH":
7295 case "FitV":
7296 case "FitBV":
7297 if (destLength !== 3) {
7298 return false;
7299 }
7300
7301 break;
7302
7303 case "FitR":
7304 if (destLength !== 6) {
7305 return false;
7306 }
7307
7308 allowNull = false;
7309 break;
7310
7311 default:
7312 return false;
7313 }
7314
7315 for (let i = 2; i < destLength; i++) {
7316 const param = dest[i];
7317
7318 if (!(typeof param === "number" || allowNull && param === null)) {
7319 return false;
7320 }
7321 }
7322
7323 return true;
7324}
7325
7326class SimpleLinkService {
7327 constructor() {
7328 this.externalLinkTarget = null;
7329 this.externalLinkRel = null;
7330 this.externalLinkEnabled = true;
7331 this._ignoreDestinationZoom = false;
7332 }
7333
7334 get pagesCount() {
7335 return 0;
7336 }
7337
7338 get page() {
7339 return 0;
7340 }
7341
7342 set page(value) {}
7343
7344 get rotation() {
7345 return 0;
7346 }
7347
7348 set rotation(value) {}
7349
7350 async goToDestination(dest) {}
7351
7352 goToPage(val) {}
7353
7354 getDestinationHash(dest) {
7355 return "#";
7356 }
7357
7358 getAnchorUrl(hash) {
7359 return "#";
7360 }
7361
7362 setHash(hash) {}
7363
7364 executeNamedAction(action) {}
7365
7366 cachePageRef(pageNum, pageRef) {}
7367
7368 isPageVisible(pageNumber) {
7369 return true;
7370 }
7371
7372 isPageCached(pageNumber) {
7373 return true;
7374 }
7375
7376}
7377
7378exports.SimpleLinkService = SimpleLinkService;
7379
7380/***/ }),
7381/* 20 */
7382/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
7383
7384
7385
7386Object.defineProperty(exports, "__esModule", ({
7387 value: true
7388}));
7389exports.PDFOutlineViewer = void 0;
7390
7391var _pdfjsLib = __webpack_require__(5);
7392
7393var _base_tree_viewer = __webpack_require__(12);
7394
7395var _ui_utils = __webpack_require__(4);
7396
7397class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
7398 constructor(options) {
7399 super(options);
7400 this.linkService = options.linkService;
7401
7402 this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
7403
7404 this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
7405
7406 this.eventBus._on("pagechanging", evt => {
7407 this._currentPageNumber = evt.pageNumber;
7408 });
7409
7410 this.eventBus._on("pagesloaded", evt => {
7411 this._isPagesLoaded = !!evt.pagesCount;
7412 });
7413
7414 this.eventBus._on("sidebarviewchanged", evt => {
7415 this._sidebarView = evt.view;
7416 });
7417 }
7418
7419 reset() {
7420 super.reset();
7421 this._outline = null;
7422 this._pageNumberToDestHashCapability = null;
7423 this._currentPageNumber = 1;
7424 this._isPagesLoaded = false;
7425 }
7426
7427 _dispatchEvent(outlineCount) {
7428 this.eventBus.dispatch("outlineloaded", {
7429 source: this,
7430 outlineCount,
7431 enableCurrentOutlineItemButton: outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch
7432 });
7433 }
7434
7435 _bindLink(element, {
7436 url,
7437 newWindow,
7438 dest
7439 }) {
7440 const {
7441 linkService
7442 } = this;
7443
7444 if (url) {
7445 (0, _pdfjsLib.addLinkAttributes)(element, {
7446 url,
7447 target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
7448 rel: linkService.externalLinkRel,
7449 enabled: linkService.externalLinkEnabled
7450 });
7451 return;
7452 }
7453
7454 element.href = linkService.getDestinationHash(dest);
7455
7456 element.onclick = evt => {
7457 this._updateCurrentTreeItem(evt.target.parentNode);
7458
7459 if (dest) {
7460 linkService.goToDestination(dest);
7461 }
7462
7463 return false;
7464 };
7465 }
7466
7467 _setStyles(element, {
7468 bold,
7469 italic
7470 }) {
7471 if (bold) {
7472 element.style.fontWeight = "bold";
7473 }
7474
7475 if (italic) {
7476 element.style.fontStyle = "italic";
7477 }
7478 }
7479
7480 _addToggleButton(div, {
7481 count,
7482 items
7483 }) {
7484 let hidden = false;
7485
7486 if (count < 0) {
7487 let totalCount = items.length;
7488
7489 if (totalCount > 0) {
7490 const queue = [...items];
7491
7492 while (queue.length > 0) {
7493 const {
7494 count: nestedCount,
7495 items: nestedItems
7496 } = queue.shift();
7497
7498 if (nestedCount > 0 && nestedItems.length > 0) {
7499 totalCount += nestedItems.length;
7500 queue.push(...nestedItems);
7501 }
7502 }
7503 }
7504
7505 if (Math.abs(count) === totalCount) {
7506 hidden = true;
7507 }
7508 }
7509
7510 super._addToggleButton(div, hidden);
7511 }
7512
7513 _toggleAllTreeItems() {
7514 if (!this._outline) {
7515 return;
7516 }
7517
7518 super._toggleAllTreeItems();
7519 }
7520
7521 render({
7522 outline,
7523 pdfDocument
7524 }) {
7525 if (this._outline) {
7526 this.reset();
7527 }
7528
7529 this._outline = outline || null;
7530 this._pdfDocument = pdfDocument || null;
7531
7532 if (!outline) {
7533 this._dispatchEvent(0);
7534
7535 return;
7536 }
7537
7538 const fragment = document.createDocumentFragment();
7539 const queue = [{
7540 parent: fragment,
7541 items: outline
7542 }];
7543 let outlineCount = 0,
7544 hasAnyNesting = false;
7545
7546 while (queue.length > 0) {
7547 const levelData = queue.shift();
7548
7549 for (const item of levelData.items) {
7550 const div = document.createElement("div");
7551 div.className = "treeItem";
7552 const element = document.createElement("a");
7553
7554 this._bindLink(element, item);
7555
7556 this._setStyles(element, item);
7557
7558 element.textContent = this._normalizeTextContent(item.title);
7559 div.appendChild(element);
7560
7561 if (item.items.length > 0) {
7562 hasAnyNesting = true;
7563
7564 this._addToggleButton(div, item);
7565
7566 const itemsDiv = document.createElement("div");
7567 itemsDiv.className = "treeItems";
7568 div.appendChild(itemsDiv);
7569 queue.push({
7570 parent: itemsDiv,
7571 items: item.items
7572 });
7573 }
7574
7575 levelData.parent.appendChild(div);
7576 outlineCount++;
7577 }
7578 }
7579
7580 this._finishRendering(fragment, outlineCount, hasAnyNesting);
7581 }
7582
7583 async _currentOutlineItem() {
7584 if (!this._isPagesLoaded) {
7585 throw new Error("_currentOutlineItem: All pages have not been loaded.");
7586 }
7587
7588 if (!this._outline || !this._pdfDocument) {
7589 return;
7590 }
7591
7592 const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
7593
7594 if (!pageNumberToDestHash) {
7595 return;
7596 }
7597
7598 this._updateCurrentTreeItem(null);
7599
7600 if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
7601 return;
7602 }
7603
7604 for (let i = this._currentPageNumber; i > 0; i--) {
7605 const destHash = pageNumberToDestHash.get(i);
7606
7607 if (!destHash) {
7608 continue;
7609 }
7610
7611 const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
7612
7613 if (!linkElement) {
7614 continue;
7615 }
7616
7617 this._scrollToCurrentTreeItem(linkElement.parentNode);
7618
7619 break;
7620 }
7621 }
7622
7623 async _getPageNumberToDestHash(pdfDocument) {
7624 if (this._pageNumberToDestHashCapability) {
7625 return this._pageNumberToDestHashCapability.promise;
7626 }
7627
7628 this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
7629 const pageNumberToDestHash = new Map(),
7630 pageNumberNesting = new Map();
7631 const queue = [{
7632 nesting: 0,
7633 items: this._outline
7634 }];
7635
7636 while (queue.length > 0) {
7637 const levelData = queue.shift(),
7638 currentNesting = levelData.nesting;
7639
7640 for (const {
7641 dest,
7642 items
7643 } of levelData.items) {
7644 let explicitDest, pageNumber;
7645
7646 if (typeof dest === "string") {
7647 explicitDest = await pdfDocument.getDestination(dest);
7648
7649 if (pdfDocument !== this._pdfDocument) {
7650 return null;
7651 }
7652 } else {
7653 explicitDest = dest;
7654 }
7655
7656 if (Array.isArray(explicitDest)) {
7657 const [destRef] = explicitDest;
7658
7659 if (destRef instanceof Object) {
7660 pageNumber = this.linkService._cachedPageNumber(destRef);
7661
7662 if (!pageNumber) {
7663 try {
7664 pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
7665
7666 if (pdfDocument !== this._pdfDocument) {
7667 return null;
7668 }
7669
7670 this.linkService.cachePageRef(pageNumber, destRef);
7671 } catch (ex) {}
7672 }
7673 } else if (Number.isInteger(destRef)) {
7674 pageNumber = destRef + 1;
7675 }
7676
7677 if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
7678 const destHash = this.linkService.getDestinationHash(dest);
7679 pageNumberToDestHash.set(pageNumber, destHash);
7680 pageNumberNesting.set(pageNumber, currentNesting);
7681 }
7682 }
7683
7684 if (items.length > 0) {
7685 queue.push({
7686 nesting: currentNesting + 1,
7687 items
7688 });
7689 }
7690 }
7691 }
7692
7693 this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
7694
7695 return this._pageNumberToDestHashCapability.promise;
7696 }
7697
7698}
7699
7700exports.PDFOutlineViewer = PDFOutlineViewer;
7701
7702/***/ }),
7703/* 21 */
7704/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
7705
7706
7707
7708Object.defineProperty(exports, "__esModule", ({
7709 value: true
7710}));
7711exports.PDFPresentationMode = void 0;
7712
7713var _ui_utils = __webpack_require__(4);
7714
7715const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
7716const DELAY_BEFORE_HIDING_CONTROLS = 3000;
7717const ACTIVE_SELECTOR = "pdfPresentationMode";
7718const CONTROLS_SELECTOR = "pdfPresentationModeControls";
7719const MOUSE_SCROLL_COOLDOWN_TIME = 50;
7720const PAGE_SWITCH_THRESHOLD = 0.1;
7721const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
7722const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
7723
7724class PDFPresentationMode {
7725 constructor({
7726 container,
7727 pdfViewer,
7728 eventBus
7729 }) {
7730 this.container = container;
7731 this.pdfViewer = pdfViewer;
7732 this.eventBus = eventBus;
7733 this.active = false;
7734 this.args = null;
7735 this.contextMenuOpen = false;
7736 this.mouseScrollTimeStamp = 0;
7737 this.mouseScrollDelta = 0;
7738 this.touchSwipeState = null;
7739 }
7740
7741 request() {
7742 if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
7743 return false;
7744 }
7745
7746 this._addFullscreenChangeListeners();
7747
7748 this._setSwitchInProgress();
7749
7750 this._notifyStateChange();
7751
7752 if (this.container.requestFullscreen) {
7753 this.container.requestFullscreen();
7754 } else if (this.container.mozRequestFullScreen) {
7755 this.container.mozRequestFullScreen();
7756 } else if (this.container.webkitRequestFullscreen) {
7757 this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
7758 } else {
7759 return false;
7760 }
7761
7762 this.args = {
7763 page: this.pdfViewer.currentPageNumber,
7764 previousScale: this.pdfViewer.currentScaleValue
7765 };
7766 return true;
7767 }
7768
7769 _mouseWheel(evt) {
7770 if (!this.active) {
7771 return;
7772 }
7773
7774 evt.preventDefault();
7775 const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
7776 const currentTime = Date.now();
7777 const storedTime = this.mouseScrollTimeStamp;
7778
7779 if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
7780 return;
7781 }
7782
7783 if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
7784 this._resetMouseScrollState();
7785 }
7786
7787 this.mouseScrollDelta += delta;
7788
7789 if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
7790 const totalDelta = this.mouseScrollDelta;
7791
7792 this._resetMouseScrollState();
7793
7794 const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
7795
7796 if (success) {
7797 this.mouseScrollTimeStamp = currentTime;
7798 }
7799 }
7800 }
7801
7802 get isFullscreen() {
7803 return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
7804 }
7805
7806 _notifyStateChange() {
7807 let state = _ui_utils.PresentationModeState.NORMAL;
7808
7809 if (this.switchInProgress) {
7810 state = _ui_utils.PresentationModeState.CHANGING;
7811 } else if (this.active) {
7812 state = _ui_utils.PresentationModeState.FULLSCREEN;
7813 }
7814
7815 this.eventBus.dispatch("presentationmodechanged", {
7816 source: this,
7817 state,
7818
7819 get active() {
7820 throw new Error("Deprecated parameter: `active`, please use `state` instead.");
7821 },
7822
7823 get switchInProgress() {
7824 throw new Error("Deprecated parameter: `switchInProgress`, please use `state` instead.");
7825 }
7826
7827 });
7828 }
7829
7830 _setSwitchInProgress() {
7831 if (this.switchInProgress) {
7832 clearTimeout(this.switchInProgress);
7833 }
7834
7835 this.switchInProgress = setTimeout(() => {
7836 this._removeFullscreenChangeListeners();
7837
7838 delete this.switchInProgress;
7839
7840 this._notifyStateChange();
7841 }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
7842 }
7843
7844 _resetSwitchInProgress() {
7845 if (this.switchInProgress) {
7846 clearTimeout(this.switchInProgress);
7847 delete this.switchInProgress;
7848 }
7849 }
7850
7851 _enter() {
7852 this.active = true;
7853
7854 this._resetSwitchInProgress();
7855
7856 this._notifyStateChange();
7857
7858 this.container.classList.add(ACTIVE_SELECTOR);
7859 setTimeout(() => {
7860 this.pdfViewer.currentPageNumber = this.args.page;
7861 this.pdfViewer.currentScaleValue = "page-fit";
7862 }, 0);
7863
7864 this._addWindowListeners();
7865
7866 this._showControls();
7867
7868 this.contextMenuOpen = false;
7869 window.getSelection().removeAllRanges();
7870 }
7871
7872 _exit() {
7873 const page = this.pdfViewer.currentPageNumber;
7874 this.container.classList.remove(ACTIVE_SELECTOR);
7875 setTimeout(() => {
7876 this.active = false;
7877
7878 this._removeFullscreenChangeListeners();
7879
7880 this._notifyStateChange();
7881
7882 this.pdfViewer.currentScaleValue = this.args.previousScale;
7883 this.pdfViewer.currentPageNumber = page;
7884 this.args = null;
7885 }, 0);
7886
7887 this._removeWindowListeners();
7888
7889 this._hideControls();
7890
7891 this._resetMouseScrollState();
7892
7893 this.contextMenuOpen = false;
7894 }
7895
7896 _mouseDown(evt) {
7897 if (this.contextMenuOpen) {
7898 this.contextMenuOpen = false;
7899 evt.preventDefault();
7900 return;
7901 }
7902
7903 if (evt.button === 0) {
7904 const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
7905
7906 if (!isInternalLink) {
7907 evt.preventDefault();
7908
7909 if (evt.shiftKey) {
7910 this.pdfViewer.previousPage();
7911 } else {
7912 this.pdfViewer.nextPage();
7913 }
7914 }
7915 }
7916 }
7917
7918 _contextMenu() {
7919 this.contextMenuOpen = true;
7920 }
7921
7922 _showControls() {
7923 if (this.controlsTimeout) {
7924 clearTimeout(this.controlsTimeout);
7925 } else {
7926 this.container.classList.add(CONTROLS_SELECTOR);
7927 }
7928
7929 this.controlsTimeout = setTimeout(() => {
7930 this.container.classList.remove(CONTROLS_SELECTOR);
7931 delete this.controlsTimeout;
7932 }, DELAY_BEFORE_HIDING_CONTROLS);
7933 }
7934
7935 _hideControls() {
7936 if (!this.controlsTimeout) {
7937 return;
7938 }
7939
7940 clearTimeout(this.controlsTimeout);
7941 this.container.classList.remove(CONTROLS_SELECTOR);
7942 delete this.controlsTimeout;
7943 }
7944
7945 _resetMouseScrollState() {
7946 this.mouseScrollTimeStamp = 0;
7947 this.mouseScrollDelta = 0;
7948 }
7949
7950 _touchSwipe(evt) {
7951 if (!this.active) {
7952 return;
7953 }
7954
7955 if (evt.touches.length > 1) {
7956 this.touchSwipeState = null;
7957 return;
7958 }
7959
7960 switch (evt.type) {
7961 case "touchstart":
7962 this.touchSwipeState = {
7963 startX: evt.touches[0].pageX,
7964 startY: evt.touches[0].pageY,
7965 endX: evt.touches[0].pageX,
7966 endY: evt.touches[0].pageY
7967 };
7968 break;
7969
7970 case "touchmove":
7971 if (this.touchSwipeState === null) {
7972 return;
7973 }
7974
7975 this.touchSwipeState.endX = evt.touches[0].pageX;
7976 this.touchSwipeState.endY = evt.touches[0].pageY;
7977 evt.preventDefault();
7978 break;
7979
7980 case "touchend":
7981 if (this.touchSwipeState === null) {
7982 return;
7983 }
7984
7985 let delta = 0;
7986 const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
7987 const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
7988 const absAngle = Math.abs(Math.atan2(dy, dx));
7989
7990 if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
7991 delta = dx;
7992 } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
7993 delta = dy;
7994 }
7995
7996 if (delta > 0) {
7997 this.pdfViewer.previousPage();
7998 } else if (delta < 0) {
7999 this.pdfViewer.nextPage();
8000 }
8001
8002 break;
8003 }
8004 }
8005
8006 _addWindowListeners() {
8007 this.showControlsBind = this._showControls.bind(this);
8008 this.mouseDownBind = this._mouseDown.bind(this);
8009 this.mouseWheelBind = this._mouseWheel.bind(this);
8010 this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
8011 this.contextMenuBind = this._contextMenu.bind(this);
8012 this.touchSwipeBind = this._touchSwipe.bind(this);
8013 window.addEventListener("mousemove", this.showControlsBind);
8014 window.addEventListener("mousedown", this.mouseDownBind);
8015 window.addEventListener("wheel", this.mouseWheelBind, {
8016 passive: false
8017 });
8018 window.addEventListener("keydown", this.resetMouseScrollStateBind);
8019 window.addEventListener("contextmenu", this.contextMenuBind);
8020 window.addEventListener("touchstart", this.touchSwipeBind);
8021 window.addEventListener("touchmove", this.touchSwipeBind);
8022 window.addEventListener("touchend", this.touchSwipeBind);
8023 }
8024
8025 _removeWindowListeners() {
8026 window.removeEventListener("mousemove", this.showControlsBind);
8027 window.removeEventListener("mousedown", this.mouseDownBind);
8028 window.removeEventListener("wheel", this.mouseWheelBind, {
8029 passive: false
8030 });
8031 window.removeEventListener("keydown", this.resetMouseScrollStateBind);
8032 window.removeEventListener("contextmenu", this.contextMenuBind);
8033 window.removeEventListener("touchstart", this.touchSwipeBind);
8034 window.removeEventListener("touchmove", this.touchSwipeBind);
8035 window.removeEventListener("touchend", this.touchSwipeBind);
8036 delete this.showControlsBind;
8037 delete this.mouseDownBind;
8038 delete this.mouseWheelBind;
8039 delete this.resetMouseScrollStateBind;
8040 delete this.contextMenuBind;
8041 delete this.touchSwipeBind;
8042 }
8043
8044 _fullscreenChange() {
8045 if (this.isFullscreen) {
8046 this._enter();
8047 } else {
8048 this._exit();
8049 }
8050 }
8051
8052 _addFullscreenChangeListeners() {
8053 this.fullscreenChangeBind = this._fullscreenChange.bind(this);
8054 window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
8055 window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
8056 window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
8057 }
8058
8059 _removeFullscreenChangeListeners() {
8060 window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
8061 window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
8062 window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
8063 delete this.fullscreenChangeBind;
8064 }
8065
8066}
8067
8068exports.PDFPresentationMode = PDFPresentationMode;
8069
8070/***/ }),
8071/* 22 */
8072/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
8073
8074
8075
8076Object.defineProperty(exports, "__esModule", ({
8077 value: true
8078}));
8079exports.PDFScriptingManager = void 0;
8080
8081var _pdfjsLib = __webpack_require__(5);
8082
8083var _ui_utils = __webpack_require__(4);
8084
8085var _pdf_rendering_queue = __webpack_require__(8);
8086
8087class PDFScriptingManager {
8088 constructor({
8089 eventBus,
8090 sandboxBundleSrc = null,
8091 scriptingFactory = null,
8092 docPropertiesLookup = null
8093 }) {
8094 this._pdfDocument = null;
8095 this._pdfViewer = null;
8096 this._closeCapability = null;
8097 this._destroyCapability = null;
8098 this._scripting = null;
8099 this._mouseState = Object.create(null);
8100 this._pageEventsReady = false;
8101 this._ready = false;
8102 this._eventBus = eventBus;
8103 this._sandboxBundleSrc = sandboxBundleSrc;
8104 this._scriptingFactory = scriptingFactory;
8105 this._docPropertiesLookup = docPropertiesLookup;
8106 }
8107
8108 setViewer(pdfViewer) {
8109 this._pdfViewer = pdfViewer;
8110 }
8111
8112 async setDocument(pdfDocument) {
8113 if (this._pdfDocument) {
8114 await this._destroyScripting();
8115 }
8116
8117 this._pdfDocument = pdfDocument;
8118
8119 if (!pdfDocument) {
8120 return;
8121 }
8122
8123 const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
8124
8125 if (!objects && !docActions) {
8126 await this._destroyScripting();
8127 return;
8128 }
8129
8130 if (pdfDocument !== this._pdfDocument) {
8131 return;
8132 }
8133
8134 this._scripting = this._createScripting();
8135
8136 this._internalEvents.set("updatefromsandbox", event => {
8137 if (event?.source !== window) {
8138 return;
8139 }
8140
8141 this._updateFromSandbox(event.detail);
8142 });
8143
8144 this._internalEvents.set("dispatcheventinsandbox", event => {
8145 this._scripting?.dispatchEventInSandbox(event.detail);
8146 });
8147
8148 this._internalEvents.set("pagechanging", ({
8149 pageNumber,
8150 previous
8151 }) => {
8152 if (pageNumber === previous) {
8153 return;
8154 }
8155
8156 this._dispatchPageClose(previous);
8157
8158 this._dispatchPageOpen(pageNumber);
8159 });
8160
8161 this._internalEvents.set("pagerendered", ({
8162 pageNumber
8163 }) => {
8164 if (!this._pageOpenPending.has(pageNumber)) {
8165 return;
8166 }
8167
8168 if (pageNumber !== this._pdfViewer.currentPageNumber) {
8169 return;
8170 }
8171
8172 this._dispatchPageOpen(pageNumber);
8173 });
8174
8175 this._internalEvents.set("pagesdestroy", async event => {
8176 await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
8177 await this._scripting?.dispatchEventInSandbox({
8178 id: "doc",
8179 name: "WillClose"
8180 });
8181 this._closeCapability?.resolve();
8182 });
8183
8184 this._domEvents.set("mousedown", event => {
8185 this._mouseState.isDown = true;
8186 });
8187
8188 this._domEvents.set("mouseup", event => {
8189 this._mouseState.isDown = false;
8190 });
8191
8192 for (const [name, listener] of this._internalEvents) {
8193 this._eventBus._on(name, listener);
8194 }
8195
8196 for (const [name, listener] of this._domEvents) {
8197 window.addEventListener(name, listener);
8198 }
8199
8200 try {
8201 const docProperties = await this._getDocProperties();
8202
8203 if (pdfDocument !== this._pdfDocument) {
8204 return;
8205 }
8206
8207 await this._scripting.createSandbox({
8208 objects,
8209 calculationOrder,
8210 appInfo: {
8211 platform: navigator.platform,
8212 language: navigator.language
8213 },
8214 docInfo: { ...docProperties,
8215 actions: docActions
8216 }
8217 });
8218
8219 this._eventBus.dispatch("sandboxcreated", {
8220 source: this
8221 });
8222 } catch (error) {
8223 console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
8224 await this._destroyScripting();
8225 return;
8226 }
8227
8228 await this._scripting?.dispatchEventInSandbox({
8229 id: "doc",
8230 name: "Open"
8231 });
8232 await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
8233 Promise.resolve().then(() => {
8234 if (pdfDocument === this._pdfDocument) {
8235 this._ready = true;
8236 }
8237 });
8238 }
8239
8240 async dispatchWillSave(detail) {
8241 return this._scripting?.dispatchEventInSandbox({
8242 id: "doc",
8243 name: "WillSave"
8244 });
8245 }
8246
8247 async dispatchDidSave(detail) {
8248 return this._scripting?.dispatchEventInSandbox({
8249 id: "doc",
8250 name: "DidSave"
8251 });
8252 }
8253
8254 async dispatchWillPrint(detail) {
8255 return this._scripting?.dispatchEventInSandbox({
8256 id: "doc",
8257 name: "WillPrint"
8258 });
8259 }
8260
8261 async dispatchDidPrint(detail) {
8262 return this._scripting?.dispatchEventInSandbox({
8263 id: "doc",
8264 name: "DidPrint"
8265 });
8266 }
8267
8268 get mouseState() {
8269 return this._mouseState;
8270 }
8271
8272 get destroyPromise() {
8273 return this._destroyCapability?.promise || null;
8274 }
8275
8276 get ready() {
8277 return this._ready;
8278 }
8279
8280 get _internalEvents() {
8281 return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
8282 }
8283
8284 get _domEvents() {
8285 return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
8286 }
8287
8288 get _pageOpenPending() {
8289 return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
8290 }
8291
8292 get _visitedPages() {
8293 return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
8294 }
8295
8296 async _updateFromSandbox(detail) {
8297 const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
8298 const {
8299 id,
8300 command,
8301 value
8302 } = detail;
8303
8304 if (!id) {
8305 switch (command) {
8306 case "clear":
8307 console.clear();
8308 break;
8309
8310 case "error":
8311 console.error(value);
8312 break;
8313
8314 case "layout":
8315 this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
8316 break;
8317
8318 case "page-num":
8319 this._pdfViewer.currentPageNumber = value + 1;
8320 break;
8321
8322 case "print":
8323 await this._pdfViewer.pagesPromise;
8324
8325 this._eventBus.dispatch("print", {
8326 source: this
8327 });
8328
8329 break;
8330
8331 case "println":
8332 console.log(value);
8333 break;
8334
8335 case "zoom":
8336 if (isInPresentationMode) {
8337 return;
8338 }
8339
8340 this._pdfViewer.currentScaleValue = value;
8341 break;
8342 }
8343
8344 return;
8345 }
8346
8347 if (isInPresentationMode) {
8348 if (detail.focus) {
8349 return;
8350 }
8351 }
8352
8353 const element = document.getElementById(id);
8354
8355 if (element) {
8356 element.dispatchEvent(new CustomEvent("updatefromsandbox", {
8357 detail
8358 }));
8359 } else {
8360 delete detail.id;
8361 this._pdfDocument?.annotationStorage.setValue(id, detail);
8362 }
8363 }
8364
8365 async _dispatchPageOpen(pageNumber, initialize = false) {
8366 const pdfDocument = this._pdfDocument,
8367 visitedPages = this._visitedPages;
8368
8369 if (initialize) {
8370 this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
8371 this._pageEventsReady = true;
8372 }
8373
8374 if (!this._pageEventsReady) {
8375 return;
8376 }
8377
8378 const pageView = this._pdfViewer.getPageView(pageNumber - 1);
8379
8380 if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
8381 this._pageOpenPending.add(pageNumber);
8382
8383 return;
8384 }
8385
8386 this._pageOpenPending.delete(pageNumber);
8387
8388 const actionsPromise = (async () => {
8389 const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
8390
8391 if (pdfDocument !== this._pdfDocument) {
8392 return;
8393 }
8394
8395 await this._scripting?.dispatchEventInSandbox({
8396 id: "page",
8397 name: "PageOpen",
8398 pageNumber,
8399 actions
8400 });
8401 })();
8402
8403 visitedPages.set(pageNumber, actionsPromise);
8404 }
8405
8406 async _dispatchPageClose(pageNumber) {
8407 const pdfDocument = this._pdfDocument,
8408 visitedPages = this._visitedPages;
8409
8410 if (!this._pageEventsReady) {
8411 return;
8412 }
8413
8414 if (this._pageOpenPending.has(pageNumber)) {
8415 return;
8416 }
8417
8418 const actionsPromise = visitedPages.get(pageNumber);
8419
8420 if (!actionsPromise) {
8421 return;
8422 }
8423
8424 visitedPages.set(pageNumber, null);
8425 await actionsPromise;
8426
8427 if (pdfDocument !== this._pdfDocument) {
8428 return;
8429 }
8430
8431 await this._scripting?.dispatchEventInSandbox({
8432 id: "page",
8433 name: "PageClose",
8434 pageNumber
8435 });
8436 }
8437
8438 async _getDocProperties() {
8439 if (this._docPropertiesLookup) {
8440 return this._docPropertiesLookup(this._pdfDocument);
8441 }
8442
8443 throw new Error("_getDocProperties: Unable to lookup properties.");
8444 }
8445
8446 _createScripting() {
8447 this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
8448
8449 if (this._scripting) {
8450 throw new Error("_createScripting: Scripting already exists.");
8451 }
8452
8453 if (this._scriptingFactory) {
8454 return this._scriptingFactory.createScripting({
8455 sandboxBundleSrc: this._sandboxBundleSrc
8456 });
8457 }
8458
8459 throw new Error("_createScripting: Cannot create scripting.");
8460 }
8461
8462 async _destroyScripting() {
8463 if (!this._scripting) {
8464 this._pdfDocument = null;
8465 this._destroyCapability?.resolve();
8466 return;
8467 }
8468
8469 if (this._closeCapability) {
8470 await Promise.race([this._closeCapability.promise, new Promise(resolve => {
8471 setTimeout(resolve, 1000);
8472 })]).catch(reason => {});
8473 this._closeCapability = null;
8474 }
8475
8476 this._pdfDocument = null;
8477
8478 try {
8479 await this._scripting.destroySandbox();
8480 } catch (ex) {}
8481
8482 for (const [name, listener] of this._internalEvents) {
8483 this._eventBus._off(name, listener);
8484 }
8485
8486 this._internalEvents.clear();
8487
8488 for (const [name, listener] of this._domEvents) {
8489 window.removeEventListener(name, listener);
8490 }
8491
8492 this._domEvents.clear();
8493
8494 this._pageOpenPending.clear();
8495
8496 this._visitedPages.clear();
8497
8498 this._scripting = null;
8499 delete this._mouseState.isDown;
8500 this._pageEventsReady = false;
8501 this._ready = false;
8502 this._destroyCapability?.resolve();
8503 }
8504
8505}
8506
8507exports.PDFScriptingManager = PDFScriptingManager;
8508
8509/***/ }),
8510/* 23 */
8511/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
8512
8513
8514
8515Object.defineProperty(exports, "__esModule", ({
8516 value: true
8517}));
8518exports.PDFSidebar = void 0;
8519
8520var _ui_utils = __webpack_require__(4);
8521
8522var _pdf_rendering_queue = __webpack_require__(8);
8523
8524const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
8525
8526class PDFSidebar {
8527 constructor({
8528 elements,
8529 pdfViewer,
8530 pdfThumbnailViewer,
8531 eventBus,
8532 l10n
8533 }) {
8534 this.isOpen = false;
8535 this.active = _ui_utils.SidebarView.THUMBS;
8536 this.isInitialViewSet = false;
8537 this.onToggled = null;
8538 this.pdfViewer = pdfViewer;
8539 this.pdfThumbnailViewer = pdfThumbnailViewer;
8540 this.outerContainer = elements.outerContainer;
8541 this.viewerContainer = elements.viewerContainer;
8542 this.toggleButton = elements.toggleButton;
8543 this.thumbnailButton = elements.thumbnailButton;
8544 this.outlineButton = elements.outlineButton;
8545 this.attachmentsButton = elements.attachmentsButton;
8546 this.layersButton = elements.layersButton;
8547 this.thumbnailView = elements.thumbnailView;
8548 this.outlineView = elements.outlineView;
8549 this.attachmentsView = elements.attachmentsView;
8550 this.layersView = elements.layersView;
8551 this._outlineOptionsContainer = elements.outlineOptionsContainer;
8552 this._currentOutlineItemButton = elements.currentOutlineItemButton;
8553 this.eventBus = eventBus;
8554 this.l10n = l10n;
8555
8556 this._addEventListeners();
8557 }
8558
8559 reset() {
8560 this.isInitialViewSet = false;
8561
8562 this._hideUINotification(true);
8563
8564 this.switchView(_ui_utils.SidebarView.THUMBS);
8565 this.outlineButton.disabled = false;
8566 this.attachmentsButton.disabled = false;
8567 this.layersButton.disabled = false;
8568 this._currentOutlineItemButton.disabled = true;
8569 }
8570
8571 get visibleView() {
8572 return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
8573 }
8574
8575 get isThumbnailViewVisible() {
8576 return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
8577 }
8578
8579 get isOutlineViewVisible() {
8580 return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
8581 }
8582
8583 get isAttachmentsViewVisible() {
8584 return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
8585 }
8586
8587 get isLayersViewVisible() {
8588 return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
8589 }
8590
8591 setInitialView(view = _ui_utils.SidebarView.NONE) {
8592 if (this.isInitialViewSet) {
8593 return;
8594 }
8595
8596 this.isInitialViewSet = true;
8597
8598 if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
8599 this._dispatchEvent();
8600
8601 return;
8602 }
8603
8604 if (!this._switchView(view, true)) {
8605 this._dispatchEvent();
8606 }
8607 }
8608
8609 switchView(view, forceOpen = false) {
8610 this._switchView(view, forceOpen);
8611 }
8612
8613 _switchView(view, forceOpen = false) {
8614 const isViewChanged = view !== this.active;
8615 let shouldForceRendering = false;
8616
8617 switch (view) {
8618 case _ui_utils.SidebarView.NONE:
8619 if (this.isOpen) {
8620 this.close();
8621 return true;
8622 }
8623
8624 return false;
8625
8626 case _ui_utils.SidebarView.THUMBS:
8627 if (this.isOpen && isViewChanged) {
8628 shouldForceRendering = true;
8629 }
8630
8631 break;
8632
8633 case _ui_utils.SidebarView.OUTLINE:
8634 if (this.outlineButton.disabled) {
8635 return false;
8636 }
8637
8638 break;
8639
8640 case _ui_utils.SidebarView.ATTACHMENTS:
8641 if (this.attachmentsButton.disabled) {
8642 return false;
8643 }
8644
8645 break;
8646
8647 case _ui_utils.SidebarView.LAYERS:
8648 if (this.layersButton.disabled) {
8649 return false;
8650 }
8651
8652 break;
8653
8654 default:
8655 console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
8656 return false;
8657 }
8658
8659 this.active = view;
8660 this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
8661 this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
8662 this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
8663 this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
8664 this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
8665 this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
8666 this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
8667 this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
8668
8669 this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
8670
8671 if (forceOpen && !this.isOpen) {
8672 this.open();
8673 return true;
8674 }
8675
8676 if (shouldForceRendering) {
8677 this._updateThumbnailViewer();
8678
8679 this._forceRendering();
8680 }
8681
8682 if (isViewChanged) {
8683 this._dispatchEvent();
8684 }
8685
8686 return isViewChanged;
8687 }
8688
8689 open() {
8690 if (this.isOpen) {
8691 return;
8692 }
8693
8694 this.isOpen = true;
8695 this.toggleButton.classList.add("toggled");
8696 this.toggleButton.setAttribute("aria-expanded", "true");
8697 this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
8698
8699 if (this.active === _ui_utils.SidebarView.THUMBS) {
8700 this._updateThumbnailViewer();
8701 }
8702
8703 this._forceRendering();
8704
8705 this._dispatchEvent();
8706
8707 this._hideUINotification();
8708 }
8709
8710 close() {
8711 if (!this.isOpen) {
8712 return;
8713 }
8714
8715 this.isOpen = false;
8716 this.toggleButton.classList.remove("toggled");
8717 this.toggleButton.setAttribute("aria-expanded", "false");
8718 this.outerContainer.classList.add("sidebarMoving");
8719 this.outerContainer.classList.remove("sidebarOpen");
8720
8721 this._forceRendering();
8722
8723 this._dispatchEvent();
8724 }
8725
8726 toggle() {
8727 if (this.isOpen) {
8728 this.close();
8729 } else {
8730 this.open();
8731 }
8732 }
8733
8734 _dispatchEvent() {
8735 this.eventBus.dispatch("sidebarviewchanged", {
8736 source: this,
8737 view: this.visibleView
8738 });
8739 }
8740
8741 _forceRendering() {
8742 if (this.onToggled) {
8743 this.onToggled();
8744 } else {
8745 this.pdfViewer.forceRendering();
8746 this.pdfThumbnailViewer.forceRendering();
8747 }
8748 }
8749
8750 _updateThumbnailViewer() {
8751 const {
8752 pdfViewer,
8753 pdfThumbnailViewer
8754 } = this;
8755 const pagesCount = pdfViewer.pagesCount;
8756
8757 for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
8758 const pageView = pdfViewer.getPageView(pageIndex);
8759
8760 if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
8761 const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
8762 thumbnailView.setImage(pageView);
8763 }
8764 }
8765
8766 pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
8767 }
8768
8769 _showUINotification() {
8770 this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
8771 this.toggleButton.title = msg;
8772 });
8773
8774 if (!this.isOpen) {
8775 this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
8776 }
8777 }
8778
8779 _hideUINotification(reset = false) {
8780 if (this.isOpen || reset) {
8781 this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
8782 }
8783
8784 if (reset) {
8785 this.l10n.get("toggle_sidebar.title").then(msg => {
8786 this.toggleButton.title = msg;
8787 });
8788 }
8789 }
8790
8791 _addEventListeners() {
8792 this.viewerContainer.addEventListener("transitionend", evt => {
8793 if (evt.target === this.viewerContainer) {
8794 this.outerContainer.classList.remove("sidebarMoving");
8795 }
8796 });
8797 this.toggleButton.addEventListener("click", () => {
8798 this.toggle();
8799 });
8800 this.thumbnailButton.addEventListener("click", () => {
8801 this.switchView(_ui_utils.SidebarView.THUMBS);
8802 });
8803 this.outlineButton.addEventListener("click", () => {
8804 this.switchView(_ui_utils.SidebarView.OUTLINE);
8805 });
8806 this.outlineButton.addEventListener("dblclick", () => {
8807 this.eventBus.dispatch("toggleoutlinetree", {
8808 source: this
8809 });
8810 });
8811 this.attachmentsButton.addEventListener("click", () => {
8812 this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
8813 });
8814 this.layersButton.addEventListener("click", () => {
8815 this.switchView(_ui_utils.SidebarView.LAYERS);
8816 });
8817 this.layersButton.addEventListener("dblclick", () => {
8818 this.eventBus.dispatch("resetlayers", {
8819 source: this
8820 });
8821 });
8822
8823 this._currentOutlineItemButton.addEventListener("click", () => {
8824 this.eventBus.dispatch("currentoutlineitem", {
8825 source: this
8826 });
8827 });
8828
8829 const onTreeLoaded = (count, button, view) => {
8830 button.disabled = !count;
8831
8832 if (count) {
8833 this._showUINotification();
8834 } else if (this.active === view) {
8835 this.switchView(_ui_utils.SidebarView.THUMBS);
8836 }
8837 };
8838
8839 this.eventBus._on("outlineloaded", evt => {
8840 onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
8841
8842 if (evt.enableCurrentOutlineItemButton) {
8843 this.pdfViewer.pagesPromise.then(() => {
8844 this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
8845 });
8846 }
8847 });
8848
8849 this.eventBus._on("attachmentsloaded", evt => {
8850 onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
8851 });
8852
8853 this.eventBus._on("layersloaded", evt => {
8854 onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
8855 });
8856
8857 this.eventBus._on("presentationmodechanged", evt => {
8858 if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
8859 this._updateThumbnailViewer();
8860 }
8861 });
8862 }
8863
8864}
8865
8866exports.PDFSidebar = PDFSidebar;
8867
8868/***/ }),
8869/* 24 */
8870/***/ ((__unused_webpack_module, exports) => {
8871
8872
8873
8874Object.defineProperty(exports, "__esModule", ({
8875 value: true
8876}));
8877exports.PDFSidebarResizer = void 0;
8878const SIDEBAR_WIDTH_VAR = "--sidebar-width";
8879const SIDEBAR_MIN_WIDTH = 200;
8880const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
8881
8882class PDFSidebarResizer {
8883 constructor(options, eventBus, l10n) {
8884 this.isRTL = false;
8885 this.sidebarOpen = false;
8886 this.doc = document.documentElement;
8887 this._width = null;
8888 this._outerContainerWidth = null;
8889 this._boundEvents = Object.create(null);
8890 this.outerContainer = options.outerContainer;
8891 this.resizer = options.resizer;
8892 this.eventBus = eventBus;
8893 l10n.getDirection().then(dir => {
8894 this.isRTL = dir === "rtl";
8895 });
8896
8897 this._addEventListeners();
8898 }
8899
8900 get outerContainerWidth() {
8901 return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
8902 }
8903
8904 _updateWidth(width = 0) {
8905 const maxWidth = Math.floor(this.outerContainerWidth / 2);
8906
8907 if (width > maxWidth) {
8908 width = maxWidth;
8909 }
8910
8911 if (width < SIDEBAR_MIN_WIDTH) {
8912 width = SIDEBAR_MIN_WIDTH;
8913 }
8914
8915 if (width === this._width) {
8916 return false;
8917 }
8918
8919 this._width = width;
8920 this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
8921 return true;
8922 }
8923
8924 _mouseMove(evt) {
8925 let width = evt.clientX;
8926
8927 if (this.isRTL) {
8928 width = this.outerContainerWidth - width;
8929 }
8930
8931 this._updateWidth(width);
8932 }
8933
8934 _mouseUp(evt) {
8935 this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
8936 this.eventBus.dispatch("resize", {
8937 source: this
8938 });
8939 const _boundEvents = this._boundEvents;
8940 window.removeEventListener("mousemove", _boundEvents.mouseMove);
8941 window.removeEventListener("mouseup", _boundEvents.mouseUp);
8942 }
8943
8944 _addEventListeners() {
8945 const _boundEvents = this._boundEvents;
8946 _boundEvents.mouseMove = this._mouseMove.bind(this);
8947 _boundEvents.mouseUp = this._mouseUp.bind(this);
8948 this.resizer.addEventListener("mousedown", evt => {
8949 if (evt.button !== 0) {
8950 return;
8951 }
8952
8953 this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
8954 window.addEventListener("mousemove", _boundEvents.mouseMove);
8955 window.addEventListener("mouseup", _boundEvents.mouseUp);
8956 });
8957
8958 this.eventBus._on("sidebarviewchanged", evt => {
8959 this.sidebarOpen = !!evt?.view;
8960 });
8961
8962 this.eventBus._on("resize", evt => {
8963 if (evt?.source !== window) {
8964 return;
8965 }
8966
8967 this._outerContainerWidth = null;
8968
8969 if (!this._width) {
8970 return;
8971 }
8972
8973 if (!this.sidebarOpen) {
8974 this._updateWidth(this._width);
8975
8976 return;
8977 }
8978
8979 this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
8980
8981 const updated = this._updateWidth(this._width);
8982
8983 Promise.resolve().then(() => {
8984 this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
8985
8986 if (updated) {
8987 this.eventBus.dispatch("resize", {
8988 source: this
8989 });
8990 }
8991 });
8992 });
8993 }
8994
8995}
8996
8997exports.PDFSidebarResizer = PDFSidebarResizer;
8998
8999/***/ }),
9000/* 25 */
9001/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
9002
9003
9004
9005Object.defineProperty(exports, "__esModule", ({
9006 value: true
9007}));
9008exports.PDFThumbnailViewer = void 0;
9009
9010var _ui_utils = __webpack_require__(4);
9011
9012var _pdf_thumbnail_view = __webpack_require__(26);
9013
9014var _pdf_rendering_queue = __webpack_require__(8);
9015
9016const THUMBNAIL_SCROLL_MARGIN = -19;
9017const THUMBNAIL_SELECTED_CLASS = "selected";
9018
9019class PDFThumbnailViewer {
9020 constructor({
9021 container,
9022 eventBus,
9023 linkService,
9024 renderingQueue,
9025 l10n
9026 }) {
9027 this.container = container;
9028 this.linkService = linkService;
9029 this.renderingQueue = renderingQueue;
9030 this.l10n = l10n;
9031 this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
9032
9033 this._resetView();
9034
9035 eventBus._on("optionalcontentconfigchanged", () => {
9036 this._setImageDisabled = true;
9037 });
9038 }
9039
9040 _scrollUpdated() {
9041 this.renderingQueue.renderHighestPriority();
9042 }
9043
9044 getThumbnail(index) {
9045 return this._thumbnails[index];
9046 }
9047
9048 _getVisibleThumbs() {
9049 return (0, _ui_utils.getVisibleElements)({
9050 scrollEl: this.container,
9051 views: this._thumbnails
9052 });
9053 }
9054
9055 scrollThumbnailIntoView(pageNumber) {
9056 if (!this.pdfDocument) {
9057 return;
9058 }
9059
9060 const thumbnailView = this._thumbnails[pageNumber - 1];
9061
9062 if (!thumbnailView) {
9063 console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
9064 return;
9065 }
9066
9067 if (pageNumber !== this._currentPageNumber) {
9068 const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
9069 prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
9070 thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
9071 }
9072
9073 const visibleThumbs = this._getVisibleThumbs();
9074
9075 const numVisibleThumbs = visibleThumbs.views.length;
9076
9077 if (numVisibleThumbs > 0) {
9078 const first = visibleThumbs.first.id;
9079 const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
9080 let shouldScroll = false;
9081
9082 if (pageNumber <= first || pageNumber >= last) {
9083 shouldScroll = true;
9084 } else {
9085 visibleThumbs.views.some(function (view) {
9086 if (view.id !== pageNumber) {
9087 return false;
9088 }
9089
9090 shouldScroll = view.percent < 100;
9091 return true;
9092 });
9093 }
9094
9095 if (shouldScroll) {
9096 (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
9097 top: THUMBNAIL_SCROLL_MARGIN
9098 });
9099 }
9100 }
9101
9102 this._currentPageNumber = pageNumber;
9103 }
9104
9105 get pagesRotation() {
9106 return this._pagesRotation;
9107 }
9108
9109 set pagesRotation(rotation) {
9110 if (!(0, _ui_utils.isValidRotation)(rotation)) {
9111 throw new Error("Invalid thumbnails rotation angle.");
9112 }
9113
9114 if (!this.pdfDocument) {
9115 return;
9116 }
9117
9118 if (this._pagesRotation === rotation) {
9119 return;
9120 }
9121
9122 this._pagesRotation = rotation;
9123
9124 for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
9125 this._thumbnails[i].update(rotation);
9126 }
9127 }
9128
9129 cleanup() {
9130 for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
9131 if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
9132 this._thumbnails[i].reset();
9133 }
9134 }
9135
9136 _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
9137 }
9138
9139 _resetView() {
9140 this._thumbnails = [];
9141 this._currentPageNumber = 1;
9142 this._pageLabels = null;
9143 this._pagesRotation = 0;
9144 this._optionalContentConfigPromise = null;
9145 this._pagesRequests = new WeakMap();
9146 this._setImageDisabled = false;
9147 this.container.textContent = "";
9148 }
9149
9150 setDocument(pdfDocument) {
9151 if (this.pdfDocument) {
9152 this._cancelRendering();
9153
9154 this._resetView();
9155 }
9156
9157 this.pdfDocument = pdfDocument;
9158
9159 if (!pdfDocument) {
9160 return;
9161 }
9162
9163 const firstPagePromise = pdfDocument.getPage(1);
9164 const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
9165 firstPagePromise.then(firstPdfPage => {
9166 this._optionalContentConfigPromise = optionalContentConfigPromise;
9167 const pagesCount = pdfDocument.numPages;
9168 const viewport = firstPdfPage.getViewport({
9169 scale: 1
9170 });
9171
9172 const checkSetImageDisabled = () => {
9173 return this._setImageDisabled;
9174 };
9175
9176 for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
9177 const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
9178 container: this.container,
9179 id: pageNum,
9180 defaultViewport: viewport.clone(),
9181 optionalContentConfigPromise,
9182 linkService: this.linkService,
9183 renderingQueue: this.renderingQueue,
9184 checkSetImageDisabled,
9185 disableCanvasToImageConversion: false,
9186 l10n: this.l10n
9187 });
9188
9189 this._thumbnails.push(thumbnail);
9190 }
9191
9192 const firstThumbnailView = this._thumbnails[0];
9193
9194 if (firstThumbnailView) {
9195 firstThumbnailView.setPdfPage(firstPdfPage);
9196 }
9197
9198 const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
9199 thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
9200 }).catch(reason => {
9201 console.error("Unable to initialize thumbnail viewer", reason);
9202 });
9203 }
9204
9205 _cancelRendering() {
9206 for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
9207 if (this._thumbnails[i]) {
9208 this._thumbnails[i].cancelRendering();
9209 }
9210 }
9211 }
9212
9213 setPageLabels(labels) {
9214 if (!this.pdfDocument) {
9215 return;
9216 }
9217
9218 if (!labels) {
9219 this._pageLabels = null;
9220 } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
9221 this._pageLabels = null;
9222 console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
9223 } else {
9224 this._pageLabels = labels;
9225 }
9226
9227 for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
9228 this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
9229 }
9230 }
9231
9232 _ensurePdfPageLoaded(thumbView) {
9233 if (thumbView.pdfPage) {
9234 return Promise.resolve(thumbView.pdfPage);
9235 }
9236
9237 if (this._pagesRequests.has(thumbView)) {
9238 return this._pagesRequests.get(thumbView);
9239 }
9240
9241 const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
9242 if (!thumbView.pdfPage) {
9243 thumbView.setPdfPage(pdfPage);
9244 }
9245
9246 this._pagesRequests.delete(thumbView);
9247
9248 return pdfPage;
9249 }).catch(reason => {
9250 console.error("Unable to get page for thumb view", reason);
9251
9252 this._pagesRequests.delete(thumbView);
9253 });
9254
9255 this._pagesRequests.set(thumbView, promise);
9256
9257 return promise;
9258 }
9259
9260 forceRendering() {
9261 const visibleThumbs = this._getVisibleThumbs();
9262
9263 const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
9264
9265 if (thumbView) {
9266 this._ensurePdfPageLoaded(thumbView).then(() => {
9267 this.renderingQueue.renderView(thumbView);
9268 });
9269
9270 return true;
9271 }
9272
9273 return false;
9274 }
9275
9276}
9277
9278exports.PDFThumbnailViewer = PDFThumbnailViewer;
9279
9280/***/ }),
9281/* 26 */
9282/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
9283
9284
9285
9286Object.defineProperty(exports, "__esModule", ({
9287 value: true
9288}));
9289exports.TempImageFactory = exports.PDFThumbnailView = void 0;
9290
9291var _ui_utils = __webpack_require__(4);
9292
9293var _pdfjsLib = __webpack_require__(5);
9294
9295var _pdf_rendering_queue = __webpack_require__(8);
9296
9297const MAX_NUM_SCALING_STEPS = 3;
9298const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
9299const THUMBNAIL_WIDTH = 98;
9300
9301const TempImageFactory = function TempImageFactoryClosure() {
9302 let tempCanvasCache = null;
9303 return {
9304 getCanvas(width, height) {
9305 let tempCanvas = tempCanvasCache;
9306
9307 if (!tempCanvas) {
9308 tempCanvas = document.createElement("canvas");
9309 tempCanvasCache = tempCanvas;
9310 }
9311
9312 tempCanvas.width = width;
9313 tempCanvas.height = height;
9314 tempCanvas.mozOpaque = true;
9315 const ctx = tempCanvas.getContext("2d", {
9316 alpha: false
9317 });
9318 ctx.save();
9319 ctx.fillStyle = "rgb(255, 255, 255)";
9320 ctx.fillRect(0, 0, width, height);
9321 ctx.restore();
9322 return tempCanvas;
9323 },
9324
9325 destroyCanvas() {
9326 const tempCanvas = tempCanvasCache;
9327
9328 if (tempCanvas) {
9329 tempCanvas.width = 0;
9330 tempCanvas.height = 0;
9331 }
9332
9333 tempCanvasCache = null;
9334 }
9335
9336 };
9337}();
9338
9339exports.TempImageFactory = TempImageFactory;
9340
9341class PDFThumbnailView {
9342 constructor({
9343 container,
9344 id,
9345 defaultViewport,
9346 optionalContentConfigPromise,
9347 linkService,
9348 renderingQueue,
9349 checkSetImageDisabled,
9350 disableCanvasToImageConversion = false,
9351 l10n
9352 }) {
9353 this.id = id;
9354 this.renderingId = "thumbnail" + id;
9355 this.pageLabel = null;
9356 this.pdfPage = null;
9357 this.rotation = 0;
9358 this.viewport = defaultViewport;
9359 this.pdfPageRotate = defaultViewport.rotation;
9360 this._optionalContentConfigPromise = optionalContentConfigPromise || null;
9361 this.linkService = linkService;
9362 this.renderingQueue = renderingQueue;
9363 this.renderTask = null;
9364 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
9365 this.resume = null;
9366
9367 this._checkSetImageDisabled = checkSetImageDisabled || function () {
9368 return false;
9369 };
9370
9371 this.disableCanvasToImageConversion = disableCanvasToImageConversion;
9372 this.pageWidth = this.viewport.width;
9373 this.pageHeight = this.viewport.height;
9374 this.pageRatio = this.pageWidth / this.pageHeight;
9375 this.canvasWidth = THUMBNAIL_WIDTH;
9376 this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
9377 this.scale = this.canvasWidth / this.pageWidth;
9378 this.l10n = l10n;
9379 const anchor = document.createElement("a");
9380 anchor.href = linkService.getAnchorUrl("#page=" + id);
9381
9382 this._thumbPageTitle.then(msg => {
9383 anchor.title = msg;
9384 });
9385
9386 anchor.onclick = function () {
9387 linkService.goToPage(id);
9388 return false;
9389 };
9390
9391 this.anchor = anchor;
9392 const div = document.createElement("div");
9393 div.className = "thumbnail";
9394 div.setAttribute("data-page-number", this.id);
9395 this.div = div;
9396 const ring = document.createElement("div");
9397 ring.className = "thumbnailSelectionRing";
9398 const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
9399 ring.style.width = this.canvasWidth + borderAdjustment + "px";
9400 ring.style.height = this.canvasHeight + borderAdjustment + "px";
9401 this.ring = ring;
9402 div.appendChild(ring);
9403 anchor.appendChild(div);
9404 container.appendChild(anchor);
9405 }
9406
9407 setPdfPage(pdfPage) {
9408 this.pdfPage = pdfPage;
9409 this.pdfPageRotate = pdfPage.rotate;
9410 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
9411 this.viewport = pdfPage.getViewport({
9412 scale: 1,
9413 rotation: totalRotation
9414 });
9415 this.reset();
9416 }
9417
9418 reset() {
9419 this.cancelRendering();
9420 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
9421 this.pageWidth = this.viewport.width;
9422 this.pageHeight = this.viewport.height;
9423 this.pageRatio = this.pageWidth / this.pageHeight;
9424 this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
9425 this.scale = this.canvasWidth / this.pageWidth;
9426 this.div.removeAttribute("data-loaded");
9427 const ring = this.ring;
9428 const childNodes = ring.childNodes;
9429
9430 for (let i = childNodes.length - 1; i >= 0; i--) {
9431 ring.removeChild(childNodes[i]);
9432 }
9433
9434 const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
9435 ring.style.width = this.canvasWidth + borderAdjustment + "px";
9436 ring.style.height = this.canvasHeight + borderAdjustment + "px";
9437
9438 if (this.canvas) {
9439 this.canvas.width = 0;
9440 this.canvas.height = 0;
9441 delete this.canvas;
9442 }
9443
9444 if (this.image) {
9445 this.image.removeAttribute("src");
9446 delete this.image;
9447 }
9448 }
9449
9450 update(rotation) {
9451 if (typeof rotation !== "undefined") {
9452 this.rotation = rotation;
9453 }
9454
9455 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
9456 this.viewport = this.viewport.clone({
9457 scale: 1,
9458 rotation: totalRotation
9459 });
9460 this.reset();
9461 }
9462
9463 cancelRendering() {
9464 if (this.renderTask) {
9465 this.renderTask.cancel();
9466 this.renderTask = null;
9467 }
9468
9469 this.resume = null;
9470 }
9471
9472 _getPageDrawContext() {
9473 const canvas = document.createElement("canvas");
9474 this.canvas = canvas;
9475 canvas.mozOpaque = true;
9476 const ctx = canvas.getContext("2d", {
9477 alpha: false
9478 });
9479 const outputScale = (0, _ui_utils.getOutputScale)(ctx);
9480 canvas.width = this.canvasWidth * outputScale.sx | 0;
9481 canvas.height = this.canvasHeight * outputScale.sy | 0;
9482 canvas.style.width = this.canvasWidth + "px";
9483 canvas.style.height = this.canvasHeight + "px";
9484 const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
9485 return [ctx, transform];
9486 }
9487
9488 _convertCanvasToImage() {
9489 if (!this.canvas) {
9490 return;
9491 }
9492
9493 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
9494 return;
9495 }
9496
9497 const className = "thumbnailImage";
9498
9499 if (this.disableCanvasToImageConversion) {
9500 this.canvas.className = className;
9501
9502 this._thumbPageCanvas.then(msg => {
9503 this.canvas.setAttribute("aria-label", msg);
9504 });
9505
9506 this.div.setAttribute("data-loaded", true);
9507 this.ring.appendChild(this.canvas);
9508 return;
9509 }
9510
9511 const image = document.createElement("img");
9512 image.className = className;
9513
9514 this._thumbPageCanvas.then(msg => {
9515 image.setAttribute("aria-label", msg);
9516 });
9517
9518 image.style.width = this.canvasWidth + "px";
9519 image.style.height = this.canvasHeight + "px";
9520 image.src = this.canvas.toDataURL();
9521 this.image = image;
9522 this.div.setAttribute("data-loaded", true);
9523 this.ring.appendChild(image);
9524 this.canvas.width = 0;
9525 this.canvas.height = 0;
9526 delete this.canvas;
9527 }
9528
9529 draw() {
9530 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
9531 console.error("Must be in new state before drawing");
9532 return Promise.resolve(undefined);
9533 }
9534
9535 const {
9536 pdfPage
9537 } = this;
9538
9539 if (!pdfPage) {
9540 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
9541 return Promise.reject(new Error("pdfPage is not loaded"));
9542 }
9543
9544 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
9545
9546 const finishRenderTask = async (error = null) => {
9547 if (renderTask === this.renderTask) {
9548 this.renderTask = null;
9549 }
9550
9551 if (error instanceof _pdfjsLib.RenderingCancelledException) {
9552 return;
9553 }
9554
9555 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
9556
9557 this._convertCanvasToImage();
9558
9559 if (error) {
9560 throw error;
9561 }
9562 };
9563
9564 const [ctx, transform] = this._getPageDrawContext();
9565
9566 const drawViewport = this.viewport.clone({
9567 scale: this.scale
9568 });
9569
9570 const renderContinueCallback = cont => {
9571 if (!this.renderingQueue.isHighestPriority(this)) {
9572 this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
9573
9574 this.resume = () => {
9575 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
9576 cont();
9577 };
9578
9579 return;
9580 }
9581
9582 cont();
9583 };
9584
9585 const renderContext = {
9586 canvasContext: ctx,
9587 transform,
9588 viewport: drawViewport,
9589 optionalContentConfigPromise: this._optionalContentConfigPromise
9590 };
9591 const renderTask = this.renderTask = pdfPage.render(renderContext);
9592 renderTask.onContinue = renderContinueCallback;
9593 const resultPromise = renderTask.promise.then(function () {
9594 finishRenderTask(null);
9595 }, function (error) {
9596 finishRenderTask(error);
9597 });
9598 resultPromise.finally(() => {
9599 const pageCached = this.linkService.isPageCached(this.id);
9600
9601 if (pageCached) {
9602 return;
9603 }
9604
9605 this.pdfPage?.cleanup();
9606 });
9607 return resultPromise;
9608 }
9609
9610 setImage(pageView) {
9611 if (this._checkSetImageDisabled()) {
9612 return;
9613 }
9614
9615 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
9616 return;
9617 }
9618
9619 const img = pageView.canvas;
9620
9621 if (!img) {
9622 return;
9623 }
9624
9625 if (!this.pdfPage) {
9626 this.setPdfPage(pageView.pdfPage);
9627 }
9628
9629 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
9630
9631 const [ctx] = this._getPageDrawContext();
9632
9633 const canvas = ctx.canvas;
9634
9635 if (img.width <= 2 * canvas.width) {
9636 ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
9637
9638 this._convertCanvasToImage();
9639
9640 return;
9641 }
9642
9643 let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
9644 let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
9645 const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
9646 const reducedImageCtx = reducedImage.getContext("2d");
9647
9648 while (reducedWidth > img.width || reducedHeight > img.height) {
9649 reducedWidth >>= 1;
9650 reducedHeight >>= 1;
9651 }
9652
9653 reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
9654
9655 while (reducedWidth > 2 * canvas.width) {
9656 reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
9657 reducedWidth >>= 1;
9658 reducedHeight >>= 1;
9659 }
9660
9661 ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
9662
9663 this._convertCanvasToImage();
9664 }
9665
9666 get _thumbPageTitle() {
9667 return this.l10n.get("thumb_page_title", {
9668 page: this.pageLabel ?? this.id
9669 });
9670 }
9671
9672 get _thumbPageCanvas() {
9673 return this.l10n.get("thumb_page_canvas", {
9674 page: this.pageLabel ?? this.id
9675 });
9676 }
9677
9678 setPageLabel(label) {
9679 this.pageLabel = typeof label === "string" ? label : null;
9680
9681 this._thumbPageTitle.then(msg => {
9682 this.anchor.title = msg;
9683 });
9684
9685 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
9686 return;
9687 }
9688
9689 this._thumbPageCanvas.then(msg => {
9690 if (this.image) {
9691 this.image.setAttribute("aria-label", msg);
9692 } else if (this.disableCanvasToImageConversion && this.canvas) {
9693 this.canvas.setAttribute("aria-label", msg);
9694 }
9695 });
9696 }
9697
9698}
9699
9700exports.PDFThumbnailView = PDFThumbnailView;
9701
9702/***/ }),
9703/* 27 */
9704/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
9705
9706
9707
9708Object.defineProperty(exports, "__esModule", ({
9709 value: true
9710}));
9711exports.PDFViewer = void 0;
9712
9713var _ui_utils = __webpack_require__(4);
9714
9715var _base_viewer = __webpack_require__(28);
9716
9717var _pdfjsLib = __webpack_require__(5);
9718
9719class PDFViewer extends _base_viewer.BaseViewer {
9720 get _viewerElement() {
9721 return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
9722 }
9723
9724 _scrollIntoView({
9725 pageDiv,
9726 pageSpot = null,
9727 pageNumber = null
9728 }) {
9729 if (!pageSpot && !this.isInPresentationMode) {
9730 const left = pageDiv.offsetLeft + pageDiv.clientLeft;
9731 const right = left + pageDiv.clientWidth;
9732 const {
9733 scrollLeft,
9734 clientWidth
9735 } = this.container;
9736
9737 if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
9738 pageSpot = {
9739 left: 0,
9740 top: 0
9741 };
9742 }
9743 }
9744
9745 super._scrollIntoView({
9746 pageDiv,
9747 pageSpot,
9748 pageNumber
9749 });
9750 }
9751
9752 _getVisiblePages() {
9753 if (this.isInPresentationMode) {
9754 return this._getCurrentVisiblePage();
9755 }
9756
9757 return super._getVisiblePages();
9758 }
9759
9760 _updateHelper(visiblePages) {
9761 if (this.isInPresentationMode) {
9762 return;
9763 }
9764
9765 let currentId = this._currentPageNumber;
9766 let stillFullyVisible = false;
9767
9768 for (const page of visiblePages) {
9769 if (page.percent < 100) {
9770 break;
9771 }
9772
9773 if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
9774 stillFullyVisible = true;
9775 break;
9776 }
9777 }
9778
9779 if (!stillFullyVisible) {
9780 currentId = visiblePages[0].id;
9781 }
9782
9783 this._setCurrentPageNumber(currentId);
9784 }
9785
9786}
9787
9788exports.PDFViewer = PDFViewer;
9789
9790/***/ }),
9791/* 28 */
9792/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
9793
9794
9795
9796Object.defineProperty(exports, "__esModule", ({
9797 value: true
9798}));
9799exports.BaseViewer = void 0;
9800
9801var _pdfjsLib = __webpack_require__(5);
9802
9803var _ui_utils = __webpack_require__(4);
9804
9805var _pdf_rendering_queue = __webpack_require__(8);
9806
9807var _annotation_layer_builder = __webpack_require__(29);
9808
9809var _l10n_utils = __webpack_require__(30);
9810
9811var _pdf_page_view = __webpack_require__(31);
9812
9813var _pdf_link_service = __webpack_require__(19);
9814
9815var _text_layer_builder = __webpack_require__(32);
9816
9817var _xfa_layer_builder = __webpack_require__(33);
9818
9819const DEFAULT_CACHE_SIZE = 10;
9820
9821function PDFPageViewBuffer(size) {
9822 const data = [];
9823
9824 this.push = function (view) {
9825 const i = data.indexOf(view);
9826
9827 if (i >= 0) {
9828 data.splice(i, 1);
9829 }
9830
9831 data.push(view);
9832
9833 if (data.length > size) {
9834 data.shift().destroy();
9835 }
9836 };
9837
9838 this.resize = function (newSize, pagesToKeep) {
9839 size = newSize;
9840
9841 if (pagesToKeep) {
9842 const pageIdsToKeep = new Set();
9843
9844 for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
9845 pageIdsToKeep.add(pagesToKeep[i].id);
9846 }
9847
9848 (0, _ui_utils.moveToEndOfArray)(data, function (page) {
9849 return pageIdsToKeep.has(page.id);
9850 });
9851 }
9852
9853 while (data.length > size) {
9854 data.shift().destroy();
9855 }
9856 };
9857
9858 this.has = function (view) {
9859 return data.includes(view);
9860 };
9861}
9862
9863function isSameScale(oldScale, newScale) {
9864 if (newScale === oldScale) {
9865 return true;
9866 }
9867
9868 if (Math.abs(newScale - oldScale) < 1e-15) {
9869 return true;
9870 }
9871
9872 return false;
9873}
9874
9875class BaseViewer {
9876 constructor(options) {
9877 if (this.constructor === BaseViewer) {
9878 throw new Error("Cannot initialize BaseViewer.");
9879 }
9880
9881 const viewerVersion = '2.8.335';
9882
9883 if (_pdfjsLib.version !== viewerVersion) {
9884 throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
9885 }
9886
9887 this._name = this.constructor.name;
9888 this.container = options.container;
9889 this.viewer = options.viewer || options.container.firstElementChild;
9890
9891 if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
9892 throw new Error("Invalid `container` and/or `viewer` option.");
9893 }
9894
9895 if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
9896 throw new Error("The `container` must be absolutely positioned.");
9897 }
9898
9899 this.eventBus = options.eventBus;
9900 this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
9901 this.downloadManager = options.downloadManager || null;
9902 this.findController = options.findController || null;
9903 this._scriptingManager = options.scriptingManager || null;
9904 this.removePageBorders = options.removePageBorders || false;
9905 this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
9906 this.imageResourcesPath = options.imageResourcesPath || "";
9907 this.renderInteractiveForms = options.renderInteractiveForms !== false;
9908 this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
9909 this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
9910 this.enableWebGL = options.enableWebGL || false;
9911 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
9912 this.maxCanvasPixels = options.maxCanvasPixels;
9913 this.l10n = options.l10n || _l10n_utils.NullL10n;
9914 this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
9915 this.defaultRenderingQueue = !options.renderingQueue;
9916
9917 if (this.defaultRenderingQueue) {
9918 this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
9919 this.renderingQueue.setViewer(this);
9920 } else {
9921 this.renderingQueue = options.renderingQueue;
9922 }
9923
9924 this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
9925 this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
9926 this._onBeforeDraw = this._onAfterDraw = null;
9927
9928 this._resetView();
9929
9930 if (this.removePageBorders) {
9931 this.viewer.classList.add("removePageBorders");
9932 }
9933
9934 Promise.resolve().then(() => {
9935 this.eventBus.dispatch("baseviewerinit", {
9936 source: this
9937 });
9938 });
9939 }
9940
9941 get pagesCount() {
9942 return this._pages.length;
9943 }
9944
9945 getPageView(index) {
9946 return this._pages[index];
9947 }
9948
9949 get pageViewsReady() {
9950 if (!this._pagesCapability.settled) {
9951 return false;
9952 }
9953
9954 return this._pages.every(function (pageView) {
9955 return pageView?.pdfPage;
9956 });
9957 }
9958
9959 get currentPageNumber() {
9960 return this._currentPageNumber;
9961 }
9962
9963 set currentPageNumber(val) {
9964 if (!Number.isInteger(val)) {
9965 throw new Error("Invalid page number.");
9966 }
9967
9968 if (!this.pdfDocument) {
9969 return;
9970 }
9971
9972 if (!this._setCurrentPageNumber(val, true)) {
9973 console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
9974 }
9975 }
9976
9977 _setCurrentPageNumber(val, resetCurrentPageView = false) {
9978 if (this._currentPageNumber === val) {
9979 if (resetCurrentPageView) {
9980 this._resetCurrentPageView();
9981 }
9982
9983 return true;
9984 }
9985
9986 if (!(0 < val && val <= this.pagesCount)) {
9987 return false;
9988 }
9989
9990 const previous = this._currentPageNumber;
9991 this._currentPageNumber = val;
9992 this.eventBus.dispatch("pagechanging", {
9993 source: this,
9994 pageNumber: val,
9995 pageLabel: this._pageLabels?.[val - 1] ?? null,
9996 previous
9997 });
9998
9999 if (resetCurrentPageView) {
10000 this._resetCurrentPageView();
10001 }
10002
10003 return true;
10004 }
10005
10006 get currentPageLabel() {
10007 return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
10008 }
10009
10010 set currentPageLabel(val) {
10011 if (!this.pdfDocument) {
10012 return;
10013 }
10014
10015 let page = val | 0;
10016
10017 if (this._pageLabels) {
10018 const i = this._pageLabels.indexOf(val);
10019
10020 if (i >= 0) {
10021 page = i + 1;
10022 }
10023 }
10024
10025 if (!this._setCurrentPageNumber(page, true)) {
10026 console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
10027 }
10028 }
10029
10030 get currentScale() {
10031 return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
10032 }
10033
10034 set currentScale(val) {
10035 if (isNaN(val)) {
10036 throw new Error("Invalid numeric scale.");
10037 }
10038
10039 if (!this.pdfDocument) {
10040 return;
10041 }
10042
10043 this._setScale(val, false);
10044 }
10045
10046 get currentScaleValue() {
10047 return this._currentScaleValue;
10048 }
10049
10050 set currentScaleValue(val) {
10051 if (!this.pdfDocument) {
10052 return;
10053 }
10054
10055 this._setScale(val, false);
10056 }
10057
10058 get pagesRotation() {
10059 return this._pagesRotation;
10060 }
10061
10062 set pagesRotation(rotation) {
10063 if (!(0, _ui_utils.isValidRotation)(rotation)) {
10064 throw new Error("Invalid pages rotation angle.");
10065 }
10066
10067 if (!this.pdfDocument) {
10068 return;
10069 }
10070
10071 rotation %= 360;
10072
10073 if (rotation < 0) {
10074 rotation += 360;
10075 }
10076
10077 if (this._pagesRotation === rotation) {
10078 return;
10079 }
10080
10081 this._pagesRotation = rotation;
10082 const pageNumber = this._currentPageNumber;
10083
10084 for (let i = 0, ii = this._pages.length; i < ii; i++) {
10085 const pageView = this._pages[i];
10086 pageView.update(pageView.scale, rotation);
10087 }
10088
10089 if (this._currentScaleValue) {
10090 this._setScale(this._currentScaleValue, true);
10091 }
10092
10093 this.eventBus.dispatch("rotationchanging", {
10094 source: this,
10095 pagesRotation: rotation,
10096 pageNumber
10097 });
10098
10099 if (this.defaultRenderingQueue) {
10100 this.update();
10101 }
10102 }
10103
10104 get firstPagePromise() {
10105 return this.pdfDocument ? this._firstPageCapability.promise : null;
10106 }
10107
10108 get onePageRendered() {
10109 return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
10110 }
10111
10112 get pagesPromise() {
10113 return this.pdfDocument ? this._pagesCapability.promise : null;
10114 }
10115
10116 get _viewerElement() {
10117 throw new Error("Not implemented: _viewerElement");
10118 }
10119
10120 _onePageRenderedOrForceFetch() {
10121 if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
10122 return Promise.resolve();
10123 }
10124
10125 return this._onePageRenderedCapability.promise;
10126 }
10127
10128 setDocument(pdfDocument) {
10129 if (this.pdfDocument) {
10130 this.eventBus.dispatch("pagesdestroy", {
10131 source: this
10132 });
10133
10134 this._cancelRendering();
10135
10136 this._resetView();
10137
10138 if (this.findController) {
10139 this.findController.setDocument(null);
10140 }
10141
10142 if (this._scriptingManager) {
10143 this._scriptingManager.setDocument(null);
10144 }
10145 }
10146
10147 this.pdfDocument = pdfDocument;
10148
10149 if (!pdfDocument) {
10150 return;
10151 }
10152
10153 const isPureXfa = pdfDocument.isPureXfa;
10154 const pagesCount = pdfDocument.numPages;
10155 const firstPagePromise = pdfDocument.getPage(1);
10156 const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
10157
10158 this._pagesCapability.promise.then(() => {
10159 this.eventBus.dispatch("pagesloaded", {
10160 source: this,
10161 pagesCount
10162 });
10163 });
10164
10165 this._onBeforeDraw = evt => {
10166 const pageView = this._pages[evt.pageNumber - 1];
10167
10168 if (!pageView) {
10169 return;
10170 }
10171
10172 this._buffer.push(pageView);
10173 };
10174
10175 this.eventBus._on("pagerender", this._onBeforeDraw);
10176
10177 this._onAfterDraw = evt => {
10178 if (evt.cssTransform || this._onePageRenderedCapability.settled) {
10179 return;
10180 }
10181
10182 this._onePageRenderedCapability.resolve();
10183
10184 this.eventBus._off("pagerendered", this._onAfterDraw);
10185
10186 this._onAfterDraw = null;
10187 };
10188
10189 this.eventBus._on("pagerendered", this._onAfterDraw);
10190
10191 firstPagePromise.then(firstPdfPage => {
10192 this._firstPageCapability.resolve(firstPdfPage);
10193
10194 this._optionalContentConfigPromise = optionalContentConfigPromise;
10195 const scale = this.currentScale;
10196 const viewport = firstPdfPage.getViewport({
10197 scale: scale * _ui_utils.CSS_UNITS
10198 });
10199 const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
10200 const xfaLayerFactory = isPureXfa ? this : null;
10201
10202 for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
10203 const pageView = new _pdf_page_view.PDFPageView({
10204 container: this._viewerElement,
10205 eventBus: this.eventBus,
10206 id: pageNum,
10207 scale,
10208 defaultViewport: viewport.clone(),
10209 optionalContentConfigPromise,
10210 renderingQueue: this.renderingQueue,
10211 textLayerFactory,
10212 textLayerMode: this.textLayerMode,
10213 annotationLayerFactory: this,
10214 xfaLayerFactory,
10215 imageResourcesPath: this.imageResourcesPath,
10216 renderInteractiveForms: this.renderInteractiveForms,
10217 renderer: this.renderer,
10218 enableWebGL: this.enableWebGL,
10219 useOnlyCssZoom: this.useOnlyCssZoom,
10220 maxCanvasPixels: this.maxCanvasPixels,
10221 l10n: this.l10n,
10222 enableScripting: this.enableScripting
10223 });
10224
10225 this._pages.push(pageView);
10226 }
10227
10228 const firstPageView = this._pages[0];
10229
10230 if (firstPageView) {
10231 firstPageView.setPdfPage(firstPdfPage);
10232 this.linkService.cachePageRef(1, firstPdfPage.ref);
10233 }
10234
10235 if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
10236 this._updateSpreadMode();
10237 }
10238
10239 this._onePageRenderedOrForceFetch().then(() => {
10240 if (this.findController) {
10241 this.findController.setDocument(pdfDocument);
10242 }
10243
10244 if (this.enableScripting) {
10245 this._scriptingManager.setDocument(pdfDocument);
10246 }
10247
10248 if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
10249 this._pagesCapability.resolve();
10250
10251 return;
10252 }
10253
10254 let getPagesLeft = pagesCount - 1;
10255
10256 if (getPagesLeft <= 0) {
10257 this._pagesCapability.resolve();
10258
10259 return;
10260 }
10261
10262 for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
10263 pdfDocument.getPage(pageNum).then(pdfPage => {
10264 const pageView = this._pages[pageNum - 1];
10265
10266 if (!pageView.pdfPage) {
10267 pageView.setPdfPage(pdfPage);
10268 }
10269
10270 this.linkService.cachePageRef(pageNum, pdfPage.ref);
10271
10272 if (--getPagesLeft === 0) {
10273 this._pagesCapability.resolve();
10274 }
10275 }, reason => {
10276 console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
10277
10278 if (--getPagesLeft === 0) {
10279 this._pagesCapability.resolve();
10280 }
10281 });
10282 }
10283 });
10284
10285 this.eventBus.dispatch("pagesinit", {
10286 source: this
10287 });
10288
10289 if (this.defaultRenderingQueue) {
10290 this.update();
10291 }
10292 }).catch(reason => {
10293 console.error("Unable to initialize viewer", reason);
10294 });
10295 }
10296
10297 setPageLabels(labels) {
10298 if (!this.pdfDocument) {
10299 return;
10300 }
10301
10302 if (!labels) {
10303 this._pageLabels = null;
10304 } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
10305 this._pageLabels = null;
10306 console.error(`${this._name}.setPageLabels: Invalid page labels.`);
10307 } else {
10308 this._pageLabels = labels;
10309 }
10310
10311 for (let i = 0, ii = this._pages.length; i < ii; i++) {
10312 this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
10313 }
10314 }
10315
10316 _resetView() {
10317 this._pages = [];
10318 this._currentPageNumber = 1;
10319 this._currentScale = _ui_utils.UNKNOWN_SCALE;
10320 this._currentScaleValue = null;
10321 this._pageLabels = null;
10322 this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
10323 this._location = null;
10324 this._pagesRotation = 0;
10325 this._optionalContentConfigPromise = null;
10326 this._pagesRequests = new WeakMap();
10327 this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
10328 this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
10329 this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
10330 this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
10331 this._spreadMode = _ui_utils.SpreadMode.NONE;
10332
10333 if (this._onBeforeDraw) {
10334 this.eventBus._off("pagerender", this._onBeforeDraw);
10335
10336 this._onBeforeDraw = null;
10337 }
10338
10339 if (this._onAfterDraw) {
10340 this.eventBus._off("pagerendered", this._onAfterDraw);
10341
10342 this._onAfterDraw = null;
10343 }
10344
10345 this.viewer.textContent = "";
10346
10347 this._updateScrollMode();
10348 }
10349
10350 _scrollUpdate() {
10351 if (this.pagesCount === 0) {
10352 return;
10353 }
10354
10355 this.update();
10356 }
10357
10358 _scrollIntoView({
10359 pageDiv,
10360 pageSpot = null,
10361 pageNumber = null
10362 }) {
10363 (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
10364 }
10365
10366 _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
10367 this._currentScaleValue = newValue.toString();
10368
10369 if (isSameScale(this._currentScale, newScale)) {
10370 if (preset) {
10371 this.eventBus.dispatch("scalechanging", {
10372 source: this,
10373 scale: newScale,
10374 presetValue: newValue
10375 });
10376 }
10377
10378 return;
10379 }
10380
10381 for (let i = 0, ii = this._pages.length; i < ii; i++) {
10382 this._pages[i].update(newScale);
10383 }
10384
10385 this._currentScale = newScale;
10386
10387 if (!noScroll) {
10388 let page = this._currentPageNumber,
10389 dest;
10390
10391 if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
10392 page = this._location.pageNumber;
10393 dest = [null, {
10394 name: "XYZ"
10395 }, this._location.left, this._location.top, null];
10396 }
10397
10398 this.scrollPageIntoView({
10399 pageNumber: page,
10400 destArray: dest,
10401 allowNegativeOffset: true
10402 });
10403 }
10404
10405 this.eventBus.dispatch("scalechanging", {
10406 source: this,
10407 scale: newScale,
10408 presetValue: preset ? newValue : undefined
10409 });
10410
10411 if (this.defaultRenderingQueue) {
10412 this.update();
10413 }
10414 }
10415
10416 get _pageWidthScaleFactor() {
10417 if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
10418 return 2;
10419 }
10420
10421 return 1;
10422 }
10423
10424 _setScale(value, noScroll = false) {
10425 let scale = parseFloat(value);
10426
10427 if (scale > 0) {
10428 this._setScaleUpdatePages(scale, value, noScroll, false);
10429 } else {
10430 const currentPage = this._pages[this._currentPageNumber - 1];
10431
10432 if (!currentPage) {
10433 return;
10434 }
10435
10436 const noPadding = this.isInPresentationMode || this.removePageBorders;
10437 let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
10438 let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
10439
10440 if (!noPadding && this._isScrollModeHorizontal) {
10441 [hPadding, vPadding] = [vPadding, hPadding];
10442 }
10443
10444 const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
10445 const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
10446
10447 switch (value) {
10448 case "page-actual":
10449 scale = 1;
10450 break;
10451
10452 case "page-width":
10453 scale = pageWidthScale;
10454 break;
10455
10456 case "page-height":
10457 scale = pageHeightScale;
10458 break;
10459
10460 case "page-fit":
10461 scale = Math.min(pageWidthScale, pageHeightScale);
10462 break;
10463
10464 case "auto":
10465 const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
10466 scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
10467 break;
10468
10469 default:
10470 console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
10471 return;
10472 }
10473
10474 this._setScaleUpdatePages(scale, value, noScroll, true);
10475 }
10476 }
10477
10478 _resetCurrentPageView() {
10479 if (this.isInPresentationMode) {
10480 this._setScale(this._currentScaleValue, true);
10481 }
10482
10483 const pageView = this._pages[this._currentPageNumber - 1];
10484
10485 this._scrollIntoView({
10486 pageDiv: pageView.div
10487 });
10488 }
10489
10490 pageLabelToPageNumber(label) {
10491 if (!this._pageLabels) {
10492 return null;
10493 }
10494
10495 const i = this._pageLabels.indexOf(label);
10496
10497 if (i < 0) {
10498 return null;
10499 }
10500
10501 return i + 1;
10502 }
10503
10504 scrollPageIntoView({
10505 pageNumber,
10506 destArray = null,
10507 allowNegativeOffset = false,
10508 ignoreDestinationZoom = false
10509 }) {
10510 if (!this.pdfDocument) {
10511 return;
10512 }
10513
10514 const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
10515
10516 if (!pageView) {
10517 console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
10518 return;
10519 }
10520
10521 if (this.isInPresentationMode || !destArray) {
10522 this._setCurrentPageNumber(pageNumber, true);
10523
10524 return;
10525 }
10526
10527 let x = 0,
10528 y = 0;
10529 let width = 0,
10530 height = 0,
10531 widthScale,
10532 heightScale;
10533 const changeOrientation = pageView.rotation % 180 !== 0;
10534 const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
10535 const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
10536 let scale = 0;
10537
10538 switch (destArray[1].name) {
10539 case "XYZ":
10540 x = destArray[2];
10541 y = destArray[3];
10542 scale = destArray[4];
10543 x = x !== null ? x : 0;
10544 y = y !== null ? y : pageHeight;
10545 break;
10546
10547 case "Fit":
10548 case "FitB":
10549 scale = "page-fit";
10550 break;
10551
10552 case "FitH":
10553 case "FitBH":
10554 y = destArray[2];
10555 scale = "page-width";
10556
10557 if (y === null && this._location) {
10558 x = this._location.left;
10559 y = this._location.top;
10560 } else if (typeof y !== "number") {
10561 y = pageHeight;
10562 }
10563
10564 break;
10565
10566 case "FitV":
10567 case "FitBV":
10568 x = destArray[2];
10569 width = pageWidth;
10570 height = pageHeight;
10571 scale = "page-height";
10572 break;
10573
10574 case "FitR":
10575 x = destArray[2];
10576 y = destArray[3];
10577 width = destArray[4] - x;
10578 height = destArray[5] - y;
10579 const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
10580 const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
10581 widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
10582 heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
10583 scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
10584 break;
10585
10586 default:
10587 console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
10588 return;
10589 }
10590
10591 if (!ignoreDestinationZoom) {
10592 if (scale && scale !== this._currentScale) {
10593 this.currentScaleValue = scale;
10594 } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
10595 this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
10596 }
10597 }
10598
10599 if (scale === "page-fit" && !destArray[4]) {
10600 this._scrollIntoView({
10601 pageDiv: pageView.div,
10602 pageNumber
10603 });
10604
10605 return;
10606 }
10607
10608 const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
10609 let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
10610 let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
10611
10612 if (!allowNegativeOffset) {
10613 left = Math.max(left, 0);
10614 top = Math.max(top, 0);
10615 }
10616
10617 this._scrollIntoView({
10618 pageDiv: pageView.div,
10619 pageSpot: {
10620 left,
10621 top
10622 },
10623 pageNumber
10624 });
10625 }
10626
10627 _updateLocation(firstPage) {
10628 const currentScale = this._currentScale;
10629 const currentScaleValue = this._currentScaleValue;
10630 const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
10631 const pageNumber = firstPage.id;
10632 let pdfOpenParams = "#page=" + pageNumber;
10633 pdfOpenParams += "&zoom=" + normalizedScaleValue;
10634 const currentPageView = this._pages[pageNumber - 1];
10635 const container = this.container;
10636 const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
10637 const intLeft = Math.round(topLeft[0]);
10638 const intTop = Math.round(topLeft[1]);
10639 pdfOpenParams += "," + intLeft + "," + intTop;
10640 this._location = {
10641 pageNumber,
10642 scale: normalizedScaleValue,
10643 top: intTop,
10644 left: intLeft,
10645 rotation: this._pagesRotation,
10646 pdfOpenParams
10647 };
10648 }
10649
10650 _updateHelper(visiblePages) {
10651 throw new Error("Not implemented: _updateHelper");
10652 }
10653
10654 update() {
10655 const visible = this._getVisiblePages();
10656
10657 const visiblePages = visible.views,
10658 numVisiblePages = visiblePages.length;
10659
10660 if (numVisiblePages === 0) {
10661 return;
10662 }
10663
10664 const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
10665
10666 this._buffer.resize(newCacheSize, visiblePages);
10667
10668 this.renderingQueue.renderHighestPriority(visible);
10669
10670 this._updateHelper(visiblePages);
10671
10672 this._updateLocation(visible.first);
10673
10674 this.eventBus.dispatch("updateviewarea", {
10675 source: this,
10676 location: this._location
10677 });
10678 }
10679
10680 containsElement(element) {
10681 return this.container.contains(element);
10682 }
10683
10684 focus() {
10685 this.container.focus();
10686 }
10687
10688 get _isScrollModeHorizontal() {
10689 return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
10690 }
10691
10692 get _isContainerRtl() {
10693 return getComputedStyle(this.container).direction === "rtl";
10694 }
10695
10696 get isInPresentationMode() {
10697 return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
10698 }
10699
10700 get isChangingPresentationMode() {
10701 return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
10702 }
10703
10704 get isHorizontalScrollbarEnabled() {
10705 return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
10706 }
10707
10708 get isVerticalScrollbarEnabled() {
10709 return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
10710 }
10711
10712 _getCurrentVisiblePage() {
10713 if (!this.pagesCount) {
10714 return {
10715 views: []
10716 };
10717 }
10718
10719 const pageView = this._pages[this._currentPageNumber - 1];
10720 const element = pageView.div;
10721 const view = {
10722 id: pageView.id,
10723 x: element.offsetLeft + element.clientLeft,
10724 y: element.offsetTop + element.clientTop,
10725 view: pageView
10726 };
10727 return {
10728 first: view,
10729 last: view,
10730 views: [view]
10731 };
10732 }
10733
10734 _getVisiblePages() {
10735 return (0, _ui_utils.getVisibleElements)({
10736 scrollEl: this.container,
10737 views: this._pages,
10738 sortByVisibility: true,
10739 horizontal: this._isScrollModeHorizontal,
10740 rtl: this._isScrollModeHorizontal && this._isContainerRtl
10741 });
10742 }
10743
10744 isPageVisible(pageNumber) {
10745 if (!this.pdfDocument) {
10746 return false;
10747 }
10748
10749 if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
10750 console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
10751 return false;
10752 }
10753
10754 return this._getVisiblePages().views.some(function (view) {
10755 return view.id === pageNumber;
10756 });
10757 }
10758
10759 isPageCached(pageNumber) {
10760 if (!this.pdfDocument || !this._buffer) {
10761 return false;
10762 }
10763
10764 if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
10765 console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
10766 return false;
10767 }
10768
10769 const pageView = this._pages[pageNumber - 1];
10770
10771 if (!pageView) {
10772 return false;
10773 }
10774
10775 return this._buffer.has(pageView);
10776 }
10777
10778 cleanup() {
10779 for (let i = 0, ii = this._pages.length; i < ii; i++) {
10780 if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
10781 this._pages[i].reset();
10782 }
10783 }
10784 }
10785
10786 _cancelRendering() {
10787 for (let i = 0, ii = this._pages.length; i < ii; i++) {
10788 if (this._pages[i]) {
10789 this._pages[i].cancelRendering();
10790 }
10791 }
10792 }
10793
10794 _ensurePdfPageLoaded(pageView) {
10795 if (pageView.pdfPage) {
10796 return Promise.resolve(pageView.pdfPage);
10797 }
10798
10799 if (this._pagesRequests.has(pageView)) {
10800 return this._pagesRequests.get(pageView);
10801 }
10802
10803 const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
10804 if (!pageView.pdfPage) {
10805 pageView.setPdfPage(pdfPage);
10806 }
10807
10808 this._pagesRequests.delete(pageView);
10809
10810 return pdfPage;
10811 }).catch(reason => {
10812 console.error("Unable to get page for page view", reason);
10813
10814 this._pagesRequests.delete(pageView);
10815 });
10816
10817 this._pagesRequests.set(pageView, promise);
10818
10819 return promise;
10820 }
10821
10822 forceRendering(currentlyVisiblePages) {
10823 const visiblePages = currentlyVisiblePages || this._getVisiblePages();
10824
10825 const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
10826 const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
10827
10828 if (pageView) {
10829 this._ensurePdfPageLoaded(pageView).then(() => {
10830 this.renderingQueue.renderView(pageView);
10831 });
10832
10833 return true;
10834 }
10835
10836 return false;
10837 }
10838
10839 createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
10840 return new _text_layer_builder.TextLayerBuilder({
10841 textLayerDiv,
10842 eventBus,
10843 pageIndex,
10844 viewport,
10845 findController: this.isInPresentationMode ? null : this.findController,
10846 enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
10847 });
10848 }
10849
10850 createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
10851 return new _annotation_layer_builder.AnnotationLayerBuilder({
10852 pageDiv,
10853 pdfPage,
10854 annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
10855 imageResourcesPath,
10856 renderInteractiveForms,
10857 linkService: this.linkService,
10858 downloadManager: this.downloadManager,
10859 l10n,
10860 enableScripting,
10861 hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
10862 mouseState: mouseState || this._scriptingManager?.mouseState
10863 });
10864 }
10865
10866 createXfaLayerBuilder(pageDiv, pdfPage) {
10867 return new _xfa_layer_builder.XfaLayerBuilder({
10868 pageDiv,
10869 pdfPage
10870 });
10871 }
10872
10873 get hasEqualPageSizes() {
10874 const firstPageView = this._pages[0];
10875
10876 for (let i = 1, ii = this._pages.length; i < ii; ++i) {
10877 const pageView = this._pages[i];
10878
10879 if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
10880 return false;
10881 }
10882 }
10883
10884 return true;
10885 }
10886
10887 getPagesOverview() {
10888 return this._pages.map(pageView => {
10889 const viewport = pageView.pdfPage.getViewport({
10890 scale: 1
10891 });
10892
10893 if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
10894 return {
10895 width: viewport.width,
10896 height: viewport.height,
10897 rotation: viewport.rotation
10898 };
10899 }
10900
10901 return {
10902 width: viewport.height,
10903 height: viewport.width,
10904 rotation: (viewport.rotation - 90) % 360
10905 };
10906 });
10907 }
10908
10909 get optionalContentConfigPromise() {
10910 if (!this.pdfDocument) {
10911 return Promise.resolve(null);
10912 }
10913
10914 if (!this._optionalContentConfigPromise) {
10915 return this.pdfDocument.getOptionalContentConfig();
10916 }
10917
10918 return this._optionalContentConfigPromise;
10919 }
10920
10921 set optionalContentConfigPromise(promise) {
10922 if (!(promise instanceof Promise)) {
10923 throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
10924 }
10925
10926 if (!this.pdfDocument) {
10927 return;
10928 }
10929
10930 if (!this._optionalContentConfigPromise) {
10931 return;
10932 }
10933
10934 this._optionalContentConfigPromise = promise;
10935
10936 for (const pageView of this._pages) {
10937 pageView.update(pageView.scale, pageView.rotation, promise);
10938 }
10939
10940 this.update();
10941 this.eventBus.dispatch("optionalcontentconfigchanged", {
10942 source: this,
10943 promise
10944 });
10945 }
10946
10947 get scrollMode() {
10948 return this._scrollMode;
10949 }
10950
10951 set scrollMode(mode) {
10952 if (this._scrollMode === mode) {
10953 return;
10954 }
10955
10956 if (!(0, _ui_utils.isValidScrollMode)(mode)) {
10957 throw new Error(`Invalid scroll mode: ${mode}`);
10958 }
10959
10960 this._scrollMode = mode;
10961 this.eventBus.dispatch("scrollmodechanged", {
10962 source: this,
10963 mode
10964 });
10965
10966 this._updateScrollMode(this._currentPageNumber);
10967 }
10968
10969 _updateScrollMode(pageNumber = null) {
10970 const scrollMode = this._scrollMode,
10971 viewer = this.viewer;
10972 viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
10973 viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
10974
10975 if (!this.pdfDocument || !pageNumber) {
10976 return;
10977 }
10978
10979 if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
10980 this._setScale(this._currentScaleValue, true);
10981 }
10982
10983 this._setCurrentPageNumber(pageNumber, true);
10984
10985 this.update();
10986 }
10987
10988 get spreadMode() {
10989 return this._spreadMode;
10990 }
10991
10992 set spreadMode(mode) {
10993 if (this._spreadMode === mode) {
10994 return;
10995 }
10996
10997 if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
10998 throw new Error(`Invalid spread mode: ${mode}`);
10999 }
11000
11001 this._spreadMode = mode;
11002 this.eventBus.dispatch("spreadmodechanged", {
11003 source: this,
11004 mode
11005 });
11006
11007 this._updateSpreadMode(this._currentPageNumber);
11008 }
11009
11010 _updateSpreadMode(pageNumber = null) {
11011 if (!this.pdfDocument) {
11012 return;
11013 }
11014
11015 const viewer = this.viewer,
11016 pages = this._pages;
11017 viewer.textContent = "";
11018
11019 if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
11020 for (let i = 0, iMax = pages.length; i < iMax; ++i) {
11021 viewer.appendChild(pages[i].div);
11022 }
11023 } else {
11024 const parity = this._spreadMode - 1;
11025 let spread = null;
11026
11027 for (let i = 0, iMax = pages.length; i < iMax; ++i) {
11028 if (spread === null) {
11029 spread = document.createElement("div");
11030 spread.className = "spread";
11031 viewer.appendChild(spread);
11032 } else if (i % 2 === parity) {
11033 spread = spread.cloneNode(false);
11034 viewer.appendChild(spread);
11035 }
11036
11037 spread.appendChild(pages[i].div);
11038 }
11039 }
11040
11041 if (!pageNumber) {
11042 return;
11043 }
11044
11045 if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
11046 this._setScale(this._currentScaleValue, true);
11047 }
11048
11049 this._setCurrentPageNumber(pageNumber, true);
11050
11051 this.update();
11052 }
11053
11054 _getPageAdvance(currentPageNumber, previous = false) {
11055 if (this.isInPresentationMode) {
11056 return 1;
11057 }
11058
11059 switch (this._scrollMode) {
11060 case _ui_utils.ScrollMode.WRAPPED:
11061 {
11062 const {
11063 views
11064 } = this._getVisiblePages(),
11065 pageLayout = new Map();
11066
11067 for (const {
11068 id,
11069 y,
11070 percent,
11071 widthPercent
11072 } of views) {
11073 if (percent === 0 || widthPercent < 100) {
11074 continue;
11075 }
11076
11077 let yArray = pageLayout.get(y);
11078
11079 if (!yArray) {
11080 pageLayout.set(y, yArray || (yArray = []));
11081 }
11082
11083 yArray.push(id);
11084 }
11085
11086 for (const yArray of pageLayout.values()) {
11087 const currentIndex = yArray.indexOf(currentPageNumber);
11088
11089 if (currentIndex === -1) {
11090 continue;
11091 }
11092
11093 const numPages = yArray.length;
11094
11095 if (numPages === 1) {
11096 break;
11097 }
11098
11099 if (previous) {
11100 for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
11101 const currentId = yArray[i],
11102 expectedId = yArray[i + 1] - 1;
11103
11104 if (currentId < expectedId) {
11105 return currentPageNumber - expectedId;
11106 }
11107 }
11108 } else {
11109 for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
11110 const currentId = yArray[i],
11111 expectedId = yArray[i - 1] + 1;
11112
11113 if (currentId > expectedId) {
11114 return expectedId - currentPageNumber;
11115 }
11116 }
11117 }
11118
11119 if (previous) {
11120 const firstId = yArray[0];
11121
11122 if (firstId < currentPageNumber) {
11123 return currentPageNumber - firstId + 1;
11124 }
11125 } else {
11126 const lastId = yArray[numPages - 1];
11127
11128 if (lastId > currentPageNumber) {
11129 return lastId - currentPageNumber + 1;
11130 }
11131 }
11132
11133 break;
11134 }
11135
11136 break;
11137 }
11138
11139 case _ui_utils.ScrollMode.HORIZONTAL:
11140 {
11141 break;
11142 }
11143
11144 case _ui_utils.ScrollMode.VERTICAL:
11145 {
11146 if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
11147 break;
11148 }
11149
11150 const parity = this._spreadMode - 1;
11151
11152 if (previous && currentPageNumber % 2 !== parity) {
11153 break;
11154 } else if (!previous && currentPageNumber % 2 === parity) {
11155 break;
11156 }
11157
11158 const {
11159 views
11160 } = this._getVisiblePages(),
11161 expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
11162
11163 for (const {
11164 id,
11165 percent,
11166 widthPercent
11167 } of views) {
11168 if (id !== expectedId) {
11169 continue;
11170 }
11171
11172 if (percent > 0 && widthPercent === 100) {
11173 return 2;
11174 }
11175
11176 break;
11177 }
11178
11179 break;
11180 }
11181 }
11182
11183 return 1;
11184 }
11185
11186 nextPage() {
11187 const currentPageNumber = this._currentPageNumber,
11188 pagesCount = this.pagesCount;
11189
11190 if (currentPageNumber >= pagesCount) {
11191 return false;
11192 }
11193
11194 const advance = this._getPageAdvance(currentPageNumber, false) || 1;
11195 this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
11196 return true;
11197 }
11198
11199 previousPage() {
11200 const currentPageNumber = this._currentPageNumber;
11201
11202 if (currentPageNumber <= 1) {
11203 return false;
11204 }
11205
11206 const advance = this._getPageAdvance(currentPageNumber, true) || 1;
11207 this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
11208 return true;
11209 }
11210
11211}
11212
11213exports.BaseViewer = BaseViewer;
11214
11215/***/ }),
11216/* 29 */
11217/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
11218
11219
11220
11221Object.defineProperty(exports, "__esModule", ({
11222 value: true
11223}));
11224exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
11225
11226var _pdfjsLib = __webpack_require__(5);
11227
11228var _l10n_utils = __webpack_require__(30);
11229
11230var _pdf_link_service = __webpack_require__(19);
11231
11232class AnnotationLayerBuilder {
11233 constructor({
11234 pageDiv,
11235 pdfPage,
11236 linkService,
11237 downloadManager,
11238 annotationStorage = null,
11239 imageResourcesPath = "",
11240 renderInteractiveForms = true,
11241 l10n = _l10n_utils.NullL10n,
11242 enableScripting = false,
11243 hasJSActionsPromise = null,
11244 mouseState = null
11245 }) {
11246 this.pageDiv = pageDiv;
11247 this.pdfPage = pdfPage;
11248 this.linkService = linkService;
11249 this.downloadManager = downloadManager;
11250 this.imageResourcesPath = imageResourcesPath;
11251 this.renderInteractiveForms = renderInteractiveForms;
11252 this.l10n = l10n;
11253 this.annotationStorage = annotationStorage;
11254 this.enableScripting = enableScripting;
11255 this._hasJSActionsPromise = hasJSActionsPromise;
11256 this._mouseState = mouseState;
11257 this.div = null;
11258 this._cancelled = false;
11259 }
11260
11261 render(viewport, intent = "display") {
11262 return Promise.all([this.pdfPage.getAnnotations({
11263 intent
11264 }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
11265 if (this._cancelled) {
11266 return;
11267 }
11268
11269 if (annotations.length === 0) {
11270 return;
11271 }
11272
11273 const parameters = {
11274 viewport: viewport.clone({
11275 dontFlip: true
11276 }),
11277 div: this.div,
11278 annotations,
11279 page: this.pdfPage,
11280 imageResourcesPath: this.imageResourcesPath,
11281 renderInteractiveForms: this.renderInteractiveForms,
11282 linkService: this.linkService,
11283 downloadManager: this.downloadManager,
11284 annotationStorage: this.annotationStorage,
11285 enableScripting: this.enableScripting,
11286 hasJSActions,
11287 mouseState: this._mouseState
11288 };
11289
11290 if (this.div) {
11291 _pdfjsLib.AnnotationLayer.update(parameters);
11292 } else {
11293 this.div = document.createElement("div");
11294 this.div.className = "annotationLayer";
11295 this.pageDiv.appendChild(this.div);
11296 parameters.div = this.div;
11297
11298 _pdfjsLib.AnnotationLayer.render(parameters);
11299
11300 this.l10n.translate(this.div);
11301 }
11302 });
11303 }
11304
11305 cancel() {
11306 this._cancelled = true;
11307 }
11308
11309 hide() {
11310 if (!this.div) {
11311 return;
11312 }
11313
11314 this.div.hidden = true;
11315 }
11316
11317}
11318
11319exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
11320
11321class DefaultAnnotationLayerFactory {
11322 createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
11323 return new AnnotationLayerBuilder({
11324 pageDiv,
11325 pdfPage,
11326 imageResourcesPath,
11327 renderInteractiveForms,
11328 linkService: new _pdf_link_service.SimpleLinkService(),
11329 l10n,
11330 annotationStorage,
11331 enableScripting,
11332 hasJSActionsPromise,
11333 mouseState
11334 });
11335 }
11336
11337}
11338
11339exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
11340
11341/***/ }),
11342/* 30 */
11343/***/ ((__unused_webpack_module, exports) => {
11344
11345
11346
11347Object.defineProperty(exports, "__esModule", ({
11348 value: true
11349}));
11350exports.getL10nFallback = getL10nFallback;
11351exports.NullL10n = void 0;
11352const DEFAULT_L10N_STRINGS = {
11353 of_pages: "of {{pagesCount}}",
11354 page_of_pages: "({{pageNumber}} of {{pagesCount}})",
11355 document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
11356 document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
11357 document_properties_date_string: "{{date}}, {{time}}",
11358 document_properties_page_size_unit_inches: "in",
11359 document_properties_page_size_unit_millimeters: "mm",
11360 document_properties_page_size_orientation_portrait: "portrait",
11361 document_properties_page_size_orientation_landscape: "landscape",
11362 document_properties_page_size_name_a3: "A3",
11363 document_properties_page_size_name_a4: "A4",
11364 document_properties_page_size_name_letter: "Letter",
11365 document_properties_page_size_name_legal: "Legal",
11366 document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
11367 document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
11368 document_properties_linearized_yes: "Yes",
11369 document_properties_linearized_no: "No",
11370 print_progress_percent: "{{progress}}%",
11371 "toggle_sidebar.title": "Toggle Sidebar",
11372 "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
11373 additional_layers: "Additional Layers",
11374 page_landmark: "Page {{page}}",
11375 thumb_page_title: "Page {{page}}",
11376 thumb_page_canvas: "Thumbnail of Page {{page}}",
11377 find_reached_top: "Reached top of document, continued from bottom",
11378 find_reached_bottom: "Reached end of document, continued from top",
11379 "find_match_count[one]": "{{current}} of {{total}} match",
11380 "find_match_count[other]": "{{current}} of {{total}} matches",
11381 "find_match_count_limit[one]": "More than {{limit}} match",
11382 "find_match_count_limit[other]": "More than {{limit}} matches",
11383 find_not_found: "Phrase not found",
11384 error_version_info: "PDF.js v{{version}} (build: {{build}})",
11385 error_message: "Message: {{message}}",
11386 error_stack: "Stack: {{stack}}",
11387 error_file: "File: {{file}}",
11388 error_line: "Line: {{line}}",
11389 rendering_error: "An error occurred while rendering the page.",
11390 page_scale_width: "Page Width",
11391 page_scale_fit: "Page Fit",
11392 page_scale_auto: "Automatic Zoom",
11393 page_scale_actual: "Actual Size",
11394 page_scale_percent: "{{scale}}%",
11395 loading: "Loading…",
11396 loading_error: "An error occurred while loading the PDF.",
11397 invalid_file_error: "Invalid or corrupted PDF file.",
11398 missing_file_error: "Missing PDF file.",
11399 unexpected_response_error: "Unexpected server response.",
11400 printing_not_supported: "Warning: Printing is not fully supported by this browser.",
11401 printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
11402 web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
11403};
11404
11405function getL10nFallback(key, args) {
11406 switch (key) {
11407 case "find_match_count":
11408 key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
11409 break;
11410
11411 case "find_match_count_limit":
11412 key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
11413 break;
11414 }
11415
11416 return DEFAULT_L10N_STRINGS[key] || "";
11417}
11418
11419function formatL10nValue(text, args) {
11420 if (!args) {
11421 return text;
11422 }
11423
11424 return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
11425 return name in args ? args[name] : "{{" + name + "}}";
11426 });
11427}
11428
11429const NullL10n = {
11430 async getLanguage() {
11431 return "en-us";
11432 },
11433
11434 async getDirection() {
11435 return "ltr";
11436 },
11437
11438 async get(key, args = null, fallback = getL10nFallback(key, args)) {
11439 return formatL10nValue(fallback, args);
11440 },
11441
11442 async translate(element) {}
11443
11444};
11445exports.NullL10n = NullL10n;
11446
11447/***/ }),
11448/* 31 */
11449/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
11450
11451
11452
11453Object.defineProperty(exports, "__esModule", ({
11454 value: true
11455}));
11456exports.PDFPageView = void 0;
11457
11458var _ui_utils = __webpack_require__(4);
11459
11460var _pdfjsLib = __webpack_require__(5);
11461
11462var _l10n_utils = __webpack_require__(30);
11463
11464var _pdf_rendering_queue = __webpack_require__(8);
11465
11466var _viewer_compatibility = __webpack_require__(2);
11467
11468const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
11469
11470class PDFPageView {
11471 constructor(options) {
11472 const container = options.container;
11473 const defaultViewport = options.defaultViewport;
11474 this.id = options.id;
11475 this.renderingId = "page" + this.id;
11476 this.pdfPage = null;
11477 this.pageLabel = null;
11478 this.rotation = 0;
11479 this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
11480 this.viewport = defaultViewport;
11481 this.pdfPageRotate = defaultViewport.rotation;
11482 this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
11483 this.hasRestrictedScaling = false;
11484 this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
11485 this.imageResourcesPath = options.imageResourcesPath || "";
11486 this.renderInteractiveForms = options.renderInteractiveForms !== false;
11487 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
11488 this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
11489 this.eventBus = options.eventBus;
11490 this.renderingQueue = options.renderingQueue;
11491 this.textLayerFactory = options.textLayerFactory;
11492 this.annotationLayerFactory = options.annotationLayerFactory;
11493 this.xfaLayerFactory = options.xfaLayerFactory;
11494 this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
11495 this.enableWebGL = options.enableWebGL || false;
11496 this.l10n = options.l10n || _l10n_utils.NullL10n;
11497 this.enableScripting = options.enableScripting === true;
11498 this.paintTask = null;
11499 this.paintedViewportMap = new WeakMap();
11500 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
11501 this.resume = null;
11502 this._renderError = null;
11503 this.annotationLayer = null;
11504 this.textLayer = null;
11505 this.zoomLayer = null;
11506 this.xfaLayer = null;
11507 const div = document.createElement("div");
11508 div.className = "page";
11509 div.style.width = Math.floor(this.viewport.width) + "px";
11510 div.style.height = Math.floor(this.viewport.height) + "px";
11511 div.setAttribute("data-page-number", this.id);
11512 div.setAttribute("role", "region");
11513 this.l10n.get("page_landmark", {
11514 page: this.id
11515 }).then(msg => {
11516 div.setAttribute("aria-label", msg);
11517 });
11518 this.div = div;
11519 container.appendChild(div);
11520 }
11521
11522 setPdfPage(pdfPage) {
11523 this.pdfPage = pdfPage;
11524 this.pdfPageRotate = pdfPage.rotate;
11525 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
11526 this.viewport = pdfPage.getViewport({
11527 scale: this.scale * _ui_utils.CSS_UNITS,
11528 rotation: totalRotation
11529 });
11530 this.reset();
11531 }
11532
11533 destroy() {
11534 this.reset();
11535
11536 if (this.pdfPage) {
11537 this.pdfPage.cleanup();
11538 }
11539 }
11540
11541 async _renderAnnotationLayer() {
11542 let error = null;
11543
11544 try {
11545 await this.annotationLayer.render(this.viewport, "display");
11546 } catch (ex) {
11547 error = ex;
11548 } finally {
11549 this.eventBus.dispatch("annotationlayerrendered", {
11550 source: this,
11551 pageNumber: this.id,
11552 error
11553 });
11554 }
11555 }
11556
11557 async _renderXfaLayer() {
11558 let error = null;
11559
11560 try {
11561 await this.xfaLayer.render(this.viewport, "display");
11562 } catch (ex) {
11563 error = ex;
11564 } finally {
11565 this.eventBus.dispatch("xfalayerrendered", {
11566 source: this,
11567 pageNumber: this.id,
11568 error
11569 });
11570 }
11571 }
11572
11573 _resetZoomLayer(removeFromDOM = false) {
11574 if (!this.zoomLayer) {
11575 return;
11576 }
11577
11578 const zoomLayerCanvas = this.zoomLayer.firstChild;
11579 this.paintedViewportMap.delete(zoomLayerCanvas);
11580 zoomLayerCanvas.width = 0;
11581 zoomLayerCanvas.height = 0;
11582
11583 if (removeFromDOM) {
11584 this.zoomLayer.remove();
11585 }
11586
11587 this.zoomLayer = null;
11588 }
11589
11590 reset(keepZoomLayer = false, keepAnnotations = false) {
11591 this.cancelRendering(keepAnnotations);
11592 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
11593 const div = this.div;
11594 div.style.width = Math.floor(this.viewport.width) + "px";
11595 div.style.height = Math.floor(this.viewport.height) + "px";
11596 const childNodes = div.childNodes;
11597 const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
11598 const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
11599 const currentXfaLayerNode = this.xfaLayer?.div || null;
11600
11601 for (let i = childNodes.length - 1; i >= 0; i--) {
11602 const node = childNodes[i];
11603
11604 if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
11605 continue;
11606 }
11607
11608 div.removeChild(node);
11609 }
11610
11611 div.removeAttribute("data-loaded");
11612
11613 if (currentAnnotationNode) {
11614 this.annotationLayer.hide();
11615 } else if (this.annotationLayer) {
11616 this.annotationLayer.cancel();
11617 this.annotationLayer = null;
11618 }
11619
11620 if (!currentZoomLayerNode) {
11621 if (this.canvas) {
11622 this.paintedViewportMap.delete(this.canvas);
11623 this.canvas.width = 0;
11624 this.canvas.height = 0;
11625 delete this.canvas;
11626 }
11627
11628 this._resetZoomLayer();
11629 }
11630
11631 if (this.svg) {
11632 this.paintedViewportMap.delete(this.svg);
11633 delete this.svg;
11634 }
11635
11636 this.loadingIconDiv = document.createElement("div");
11637 this.loadingIconDiv.className = "loadingIcon";
11638 this.loadingIconDiv.setAttribute("role", "img");
11639 this.l10n.get("loading").then(msg => {
11640 this.loadingIconDiv?.setAttribute("aria-label", msg);
11641 });
11642 div.appendChild(this.loadingIconDiv);
11643 }
11644
11645 update(scale, rotation, optionalContentConfigPromise = null) {
11646 this.scale = scale || this.scale;
11647
11648 if (typeof rotation !== "undefined") {
11649 this.rotation = rotation;
11650 }
11651
11652 if (optionalContentConfigPromise instanceof Promise) {
11653 this._optionalContentConfigPromise = optionalContentConfigPromise;
11654 }
11655
11656 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
11657 this.viewport = this.viewport.clone({
11658 scale: this.scale * _ui_utils.CSS_UNITS,
11659 rotation: totalRotation
11660 });
11661
11662 if (this.svg) {
11663 this.cssTransform(this.svg, true);
11664 this.eventBus.dispatch("pagerendered", {
11665 source: this,
11666 pageNumber: this.id,
11667 cssTransform: true,
11668 timestamp: performance.now(),
11669 error: this._renderError
11670 });
11671 return;
11672 }
11673
11674 let isScalingRestricted = false;
11675
11676 if (this.canvas && this.maxCanvasPixels > 0) {
11677 const outputScale = this.outputScale;
11678
11679 if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
11680 isScalingRestricted = true;
11681 }
11682 }
11683
11684 if (this.canvas) {
11685 if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
11686 this.cssTransform(this.canvas, true);
11687 this.eventBus.dispatch("pagerendered", {
11688 source: this,
11689 pageNumber: this.id,
11690 cssTransform: true,
11691 timestamp: performance.now(),
11692 error: this._renderError
11693 });
11694 return;
11695 }
11696
11697 if (!this.zoomLayer && !this.canvas.hidden) {
11698 this.zoomLayer = this.canvas.parentNode;
11699 this.zoomLayer.style.position = "absolute";
11700 }
11701 }
11702
11703 if (this.zoomLayer) {
11704 this.cssTransform(this.zoomLayer.firstChild);
11705 }
11706
11707 this.reset(true, true);
11708 }
11709
11710 cancelRendering(keepAnnotations = false) {
11711 if (this.paintTask) {
11712 this.paintTask.cancel();
11713 this.paintTask = null;
11714 }
11715
11716 this.resume = null;
11717
11718 if (this.textLayer) {
11719 this.textLayer.cancel();
11720 this.textLayer = null;
11721 }
11722
11723 if (!keepAnnotations && this.annotationLayer) {
11724 this.annotationLayer.cancel();
11725 this.annotationLayer = null;
11726 }
11727 }
11728
11729 cssTransform(target, redrawAnnotations = false) {
11730 const width = this.viewport.width;
11731 const height = this.viewport.height;
11732 const div = this.div;
11733 target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
11734 target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
11735 const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
11736 const absRotation = Math.abs(relativeRotation);
11737 let scaleX = 1,
11738 scaleY = 1;
11739
11740 if (absRotation === 90 || absRotation === 270) {
11741 scaleX = height / width;
11742 scaleY = width / height;
11743 }
11744
11745 target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
11746
11747 if (this.textLayer) {
11748 const textLayerViewport = this.textLayer.viewport;
11749 const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
11750 const textAbsRotation = Math.abs(textRelativeRotation);
11751 let scale = width / textLayerViewport.width;
11752
11753 if (textAbsRotation === 90 || textAbsRotation === 270) {
11754 scale = width / textLayerViewport.height;
11755 }
11756
11757 const textLayerDiv = this.textLayer.textLayerDiv;
11758 let transX, transY;
11759
11760 switch (textAbsRotation) {
11761 case 0:
11762 transX = transY = 0;
11763 break;
11764
11765 case 90:
11766 transX = 0;
11767 transY = "-" + textLayerDiv.style.height;
11768 break;
11769
11770 case 180:
11771 transX = "-" + textLayerDiv.style.width;
11772 transY = "-" + textLayerDiv.style.height;
11773 break;
11774
11775 case 270:
11776 transX = "-" + textLayerDiv.style.width;
11777 transY = 0;
11778 break;
11779
11780 default:
11781 console.error("Bad rotation value.");
11782 break;
11783 }
11784
11785 textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
11786 textLayerDiv.style.transformOrigin = "0% 0%";
11787 }
11788
11789 if (redrawAnnotations && this.annotationLayer) {
11790 this._renderAnnotationLayer();
11791 }
11792
11793 if (this.xfaLayer) {
11794 this._renderXfaLayer();
11795 }
11796 }
11797
11798 get width() {
11799 return this.viewport.width;
11800 }
11801
11802 get height() {
11803 return this.viewport.height;
11804 }
11805
11806 getPagePoint(x, y) {
11807 return this.viewport.convertToPdfPoint(x, y);
11808 }
11809
11810 draw() {
11811 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
11812 console.error("Must be in new state before drawing");
11813 this.reset();
11814 }
11815
11816 const {
11817 div,
11818 pdfPage
11819 } = this;
11820
11821 if (!pdfPage) {
11822 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
11823
11824 if (this.loadingIconDiv) {
11825 div.removeChild(this.loadingIconDiv);
11826 delete this.loadingIconDiv;
11827 }
11828
11829 return Promise.reject(new Error("pdfPage is not loaded"));
11830 }
11831
11832 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
11833 const canvasWrapper = document.createElement("div");
11834 canvasWrapper.style.width = div.style.width;
11835 canvasWrapper.style.height = div.style.height;
11836 canvasWrapper.classList.add("canvasWrapper");
11837
11838 if (this.annotationLayer?.div) {
11839 div.insertBefore(canvasWrapper, this.annotationLayer.div);
11840 } else {
11841 div.appendChild(canvasWrapper);
11842 }
11843
11844 let textLayer = null;
11845
11846 if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
11847 const textLayerDiv = document.createElement("div");
11848 textLayerDiv.className = "textLayer";
11849 textLayerDiv.style.width = canvasWrapper.style.width;
11850 textLayerDiv.style.height = canvasWrapper.style.height;
11851
11852 if (this.annotationLayer?.div) {
11853 div.insertBefore(textLayerDiv, this.annotationLayer.div);
11854 } else {
11855 div.appendChild(textLayerDiv);
11856 }
11857
11858 textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
11859 }
11860
11861 this.textLayer = textLayer;
11862 let renderContinueCallback = null;
11863
11864 if (this.renderingQueue) {
11865 renderContinueCallback = cont => {
11866 if (!this.renderingQueue.isHighestPriority(this)) {
11867 this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
11868
11869 this.resume = () => {
11870 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
11871 cont();
11872 };
11873
11874 return;
11875 }
11876
11877 cont();
11878 };
11879 }
11880
11881 const finishPaintTask = async (error = null) => {
11882 if (paintTask === this.paintTask) {
11883 this.paintTask = null;
11884 }
11885
11886 if (error instanceof _pdfjsLib.RenderingCancelledException) {
11887 this._renderError = null;
11888 return;
11889 }
11890
11891 this._renderError = error;
11892 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
11893
11894 if (this.loadingIconDiv) {
11895 div.removeChild(this.loadingIconDiv);
11896 delete this.loadingIconDiv;
11897 }
11898
11899 this._resetZoomLayer(true);
11900
11901 this.eventBus.dispatch("pagerendered", {
11902 source: this,
11903 pageNumber: this.id,
11904 cssTransform: false,
11905 timestamp: performance.now(),
11906 error: this._renderError
11907 });
11908
11909 if (error) {
11910 throw error;
11911 }
11912 };
11913
11914 const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
11915 paintTask.onRenderContinue = renderContinueCallback;
11916 this.paintTask = paintTask;
11917 const resultPromise = paintTask.promise.then(function () {
11918 return finishPaintTask(null).then(function () {
11919 if (textLayer) {
11920 const readableStream = pdfPage.streamTextContent({
11921 normalizeWhitespace: true
11922 });
11923 textLayer.setTextContentStream(readableStream);
11924 textLayer.render();
11925 }
11926 });
11927 }, function (reason) {
11928 return finishPaintTask(reason);
11929 });
11930
11931 if (this.annotationLayerFactory) {
11932 if (!this.annotationLayer) {
11933 this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, this.enableScripting, null, null);
11934 }
11935
11936 this._renderAnnotationLayer();
11937 }
11938
11939 if (this.xfaLayerFactory) {
11940 if (!this.xfaLayer) {
11941 this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage);
11942 }
11943
11944 this._renderXfaLayer();
11945 }
11946
11947 div.setAttribute("data-loaded", true);
11948 this.eventBus.dispatch("pagerender", {
11949 source: this,
11950 pageNumber: this.id
11951 });
11952 return resultPromise;
11953 }
11954
11955 paintOnCanvas(canvasWrapper) {
11956 const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
11957 const result = {
11958 promise: renderCapability.promise,
11959
11960 onRenderContinue(cont) {
11961 cont();
11962 },
11963
11964 cancel() {
11965 renderTask.cancel();
11966 }
11967
11968 };
11969 const viewport = this.viewport;
11970 const canvas = document.createElement("canvas");
11971 canvas.hidden = true;
11972 let isCanvasHidden = true;
11973
11974 const showCanvas = function () {
11975 if (isCanvasHidden) {
11976 canvas.hidden = false;
11977 isCanvasHidden = false;
11978 }
11979 };
11980
11981 canvasWrapper.appendChild(canvas);
11982 this.canvas = canvas;
11983 canvas.mozOpaque = true;
11984 const ctx = canvas.getContext("2d", {
11985 alpha: false
11986 });
11987 const outputScale = (0, _ui_utils.getOutputScale)(ctx);
11988 this.outputScale = outputScale;
11989
11990 if (this.useOnlyCssZoom) {
11991 const actualSizeViewport = viewport.clone({
11992 scale: _ui_utils.CSS_UNITS
11993 });
11994 outputScale.sx *= actualSizeViewport.width / viewport.width;
11995 outputScale.sy *= actualSizeViewport.height / viewport.height;
11996 outputScale.scaled = true;
11997 }
11998
11999 if (this.maxCanvasPixels > 0) {
12000 const pixelsInViewport = viewport.width * viewport.height;
12001 const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
12002
12003 if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
12004 outputScale.sx = maxScale;
12005 outputScale.sy = maxScale;
12006 outputScale.scaled = true;
12007 this.hasRestrictedScaling = true;
12008 } else {
12009 this.hasRestrictedScaling = false;
12010 }
12011 }
12012
12013 const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
12014 const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
12015 canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
12016 canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
12017 canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
12018 canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
12019 this.paintedViewportMap.set(canvas, viewport);
12020 const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
12021 const renderContext = {
12022 canvasContext: ctx,
12023 transform,
12024 viewport: this.viewport,
12025 enableWebGL: this.enableWebGL,
12026 renderInteractiveForms: this.renderInteractiveForms,
12027 optionalContentConfigPromise: this._optionalContentConfigPromise
12028 };
12029 const renderTask = this.pdfPage.render(renderContext);
12030
12031 renderTask.onContinue = function (cont) {
12032 showCanvas();
12033
12034 if (result.onRenderContinue) {
12035 result.onRenderContinue(cont);
12036 } else {
12037 cont();
12038 }
12039 };
12040
12041 renderTask.promise.then(function () {
12042 showCanvas();
12043 renderCapability.resolve(undefined);
12044 }, function (error) {
12045 showCanvas();
12046 renderCapability.reject(error);
12047 });
12048 return result;
12049 }
12050
12051 paintOnSvg(wrapper) {
12052 let cancelled = false;
12053
12054 const ensureNotCancelled = () => {
12055 if (cancelled) {
12056 throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
12057 }
12058 };
12059
12060 const pdfPage = this.pdfPage;
12061 const actualSizeViewport = this.viewport.clone({
12062 scale: _ui_utils.CSS_UNITS
12063 });
12064 const promise = pdfPage.getOperatorList().then(opList => {
12065 ensureNotCancelled();
12066 const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
12067 return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
12068 ensureNotCancelled();
12069 this.svg = svg;
12070 this.paintedViewportMap.set(svg, actualSizeViewport);
12071 svg.style.width = wrapper.style.width;
12072 svg.style.height = wrapper.style.height;
12073 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
12074 wrapper.appendChild(svg);
12075 });
12076 });
12077 return {
12078 promise,
12079
12080 onRenderContinue(cont) {
12081 cont();
12082 },
12083
12084 cancel() {
12085 cancelled = true;
12086 }
12087
12088 };
12089 }
12090
12091 setPageLabel(label) {
12092 this.pageLabel = typeof label === "string" ? label : null;
12093
12094 if (this.pageLabel !== null) {
12095 this.div.setAttribute("data-page-label", this.pageLabel);
12096 } else {
12097 this.div.removeAttribute("data-page-label");
12098 }
12099 }
12100
12101}
12102
12103exports.PDFPageView = PDFPageView;
12104
12105/***/ }),
12106/* 32 */
12107/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
12108
12109
12110
12111Object.defineProperty(exports, "__esModule", ({
12112 value: true
12113}));
12114exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
12115
12116var _pdfjsLib = __webpack_require__(5);
12117
12118const EXPAND_DIVS_TIMEOUT = 300;
12119
12120class TextLayerBuilder {
12121 constructor({
12122 textLayerDiv,
12123 eventBus,
12124 pageIndex,
12125 viewport,
12126 findController = null,
12127 enhanceTextSelection = false
12128 }) {
12129 this.textLayerDiv = textLayerDiv;
12130 this.eventBus = eventBus;
12131 this.textContent = null;
12132 this.textContentItemsStr = [];
12133 this.textContentStream = null;
12134 this.renderingDone = false;
12135 this.pageIdx = pageIndex;
12136 this.pageNumber = this.pageIdx + 1;
12137 this.matches = [];
12138 this.viewport = viewport;
12139 this.textDivs = [];
12140 this.findController = findController;
12141 this.textLayerRenderTask = null;
12142 this.enhanceTextSelection = enhanceTextSelection;
12143 this._onUpdateTextLayerMatches = null;
12144
12145 this._bindMouse();
12146 }
12147
12148 _finishRendering() {
12149 this.renderingDone = true;
12150
12151 if (!this.enhanceTextSelection) {
12152 const endOfContent = document.createElement("div");
12153 endOfContent.className = "endOfContent";
12154 this.textLayerDiv.appendChild(endOfContent);
12155 }
12156
12157 this.eventBus.dispatch("textlayerrendered", {
12158 source: this,
12159 pageNumber: this.pageNumber,
12160 numTextDivs: this.textDivs.length
12161 });
12162 }
12163
12164 render(timeout = 0) {
12165 if (!(this.textContent || this.textContentStream) || this.renderingDone) {
12166 return;
12167 }
12168
12169 this.cancel();
12170 this.textDivs = [];
12171 const textLayerFrag = document.createDocumentFragment();
12172 this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
12173 textContent: this.textContent,
12174 textContentStream: this.textContentStream,
12175 container: textLayerFrag,
12176 viewport: this.viewport,
12177 textDivs: this.textDivs,
12178 textContentItemsStr: this.textContentItemsStr,
12179 timeout,
12180 enhanceTextSelection: this.enhanceTextSelection
12181 });
12182 this.textLayerRenderTask.promise.then(() => {
12183 this.textLayerDiv.appendChild(textLayerFrag);
12184
12185 this._finishRendering();
12186
12187 this._updateMatches();
12188 }, function (reason) {});
12189
12190 if (!this._onUpdateTextLayerMatches) {
12191 this._onUpdateTextLayerMatches = evt => {
12192 if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
12193 this._updateMatches();
12194 }
12195 };
12196
12197 this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
12198 }
12199 }
12200
12201 cancel() {
12202 if (this.textLayerRenderTask) {
12203 this.textLayerRenderTask.cancel();
12204 this.textLayerRenderTask = null;
12205 }
12206
12207 if (this._onUpdateTextLayerMatches) {
12208 this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
12209
12210 this._onUpdateTextLayerMatches = null;
12211 }
12212 }
12213
12214 setTextContentStream(readableStream) {
12215 this.cancel();
12216 this.textContentStream = readableStream;
12217 }
12218
12219 setTextContent(textContent) {
12220 this.cancel();
12221 this.textContent = textContent;
12222 }
12223
12224 _convertMatches(matches, matchesLength) {
12225 if (!matches) {
12226 return [];
12227 }
12228
12229 const {
12230 textContentItemsStr
12231 } = this;
12232 let i = 0,
12233 iIndex = 0;
12234 const end = textContentItemsStr.length - 1;
12235 const result = [];
12236
12237 for (let m = 0, mm = matches.length; m < mm; m++) {
12238 let matchIdx = matches[m];
12239
12240 while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
12241 iIndex += textContentItemsStr[i].length;
12242 i++;
12243 }
12244
12245 if (i === textContentItemsStr.length) {
12246 console.error("Could not find a matching mapping");
12247 }
12248
12249 const match = {
12250 begin: {
12251 divIdx: i,
12252 offset: matchIdx - iIndex
12253 }
12254 };
12255 matchIdx += matchesLength[m];
12256
12257 while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
12258 iIndex += textContentItemsStr[i].length;
12259 i++;
12260 }
12261
12262 match.end = {
12263 divIdx: i,
12264 offset: matchIdx - iIndex
12265 };
12266 result.push(match);
12267 }
12268
12269 return result;
12270 }
12271
12272 _renderMatches(matches) {
12273 if (matches.length === 0) {
12274 return;
12275 }
12276
12277 const {
12278 findController,
12279 pageIdx,
12280 textContentItemsStr,
12281 textDivs
12282 } = this;
12283 const isSelectedPage = pageIdx === findController.selected.pageIdx;
12284 const selectedMatchIdx = findController.selected.matchIdx;
12285 const highlightAll = findController.state.highlightAll;
12286 let prevEnd = null;
12287 const infinity = {
12288 divIdx: -1,
12289 offset: undefined
12290 };
12291
12292 function beginText(begin, className) {
12293 const divIdx = begin.divIdx;
12294 textDivs[divIdx].textContent = "";
12295 appendTextToDiv(divIdx, 0, begin.offset, className);
12296 }
12297
12298 function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
12299 const div = textDivs[divIdx];
12300 const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
12301 const node = document.createTextNode(content);
12302
12303 if (className) {
12304 const span = document.createElement("span");
12305 span.className = className;
12306 span.appendChild(node);
12307 div.appendChild(span);
12308 return;
12309 }
12310
12311 div.appendChild(node);
12312 }
12313
12314 let i0 = selectedMatchIdx,
12315 i1 = i0 + 1;
12316
12317 if (highlightAll) {
12318 i0 = 0;
12319 i1 = matches.length;
12320 } else if (!isSelectedPage) {
12321 return;
12322 }
12323
12324 for (let i = i0; i < i1; i++) {
12325 const match = matches[i];
12326 const begin = match.begin;
12327 const end = match.end;
12328 const isSelected = isSelectedPage && i === selectedMatchIdx;
12329 const highlightSuffix = isSelected ? " selected" : "";
12330
12331 if (isSelected) {
12332 findController.scrollMatchIntoView({
12333 element: textDivs[begin.divIdx],
12334 pageIndex: pageIdx,
12335 matchIndex: selectedMatchIdx
12336 });
12337 }
12338
12339 if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
12340 if (prevEnd !== null) {
12341 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
12342 }
12343
12344 beginText(begin);
12345 } else {
12346 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
12347 }
12348
12349 if (begin.divIdx === end.divIdx) {
12350 appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
12351 } else {
12352 appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
12353
12354 for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
12355 textDivs[n0].className = "highlight middle" + highlightSuffix;
12356 }
12357
12358 beginText(end, "highlight end" + highlightSuffix);
12359 }
12360
12361 prevEnd = end;
12362 }
12363
12364 if (prevEnd) {
12365 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
12366 }
12367 }
12368
12369 _updateMatches() {
12370 if (!this.renderingDone) {
12371 return;
12372 }
12373
12374 const {
12375 findController,
12376 matches,
12377 pageIdx,
12378 textContentItemsStr,
12379 textDivs
12380 } = this;
12381 let clearedUntilDivIdx = -1;
12382
12383 for (let i = 0, ii = matches.length; i < ii; i++) {
12384 const match = matches[i];
12385 const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
12386
12387 for (let n = begin, end = match.end.divIdx; n <= end; n++) {
12388 const div = textDivs[n];
12389 div.textContent = textContentItemsStr[n];
12390 div.className = "";
12391 }
12392
12393 clearedUntilDivIdx = match.end.divIdx + 1;
12394 }
12395
12396 if (!findController?.highlightMatches) {
12397 return;
12398 }
12399
12400 const pageMatches = findController.pageMatches[pageIdx] || null;
12401 const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
12402 this.matches = this._convertMatches(pageMatches, pageMatchesLength);
12403
12404 this._renderMatches(this.matches);
12405 }
12406
12407 _bindMouse() {
12408 const div = this.textLayerDiv;
12409 let expandDivsTimer = null;
12410 div.addEventListener("mousedown", evt => {
12411 if (this.enhanceTextSelection && this.textLayerRenderTask) {
12412 this.textLayerRenderTask.expandTextDivs(true);
12413
12414 if (expandDivsTimer) {
12415 clearTimeout(expandDivsTimer);
12416 expandDivsTimer = null;
12417 }
12418
12419 return;
12420 }
12421
12422 const end = div.querySelector(".endOfContent");
12423
12424 if (!end) {
12425 return;
12426 }
12427
12428 let adjustTop = evt.target !== div;
12429 adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
12430
12431 if (adjustTop) {
12432 const divBounds = div.getBoundingClientRect();
12433 const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
12434 end.style.top = (r * 100).toFixed(2) + "%";
12435 }
12436
12437 end.classList.add("active");
12438 });
12439 div.addEventListener("mouseup", () => {
12440 if (this.enhanceTextSelection && this.textLayerRenderTask) {
12441 expandDivsTimer = setTimeout(() => {
12442 if (this.textLayerRenderTask) {
12443 this.textLayerRenderTask.expandTextDivs(false);
12444 }
12445
12446 expandDivsTimer = null;
12447 }, EXPAND_DIVS_TIMEOUT);
12448 return;
12449 }
12450
12451 const end = div.querySelector(".endOfContent");
12452
12453 if (!end) {
12454 return;
12455 }
12456
12457 end.style.top = "";
12458 end.classList.remove("active");
12459 });
12460 }
12461
12462}
12463
12464exports.TextLayerBuilder = TextLayerBuilder;
12465
12466class DefaultTextLayerFactory {
12467 createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
12468 return new TextLayerBuilder({
12469 textLayerDiv,
12470 pageIndex,
12471 viewport,
12472 enhanceTextSelection,
12473 eventBus
12474 });
12475 }
12476
12477}
12478
12479exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
12480
12481/***/ }),
12482/* 33 */
12483/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
12484
12485
12486
12487Object.defineProperty(exports, "__esModule", ({
12488 value: true
12489}));
12490exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
12491
12492var _pdfjsLib = __webpack_require__(5);
12493
12494class XfaLayerBuilder {
12495 constructor({
12496 pageDiv,
12497 pdfPage
12498 }) {
12499 this.pageDiv = pageDiv;
12500 this.pdfPage = pdfPage;
12501 this.div = null;
12502 this._cancelled = false;
12503 }
12504
12505 render(viewport, intent = "display") {
12506 return this.pdfPage.getXfa().then(xfa => {
12507 if (this._cancelled) {
12508 return;
12509 }
12510
12511 const parameters = {
12512 viewport: viewport.clone({
12513 dontFlip: true
12514 }),
12515 div: this.div,
12516 xfa,
12517 page: this.pdfPage
12518 };
12519
12520 if (this.div) {
12521 _pdfjsLib.XfaLayer.update(parameters);
12522 } else {
12523 this.div = document.createElement("div");
12524 this.pageDiv.appendChild(this.div);
12525 parameters.div = this.div;
12526
12527 _pdfjsLib.XfaLayer.render(parameters);
12528 }
12529 });
12530 }
12531
12532 cancel() {
12533 this._cancelled = true;
12534 }
12535
12536 hide() {
12537 if (!this.div) {
12538 return;
12539 }
12540
12541 this.div.hidden = true;
12542 }
12543
12544}
12545
12546exports.XfaLayerBuilder = XfaLayerBuilder;
12547
12548class DefaultXfaLayerFactory {
12549 createXfaLayerBuilder(pageDiv, pdfPage) {
12550 return new XfaLayerBuilder({
12551 pageDiv,
12552 pdfPage
12553 });
12554 }
12555
12556}
12557
12558exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
12559
12560/***/ }),
12561/* 34 */
12562/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
12563
12564
12565
12566Object.defineProperty(exports, "__esModule", ({
12567 value: true
12568}));
12569exports.SecondaryToolbar = void 0;
12570
12571var _ui_utils = __webpack_require__(4);
12572
12573var _pdf_cursor_tools = __webpack_require__(6);
12574
12575var _pdf_single_page_viewer = __webpack_require__(35);
12576
12577class SecondaryToolbar {
12578 constructor(options, mainContainer, eventBus) {
12579 this.toolbar = options.toolbar;
12580 this.toggleButton = options.toggleButton;
12581 this.toolbarButtonContainer = options.toolbarButtonContainer;
12582 this.buttons = [{
12583 element: options.presentationModeButton,
12584 eventName: "presentationmode",
12585 close: true
12586 }, {
12587 element: options.openFileButton,
12588 eventName: "openfile",
12589 close: true
12590 }, {
12591 element: options.printButton,
12592 eventName: "print",
12593 close: true
12594 }, {
12595 element: options.downloadButton,
12596 eventName: "download",
12597 close: true
12598 }, {
12599 element: options.viewBookmarkButton,
12600 eventName: null,
12601 close: true
12602 }, {
12603 element: options.firstPageButton,
12604 eventName: "firstpage",
12605 close: true
12606 }, {
12607 element: options.lastPageButton,
12608 eventName: "lastpage",
12609 close: true
12610 }, {
12611 element: options.pageRotateCwButton,
12612 eventName: "rotatecw",
12613 close: false
12614 }, {
12615 element: options.pageRotateCcwButton,
12616 eventName: "rotateccw",
12617 close: false
12618 }, {
12619 element: options.cursorSelectToolButton,
12620 eventName: "switchcursortool",
12621 eventDetails: {
12622 tool: _pdf_cursor_tools.CursorTool.SELECT
12623 },
12624 close: true
12625 }, {
12626 element: options.cursorHandToolButton,
12627 eventName: "switchcursortool",
12628 eventDetails: {
12629 tool: _pdf_cursor_tools.CursorTool.HAND
12630 },
12631 close: true
12632 }, {
12633 element: options.scrollVerticalButton,
12634 eventName: "switchscrollmode",
12635 eventDetails: {
12636 mode: _ui_utils.ScrollMode.VERTICAL
12637 },
12638 close: true
12639 }, {
12640 element: options.scrollHorizontalButton,
12641 eventName: "switchscrollmode",
12642 eventDetails: {
12643 mode: _ui_utils.ScrollMode.HORIZONTAL
12644 },
12645 close: true
12646 }, {
12647 element: options.scrollWrappedButton,
12648 eventName: "switchscrollmode",
12649 eventDetails: {
12650 mode: _ui_utils.ScrollMode.WRAPPED
12651 },
12652 close: true
12653 }, {
12654 element: options.spreadNoneButton,
12655 eventName: "switchspreadmode",
12656 eventDetails: {
12657 mode: _ui_utils.SpreadMode.NONE
12658 },
12659 close: true
12660 }, {
12661 element: options.spreadOddButton,
12662 eventName: "switchspreadmode",
12663 eventDetails: {
12664 mode: _ui_utils.SpreadMode.ODD
12665 },
12666 close: true
12667 }, {
12668 element: options.spreadEvenButton,
12669 eventName: "switchspreadmode",
12670 eventDetails: {
12671 mode: _ui_utils.SpreadMode.EVEN
12672 },
12673 close: true
12674 }, {
12675 element: options.documentPropertiesButton,
12676 eventName: "documentproperties",
12677 close: true
12678 }];
12679 this.items = {
12680 firstPage: options.firstPageButton,
12681 lastPage: options.lastPageButton,
12682 pageRotateCw: options.pageRotateCwButton,
12683 pageRotateCcw: options.pageRotateCcwButton
12684 };
12685 this.mainContainer = mainContainer;
12686 this.eventBus = eventBus;
12687 this.opened = false;
12688 this.containerHeight = null;
12689 this.previousContainerHeight = null;
12690 this.reset();
12691
12692 this._bindClickListeners();
12693
12694 this._bindCursorToolsListener(options);
12695
12696 this._bindScrollModeListener(options);
12697
12698 this._bindSpreadModeListener(options);
12699
12700 this.eventBus._on("resize", this._setMaxHeight.bind(this));
12701
12702 this.eventBus._on("baseviewerinit", evt => {
12703 if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
12704 this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
12705 } else {
12706 this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
12707 }
12708 });
12709 }
12710
12711 get isOpen() {
12712 return this.opened;
12713 }
12714
12715 setPageNumber(pageNumber) {
12716 this.pageNumber = pageNumber;
12717
12718 this._updateUIState();
12719 }
12720
12721 setPagesCount(pagesCount) {
12722 this.pagesCount = pagesCount;
12723
12724 this._updateUIState();
12725 }
12726
12727 reset() {
12728 this.pageNumber = 0;
12729 this.pagesCount = 0;
12730
12731 this._updateUIState();
12732
12733 this.eventBus.dispatch("secondarytoolbarreset", {
12734 source: this
12735 });
12736 }
12737
12738 _updateUIState() {
12739 this.items.firstPage.disabled = this.pageNumber <= 1;
12740 this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
12741 this.items.pageRotateCw.disabled = this.pagesCount === 0;
12742 this.items.pageRotateCcw.disabled = this.pagesCount === 0;
12743 }
12744
12745 _bindClickListeners() {
12746 this.toggleButton.addEventListener("click", this.toggle.bind(this));
12747
12748 for (const {
12749 element,
12750 eventName,
12751 close,
12752 eventDetails
12753 } of this.buttons) {
12754 element.addEventListener("click", evt => {
12755 if (eventName !== null) {
12756 const details = {
12757 source: this
12758 };
12759
12760 for (const property in eventDetails) {
12761 details[property] = eventDetails[property];
12762 }
12763
12764 this.eventBus.dispatch(eventName, details);
12765 }
12766
12767 if (close) {
12768 this.close();
12769 }
12770 });
12771 }
12772 }
12773
12774 _bindCursorToolsListener(buttons) {
12775 this.eventBus._on("cursortoolchanged", function ({
12776 tool
12777 }) {
12778 buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
12779 buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
12780 });
12781 }
12782
12783 _bindScrollModeListener(buttons) {
12784 function scrollModeChanged({
12785 mode
12786 }) {
12787 buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
12788 buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
12789 buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
12790 const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
12791 buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
12792 buttons.spreadOddButton.disabled = isScrollModeHorizontal;
12793 buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
12794 }
12795
12796 this.eventBus._on("scrollmodechanged", scrollModeChanged);
12797
12798 this.eventBus._on("secondarytoolbarreset", evt => {
12799 if (evt.source === this) {
12800 scrollModeChanged({
12801 mode: _ui_utils.ScrollMode.VERTICAL
12802 });
12803 }
12804 });
12805 }
12806
12807 _bindSpreadModeListener(buttons) {
12808 function spreadModeChanged({
12809 mode
12810 }) {
12811 buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
12812 buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
12813 buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
12814 }
12815
12816 this.eventBus._on("spreadmodechanged", spreadModeChanged);
12817
12818 this.eventBus._on("secondarytoolbarreset", evt => {
12819 if (evt.source === this) {
12820 spreadModeChanged({
12821 mode: _ui_utils.SpreadMode.NONE
12822 });
12823 }
12824 });
12825 }
12826
12827 open() {
12828 if (this.opened) {
12829 return;
12830 }
12831
12832 this.opened = true;
12833
12834 this._setMaxHeight();
12835
12836 this.toggleButton.classList.add("toggled");
12837 this.toggleButton.setAttribute("aria-expanded", "true");
12838 this.toolbar.classList.remove("hidden");
12839 }
12840
12841 close() {
12842 if (!this.opened) {
12843 return;
12844 }
12845
12846 this.opened = false;
12847 this.toolbar.classList.add("hidden");
12848 this.toggleButton.classList.remove("toggled");
12849 this.toggleButton.setAttribute("aria-expanded", "false");
12850 }
12851
12852 toggle() {
12853 if (this.opened) {
12854 this.close();
12855 } else {
12856 this.open();
12857 }
12858 }
12859
12860 _setMaxHeight() {
12861 if (!this.opened) {
12862 return;
12863 }
12864
12865 this.containerHeight = this.mainContainer.clientHeight;
12866
12867 if (this.containerHeight === this.previousContainerHeight) {
12868 return;
12869 }
12870
12871 this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
12872 this.previousContainerHeight = this.containerHeight;
12873 }
12874
12875}
12876
12877exports.SecondaryToolbar = SecondaryToolbar;
12878
12879/***/ }),
12880/* 35 */
12881/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
12882
12883
12884
12885Object.defineProperty(exports, "__esModule", ({
12886 value: true
12887}));
12888exports.PDFSinglePageViewer = void 0;
12889
12890var _base_viewer = __webpack_require__(28);
12891
12892var _pdfjsLib = __webpack_require__(5);
12893
12894class PDFSinglePageViewer extends _base_viewer.BaseViewer {
12895 constructor(options) {
12896 super(options);
12897
12898 this.eventBus._on("pagesinit", evt => {
12899 this._ensurePageViewVisible();
12900 });
12901 }
12902
12903 get _viewerElement() {
12904 return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
12905 }
12906
12907 get _pageWidthScaleFactor() {
12908 return 1;
12909 }
12910
12911 _resetView() {
12912 super._resetView();
12913
12914 this._previousPageNumber = 1;
12915 this._shadowViewer = document.createDocumentFragment();
12916 this._updateScrollDown = null;
12917 }
12918
12919 _ensurePageViewVisible() {
12920 const pageView = this._pages[this._currentPageNumber - 1];
12921 const previousPageView = this._pages[this._previousPageNumber - 1];
12922 const viewerNodes = this.viewer.childNodes;
12923
12924 switch (viewerNodes.length) {
12925 case 0:
12926 this.viewer.appendChild(pageView.div);
12927 break;
12928
12929 case 1:
12930 if (viewerNodes[0] !== previousPageView.div) {
12931 throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
12932 }
12933
12934 if (pageView === previousPageView) {
12935 break;
12936 }
12937
12938 this._shadowViewer.appendChild(previousPageView.div);
12939
12940 this.viewer.appendChild(pageView.div);
12941 this.container.scrollTop = 0;
12942 break;
12943
12944 default:
12945 throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
12946 }
12947
12948 this._previousPageNumber = this._currentPageNumber;
12949 }
12950
12951 _scrollUpdate() {
12952 if (this._updateScrollDown) {
12953 this._updateScrollDown();
12954 }
12955
12956 super._scrollUpdate();
12957 }
12958
12959 _scrollIntoView({
12960 pageDiv,
12961 pageSpot = null,
12962 pageNumber = null
12963 }) {
12964 if (pageNumber) {
12965 this._setCurrentPageNumber(pageNumber);
12966 }
12967
12968 const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
12969
12970 this._ensurePageViewVisible();
12971
12972 this.update();
12973
12974 super._scrollIntoView({
12975 pageDiv,
12976 pageSpot,
12977 pageNumber
12978 });
12979
12980 this._updateScrollDown = () => {
12981 this.scroll.down = scrolledDown;
12982 this._updateScrollDown = null;
12983 };
12984 }
12985
12986 _getVisiblePages() {
12987 return this._getCurrentVisiblePage();
12988 }
12989
12990 _updateHelper(visiblePages) {}
12991
12992 get _isScrollModeHorizontal() {
12993 return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
12994 }
12995
12996 _updateScrollMode() {}
12997
12998 _updateSpreadMode() {}
12999
13000 _getPageAdvance() {
13001 return 1;
13002 }
13003
13004}
13005
13006exports.PDFSinglePageViewer = PDFSinglePageViewer;
13007
13008/***/ }),
13009/* 36 */
13010/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13011
13012
13013
13014Object.defineProperty(exports, "__esModule", ({
13015 value: true
13016}));
13017exports.Toolbar = void 0;
13018
13019var _ui_utils = __webpack_require__(4);
13020
13021const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
13022const SCALE_SELECT_CONTAINER_WIDTH = 140;
13023const SCALE_SELECT_WIDTH = 162;
13024
13025class Toolbar {
13026 constructor(options, eventBus, l10n) {
13027 this.toolbar = options.container;
13028 this.eventBus = eventBus;
13029 this.l10n = l10n;
13030 this.buttons = [{
13031 element: options.previous,
13032 eventName: "previouspage"
13033 }, {
13034 element: options.next,
13035 eventName: "nextpage"
13036 }, {
13037 element: options.zoomIn,
13038 eventName: "zoomin"
13039 }, {
13040 element: options.zoomOut,
13041 eventName: "zoomout"
13042 }, {
13043 element: options.openFile,
13044 eventName: "openfile"
13045 }, {
13046 element: options.print,
13047 eventName: "print"
13048 }, {
13049 element: options.presentationModeButton,
13050 eventName: "presentationmode"
13051 }, {
13052 element: options.download,
13053 eventName: "download"
13054 }, {
13055 element: options.viewBookmark,
13056 eventName: null
13057 }];
13058 this.items = {
13059 numPages: options.numPages,
13060 pageNumber: options.pageNumber,
13061 scaleSelectContainer: options.scaleSelectContainer,
13062 scaleSelect: options.scaleSelect,
13063 customScaleOption: options.customScaleOption,
13064 previous: options.previous,
13065 next: options.next,
13066 zoomIn: options.zoomIn,
13067 zoomOut: options.zoomOut
13068 };
13069 this._wasLocalized = false;
13070 this.reset();
13071
13072 this._bindListeners();
13073 }
13074
13075 setPageNumber(pageNumber, pageLabel) {
13076 this.pageNumber = pageNumber;
13077 this.pageLabel = pageLabel;
13078
13079 this._updateUIState(false);
13080 }
13081
13082 setPagesCount(pagesCount, hasPageLabels) {
13083 this.pagesCount = pagesCount;
13084 this.hasPageLabels = hasPageLabels;
13085
13086 this._updateUIState(true);
13087 }
13088
13089 setPageScale(pageScaleValue, pageScale) {
13090 this.pageScaleValue = (pageScaleValue || pageScale).toString();
13091 this.pageScale = pageScale;
13092
13093 this._updateUIState(false);
13094 }
13095
13096 reset() {
13097 this.pageNumber = 0;
13098 this.pageLabel = null;
13099 this.hasPageLabels = false;
13100 this.pagesCount = 0;
13101 this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
13102 this.pageScale = _ui_utils.DEFAULT_SCALE;
13103
13104 this._updateUIState(true);
13105
13106 this.updateLoadingIndicatorState();
13107 }
13108
13109 _bindListeners() {
13110 const {
13111 pageNumber,
13112 scaleSelect
13113 } = this.items;
13114 const self = this;
13115
13116 for (const {
13117 element,
13118 eventName
13119 } of this.buttons) {
13120 element.addEventListener("click", evt => {
13121 if (eventName !== null) {
13122 this.eventBus.dispatch(eventName, {
13123 source: this
13124 });
13125 }
13126 });
13127 }
13128
13129 pageNumber.addEventListener("click", function () {
13130 this.select();
13131 });
13132 pageNumber.addEventListener("change", function () {
13133 self.eventBus.dispatch("pagenumberchanged", {
13134 source: self,
13135 value: this.value
13136 });
13137 });
13138 scaleSelect.addEventListener("change", function () {
13139 if (this.value === "custom") {
13140 return;
13141 }
13142
13143 self.eventBus.dispatch("scalechanged", {
13144 source: self,
13145 value: this.value
13146 });
13147 });
13148 scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
13149
13150 this.eventBus._on("localized", () => {
13151 this._wasLocalized = true;
13152
13153 this._adjustScaleWidth();
13154
13155 this._updateUIState(true);
13156 });
13157 }
13158
13159 _updateUIState(resetNumPages = false) {
13160 if (!this._wasLocalized) {
13161 return;
13162 }
13163
13164 const {
13165 pageNumber,
13166 pagesCount,
13167 pageScaleValue,
13168 pageScale,
13169 items
13170 } = this;
13171
13172 if (resetNumPages) {
13173 if (this.hasPageLabels) {
13174 items.pageNumber.type = "text";
13175 } else {
13176 items.pageNumber.type = "number";
13177 this.l10n.get("of_pages", {
13178 pagesCount
13179 }).then(msg => {
13180 items.numPages.textContent = msg;
13181 });
13182 }
13183
13184 items.pageNumber.max = pagesCount;
13185 }
13186
13187 if (this.hasPageLabels) {
13188 items.pageNumber.value = this.pageLabel;
13189 this.l10n.get("page_of_pages", {
13190 pageNumber,
13191 pagesCount
13192 }).then(msg => {
13193 items.numPages.textContent = msg;
13194 });
13195 } else {
13196 items.pageNumber.value = pageNumber;
13197 }
13198
13199 items.previous.disabled = pageNumber <= 1;
13200 items.next.disabled = pageNumber >= pagesCount;
13201 items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
13202 items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
13203 this.l10n.get("page_scale_percent", {
13204 scale: Math.round(pageScale * 10000) / 100
13205 }).then(msg => {
13206 let predefinedValueFound = false;
13207
13208 for (const option of items.scaleSelect.options) {
13209 if (option.value !== pageScaleValue) {
13210 option.selected = false;
13211 continue;
13212 }
13213
13214 option.selected = true;
13215 predefinedValueFound = true;
13216 }
13217
13218 if (!predefinedValueFound) {
13219 items.customScaleOption.textContent = msg;
13220 items.customScaleOption.selected = true;
13221 }
13222 });
13223 }
13224
13225 updateLoadingIndicatorState(loading = false) {
13226 const pageNumberInput = this.items.pageNumber;
13227 pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
13228 }
13229
13230 async _adjustScaleWidth() {
13231 const {
13232 items,
13233 l10n
13234 } = this;
13235 const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
13236 let canvas = document.createElement("canvas");
13237 canvas.mozOpaque = true;
13238 let ctx = canvas.getContext("2d", {
13239 alpha: false
13240 });
13241 await _ui_utils.animationStarted;
13242 const {
13243 fontSize,
13244 fontFamily
13245 } = getComputedStyle(items.scaleSelect);
13246 ctx.font = `${fontSize} ${fontFamily}`;
13247 let maxWidth = 0;
13248
13249 for (const predefinedValue of await predefinedValuesPromise) {
13250 const {
13251 width
13252 } = ctx.measureText(predefinedValue);
13253
13254 if (width > maxWidth) {
13255 maxWidth = width;
13256 }
13257 }
13258
13259 const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
13260 maxWidth += 2 * overflow;
13261
13262 if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
13263 items.scaleSelect.style.width = `${maxWidth + overflow}px`;
13264 items.scaleSelectContainer.style.width = `${maxWidth}px`;
13265 }
13266
13267 canvas.width = 0;
13268 canvas.height = 0;
13269 canvas = ctx = null;
13270 }
13271
13272}
13273
13274exports.Toolbar = Toolbar;
13275
13276/***/ }),
13277/* 37 */
13278/***/ ((__unused_webpack_module, exports) => {
13279
13280
13281
13282Object.defineProperty(exports, "__esModule", ({
13283 value: true
13284}));
13285exports.ViewHistory = void 0;
13286const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
13287
13288class ViewHistory {
13289 constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
13290 this.fingerprint = fingerprint;
13291 this.cacheSize = cacheSize;
13292 this._initializedPromise = this._readFromStorage().then(databaseStr => {
13293 const database = JSON.parse(databaseStr || "{}");
13294 let index = -1;
13295
13296 if (!Array.isArray(database.files)) {
13297 database.files = [];
13298 } else {
13299 while (database.files.length >= this.cacheSize) {
13300 database.files.shift();
13301 }
13302
13303 for (let i = 0, ii = database.files.length; i < ii; i++) {
13304 const branch = database.files[i];
13305
13306 if (branch.fingerprint === this.fingerprint) {
13307 index = i;
13308 break;
13309 }
13310 }
13311 }
13312
13313 if (index === -1) {
13314 index = database.files.push({
13315 fingerprint: this.fingerprint
13316 }) - 1;
13317 }
13318
13319 this.file = database.files[index];
13320 this.database = database;
13321 });
13322 }
13323
13324 async _writeToStorage() {
13325 const databaseStr = JSON.stringify(this.database);
13326 localStorage.setItem("pdfjs.history", databaseStr);
13327 }
13328
13329 async _readFromStorage() {
13330 return localStorage.getItem("pdfjs.history");
13331 }
13332
13333 async set(name, val) {
13334 await this._initializedPromise;
13335 this.file[name] = val;
13336 return this._writeToStorage();
13337 }
13338
13339 async setMultiple(properties) {
13340 await this._initializedPromise;
13341
13342 for (const name in properties) {
13343 this.file[name] = properties[name];
13344 }
13345
13346 return this._writeToStorage();
13347 }
13348
13349 async get(name, defaultValue) {
13350 await this._initializedPromise;
13351 const val = this.file[name];
13352 return val !== undefined ? val : defaultValue;
13353 }
13354
13355 async getMultiple(properties) {
13356 await this._initializedPromise;
13357 const values = Object.create(null);
13358
13359 for (const name in properties) {
13360 const val = this.file[name];
13361 values[name] = val !== undefined ? val : properties[name];
13362 }
13363
13364 return values;
13365 }
13366
13367}
13368
13369exports.ViewHistory = ViewHistory;
13370
13371/***/ }),
13372/* 38 */
13373/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13374
13375
13376
13377Object.defineProperty(exports, "__esModule", ({
13378 value: true
13379}));
13380exports.GenericCom = void 0;
13381
13382var _app = __webpack_require__(3);
13383
13384var _preferences = __webpack_require__(39);
13385
13386var _download_manager = __webpack_require__(40);
13387
13388var _genericl10n = __webpack_require__(41);
13389
13390var _generic_scripting = __webpack_require__(43);
13391
13392;
13393const GenericCom = {};
13394exports.GenericCom = GenericCom;
13395
13396class GenericPreferences extends _preferences.BasePreferences {
13397 async _writeToStorage(prefObj) {
13398 localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
13399 }
13400
13401 async _readFromStorage(prefObj) {
13402 return JSON.parse(localStorage.getItem("pdfjs.preferences"));
13403 }
13404
13405}
13406
13407class GenericExternalServices extends _app.DefaultExternalServices {
13408 static createDownloadManager(options) {
13409 return new _download_manager.DownloadManager();
13410 }
13411
13412 static createPreferences() {
13413 return new GenericPreferences();
13414 }
13415
13416 static createL10n({
13417 locale = "en-US"
13418 }) {
13419 return new _genericl10n.GenericL10n(locale);
13420 }
13421
13422 static createScripting({
13423 sandboxBundleSrc
13424 }) {
13425 return new _generic_scripting.GenericScripting(sandboxBundleSrc);
13426 }
13427
13428}
13429
13430_app.PDFViewerApplication.externalServices = GenericExternalServices;
13431
13432/***/ }),
13433/* 39 */
13434/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13435
13436
13437
13438Object.defineProperty(exports, "__esModule", ({
13439 value: true
13440}));
13441exports.BasePreferences = void 0;
13442
13443var _app_options = __webpack_require__(1);
13444
13445class BasePreferences {
13446 constructor() {
13447 if (this.constructor === BasePreferences) {
13448 throw new Error("Cannot initialize BasePreferences.");
13449 }
13450
13451 Object.defineProperty(this, "defaults", {
13452 value: Object.freeze({
13453 "cursorToolOnLoad": 0,
13454 "defaultZoomValue": "",
13455 "disablePageLabels": false,
13456 "enablePermissions": false,
13457 "enablePrintAutoRotate": true,
13458 "enableScripting": true,
13459 "enableWebGL": false,
13460 "externalLinkTarget": 0,
13461 "historyUpdateUrl": false,
13462 "ignoreDestinationZoom": false,
13463 "pdfBugEnabled": false,
13464 "renderer": "canvas",
13465 "renderInteractiveForms": true,
13466 "sidebarViewOnLoad": -1,
13467 "scrollModeOnLoad": -1,
13468 "spreadModeOnLoad": -1,
13469 "textLayerMode": 1,
13470 "useOnlyCssZoom": false,
13471 "viewerCssTheme": 0,
13472 "viewOnLoad": 0,
13473 "disableAutoFetch": false,
13474 "disableFontFace": false,
13475 "disableRange": false,
13476 "disableStream": false
13477 }),
13478 writable: false,
13479 enumerable: true,
13480 configurable: false
13481 });
13482 this.prefs = Object.create(null);
13483 this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
13484 for (const name in this.defaults) {
13485 const prefValue = prefs?.[name];
13486
13487 if (typeof prefValue === typeof this.defaults[name]) {
13488 this.prefs[name] = prefValue;
13489 }
13490 }
13491 });
13492 }
13493
13494 async _writeToStorage(prefObj) {
13495 throw new Error("Not implemented: _writeToStorage");
13496 }
13497
13498 async _readFromStorage(prefObj) {
13499 throw new Error("Not implemented: _readFromStorage");
13500 }
13501
13502 async reset() {
13503 await this._initializedPromise;
13504 this.prefs = Object.create(null);
13505 return this._writeToStorage(this.defaults);
13506 }
13507
13508 async set(name, value) {
13509 await this._initializedPromise;
13510 const defaultValue = this.defaults[name];
13511
13512 if (defaultValue === undefined) {
13513 throw new Error(`Set preference: "${name}" is undefined.`);
13514 } else if (value === undefined) {
13515 throw new Error("Set preference: no value is specified.");
13516 }
13517
13518 const valueType = typeof value;
13519 const defaultType = typeof defaultValue;
13520
13521 if (valueType !== defaultType) {
13522 if (valueType === "number" && defaultType === "string") {
13523 value = value.toString();
13524 } else {
13525 throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
13526 }
13527 } else {
13528 if (valueType === "number" && !Number.isInteger(value)) {
13529 throw new Error(`Set preference: "${value}" must be an integer.`);
13530 }
13531 }
13532
13533 this.prefs[name] = value;
13534 return this._writeToStorage(this.prefs);
13535 }
13536
13537 async get(name) {
13538 await this._initializedPromise;
13539 const defaultValue = this.defaults[name],
13540 prefValue = this.prefs[name];
13541
13542 if (defaultValue === undefined) {
13543 throw new Error(`Get preference: "${name}" is undefined.`);
13544 }
13545
13546 return prefValue !== undefined ? prefValue : defaultValue;
13547 }
13548
13549 async getAll() {
13550 await this._initializedPromise;
13551 const obj = Object.create(null);
13552
13553 for (const name in this.defaults) {
13554 const prefValue = this.prefs[name];
13555 obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
13556 }
13557
13558 return obj;
13559 }
13560
13561}
13562
13563exports.BasePreferences = BasePreferences;
13564
13565/***/ }),
13566/* 40 */
13567/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13568
13569
13570
13571Object.defineProperty(exports, "__esModule", ({
13572 value: true
13573}));
13574exports.DownloadManager = void 0;
13575
13576var _pdfjsLib = __webpack_require__(5);
13577
13578var _viewer_compatibility = __webpack_require__(2);
13579
13580;
13581
13582function download(blobUrl, filename) {
13583 const a = document.createElement("a");
13584
13585 if (!a.click) {
13586 throw new Error('DownloadManager: "a.click()" is not supported.');
13587 }
13588
13589 a.href = blobUrl;
13590 a.target = "_parent";
13591
13592 if ("download" in a) {
13593 a.download = filename;
13594 }
13595
13596 (document.body || document.documentElement).appendChild(a);
13597 a.click();
13598 a.remove();
13599}
13600
13601class DownloadManager {
13602 constructor() {
13603 this._openBlobUrls = new WeakMap();
13604 }
13605
13606 downloadUrl(url, filename) {
13607 if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
13608 return;
13609 }
13610
13611 download(url + "#pdfjs.action=download", filename);
13612 }
13613
13614 downloadData(data, filename, contentType) {
13615 const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
13616 download(blobUrl, filename);
13617 }
13618
13619 openOrDownloadData(element, data, filename) {
13620 const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
13621 const contentType = isPdfData ? "application/pdf" : "";
13622
13623 if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
13624 let blobUrl = this._openBlobUrls.get(element);
13625
13626 if (!blobUrl) {
13627 blobUrl = URL.createObjectURL(new Blob([data], {
13628 type: contentType
13629 }));
13630
13631 this._openBlobUrls.set(element, blobUrl);
13632 }
13633
13634 let viewerUrl;
13635 viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
13636
13637 try {
13638 window.open(viewerUrl);
13639 return true;
13640 } catch (ex) {
13641 console.error(`openOrDownloadData: ${ex}`);
13642 URL.revokeObjectURL(blobUrl);
13643
13644 this._openBlobUrls.delete(element);
13645 }
13646 }
13647
13648 this.downloadData(data, filename, contentType);
13649 return false;
13650 }
13651
13652 download(blob, url, filename, sourceEventType = "download") {
13653 if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
13654 this.downloadUrl(url, filename);
13655 return;
13656 }
13657
13658 const blobUrl = URL.createObjectURL(blob);
13659 download(blobUrl, filename);
13660 }
13661
13662}
13663
13664exports.DownloadManager = DownloadManager;
13665
13666/***/ }),
13667/* 41 */
13668/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
13669
13670
13671
13672Object.defineProperty(exports, "__esModule", ({
13673 value: true
13674}));
13675exports.GenericL10n = void 0;
13676
13677__webpack_require__(42);
13678
13679var _l10n_utils = __webpack_require__(30);
13680
13681const webL10n = document.webL10n;
13682
13683class GenericL10n {
13684 constructor(lang) {
13685 this._lang = lang;
13686 this._ready = new Promise((resolve, reject) => {
13687 webL10n.setLanguage(lang, () => {
13688 resolve(webL10n);
13689 });
13690 });
13691 }
13692
13693 async getLanguage() {
13694 const l10n = await this._ready;
13695 return l10n.getLanguage();
13696 }
13697
13698 async getDirection() {
13699 const l10n = await this._ready;
13700 return l10n.getDirection();
13701 }
13702
13703 async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
13704 const l10n = await this._ready;
13705 return l10n.get(key, args, fallback);
13706 }
13707
13708 async translate(element) {
13709 const l10n = await this._ready;
13710 return l10n.translate(element);
13711 }
13712
13713}
13714
13715exports.GenericL10n = GenericL10n;
13716
13717/***/ }),
13718/* 42 */
13719/***/ (() => {
13720
13721
13722
13723document.webL10n = function (window, document, undefined) {
13724 var gL10nData = {};
13725 var gTextData = '';
13726 var gTextProp = 'textContent';
13727 var gLanguage = '';
13728 var gMacros = {};
13729 var gReadyState = 'loading';
13730 var gAsyncResourceLoading = true;
13731
13732 function getL10nResourceLinks() {
13733 return document.querySelectorAll('link[type="application/l10n"]');
13734 }
13735
13736 function getL10nDictionary() {
13737 var script = document.querySelector('script[type="application/l10n"]');
13738 return script ? JSON.parse(script.innerHTML) : null;
13739 }
13740
13741 function getTranslatableChildren(element) {
13742 return element ? element.querySelectorAll('*[data-l10n-id]') : [];
13743 }
13744
13745 function getL10nAttributes(element) {
13746 if (!element) return {};
13747 var l10nId = element.getAttribute('data-l10n-id');
13748 var l10nArgs = element.getAttribute('data-l10n-args');
13749 var args = {};
13750
13751 if (l10nArgs) {
13752 try {
13753 args = JSON.parse(l10nArgs);
13754 } catch (e) {
13755 console.warn('could not parse arguments for #' + l10nId);
13756 }
13757 }
13758
13759 return {
13760 id: l10nId,
13761 args: args
13762 };
13763 }
13764
13765 function xhrLoadText(url, onSuccess, onFailure) {
13766 onSuccess = onSuccess || function _onSuccess(data) {};
13767
13768 onFailure = onFailure || function _onFailure() {};
13769
13770 var xhr = new XMLHttpRequest();
13771 xhr.open('GET', url, gAsyncResourceLoading);
13772
13773 if (xhr.overrideMimeType) {
13774 xhr.overrideMimeType('text/plain; charset=utf-8');
13775 }
13776
13777 xhr.onreadystatechange = function () {
13778 if (xhr.readyState == 4) {
13779 if (xhr.status == 200 || xhr.status === 0) {
13780 onSuccess(xhr.responseText);
13781 } else {
13782 onFailure();
13783 }
13784 }
13785 };
13786
13787 xhr.onerror = onFailure;
13788 xhr.ontimeout = onFailure;
13789
13790 try {
13791 xhr.send(null);
13792 } catch (e) {
13793 onFailure();
13794 }
13795 }
13796
13797 function parseResource(href, lang, successCallback, failureCallback) {
13798 var baseURL = href.replace(/[^\/]*$/, '') || './';
13799
13800 function evalString(text) {
13801 if (text.lastIndexOf('\\') < 0) return text;
13802 return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
13803 }
13804
13805 function parseProperties(text, parsedPropertiesCallback) {
13806 var dictionary = {};
13807 var reBlank = /^\s*|\s*$/;
13808 var reComment = /^\s*#|^\s*$/;
13809 var reSection = /^\s*\[(.*)\]\s*$/;
13810 var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
13811 var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
13812
13813 function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
13814 var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
13815 var currentLang = '*';
13816 var genericLang = lang.split('-', 1)[0];
13817 var skipLang = false;
13818 var match = '';
13819
13820 function nextEntry() {
13821 while (true) {
13822 if (!entries.length) {
13823 parsedRawLinesCallback();
13824 return;
13825 }
13826
13827 var line = entries.shift();
13828 if (reComment.test(line)) continue;
13829
13830 if (extendedSyntax) {
13831 match = reSection.exec(line);
13832
13833 if (match) {
13834 currentLang = match[1].toLowerCase();
13835 skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
13836 continue;
13837 } else if (skipLang) {
13838 continue;
13839 }
13840
13841 match = reImport.exec(line);
13842
13843 if (match) {
13844 loadImport(baseURL + match[1], nextEntry);
13845 return;
13846 }
13847 }
13848
13849 var tmp = line.match(reSplit);
13850
13851 if (tmp && tmp.length == 3) {
13852 dictionary[tmp[1]] = evalString(tmp[2]);
13853 }
13854 }
13855 }
13856
13857 nextEntry();
13858 }
13859
13860 function loadImport(url, callback) {
13861 xhrLoadText(url, function (content) {
13862 parseRawLines(content, false, callback);
13863 }, function () {
13864 console.warn(url + ' not found.');
13865 callback();
13866 });
13867 }
13868
13869 parseRawLines(text, true, function () {
13870 parsedPropertiesCallback(dictionary);
13871 });
13872 }
13873
13874 xhrLoadText(href, function (response) {
13875 gTextData += response;
13876 parseProperties(response, function (data) {
13877 for (var key in data) {
13878 var id,
13879 prop,
13880 index = key.lastIndexOf('.');
13881
13882 if (index > 0) {
13883 id = key.substring(0, index);
13884 prop = key.substring(index + 1);
13885 } else {
13886 id = key;
13887 prop = gTextProp;
13888 }
13889
13890 if (!gL10nData[id]) {
13891 gL10nData[id] = {};
13892 }
13893
13894 gL10nData[id][prop] = data[key];
13895 }
13896
13897 if (successCallback) {
13898 successCallback();
13899 }
13900 });
13901 }, failureCallback);
13902 }
13903
13904 function loadLocale(lang, callback) {
13905 if (lang) {
13906 lang = lang.toLowerCase();
13907 }
13908
13909 callback = callback || function _callback() {};
13910
13911 clear();
13912 gLanguage = lang;
13913 var langLinks = getL10nResourceLinks();
13914 var langCount = langLinks.length;
13915
13916 if (langCount === 0) {
13917 var dict = getL10nDictionary();
13918
13919 if (dict && dict.locales && dict.default_locale) {
13920 console.log('using the embedded JSON directory, early way out');
13921 gL10nData = dict.locales[lang];
13922
13923 if (!gL10nData) {
13924 var defaultLocale = dict.default_locale.toLowerCase();
13925
13926 for (var anyCaseLang in dict.locales) {
13927 anyCaseLang = anyCaseLang.toLowerCase();
13928
13929 if (anyCaseLang === lang) {
13930 gL10nData = dict.locales[lang];
13931 break;
13932 } else if (anyCaseLang === defaultLocale) {
13933 gL10nData = dict.locales[defaultLocale];
13934 }
13935 }
13936 }
13937
13938 callback();
13939 } else {
13940 console.log('no resource to load, early way out');
13941 }
13942
13943 gReadyState = 'complete';
13944 return;
13945 }
13946
13947 var onResourceLoaded = null;
13948 var gResourceCount = 0;
13949
13950 onResourceLoaded = function () {
13951 gResourceCount++;
13952
13953 if (gResourceCount >= langCount) {
13954 callback();
13955 gReadyState = 'complete';
13956 }
13957 };
13958
13959 function L10nResourceLink(link) {
13960 var href = link.href;
13961
13962 this.load = function (lang, callback) {
13963 parseResource(href, lang, callback, function () {
13964 console.warn(href + ' not found.');
13965 console.warn('"' + lang + '" resource not found');
13966 gLanguage = '';
13967 callback();
13968 });
13969 };
13970 }
13971
13972 for (var i = 0; i < langCount; i++) {
13973 var resource = new L10nResourceLink(langLinks[i]);
13974 resource.load(lang, onResourceLoaded);
13975 }
13976 }
13977
13978 function clear() {
13979 gL10nData = {};
13980 gTextData = '';
13981 gLanguage = '';
13982 }
13983
13984 function getPluralRules(lang) {
13985 var locales2rules = {
13986 'af': 3,
13987 'ak': 4,
13988 'am': 4,
13989 'ar': 1,
13990 'asa': 3,
13991 'az': 0,
13992 'be': 11,
13993 'bem': 3,
13994 'bez': 3,
13995 'bg': 3,
13996 'bh': 4,
13997 'bm': 0,
13998 'bn': 3,
13999 'bo': 0,
14000 'br': 20,
14001 'brx': 3,
14002 'bs': 11,
14003 'ca': 3,
14004 'cgg': 3,
14005 'chr': 3,
14006 'cs': 12,
14007 'cy': 17,
14008 'da': 3,
14009 'de': 3,
14010 'dv': 3,
14011 'dz': 0,
14012 'ee': 3,
14013 'el': 3,
14014 'en': 3,
14015 'eo': 3,
14016 'es': 3,
14017 'et': 3,
14018 'eu': 3,
14019 'fa': 0,
14020 'ff': 5,
14021 'fi': 3,
14022 'fil': 4,
14023 'fo': 3,
14024 'fr': 5,
14025 'fur': 3,
14026 'fy': 3,
14027 'ga': 8,
14028 'gd': 24,
14029 'gl': 3,
14030 'gsw': 3,
14031 'gu': 3,
14032 'guw': 4,
14033 'gv': 23,
14034 'ha': 3,
14035 'haw': 3,
14036 'he': 2,
14037 'hi': 4,
14038 'hr': 11,
14039 'hu': 0,
14040 'id': 0,
14041 'ig': 0,
14042 'ii': 0,
14043 'is': 3,
14044 'it': 3,
14045 'iu': 7,
14046 'ja': 0,
14047 'jmc': 3,
14048 'jv': 0,
14049 'ka': 0,
14050 'kab': 5,
14051 'kaj': 3,
14052 'kcg': 3,
14053 'kde': 0,
14054 'kea': 0,
14055 'kk': 3,
14056 'kl': 3,
14057 'km': 0,
14058 'kn': 0,
14059 'ko': 0,
14060 'ksb': 3,
14061 'ksh': 21,
14062 'ku': 3,
14063 'kw': 7,
14064 'lag': 18,
14065 'lb': 3,
14066 'lg': 3,
14067 'ln': 4,
14068 'lo': 0,
14069 'lt': 10,
14070 'lv': 6,
14071 'mas': 3,
14072 'mg': 4,
14073 'mk': 16,
14074 'ml': 3,
14075 'mn': 3,
14076 'mo': 9,
14077 'mr': 3,
14078 'ms': 0,
14079 'mt': 15,
14080 'my': 0,
14081 'nah': 3,
14082 'naq': 7,
14083 'nb': 3,
14084 'nd': 3,
14085 'ne': 3,
14086 'nl': 3,
14087 'nn': 3,
14088 'no': 3,
14089 'nr': 3,
14090 'nso': 4,
14091 'ny': 3,
14092 'nyn': 3,
14093 'om': 3,
14094 'or': 3,
14095 'pa': 3,
14096 'pap': 3,
14097 'pl': 13,
14098 'ps': 3,
14099 'pt': 3,
14100 'rm': 3,
14101 'ro': 9,
14102 'rof': 3,
14103 'ru': 11,
14104 'rwk': 3,
14105 'sah': 0,
14106 'saq': 3,
14107 'se': 7,
14108 'seh': 3,
14109 'ses': 0,
14110 'sg': 0,
14111 'sh': 11,
14112 'shi': 19,
14113 'sk': 12,
14114 'sl': 14,
14115 'sma': 7,
14116 'smi': 7,
14117 'smj': 7,
14118 'smn': 7,
14119 'sms': 7,
14120 'sn': 3,
14121 'so': 3,
14122 'sq': 3,
14123 'sr': 11,
14124 'ss': 3,
14125 'ssy': 3,
14126 'st': 3,
14127 'sv': 3,
14128 'sw': 3,
14129 'syr': 3,
14130 'ta': 3,
14131 'te': 3,
14132 'teo': 3,
14133 'th': 0,
14134 'ti': 4,
14135 'tig': 3,
14136 'tk': 3,
14137 'tl': 4,
14138 'tn': 3,
14139 'to': 0,
14140 'tr': 0,
14141 'ts': 3,
14142 'tzm': 22,
14143 'uk': 11,
14144 'ur': 3,
14145 've': 3,
14146 'vi': 0,
14147 'vun': 3,
14148 'wa': 4,
14149 'wae': 3,
14150 'wo': 0,
14151 'xh': 3,
14152 'xog': 3,
14153 'yo': 0,
14154 'zh': 0,
14155 'zu': 3
14156 };
14157
14158 function isIn(n, list) {
14159 return list.indexOf(n) !== -1;
14160 }
14161
14162 function isBetween(n, start, end) {
14163 return start <= n && n <= end;
14164 }
14165
14166 var pluralRules = {
14167 '0': function (n) {
14168 return 'other';
14169 },
14170 '1': function (n) {
14171 if (isBetween(n % 100, 3, 10)) return 'few';
14172 if (n === 0) return 'zero';
14173 if (isBetween(n % 100, 11, 99)) return 'many';
14174 if (n == 2) return 'two';
14175 if (n == 1) return 'one';
14176 return 'other';
14177 },
14178 '2': function (n) {
14179 if (n !== 0 && n % 10 === 0) return 'many';
14180 if (n == 2) return 'two';
14181 if (n == 1) return 'one';
14182 return 'other';
14183 },
14184 '3': function (n) {
14185 if (n == 1) return 'one';
14186 return 'other';
14187 },
14188 '4': function (n) {
14189 if (isBetween(n, 0, 1)) return 'one';
14190 return 'other';
14191 },
14192 '5': function (n) {
14193 if (isBetween(n, 0, 2) && n != 2) return 'one';
14194 return 'other';
14195 },
14196 '6': function (n) {
14197 if (n === 0) return 'zero';
14198 if (n % 10 == 1 && n % 100 != 11) return 'one';
14199 return 'other';
14200 },
14201 '7': function (n) {
14202 if (n == 2) return 'two';
14203 if (n == 1) return 'one';
14204 return 'other';
14205 },
14206 '8': function (n) {
14207 if (isBetween(n, 3, 6)) return 'few';
14208 if (isBetween(n, 7, 10)) return 'many';
14209 if (n == 2) return 'two';
14210 if (n == 1) return 'one';
14211 return 'other';
14212 },
14213 '9': function (n) {
14214 if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
14215 if (n == 1) return 'one';
14216 return 'other';
14217 },
14218 '10': function (n) {
14219 if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
14220 if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
14221 return 'other';
14222 },
14223 '11': function (n) {
14224 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
14225 if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
14226 if (n % 10 == 1 && n % 100 != 11) return 'one';
14227 return 'other';
14228 },
14229 '12': function (n) {
14230 if (isBetween(n, 2, 4)) return 'few';
14231 if (n == 1) return 'one';
14232 return 'other';
14233 },
14234 '13': function (n) {
14235 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
14236 if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
14237 if (n == 1) return 'one';
14238 return 'other';
14239 },
14240 '14': function (n) {
14241 if (isBetween(n % 100, 3, 4)) return 'few';
14242 if (n % 100 == 2) return 'two';
14243 if (n % 100 == 1) return 'one';
14244 return 'other';
14245 },
14246 '15': function (n) {
14247 if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
14248 if (isBetween(n % 100, 11, 19)) return 'many';
14249 if (n == 1) return 'one';
14250 return 'other';
14251 },
14252 '16': function (n) {
14253 if (n % 10 == 1 && n != 11) return 'one';
14254 return 'other';
14255 },
14256 '17': function (n) {
14257 if (n == 3) return 'few';
14258 if (n === 0) return 'zero';
14259 if (n == 6) return 'many';
14260 if (n == 2) return 'two';
14261 if (n == 1) return 'one';
14262 return 'other';
14263 },
14264 '18': function (n) {
14265 if (n === 0) return 'zero';
14266 if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
14267 return 'other';
14268 },
14269 '19': function (n) {
14270 if (isBetween(n, 2, 10)) return 'few';
14271 if (isBetween(n, 0, 1)) return 'one';
14272 return 'other';
14273 },
14274 '20': function (n) {
14275 if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
14276 if (n % 1000000 === 0 && n !== 0) return 'many';
14277 if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
14278 if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
14279 return 'other';
14280 },
14281 '21': function (n) {
14282 if (n === 0) return 'zero';
14283 if (n == 1) return 'one';
14284 return 'other';
14285 },
14286 '22': function (n) {
14287 if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
14288 return 'other';
14289 },
14290 '23': function (n) {
14291 if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
14292 return 'other';
14293 },
14294 '24': function (n) {
14295 if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
14296 if (isIn(n, [2, 12])) return 'two';
14297 if (isIn(n, [1, 11])) return 'one';
14298 return 'other';
14299 }
14300 };
14301 var index = locales2rules[lang.replace(/-.*$/, '')];
14302
14303 if (!(index in pluralRules)) {
14304 console.warn('plural form unknown for [' + lang + ']');
14305 return function () {
14306 return 'other';
14307 };
14308 }
14309
14310 return pluralRules[index];
14311 }
14312
14313 gMacros.plural = function (str, param, key, prop) {
14314 var n = parseFloat(param);
14315 if (isNaN(n)) return str;
14316 if (prop != gTextProp) return str;
14317
14318 if (!gMacros._pluralRules) {
14319 gMacros._pluralRules = getPluralRules(gLanguage);
14320 }
14321
14322 var index = '[' + gMacros._pluralRules(n) + ']';
14323
14324 if (n === 0 && key + '[zero]' in gL10nData) {
14325 str = gL10nData[key + '[zero]'][prop];
14326 } else if (n == 1 && key + '[one]' in gL10nData) {
14327 str = gL10nData[key + '[one]'][prop];
14328 } else if (n == 2 && key + '[two]' in gL10nData) {
14329 str = gL10nData[key + '[two]'][prop];
14330 } else if (key + index in gL10nData) {
14331 str = gL10nData[key + index][prop];
14332 } else if (key + '[other]' in gL10nData) {
14333 str = gL10nData[key + '[other]'][prop];
14334 }
14335
14336 return str;
14337 };
14338
14339 function getL10nData(key, args, fallback) {
14340 var data = gL10nData[key];
14341
14342 if (!data) {
14343 console.warn('#' + key + ' is undefined.');
14344
14345 if (!fallback) {
14346 return null;
14347 }
14348
14349 data = fallback;
14350 }
14351
14352 var rv = {};
14353
14354 for (var prop in data) {
14355 var str = data[prop];
14356 str = substIndexes(str, args, key, prop);
14357 str = substArguments(str, args, key);
14358 rv[prop] = str;
14359 }
14360
14361 return rv;
14362 }
14363
14364 function substIndexes(str, args, key, prop) {
14365 var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
14366 var reMatch = reIndex.exec(str);
14367 if (!reMatch || !reMatch.length) return str;
14368 var macroName = reMatch[1];
14369 var paramName = reMatch[2];
14370 var param;
14371
14372 if (args && paramName in args) {
14373 param = args[paramName];
14374 } else if (paramName in gL10nData) {
14375 param = gL10nData[paramName];
14376 }
14377
14378 if (macroName in gMacros) {
14379 var macro = gMacros[macroName];
14380 str = macro(str, param, key, prop);
14381 }
14382
14383 return str;
14384 }
14385
14386 function substArguments(str, args, key) {
14387 var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
14388 return str.replace(reArgs, function (matched_text, arg) {
14389 if (args && arg in args) {
14390 return args[arg];
14391 }
14392
14393 if (arg in gL10nData) {
14394 return gL10nData[arg];
14395 }
14396
14397 console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
14398 return matched_text;
14399 });
14400 }
14401
14402 function translateElement(element) {
14403 var l10n = getL10nAttributes(element);
14404 if (!l10n.id) return;
14405 var data = getL10nData(l10n.id, l10n.args);
14406
14407 if (!data) {
14408 console.warn('#' + l10n.id + ' is undefined.');
14409 return;
14410 }
14411
14412 if (data[gTextProp]) {
14413 if (getChildElementCount(element) === 0) {
14414 element[gTextProp] = data[gTextProp];
14415 } else {
14416 var children = element.childNodes;
14417 var found = false;
14418
14419 for (var i = 0, l = children.length; i < l; i++) {
14420 if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
14421 if (found) {
14422 children[i].nodeValue = '';
14423 } else {
14424 children[i].nodeValue = data[gTextProp];
14425 found = true;
14426 }
14427 }
14428 }
14429
14430 if (!found) {
14431 var textNode = document.createTextNode(data[gTextProp]);
14432 element.insertBefore(textNode, element.firstChild);
14433 }
14434 }
14435
14436 delete data[gTextProp];
14437 }
14438
14439 for (var k in data) {
14440 element[k] = data[k];
14441 }
14442 }
14443
14444 function getChildElementCount(element) {
14445 if (element.children) {
14446 return element.children.length;
14447 }
14448
14449 if (typeof element.childElementCount !== 'undefined') {
14450 return element.childElementCount;
14451 }
14452
14453 var count = 0;
14454
14455 for (var i = 0; i < element.childNodes.length; i++) {
14456 count += element.nodeType === 1 ? 1 : 0;
14457 }
14458
14459 return count;
14460 }
14461
14462 function translateFragment(element) {
14463 element = element || document.documentElement;
14464 var children = getTranslatableChildren(element);
14465 var elementCount = children.length;
14466
14467 for (var i = 0; i < elementCount; i++) {
14468 translateElement(children[i]);
14469 }
14470
14471 translateElement(element);
14472 }
14473
14474 return {
14475 get: function (key, args, fallbackString) {
14476 var index = key.lastIndexOf('.');
14477 var prop = gTextProp;
14478
14479 if (index > 0) {
14480 prop = key.substring(index + 1);
14481 key = key.substring(0, index);
14482 }
14483
14484 var fallback;
14485
14486 if (fallbackString) {
14487 fallback = {};
14488 fallback[prop] = fallbackString;
14489 }
14490
14491 var data = getL10nData(key, args, fallback);
14492
14493 if (data && prop in data) {
14494 return data[prop];
14495 }
14496
14497 return '{{' + key + '}}';
14498 },
14499 getData: function () {
14500 return gL10nData;
14501 },
14502 getText: function () {
14503 return gTextData;
14504 },
14505 getLanguage: function () {
14506 return gLanguage;
14507 },
14508 setLanguage: function (lang, callback) {
14509 loadLocale(lang, function () {
14510 if (callback) callback();
14511 });
14512 },
14513 getDirection: function () {
14514 var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
14515 var shortCode = gLanguage.split('-', 1)[0];
14516 return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
14517 },
14518 translate: translateFragment,
14519 getReadyState: function () {
14520 return gReadyState;
14521 },
14522 ready: function (callback) {
14523 if (!callback) {
14524 return;
14525 } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
14526 window.setTimeout(function () {
14527 callback();
14528 });
14529 } else if (document.addEventListener) {
14530 document.addEventListener('localized', function once() {
14531 document.removeEventListener('localized', once);
14532 callback();
14533 });
14534 }
14535 }
14536 };
14537}(window, document);
14538
14539/***/ }),
14540/* 43 */
14541/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
14542
14543
14544
14545Object.defineProperty(exports, "__esModule", ({
14546 value: true
14547}));
14548exports.docPropertiesLookup = docPropertiesLookup;
14549exports.GenericScripting = void 0;
14550
14551var _pdfjsLib = __webpack_require__(5);
14552
14553async function docPropertiesLookup(pdfDocument) {
14554 const url = "",
14555 baseUrl = url.split("#")[0];
14556 let {
14557 info,
14558 metadata,
14559 contentDispositionFilename,
14560 contentLength
14561 } = await pdfDocument.getMetadata();
14562
14563 if (!contentLength) {
14564 const {
14565 length
14566 } = await pdfDocument.getDownloadInfo();
14567 contentLength = length;
14568 }
14569
14570 return { ...info,
14571 baseURL: baseUrl,
14572 filesize: contentLength,
14573 filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
14574 metadata: metadata?.getRaw(),
14575 authors: metadata?.get("dc:creator"),
14576 numPages: pdfDocument.numPages,
14577 URL: url
14578 };
14579}
14580
14581class GenericScripting {
14582 constructor(sandboxBundleSrc) {
14583 this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
14584 return window.pdfjsSandbox.QuickJSSandbox();
14585 });
14586 }
14587
14588 async createSandbox(data) {
14589 const sandbox = await this._ready;
14590 sandbox.create(data);
14591 }
14592
14593 async dispatchEventInSandbox(event) {
14594 const sandbox = await this._ready;
14595 sandbox.dispatchEvent(event);
14596 }
14597
14598 async destroySandbox() {
14599 const sandbox = await this._ready;
14600 sandbox.nukeSandbox();
14601 }
14602
14603}
14604
14605exports.GenericScripting = GenericScripting;
14606
14607/***/ }),
14608/* 44 */
14609/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
14610
14611
14612
14613Object.defineProperty(exports, "__esModule", ({
14614 value: true
14615}));
14616exports.PDFPrintService = PDFPrintService;
14617
14618var _app = __webpack_require__(3);
14619
14620var _viewer_compatibility = __webpack_require__(2);
14621
14622let activeService = null;
14623let overlayManager = null;
14624
14625function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
14626 const scratchCanvas = activeService.scratchCanvas;
14627 const PRINT_UNITS = printResolution / 72.0;
14628 scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
14629 scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
14630 const ctx = scratchCanvas.getContext("2d");
14631 ctx.save();
14632 ctx.fillStyle = "rgb(255, 255, 255)";
14633 ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
14634 ctx.restore();
14635 return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
14636 const renderContext = {
14637 canvasContext: ctx,
14638 transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
14639 viewport: pdfPage.getViewport({
14640 scale: 1,
14641 rotation: size.rotation
14642 }),
14643 intent: "print",
14644 annotationStorage: pdfDocument.annotationStorage,
14645 optionalContentConfigPromise
14646 };
14647 return pdfPage.render(renderContext).promise;
14648 });
14649}
14650
14651function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
14652 this.pdfDocument = pdfDocument;
14653 this.pagesOverview = pagesOverview;
14654 this.printContainer = printContainer;
14655 this._printResolution = printResolution || 150;
14656 this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
14657 this.l10n = l10n;
14658 this.currentPage = -1;
14659 this.scratchCanvas = document.createElement("canvas");
14660}
14661
14662PDFPrintService.prototype = {
14663 layout() {
14664 this.throwIfInactive();
14665 const body = document.querySelector("body");
14666 body.setAttribute("data-pdfjsprinting", true);
14667 const hasEqualPageSizes = this.pagesOverview.every(function (size) {
14668 return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
14669 }, this);
14670
14671 if (!hasEqualPageSizes) {
14672 console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
14673 }
14674
14675 this.pageStyleSheet = document.createElement("style");
14676 const pageSize = this.pagesOverview[0];
14677 this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
14678 body.appendChild(this.pageStyleSheet);
14679 },
14680
14681 destroy() {
14682 if (activeService !== this) {
14683 return;
14684 }
14685
14686 this.printContainer.textContent = "";
14687 const body = document.querySelector("body");
14688 body.removeAttribute("data-pdfjsprinting");
14689
14690 if (this.pageStyleSheet) {
14691 this.pageStyleSheet.remove();
14692 this.pageStyleSheet = null;
14693 }
14694
14695 this.scratchCanvas.width = this.scratchCanvas.height = 0;
14696 this.scratchCanvas = null;
14697 activeService = null;
14698 ensureOverlay().then(function () {
14699 if (overlayManager.active !== "printServiceOverlay") {
14700 return;
14701 }
14702
14703 overlayManager.close("printServiceOverlay");
14704 });
14705 },
14706
14707 renderPages() {
14708 const pageCount = this.pagesOverview.length;
14709
14710 const renderNextPage = (resolve, reject) => {
14711 this.throwIfInactive();
14712
14713 if (++this.currentPage >= pageCount) {
14714 renderProgress(pageCount, pageCount, this.l10n);
14715 resolve();
14716 return;
14717 }
14718
14719 const index = this.currentPage;
14720 renderProgress(index, pageCount, this.l10n);
14721 renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
14722 renderNextPage(resolve, reject);
14723 }, reject);
14724 };
14725
14726 return new Promise(renderNextPage);
14727 },
14728
14729 useRenderedPage() {
14730 this.throwIfInactive();
14731 const img = document.createElement("img");
14732 const scratchCanvas = this.scratchCanvas;
14733
14734 if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
14735 scratchCanvas.toBlob(function (blob) {
14736 img.src = URL.createObjectURL(blob);
14737 });
14738 } else {
14739 img.src = scratchCanvas.toDataURL();
14740 }
14741
14742 const wrapper = document.createElement("div");
14743 wrapper.appendChild(img);
14744 this.printContainer.appendChild(wrapper);
14745 return new Promise(function (resolve, reject) {
14746 img.onload = resolve;
14747 img.onerror = reject;
14748 });
14749 },
14750
14751 performPrint() {
14752 this.throwIfInactive();
14753 return new Promise(resolve => {
14754 setTimeout(() => {
14755 if (!this.active) {
14756 resolve();
14757 return;
14758 }
14759
14760 print.call(window);
14761 setTimeout(resolve, 20);
14762 }, 0);
14763 });
14764 },
14765
14766 get active() {
14767 return this === activeService;
14768 },
14769
14770 throwIfInactive() {
14771 if (!this.active) {
14772 throw new Error("This print request was cancelled or completed.");
14773 }
14774 }
14775
14776};
14777const print = window.print;
14778
14779window.print = function () {
14780 if (activeService) {
14781 console.warn("Ignored window.print() because of a pending print job.");
14782 return;
14783 }
14784
14785 ensureOverlay().then(function () {
14786 if (activeService) {
14787 overlayManager.open("printServiceOverlay");
14788 }
14789 });
14790
14791 try {
14792 dispatchEvent("beforeprint");
14793 } finally {
14794 if (!activeService) {
14795 console.error("Expected print service to be initialized.");
14796 ensureOverlay().then(function () {
14797 if (overlayManager.active === "printServiceOverlay") {
14798 overlayManager.close("printServiceOverlay");
14799 }
14800 });
14801 return;
14802 }
14803
14804 const activeServiceOnEntry = activeService;
14805 activeService.renderPages().then(function () {
14806 return activeServiceOnEntry.performPrint();
14807 }).catch(function () {}).then(function () {
14808 if (activeServiceOnEntry.active) {
14809 abort();
14810 }
14811 });
14812 }
14813};
14814
14815function dispatchEvent(eventType) {
14816 const event = document.createEvent("CustomEvent");
14817 event.initCustomEvent(eventType, false, false, "custom");
14818 window.dispatchEvent(event);
14819}
14820
14821function abort() {
14822 if (activeService) {
14823 activeService.destroy();
14824 dispatchEvent("afterprint");
14825 }
14826}
14827
14828function renderProgress(index, total, l10n) {
14829 const progressContainer = document.getElementById("printServiceOverlay");
14830 const progress = Math.round(100 * index / total);
14831 const progressBar = progressContainer.querySelector("progress");
14832 const progressPerc = progressContainer.querySelector(".relative-progress");
14833 progressBar.value = progress;
14834 l10n.get("print_progress_percent", {
14835 progress
14836 }).then(msg => {
14837 progressPerc.textContent = msg;
14838 });
14839}
14840
14841window.addEventListener("keydown", function (event) {
14842 if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
14843 window.print();
14844 event.preventDefault();
14845
14846 if (event.stopImmediatePropagation) {
14847 event.stopImmediatePropagation();
14848 } else {
14849 event.stopPropagation();
14850 }
14851 }
14852}, true);
14853
14854if ("onbeforeprint" in window) {
14855 const stopPropagationIfNeeded = function (event) {
14856 if (event.detail !== "custom" && event.stopImmediatePropagation) {
14857 event.stopImmediatePropagation();
14858 }
14859 };
14860
14861 window.addEventListener("beforeprint", stopPropagationIfNeeded);
14862 window.addEventListener("afterprint", stopPropagationIfNeeded);
14863}
14864
14865let overlayPromise;
14866
14867function ensureOverlay() {
14868 if (!overlayPromise) {
14869 overlayManager = _app.PDFViewerApplication.overlayManager;
14870
14871 if (!overlayManager) {
14872 throw new Error("The overlay manager has not yet been initialized.");
14873 }
14874
14875 overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
14876 document.getElementById("printCancel").onclick = abort;
14877 }
14878
14879 return overlayPromise;
14880}
14881
14882_app.PDFPrintServiceFactory.instance = {
14883 supportsPrinting: true,
14884
14885 createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
14886 if (activeService) {
14887 throw new Error("The print service is created and active.");
14888 }
14889
14890 activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
14891 return activeService;
14892 }
14893
14894};
14895
14896/***/ })
14897/******/ ]);
14898/************************************************************************/
14899/******/ // The module cache
14900/******/ var __webpack_module_cache__ = {};
14901/******/
14902/******/ // The require function
14903/******/ function __webpack_require__(moduleId) {
14904/******/ // Check if module is in cache
14905/******/ var cachedModule = __webpack_module_cache__[moduleId];
14906/******/ if (cachedModule !== undefined) {
14907/******/ return cachedModule.exports;
14908/******/ }
14909/******/ // Create a new module (and put it into the cache)
14910/******/ var module = __webpack_module_cache__[moduleId] = {
14911/******/ // no module.id needed
14912/******/ // no module.loaded needed
14913/******/ exports: {}
14914/******/ };
14915/******/
14916/******/ // Execute the module function
14917/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
14918/******/
14919/******/ // Return the exports of the module
14920/******/ return module.exports;
14921/******/ }
14922/******/
14923/************************************************************************/
14924var __webpack_exports__ = {};
14925// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
14926(() => {
14927var exports = __webpack_exports__;
14928
14929
14930Object.defineProperty(exports, "__esModule", ({
14931 value: true
14932}));
14933Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
14934 enumerable: true,
14935 get: function () {
14936 return _app_options.AppOptions;
14937 }
14938}));
14939Object.defineProperty(exports, "PDFViewerApplication", ({
14940 enumerable: true,
14941 get: function () {
14942 return _app.PDFViewerApplication;
14943 }
14944}));
14945
14946var _app_options = __webpack_require__(1);
14947
14948var _app = __webpack_require__(3);
14949
14950const pdfjsVersion = '2.8.335';
14951const pdfjsBuild = '228adbf67';
14952window.PDFViewerApplication = _app.PDFViewerApplication;
14953window.PDFViewerApplicationOptions = _app_options.AppOptions;
14954;
14955;
14956{
14957 __webpack_require__(38);
14958}
14959;
14960{
14961 __webpack_require__(44);
14962}
14963
14964function getViewerConfiguration() {
14965 let errorWrapper = null;
14966 errorWrapper = {
14967 container: document.getElementById("errorWrapper"),
14968 errorMessage: document.getElementById("errorMessage"),
14969 closeButton: document.getElementById("errorClose"),
14970 errorMoreInfo: document.getElementById("errorMoreInfo"),
14971 moreInfoButton: document.getElementById("errorShowMore"),
14972 lessInfoButton: document.getElementById("errorShowLess")
14973 };
14974 return {
14975 appContainer: document.body,
14976 mainContainer: document.getElementById("viewerContainer"),
14977 viewerContainer: document.getElementById("viewer"),
14978 eventBus: null,
14979 toolbar: {
14980 container: document.getElementById("toolbarViewer"),
14981 numPages: document.getElementById("numPages"),
14982 pageNumber: document.getElementById("pageNumber"),
14983 scaleSelectContainer: document.getElementById("scaleSelectContainer"),
14984 scaleSelect: document.getElementById("scaleSelect"),
14985 customScaleOption: document.getElementById("customScaleOption"),
14986 previous: document.getElementById("previous"),
14987 next: document.getElementById("next"),
14988 zoomIn: document.getElementById("zoomIn"),
14989 zoomOut: document.getElementById("zoomOut"),
14990 viewFind: document.getElementById("viewFind"),
14991 openFile: document.getElementById("openFile"),
14992 print: document.getElementById("print"),
14993 presentationModeButton: document.getElementById("presentationMode"),
14994 download: document.getElementById("download"),
14995 viewBookmark: document.getElementById("viewBookmark")
14996 },
14997 secondaryToolbar: {
14998 toolbar: document.getElementById("secondaryToolbar"),
14999 toggleButton: document.getElementById("secondaryToolbarToggle"),
15000 toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
15001 presentationModeButton: document.getElementById("secondaryPresentationMode"),
15002 openFileButton: document.getElementById("secondaryOpenFile"),
15003 printButton: document.getElementById("secondaryPrint"),
15004 downloadButton: document.getElementById("secondaryDownload"),
15005 viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
15006 firstPageButton: document.getElementById("firstPage"),
15007 lastPageButton: document.getElementById("lastPage"),
15008 pageRotateCwButton: document.getElementById("pageRotateCw"),
15009 pageRotateCcwButton: document.getElementById("pageRotateCcw"),
15010 cursorSelectToolButton: document.getElementById("cursorSelectTool"),
15011 cursorHandToolButton: document.getElementById("cursorHandTool"),
15012 scrollVerticalButton: document.getElementById("scrollVertical"),
15013 scrollHorizontalButton: document.getElementById("scrollHorizontal"),
15014 scrollWrappedButton: document.getElementById("scrollWrapped"),
15015 spreadNoneButton: document.getElementById("spreadNone"),
15016 spreadOddButton: document.getElementById("spreadOdd"),
15017 spreadEvenButton: document.getElementById("spreadEven"),
15018 documentPropertiesButton: document.getElementById("documentProperties")
15019 },
15020 sidebar: {
15021 outerContainer: document.getElementById("outerContainer"),
15022 viewerContainer: document.getElementById("viewerContainer"),
15023 toggleButton: document.getElementById("sidebarToggle"),
15024 thumbnailButton: document.getElementById("viewThumbnail"),
15025 outlineButton: document.getElementById("viewOutline"),
15026 attachmentsButton: document.getElementById("viewAttachments"),
15027 layersButton: document.getElementById("viewLayers"),
15028 thumbnailView: document.getElementById("thumbnailView"),
15029 outlineView: document.getElementById("outlineView"),
15030 attachmentsView: document.getElementById("attachmentsView"),
15031 layersView: document.getElementById("layersView"),
15032 outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
15033 currentOutlineItemButton: document.getElementById("currentOutlineItem")
15034 },
15035 sidebarResizer: {
15036 outerContainer: document.getElementById("outerContainer"),
15037 resizer: document.getElementById("sidebarResizer")
15038 },
15039 findBar: {
15040 bar: document.getElementById("findbar"),
15041 toggleButton: document.getElementById("viewFind"),
15042 findField: document.getElementById("findInput"),
15043 highlightAllCheckbox: document.getElementById("findHighlightAll"),
15044 caseSensitiveCheckbox: document.getElementById("findMatchCase"),
15045 entireWordCheckbox: document.getElementById("findEntireWord"),
15046 findMsg: document.getElementById("findMsg"),
15047 findResultsCount: document.getElementById("findResultsCount"),
15048 findPreviousButton: document.getElementById("findPrevious"),
15049 findNextButton: document.getElementById("findNext")
15050 },
15051 passwordOverlay: {
15052 overlayName: "passwordOverlay",
15053 container: document.getElementById("passwordOverlay"),
15054 label: document.getElementById("passwordText"),
15055 input: document.getElementById("password"),
15056 submitButton: document.getElementById("passwordSubmit"),
15057 cancelButton: document.getElementById("passwordCancel")
15058 },
15059 documentProperties: {
15060 overlayName: "documentPropertiesOverlay",
15061 container: document.getElementById("documentPropertiesOverlay"),
15062 closeButton: document.getElementById("documentPropertiesClose"),
15063 fields: {
15064 fileName: document.getElementById("fileNameField"),
15065 fileSize: document.getElementById("fileSizeField"),
15066 title: document.getElementById("titleField"),
15067 author: document.getElementById("authorField"),
15068 subject: document.getElementById("subjectField"),
15069 keywords: document.getElementById("keywordsField"),
15070 creationDate: document.getElementById("creationDateField"),
15071 modificationDate: document.getElementById("modificationDateField"),
15072 creator: document.getElementById("creatorField"),
15073 producer: document.getElementById("producerField"),
15074 version: document.getElementById("versionField"),
15075 pageCount: document.getElementById("pageCountField"),
15076 pageSize: document.getElementById("pageSizeField"),
15077 linearized: document.getElementById("linearizedField")
15078 }
15079 },
15080 errorWrapper,
15081 printContainer: document.getElementById("printContainer"),
15082 openFileInputName: "fileInput",
15083 debuggerScriptPath: "./debugger.js"
15084 };
15085}
15086
15087function webViewerLoad() {
15088 const config = getViewerConfiguration();
15089 const event = document.createEvent("CustomEvent");
15090 event.initCustomEvent("webviewerloaded", true, true, {
15091 source: window
15092 });
15093
15094 try {
15095 parent.document.dispatchEvent(event);
15096 } catch (ex) {
15097 console.error(`webviewerloaded: ${ex}`);
15098 document.dispatchEvent(event);
15099 }
15100
15101 _app.PDFViewerApplication.run(config);
15102}
15103
15104if (document.blockUnblockOnload) {
15105 document.blockUnblockOnload(true);
15106}
15107
15108if (document.readyState === "interactive" || document.readyState === "complete") {
15109 webViewerLoad();
15110} else {
15111 document.addEventListener("DOMContentLoaded", webViewerLoad, true);
15112}
15113})();
15114
15115/******/ })()
15116;
15117//# sourceMappingURL=viewer.js.map