UNPKG

159 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2020 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(function webpackUniversalModuleDefinition(root, factory) {
24 if(typeof exports === 'object' && typeof module === 'object')
25 module.exports = factory();
26 else if(typeof define === 'function' && define.amd)
27 define("pdfjs-dist/web/pdf_viewer", [], factory);
28 else if(typeof exports === 'object')
29 exports["pdfjs-dist/web/pdf_viewer"] = factory();
30 else
31 root["pdfjs-dist/web/pdf_viewer"] = root.pdfjsViewer = factory();
32})(this, function() {
33return /******/ (function(modules) { // webpackBootstrap
34/******/ // The module cache
35/******/ var installedModules = {};
36/******/
37/******/ // The require function
38/******/ function __w_pdfjs_require__(moduleId) {
39/******/
40/******/ // Check if module is in cache
41/******/ if(installedModules[moduleId]) {
42/******/ return installedModules[moduleId].exports;
43/******/ }
44/******/ // Create a new module (and put it into the cache)
45/******/ var module = installedModules[moduleId] = {
46/******/ i: moduleId,
47/******/ l: false,
48/******/ exports: {}
49/******/ };
50/******/
51/******/ // Execute the module function
52/******/ modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
53/******/
54/******/ // Flag the module as loaded
55/******/ module.l = true;
56/******/
57/******/ // Return the exports of the module
58/******/ return module.exports;
59/******/ }
60/******/
61/******/
62/******/ // expose the modules object (__webpack_modules__)
63/******/ __w_pdfjs_require__.m = modules;
64/******/
65/******/ // expose the module cache
66/******/ __w_pdfjs_require__.c = installedModules;
67/******/
68/******/ // define getter function for harmony exports
69/******/ __w_pdfjs_require__.d = function(exports, name, getter) {
70/******/ if(!__w_pdfjs_require__.o(exports, name)) {
71/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
72/******/ }
73/******/ };
74/******/
75/******/ // define __esModule on exports
76/******/ __w_pdfjs_require__.r = function(exports) {
77/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
78/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
79/******/ }
80/******/ Object.defineProperty(exports, '__esModule', { value: true });
81/******/ };
82/******/
83/******/ // create a fake namespace object
84/******/ // mode & 1: value is a module id, require it
85/******/ // mode & 2: merge all properties of value into the ns
86/******/ // mode & 4: return value when already ns object
87/******/ // mode & 8|1: behave like require
88/******/ __w_pdfjs_require__.t = function(value, mode) {
89/******/ if(mode & 1) value = __w_pdfjs_require__(value);
90/******/ if(mode & 8) return value;
91/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
92/******/ var ns = Object.create(null);
93/******/ __w_pdfjs_require__.r(ns);
94/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
95/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __w_pdfjs_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
96/******/ return ns;
97/******/ };
98/******/
99/******/ // getDefaultExport function for compatibility with non-harmony modules
100/******/ __w_pdfjs_require__.n = function(module) {
101/******/ var getter = module && module.__esModule ?
102/******/ function getDefault() { return module['default']; } :
103/******/ function getModuleExports() { return module; };
104/******/ __w_pdfjs_require__.d(getter, 'a', getter);
105/******/ return getter;
106/******/ };
107/******/
108/******/ // Object.prototype.hasOwnProperty.call
109/******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
110/******/
111/******/ // __webpack_public_path__
112/******/ __w_pdfjs_require__.p = "";
113/******/
114/******/
115/******/ // Load entry module and return exports
116/******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 0);
117/******/ })
118/************************************************************************/
119/******/ ([
120/* 0 */
121/***/ (function(module, exports, __w_pdfjs_require__) {
122
123"use strict";
124
125
126Object.defineProperty(exports, "__esModule", {
127 value: true
128});
129Object.defineProperty(exports, "AnnotationLayerBuilder", {
130 enumerable: true,
131 get: function () {
132 return _annotation_layer_builder.AnnotationLayerBuilder;
133 }
134});
135Object.defineProperty(exports, "DefaultAnnotationLayerFactory", {
136 enumerable: true,
137 get: function () {
138 return _annotation_layer_builder.DefaultAnnotationLayerFactory;
139 }
140});
141Object.defineProperty(exports, "DefaultTextLayerFactory", {
142 enumerable: true,
143 get: function () {
144 return _text_layer_builder.DefaultTextLayerFactory;
145 }
146});
147Object.defineProperty(exports, "TextLayerBuilder", {
148 enumerable: true,
149 get: function () {
150 return _text_layer_builder.TextLayerBuilder;
151 }
152});
153Object.defineProperty(exports, "EventBus", {
154 enumerable: true,
155 get: function () {
156 return _ui_utils.EventBus;
157 }
158});
159Object.defineProperty(exports, "NullL10n", {
160 enumerable: true,
161 get: function () {
162 return _ui_utils.NullL10n;
163 }
164});
165Object.defineProperty(exports, "ProgressBar", {
166 enumerable: true,
167 get: function () {
168 return _ui_utils.ProgressBar;
169 }
170});
171Object.defineProperty(exports, "PDFLinkService", {
172 enumerable: true,
173 get: function () {
174 return _pdf_link_service.PDFLinkService;
175 }
176});
177Object.defineProperty(exports, "SimpleLinkService", {
178 enumerable: true,
179 get: function () {
180 return _pdf_link_service.SimpleLinkService;
181 }
182});
183Object.defineProperty(exports, "DownloadManager", {
184 enumerable: true,
185 get: function () {
186 return _download_manager.DownloadManager;
187 }
188});
189Object.defineProperty(exports, "GenericL10n", {
190 enumerable: true,
191 get: function () {
192 return _genericl10n.GenericL10n;
193 }
194});
195Object.defineProperty(exports, "PDFFindController", {
196 enumerable: true,
197 get: function () {
198 return _pdf_find_controller.PDFFindController;
199 }
200});
201Object.defineProperty(exports, "PDFHistory", {
202 enumerable: true,
203 get: function () {
204 return _pdf_history.PDFHistory;
205 }
206});
207Object.defineProperty(exports, "PDFPageView", {
208 enumerable: true,
209 get: function () {
210 return _pdf_page_view.PDFPageView;
211 }
212});
213Object.defineProperty(exports, "PDFSinglePageViewer", {
214 enumerable: true,
215 get: function () {
216 return _pdf_single_page_viewer.PDFSinglePageViewer;
217 }
218});
219Object.defineProperty(exports, "PDFViewer", {
220 enumerable: true,
221 get: function () {
222 return _pdf_viewer.PDFViewer;
223 }
224});
225
226var _annotation_layer_builder = __w_pdfjs_require__(1);
227
228var _text_layer_builder = __w_pdfjs_require__(5);
229
230var _ui_utils = __w_pdfjs_require__(3);
231
232var _pdf_link_service = __w_pdfjs_require__(4);
233
234var _download_manager = __w_pdfjs_require__(6);
235
236var _genericl10n = __w_pdfjs_require__(8);
237
238var _pdf_find_controller = __w_pdfjs_require__(10);
239
240var _pdf_history = __w_pdfjs_require__(12);
241
242var _pdf_page_view = __w_pdfjs_require__(13);
243
244var _pdf_single_page_viewer = __w_pdfjs_require__(15);
245
246var _pdf_viewer = __w_pdfjs_require__(17);
247
248const pdfjsVersion = '2.5.207';
249const pdfjsBuild = '0974d605';
250
251/***/ }),
252/* 1 */
253/***/ (function(module, exports, __w_pdfjs_require__) {
254
255"use strict";
256
257
258Object.defineProperty(exports, "__esModule", {
259 value: true
260});
261exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
262
263var _pdfjsLib = __w_pdfjs_require__(2);
264
265var _ui_utils = __w_pdfjs_require__(3);
266
267var _pdf_link_service = __w_pdfjs_require__(4);
268
269class AnnotationLayerBuilder {
270 constructor({
271 pageDiv,
272 pdfPage,
273 linkService,
274 downloadManager,
275 imageResourcesPath = "",
276 renderInteractiveForms = false,
277 l10n = _ui_utils.NullL10n
278 }) {
279 this.pageDiv = pageDiv;
280 this.pdfPage = pdfPage;
281 this.linkService = linkService;
282 this.downloadManager = downloadManager;
283 this.imageResourcesPath = imageResourcesPath;
284 this.renderInteractiveForms = renderInteractiveForms;
285 this.l10n = l10n;
286 this.div = null;
287 this._cancelled = false;
288 }
289
290 render(viewport, intent = "display") {
291 this.pdfPage.getAnnotations({
292 intent
293 }).then(annotations => {
294 if (this._cancelled) {
295 return;
296 }
297
298 const parameters = {
299 viewport: viewport.clone({
300 dontFlip: true
301 }),
302 div: this.div,
303 annotations,
304 page: this.pdfPage,
305 imageResourcesPath: this.imageResourcesPath,
306 renderInteractiveForms: this.renderInteractiveForms,
307 linkService: this.linkService,
308 downloadManager: this.downloadManager
309 };
310
311 if (this.div) {
312 _pdfjsLib.AnnotationLayer.update(parameters);
313 } else {
314 if (annotations.length === 0) {
315 return;
316 }
317
318 this.div = document.createElement("div");
319 this.div.className = "annotationLayer";
320 this.pageDiv.appendChild(this.div);
321 parameters.div = this.div;
322
323 _pdfjsLib.AnnotationLayer.render(parameters);
324
325 this.l10n.translate(this.div);
326 }
327 });
328 }
329
330 cancel() {
331 this._cancelled = true;
332 }
333
334 hide() {
335 if (!this.div) {
336 return;
337 }
338
339 this.div.setAttribute("hidden", "true");
340 }
341
342}
343
344exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
345
346class DefaultAnnotationLayerFactory {
347 createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
348 return new AnnotationLayerBuilder({
349 pageDiv,
350 pdfPage,
351 imageResourcesPath,
352 renderInteractiveForms,
353 linkService: new _pdf_link_service.SimpleLinkService(),
354 l10n
355 });
356 }
357
358}
359
360exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
361
362/***/ }),
363/* 2 */
364/***/ (function(module, exports, __w_pdfjs_require__) {
365
366"use strict";
367
368
369let pdfjsLib;
370
371if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
372 pdfjsLib = window["pdfjs-dist/build/pdf"];
373} else {
374 pdfjsLib = require("../build/pdf.js");
375}
376
377module.exports = pdfjsLib;
378
379/***/ }),
380/* 3 */
381/***/ (function(module, exports, __w_pdfjs_require__) {
382
383"use strict";
384
385
386Object.defineProperty(exports, "__esModule", {
387 value: true
388});
389exports.isValidRotation = isValidRotation;
390exports.isValidScrollMode = isValidScrollMode;
391exports.isValidSpreadMode = isValidSpreadMode;
392exports.isPortraitOrientation = isPortraitOrientation;
393exports.clamp = clamp;
394exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
395exports.noContextMenuHandler = noContextMenuHandler;
396exports.parseQueryString = parseQueryString;
397exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
398exports.getVisibleElements = getVisibleElements;
399exports.roundToDivide = roundToDivide;
400exports.getPageSizeInches = getPageSizeInches;
401exports.approximateFraction = approximateFraction;
402exports.getOutputScale = getOutputScale;
403exports.scrollIntoView = scrollIntoView;
404exports.watchScroll = watchScroll;
405exports.binarySearchFirstItem = binarySearchFirstItem;
406exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
407exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
408exports.moveToEndOfArray = moveToEndOfArray;
409exports.WaitOnType = exports.animationStarted = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.SpreadMode = exports.ScrollMode = exports.TextLayerMode = exports.RendererType = exports.PresentationModeState = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = exports.AutoPrintRegExp = void 0;
410const CSS_UNITS = 96.0 / 72.0;
411exports.CSS_UNITS = CSS_UNITS;
412const DEFAULT_SCALE_VALUE = "auto";
413exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
414const DEFAULT_SCALE = 1.0;
415exports.DEFAULT_SCALE = DEFAULT_SCALE;
416const MIN_SCALE = 0.1;
417exports.MIN_SCALE = MIN_SCALE;
418const MAX_SCALE = 10.0;
419exports.MAX_SCALE = MAX_SCALE;
420const UNKNOWN_SCALE = 0;
421exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
422const MAX_AUTO_SCALE = 1.25;
423exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
424const SCROLLBAR_PADDING = 40;
425exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
426const VERTICAL_PADDING = 5;
427exports.VERTICAL_PADDING = VERTICAL_PADDING;
428const PresentationModeState = {
429 UNKNOWN: 0,
430 NORMAL: 1,
431 CHANGING: 2,
432 FULLSCREEN: 3
433};
434exports.PresentationModeState = PresentationModeState;
435const RendererType = {
436 CANVAS: "canvas",
437 SVG: "svg"
438};
439exports.RendererType = RendererType;
440const TextLayerMode = {
441 DISABLE: 0,
442 ENABLE: 1,
443 ENABLE_ENHANCE: 2
444};
445exports.TextLayerMode = TextLayerMode;
446const ScrollMode = {
447 UNKNOWN: -1,
448 VERTICAL: 0,
449 HORIZONTAL: 1,
450 WRAPPED: 2
451};
452exports.ScrollMode = ScrollMode;
453const SpreadMode = {
454 UNKNOWN: -1,
455 NONE: 0,
456 ODD: 1,
457 EVEN: 2
458};
459exports.SpreadMode = SpreadMode;
460const AutoPrintRegExp = /\bprint\s*\(/;
461exports.AutoPrintRegExp = AutoPrintRegExp;
462
463function formatL10nValue(text, args) {
464 if (!args) {
465 return text;
466 }
467
468 return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
469 return name in args ? args[name] : "{{" + name + "}}";
470 });
471}
472
473const NullL10n = {
474 async getLanguage() {
475 return "en-us";
476 },
477
478 async getDirection() {
479 return "ltr";
480 },
481
482 async get(property, args, fallback) {
483 return formatL10nValue(fallback, args);
484 },
485
486 async translate(element) {}
487
488};
489exports.NullL10n = NullL10n;
490
491function getOutputScale(ctx) {
492 const devicePixelRatio = window.devicePixelRatio || 1;
493 const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
494 const pixelRatio = devicePixelRatio / backingStoreRatio;
495 return {
496 sx: pixelRatio,
497 sy: pixelRatio,
498 scaled: pixelRatio !== 1
499 };
500}
501
502function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
503 let parent = element.offsetParent;
504
505 if (!parent) {
506 console.error("offsetParent is not set -- cannot scroll");
507 return;
508 }
509
510 let offsetY = element.offsetTop + element.clientTop;
511 let offsetX = element.offsetLeft + element.clientLeft;
512
513 while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
514 if (parent.dataset._scaleY) {
515 offsetY /= parent.dataset._scaleY;
516 offsetX /= parent.dataset._scaleX;
517 }
518
519 offsetY += parent.offsetTop;
520 offsetX += parent.offsetLeft;
521 parent = parent.offsetParent;
522
523 if (!parent) {
524 return;
525 }
526 }
527
528 if (spot) {
529 if (spot.top !== undefined) {
530 offsetY += spot.top;
531 }
532
533 if (spot.left !== undefined) {
534 offsetX += spot.left;
535 parent.scrollLeft = offsetX;
536 }
537 }
538
539 parent.scrollTop = offsetY;
540}
541
542function watchScroll(viewAreaElement, callback) {
543 const debounceScroll = function (evt) {
544 if (rAF) {
545 return;
546 }
547
548 rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
549 rAF = null;
550 const currentX = viewAreaElement.scrollLeft;
551 const lastX = state.lastX;
552
553 if (currentX !== lastX) {
554 state.right = currentX > lastX;
555 }
556
557 state.lastX = currentX;
558 const currentY = viewAreaElement.scrollTop;
559 const lastY = state.lastY;
560
561 if (currentY !== lastY) {
562 state.down = currentY > lastY;
563 }
564
565 state.lastY = currentY;
566 callback(state);
567 });
568 };
569
570 const state = {
571 right: true,
572 down: true,
573 lastX: viewAreaElement.scrollLeft,
574 lastY: viewAreaElement.scrollTop,
575 _eventHandler: debounceScroll
576 };
577 let rAF = null;
578 viewAreaElement.addEventListener("scroll", debounceScroll, true);
579 return state;
580}
581
582function parseQueryString(query) {
583 const parts = query.split("&");
584 const params = Object.create(null);
585
586 for (let i = 0, ii = parts.length; i < ii; ++i) {
587 const param = parts[i].split("=");
588 const key = param[0].toLowerCase();
589 const value = param.length > 1 ? param[1] : null;
590 params[decodeURIComponent(key)] = decodeURIComponent(value);
591 }
592
593 return params;
594}
595
596function binarySearchFirstItem(items, condition) {
597 let minIndex = 0;
598 let maxIndex = items.length - 1;
599
600 if (maxIndex < 0 || !condition(items[maxIndex])) {
601 return items.length;
602 }
603
604 if (condition(items[minIndex])) {
605 return minIndex;
606 }
607
608 while (minIndex < maxIndex) {
609 const currentIndex = minIndex + maxIndex >> 1;
610 const currentItem = items[currentIndex];
611
612 if (condition(currentItem)) {
613 maxIndex = currentIndex;
614 } else {
615 minIndex = currentIndex + 1;
616 }
617 }
618
619 return minIndex;
620}
621
622function approximateFraction(x) {
623 if (Math.floor(x) === x) {
624 return [x, 1];
625 }
626
627 const xinv = 1 / x;
628 const limit = 8;
629
630 if (xinv > limit) {
631 return [1, limit];
632 } else if (Math.floor(xinv) === xinv) {
633 return [1, xinv];
634 }
635
636 const x_ = x > 1 ? xinv : x;
637 let a = 0,
638 b = 1,
639 c = 1,
640 d = 1;
641
642 while (true) {
643 const p = a + c,
644 q = b + d;
645
646 if (q > limit) {
647 break;
648 }
649
650 if (x_ <= p / q) {
651 c = p;
652 d = q;
653 } else {
654 a = p;
655 b = q;
656 }
657 }
658
659 let result;
660
661 if (x_ - a / b < c / d - x_) {
662 result = x_ === x ? [a, b] : [b, a];
663 } else {
664 result = x_ === x ? [c, d] : [d, c];
665 }
666
667 return result;
668}
669
670function roundToDivide(x, div) {
671 const r = x % div;
672 return r === 0 ? x : Math.round(x - r + div);
673}
674
675function getPageSizeInches({
676 view,
677 userUnit,
678 rotate
679}) {
680 const [x1, y1, x2, y2] = view;
681 const changeOrientation = rotate % 180 !== 0;
682 const width = (x2 - x1) / 72 * userUnit;
683 const height = (y2 - y1) / 72 * userUnit;
684 return {
685 width: changeOrientation ? height : width,
686 height: changeOrientation ? width : height
687 };
688}
689
690function backtrackBeforeAllVisibleElements(index, views, top) {
691 if (index < 2) {
692 return index;
693 }
694
695 let elt = views[index].div;
696 let pageTop = elt.offsetTop + elt.clientTop;
697
698 if (pageTop >= top) {
699 elt = views[index - 1].div;
700 pageTop = elt.offsetTop + elt.clientTop;
701 }
702
703 for (let i = index - 2; i >= 0; --i) {
704 elt = views[i].div;
705
706 if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
707 break;
708 }
709
710 index = i;
711 }
712
713 return index;
714}
715
716function getVisibleElements(scrollEl, views, sortByVisibility = false, horizontal = false) {
717 const top = scrollEl.scrollTop,
718 bottom = top + scrollEl.clientHeight;
719 const left = scrollEl.scrollLeft,
720 right = left + scrollEl.clientWidth;
721
722 function isElementBottomAfterViewTop(view) {
723 const element = view.div;
724 const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
725 return elementBottom > top;
726 }
727
728 function isElementRightAfterViewLeft(view) {
729 const element = view.div;
730 const elementRight = element.offsetLeft + element.clientLeft + element.clientWidth;
731 return elementRight > left;
732 }
733
734 const visible = [],
735 numViews = views.length;
736 let firstVisibleElementInd = numViews === 0 ? 0 : binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop);
737
738 if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
739 firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
740 }
741
742 let lastEdge = horizontal ? right : -1;
743
744 for (let i = firstVisibleElementInd; i < numViews; i++) {
745 const view = views[i],
746 element = view.div;
747 const currentWidth = element.offsetLeft + element.clientLeft;
748 const currentHeight = element.offsetTop + element.clientTop;
749 const viewWidth = element.clientWidth,
750 viewHeight = element.clientHeight;
751 const viewRight = currentWidth + viewWidth;
752 const viewBottom = currentHeight + viewHeight;
753
754 if (lastEdge === -1) {
755 if (viewBottom >= bottom) {
756 lastEdge = viewBottom;
757 }
758 } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
759 break;
760 }
761
762 if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
763 continue;
764 }
765
766 const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
767 const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
768 const percent = (viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100 / viewHeight / viewWidth | 0;
769 visible.push({
770 id: view.id,
771 x: currentWidth,
772 y: currentHeight,
773 view,
774 percent
775 });
776 }
777
778 const first = visible[0],
779 last = visible[visible.length - 1];
780
781 if (sortByVisibility) {
782 visible.sort(function (a, b) {
783 const pc = a.percent - b.percent;
784
785 if (Math.abs(pc) > 0.001) {
786 return -pc;
787 }
788
789 return a.id - b.id;
790 });
791 }
792
793 return {
794 first,
795 last,
796 views: visible
797 };
798}
799
800function noContextMenuHandler(evt) {
801 evt.preventDefault();
802}
803
804function isDataSchema(url) {
805 let i = 0;
806 const ii = url.length;
807
808 while (i < ii && url[i].trim() === "") {
809 i++;
810 }
811
812 return url.substring(i, i + 5).toLowerCase() === "data:";
813}
814
815function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
816 if (typeof url !== "string") {
817 return defaultFilename;
818 }
819
820 if (isDataSchema(url)) {
821 console.warn("getPDFFileNameFromURL: " + 'ignoring "data:" URL for performance reasons.');
822 return defaultFilename;
823 }
824
825 const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
826 const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
827 const splitURI = reURI.exec(url);
828 let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
829
830 if (suggestedFilename) {
831 suggestedFilename = suggestedFilename[0];
832
833 if (suggestedFilename.includes("%")) {
834 try {
835 suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
836 } catch (ex) {}
837 }
838 }
839
840 return suggestedFilename || defaultFilename;
841}
842
843function normalizeWheelEventDelta(evt) {
844 let delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
845 const angle = Math.atan2(evt.deltaY, evt.deltaX);
846
847 if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
848 delta = -delta;
849 }
850
851 const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
852 const MOUSE_DOM_DELTA_LINE_MODE = 1;
853 const MOUSE_PIXELS_PER_LINE = 30;
854 const MOUSE_LINES_PER_PAGE = 30;
855
856 if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
857 delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
858 } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
859 delta /= MOUSE_LINES_PER_PAGE;
860 }
861
862 return delta;
863}
864
865function isValidRotation(angle) {
866 return Number.isInteger(angle) && angle % 90 === 0;
867}
868
869function isValidScrollMode(mode) {
870 return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
871}
872
873function isValidSpreadMode(mode) {
874 return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
875}
876
877function isPortraitOrientation(size) {
878 return size.width <= size.height;
879}
880
881const WaitOnType = {
882 EVENT: "event",
883 TIMEOUT: "timeout"
884};
885exports.WaitOnType = WaitOnType;
886
887function waitOnEventOrTimeout({
888 target,
889 name,
890 delay = 0
891}) {
892 return new Promise(function (resolve, reject) {
893 if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
894 throw new Error("waitOnEventOrTimeout - invalid parameters.");
895 }
896
897 function handler(type) {
898 if (target instanceof EventBus) {
899 target._off(name, eventHandler);
900 } else {
901 target.removeEventListener(name, eventHandler);
902 }
903
904 if (timeout) {
905 clearTimeout(timeout);
906 }
907
908 resolve(type);
909 }
910
911 const eventHandler = handler.bind(null, WaitOnType.EVENT);
912
913 if (target instanceof EventBus) {
914 target._on(name, eventHandler);
915 } else {
916 target.addEventListener(name, eventHandler);
917 }
918
919 const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
920 const timeout = setTimeout(timeoutHandler, delay);
921 });
922}
923
924const animationStarted = new Promise(function (resolve) {
925 window.requestAnimationFrame(resolve);
926});
927exports.animationStarted = animationStarted;
928
929function dispatchDOMEvent(eventName, args = null) {
930 throw new Error("Not implemented: dispatchDOMEvent");
931}
932
933class EventBus {
934 constructor(options) {
935 this._listeners = Object.create(null);
936 }
937
938 on(eventName, listener) {
939 this._on(eventName, listener, {
940 external: true
941 });
942 }
943
944 off(eventName, listener) {
945 this._off(eventName, listener, {
946 external: true
947 });
948 }
949
950 dispatch(eventName) {
951 const eventListeners = this._listeners[eventName];
952
953 if (!eventListeners || eventListeners.length === 0) {
954 return;
955 }
956
957 const args = Array.prototype.slice.call(arguments, 1);
958 let externalListeners;
959 eventListeners.slice(0).forEach(function ({
960 listener,
961 external
962 }) {
963 if (external) {
964 if (!externalListeners) {
965 externalListeners = [];
966 }
967
968 externalListeners.push(listener);
969 return;
970 }
971
972 listener.apply(null, args);
973 });
974
975 if (externalListeners) {
976 externalListeners.forEach(function (listener) {
977 listener.apply(null, args);
978 });
979 externalListeners = null;
980 }
981 }
982
983 _on(eventName, listener, options = null) {
984 let eventListeners = this._listeners[eventName];
985
986 if (!eventListeners) {
987 this._listeners[eventName] = eventListeners = [];
988 }
989
990 eventListeners.push({
991 listener,
992 external: (options && options.external) === true
993 });
994 }
995
996 _off(eventName, listener, options = null) {
997 const eventListeners = this._listeners[eventName];
998
999 if (!eventListeners) {
1000 return;
1001 }
1002
1003 for (let i = 0, ii = eventListeners.length; i < ii; i++) {
1004 if (eventListeners[i].listener === listener) {
1005 eventListeners.splice(i, 1);
1006 return;
1007 }
1008 }
1009 }
1010
1011}
1012
1013exports.EventBus = EventBus;
1014
1015function clamp(v, min, max) {
1016 return Math.min(Math.max(v, min), max);
1017}
1018
1019class ProgressBar {
1020 constructor(id, {
1021 height,
1022 width,
1023 units
1024 } = {}) {
1025 this.visible = true;
1026 this.div = document.querySelector(id + " .progress");
1027 this.bar = this.div.parentNode;
1028 this.height = height || 100;
1029 this.width = width || 100;
1030 this.units = units || "%";
1031 this.div.style.height = this.height + this.units;
1032 this.percent = 0;
1033 }
1034
1035 _updateBar() {
1036 if (this._indeterminate) {
1037 this.div.classList.add("indeterminate");
1038 this.div.style.width = this.width + this.units;
1039 return;
1040 }
1041
1042 this.div.classList.remove("indeterminate");
1043 const progressSize = this.width * this._percent / 100;
1044 this.div.style.width = progressSize + this.units;
1045 }
1046
1047 get percent() {
1048 return this._percent;
1049 }
1050
1051 set percent(val) {
1052 this._indeterminate = isNaN(val);
1053 this._percent = clamp(val, 0, 100);
1054
1055 this._updateBar();
1056 }
1057
1058 setWidth(viewer) {
1059 if (!viewer) {
1060 return;
1061 }
1062
1063 const container = viewer.parentNode;
1064 const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
1065
1066 if (scrollbarWidth > 0) {
1067 this.bar.style.width = `calc(100% - ${scrollbarWidth}px)`;
1068 }
1069 }
1070
1071 hide() {
1072 if (!this.visible) {
1073 return;
1074 }
1075
1076 this.visible = false;
1077 this.bar.classList.add("hidden");
1078 document.body.classList.remove("loadingInProgress");
1079 }
1080
1081 show() {
1082 if (this.visible) {
1083 return;
1084 }
1085
1086 this.visible = true;
1087 document.body.classList.add("loadingInProgress");
1088 this.bar.classList.remove("hidden");
1089 }
1090
1091}
1092
1093exports.ProgressBar = ProgressBar;
1094
1095function moveToEndOfArray(arr, condition) {
1096 const moved = [],
1097 len = arr.length;
1098 let write = 0;
1099
1100 for (let read = 0; read < len; ++read) {
1101 if (condition(arr[read])) {
1102 moved.push(arr[read]);
1103 } else {
1104 arr[write] = arr[read];
1105 ++write;
1106 }
1107 }
1108
1109 for (let read = 0; write < len; ++read, ++write) {
1110 arr[write] = moved[read];
1111 }
1112}
1113
1114/***/ }),
1115/* 4 */
1116/***/ (function(module, exports, __w_pdfjs_require__) {
1117
1118"use strict";
1119
1120
1121Object.defineProperty(exports, "__esModule", {
1122 value: true
1123});
1124exports.SimpleLinkService = exports.PDFLinkService = void 0;
1125
1126var _ui_utils = __w_pdfjs_require__(3);
1127
1128class PDFLinkService {
1129 constructor({
1130 eventBus,
1131 externalLinkTarget = null,
1132 externalLinkRel = null,
1133 externalLinkEnabled = true,
1134 ignoreDestinationZoom = false
1135 } = {}) {
1136 this.eventBus = eventBus;
1137 this.externalLinkTarget = externalLinkTarget;
1138 this.externalLinkRel = externalLinkRel;
1139 this.externalLinkEnabled = externalLinkEnabled;
1140 this._ignoreDestinationZoom = ignoreDestinationZoom;
1141 this.baseUrl = null;
1142 this.pdfDocument = null;
1143 this.pdfViewer = null;
1144 this.pdfHistory = null;
1145 this._pagesRefCache = null;
1146 }
1147
1148 setDocument(pdfDocument, baseUrl = null) {
1149 this.baseUrl = baseUrl;
1150 this.pdfDocument = pdfDocument;
1151 this._pagesRefCache = Object.create(null);
1152 }
1153
1154 setViewer(pdfViewer) {
1155 this.pdfViewer = pdfViewer;
1156 }
1157
1158 setHistory(pdfHistory) {
1159 this.pdfHistory = pdfHistory;
1160 }
1161
1162 get pagesCount() {
1163 return this.pdfDocument ? this.pdfDocument.numPages : 0;
1164 }
1165
1166 get page() {
1167 return this.pdfViewer.currentPageNumber;
1168 }
1169
1170 set page(value) {
1171 this.pdfViewer.currentPageNumber = value;
1172 }
1173
1174 get rotation() {
1175 return this.pdfViewer.pagesRotation;
1176 }
1177
1178 set rotation(value) {
1179 this.pdfViewer.pagesRotation = value;
1180 }
1181
1182 navigateTo(dest) {
1183 const goToDestination = ({
1184 namedDest,
1185 explicitDest
1186 }) => {
1187 const destRef = explicitDest[0];
1188 let pageNumber;
1189
1190 if (destRef instanceof Object) {
1191 pageNumber = this._cachedPageNumber(destRef);
1192
1193 if (pageNumber === null) {
1194 this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
1195 this.cachePageRef(pageIndex + 1, destRef);
1196 goToDestination({
1197 namedDest,
1198 explicitDest
1199 });
1200 }).catch(() => {
1201 console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid page reference, for dest="${dest}".`);
1202 });
1203 return;
1204 }
1205 } else if (Number.isInteger(destRef)) {
1206 pageNumber = destRef + 1;
1207 } else {
1208 console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid destination reference, for dest="${dest}".`);
1209 return;
1210 }
1211
1212 if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
1213 console.error(`PDFLinkService.navigateTo: "${pageNumber}" is not ` + `a valid page number, for dest="${dest}".`);
1214 return;
1215 }
1216
1217 if (this.pdfHistory) {
1218 this.pdfHistory.pushCurrentPosition();
1219 this.pdfHistory.push({
1220 namedDest,
1221 explicitDest,
1222 pageNumber
1223 });
1224 }
1225
1226 this.pdfViewer.scrollPageIntoView({
1227 pageNumber,
1228 destArray: explicitDest,
1229 ignoreDestinationZoom: this._ignoreDestinationZoom
1230 });
1231 };
1232
1233 new Promise((resolve, reject) => {
1234 if (typeof dest === "string") {
1235 this.pdfDocument.getDestination(dest).then(destArray => {
1236 resolve({
1237 namedDest: dest,
1238 explicitDest: destArray
1239 });
1240 });
1241 return;
1242 }
1243
1244 resolve({
1245 namedDest: "",
1246 explicitDest: dest
1247 });
1248 }).then(data => {
1249 if (!Array.isArray(data.explicitDest)) {
1250 console.error(`PDFLinkService.navigateTo: "${data.explicitDest}" is` + ` not a valid destination array, for dest="${dest}".`);
1251 return;
1252 }
1253
1254 goToDestination(data);
1255 });
1256 }
1257
1258 getDestinationHash(dest) {
1259 if (typeof dest === "string") {
1260 return this.getAnchorUrl("#" + escape(dest));
1261 }
1262
1263 if (Array.isArray(dest)) {
1264 const str = JSON.stringify(dest);
1265 return this.getAnchorUrl("#" + escape(str));
1266 }
1267
1268 return this.getAnchorUrl("");
1269 }
1270
1271 getAnchorUrl(anchor) {
1272 return (this.baseUrl || "") + anchor;
1273 }
1274
1275 setHash(hash) {
1276 let pageNumber, dest;
1277
1278 if (hash.includes("=")) {
1279 const params = (0, _ui_utils.parseQueryString)(hash);
1280
1281 if ("search" in params) {
1282 this.eventBus.dispatch("findfromurlhash", {
1283 source: this,
1284 query: params.search.replace(/"/g, ""),
1285 phraseSearch: params.phrase === "true"
1286 });
1287 }
1288
1289 if ("page" in params) {
1290 pageNumber = params.page | 0 || 1;
1291 }
1292
1293 if ("zoom" in params) {
1294 const zoomArgs = params.zoom.split(",");
1295 const zoomArg = zoomArgs[0];
1296 const zoomArgNumber = parseFloat(zoomArg);
1297
1298 if (!zoomArg.includes("Fit")) {
1299 dest = [null, {
1300 name: "XYZ"
1301 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
1302 } else {
1303 if (zoomArg === "Fit" || zoomArg === "FitB") {
1304 dest = [null, {
1305 name: zoomArg
1306 }];
1307 } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
1308 dest = [null, {
1309 name: zoomArg
1310 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
1311 } else if (zoomArg === "FitR") {
1312 if (zoomArgs.length !== 5) {
1313 console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
1314 } else {
1315 dest = [null, {
1316 name: zoomArg
1317 }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
1318 }
1319 } else {
1320 console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
1321 }
1322 }
1323 }
1324
1325 if (dest) {
1326 this.pdfViewer.scrollPageIntoView({
1327 pageNumber: pageNumber || this.page,
1328 destArray: dest,
1329 allowNegativeOffset: true
1330 });
1331 } else if (pageNumber) {
1332 this.page = pageNumber;
1333 }
1334
1335 if ("pagemode" in params) {
1336 this.eventBus.dispatch("pagemode", {
1337 source: this,
1338 mode: params.pagemode
1339 });
1340 }
1341
1342 if ("nameddest" in params) {
1343 this.navigateTo(params.nameddest);
1344 }
1345 } else {
1346 dest = unescape(hash);
1347
1348 try {
1349 dest = JSON.parse(dest);
1350
1351 if (!Array.isArray(dest)) {
1352 dest = dest.toString();
1353 }
1354 } catch (ex) {}
1355
1356 if (typeof dest === "string" || isValidExplicitDestination(dest)) {
1357 this.navigateTo(dest);
1358 return;
1359 }
1360
1361 console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
1362 }
1363 }
1364
1365 executeNamedAction(action) {
1366 switch (action) {
1367 case "GoBack":
1368 if (this.pdfHistory) {
1369 this.pdfHistory.back();
1370 }
1371
1372 break;
1373
1374 case "GoForward":
1375 if (this.pdfHistory) {
1376 this.pdfHistory.forward();
1377 }
1378
1379 break;
1380
1381 case "NextPage":
1382 if (this.page < this.pagesCount) {
1383 this.page++;
1384 }
1385
1386 break;
1387
1388 case "PrevPage":
1389 if (this.page > 1) {
1390 this.page--;
1391 }
1392
1393 break;
1394
1395 case "LastPage":
1396 this.page = this.pagesCount;
1397 break;
1398
1399 case "FirstPage":
1400 this.page = 1;
1401 break;
1402
1403 default:
1404 break;
1405 }
1406
1407 this.eventBus.dispatch("namedaction", {
1408 source: this,
1409 action
1410 });
1411 }
1412
1413 cachePageRef(pageNum, pageRef) {
1414 if (!pageRef) {
1415 return;
1416 }
1417
1418 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
1419 this._pagesRefCache[refStr] = pageNum;
1420 }
1421
1422 _cachedPageNumber(pageRef) {
1423 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
1424 return this._pagesRefCache && this._pagesRefCache[refStr] || null;
1425 }
1426
1427 isPageVisible(pageNumber) {
1428 return this.pdfViewer.isPageVisible(pageNumber);
1429 }
1430
1431}
1432
1433exports.PDFLinkService = PDFLinkService;
1434
1435function isValidExplicitDestination(dest) {
1436 if (!Array.isArray(dest)) {
1437 return false;
1438 }
1439
1440 const destLength = dest.length;
1441
1442 if (destLength < 2) {
1443 return false;
1444 }
1445
1446 const page = dest[0];
1447
1448 if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
1449 return false;
1450 }
1451
1452 const zoom = dest[1];
1453
1454 if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
1455 return false;
1456 }
1457
1458 let allowNull = true;
1459
1460 switch (zoom.name) {
1461 case "XYZ":
1462 if (destLength !== 5) {
1463 return false;
1464 }
1465
1466 break;
1467
1468 case "Fit":
1469 case "FitB":
1470 return destLength === 2;
1471
1472 case "FitH":
1473 case "FitBH":
1474 case "FitV":
1475 case "FitBV":
1476 if (destLength !== 3) {
1477 return false;
1478 }
1479
1480 break;
1481
1482 case "FitR":
1483 if (destLength !== 6) {
1484 return false;
1485 }
1486
1487 allowNull = false;
1488 break;
1489
1490 default:
1491 return false;
1492 }
1493
1494 for (let i = 2; i < destLength; i++) {
1495 const param = dest[i];
1496
1497 if (!(typeof param === "number" || allowNull && param === null)) {
1498 return false;
1499 }
1500 }
1501
1502 return true;
1503}
1504
1505class SimpleLinkService {
1506 constructor() {
1507 this.externalLinkTarget = null;
1508 this.externalLinkRel = null;
1509 this.externalLinkEnabled = true;
1510 this._ignoreDestinationZoom = false;
1511 }
1512
1513 get pagesCount() {
1514 return 0;
1515 }
1516
1517 get page() {
1518 return 0;
1519 }
1520
1521 set page(value) {}
1522
1523 get rotation() {
1524 return 0;
1525 }
1526
1527 set rotation(value) {}
1528
1529 navigateTo(dest) {}
1530
1531 getDestinationHash(dest) {
1532 return "#";
1533 }
1534
1535 getAnchorUrl(hash) {
1536 return "#";
1537 }
1538
1539 setHash(hash) {}
1540
1541 executeNamedAction(action) {}
1542
1543 cachePageRef(pageNum, pageRef) {}
1544
1545 isPageVisible(pageNumber) {
1546 return true;
1547 }
1548
1549}
1550
1551exports.SimpleLinkService = SimpleLinkService;
1552
1553/***/ }),
1554/* 5 */
1555/***/ (function(module, exports, __w_pdfjs_require__) {
1556
1557"use strict";
1558
1559
1560Object.defineProperty(exports, "__esModule", {
1561 value: true
1562});
1563exports.DefaultTextLayerFactory = exports.TextLayerBuilder = void 0;
1564
1565var _pdfjsLib = __w_pdfjs_require__(2);
1566
1567const EXPAND_DIVS_TIMEOUT = 300;
1568
1569class TextLayerBuilder {
1570 constructor({
1571 textLayerDiv,
1572 eventBus,
1573 pageIndex,
1574 viewport,
1575 findController = null,
1576 enhanceTextSelection = false
1577 }) {
1578 this.textLayerDiv = textLayerDiv;
1579 this.eventBus = eventBus;
1580 this.textContent = null;
1581 this.textContentItemsStr = [];
1582 this.textContentStream = null;
1583 this.renderingDone = false;
1584 this.pageIdx = pageIndex;
1585 this.pageNumber = this.pageIdx + 1;
1586 this.matches = [];
1587 this.viewport = viewport;
1588 this.textDivs = [];
1589 this.findController = findController;
1590 this.textLayerRenderTask = null;
1591 this.enhanceTextSelection = enhanceTextSelection;
1592 this._onUpdateTextLayerMatches = null;
1593
1594 this._bindMouse();
1595 }
1596
1597 _finishRendering() {
1598 this.renderingDone = true;
1599
1600 if (!this.enhanceTextSelection) {
1601 const endOfContent = document.createElement("div");
1602 endOfContent.className = "endOfContent";
1603 this.textLayerDiv.appendChild(endOfContent);
1604 }
1605
1606 this.eventBus.dispatch("textlayerrendered", {
1607 source: this,
1608 pageNumber: this.pageNumber,
1609 numTextDivs: this.textDivs.length
1610 });
1611 }
1612
1613 render(timeout = 0) {
1614 if (!(this.textContent || this.textContentStream) || this.renderingDone) {
1615 return;
1616 }
1617
1618 this.cancel();
1619 this.textDivs = [];
1620 const textLayerFrag = document.createDocumentFragment();
1621 this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
1622 textContent: this.textContent,
1623 textContentStream: this.textContentStream,
1624 container: textLayerFrag,
1625 viewport: this.viewport,
1626 textDivs: this.textDivs,
1627 textContentItemsStr: this.textContentItemsStr,
1628 timeout,
1629 enhanceTextSelection: this.enhanceTextSelection
1630 });
1631 this.textLayerRenderTask.promise.then(() => {
1632 this.textLayerDiv.appendChild(textLayerFrag);
1633
1634 this._finishRendering();
1635
1636 this._updateMatches();
1637 }, function (reason) {});
1638
1639 if (!this._onUpdateTextLayerMatches) {
1640 this._onUpdateTextLayerMatches = evt => {
1641 if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
1642 this._updateMatches();
1643 }
1644 };
1645
1646 this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
1647 }
1648 }
1649
1650 cancel() {
1651 if (this.textLayerRenderTask) {
1652 this.textLayerRenderTask.cancel();
1653 this.textLayerRenderTask = null;
1654 }
1655
1656 if (this._onUpdateTextLayerMatches) {
1657 this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
1658
1659 this._onUpdateTextLayerMatches = null;
1660 }
1661 }
1662
1663 setTextContentStream(readableStream) {
1664 this.cancel();
1665 this.textContentStream = readableStream;
1666 }
1667
1668 setTextContent(textContent) {
1669 this.cancel();
1670 this.textContent = textContent;
1671 }
1672
1673 _convertMatches(matches, matchesLength) {
1674 if (!matches) {
1675 return [];
1676 }
1677
1678 const {
1679 findController,
1680 textContentItemsStr
1681 } = this;
1682 let i = 0,
1683 iIndex = 0;
1684 const end = textContentItemsStr.length - 1;
1685 const queryLen = findController.state.query.length;
1686 const result = [];
1687
1688 for (let m = 0, mm = matches.length; m < mm; m++) {
1689 let matchIdx = matches[m];
1690
1691 while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
1692 iIndex += textContentItemsStr[i].length;
1693 i++;
1694 }
1695
1696 if (i === textContentItemsStr.length) {
1697 console.error("Could not find a matching mapping");
1698 }
1699
1700 const match = {
1701 begin: {
1702 divIdx: i,
1703 offset: matchIdx - iIndex
1704 }
1705 };
1706
1707 if (matchesLength) {
1708 matchIdx += matchesLength[m];
1709 } else {
1710 matchIdx += queryLen;
1711 }
1712
1713 while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
1714 iIndex += textContentItemsStr[i].length;
1715 i++;
1716 }
1717
1718 match.end = {
1719 divIdx: i,
1720 offset: matchIdx - iIndex
1721 };
1722 result.push(match);
1723 }
1724
1725 return result;
1726 }
1727
1728 _renderMatches(matches) {
1729 if (matches.length === 0) {
1730 return;
1731 }
1732
1733 const {
1734 findController,
1735 pageIdx,
1736 textContentItemsStr,
1737 textDivs
1738 } = this;
1739 const isSelectedPage = pageIdx === findController.selected.pageIdx;
1740 const selectedMatchIdx = findController.selected.matchIdx;
1741 const highlightAll = findController.state.highlightAll;
1742 let prevEnd = null;
1743 const infinity = {
1744 divIdx: -1,
1745 offset: undefined
1746 };
1747
1748 function beginText(begin, className) {
1749 const divIdx = begin.divIdx;
1750 textDivs[divIdx].textContent = "";
1751 appendTextToDiv(divIdx, 0, begin.offset, className);
1752 }
1753
1754 function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
1755 const div = textDivs[divIdx];
1756 const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
1757 const node = document.createTextNode(content);
1758
1759 if (className) {
1760 const span = document.createElement("span");
1761 span.className = className;
1762 span.appendChild(node);
1763 div.appendChild(span);
1764 return;
1765 }
1766
1767 div.appendChild(node);
1768 }
1769
1770 let i0 = selectedMatchIdx,
1771 i1 = i0 + 1;
1772
1773 if (highlightAll) {
1774 i0 = 0;
1775 i1 = matches.length;
1776 } else if (!isSelectedPage) {
1777 return;
1778 }
1779
1780 for (let i = i0; i < i1; i++) {
1781 const match = matches[i];
1782 const begin = match.begin;
1783 const end = match.end;
1784 const isSelected = isSelectedPage && i === selectedMatchIdx;
1785 const highlightSuffix = isSelected ? " selected" : "";
1786
1787 if (isSelected) {
1788 findController.scrollMatchIntoView({
1789 element: textDivs[begin.divIdx],
1790 pageIndex: pageIdx,
1791 matchIndex: selectedMatchIdx
1792 });
1793 }
1794
1795 if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
1796 if (prevEnd !== null) {
1797 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
1798 }
1799
1800 beginText(begin);
1801 } else {
1802 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
1803 }
1804
1805 if (begin.divIdx === end.divIdx) {
1806 appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
1807 } else {
1808 appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
1809
1810 for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
1811 textDivs[n0].className = "highlight middle" + highlightSuffix;
1812 }
1813
1814 beginText(end, "highlight end" + highlightSuffix);
1815 }
1816
1817 prevEnd = end;
1818 }
1819
1820 if (prevEnd) {
1821 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
1822 }
1823 }
1824
1825 _updateMatches() {
1826 if (!this.renderingDone) {
1827 return;
1828 }
1829
1830 const {
1831 findController,
1832 matches,
1833 pageIdx,
1834 textContentItemsStr,
1835 textDivs
1836 } = this;
1837 let clearedUntilDivIdx = -1;
1838
1839 for (let i = 0, ii = matches.length; i < ii; i++) {
1840 const match = matches[i];
1841 const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
1842
1843 for (let n = begin, end = match.end.divIdx; n <= end; n++) {
1844 const div = textDivs[n];
1845 div.textContent = textContentItemsStr[n];
1846 div.className = "";
1847 }
1848
1849 clearedUntilDivIdx = match.end.divIdx + 1;
1850 }
1851
1852 if (!findController || !findController.highlightMatches) {
1853 return;
1854 }
1855
1856 const pageMatches = findController.pageMatches[pageIdx] || null;
1857 const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
1858 this.matches = this._convertMatches(pageMatches, pageMatchesLength);
1859
1860 this._renderMatches(this.matches);
1861 }
1862
1863 _bindMouse() {
1864 const div = this.textLayerDiv;
1865 let expandDivsTimer = null;
1866 div.addEventListener("mousedown", evt => {
1867 if (this.enhanceTextSelection && this.textLayerRenderTask) {
1868 this.textLayerRenderTask.expandTextDivs(true);
1869
1870 if (expandDivsTimer) {
1871 clearTimeout(expandDivsTimer);
1872 expandDivsTimer = null;
1873 }
1874
1875 return;
1876 }
1877
1878 const end = div.querySelector(".endOfContent");
1879
1880 if (!end) {
1881 return;
1882 }
1883
1884 let adjustTop = evt.target !== div;
1885 adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
1886
1887 if (adjustTop) {
1888 const divBounds = div.getBoundingClientRect();
1889 const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
1890 end.style.top = (r * 100).toFixed(2) + "%";
1891 }
1892
1893 end.classList.add("active");
1894 });
1895 div.addEventListener("mouseup", () => {
1896 if (this.enhanceTextSelection && this.textLayerRenderTask) {
1897 expandDivsTimer = setTimeout(() => {
1898 if (this.textLayerRenderTask) {
1899 this.textLayerRenderTask.expandTextDivs(false);
1900 }
1901
1902 expandDivsTimer = null;
1903 }, EXPAND_DIVS_TIMEOUT);
1904 return;
1905 }
1906
1907 const end = div.querySelector(".endOfContent");
1908
1909 if (!end) {
1910 return;
1911 }
1912
1913 end.style.top = "";
1914 end.classList.remove("active");
1915 });
1916 }
1917
1918}
1919
1920exports.TextLayerBuilder = TextLayerBuilder;
1921
1922class DefaultTextLayerFactory {
1923 createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
1924 return new TextLayerBuilder({
1925 textLayerDiv,
1926 pageIndex,
1927 viewport,
1928 enhanceTextSelection,
1929 eventBus
1930 });
1931 }
1932
1933}
1934
1935exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
1936
1937/***/ }),
1938/* 6 */
1939/***/ (function(module, exports, __w_pdfjs_require__) {
1940
1941"use strict";
1942
1943
1944Object.defineProperty(exports, "__esModule", {
1945 value: true
1946});
1947exports.DownloadManager = void 0;
1948
1949var _pdfjsLib = __w_pdfjs_require__(2);
1950
1951var _viewer_compatibility = __w_pdfjs_require__(7);
1952
1953;
1954const DISABLE_CREATE_OBJECT_URL = _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL || false;
1955
1956function download(blobUrl, filename) {
1957 const a = document.createElement("a");
1958
1959 if (!a.click) {
1960 throw new Error('DownloadManager: "a.click()" is not supported.');
1961 }
1962
1963 a.href = blobUrl;
1964 a.target = "_parent";
1965
1966 if ("download" in a) {
1967 a.download = filename;
1968 }
1969
1970 (document.body || document.documentElement).appendChild(a);
1971 a.click();
1972 a.remove();
1973}
1974
1975class DownloadManager {
1976 constructor({
1977 disableCreateObjectURL = DISABLE_CREATE_OBJECT_URL
1978 }) {
1979 this.disableCreateObjectURL = disableCreateObjectURL;
1980 }
1981
1982 downloadUrl(url, filename) {
1983 if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
1984 return;
1985 }
1986
1987 download(url + "#pdfjs.action=download", filename);
1988 }
1989
1990 downloadData(data, filename, contentType) {
1991 if (navigator.msSaveBlob) {
1992 navigator.msSaveBlob(new Blob([data], {
1993 type: contentType
1994 }), filename);
1995 return;
1996 }
1997
1998 const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, this.disableCreateObjectURL);
1999 download(blobUrl, filename);
2000 }
2001
2002 download(blob, url, filename) {
2003 if (navigator.msSaveBlob) {
2004 if (!navigator.msSaveBlob(blob, filename)) {
2005 this.downloadUrl(url, filename);
2006 }
2007
2008 return;
2009 }
2010
2011 if (this.disableCreateObjectURL) {
2012 this.downloadUrl(url, filename);
2013 return;
2014 }
2015
2016 const blobUrl = URL.createObjectURL(blob);
2017 download(blobUrl, filename);
2018 }
2019
2020}
2021
2022exports.DownloadManager = DownloadManager;
2023
2024/***/ }),
2025/* 7 */
2026/***/ (function(module, exports, __w_pdfjs_require__) {
2027
2028"use strict";
2029
2030
2031Object.defineProperty(exports, "__esModule", {
2032 value: true
2033});
2034exports.viewerCompatibilityParams = void 0;
2035const compatibilityParams = Object.create(null);
2036{
2037 const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
2038 const platform = typeof navigator !== "undefined" && navigator.platform || "";
2039 const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
2040 const isAndroid = /Android/.test(userAgent);
2041 const isIE = /Trident/.test(userAgent);
2042 const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
2043 const isIOSChrome = /CriOS/.test(userAgent);
2044
2045 (function checkOnBlobSupport() {
2046 if (isIE || isIOSChrome) {
2047 compatibilityParams.disableCreateObjectURL = true;
2048 }
2049 })();
2050
2051 (function checkCanvasSizeLimitation() {
2052 if (isIOS || isAndroid) {
2053 compatibilityParams.maxCanvasPixels = 5242880;
2054 }
2055 })();
2056}
2057const viewerCompatibilityParams = Object.freeze(compatibilityParams);
2058exports.viewerCompatibilityParams = viewerCompatibilityParams;
2059
2060/***/ }),
2061/* 8 */
2062/***/ (function(module, exports, __w_pdfjs_require__) {
2063
2064"use strict";
2065
2066
2067Object.defineProperty(exports, "__esModule", {
2068 value: true
2069});
2070exports.GenericL10n = void 0;
2071
2072__w_pdfjs_require__(9);
2073
2074const webL10n = document.webL10n;
2075
2076class GenericL10n {
2077 constructor(lang) {
2078 this._lang = lang;
2079 this._ready = new Promise((resolve, reject) => {
2080 webL10n.setLanguage(lang, () => {
2081 resolve(webL10n);
2082 });
2083 });
2084 }
2085
2086 async getLanguage() {
2087 const l10n = await this._ready;
2088 return l10n.getLanguage();
2089 }
2090
2091 async getDirection() {
2092 const l10n = await this._ready;
2093 return l10n.getDirection();
2094 }
2095
2096 async get(property, args, fallback) {
2097 const l10n = await this._ready;
2098 return l10n.get(property, args, fallback);
2099 }
2100
2101 async translate(element) {
2102 const l10n = await this._ready;
2103 return l10n.translate(element);
2104 }
2105
2106}
2107
2108exports.GenericL10n = GenericL10n;
2109
2110/***/ }),
2111/* 9 */
2112/***/ (function(module, exports, __w_pdfjs_require__) {
2113
2114"use strict";
2115
2116
2117document.webL10n = function (window, document, undefined) {
2118 var gL10nData = {};
2119 var gTextData = '';
2120 var gTextProp = 'textContent';
2121 var gLanguage = '';
2122 var gMacros = {};
2123 var gReadyState = 'loading';
2124 var gAsyncResourceLoading = true;
2125
2126 function getL10nResourceLinks() {
2127 return document.querySelectorAll('link[type="application/l10n"]');
2128 }
2129
2130 function getL10nDictionary() {
2131 var script = document.querySelector('script[type="application/l10n"]');
2132 return script ? JSON.parse(script.innerHTML) : null;
2133 }
2134
2135 function getTranslatableChildren(element) {
2136 return element ? element.querySelectorAll('*[data-l10n-id]') : [];
2137 }
2138
2139 function getL10nAttributes(element) {
2140 if (!element) return {};
2141 var l10nId = element.getAttribute('data-l10n-id');
2142 var l10nArgs = element.getAttribute('data-l10n-args');
2143 var args = {};
2144
2145 if (l10nArgs) {
2146 try {
2147 args = JSON.parse(l10nArgs);
2148 } catch (e) {
2149 console.warn('could not parse arguments for #' + l10nId);
2150 }
2151 }
2152
2153 return {
2154 id: l10nId,
2155 args: args
2156 };
2157 }
2158
2159 function xhrLoadText(url, onSuccess, onFailure) {
2160 onSuccess = onSuccess || function _onSuccess(data) {};
2161
2162 onFailure = onFailure || function _onFailure() {};
2163
2164 var xhr = new XMLHttpRequest();
2165 xhr.open('GET', url, gAsyncResourceLoading);
2166
2167 if (xhr.overrideMimeType) {
2168 xhr.overrideMimeType('text/plain; charset=utf-8');
2169 }
2170
2171 xhr.onreadystatechange = function () {
2172 if (xhr.readyState == 4) {
2173 if (xhr.status == 200 || xhr.status === 0) {
2174 onSuccess(xhr.responseText);
2175 } else {
2176 onFailure();
2177 }
2178 }
2179 };
2180
2181 xhr.onerror = onFailure;
2182 xhr.ontimeout = onFailure;
2183
2184 try {
2185 xhr.send(null);
2186 } catch (e) {
2187 onFailure();
2188 }
2189 }
2190
2191 function parseResource(href, lang, successCallback, failureCallback) {
2192 var baseURL = href.replace(/[^\/]*$/, '') || './';
2193
2194 function evalString(text) {
2195 if (text.lastIndexOf('\\') < 0) return text;
2196 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, "'");
2197 }
2198
2199 function parseProperties(text, parsedPropertiesCallback) {
2200 var dictionary = {};
2201 var reBlank = /^\s*|\s*$/;
2202 var reComment = /^\s*#|^\s*$/;
2203 var reSection = /^\s*\[(.*)\]\s*$/;
2204 var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
2205 var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
2206
2207 function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
2208 var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
2209 var currentLang = '*';
2210 var genericLang = lang.split('-', 1)[0];
2211 var skipLang = false;
2212 var match = '';
2213
2214 function nextEntry() {
2215 while (true) {
2216 if (!entries.length) {
2217 parsedRawLinesCallback();
2218 return;
2219 }
2220
2221 var line = entries.shift();
2222 if (reComment.test(line)) continue;
2223
2224 if (extendedSyntax) {
2225 match = reSection.exec(line);
2226
2227 if (match) {
2228 currentLang = match[1].toLowerCase();
2229 skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
2230 continue;
2231 } else if (skipLang) {
2232 continue;
2233 }
2234
2235 match = reImport.exec(line);
2236
2237 if (match) {
2238 loadImport(baseURL + match[1], nextEntry);
2239 return;
2240 }
2241 }
2242
2243 var tmp = line.match(reSplit);
2244
2245 if (tmp && tmp.length == 3) {
2246 dictionary[tmp[1]] = evalString(tmp[2]);
2247 }
2248 }
2249 }
2250
2251 nextEntry();
2252 }
2253
2254 function loadImport(url, callback) {
2255 xhrLoadText(url, function (content) {
2256 parseRawLines(content, false, callback);
2257 }, function () {
2258 console.warn(url + ' not found.');
2259 callback();
2260 });
2261 }
2262
2263 parseRawLines(text, true, function () {
2264 parsedPropertiesCallback(dictionary);
2265 });
2266 }
2267
2268 xhrLoadText(href, function (response) {
2269 gTextData += response;
2270 parseProperties(response, function (data) {
2271 for (var key in data) {
2272 var id,
2273 prop,
2274 index = key.lastIndexOf('.');
2275
2276 if (index > 0) {
2277 id = key.substring(0, index);
2278 prop = key.substring(index + 1);
2279 } else {
2280 id = key;
2281 prop = gTextProp;
2282 }
2283
2284 if (!gL10nData[id]) {
2285 gL10nData[id] = {};
2286 }
2287
2288 gL10nData[id][prop] = data[key];
2289 }
2290
2291 if (successCallback) {
2292 successCallback();
2293 }
2294 });
2295 }, failureCallback);
2296 }
2297
2298 function loadLocale(lang, callback) {
2299 if (lang) {
2300 lang = lang.toLowerCase();
2301 }
2302
2303 callback = callback || function _callback() {};
2304
2305 clear();
2306 gLanguage = lang;
2307 var langLinks = getL10nResourceLinks();
2308 var langCount = langLinks.length;
2309
2310 if (langCount === 0) {
2311 var dict = getL10nDictionary();
2312
2313 if (dict && dict.locales && dict.default_locale) {
2314 console.log('using the embedded JSON directory, early way out');
2315 gL10nData = dict.locales[lang];
2316
2317 if (!gL10nData) {
2318 var defaultLocale = dict.default_locale.toLowerCase();
2319
2320 for (var anyCaseLang in dict.locales) {
2321 anyCaseLang = anyCaseLang.toLowerCase();
2322
2323 if (anyCaseLang === lang) {
2324 gL10nData = dict.locales[lang];
2325 break;
2326 } else if (anyCaseLang === defaultLocale) {
2327 gL10nData = dict.locales[defaultLocale];
2328 }
2329 }
2330 }
2331
2332 callback();
2333 } else {
2334 console.log('no resource to load, early way out');
2335 }
2336
2337 gReadyState = 'complete';
2338 return;
2339 }
2340
2341 var onResourceLoaded = null;
2342 var gResourceCount = 0;
2343
2344 onResourceLoaded = function () {
2345 gResourceCount++;
2346
2347 if (gResourceCount >= langCount) {
2348 callback();
2349 gReadyState = 'complete';
2350 }
2351 };
2352
2353 function L10nResourceLink(link) {
2354 var href = link.href;
2355
2356 this.load = function (lang, callback) {
2357 parseResource(href, lang, callback, function () {
2358 console.warn(href + ' not found.');
2359 console.warn('"' + lang + '" resource not found');
2360 gLanguage = '';
2361 callback();
2362 });
2363 };
2364 }
2365
2366 for (var i = 0; i < langCount; i++) {
2367 var resource = new L10nResourceLink(langLinks[i]);
2368 resource.load(lang, onResourceLoaded);
2369 }
2370 }
2371
2372 function clear() {
2373 gL10nData = {};
2374 gTextData = '';
2375 gLanguage = '';
2376 }
2377
2378 function getPluralRules(lang) {
2379 var locales2rules = {
2380 'af': 3,
2381 'ak': 4,
2382 'am': 4,
2383 'ar': 1,
2384 'asa': 3,
2385 'az': 0,
2386 'be': 11,
2387 'bem': 3,
2388 'bez': 3,
2389 'bg': 3,
2390 'bh': 4,
2391 'bm': 0,
2392 'bn': 3,
2393 'bo': 0,
2394 'br': 20,
2395 'brx': 3,
2396 'bs': 11,
2397 'ca': 3,
2398 'cgg': 3,
2399 'chr': 3,
2400 'cs': 12,
2401 'cy': 17,
2402 'da': 3,
2403 'de': 3,
2404 'dv': 3,
2405 'dz': 0,
2406 'ee': 3,
2407 'el': 3,
2408 'en': 3,
2409 'eo': 3,
2410 'es': 3,
2411 'et': 3,
2412 'eu': 3,
2413 'fa': 0,
2414 'ff': 5,
2415 'fi': 3,
2416 'fil': 4,
2417 'fo': 3,
2418 'fr': 5,
2419 'fur': 3,
2420 'fy': 3,
2421 'ga': 8,
2422 'gd': 24,
2423 'gl': 3,
2424 'gsw': 3,
2425 'gu': 3,
2426 'guw': 4,
2427 'gv': 23,
2428 'ha': 3,
2429 'haw': 3,
2430 'he': 2,
2431 'hi': 4,
2432 'hr': 11,
2433 'hu': 0,
2434 'id': 0,
2435 'ig': 0,
2436 'ii': 0,
2437 'is': 3,
2438 'it': 3,
2439 'iu': 7,
2440 'ja': 0,
2441 'jmc': 3,
2442 'jv': 0,
2443 'ka': 0,
2444 'kab': 5,
2445 'kaj': 3,
2446 'kcg': 3,
2447 'kde': 0,
2448 'kea': 0,
2449 'kk': 3,
2450 'kl': 3,
2451 'km': 0,
2452 'kn': 0,
2453 'ko': 0,
2454 'ksb': 3,
2455 'ksh': 21,
2456 'ku': 3,
2457 'kw': 7,
2458 'lag': 18,
2459 'lb': 3,
2460 'lg': 3,
2461 'ln': 4,
2462 'lo': 0,
2463 'lt': 10,
2464 'lv': 6,
2465 'mas': 3,
2466 'mg': 4,
2467 'mk': 16,
2468 'ml': 3,
2469 'mn': 3,
2470 'mo': 9,
2471 'mr': 3,
2472 'ms': 0,
2473 'mt': 15,
2474 'my': 0,
2475 'nah': 3,
2476 'naq': 7,
2477 'nb': 3,
2478 'nd': 3,
2479 'ne': 3,
2480 'nl': 3,
2481 'nn': 3,
2482 'no': 3,
2483 'nr': 3,
2484 'nso': 4,
2485 'ny': 3,
2486 'nyn': 3,
2487 'om': 3,
2488 'or': 3,
2489 'pa': 3,
2490 'pap': 3,
2491 'pl': 13,
2492 'ps': 3,
2493 'pt': 3,
2494 'rm': 3,
2495 'ro': 9,
2496 'rof': 3,
2497 'ru': 11,
2498 'rwk': 3,
2499 'sah': 0,
2500 'saq': 3,
2501 'se': 7,
2502 'seh': 3,
2503 'ses': 0,
2504 'sg': 0,
2505 'sh': 11,
2506 'shi': 19,
2507 'sk': 12,
2508 'sl': 14,
2509 'sma': 7,
2510 'smi': 7,
2511 'smj': 7,
2512 'smn': 7,
2513 'sms': 7,
2514 'sn': 3,
2515 'so': 3,
2516 'sq': 3,
2517 'sr': 11,
2518 'ss': 3,
2519 'ssy': 3,
2520 'st': 3,
2521 'sv': 3,
2522 'sw': 3,
2523 'syr': 3,
2524 'ta': 3,
2525 'te': 3,
2526 'teo': 3,
2527 'th': 0,
2528 'ti': 4,
2529 'tig': 3,
2530 'tk': 3,
2531 'tl': 4,
2532 'tn': 3,
2533 'to': 0,
2534 'tr': 0,
2535 'ts': 3,
2536 'tzm': 22,
2537 'uk': 11,
2538 'ur': 3,
2539 've': 3,
2540 'vi': 0,
2541 'vun': 3,
2542 'wa': 4,
2543 'wae': 3,
2544 'wo': 0,
2545 'xh': 3,
2546 'xog': 3,
2547 'yo': 0,
2548 'zh': 0,
2549 'zu': 3
2550 };
2551
2552 function isIn(n, list) {
2553 return list.indexOf(n) !== -1;
2554 }
2555
2556 function isBetween(n, start, end) {
2557 return start <= n && n <= end;
2558 }
2559
2560 var pluralRules = {
2561 '0': function (n) {
2562 return 'other';
2563 },
2564 '1': function (n) {
2565 if (isBetween(n % 100, 3, 10)) return 'few';
2566 if (n === 0) return 'zero';
2567 if (isBetween(n % 100, 11, 99)) return 'many';
2568 if (n == 2) return 'two';
2569 if (n == 1) return 'one';
2570 return 'other';
2571 },
2572 '2': function (n) {
2573 if (n !== 0 && n % 10 === 0) return 'many';
2574 if (n == 2) return 'two';
2575 if (n == 1) return 'one';
2576 return 'other';
2577 },
2578 '3': function (n) {
2579 if (n == 1) return 'one';
2580 return 'other';
2581 },
2582 '4': function (n) {
2583 if (isBetween(n, 0, 1)) return 'one';
2584 return 'other';
2585 },
2586 '5': function (n) {
2587 if (isBetween(n, 0, 2) && n != 2) return 'one';
2588 return 'other';
2589 },
2590 '6': function (n) {
2591 if (n === 0) return 'zero';
2592 if (n % 10 == 1 && n % 100 != 11) return 'one';
2593 return 'other';
2594 },
2595 '7': function (n) {
2596 if (n == 2) return 'two';
2597 if (n == 1) return 'one';
2598 return 'other';
2599 },
2600 '8': function (n) {
2601 if (isBetween(n, 3, 6)) return 'few';
2602 if (isBetween(n, 7, 10)) return 'many';
2603 if (n == 2) return 'two';
2604 if (n == 1) return 'one';
2605 return 'other';
2606 },
2607 '9': function (n) {
2608 if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
2609 if (n == 1) return 'one';
2610 return 'other';
2611 },
2612 '10': function (n) {
2613 if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
2614 if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
2615 return 'other';
2616 },
2617 '11': function (n) {
2618 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
2619 if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
2620 if (n % 10 == 1 && n % 100 != 11) return 'one';
2621 return 'other';
2622 },
2623 '12': function (n) {
2624 if (isBetween(n, 2, 4)) return 'few';
2625 if (n == 1) return 'one';
2626 return 'other';
2627 },
2628 '13': function (n) {
2629 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
2630 if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
2631 if (n == 1) return 'one';
2632 return 'other';
2633 },
2634 '14': function (n) {
2635 if (isBetween(n % 100, 3, 4)) return 'few';
2636 if (n % 100 == 2) return 'two';
2637 if (n % 100 == 1) return 'one';
2638 return 'other';
2639 },
2640 '15': function (n) {
2641 if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
2642 if (isBetween(n % 100, 11, 19)) return 'many';
2643 if (n == 1) return 'one';
2644 return 'other';
2645 },
2646 '16': function (n) {
2647 if (n % 10 == 1 && n != 11) return 'one';
2648 return 'other';
2649 },
2650 '17': function (n) {
2651 if (n == 3) return 'few';
2652 if (n === 0) return 'zero';
2653 if (n == 6) return 'many';
2654 if (n == 2) return 'two';
2655 if (n == 1) return 'one';
2656 return 'other';
2657 },
2658 '18': function (n) {
2659 if (n === 0) return 'zero';
2660 if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
2661 return 'other';
2662 },
2663 '19': function (n) {
2664 if (isBetween(n, 2, 10)) return 'few';
2665 if (isBetween(n, 0, 1)) return 'one';
2666 return 'other';
2667 },
2668 '20': function (n) {
2669 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';
2670 if (n % 1000000 === 0 && n !== 0) return 'many';
2671 if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
2672 if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
2673 return 'other';
2674 },
2675 '21': function (n) {
2676 if (n === 0) return 'zero';
2677 if (n == 1) return 'one';
2678 return 'other';
2679 },
2680 '22': function (n) {
2681 if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
2682 return 'other';
2683 },
2684 '23': function (n) {
2685 if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
2686 return 'other';
2687 },
2688 '24': function (n) {
2689 if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
2690 if (isIn(n, [2, 12])) return 'two';
2691 if (isIn(n, [1, 11])) return 'one';
2692 return 'other';
2693 }
2694 };
2695 var index = locales2rules[lang.replace(/-.*$/, '')];
2696
2697 if (!(index in pluralRules)) {
2698 console.warn('plural form unknown for [' + lang + ']');
2699 return function () {
2700 return 'other';
2701 };
2702 }
2703
2704 return pluralRules[index];
2705 }
2706
2707 gMacros.plural = function (str, param, key, prop) {
2708 var n = parseFloat(param);
2709 if (isNaN(n)) return str;
2710 if (prop != gTextProp) return str;
2711
2712 if (!gMacros._pluralRules) {
2713 gMacros._pluralRules = getPluralRules(gLanguage);
2714 }
2715
2716 var index = '[' + gMacros._pluralRules(n) + ']';
2717
2718 if (n === 0 && key + '[zero]' in gL10nData) {
2719 str = gL10nData[key + '[zero]'][prop];
2720 } else if (n == 1 && key + '[one]' in gL10nData) {
2721 str = gL10nData[key + '[one]'][prop];
2722 } else if (n == 2 && key + '[two]' in gL10nData) {
2723 str = gL10nData[key + '[two]'][prop];
2724 } else if (key + index in gL10nData) {
2725 str = gL10nData[key + index][prop];
2726 } else if (key + '[other]' in gL10nData) {
2727 str = gL10nData[key + '[other]'][prop];
2728 }
2729
2730 return str;
2731 };
2732
2733 function getL10nData(key, args, fallback) {
2734 var data = gL10nData[key];
2735
2736 if (!data) {
2737 console.warn('#' + key + ' is undefined.');
2738
2739 if (!fallback) {
2740 return null;
2741 }
2742
2743 data = fallback;
2744 }
2745
2746 var rv = {};
2747
2748 for (var prop in data) {
2749 var str = data[prop];
2750 str = substIndexes(str, args, key, prop);
2751 str = substArguments(str, args, key);
2752 rv[prop] = str;
2753 }
2754
2755 return rv;
2756 }
2757
2758 function substIndexes(str, args, key, prop) {
2759 var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
2760 var reMatch = reIndex.exec(str);
2761 if (!reMatch || !reMatch.length) return str;
2762 var macroName = reMatch[1];
2763 var paramName = reMatch[2];
2764 var param;
2765
2766 if (args && paramName in args) {
2767 param = args[paramName];
2768 } else if (paramName in gL10nData) {
2769 param = gL10nData[paramName];
2770 }
2771
2772 if (macroName in gMacros) {
2773 var macro = gMacros[macroName];
2774 str = macro(str, param, key, prop);
2775 }
2776
2777 return str;
2778 }
2779
2780 function substArguments(str, args, key) {
2781 var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
2782 return str.replace(reArgs, function (matched_text, arg) {
2783 if (args && arg in args) {
2784 return args[arg];
2785 }
2786
2787 if (arg in gL10nData) {
2788 return gL10nData[arg];
2789 }
2790
2791 console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
2792 return matched_text;
2793 });
2794 }
2795
2796 function translateElement(element) {
2797 var l10n = getL10nAttributes(element);
2798 if (!l10n.id) return;
2799 var data = getL10nData(l10n.id, l10n.args);
2800
2801 if (!data) {
2802 console.warn('#' + l10n.id + ' is undefined.');
2803 return;
2804 }
2805
2806 if (data[gTextProp]) {
2807 if (getChildElementCount(element) === 0) {
2808 element[gTextProp] = data[gTextProp];
2809 } else {
2810 var children = element.childNodes;
2811 var found = false;
2812
2813 for (var i = 0, l = children.length; i < l; i++) {
2814 if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
2815 if (found) {
2816 children[i].nodeValue = '';
2817 } else {
2818 children[i].nodeValue = data[gTextProp];
2819 found = true;
2820 }
2821 }
2822 }
2823
2824 if (!found) {
2825 var textNode = document.createTextNode(data[gTextProp]);
2826 element.insertBefore(textNode, element.firstChild);
2827 }
2828 }
2829
2830 delete data[gTextProp];
2831 }
2832
2833 for (var k in data) {
2834 element[k] = data[k];
2835 }
2836 }
2837
2838 function getChildElementCount(element) {
2839 if (element.children) {
2840 return element.children.length;
2841 }
2842
2843 if (typeof element.childElementCount !== 'undefined') {
2844 return element.childElementCount;
2845 }
2846
2847 var count = 0;
2848
2849 for (var i = 0; i < element.childNodes.length; i++) {
2850 count += element.nodeType === 1 ? 1 : 0;
2851 }
2852
2853 return count;
2854 }
2855
2856 function translateFragment(element) {
2857 element = element || document.documentElement;
2858 var children = getTranslatableChildren(element);
2859 var elementCount = children.length;
2860
2861 for (var i = 0; i < elementCount; i++) {
2862 translateElement(children[i]);
2863 }
2864
2865 translateElement(element);
2866 }
2867
2868 return {
2869 get: function (key, args, fallbackString) {
2870 var index = key.lastIndexOf('.');
2871 var prop = gTextProp;
2872
2873 if (index > 0) {
2874 prop = key.substring(index + 1);
2875 key = key.substring(0, index);
2876 }
2877
2878 var fallback;
2879
2880 if (fallbackString) {
2881 fallback = {};
2882 fallback[prop] = fallbackString;
2883 }
2884
2885 var data = getL10nData(key, args, fallback);
2886
2887 if (data && prop in data) {
2888 return data[prop];
2889 }
2890
2891 return '{{' + key + '}}';
2892 },
2893 getData: function () {
2894 return gL10nData;
2895 },
2896 getText: function () {
2897 return gTextData;
2898 },
2899 getLanguage: function () {
2900 return gLanguage;
2901 },
2902 setLanguage: function (lang, callback) {
2903 loadLocale(lang, function () {
2904 if (callback) callback();
2905 });
2906 },
2907 getDirection: function () {
2908 var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
2909 var shortCode = gLanguage.split('-', 1)[0];
2910 return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
2911 },
2912 translate: translateFragment,
2913 getReadyState: function () {
2914 return gReadyState;
2915 },
2916 ready: function (callback) {
2917 if (!callback) {
2918 return;
2919 } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
2920 window.setTimeout(function () {
2921 callback();
2922 });
2923 } else if (document.addEventListener) {
2924 document.addEventListener('localized', function once() {
2925 document.removeEventListener('localized', once);
2926 callback();
2927 });
2928 }
2929 }
2930 };
2931}(window, document);
2932
2933/***/ }),
2934/* 10 */
2935/***/ (function(module, exports, __w_pdfjs_require__) {
2936
2937"use strict";
2938
2939
2940Object.defineProperty(exports, "__esModule", {
2941 value: true
2942});
2943exports.PDFFindController = exports.FindState = void 0;
2944
2945var _pdfjsLib = __w_pdfjs_require__(2);
2946
2947var _pdf_find_utils = __w_pdfjs_require__(11);
2948
2949var _ui_utils = __w_pdfjs_require__(3);
2950
2951const FindState = {
2952 FOUND: 0,
2953 NOT_FOUND: 1,
2954 WRAPPED: 2,
2955 PENDING: 3
2956};
2957exports.FindState = FindState;
2958const FIND_TIMEOUT = 250;
2959const MATCH_SCROLL_OFFSET_TOP = -50;
2960const MATCH_SCROLL_OFFSET_LEFT = -400;
2961const CHARACTERS_TO_NORMALIZE = {
2962 "\u2018": "'",
2963 "\u2019": "'",
2964 "\u201A": "'",
2965 "\u201B": "'",
2966 "\u201C": '"',
2967 "\u201D": '"',
2968 "\u201E": '"',
2969 "\u201F": '"',
2970 "\u00BC": "1/4",
2971 "\u00BD": "1/2",
2972 "\u00BE": "3/4"
2973};
2974let normalizationRegex = null;
2975
2976function normalize(text) {
2977 if (!normalizationRegex) {
2978 const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
2979 normalizationRegex = new RegExp(`[${replace}]`, "g");
2980 }
2981
2982 return text.replace(normalizationRegex, function (ch) {
2983 return CHARACTERS_TO_NORMALIZE[ch];
2984 });
2985}
2986
2987class PDFFindController {
2988 constructor({
2989 linkService,
2990 eventBus
2991 }) {
2992 this._linkService = linkService;
2993 this._eventBus = eventBus;
2994
2995 this._reset();
2996
2997 eventBus._on("findbarclose", this._onFindBarClose.bind(this));
2998 }
2999
3000 get highlightMatches() {
3001 return this._highlightMatches;
3002 }
3003
3004 get pageMatches() {
3005 return this._pageMatches;
3006 }
3007
3008 get pageMatchesLength() {
3009 return this._pageMatchesLength;
3010 }
3011
3012 get selected() {
3013 return this._selected;
3014 }
3015
3016 get state() {
3017 return this._state;
3018 }
3019
3020 setDocument(pdfDocument) {
3021 if (this._pdfDocument) {
3022 this._reset();
3023 }
3024
3025 if (!pdfDocument) {
3026 return;
3027 }
3028
3029 this._pdfDocument = pdfDocument;
3030
3031 this._firstPageCapability.resolve();
3032 }
3033
3034 executeCommand(cmd, state) {
3035 if (!state) {
3036 return;
3037 }
3038
3039 const pdfDocument = this._pdfDocument;
3040
3041 if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
3042 this._dirtyMatch = true;
3043 }
3044
3045 this._state = state;
3046
3047 if (cmd !== "findhighlightallchange") {
3048 this._updateUIState(FindState.PENDING);
3049 }
3050
3051 this._firstPageCapability.promise.then(() => {
3052 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
3053 return;
3054 }
3055
3056 this._extractText();
3057
3058 const findbarClosed = !this._highlightMatches;
3059 const pendingTimeout = !!this._findTimeout;
3060
3061 if (this._findTimeout) {
3062 clearTimeout(this._findTimeout);
3063 this._findTimeout = null;
3064 }
3065
3066 if (cmd === "find") {
3067 this._findTimeout = setTimeout(() => {
3068 this._nextMatch();
3069
3070 this._findTimeout = null;
3071 }, FIND_TIMEOUT);
3072 } else if (this._dirtyMatch) {
3073 this._nextMatch();
3074 } else if (cmd === "findagain") {
3075 this._nextMatch();
3076
3077 if (findbarClosed && this._state.highlightAll) {
3078 this._updateAllPages();
3079 }
3080 } else if (cmd === "findhighlightallchange") {
3081 if (pendingTimeout) {
3082 this._nextMatch();
3083 } else {
3084 this._highlightMatches = true;
3085 }
3086
3087 this._updateAllPages();
3088 } else {
3089 this._nextMatch();
3090 }
3091 });
3092 }
3093
3094 scrollMatchIntoView({
3095 element = null,
3096 pageIndex = -1,
3097 matchIndex = -1
3098 }) {
3099 if (!this._scrollMatches || !element) {
3100 return;
3101 } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
3102 return;
3103 } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
3104 return;
3105 }
3106
3107 this._scrollMatches = false;
3108 const spot = {
3109 top: MATCH_SCROLL_OFFSET_TOP,
3110 left: MATCH_SCROLL_OFFSET_LEFT
3111 };
3112 (0, _ui_utils.scrollIntoView)(element, spot, true);
3113 }
3114
3115 _reset() {
3116 this._highlightMatches = false;
3117 this._scrollMatches = false;
3118 this._pdfDocument = null;
3119 this._pageMatches = [];
3120 this._pageMatchesLength = [];
3121 this._state = null;
3122 this._selected = {
3123 pageIdx: -1,
3124 matchIdx: -1
3125 };
3126 this._offset = {
3127 pageIdx: null,
3128 matchIdx: null,
3129 wrapped: false
3130 };
3131 this._extractTextPromises = [];
3132 this._pageContents = [];
3133 this._matchesCountTotal = 0;
3134 this._pagesToSearch = null;
3135 this._pendingFindMatches = Object.create(null);
3136 this._resumePageIdx = null;
3137 this._dirtyMatch = false;
3138 clearTimeout(this._findTimeout);
3139 this._findTimeout = null;
3140 this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
3141 }
3142
3143 get _query() {
3144 if (this._state.query !== this._rawQuery) {
3145 this._rawQuery = this._state.query;
3146 this._normalizedQuery = normalize(this._state.query);
3147 }
3148
3149 return this._normalizedQuery;
3150 }
3151
3152 _shouldDirtyMatch(cmd, state) {
3153 if (state.query !== this._state.query) {
3154 return true;
3155 }
3156
3157 switch (cmd) {
3158 case "findagain":
3159 const pageNumber = this._selected.pageIdx + 1;
3160 const linkService = this._linkService;
3161
3162 if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
3163 return true;
3164 }
3165
3166 return false;
3167
3168 case "findhighlightallchange":
3169 return false;
3170 }
3171
3172 return true;
3173 }
3174
3175 _prepareMatches(matchesWithLength, matches, matchesLength) {
3176 function isSubTerm(currentIndex) {
3177 const currentElem = matchesWithLength[currentIndex];
3178 const nextElem = matchesWithLength[currentIndex + 1];
3179
3180 if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
3181 currentElem.skipped = true;
3182 return true;
3183 }
3184
3185 for (let i = currentIndex - 1; i >= 0; i--) {
3186 const prevElem = matchesWithLength[i];
3187
3188 if (prevElem.skipped) {
3189 continue;
3190 }
3191
3192 if (prevElem.match + prevElem.matchLength < currentElem.match) {
3193 break;
3194 }
3195
3196 if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
3197 currentElem.skipped = true;
3198 return true;
3199 }
3200 }
3201
3202 return false;
3203 }
3204
3205 matchesWithLength.sort(function (a, b) {
3206 return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
3207 });
3208
3209 for (let i = 0, len = matchesWithLength.length; i < len; i++) {
3210 if (isSubTerm(i)) {
3211 continue;
3212 }
3213
3214 matches.push(matchesWithLength[i].match);
3215 matchesLength.push(matchesWithLength[i].matchLength);
3216 }
3217 }
3218
3219 _isEntireWord(content, startIdx, length) {
3220 if (startIdx > 0) {
3221 const first = content.charCodeAt(startIdx);
3222 const limit = content.charCodeAt(startIdx - 1);
3223
3224 if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
3225 return false;
3226 }
3227 }
3228
3229 const endIdx = startIdx + length - 1;
3230
3231 if (endIdx < content.length - 1) {
3232 const last = content.charCodeAt(endIdx);
3233 const limit = content.charCodeAt(endIdx + 1);
3234
3235 if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
3236 return false;
3237 }
3238 }
3239
3240 return true;
3241 }
3242
3243 _calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
3244 const matches = [];
3245 const queryLen = query.length;
3246 let matchIdx = -queryLen;
3247
3248 while (true) {
3249 matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
3250
3251 if (matchIdx === -1) {
3252 break;
3253 }
3254
3255 if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
3256 continue;
3257 }
3258
3259 matches.push(matchIdx);
3260 }
3261
3262 this._pageMatches[pageIndex] = matches;
3263 }
3264
3265 _calculateWordMatch(query, pageIndex, pageContent, entireWord) {
3266 const matchesWithLength = [];
3267 const queryArray = query.match(/\S+/g);
3268
3269 for (let i = 0, len = queryArray.length; i < len; i++) {
3270 const subquery = queryArray[i];
3271 const subqueryLen = subquery.length;
3272 let matchIdx = -subqueryLen;
3273
3274 while (true) {
3275 matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
3276
3277 if (matchIdx === -1) {
3278 break;
3279 }
3280
3281 if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
3282 continue;
3283 }
3284
3285 matchesWithLength.push({
3286 match: matchIdx,
3287 matchLength: subqueryLen,
3288 skipped: false
3289 });
3290 }
3291 }
3292
3293 this._pageMatchesLength[pageIndex] = [];
3294 this._pageMatches[pageIndex] = [];
3295
3296 this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
3297 }
3298
3299 _calculateMatch(pageIndex) {
3300 let pageContent = this._pageContents[pageIndex];
3301 let query = this._query;
3302 const {
3303 caseSensitive,
3304 entireWord,
3305 phraseSearch
3306 } = this._state;
3307
3308 if (query.length === 0) {
3309 return;
3310 }
3311
3312 if (!caseSensitive) {
3313 pageContent = pageContent.toLowerCase();
3314 query = query.toLowerCase();
3315 }
3316
3317 if (phraseSearch) {
3318 this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
3319 } else {
3320 this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
3321 }
3322
3323 if (this._state.highlightAll) {
3324 this._updatePage(pageIndex);
3325 }
3326
3327 if (this._resumePageIdx === pageIndex) {
3328 this._resumePageIdx = null;
3329
3330 this._nextPageMatch();
3331 }
3332
3333 const pageMatchesCount = this._pageMatches[pageIndex].length;
3334
3335 if (pageMatchesCount > 0) {
3336 this._matchesCountTotal += pageMatchesCount;
3337
3338 this._updateUIResultsCount();
3339 }
3340 }
3341
3342 _extractText() {
3343 if (this._extractTextPromises.length > 0) {
3344 return;
3345 }
3346
3347 let promise = Promise.resolve();
3348
3349 for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
3350 const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
3351 this._extractTextPromises[i] = extractTextCapability.promise;
3352 promise = promise.then(() => {
3353 return this._pdfDocument.getPage(i + 1).then(pdfPage => {
3354 return pdfPage.getTextContent({
3355 normalizeWhitespace: true
3356 });
3357 }).then(textContent => {
3358 const textItems = textContent.items;
3359 const strBuf = [];
3360
3361 for (let j = 0, jj = textItems.length; j < jj; j++) {
3362 strBuf.push(textItems[j].str);
3363 }
3364
3365 this._pageContents[i] = normalize(strBuf.join(""));
3366 extractTextCapability.resolve(i);
3367 }, reason => {
3368 console.error(`Unable to get text content for page ${i + 1}`, reason);
3369 this._pageContents[i] = "";
3370 extractTextCapability.resolve(i);
3371 });
3372 });
3373 }
3374 }
3375
3376 _updatePage(index) {
3377 if (this._scrollMatches && this._selected.pageIdx === index) {
3378 this._linkService.page = index + 1;
3379 }
3380
3381 this._eventBus.dispatch("updatetextlayermatches", {
3382 source: this,
3383 pageIndex: index
3384 });
3385 }
3386
3387 _updateAllPages() {
3388 this._eventBus.dispatch("updatetextlayermatches", {
3389 source: this,
3390 pageIndex: -1
3391 });
3392 }
3393
3394 _nextMatch() {
3395 const previous = this._state.findPrevious;
3396 const currentPageIndex = this._linkService.page - 1;
3397 const numPages = this._linkService.pagesCount;
3398 this._highlightMatches = true;
3399
3400 if (this._dirtyMatch) {
3401 this._dirtyMatch = false;
3402 this._selected.pageIdx = this._selected.matchIdx = -1;
3403 this._offset.pageIdx = currentPageIndex;
3404 this._offset.matchIdx = null;
3405 this._offset.wrapped = false;
3406 this._resumePageIdx = null;
3407 this._pageMatches.length = 0;
3408 this._pageMatchesLength.length = 0;
3409 this._matchesCountTotal = 0;
3410
3411 this._updateAllPages();
3412
3413 for (let i = 0; i < numPages; i++) {
3414 if (this._pendingFindMatches[i] === true) {
3415 continue;
3416 }
3417
3418 this._pendingFindMatches[i] = true;
3419
3420 this._extractTextPromises[i].then(pageIdx => {
3421 delete this._pendingFindMatches[pageIdx];
3422
3423 this._calculateMatch(pageIdx);
3424 });
3425 }
3426 }
3427
3428 if (this._query === "") {
3429 this._updateUIState(FindState.FOUND);
3430
3431 return;
3432 }
3433
3434 if (this._resumePageIdx) {
3435 return;
3436 }
3437
3438 const offset = this._offset;
3439 this._pagesToSearch = numPages;
3440
3441 if (offset.matchIdx !== null) {
3442 const numPageMatches = this._pageMatches[offset.pageIdx].length;
3443
3444 if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
3445 offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
3446
3447 this._updateMatch(true);
3448
3449 return;
3450 }
3451
3452 this._advanceOffsetPage(previous);
3453 }
3454
3455 this._nextPageMatch();
3456 }
3457
3458 _matchesReady(matches) {
3459 const offset = this._offset;
3460 const numMatches = matches.length;
3461 const previous = this._state.findPrevious;
3462
3463 if (numMatches) {
3464 offset.matchIdx = previous ? numMatches - 1 : 0;
3465
3466 this._updateMatch(true);
3467
3468 return true;
3469 }
3470
3471 this._advanceOffsetPage(previous);
3472
3473 if (offset.wrapped) {
3474 offset.matchIdx = null;
3475
3476 if (this._pagesToSearch < 0) {
3477 this._updateMatch(false);
3478
3479 return true;
3480 }
3481 }
3482
3483 return false;
3484 }
3485
3486 _nextPageMatch() {
3487 if (this._resumePageIdx !== null) {
3488 console.error("There can only be one pending page.");
3489 }
3490
3491 let matches = null;
3492
3493 do {
3494 const pageIdx = this._offset.pageIdx;
3495 matches = this._pageMatches[pageIdx];
3496
3497 if (!matches) {
3498 this._resumePageIdx = pageIdx;
3499 break;
3500 }
3501 } while (!this._matchesReady(matches));
3502 }
3503
3504 _advanceOffsetPage(previous) {
3505 const offset = this._offset;
3506 const numPages = this._linkService.pagesCount;
3507 offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
3508 offset.matchIdx = null;
3509 this._pagesToSearch--;
3510
3511 if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
3512 offset.pageIdx = previous ? numPages - 1 : 0;
3513 offset.wrapped = true;
3514 }
3515 }
3516
3517 _updateMatch(found = false) {
3518 let state = FindState.NOT_FOUND;
3519 const wrapped = this._offset.wrapped;
3520 this._offset.wrapped = false;
3521
3522 if (found) {
3523 const previousPage = this._selected.pageIdx;
3524 this._selected.pageIdx = this._offset.pageIdx;
3525 this._selected.matchIdx = this._offset.matchIdx;
3526 state = wrapped ? FindState.WRAPPED : FindState.FOUND;
3527
3528 if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
3529 this._updatePage(previousPage);
3530 }
3531 }
3532
3533 this._updateUIState(state, this._state.findPrevious);
3534
3535 if (this._selected.pageIdx !== -1) {
3536 this._scrollMatches = true;
3537
3538 this._updatePage(this._selected.pageIdx);
3539 }
3540 }
3541
3542 _onFindBarClose(evt) {
3543 const pdfDocument = this._pdfDocument;
3544
3545 this._firstPageCapability.promise.then(() => {
3546 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
3547 return;
3548 }
3549
3550 if (this._findTimeout) {
3551 clearTimeout(this._findTimeout);
3552 this._findTimeout = null;
3553 }
3554
3555 if (this._resumePageIdx) {
3556 this._resumePageIdx = null;
3557 this._dirtyMatch = true;
3558 }
3559
3560 this._updateUIState(FindState.FOUND);
3561
3562 this._highlightMatches = false;
3563
3564 this._updateAllPages();
3565 });
3566 }
3567
3568 _requestMatchesCount() {
3569 const {
3570 pageIdx,
3571 matchIdx
3572 } = this._selected;
3573 let current = 0,
3574 total = this._matchesCountTotal;
3575
3576 if (matchIdx !== -1) {
3577 for (let i = 0; i < pageIdx; i++) {
3578 current += this._pageMatches[i] && this._pageMatches[i].length || 0;
3579 }
3580
3581 current += matchIdx + 1;
3582 }
3583
3584 if (current < 1 || current > total) {
3585 current = total = 0;
3586 }
3587
3588 return {
3589 current,
3590 total
3591 };
3592 }
3593
3594 _updateUIResultsCount() {
3595 this._eventBus.dispatch("updatefindmatchescount", {
3596 source: this,
3597 matchesCount: this._requestMatchesCount()
3598 });
3599 }
3600
3601 _updateUIState(state, previous) {
3602 this._eventBus.dispatch("updatefindcontrolstate", {
3603 source: this,
3604 state,
3605 previous,
3606 matchesCount: this._requestMatchesCount()
3607 });
3608 }
3609
3610}
3611
3612exports.PDFFindController = PDFFindController;
3613
3614/***/ }),
3615/* 11 */
3616/***/ (function(module, exports, __w_pdfjs_require__) {
3617
3618"use strict";
3619
3620
3621Object.defineProperty(exports, "__esModule", {
3622 value: true
3623});
3624exports.getCharacterType = getCharacterType;
3625exports.CharacterType = void 0;
3626const CharacterType = {
3627 SPACE: 0,
3628 ALPHA_LETTER: 1,
3629 PUNCT: 2,
3630 HAN_LETTER: 3,
3631 KATAKANA_LETTER: 4,
3632 HIRAGANA_LETTER: 5,
3633 HALFWIDTH_KATAKANA_LETTER: 6,
3634 THAI_LETTER: 7
3635};
3636exports.CharacterType = CharacterType;
3637
3638function isAlphabeticalScript(charCode) {
3639 return charCode < 0x2e80;
3640}
3641
3642function isAscii(charCode) {
3643 return (charCode & 0xff80) === 0;
3644}
3645
3646function isAsciiAlpha(charCode) {
3647 return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
3648}
3649
3650function isAsciiDigit(charCode) {
3651 return charCode >= 0x30 && charCode <= 0x39;
3652}
3653
3654function isAsciiSpace(charCode) {
3655 return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
3656}
3657
3658function isHan(charCode) {
3659 return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
3660}
3661
3662function isKatakana(charCode) {
3663 return charCode >= 0x30a0 && charCode <= 0x30ff;
3664}
3665
3666function isHiragana(charCode) {
3667 return charCode >= 0x3040 && charCode <= 0x309f;
3668}
3669
3670function isHalfwidthKatakana(charCode) {
3671 return charCode >= 0xff60 && charCode <= 0xff9f;
3672}
3673
3674function isThai(charCode) {
3675 return (charCode & 0xff80) === 0x0e00;
3676}
3677
3678function getCharacterType(charCode) {
3679 if (isAlphabeticalScript(charCode)) {
3680 if (isAscii(charCode)) {
3681 if (isAsciiSpace(charCode)) {
3682 return CharacterType.SPACE;
3683 } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
3684 return CharacterType.ALPHA_LETTER;
3685 }
3686
3687 return CharacterType.PUNCT;
3688 } else if (isThai(charCode)) {
3689 return CharacterType.THAI_LETTER;
3690 } else if (charCode === 0xa0) {
3691 return CharacterType.SPACE;
3692 }
3693
3694 return CharacterType.ALPHA_LETTER;
3695 }
3696
3697 if (isHan(charCode)) {
3698 return CharacterType.HAN_LETTER;
3699 } else if (isKatakana(charCode)) {
3700 return CharacterType.KATAKANA_LETTER;
3701 } else if (isHiragana(charCode)) {
3702 return CharacterType.HIRAGANA_LETTER;
3703 } else if (isHalfwidthKatakana(charCode)) {
3704 return CharacterType.HALFWIDTH_KATAKANA_LETTER;
3705 }
3706
3707 return CharacterType.ALPHA_LETTER;
3708}
3709
3710/***/ }),
3711/* 12 */
3712/***/ (function(module, exports, __w_pdfjs_require__) {
3713
3714"use strict";
3715
3716
3717Object.defineProperty(exports, "__esModule", {
3718 value: true
3719});
3720exports.isDestHashesEqual = isDestHashesEqual;
3721exports.isDestArraysEqual = isDestArraysEqual;
3722exports.PDFHistory = void 0;
3723
3724var _ui_utils = __w_pdfjs_require__(3);
3725
3726const HASH_CHANGE_TIMEOUT = 1000;
3727const POSITION_UPDATED_THRESHOLD = 50;
3728const UPDATE_VIEWAREA_TIMEOUT = 1000;
3729
3730function getCurrentHash() {
3731 return document.location.hash;
3732}
3733
3734class PDFHistory {
3735 constructor({
3736 linkService,
3737 eventBus
3738 }) {
3739 this.linkService = linkService;
3740 this.eventBus = eventBus;
3741 this._initialized = false;
3742 this._fingerprint = "";
3743 this.reset();
3744 this._boundEvents = null;
3745 this._isViewerInPresentationMode = false;
3746
3747 this.eventBus._on("presentationmodechanged", evt => {
3748 this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
3749 });
3750
3751 this.eventBus._on("pagesinit", () => {
3752 this._isPagesLoaded = false;
3753
3754 const onPagesLoaded = evt => {
3755 this.eventBus._off("pagesloaded", onPagesLoaded);
3756
3757 this._isPagesLoaded = !!evt.pagesCount;
3758 };
3759
3760 this.eventBus._on("pagesloaded", onPagesLoaded);
3761 });
3762 }
3763
3764 initialize({
3765 fingerprint,
3766 resetHistory = false,
3767 updateUrl = false
3768 }) {
3769 if (!fingerprint || typeof fingerprint !== "string") {
3770 console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
3771 return;
3772 }
3773
3774 if (this._initialized) {
3775 this.reset();
3776 }
3777
3778 const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
3779 this._fingerprint = fingerprint;
3780 this._updateUrl = updateUrl === true;
3781 this._initialized = true;
3782
3783 this._bindEvents();
3784
3785 const state = window.history.state;
3786 this._popStateInProgress = false;
3787 this._blockHashChange = 0;
3788 this._currentHash = getCurrentHash();
3789 this._numPositionUpdates = 0;
3790 this._uid = this._maxUid = 0;
3791 this._destination = null;
3792 this._position = null;
3793
3794 if (!this._isValidState(state, true) || resetHistory) {
3795 const {
3796 hash,
3797 page,
3798 rotation
3799 } = this._parseCurrentHash(true);
3800
3801 if (!hash || reInitialized || resetHistory) {
3802 this._pushOrReplaceState(null, true);
3803
3804 return;
3805 }
3806
3807 this._pushOrReplaceState({
3808 hash,
3809 page,
3810 rotation
3811 }, true);
3812
3813 return;
3814 }
3815
3816 const destination = state.destination;
3817
3818 this._updateInternalState(destination, state.uid, true);
3819
3820 if (this._uid > this._maxUid) {
3821 this._maxUid = this._uid;
3822 }
3823
3824 if (destination.rotation !== undefined) {
3825 this._initialRotation = destination.rotation;
3826 }
3827
3828 if (destination.dest) {
3829 this._initialBookmark = JSON.stringify(destination.dest);
3830 this._destination.page = null;
3831 } else if (destination.hash) {
3832 this._initialBookmark = destination.hash;
3833 } else if (destination.page) {
3834 this._initialBookmark = `page=${destination.page}`;
3835 }
3836 }
3837
3838 reset() {
3839 if (this._initialized) {
3840 this._pageHide();
3841
3842 this._initialized = false;
3843
3844 this._unbindEvents();
3845 }
3846
3847 if (this._updateViewareaTimeout) {
3848 clearTimeout(this._updateViewareaTimeout);
3849 this._updateViewareaTimeout = null;
3850 }
3851
3852 this._initialBookmark = null;
3853 this._initialRotation = null;
3854 }
3855
3856 push({
3857 namedDest = null,
3858 explicitDest,
3859 pageNumber
3860 }) {
3861 if (!this._initialized) {
3862 return;
3863 }
3864
3865 if (namedDest && typeof namedDest !== "string") {
3866 console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
3867 return;
3868 } else if (!Array.isArray(explicitDest)) {
3869 console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
3870 return;
3871 } else if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
3872 if (pageNumber !== null || this._destination) {
3873 console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
3874 return;
3875 }
3876 }
3877
3878 const hash = namedDest || JSON.stringify(explicitDest);
3879
3880 if (!hash) {
3881 return;
3882 }
3883
3884 let forceReplace = false;
3885
3886 if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
3887 if (this._destination.page) {
3888 return;
3889 }
3890
3891 forceReplace = true;
3892 }
3893
3894 if (this._popStateInProgress && !forceReplace) {
3895 return;
3896 }
3897
3898 this._pushOrReplaceState({
3899 dest: explicitDest,
3900 hash,
3901 page: pageNumber,
3902 rotation: this.linkService.rotation
3903 }, forceReplace);
3904
3905 if (!this._popStateInProgress) {
3906 this._popStateInProgress = true;
3907 Promise.resolve().then(() => {
3908 this._popStateInProgress = false;
3909 });
3910 }
3911 }
3912
3913 pushCurrentPosition() {
3914 if (!this._initialized || this._popStateInProgress) {
3915 return;
3916 }
3917
3918 this._tryPushCurrentPosition();
3919 }
3920
3921 back() {
3922 if (!this._initialized || this._popStateInProgress) {
3923 return;
3924 }
3925
3926 const state = window.history.state;
3927
3928 if (this._isValidState(state) && state.uid > 0) {
3929 window.history.back();
3930 }
3931 }
3932
3933 forward() {
3934 if (!this._initialized || this._popStateInProgress) {
3935 return;
3936 }
3937
3938 const state = window.history.state;
3939
3940 if (this._isValidState(state) && state.uid < this._maxUid) {
3941 window.history.forward();
3942 }
3943 }
3944
3945 get popStateInProgress() {
3946 return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
3947 }
3948
3949 get initialBookmark() {
3950 return this._initialized ? this._initialBookmark : null;
3951 }
3952
3953 get initialRotation() {
3954 return this._initialized ? this._initialRotation : null;
3955 }
3956
3957 _pushOrReplaceState(destination, forceReplace = false) {
3958 const shouldReplace = forceReplace || !this._destination;
3959 const newState = {
3960 fingerprint: this._fingerprint,
3961 uid: shouldReplace ? this._uid : this._uid + 1,
3962 destination
3963 };
3964
3965 this._updateInternalState(destination, newState.uid);
3966
3967 let newUrl;
3968
3969 if (this._updateUrl && destination && destination.hash) {
3970 const baseUrl = document.location.href.split("#")[0];
3971
3972 if (!baseUrl.startsWith("file://")) {
3973 newUrl = `${baseUrl}#${destination.hash}`;
3974 }
3975 }
3976
3977 if (shouldReplace) {
3978 window.history.replaceState(newState, "", newUrl);
3979 } else {
3980 this._maxUid = this._uid;
3981 window.history.pushState(newState, "", newUrl);
3982 }
3983 }
3984
3985 _tryPushCurrentPosition(temporary = false) {
3986 if (!this._position) {
3987 return;
3988 }
3989
3990 let position = this._position;
3991
3992 if (temporary) {
3993 position = Object.assign(Object.create(null), this._position);
3994 position.temporary = true;
3995 }
3996
3997 if (!this._destination) {
3998 this._pushOrReplaceState(position);
3999
4000 return;
4001 }
4002
4003 if (this._destination.temporary) {
4004 this._pushOrReplaceState(position, true);
4005
4006 return;
4007 }
4008
4009 if (this._destination.hash === position.hash) {
4010 return;
4011 }
4012
4013 if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
4014 return;
4015 }
4016
4017 let forceReplace = false;
4018
4019 if (this._destination.page >= position.first && this._destination.page <= position.page) {
4020 if (this._destination.dest || !this._destination.first) {
4021 return;
4022 }
4023
4024 forceReplace = true;
4025 }
4026
4027 this._pushOrReplaceState(position, forceReplace);
4028 }
4029
4030 _isValidState(state, checkReload = false) {
4031 if (!state) {
4032 return false;
4033 }
4034
4035 if (state.fingerprint !== this._fingerprint) {
4036 if (checkReload) {
4037 if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
4038 return false;
4039 }
4040
4041 const [perfEntry] = performance.getEntriesByType("navigation");
4042
4043 if (!perfEntry || perfEntry.type !== "reload") {
4044 return false;
4045 }
4046 } else {
4047 return false;
4048 }
4049 }
4050
4051 if (!Number.isInteger(state.uid) || state.uid < 0) {
4052 return false;
4053 }
4054
4055 if (state.destination === null || typeof state.destination !== "object") {
4056 return false;
4057 }
4058
4059 return true;
4060 }
4061
4062 _updateInternalState(destination, uid, removeTemporary = false) {
4063 if (this._updateViewareaTimeout) {
4064 clearTimeout(this._updateViewareaTimeout);
4065 this._updateViewareaTimeout = null;
4066 }
4067
4068 if (removeTemporary && destination && destination.temporary) {
4069 delete destination.temporary;
4070 }
4071
4072 this._destination = destination;
4073 this._uid = uid;
4074 this._numPositionUpdates = 0;
4075 }
4076
4077 _parseCurrentHash(checkNameddest = false) {
4078 const hash = unescape(getCurrentHash()).substring(1);
4079 const params = (0, _ui_utils.parseQueryString)(hash);
4080 const nameddest = params.nameddest || "";
4081 let page = params.page | 0;
4082
4083 if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount) || checkNameddest && nameddest.length > 0) {
4084 page = null;
4085 }
4086
4087 return {
4088 hash,
4089 page,
4090 rotation: this.linkService.rotation
4091 };
4092 }
4093
4094 _updateViewarea({
4095 location
4096 }) {
4097 if (this._updateViewareaTimeout) {
4098 clearTimeout(this._updateViewareaTimeout);
4099 this._updateViewareaTimeout = null;
4100 }
4101
4102 this._position = {
4103 hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
4104 page: this.linkService.page,
4105 first: location.pageNumber,
4106 rotation: location.rotation
4107 };
4108
4109 if (this._popStateInProgress) {
4110 return;
4111 }
4112
4113 if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
4114 this._numPositionUpdates++;
4115 }
4116
4117 if (UPDATE_VIEWAREA_TIMEOUT > 0) {
4118 this._updateViewareaTimeout = setTimeout(() => {
4119 if (!this._popStateInProgress) {
4120 this._tryPushCurrentPosition(true);
4121 }
4122
4123 this._updateViewareaTimeout = null;
4124 }, UPDATE_VIEWAREA_TIMEOUT);
4125 }
4126 }
4127
4128 _popState({
4129 state
4130 }) {
4131 const newHash = getCurrentHash(),
4132 hashChanged = this._currentHash !== newHash;
4133 this._currentHash = newHash;
4134
4135 if (!state) {
4136 this._uid++;
4137
4138 const {
4139 hash,
4140 page,
4141 rotation
4142 } = this._parseCurrentHash();
4143
4144 this._pushOrReplaceState({
4145 hash,
4146 page,
4147 rotation
4148 }, true);
4149
4150 return;
4151 }
4152
4153 if (!this._isValidState(state)) {
4154 return;
4155 }
4156
4157 this._popStateInProgress = true;
4158
4159 if (hashChanged) {
4160 this._blockHashChange++;
4161 (0, _ui_utils.waitOnEventOrTimeout)({
4162 target: window,
4163 name: "hashchange",
4164 delay: HASH_CHANGE_TIMEOUT
4165 }).then(() => {
4166 this._blockHashChange--;
4167 });
4168 }
4169
4170 const destination = state.destination;
4171
4172 this._updateInternalState(destination, state.uid, true);
4173
4174 if (this._uid > this._maxUid) {
4175 this._maxUid = this._uid;
4176 }
4177
4178 if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
4179 this.linkService.rotation = destination.rotation;
4180 }
4181
4182 if (destination.dest) {
4183 this.linkService.navigateTo(destination.dest);
4184 } else if (destination.hash) {
4185 this.linkService.setHash(destination.hash);
4186 } else if (destination.page) {
4187 this.linkService.page = destination.page;
4188 }
4189
4190 Promise.resolve().then(() => {
4191 this._popStateInProgress = false;
4192 });
4193 }
4194
4195 _pageHide() {
4196 if (!this._destination || this._destination.temporary) {
4197 this._tryPushCurrentPosition();
4198 }
4199 }
4200
4201 _bindEvents() {
4202 if (this._boundEvents) {
4203 return;
4204 }
4205
4206 this._boundEvents = {
4207 updateViewarea: this._updateViewarea.bind(this),
4208 popState: this._popState.bind(this),
4209 pageHide: this._pageHide.bind(this)
4210 };
4211
4212 this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
4213
4214 window.addEventListener("popstate", this._boundEvents.popState);
4215 window.addEventListener("pagehide", this._boundEvents.pageHide);
4216 }
4217
4218 _unbindEvents() {
4219 if (!this._boundEvents) {
4220 return;
4221 }
4222
4223 this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
4224
4225 window.removeEventListener("popstate", this._boundEvents.popState);
4226 window.removeEventListener("pagehide", this._boundEvents.pageHide);
4227 this._boundEvents = null;
4228 }
4229
4230}
4231
4232exports.PDFHistory = PDFHistory;
4233
4234function isDestHashesEqual(destHash, pushHash) {
4235 if (typeof destHash !== "string" || typeof pushHash !== "string") {
4236 return false;
4237 }
4238
4239 if (destHash === pushHash) {
4240 return true;
4241 }
4242
4243 const {
4244 nameddest
4245 } = (0, _ui_utils.parseQueryString)(destHash);
4246
4247 if (nameddest === pushHash) {
4248 return true;
4249 }
4250
4251 return false;
4252}
4253
4254function isDestArraysEqual(firstDest, secondDest) {
4255 function isEntryEqual(first, second) {
4256 if (typeof first !== typeof second) {
4257 return false;
4258 }
4259
4260 if (Array.isArray(first) || Array.isArray(second)) {
4261 return false;
4262 }
4263
4264 if (first !== null && typeof first === "object" && second !== null) {
4265 if (Object.keys(first).length !== Object.keys(second).length) {
4266 return false;
4267 }
4268
4269 for (const key in first) {
4270 if (!isEntryEqual(first[key], second[key])) {
4271 return false;
4272 }
4273 }
4274
4275 return true;
4276 }
4277
4278 return first === second || Number.isNaN(first) && Number.isNaN(second);
4279 }
4280
4281 if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
4282 return false;
4283 }
4284
4285 if (firstDest.length !== secondDest.length) {
4286 return false;
4287 }
4288
4289 for (let i = 0, ii = firstDest.length; i < ii; i++) {
4290 if (!isEntryEqual(firstDest[i], secondDest[i])) {
4291 return false;
4292 }
4293 }
4294
4295 return true;
4296}
4297
4298/***/ }),
4299/* 13 */
4300/***/ (function(module, exports, __w_pdfjs_require__) {
4301
4302"use strict";
4303
4304
4305Object.defineProperty(exports, "__esModule", {
4306 value: true
4307});
4308exports.PDFPageView = void 0;
4309
4310var _ui_utils = __w_pdfjs_require__(3);
4311
4312var _pdfjsLib = __w_pdfjs_require__(2);
4313
4314var _pdf_rendering_queue = __w_pdfjs_require__(14);
4315
4316var _viewer_compatibility = __w_pdfjs_require__(7);
4317
4318const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
4319
4320class PDFPageView {
4321 constructor(options) {
4322 const container = options.container;
4323 const defaultViewport = options.defaultViewport;
4324 this.id = options.id;
4325 this.renderingId = "page" + this.id;
4326 this.pdfPage = null;
4327 this.pageLabel = null;
4328 this.rotation = 0;
4329 this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
4330 this.viewport = defaultViewport;
4331 this.pdfPageRotate = defaultViewport.rotation;
4332 this.hasRestrictedScaling = false;
4333 this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
4334 this.imageResourcesPath = options.imageResourcesPath || "";
4335 this.renderInteractiveForms = options.renderInteractiveForms || false;
4336 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
4337 this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
4338 this.eventBus = options.eventBus;
4339 this.renderingQueue = options.renderingQueue;
4340 this.textLayerFactory = options.textLayerFactory;
4341 this.annotationLayerFactory = options.annotationLayerFactory;
4342 this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
4343 this.enableWebGL = options.enableWebGL || false;
4344 this.l10n = options.l10n || _ui_utils.NullL10n;
4345 this.paintTask = null;
4346 this.paintedViewportMap = new WeakMap();
4347 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
4348 this.resume = null;
4349 this.error = null;
4350 this.annotationLayer = null;
4351 this.textLayer = null;
4352 this.zoomLayer = null;
4353 const div = document.createElement("div");
4354 div.className = "page";
4355 div.style.width = Math.floor(this.viewport.width) + "px";
4356 div.style.height = Math.floor(this.viewport.height) + "px";
4357 div.setAttribute("data-page-number", this.id);
4358 this.div = div;
4359 container.appendChild(div);
4360 }
4361
4362 setPdfPage(pdfPage) {
4363 this.pdfPage = pdfPage;
4364 this.pdfPageRotate = pdfPage.rotate;
4365 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
4366 this.viewport = pdfPage.getViewport({
4367 scale: this.scale * _ui_utils.CSS_UNITS,
4368 rotation: totalRotation
4369 });
4370 this.stats = pdfPage.stats;
4371 this.reset();
4372 }
4373
4374 destroy() {
4375 this.reset();
4376
4377 if (this.pdfPage) {
4378 this.pdfPage.cleanup();
4379 }
4380 }
4381
4382 _resetZoomLayer(removeFromDOM = false) {
4383 if (!this.zoomLayer) {
4384 return;
4385 }
4386
4387 const zoomLayerCanvas = this.zoomLayer.firstChild;
4388 this.paintedViewportMap.delete(zoomLayerCanvas);
4389 zoomLayerCanvas.width = 0;
4390 zoomLayerCanvas.height = 0;
4391
4392 if (removeFromDOM) {
4393 this.zoomLayer.remove();
4394 }
4395
4396 this.zoomLayer = null;
4397 }
4398
4399 reset(keepZoomLayer = false, keepAnnotations = false) {
4400 this.cancelRendering(keepAnnotations);
4401 this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
4402 const div = this.div;
4403 div.style.width = Math.floor(this.viewport.width) + "px";
4404 div.style.height = Math.floor(this.viewport.height) + "px";
4405 const childNodes = div.childNodes;
4406 const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
4407 const currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
4408
4409 for (let i = childNodes.length - 1; i >= 0; i--) {
4410 const node = childNodes[i];
4411
4412 if (currentZoomLayerNode === node || currentAnnotationNode === node) {
4413 continue;
4414 }
4415
4416 div.removeChild(node);
4417 }
4418
4419 div.removeAttribute("data-loaded");
4420
4421 if (currentAnnotationNode) {
4422 this.annotationLayer.hide();
4423 } else if (this.annotationLayer) {
4424 this.annotationLayer.cancel();
4425 this.annotationLayer = null;
4426 }
4427
4428 if (!currentZoomLayerNode) {
4429 if (this.canvas) {
4430 this.paintedViewportMap.delete(this.canvas);
4431 this.canvas.width = 0;
4432 this.canvas.height = 0;
4433 delete this.canvas;
4434 }
4435
4436 this._resetZoomLayer();
4437 }
4438
4439 if (this.svg) {
4440 this.paintedViewportMap.delete(this.svg);
4441 delete this.svg;
4442 }
4443
4444 this.loadingIconDiv = document.createElement("div");
4445 this.loadingIconDiv.className = "loadingIcon";
4446 div.appendChild(this.loadingIconDiv);
4447 }
4448
4449 update(scale, rotation) {
4450 this.scale = scale || this.scale;
4451
4452 if (typeof rotation !== "undefined") {
4453 this.rotation = rotation;
4454 }
4455
4456 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
4457 this.viewport = this.viewport.clone({
4458 scale: this.scale * _ui_utils.CSS_UNITS,
4459 rotation: totalRotation
4460 });
4461
4462 if (this.svg) {
4463 this.cssTransform(this.svg, true);
4464 this.eventBus.dispatch("pagerendered", {
4465 source: this,
4466 pageNumber: this.id,
4467 cssTransform: true,
4468 timestamp: performance.now()
4469 });
4470 return;
4471 }
4472
4473 let isScalingRestricted = false;
4474
4475 if (this.canvas && this.maxCanvasPixels > 0) {
4476 const outputScale = this.outputScale;
4477
4478 if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
4479 isScalingRestricted = true;
4480 }
4481 }
4482
4483 if (this.canvas) {
4484 if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
4485 this.cssTransform(this.canvas, true);
4486 this.eventBus.dispatch("pagerendered", {
4487 source: this,
4488 pageNumber: this.id,
4489 cssTransform: true,
4490 timestamp: performance.now()
4491 });
4492 return;
4493 }
4494
4495 if (!this.zoomLayer && !this.canvas.hasAttribute("hidden")) {
4496 this.zoomLayer = this.canvas.parentNode;
4497 this.zoomLayer.style.position = "absolute";
4498 }
4499 }
4500
4501 if (this.zoomLayer) {
4502 this.cssTransform(this.zoomLayer.firstChild);
4503 }
4504
4505 this.reset(true, true);
4506 }
4507
4508 cancelRendering(keepAnnotations = false) {
4509 if (this.paintTask) {
4510 this.paintTask.cancel();
4511 this.paintTask = null;
4512 }
4513
4514 this.resume = null;
4515
4516 if (this.textLayer) {
4517 this.textLayer.cancel();
4518 this.textLayer = null;
4519 }
4520
4521 if (!keepAnnotations && this.annotationLayer) {
4522 this.annotationLayer.cancel();
4523 this.annotationLayer = null;
4524 }
4525 }
4526
4527 cssTransform(target, redrawAnnotations = false) {
4528 const width = this.viewport.width;
4529 const height = this.viewport.height;
4530 const div = this.div;
4531 target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
4532 target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
4533 const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
4534 const absRotation = Math.abs(relativeRotation);
4535 let scaleX = 1,
4536 scaleY = 1;
4537
4538 if (absRotation === 90 || absRotation === 270) {
4539 scaleX = height / width;
4540 scaleY = width / height;
4541 }
4542
4543 const cssTransform = "rotate(" + relativeRotation + "deg) " + "scale(" + scaleX + "," + scaleY + ")";
4544 target.style.transform = cssTransform;
4545
4546 if (this.textLayer) {
4547 const textLayerViewport = this.textLayer.viewport;
4548 const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
4549 const textAbsRotation = Math.abs(textRelativeRotation);
4550 let scale = width / textLayerViewport.width;
4551
4552 if (textAbsRotation === 90 || textAbsRotation === 270) {
4553 scale = width / textLayerViewport.height;
4554 }
4555
4556 const textLayerDiv = this.textLayer.textLayerDiv;
4557 let transX, transY;
4558
4559 switch (textAbsRotation) {
4560 case 0:
4561 transX = transY = 0;
4562 break;
4563
4564 case 90:
4565 transX = 0;
4566 transY = "-" + textLayerDiv.style.height;
4567 break;
4568
4569 case 180:
4570 transX = "-" + textLayerDiv.style.width;
4571 transY = "-" + textLayerDiv.style.height;
4572 break;
4573
4574 case 270:
4575 transX = "-" + textLayerDiv.style.width;
4576 transY = 0;
4577 break;
4578
4579 default:
4580 console.error("Bad rotation value.");
4581 break;
4582 }
4583
4584 textLayerDiv.style.transform = "rotate(" + textAbsRotation + "deg) " + "scale(" + scale + ", " + scale + ") " + "translate(" + transX + ", " + transY + ")";
4585 textLayerDiv.style.transformOrigin = "0% 0%";
4586 }
4587
4588 if (redrawAnnotations && this.annotationLayer) {
4589 this.annotationLayer.render(this.viewport, "display");
4590 }
4591 }
4592
4593 get width() {
4594 return this.viewport.width;
4595 }
4596
4597 get height() {
4598 return this.viewport.height;
4599 }
4600
4601 getPagePoint(x, y) {
4602 return this.viewport.convertToPdfPoint(x, y);
4603 }
4604
4605 draw() {
4606 if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
4607 console.error("Must be in new state before drawing");
4608 this.reset();
4609 }
4610
4611 const {
4612 div,
4613 pdfPage
4614 } = this;
4615
4616 if (!pdfPage) {
4617 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
4618
4619 if (this.loadingIconDiv) {
4620 div.removeChild(this.loadingIconDiv);
4621 delete this.loadingIconDiv;
4622 }
4623
4624 return Promise.reject(new Error("pdfPage is not loaded"));
4625 }
4626
4627 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
4628 const canvasWrapper = document.createElement("div");
4629 canvasWrapper.style.width = div.style.width;
4630 canvasWrapper.style.height = div.style.height;
4631 canvasWrapper.classList.add("canvasWrapper");
4632
4633 if (this.annotationLayer && this.annotationLayer.div) {
4634 div.insertBefore(canvasWrapper, this.annotationLayer.div);
4635 } else {
4636 div.appendChild(canvasWrapper);
4637 }
4638
4639 let textLayer = null;
4640
4641 if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
4642 const textLayerDiv = document.createElement("div");
4643 textLayerDiv.className = "textLayer";
4644 textLayerDiv.style.width = canvasWrapper.style.width;
4645 textLayerDiv.style.height = canvasWrapper.style.height;
4646
4647 if (this.annotationLayer && this.annotationLayer.div) {
4648 div.insertBefore(textLayerDiv, this.annotationLayer.div);
4649 } else {
4650 div.appendChild(textLayerDiv);
4651 }
4652
4653 textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
4654 }
4655
4656 this.textLayer = textLayer;
4657 let renderContinueCallback = null;
4658
4659 if (this.renderingQueue) {
4660 renderContinueCallback = cont => {
4661 if (!this.renderingQueue.isHighestPriority(this)) {
4662 this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
4663
4664 this.resume = () => {
4665 this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
4666 cont();
4667 };
4668
4669 return;
4670 }
4671
4672 cont();
4673 };
4674 }
4675
4676 const finishPaintTask = async error => {
4677 if (paintTask === this.paintTask) {
4678 this.paintTask = null;
4679 }
4680
4681 if (error instanceof _pdfjsLib.RenderingCancelledException) {
4682 this.error = null;
4683 return;
4684 }
4685
4686 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
4687
4688 if (this.loadingIconDiv) {
4689 div.removeChild(this.loadingIconDiv);
4690 delete this.loadingIconDiv;
4691 }
4692
4693 this._resetZoomLayer(true);
4694
4695 this.error = error;
4696 this.stats = pdfPage.stats;
4697 this.eventBus.dispatch("pagerendered", {
4698 source: this,
4699 pageNumber: this.id,
4700 cssTransform: false,
4701 timestamp: performance.now()
4702 });
4703
4704 if (error) {
4705 throw error;
4706 }
4707 };
4708
4709 const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
4710 paintTask.onRenderContinue = renderContinueCallback;
4711 this.paintTask = paintTask;
4712 const resultPromise = paintTask.promise.then(function () {
4713 return finishPaintTask(null).then(function () {
4714 if (textLayer) {
4715 const readableStream = pdfPage.streamTextContent({
4716 normalizeWhitespace: true
4717 });
4718 textLayer.setTextContentStream(readableStream);
4719 textLayer.render();
4720 }
4721 });
4722 }, function (reason) {
4723 return finishPaintTask(reason);
4724 });
4725
4726 if (this.annotationLayerFactory) {
4727 if (!this.annotationLayer) {
4728 this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
4729 }
4730
4731 this.annotationLayer.render(this.viewport, "display");
4732 }
4733
4734 div.setAttribute("data-loaded", true);
4735 this.eventBus.dispatch("pagerender", {
4736 source: this,
4737 pageNumber: this.id
4738 });
4739 return resultPromise;
4740 }
4741
4742 paintOnCanvas(canvasWrapper) {
4743 const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
4744 const result = {
4745 promise: renderCapability.promise,
4746
4747 onRenderContinue(cont) {
4748 cont();
4749 },
4750
4751 cancel() {
4752 renderTask.cancel();
4753 }
4754
4755 };
4756 const viewport = this.viewport;
4757 const canvas = document.createElement("canvas");
4758 this.l10n.get("page_canvas", {
4759 page: this.id
4760 }, "Page {{page}}").then(msg => {
4761 canvas.setAttribute("aria-label", msg);
4762 });
4763 canvas.setAttribute("hidden", "hidden");
4764 let isCanvasHidden = true;
4765
4766 const showCanvas = function () {
4767 if (isCanvasHidden) {
4768 canvas.removeAttribute("hidden");
4769 isCanvasHidden = false;
4770 }
4771 };
4772
4773 canvasWrapper.appendChild(canvas);
4774 this.canvas = canvas;
4775 canvas.mozOpaque = true;
4776 const ctx = canvas.getContext("2d", {
4777 alpha: false
4778 });
4779 const outputScale = (0, _ui_utils.getOutputScale)(ctx);
4780 this.outputScale = outputScale;
4781
4782 if (this.useOnlyCssZoom) {
4783 const actualSizeViewport = viewport.clone({
4784 scale: _ui_utils.CSS_UNITS
4785 });
4786 outputScale.sx *= actualSizeViewport.width / viewport.width;
4787 outputScale.sy *= actualSizeViewport.height / viewport.height;
4788 outputScale.scaled = true;
4789 }
4790
4791 if (this.maxCanvasPixels > 0) {
4792 const pixelsInViewport = viewport.width * viewport.height;
4793 const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
4794
4795 if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
4796 outputScale.sx = maxScale;
4797 outputScale.sy = maxScale;
4798 outputScale.scaled = true;
4799 this.hasRestrictedScaling = true;
4800 } else {
4801 this.hasRestrictedScaling = false;
4802 }
4803 }
4804
4805 const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
4806 const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
4807 canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
4808 canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
4809 canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
4810 canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
4811 this.paintedViewportMap.set(canvas, viewport);
4812 const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
4813 const renderContext = {
4814 canvasContext: ctx,
4815 transform,
4816 viewport: this.viewport,
4817 enableWebGL: this.enableWebGL,
4818 renderInteractiveForms: this.renderInteractiveForms
4819 };
4820 const renderTask = this.pdfPage.render(renderContext);
4821
4822 renderTask.onContinue = function (cont) {
4823 showCanvas();
4824
4825 if (result.onRenderContinue) {
4826 result.onRenderContinue(cont);
4827 } else {
4828 cont();
4829 }
4830 };
4831
4832 renderTask.promise.then(function () {
4833 showCanvas();
4834 renderCapability.resolve(undefined);
4835 }, function (error) {
4836 showCanvas();
4837 renderCapability.reject(error);
4838 });
4839 return result;
4840 }
4841
4842 paintOnSvg(wrapper) {
4843 let cancelled = false;
4844
4845 const ensureNotCancelled = () => {
4846 if (cancelled) {
4847 throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
4848 }
4849 };
4850
4851 const pdfPage = this.pdfPage;
4852 const actualSizeViewport = this.viewport.clone({
4853 scale: _ui_utils.CSS_UNITS
4854 });
4855 const promise = pdfPage.getOperatorList().then(opList => {
4856 ensureNotCancelled();
4857 const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
4858 return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
4859 ensureNotCancelled();
4860 this.svg = svg;
4861 this.paintedViewportMap.set(svg, actualSizeViewport);
4862 svg.style.width = wrapper.style.width;
4863 svg.style.height = wrapper.style.height;
4864 this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
4865 wrapper.appendChild(svg);
4866 });
4867 });
4868 return {
4869 promise,
4870
4871 onRenderContinue(cont) {
4872 cont();
4873 },
4874
4875 cancel() {
4876 cancelled = true;
4877 }
4878
4879 };
4880 }
4881
4882 setPageLabel(label) {
4883 this.pageLabel = typeof label === "string" ? label : null;
4884
4885 if (this.pageLabel !== null) {
4886 this.div.setAttribute("data-page-label", this.pageLabel);
4887 } else {
4888 this.div.removeAttribute("data-page-label");
4889 }
4890 }
4891
4892}
4893
4894exports.PDFPageView = PDFPageView;
4895
4896/***/ }),
4897/* 14 */
4898/***/ (function(module, exports, __w_pdfjs_require__) {
4899
4900"use strict";
4901
4902
4903Object.defineProperty(exports, "__esModule", {
4904 value: true
4905});
4906exports.PDFRenderingQueue = exports.RenderingStates = void 0;
4907const CLEANUP_TIMEOUT = 30000;
4908const RenderingStates = {
4909 INITIAL: 0,
4910 RUNNING: 1,
4911 PAUSED: 2,
4912 FINISHED: 3
4913};
4914exports.RenderingStates = RenderingStates;
4915
4916class PDFRenderingQueue {
4917 constructor() {
4918 this.pdfViewer = null;
4919 this.pdfThumbnailViewer = null;
4920 this.onIdle = null;
4921 this.highestPriorityPage = null;
4922 this.idleTimeout = null;
4923 this.printing = false;
4924 this.isThumbnailViewEnabled = false;
4925 }
4926
4927 setViewer(pdfViewer) {
4928 this.pdfViewer = pdfViewer;
4929 }
4930
4931 setThumbnailViewer(pdfThumbnailViewer) {
4932 this.pdfThumbnailViewer = pdfThumbnailViewer;
4933 }
4934
4935 isHighestPriority(view) {
4936 return this.highestPriorityPage === view.renderingId;
4937 }
4938
4939 renderHighestPriority(currentlyVisiblePages) {
4940 if (this.idleTimeout) {
4941 clearTimeout(this.idleTimeout);
4942 this.idleTimeout = null;
4943 }
4944
4945 if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
4946 return;
4947 }
4948
4949 if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
4950 if (this.pdfThumbnailViewer.forceRendering()) {
4951 return;
4952 }
4953 }
4954
4955 if (this.printing) {
4956 return;
4957 }
4958
4959 if (this.onIdle) {
4960 this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
4961 }
4962 }
4963
4964 getHighestPriority(visible, views, scrolledDown) {
4965 const visibleViews = visible.views;
4966 const numVisible = visibleViews.length;
4967
4968 if (numVisible === 0) {
4969 return null;
4970 }
4971
4972 for (let i = 0; i < numVisible; ++i) {
4973 const view = visibleViews[i].view;
4974
4975 if (!this.isViewFinished(view)) {
4976 return view;
4977 }
4978 }
4979
4980 if (scrolledDown) {
4981 const nextPageIndex = visible.last.id;
4982
4983 if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
4984 return views[nextPageIndex];
4985 }
4986 } else {
4987 const previousPageIndex = visible.first.id - 2;
4988
4989 if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
4990 return views[previousPageIndex];
4991 }
4992 }
4993
4994 return null;
4995 }
4996
4997 isViewFinished(view) {
4998 return view.renderingState === RenderingStates.FINISHED;
4999 }
5000
5001 renderView(view) {
5002 switch (view.renderingState) {
5003 case RenderingStates.FINISHED:
5004 return false;
5005
5006 case RenderingStates.PAUSED:
5007 this.highestPriorityPage = view.renderingId;
5008 view.resume();
5009 break;
5010
5011 case RenderingStates.RUNNING:
5012 this.highestPriorityPage = view.renderingId;
5013 break;
5014
5015 case RenderingStates.INITIAL:
5016 this.highestPriorityPage = view.renderingId;
5017 view.draw().finally(() => {
5018 this.renderHighestPriority();
5019 }).catch(reason => {
5020 console.error(`renderView: "${reason}"`);
5021 });
5022 break;
5023 }
5024
5025 return true;
5026 }
5027
5028}
5029
5030exports.PDFRenderingQueue = PDFRenderingQueue;
5031
5032/***/ }),
5033/* 15 */
5034/***/ (function(module, exports, __w_pdfjs_require__) {
5035
5036"use strict";
5037
5038
5039Object.defineProperty(exports, "__esModule", {
5040 value: true
5041});
5042exports.PDFSinglePageViewer = void 0;
5043
5044var _base_viewer = __w_pdfjs_require__(16);
5045
5046var _pdfjsLib = __w_pdfjs_require__(2);
5047
5048class PDFSinglePageViewer extends _base_viewer.BaseViewer {
5049 constructor(options) {
5050 super(options);
5051
5052 this.eventBus._on("pagesinit", evt => {
5053 this._ensurePageViewVisible();
5054 });
5055 }
5056
5057 get _viewerElement() {
5058 return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
5059 }
5060
5061 _resetView() {
5062 super._resetView();
5063
5064 this._previousPageNumber = 1;
5065 this._shadowViewer = document.createDocumentFragment();
5066 this._updateScrollDown = null;
5067 }
5068
5069 _ensurePageViewVisible() {
5070 const pageView = this._pages[this._currentPageNumber - 1];
5071 const previousPageView = this._pages[this._previousPageNumber - 1];
5072 const viewerNodes = this.viewer.childNodes;
5073
5074 switch (viewerNodes.length) {
5075 case 0:
5076 this.viewer.appendChild(pageView.div);
5077 break;
5078
5079 case 1:
5080 if (viewerNodes[0] !== previousPageView.div) {
5081 throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
5082 }
5083
5084 if (pageView === previousPageView) {
5085 break;
5086 }
5087
5088 this._shadowViewer.appendChild(previousPageView.div);
5089
5090 this.viewer.appendChild(pageView.div);
5091 this.container.scrollTop = 0;
5092 break;
5093
5094 default:
5095 throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
5096 }
5097
5098 this._previousPageNumber = this._currentPageNumber;
5099 }
5100
5101 _scrollUpdate() {
5102 if (this._updateScrollDown) {
5103 this._updateScrollDown();
5104 }
5105
5106 super._scrollUpdate();
5107 }
5108
5109 _scrollIntoView({
5110 pageDiv,
5111 pageSpot = null,
5112 pageNumber = null
5113 }) {
5114 if (pageNumber) {
5115 this._setCurrentPageNumber(pageNumber);
5116 }
5117
5118 const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
5119
5120 this._ensurePageViewVisible();
5121
5122 this.update();
5123
5124 super._scrollIntoView({
5125 pageDiv,
5126 pageSpot,
5127 pageNumber
5128 });
5129
5130 this._updateScrollDown = () => {
5131 this.scroll.down = scrolledDown;
5132 this._updateScrollDown = null;
5133 };
5134 }
5135
5136 _getVisiblePages() {
5137 return this._getCurrentVisiblePage();
5138 }
5139
5140 _updateHelper(visiblePages) {}
5141
5142 get _isScrollModeHorizontal() {
5143 return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
5144 }
5145
5146 _updateScrollMode() {}
5147
5148 _updateSpreadMode() {}
5149
5150}
5151
5152exports.PDFSinglePageViewer = PDFSinglePageViewer;
5153
5154/***/ }),
5155/* 16 */
5156/***/ (function(module, exports, __w_pdfjs_require__) {
5157
5158"use strict";
5159
5160
5161Object.defineProperty(exports, "__esModule", {
5162 value: true
5163});
5164exports.BaseViewer = void 0;
5165
5166var _ui_utils = __w_pdfjs_require__(3);
5167
5168var _pdf_rendering_queue = __w_pdfjs_require__(14);
5169
5170var _annotation_layer_builder = __w_pdfjs_require__(1);
5171
5172var _pdfjsLib = __w_pdfjs_require__(2);
5173
5174var _pdf_page_view = __w_pdfjs_require__(13);
5175
5176var _pdf_link_service = __w_pdfjs_require__(4);
5177
5178var _text_layer_builder = __w_pdfjs_require__(5);
5179
5180const DEFAULT_CACHE_SIZE = 10;
5181
5182function PDFPageViewBuffer(size) {
5183 const data = [];
5184
5185 this.push = function (view) {
5186 const i = data.indexOf(view);
5187
5188 if (i >= 0) {
5189 data.splice(i, 1);
5190 }
5191
5192 data.push(view);
5193
5194 if (data.length > size) {
5195 data.shift().destroy();
5196 }
5197 };
5198
5199 this.resize = function (newSize, pagesToKeep) {
5200 size = newSize;
5201
5202 if (pagesToKeep) {
5203 const pageIdsToKeep = new Set();
5204
5205 for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
5206 pageIdsToKeep.add(pagesToKeep[i].id);
5207 }
5208
5209 (0, _ui_utils.moveToEndOfArray)(data, function (page) {
5210 return pageIdsToKeep.has(page.id);
5211 });
5212 }
5213
5214 while (data.length > size) {
5215 data.shift().destroy();
5216 }
5217 };
5218}
5219
5220function isSameScale(oldScale, newScale) {
5221 if (newScale === oldScale) {
5222 return true;
5223 }
5224
5225 if (Math.abs(newScale - oldScale) < 1e-15) {
5226 return true;
5227 }
5228
5229 return false;
5230}
5231
5232class BaseViewer {
5233 constructor(options) {
5234 if (this.constructor === BaseViewer) {
5235 throw new Error("Cannot initialize BaseViewer.");
5236 }
5237
5238 this._name = this.constructor.name;
5239 this.container = options.container;
5240 this.viewer = options.viewer || options.container.firstElementChild;
5241 this.eventBus = options.eventBus;
5242 this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
5243 this.downloadManager = options.downloadManager || null;
5244 this.findController = options.findController || null;
5245 this.removePageBorders = options.removePageBorders || false;
5246 this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
5247 this.imageResourcesPath = options.imageResourcesPath || "";
5248 this.renderInteractiveForms = options.renderInteractiveForms || false;
5249 this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
5250 this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
5251 this.enableWebGL = options.enableWebGL || false;
5252 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
5253 this.maxCanvasPixels = options.maxCanvasPixels;
5254 this.l10n = options.l10n || _ui_utils.NullL10n;
5255 this.defaultRenderingQueue = !options.renderingQueue;
5256
5257 if (this.defaultRenderingQueue) {
5258 this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
5259 this.renderingQueue.setViewer(this);
5260 } else {
5261 this.renderingQueue = options.renderingQueue;
5262 }
5263
5264 this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
5265 this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
5266 this._onBeforeDraw = this._onAfterDraw = null;
5267
5268 this._resetView();
5269
5270 if (this.removePageBorders) {
5271 this.viewer.classList.add("removePageBorders");
5272 }
5273
5274 Promise.resolve().then(() => {
5275 this.eventBus.dispatch("baseviewerinit", {
5276 source: this
5277 });
5278 });
5279 }
5280
5281 get pagesCount() {
5282 return this._pages.length;
5283 }
5284
5285 getPageView(index) {
5286 return this._pages[index];
5287 }
5288
5289 get pageViewsReady() {
5290 if (!this._pagesCapability.settled) {
5291 return false;
5292 }
5293
5294 return this._pages.every(function (pageView) {
5295 return pageView && pageView.pdfPage;
5296 });
5297 }
5298
5299 get currentPageNumber() {
5300 return this._currentPageNumber;
5301 }
5302
5303 set currentPageNumber(val) {
5304 if (!Number.isInteger(val)) {
5305 throw new Error("Invalid page number.");
5306 }
5307
5308 if (!this.pdfDocument) {
5309 return;
5310 }
5311
5312 if (!this._setCurrentPageNumber(val, true)) {
5313 console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
5314 }
5315 }
5316
5317 _setCurrentPageNumber(val, resetCurrentPageView = false) {
5318 if (this._currentPageNumber === val) {
5319 if (resetCurrentPageView) {
5320 this._resetCurrentPageView();
5321 }
5322
5323 return true;
5324 }
5325
5326 if (!(0 < val && val <= this.pagesCount)) {
5327 return false;
5328 }
5329
5330 this._currentPageNumber = val;
5331 this.eventBus.dispatch("pagechanging", {
5332 source: this,
5333 pageNumber: val,
5334 pageLabel: this._pageLabels && this._pageLabels[val - 1]
5335 });
5336
5337 if (resetCurrentPageView) {
5338 this._resetCurrentPageView();
5339 }
5340
5341 return true;
5342 }
5343
5344 get currentPageLabel() {
5345 return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
5346 }
5347
5348 set currentPageLabel(val) {
5349 if (!this.pdfDocument) {
5350 return;
5351 }
5352
5353 let page = val | 0;
5354
5355 if (this._pageLabels) {
5356 const i = this._pageLabels.indexOf(val);
5357
5358 if (i >= 0) {
5359 page = i + 1;
5360 }
5361 }
5362
5363 if (!this._setCurrentPageNumber(page, true)) {
5364 console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
5365 }
5366 }
5367
5368 get currentScale() {
5369 return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
5370 }
5371
5372 set currentScale(val) {
5373 if (isNaN(val)) {
5374 throw new Error("Invalid numeric scale.");
5375 }
5376
5377 if (!this.pdfDocument) {
5378 return;
5379 }
5380
5381 this._setScale(val, false);
5382 }
5383
5384 get currentScaleValue() {
5385 return this._currentScaleValue;
5386 }
5387
5388 set currentScaleValue(val) {
5389 if (!this.pdfDocument) {
5390 return;
5391 }
5392
5393 this._setScale(val, false);
5394 }
5395
5396 get pagesRotation() {
5397 return this._pagesRotation;
5398 }
5399
5400 set pagesRotation(rotation) {
5401 if (!(0, _ui_utils.isValidRotation)(rotation)) {
5402 throw new Error("Invalid pages rotation angle.");
5403 }
5404
5405 if (!this.pdfDocument) {
5406 return;
5407 }
5408
5409 if (this._pagesRotation === rotation) {
5410 return;
5411 }
5412
5413 this._pagesRotation = rotation;
5414 const pageNumber = this._currentPageNumber;
5415
5416 for (let i = 0, ii = this._pages.length; i < ii; i++) {
5417 const pageView = this._pages[i];
5418 pageView.update(pageView.scale, rotation);
5419 }
5420
5421 if (this._currentScaleValue) {
5422 this._setScale(this._currentScaleValue, true);
5423 }
5424
5425 this.eventBus.dispatch("rotationchanging", {
5426 source: this,
5427 pagesRotation: rotation,
5428 pageNumber
5429 });
5430
5431 if (this.defaultRenderingQueue) {
5432 this.update();
5433 }
5434 }
5435
5436 get firstPagePromise() {
5437 return this.pdfDocument ? this._firstPageCapability.promise : null;
5438 }
5439
5440 get onePageRendered() {
5441 return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
5442 }
5443
5444 get pagesPromise() {
5445 return this.pdfDocument ? this._pagesCapability.promise : null;
5446 }
5447
5448 get _viewerElement() {
5449 throw new Error("Not implemented: _viewerElement");
5450 }
5451
5452 _onePageRenderedOrForceFetch() {
5453 if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
5454 return Promise.resolve();
5455 }
5456
5457 return this._onePageRenderedCapability.promise;
5458 }
5459
5460 setDocument(pdfDocument) {
5461 if (this.pdfDocument) {
5462 this._cancelRendering();
5463
5464 this._resetView();
5465
5466 if (this.findController) {
5467 this.findController.setDocument(null);
5468 }
5469 }
5470
5471 this.pdfDocument = pdfDocument;
5472
5473 if (!pdfDocument) {
5474 return;
5475 }
5476
5477 const pagesCount = pdfDocument.numPages;
5478 const firstPagePromise = pdfDocument.getPage(1);
5479
5480 this._pagesCapability.promise.then(() => {
5481 this.eventBus.dispatch("pagesloaded", {
5482 source: this,
5483 pagesCount
5484 });
5485 });
5486
5487 this._onBeforeDraw = evt => {
5488 const pageView = this._pages[evt.pageNumber - 1];
5489
5490 if (!pageView) {
5491 return;
5492 }
5493
5494 this._buffer.push(pageView);
5495 };
5496
5497 this.eventBus._on("pagerender", this._onBeforeDraw);
5498
5499 this._onAfterDraw = evt => {
5500 if (evt.cssTransform || this._onePageRenderedCapability.settled) {
5501 return;
5502 }
5503
5504 this._onePageRenderedCapability.resolve();
5505
5506 this.eventBus._off("pagerendered", this._onAfterDraw);
5507
5508 this._onAfterDraw = null;
5509 };
5510
5511 this.eventBus._on("pagerendered", this._onAfterDraw);
5512
5513 firstPagePromise.then(firstPdfPage => {
5514 this._firstPageCapability.resolve(firstPdfPage);
5515
5516 const scale = this.currentScale;
5517 const viewport = firstPdfPage.getViewport({
5518 scale: scale * _ui_utils.CSS_UNITS
5519 });
5520 const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
5521
5522 for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
5523 const pageView = new _pdf_page_view.PDFPageView({
5524 container: this._viewerElement,
5525 eventBus: this.eventBus,
5526 id: pageNum,
5527 scale,
5528 defaultViewport: viewport.clone(),
5529 renderingQueue: this.renderingQueue,
5530 textLayerFactory,
5531 textLayerMode: this.textLayerMode,
5532 annotationLayerFactory: this,
5533 imageResourcesPath: this.imageResourcesPath,
5534 renderInteractiveForms: this.renderInteractiveForms,
5535 renderer: this.renderer,
5536 enableWebGL: this.enableWebGL,
5537 useOnlyCssZoom: this.useOnlyCssZoom,
5538 maxCanvasPixels: this.maxCanvasPixels,
5539 l10n: this.l10n
5540 });
5541
5542 this._pages.push(pageView);
5543 }
5544
5545 const firstPageView = this._pages[0];
5546
5547 if (firstPageView) {
5548 firstPageView.setPdfPage(firstPdfPage);
5549 this.linkService.cachePageRef(1, firstPdfPage.ref);
5550 }
5551
5552 if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
5553 this._updateSpreadMode();
5554 }
5555
5556 this._onePageRenderedOrForceFetch().then(() => {
5557 if (this.findController) {
5558 this.findController.setDocument(pdfDocument);
5559 }
5560
5561 if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
5562 this._pagesCapability.resolve();
5563
5564 return;
5565 }
5566
5567 let getPagesLeft = pagesCount - 1;
5568
5569 if (getPagesLeft <= 0) {
5570 this._pagesCapability.resolve();
5571
5572 return;
5573 }
5574
5575 for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
5576 pdfDocument.getPage(pageNum).then(pdfPage => {
5577 const pageView = this._pages[pageNum - 1];
5578
5579 if (!pageView.pdfPage) {
5580 pageView.setPdfPage(pdfPage);
5581 }
5582
5583 this.linkService.cachePageRef(pageNum, pdfPage.ref);
5584
5585 if (--getPagesLeft === 0) {
5586 this._pagesCapability.resolve();
5587 }
5588 }, reason => {
5589 console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
5590
5591 if (--getPagesLeft === 0) {
5592 this._pagesCapability.resolve();
5593 }
5594 });
5595 }
5596 });
5597
5598 this.eventBus.dispatch("pagesinit", {
5599 source: this
5600 });
5601
5602 if (this.defaultRenderingQueue) {
5603 this.update();
5604 }
5605 }).catch(reason => {
5606 console.error("Unable to initialize viewer", reason);
5607 });
5608 }
5609
5610 setPageLabels(labels) {
5611 if (!this.pdfDocument) {
5612 return;
5613 }
5614
5615 if (!labels) {
5616 this._pageLabels = null;
5617 } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
5618 this._pageLabels = null;
5619 console.error(`${this._name}.setPageLabels: Invalid page labels.`);
5620 } else {
5621 this._pageLabels = labels;
5622 }
5623
5624 for (let i = 0, ii = this._pages.length; i < ii; i++) {
5625 const pageView = this._pages[i];
5626 const label = this._pageLabels && this._pageLabels[i];
5627 pageView.setPageLabel(label);
5628 }
5629 }
5630
5631 _resetView() {
5632 this._pages = [];
5633 this._currentPageNumber = 1;
5634 this._currentScale = _ui_utils.UNKNOWN_SCALE;
5635 this._currentScaleValue = null;
5636 this._pageLabels = null;
5637 this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
5638 this._location = null;
5639 this._pagesRotation = 0;
5640 this._pagesRequests = new WeakMap();
5641 this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
5642 this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
5643 this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
5644 this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
5645 this._spreadMode = _ui_utils.SpreadMode.NONE;
5646
5647 if (this._onBeforeDraw) {
5648 this.eventBus._off("pagerender", this._onBeforeDraw);
5649
5650 this._onBeforeDraw = null;
5651 }
5652
5653 if (this._onAfterDraw) {
5654 this.eventBus._off("pagerendered", this._onAfterDraw);
5655
5656 this._onAfterDraw = null;
5657 }
5658
5659 this.viewer.textContent = "";
5660
5661 this._updateScrollMode();
5662 }
5663
5664 _scrollUpdate() {
5665 if (this.pagesCount === 0) {
5666 return;
5667 }
5668
5669 this.update();
5670 }
5671
5672 _scrollIntoView({
5673 pageDiv,
5674 pageSpot = null,
5675 pageNumber = null
5676 }) {
5677 (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
5678 }
5679
5680 _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
5681 this._currentScaleValue = newValue.toString();
5682
5683 if (isSameScale(this._currentScale, newScale)) {
5684 if (preset) {
5685 this.eventBus.dispatch("scalechanging", {
5686 source: this,
5687 scale: newScale,
5688 presetValue: newValue
5689 });
5690 }
5691
5692 return;
5693 }
5694
5695 for (let i = 0, ii = this._pages.length; i < ii; i++) {
5696 this._pages[i].update(newScale);
5697 }
5698
5699 this._currentScale = newScale;
5700
5701 if (!noScroll) {
5702 let page = this._currentPageNumber,
5703 dest;
5704
5705 if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
5706 page = this._location.pageNumber;
5707 dest = [null, {
5708 name: "XYZ"
5709 }, this._location.left, this._location.top, null];
5710 }
5711
5712 this.scrollPageIntoView({
5713 pageNumber: page,
5714 destArray: dest,
5715 allowNegativeOffset: true
5716 });
5717 }
5718
5719 this.eventBus.dispatch("scalechanging", {
5720 source: this,
5721 scale: newScale,
5722 presetValue: preset ? newValue : undefined
5723 });
5724
5725 if (this.defaultRenderingQueue) {
5726 this.update();
5727 }
5728 }
5729
5730 _setScale(value, noScroll = false) {
5731 let scale = parseFloat(value);
5732
5733 if (scale > 0) {
5734 this._setScaleUpdatePages(scale, value, noScroll, false);
5735 } else {
5736 const currentPage = this._pages[this._currentPageNumber - 1];
5737
5738 if (!currentPage) {
5739 return;
5740 }
5741
5742 const noPadding = this.isInPresentationMode || this.removePageBorders;
5743 let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
5744 let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
5745
5746 if (!noPadding && this._isScrollModeHorizontal) {
5747 [hPadding, vPadding] = [vPadding, hPadding];
5748 }
5749
5750 const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
5751 const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
5752
5753 switch (value) {
5754 case "page-actual":
5755 scale = 1;
5756 break;
5757
5758 case "page-width":
5759 scale = pageWidthScale;
5760 break;
5761
5762 case "page-height":
5763 scale = pageHeightScale;
5764 break;
5765
5766 case "page-fit":
5767 scale = Math.min(pageWidthScale, pageHeightScale);
5768 break;
5769
5770 case "auto":
5771 const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
5772 scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
5773 break;
5774
5775 default:
5776 console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
5777 return;
5778 }
5779
5780 this._setScaleUpdatePages(scale, value, noScroll, true);
5781 }
5782 }
5783
5784 _resetCurrentPageView() {
5785 if (this.isInPresentationMode) {
5786 this._setScale(this._currentScaleValue, true);
5787 }
5788
5789 const pageView = this._pages[this._currentPageNumber - 1];
5790
5791 this._scrollIntoView({
5792 pageDiv: pageView.div
5793 });
5794 }
5795
5796 scrollPageIntoView({
5797 pageNumber,
5798 destArray = null,
5799 allowNegativeOffset = false,
5800 ignoreDestinationZoom = false
5801 }) {
5802 if (!this.pdfDocument) {
5803 return;
5804 }
5805
5806 const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
5807
5808 if (!pageView) {
5809 console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
5810 return;
5811 }
5812
5813 if (this.isInPresentationMode || !destArray) {
5814 this._setCurrentPageNumber(pageNumber, true);
5815
5816 return;
5817 }
5818
5819 let x = 0,
5820 y = 0;
5821 let width = 0,
5822 height = 0,
5823 widthScale,
5824 heightScale;
5825 const changeOrientation = pageView.rotation % 180 !== 0;
5826 const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
5827 const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
5828 let scale = 0;
5829
5830 switch (destArray[1].name) {
5831 case "XYZ":
5832 x = destArray[2];
5833 y = destArray[3];
5834 scale = destArray[4];
5835 x = x !== null ? x : 0;
5836 y = y !== null ? y : pageHeight;
5837 break;
5838
5839 case "Fit":
5840 case "FitB":
5841 scale = "page-fit";
5842 break;
5843
5844 case "FitH":
5845 case "FitBH":
5846 y = destArray[2];
5847 scale = "page-width";
5848
5849 if (y === null && this._location) {
5850 x = this._location.left;
5851 y = this._location.top;
5852 }
5853
5854 break;
5855
5856 case "FitV":
5857 case "FitBV":
5858 x = destArray[2];
5859 width = pageWidth;
5860 height = pageHeight;
5861 scale = "page-height";
5862 break;
5863
5864 case "FitR":
5865 x = destArray[2];
5866 y = destArray[3];
5867 width = destArray[4] - x;
5868 height = destArray[5] - y;
5869 const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
5870 const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
5871 widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
5872 heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
5873 scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
5874 break;
5875
5876 default:
5877 console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
5878 return;
5879 }
5880
5881 if (!ignoreDestinationZoom) {
5882 if (scale && scale !== this._currentScale) {
5883 this.currentScaleValue = scale;
5884 } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
5885 this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
5886 }
5887 }
5888
5889 if (scale === "page-fit" && !destArray[4]) {
5890 this._scrollIntoView({
5891 pageDiv: pageView.div,
5892 pageNumber
5893 });
5894
5895 return;
5896 }
5897
5898 const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
5899 let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
5900 let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
5901
5902 if (!allowNegativeOffset) {
5903 left = Math.max(left, 0);
5904 top = Math.max(top, 0);
5905 }
5906
5907 this._scrollIntoView({
5908 pageDiv: pageView.div,
5909 pageSpot: {
5910 left,
5911 top
5912 },
5913 pageNumber
5914 });
5915 }
5916
5917 _updateLocation(firstPage) {
5918 const currentScale = this._currentScale;
5919 const currentScaleValue = this._currentScaleValue;
5920 const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
5921 const pageNumber = firstPage.id;
5922 let pdfOpenParams = "#page=" + pageNumber;
5923 pdfOpenParams += "&zoom=" + normalizedScaleValue;
5924 const currentPageView = this._pages[pageNumber - 1];
5925 const container = this.container;
5926 const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
5927 const intLeft = Math.round(topLeft[0]);
5928 const intTop = Math.round(topLeft[1]);
5929 pdfOpenParams += "," + intLeft + "," + intTop;
5930 this._location = {
5931 pageNumber,
5932 scale: normalizedScaleValue,
5933 top: intTop,
5934 left: intLeft,
5935 rotation: this._pagesRotation,
5936 pdfOpenParams
5937 };
5938 }
5939
5940 _updateHelper(visiblePages) {
5941 throw new Error("Not implemented: _updateHelper");
5942 }
5943
5944 update() {
5945 const visible = this._getVisiblePages();
5946
5947 const visiblePages = visible.views,
5948 numVisiblePages = visiblePages.length;
5949
5950 if (numVisiblePages === 0) {
5951 return;
5952 }
5953
5954 const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
5955
5956 this._buffer.resize(newCacheSize, visiblePages);
5957
5958 this.renderingQueue.renderHighestPriority(visible);
5959
5960 this._updateHelper(visiblePages);
5961
5962 this._updateLocation(visible.first);
5963
5964 this.eventBus.dispatch("updateviewarea", {
5965 source: this,
5966 location: this._location
5967 });
5968 }
5969
5970 containsElement(element) {
5971 return this.container.contains(element);
5972 }
5973
5974 focus() {
5975 this.container.focus();
5976 }
5977
5978 get _isScrollModeHorizontal() {
5979 return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
5980 }
5981
5982 get isInPresentationMode() {
5983 return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
5984 }
5985
5986 get isChangingPresentationMode() {
5987 return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
5988 }
5989
5990 get isHorizontalScrollbarEnabled() {
5991 return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
5992 }
5993
5994 get isVerticalScrollbarEnabled() {
5995 return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
5996 }
5997
5998 _getCurrentVisiblePage() {
5999 if (!this.pagesCount) {
6000 return {
6001 views: []
6002 };
6003 }
6004
6005 const pageView = this._pages[this._currentPageNumber - 1];
6006 const element = pageView.div;
6007 const view = {
6008 id: pageView.id,
6009 x: element.offsetLeft + element.clientLeft,
6010 y: element.offsetTop + element.clientTop,
6011 view: pageView
6012 };
6013 return {
6014 first: view,
6015 last: view,
6016 views: [view]
6017 };
6018 }
6019
6020 _getVisiblePages() {
6021 return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true, this._isScrollModeHorizontal);
6022 }
6023
6024 isPageVisible(pageNumber) {
6025 if (!this.pdfDocument) {
6026 return false;
6027 }
6028
6029 if (pageNumber < 1 || pageNumber > this.pagesCount) {
6030 console.error(`${this._name}.isPageVisible: "${pageNumber}" is out of bounds.`);
6031 return false;
6032 }
6033
6034 return this._getVisiblePages().views.some(function (view) {
6035 return view.id === pageNumber;
6036 });
6037 }
6038
6039 cleanup() {
6040 for (let i = 0, ii = this._pages.length; i < ii; i++) {
6041 if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
6042 this._pages[i].reset();
6043 }
6044 }
6045 }
6046
6047 _cancelRendering() {
6048 for (let i = 0, ii = this._pages.length; i < ii; i++) {
6049 if (this._pages[i]) {
6050 this._pages[i].cancelRendering();
6051 }
6052 }
6053 }
6054
6055 _ensurePdfPageLoaded(pageView) {
6056 if (pageView.pdfPage) {
6057 return Promise.resolve(pageView.pdfPage);
6058 }
6059
6060 if (this._pagesRequests.has(pageView)) {
6061 return this._pagesRequests.get(pageView);
6062 }
6063
6064 const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
6065 if (!pageView.pdfPage) {
6066 pageView.setPdfPage(pdfPage);
6067 }
6068
6069 this._pagesRequests.delete(pageView);
6070
6071 return pdfPage;
6072 }).catch(reason => {
6073 console.error("Unable to get page for page view", reason);
6074
6075 this._pagesRequests.delete(pageView);
6076 });
6077
6078 this._pagesRequests.set(pageView, promise);
6079
6080 return promise;
6081 }
6082
6083 forceRendering(currentlyVisiblePages) {
6084 const visiblePages = currentlyVisiblePages || this._getVisiblePages();
6085
6086 const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
6087 const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
6088
6089 if (pageView) {
6090 this._ensurePdfPageLoaded(pageView).then(() => {
6091 this.renderingQueue.renderView(pageView);
6092 });
6093
6094 return true;
6095 }
6096
6097 return false;
6098 }
6099
6100 createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
6101 return new _text_layer_builder.TextLayerBuilder({
6102 textLayerDiv,
6103 eventBus,
6104 pageIndex,
6105 viewport,
6106 findController: this.isInPresentationMode ? null : this.findController,
6107 enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
6108 });
6109 }
6110
6111 createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
6112 return new _annotation_layer_builder.AnnotationLayerBuilder({
6113 pageDiv,
6114 pdfPage,
6115 imageResourcesPath,
6116 renderInteractiveForms,
6117 linkService: this.linkService,
6118 downloadManager: this.downloadManager,
6119 l10n
6120 });
6121 }
6122
6123 get hasEqualPageSizes() {
6124 const firstPageView = this._pages[0];
6125
6126 for (let i = 1, ii = this._pages.length; i < ii; ++i) {
6127 const pageView = this._pages[i];
6128
6129 if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
6130 return false;
6131 }
6132 }
6133
6134 return true;
6135 }
6136
6137 getPagesOverview() {
6138 const pagesOverview = this._pages.map(function (pageView) {
6139 const viewport = pageView.pdfPage.getViewport({
6140 scale: 1
6141 });
6142 return {
6143 width: viewport.width,
6144 height: viewport.height,
6145 rotation: viewport.rotation
6146 };
6147 });
6148
6149 if (!this.enablePrintAutoRotate) {
6150 return pagesOverview;
6151 }
6152
6153 const isFirstPagePortrait = (0, _ui_utils.isPortraitOrientation)(pagesOverview[0]);
6154 return pagesOverview.map(function (size) {
6155 if (isFirstPagePortrait === (0, _ui_utils.isPortraitOrientation)(size)) {
6156 return size;
6157 }
6158
6159 return {
6160 width: size.height,
6161 height: size.width,
6162 rotation: (size.rotation + 90) % 360
6163 };
6164 });
6165 }
6166
6167 get scrollMode() {
6168 return this._scrollMode;
6169 }
6170
6171 set scrollMode(mode) {
6172 if (this._scrollMode === mode) {
6173 return;
6174 }
6175
6176 if (!(0, _ui_utils.isValidScrollMode)(mode)) {
6177 throw new Error(`Invalid scroll mode: ${mode}`);
6178 }
6179
6180 this._scrollMode = mode;
6181 this.eventBus.dispatch("scrollmodechanged", {
6182 source: this,
6183 mode
6184 });
6185
6186 this._updateScrollMode(this._currentPageNumber);
6187 }
6188
6189 _updateScrollMode(pageNumber = null) {
6190 const scrollMode = this._scrollMode,
6191 viewer = this.viewer;
6192 viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
6193 viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
6194
6195 if (!this.pdfDocument || !pageNumber) {
6196 return;
6197 }
6198
6199 if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
6200 this._setScale(this._currentScaleValue, true);
6201 }
6202
6203 this._setCurrentPageNumber(pageNumber, true);
6204
6205 this.update();
6206 }
6207
6208 get spreadMode() {
6209 return this._spreadMode;
6210 }
6211
6212 set spreadMode(mode) {
6213 if (this._spreadMode === mode) {
6214 return;
6215 }
6216
6217 if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
6218 throw new Error(`Invalid spread mode: ${mode}`);
6219 }
6220
6221 this._spreadMode = mode;
6222 this.eventBus.dispatch("spreadmodechanged", {
6223 source: this,
6224 mode
6225 });
6226
6227 this._updateSpreadMode(this._currentPageNumber);
6228 }
6229
6230 _updateSpreadMode(pageNumber = null) {
6231 if (!this.pdfDocument) {
6232 return;
6233 }
6234
6235 const viewer = this.viewer,
6236 pages = this._pages;
6237 viewer.textContent = "";
6238
6239 if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
6240 for (let i = 0, iMax = pages.length; i < iMax; ++i) {
6241 viewer.appendChild(pages[i].div);
6242 }
6243 } else {
6244 const parity = this._spreadMode - 1;
6245 let spread = null;
6246
6247 for (let i = 0, iMax = pages.length; i < iMax; ++i) {
6248 if (spread === null) {
6249 spread = document.createElement("div");
6250 spread.className = "spread";
6251 viewer.appendChild(spread);
6252 } else if (i % 2 === parity) {
6253 spread = spread.cloneNode(false);
6254 viewer.appendChild(spread);
6255 }
6256
6257 spread.appendChild(pages[i].div);
6258 }
6259 }
6260
6261 if (!pageNumber) {
6262 return;
6263 }
6264
6265 this._setCurrentPageNumber(pageNumber, true);
6266
6267 this.update();
6268 }
6269
6270}
6271
6272exports.BaseViewer = BaseViewer;
6273
6274/***/ }),
6275/* 17 */
6276/***/ (function(module, exports, __w_pdfjs_require__) {
6277
6278"use strict";
6279
6280
6281Object.defineProperty(exports, "__esModule", {
6282 value: true
6283});
6284exports.PDFViewer = void 0;
6285
6286var _base_viewer = __w_pdfjs_require__(16);
6287
6288var _pdfjsLib = __w_pdfjs_require__(2);
6289
6290class PDFViewer extends _base_viewer.BaseViewer {
6291 get _viewerElement() {
6292 return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
6293 }
6294
6295 _scrollIntoView({
6296 pageDiv,
6297 pageSpot = null,
6298 pageNumber = null
6299 }) {
6300 if (!pageSpot && !this.isInPresentationMode) {
6301 const left = pageDiv.offsetLeft + pageDiv.clientLeft;
6302 const right = left + pageDiv.clientWidth;
6303 const {
6304 scrollLeft,
6305 clientWidth
6306 } = this.container;
6307
6308 if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
6309 pageSpot = {
6310 left: 0,
6311 top: 0
6312 };
6313 }
6314 }
6315
6316 super._scrollIntoView({
6317 pageDiv,
6318 pageSpot,
6319 pageNumber
6320 });
6321 }
6322
6323 _getVisiblePages() {
6324 if (this.isInPresentationMode) {
6325 return this._getCurrentVisiblePage();
6326 }
6327
6328 return super._getVisiblePages();
6329 }
6330
6331 _updateHelper(visiblePages) {
6332 if (this.isInPresentationMode) {
6333 return;
6334 }
6335
6336 let currentId = this._currentPageNumber;
6337 let stillFullyVisible = false;
6338
6339 for (const page of visiblePages) {
6340 if (page.percent < 100) {
6341 break;
6342 }
6343
6344 if (page.id === currentId) {
6345 stillFullyVisible = true;
6346 break;
6347 }
6348 }
6349
6350 if (!stillFullyVisible) {
6351 currentId = visiblePages[0].id;
6352 }
6353
6354 this._setCurrentPageNumber(currentId);
6355 }
6356
6357}
6358
6359exports.PDFViewer = PDFViewer;
6360
6361/***/ })
6362/******/ ]);
6363});
6364//# sourceMappingURL=pdf_viewer.js.map
\No newline at end of file