UNPKG

246 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2023 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})(globalThis, () => {
33return /******/ (() => { // webpackBootstrap
34/******/ "use strict";
35/******/ var __webpack_modules__ = ([
36/* 0 */,
37/* 1 */
38/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
39
40
41
42Object.defineProperty(exports, "__esModule", ({
43 value: true
44}));
45exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
46var _ui_utils = __w_pdfjs_require__(2);
47const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
48const LinkTarget = {
49 NONE: 0,
50 SELF: 1,
51 BLANK: 2,
52 PARENT: 3,
53 TOP: 4
54};
55exports.LinkTarget = LinkTarget;
56function addLinkAttributes(link) {
57 let {
58 url,
59 target,
60 rel,
61 enabled = true
62 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
63 if (!url || typeof url !== "string") {
64 throw new Error('A valid "url" parameter must provided.');
65 }
66 const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
67 if (enabled) {
68 link.href = link.title = urlNullRemoved;
69 } else {
70 link.href = "";
71 link.title = `Disabled: ${urlNullRemoved}`;
72 link.onclick = () => {
73 return false;
74 };
75 }
76 let targetStr = "";
77 switch (target) {
78 case LinkTarget.NONE:
79 break;
80 case LinkTarget.SELF:
81 targetStr = "_self";
82 break;
83 case LinkTarget.BLANK:
84 targetStr = "_blank";
85 break;
86 case LinkTarget.PARENT:
87 targetStr = "_parent";
88 break;
89 case LinkTarget.TOP:
90 targetStr = "_top";
91 break;
92 }
93 link.target = targetStr;
94 link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
95}
96class PDFLinkService {
97 #pagesRefCache = new Map();
98 constructor() {
99 let {
100 eventBus,
101 externalLinkTarget = null,
102 externalLinkRel = null,
103 ignoreDestinationZoom = false
104 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
105 this.eventBus = eventBus;
106 this.externalLinkTarget = externalLinkTarget;
107 this.externalLinkRel = externalLinkRel;
108 this.externalLinkEnabled = true;
109 this._ignoreDestinationZoom = ignoreDestinationZoom;
110 this.baseUrl = null;
111 this.pdfDocument = null;
112 this.pdfViewer = null;
113 this.pdfHistory = null;
114 }
115 setDocument(pdfDocument) {
116 let baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
117 this.baseUrl = baseUrl;
118 this.pdfDocument = pdfDocument;
119 this.#pagesRefCache.clear();
120 }
121 setViewer(pdfViewer) {
122 this.pdfViewer = pdfViewer;
123 }
124 setHistory(pdfHistory) {
125 this.pdfHistory = pdfHistory;
126 }
127 get pagesCount() {
128 return this.pdfDocument ? this.pdfDocument.numPages : 0;
129 }
130 get page() {
131 return this.pdfViewer.currentPageNumber;
132 }
133 set page(value) {
134 this.pdfViewer.currentPageNumber = value;
135 }
136 get rotation() {
137 return this.pdfViewer.pagesRotation;
138 }
139 set rotation(value) {
140 this.pdfViewer.pagesRotation = value;
141 }
142 get isInPresentationMode() {
143 return this.pdfViewer.isInPresentationMode;
144 }
145 #goToDestinationHelper(rawDest) {
146 let namedDest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
147 let explicitDest = arguments.length > 2 ? arguments[2] : undefined;
148 const destRef = explicitDest[0];
149 let pageNumber;
150 if (typeof destRef === "object" && destRef !== null) {
151 pageNumber = this._cachedPageNumber(destRef);
152 if (!pageNumber) {
153 this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
154 this.cachePageRef(pageIndex + 1, destRef);
155 this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
156 }).catch(() => {
157 console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
158 });
159 return;
160 }
161 } else if (Number.isInteger(destRef)) {
162 pageNumber = destRef + 1;
163 } else {
164 console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
165 return;
166 }
167 if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
168 console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
169 return;
170 }
171 if (this.pdfHistory) {
172 this.pdfHistory.pushCurrentPosition();
173 this.pdfHistory.push({
174 namedDest,
175 explicitDest,
176 pageNumber
177 });
178 }
179 this.pdfViewer.scrollPageIntoView({
180 pageNumber,
181 destArray: explicitDest,
182 ignoreDestinationZoom: this._ignoreDestinationZoom
183 });
184 }
185 async goToDestination(dest) {
186 if (!this.pdfDocument) {
187 return;
188 }
189 let namedDest, explicitDest;
190 if (typeof dest === "string") {
191 namedDest = dest;
192 explicitDest = await this.pdfDocument.getDestination(dest);
193 } else {
194 namedDest = null;
195 explicitDest = await dest;
196 }
197 if (!Array.isArray(explicitDest)) {
198 console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
199 return;
200 }
201 this.#goToDestinationHelper(dest, namedDest, explicitDest);
202 }
203 goToPage(val) {
204 if (!this.pdfDocument) {
205 return;
206 }
207 const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
208 if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
209 console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
210 return;
211 }
212 if (this.pdfHistory) {
213 this.pdfHistory.pushCurrentPosition();
214 this.pdfHistory.pushPage(pageNumber);
215 }
216 this.pdfViewer.scrollPageIntoView({
217 pageNumber
218 });
219 }
220 addLinkAttributes(link, url) {
221 let newWindow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
222 addLinkAttributes(link, {
223 url,
224 target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
225 rel: this.externalLinkRel,
226 enabled: this.externalLinkEnabled
227 });
228 }
229 getDestinationHash(dest) {
230 if (typeof dest === "string") {
231 if (dest.length > 0) {
232 return this.getAnchorUrl("#" + escape(dest));
233 }
234 } else if (Array.isArray(dest)) {
235 const str = JSON.stringify(dest);
236 if (str.length > 0) {
237 return this.getAnchorUrl("#" + escape(str));
238 }
239 }
240 return this.getAnchorUrl("");
241 }
242 getAnchorUrl(anchor) {
243 return this.baseUrl ? this.baseUrl + anchor : anchor;
244 }
245 setHash(hash) {
246 if (!this.pdfDocument) {
247 return;
248 }
249 let pageNumber, dest;
250 if (hash.includes("=")) {
251 const params = (0, _ui_utils.parseQueryString)(hash);
252 if (params.has("search")) {
253 const query = params.get("search").replaceAll('"', ""),
254 phrase = params.get("phrase") === "true";
255 this.eventBus.dispatch("findfromurlhash", {
256 source: this,
257 query: phrase ? query : query.match(/\S+/g)
258 });
259 }
260 if (params.has("page")) {
261 pageNumber = params.get("page") | 0 || 1;
262 }
263 if (params.has("zoom")) {
264 const zoomArgs = params.get("zoom").split(",");
265 const zoomArg = zoomArgs[0];
266 const zoomArgNumber = parseFloat(zoomArg);
267 if (!zoomArg.includes("Fit")) {
268 dest = [null, {
269 name: "XYZ"
270 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
271 } else {
272 if (zoomArg === "Fit" || zoomArg === "FitB") {
273 dest = [null, {
274 name: zoomArg
275 }];
276 } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
277 dest = [null, {
278 name: zoomArg
279 }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
280 } else if (zoomArg === "FitR") {
281 if (zoomArgs.length !== 5) {
282 console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
283 } else {
284 dest = [null, {
285 name: zoomArg
286 }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
287 }
288 } else {
289 console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
290 }
291 }
292 }
293 if (dest) {
294 this.pdfViewer.scrollPageIntoView({
295 pageNumber: pageNumber || this.page,
296 destArray: dest,
297 allowNegativeOffset: true
298 });
299 } else if (pageNumber) {
300 this.page = pageNumber;
301 }
302 if (params.has("pagemode")) {
303 this.eventBus.dispatch("pagemode", {
304 source: this,
305 mode: params.get("pagemode")
306 });
307 }
308 if (params.has("nameddest")) {
309 this.goToDestination(params.get("nameddest"));
310 }
311 } else {
312 dest = unescape(hash);
313 try {
314 dest = JSON.parse(dest);
315 if (!Array.isArray(dest)) {
316 dest = dest.toString();
317 }
318 } catch (ex) {}
319 if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
320 this.goToDestination(dest);
321 return;
322 }
323 console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
324 }
325 }
326 executeNamedAction(action) {
327 var _this$pdfHistory, _this$pdfHistory2;
328 switch (action) {
329 case "GoBack":
330 (_this$pdfHistory = this.pdfHistory) === null || _this$pdfHistory === void 0 ? void 0 : _this$pdfHistory.back();
331 break;
332 case "GoForward":
333 (_this$pdfHistory2 = this.pdfHistory) === null || _this$pdfHistory2 === void 0 ? void 0 : _this$pdfHistory2.forward();
334 break;
335 case "NextPage":
336 this.pdfViewer.nextPage();
337 break;
338 case "PrevPage":
339 this.pdfViewer.previousPage();
340 break;
341 case "LastPage":
342 this.page = this.pagesCount;
343 break;
344 case "FirstPage":
345 this.page = 1;
346 break;
347 default:
348 break;
349 }
350 this.eventBus.dispatch("namedaction", {
351 source: this,
352 action
353 });
354 }
355 async executeSetOCGState(action) {
356 const pdfDocument = this.pdfDocument;
357 const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
358 if (pdfDocument !== this.pdfDocument) {
359 return;
360 }
361 let operator;
362 for (const elem of action.state) {
363 switch (elem) {
364 case "ON":
365 case "OFF":
366 case "Toggle":
367 operator = elem;
368 continue;
369 }
370 switch (operator) {
371 case "ON":
372 optionalContentConfig.setVisibility(elem, true);
373 break;
374 case "OFF":
375 optionalContentConfig.setVisibility(elem, false);
376 break;
377 case "Toggle":
378 const group = optionalContentConfig.getGroup(elem);
379 if (group) {
380 optionalContentConfig.setVisibility(elem, !group.visible);
381 }
382 break;
383 }
384 }
385 this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
386 }
387 cachePageRef(pageNum, pageRef) {
388 if (!pageRef) {
389 return;
390 }
391 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
392 this.#pagesRefCache.set(refStr, pageNum);
393 }
394 _cachedPageNumber(pageRef) {
395 if (!pageRef) {
396 return null;
397 }
398 const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
399 return this.#pagesRefCache.get(refStr) || null;
400 }
401 static #isValidExplicitDestination(dest) {
402 if (!Array.isArray(dest)) {
403 return false;
404 }
405 const destLength = dest.length;
406 if (destLength < 2) {
407 return false;
408 }
409 const page = dest[0];
410 if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
411 return false;
412 }
413 const zoom = dest[1];
414 if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
415 return false;
416 }
417 let allowNull = true;
418 switch (zoom.name) {
419 case "XYZ":
420 if (destLength !== 5) {
421 return false;
422 }
423 break;
424 case "Fit":
425 case "FitB":
426 return destLength === 2;
427 case "FitH":
428 case "FitBH":
429 case "FitV":
430 case "FitBV":
431 if (destLength !== 3) {
432 return false;
433 }
434 break;
435 case "FitR":
436 if (destLength !== 6) {
437 return false;
438 }
439 allowNull = false;
440 break;
441 default:
442 return false;
443 }
444 for (let i = 2; i < destLength; i++) {
445 const param = dest[i];
446 if (!(typeof param === "number" || allowNull && param === null)) {
447 return false;
448 }
449 }
450 return true;
451 }
452}
453exports.PDFLinkService = PDFLinkService;
454class SimpleLinkService {
455 constructor() {
456 this.externalLinkEnabled = true;
457 }
458 get pagesCount() {
459 return 0;
460 }
461 get page() {
462 return 0;
463 }
464 set page(value) {}
465 get rotation() {
466 return 0;
467 }
468 set rotation(value) {}
469 get isInPresentationMode() {
470 return false;
471 }
472 async goToDestination(dest) {}
473 goToPage(val) {}
474 addLinkAttributes(link, url) {
475 let newWindow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
476 addLinkAttributes(link, {
477 url,
478 enabled: this.externalLinkEnabled
479 });
480 }
481 getDestinationHash(dest) {
482 return "#";
483 }
484 getAnchorUrl(hash) {
485 return "#";
486 }
487 setHash(hash) {}
488 executeNamedAction(action) {}
489 executeSetOCGState(action) {}
490 cachePageRef(pageNum, pageRef) {}
491}
492exports.SimpleLinkService = SimpleLinkService;
493
494/***/ }),
495/* 2 */
496/***/ ((__unused_webpack_module, exports) => {
497
498
499
500Object.defineProperty(exports, "__esModule", ({
501 value: true
502}));
503exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.CursorTool = exports.AutoPrintRegExp = void 0;
504exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
505exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
506exports.approximateFraction = approximateFraction;
507exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
508exports.binarySearchFirstItem = binarySearchFirstItem;
509exports.docStyle = void 0;
510exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
511exports.getPageSizeInches = getPageSizeInches;
512exports.getVisibleElements = getVisibleElements;
513exports.isPortraitOrientation = isPortraitOrientation;
514exports.isValidRotation = isValidRotation;
515exports.isValidScrollMode = isValidScrollMode;
516exports.isValidSpreadMode = isValidSpreadMode;
517exports.noContextMenuHandler = noContextMenuHandler;
518exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
519exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
520exports.parseQueryString = parseQueryString;
521exports.removeNullCharacters = removeNullCharacters;
522exports.roundToDivide = roundToDivide;
523exports.scrollIntoView = scrollIntoView;
524exports.toggleCheckedBtn = toggleCheckedBtn;
525exports.toggleExpandedBtn = toggleExpandedBtn;
526exports.watchScroll = watchScroll;
527const DEFAULT_SCALE_VALUE = "auto";
528exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
529const DEFAULT_SCALE = 1.0;
530exports.DEFAULT_SCALE = DEFAULT_SCALE;
531const DEFAULT_SCALE_DELTA = 1.1;
532exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
533const MIN_SCALE = 0.1;
534exports.MIN_SCALE = MIN_SCALE;
535const MAX_SCALE = 10.0;
536exports.MAX_SCALE = MAX_SCALE;
537const UNKNOWN_SCALE = 0;
538exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
539const MAX_AUTO_SCALE = 1.25;
540exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
541const SCROLLBAR_PADDING = 40;
542exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
543const VERTICAL_PADDING = 5;
544exports.VERTICAL_PADDING = VERTICAL_PADDING;
545const RenderingStates = {
546 INITIAL: 0,
547 RUNNING: 1,
548 PAUSED: 2,
549 FINISHED: 3
550};
551exports.RenderingStates = RenderingStates;
552const PresentationModeState = {
553 UNKNOWN: 0,
554 NORMAL: 1,
555 CHANGING: 2,
556 FULLSCREEN: 3
557};
558exports.PresentationModeState = PresentationModeState;
559const SidebarView = {
560 UNKNOWN: -1,
561 NONE: 0,
562 THUMBS: 1,
563 OUTLINE: 2,
564 ATTACHMENTS: 3,
565 LAYERS: 4
566};
567exports.SidebarView = SidebarView;
568const TextLayerMode = {
569 DISABLE: 0,
570 ENABLE: 1,
571 ENABLE_PERMISSIONS: 2
572};
573exports.TextLayerMode = TextLayerMode;
574const ScrollMode = {
575 UNKNOWN: -1,
576 VERTICAL: 0,
577 HORIZONTAL: 1,
578 WRAPPED: 2,
579 PAGE: 3
580};
581exports.ScrollMode = ScrollMode;
582const SpreadMode = {
583 UNKNOWN: -1,
584 NONE: 0,
585 ODD: 1,
586 EVEN: 2
587};
588exports.SpreadMode = SpreadMode;
589const CursorTool = {
590 SELECT: 0,
591 HAND: 1,
592 ZOOM: 2
593};
594exports.CursorTool = CursorTool;
595const AutoPrintRegExp = /\bprint\s*\(/;
596exports.AutoPrintRegExp = AutoPrintRegExp;
597class OutputScale {
598 constructor() {
599 const pixelRatio = window.devicePixelRatio || 1;
600 this.sx = pixelRatio;
601 this.sy = pixelRatio;
602 }
603 get scaled() {
604 return this.sx !== 1 || this.sy !== 1;
605 }
606}
607exports.OutputScale = OutputScale;
608function scrollIntoView(element, spot) {
609 let scrollMatches = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
610 let parent = element.offsetParent;
611 if (!parent) {
612 console.error("offsetParent is not set -- cannot scroll");
613 return;
614 }
615 let offsetY = element.offsetTop + element.clientTop;
616 let offsetX = element.offsetLeft + element.clientLeft;
617 while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
618 offsetY += parent.offsetTop;
619 offsetX += parent.offsetLeft;
620 parent = parent.offsetParent;
621 if (!parent) {
622 return;
623 }
624 }
625 if (spot) {
626 if (spot.top !== undefined) {
627 offsetY += spot.top;
628 }
629 if (spot.left !== undefined) {
630 offsetX += spot.left;
631 parent.scrollLeft = offsetX;
632 }
633 }
634 parent.scrollTop = offsetY;
635}
636function watchScroll(viewAreaElement, callback) {
637 const debounceScroll = function (evt) {
638 if (rAF) {
639 return;
640 }
641 rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
642 rAF = null;
643 const currentX = viewAreaElement.scrollLeft;
644 const lastX = state.lastX;
645 if (currentX !== lastX) {
646 state.right = currentX > lastX;
647 }
648 state.lastX = currentX;
649 const currentY = viewAreaElement.scrollTop;
650 const lastY = state.lastY;
651 if (currentY !== lastY) {
652 state.down = currentY > lastY;
653 }
654 state.lastY = currentY;
655 callback(state);
656 });
657 };
658 const state = {
659 right: true,
660 down: true,
661 lastX: viewAreaElement.scrollLeft,
662 lastY: viewAreaElement.scrollTop,
663 _eventHandler: debounceScroll
664 };
665 let rAF = null;
666 viewAreaElement.addEventListener("scroll", debounceScroll, true);
667 return state;
668}
669function parseQueryString(query) {
670 const params = new Map();
671 for (const [key, value] of new URLSearchParams(query)) {
672 params.set(key.toLowerCase(), value);
673 }
674 return params;
675}
676const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
677function removeNullCharacters(str) {
678 let replaceInvisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
679 if (typeof str !== "string") {
680 console.error(`The argument must be a string.`);
681 return str;
682 }
683 if (replaceInvisible) {
684 str = str.replaceAll(InvisibleCharactersRegExp, " ");
685 }
686 return str.replaceAll("\x00", "");
687}
688function binarySearchFirstItem(items, condition) {
689 let start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
690 let minIndex = start;
691 let maxIndex = items.length - 1;
692 if (maxIndex < 0 || !condition(items[maxIndex])) {
693 return items.length;
694 }
695 if (condition(items[minIndex])) {
696 return minIndex;
697 }
698 while (minIndex < maxIndex) {
699 const currentIndex = minIndex + maxIndex >> 1;
700 const currentItem = items[currentIndex];
701 if (condition(currentItem)) {
702 maxIndex = currentIndex;
703 } else {
704 minIndex = currentIndex + 1;
705 }
706 }
707 return minIndex;
708}
709function approximateFraction(x) {
710 if (Math.floor(x) === x) {
711 return [x, 1];
712 }
713 const xinv = 1 / x;
714 const limit = 8;
715 if (xinv > limit) {
716 return [1, limit];
717 } else if (Math.floor(xinv) === xinv) {
718 return [1, xinv];
719 }
720 const x_ = x > 1 ? xinv : x;
721 let a = 0,
722 b = 1,
723 c = 1,
724 d = 1;
725 while (true) {
726 const p = a + c,
727 q = b + d;
728 if (q > limit) {
729 break;
730 }
731 if (x_ <= p / q) {
732 c = p;
733 d = q;
734 } else {
735 a = p;
736 b = q;
737 }
738 }
739 let result;
740 if (x_ - a / b < c / d - x_) {
741 result = x_ === x ? [a, b] : [b, a];
742 } else {
743 result = x_ === x ? [c, d] : [d, c];
744 }
745 return result;
746}
747function roundToDivide(x, div) {
748 const r = x % div;
749 return r === 0 ? x : Math.round(x - r + div);
750}
751function getPageSizeInches(_ref) {
752 let {
753 view,
754 userUnit,
755 rotate
756 } = _ref;
757 const [x1, y1, x2, y2] = view;
758 const changeOrientation = rotate % 180 !== 0;
759 const width = (x2 - x1) / 72 * userUnit;
760 const height = (y2 - y1) / 72 * userUnit;
761 return {
762 width: changeOrientation ? height : width,
763 height: changeOrientation ? width : height
764 };
765}
766function backtrackBeforeAllVisibleElements(index, views, top) {
767 if (index < 2) {
768 return index;
769 }
770 let elt = views[index].div;
771 let pageTop = elt.offsetTop + elt.clientTop;
772 if (pageTop >= top) {
773 elt = views[index - 1].div;
774 pageTop = elt.offsetTop + elt.clientTop;
775 }
776 for (let i = index - 2; i >= 0; --i) {
777 elt = views[i].div;
778 if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
779 break;
780 }
781 index = i;
782 }
783 return index;
784}
785function getVisibleElements(_ref2) {
786 let {
787 scrollEl,
788 views,
789 sortByVisibility = false,
790 horizontal = false,
791 rtl = false
792 } = _ref2;
793 const top = scrollEl.scrollTop,
794 bottom = top + scrollEl.clientHeight;
795 const left = scrollEl.scrollLeft,
796 right = left + scrollEl.clientWidth;
797 function isElementBottomAfterViewTop(view) {
798 const element = view.div;
799 const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
800 return elementBottom > top;
801 }
802 function isElementNextAfterViewHorizontally(view) {
803 const element = view.div;
804 const elementLeft = element.offsetLeft + element.clientLeft;
805 const elementRight = elementLeft + element.clientWidth;
806 return rtl ? elementLeft < right : elementRight > left;
807 }
808 const visible = [],
809 ids = new Set(),
810 numViews = views.length;
811 let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
812 if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
813 firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
814 }
815 let lastEdge = horizontal ? right : -1;
816 for (let i = firstVisibleElementInd; i < numViews; i++) {
817 const view = views[i],
818 element = view.div;
819 const currentWidth = element.offsetLeft + element.clientLeft;
820 const currentHeight = element.offsetTop + element.clientTop;
821 const viewWidth = element.clientWidth,
822 viewHeight = element.clientHeight;
823 const viewRight = currentWidth + viewWidth;
824 const viewBottom = currentHeight + viewHeight;
825 if (lastEdge === -1) {
826 if (viewBottom >= bottom) {
827 lastEdge = viewBottom;
828 }
829 } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
830 break;
831 }
832 if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
833 continue;
834 }
835 const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
836 const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
837 const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
838 fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
839 const percent = fractionHeight * fractionWidth * 100 | 0;
840 visible.push({
841 id: view.id,
842 x: currentWidth,
843 y: currentHeight,
844 view,
845 percent,
846 widthPercent: fractionWidth * 100 | 0
847 });
848 ids.add(view.id);
849 }
850 const first = visible[0],
851 last = visible.at(-1);
852 if (sortByVisibility) {
853 visible.sort(function (a, b) {
854 const pc = a.percent - b.percent;
855 if (Math.abs(pc) > 0.001) {
856 return -pc;
857 }
858 return a.id - b.id;
859 });
860 }
861 return {
862 first,
863 last,
864 views: visible,
865 ids
866 };
867}
868function noContextMenuHandler(evt) {
869 evt.preventDefault();
870}
871function normalizeWheelEventDirection(evt) {
872 let delta = Math.hypot(evt.deltaX, evt.deltaY);
873 const angle = Math.atan2(evt.deltaY, evt.deltaX);
874 if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
875 delta = -delta;
876 }
877 return delta;
878}
879function normalizeWheelEventDelta(evt) {
880 const deltaMode = evt.deltaMode;
881 let delta = normalizeWheelEventDirection(evt);
882 const MOUSE_PIXELS_PER_LINE = 30;
883 const MOUSE_LINES_PER_PAGE = 30;
884 if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
885 delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
886 } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
887 delta /= MOUSE_LINES_PER_PAGE;
888 }
889 return delta;
890}
891function isValidRotation(angle) {
892 return Number.isInteger(angle) && angle % 90 === 0;
893}
894function isValidScrollMode(mode) {
895 return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
896}
897function isValidSpreadMode(mode) {
898 return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
899}
900function isPortraitOrientation(size) {
901 return size.width <= size.height;
902}
903const animationStarted = new Promise(function (resolve) {
904 window.requestAnimationFrame(resolve);
905});
906exports.animationStarted = animationStarted;
907const docStyle = document.documentElement.style;
908exports.docStyle = docStyle;
909function clamp(v, min, max) {
910 return Math.min(Math.max(v, min), max);
911}
912class ProgressBar {
913 #classList = null;
914 #disableAutoFetchTimeout = null;
915 #percent = 0;
916 #style = null;
917 #visible = true;
918 constructor(bar) {
919 this.#classList = bar.classList;
920 this.#style = bar.style;
921 }
922 get percent() {
923 return this.#percent;
924 }
925 set percent(val) {
926 this.#percent = clamp(val, 0, 100);
927 if (isNaN(val)) {
928 this.#classList.add("indeterminate");
929 return;
930 }
931 this.#classList.remove("indeterminate");
932 this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
933 }
934 setWidth(viewer) {
935 if (!viewer) {
936 return;
937 }
938 const container = viewer.parentNode;
939 const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
940 if (scrollbarWidth > 0) {
941 this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
942 }
943 }
944 setDisableAutoFetch() {
945 let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5000;
946 if (isNaN(this.#percent)) {
947 return;
948 }
949 if (this.#disableAutoFetchTimeout) {
950 clearTimeout(this.#disableAutoFetchTimeout);
951 }
952 this.show();
953 this.#disableAutoFetchTimeout = setTimeout(() => {
954 this.#disableAutoFetchTimeout = null;
955 this.hide();
956 }, delay);
957 }
958 hide() {
959 if (!this.#visible) {
960 return;
961 }
962 this.#visible = false;
963 this.#classList.add("hidden");
964 }
965 show() {
966 if (this.#visible) {
967 return;
968 }
969 this.#visible = true;
970 this.#classList.remove("hidden");
971 }
972}
973exports.ProgressBar = ProgressBar;
974function getActiveOrFocusedElement() {
975 let curRoot = document;
976 let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
977 while ((_curActiveOrFocused = curActiveOrFocused) !== null && _curActiveOrFocused !== void 0 && _curActiveOrFocused.shadowRoot) {
978 var _curActiveOrFocused;
979 curRoot = curActiveOrFocused.shadowRoot;
980 curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
981 }
982 return curActiveOrFocused;
983}
984function apiPageLayoutToViewerModes(layout) {
985 let scrollMode = ScrollMode.VERTICAL,
986 spreadMode = SpreadMode.NONE;
987 switch (layout) {
988 case "SinglePage":
989 scrollMode = ScrollMode.PAGE;
990 break;
991 case "OneColumn":
992 break;
993 case "TwoPageLeft":
994 scrollMode = ScrollMode.PAGE;
995 case "TwoColumnLeft":
996 spreadMode = SpreadMode.ODD;
997 break;
998 case "TwoPageRight":
999 scrollMode = ScrollMode.PAGE;
1000 case "TwoColumnRight":
1001 spreadMode = SpreadMode.EVEN;
1002 break;
1003 }
1004 return {
1005 scrollMode,
1006 spreadMode
1007 };
1008}
1009function apiPageModeToSidebarView(mode) {
1010 switch (mode) {
1011 case "UseNone":
1012 return SidebarView.NONE;
1013 case "UseThumbs":
1014 return SidebarView.THUMBS;
1015 case "UseOutlines":
1016 return SidebarView.OUTLINE;
1017 case "UseAttachments":
1018 return SidebarView.ATTACHMENTS;
1019 case "UseOC":
1020 return SidebarView.LAYERS;
1021 }
1022 return SidebarView.NONE;
1023}
1024function toggleCheckedBtn(button, toggle) {
1025 let view = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1026 button.classList.toggle("toggled", toggle);
1027 button.setAttribute("aria-checked", toggle);
1028 view === null || view === void 0 ? void 0 : view.classList.toggle("hidden", !toggle);
1029}
1030function toggleExpandedBtn(button, toggle) {
1031 let view = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1032 button.classList.toggle("toggled", toggle);
1033 button.setAttribute("aria-expanded", toggle);
1034 view === null || view === void 0 ? void 0 : view.classList.toggle("hidden", !toggle);
1035}
1036
1037/***/ }),
1038/* 3 */
1039/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
1040
1041
1042
1043Object.defineProperty(exports, "__esModule", ({
1044 value: true
1045}));
1046exports.AnnotationLayerBuilder = void 0;
1047var _pdfjsLib = __w_pdfjs_require__(4);
1048var _l10n_utils = __w_pdfjs_require__(5);
1049var _ui_utils = __w_pdfjs_require__(2);
1050class AnnotationLayerBuilder {
1051 #numAnnotations = 0;
1052 #onPresentationModeChanged = null;
1053 constructor(_ref) {
1054 let {
1055 pageDiv,
1056 pdfPage,
1057 linkService,
1058 downloadManager,
1059 annotationStorage = null,
1060 imageResourcesPath = "",
1061 renderForms = true,
1062 l10n = _l10n_utils.NullL10n,
1063 enableScripting = false,
1064 hasJSActionsPromise = null,
1065 fieldObjectsPromise = null,
1066 annotationCanvasMap = null,
1067 accessibilityManager = null
1068 } = _ref;
1069 this.pageDiv = pageDiv;
1070 this.pdfPage = pdfPage;
1071 this.linkService = linkService;
1072 this.downloadManager = downloadManager;
1073 this.imageResourcesPath = imageResourcesPath;
1074 this.renderForms = renderForms;
1075 this.l10n = l10n;
1076 this.annotationStorage = annotationStorage;
1077 this.enableScripting = enableScripting;
1078 this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
1079 this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
1080 this._annotationCanvasMap = annotationCanvasMap;
1081 this._accessibilityManager = accessibilityManager;
1082 this.div = null;
1083 this._cancelled = false;
1084 this._eventBus = linkService.eventBus;
1085 }
1086 async render(viewport) {
1087 let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
1088 if (this.div) {
1089 if (this._cancelled || this.#numAnnotations === 0) {
1090 return;
1091 }
1092 _pdfjsLib.AnnotationLayer.update({
1093 viewport: viewport.clone({
1094 dontFlip: true
1095 }),
1096 div: this.div,
1097 annotationCanvasMap: this._annotationCanvasMap
1098 });
1099 return;
1100 }
1101 const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
1102 intent
1103 }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
1104 if (this._cancelled) {
1105 return;
1106 }
1107 this.#numAnnotations = annotations.length;
1108 this.div = document.createElement("div");
1109 this.div.className = "annotationLayer";
1110 this.pageDiv.append(this.div);
1111 if (this.#numAnnotations === 0) {
1112 this.hide();
1113 return;
1114 }
1115 _pdfjsLib.AnnotationLayer.render({
1116 viewport: viewport.clone({
1117 dontFlip: true
1118 }),
1119 div: this.div,
1120 annotations,
1121 page: this.pdfPage,
1122 imageResourcesPath: this.imageResourcesPath,
1123 renderForms: this.renderForms,
1124 linkService: this.linkService,
1125 downloadManager: this.downloadManager,
1126 annotationStorage: this.annotationStorage,
1127 enableScripting: this.enableScripting,
1128 hasJSActions,
1129 fieldObjects,
1130 annotationCanvasMap: this._annotationCanvasMap,
1131 accessibilityManager: this._accessibilityManager
1132 });
1133 this.l10n.translate(this.div);
1134 if (this.linkService.isInPresentationMode) {
1135 this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
1136 }
1137 if (!this.#onPresentationModeChanged) {
1138 var _this$_eventBus;
1139 this.#onPresentationModeChanged = evt => {
1140 this.#updatePresentationModeState(evt.state);
1141 };
1142 (_this$_eventBus = this._eventBus) === null || _this$_eventBus === void 0 ? void 0 : _this$_eventBus._on("presentationmodechanged", this.#onPresentationModeChanged);
1143 }
1144 }
1145 cancel() {
1146 this._cancelled = true;
1147 if (this.#onPresentationModeChanged) {
1148 var _this$_eventBus2;
1149 (_this$_eventBus2 = this._eventBus) === null || _this$_eventBus2 === void 0 ? void 0 : _this$_eventBus2._off("presentationmodechanged", this.#onPresentationModeChanged);
1150 this.#onPresentationModeChanged = null;
1151 }
1152 }
1153 hide() {
1154 if (!this.div) {
1155 return;
1156 }
1157 this.div.hidden = true;
1158 }
1159 #updatePresentationModeState(state) {
1160 if (!this.div) {
1161 return;
1162 }
1163 let disableFormElements = false;
1164 switch (state) {
1165 case _ui_utils.PresentationModeState.FULLSCREEN:
1166 disableFormElements = true;
1167 break;
1168 case _ui_utils.PresentationModeState.NORMAL:
1169 break;
1170 default:
1171 return;
1172 }
1173 for (const section of this.div.childNodes) {
1174 if (section.hasAttribute("data-internal-link")) {
1175 continue;
1176 }
1177 section.inert = disableFormElements;
1178 }
1179 }
1180}
1181exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
1182
1183/***/ }),
1184/* 4 */
1185/***/ ((module) => {
1186
1187
1188
1189let pdfjsLib;
1190if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
1191 pdfjsLib = window["pdfjs-dist/build/pdf"];
1192} else {
1193 pdfjsLib = require("../build/pdf.js");
1194}
1195module.exports = pdfjsLib;
1196
1197/***/ }),
1198/* 5 */
1199/***/ ((__unused_webpack_module, exports) => {
1200
1201
1202
1203Object.defineProperty(exports, "__esModule", ({
1204 value: true
1205}));
1206exports.NullL10n = void 0;
1207exports.fixupLangCode = fixupLangCode;
1208exports.getL10nFallback = getL10nFallback;
1209const DEFAULT_L10N_STRINGS = {
1210 of_pages: "of {{pagesCount}}",
1211 page_of_pages: "({{pageNumber}} of {{pagesCount}})",
1212 document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
1213 document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
1214 document_properties_date_string: "{{date}}, {{time}}",
1215 document_properties_page_size_unit_inches: "in",
1216 document_properties_page_size_unit_millimeters: "mm",
1217 document_properties_page_size_orientation_portrait: "portrait",
1218 document_properties_page_size_orientation_landscape: "landscape",
1219 document_properties_page_size_name_a3: "A3",
1220 document_properties_page_size_name_a4: "A4",
1221 document_properties_page_size_name_letter: "Letter",
1222 document_properties_page_size_name_legal: "Legal",
1223 document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
1224 document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
1225 document_properties_linearized_yes: "Yes",
1226 document_properties_linearized_no: "No",
1227 additional_layers: "Additional Layers",
1228 page_landmark: "Page {{page}}",
1229 thumb_page_title: "Page {{page}}",
1230 thumb_page_canvas: "Thumbnail of Page {{page}}",
1231 find_reached_top: "Reached top of document, continued from bottom",
1232 find_reached_bottom: "Reached end of document, continued from top",
1233 "find_match_count[one]": "{{current}} of {{total}} match",
1234 "find_match_count[other]": "{{current}} of {{total}} matches",
1235 "find_match_count_limit[one]": "More than {{limit}} match",
1236 "find_match_count_limit[other]": "More than {{limit}} matches",
1237 find_not_found: "Phrase not found",
1238 page_scale_width: "Page Width",
1239 page_scale_fit: "Page Fit",
1240 page_scale_auto: "Automatic Zoom",
1241 page_scale_actual: "Actual Size",
1242 page_scale_percent: "{{scale}}%",
1243 loading_error: "An error occurred while loading the PDF.",
1244 invalid_file_error: "Invalid or corrupted PDF file.",
1245 missing_file_error: "Missing PDF file.",
1246 unexpected_response_error: "Unexpected server response.",
1247 rendering_error: "An error occurred while rendering the page.",
1248 printing_not_supported: "Warning: Printing is not fully supported by this browser.",
1249 printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
1250 web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
1251 free_text2_default_content: "Start typing…",
1252 editor_free_text2_aria_label: "Text Editor",
1253 editor_ink2_aria_label: "Draw Editor",
1254 editor_ink_canvas_aria_label: "User-created image"
1255};
1256{
1257 DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
1258}
1259function getL10nFallback(key, args) {
1260 switch (key) {
1261 case "find_match_count":
1262 key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
1263 break;
1264 case "find_match_count_limit":
1265 key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
1266 break;
1267 }
1268 return DEFAULT_L10N_STRINGS[key] || "";
1269}
1270const PARTIAL_LANG_CODES = {
1271 en: "en-US",
1272 es: "es-ES",
1273 fy: "fy-NL",
1274 ga: "ga-IE",
1275 gu: "gu-IN",
1276 hi: "hi-IN",
1277 hy: "hy-AM",
1278 nb: "nb-NO",
1279 ne: "ne-NP",
1280 nn: "nn-NO",
1281 pa: "pa-IN",
1282 pt: "pt-PT",
1283 sv: "sv-SE",
1284 zh: "zh-CN"
1285};
1286function fixupLangCode(langCode) {
1287 return PARTIAL_LANG_CODES[langCode === null || langCode === void 0 ? void 0 : langCode.toLowerCase()] || langCode;
1288}
1289function formatL10nValue(text, args) {
1290 if (!args) {
1291 return text;
1292 }
1293 return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
1294 return name in args ? args[name] : "{{" + name + "}}";
1295 });
1296}
1297const NullL10n = {
1298 async getLanguage() {
1299 return "en-us";
1300 },
1301 async getDirection() {
1302 return "ltr";
1303 },
1304 async get(key) {
1305 let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1306 let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getL10nFallback(key, args);
1307 return formatL10nValue(fallback, args);
1308 },
1309 async translate(element) {}
1310};
1311exports.NullL10n = NullL10n;
1312
1313/***/ }),
1314/* 6 */
1315/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
1316
1317
1318
1319Object.defineProperty(exports, "__esModule", ({
1320 value: true
1321}));
1322exports.DownloadManager = void 0;
1323var _pdfjsLib = __w_pdfjs_require__(4);
1324;
1325function download(blobUrl, filename) {
1326 const a = document.createElement("a");
1327 if (!a.click) {
1328 throw new Error('DownloadManager: "a.click()" is not supported.');
1329 }
1330 a.href = blobUrl;
1331 a.target = "_parent";
1332 if ("download" in a) {
1333 a.download = filename;
1334 }
1335 (document.body || document.documentElement).append(a);
1336 a.click();
1337 a.remove();
1338}
1339class DownloadManager {
1340 #openBlobUrls = new WeakMap();
1341 downloadUrl(url, filename, _options) {
1342 if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
1343 console.error(`downloadUrl - not a valid URL: ${url}`);
1344 return;
1345 }
1346 download(url + "#pdfjs.action=download", filename);
1347 }
1348 downloadData(data, filename, contentType) {
1349 const blobUrl = URL.createObjectURL(new Blob([data], {
1350 type: contentType
1351 }));
1352 download(blobUrl, filename);
1353 }
1354 openOrDownloadData(element, data, filename) {
1355 const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
1356 const contentType = isPdfData ? "application/pdf" : "";
1357 this.downloadData(data, filename, contentType);
1358 return false;
1359 }
1360 download(blob, url, filename, _options) {
1361 const blobUrl = URL.createObjectURL(blob);
1362 download(blobUrl, filename);
1363 }
1364}
1365exports.DownloadManager = DownloadManager;
1366
1367/***/ }),
1368/* 7 */
1369/***/ ((__unused_webpack_module, exports) => {
1370
1371
1372
1373Object.defineProperty(exports, "__esModule", ({
1374 value: true
1375}));
1376exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
1377exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
1378const WaitOnType = {
1379 EVENT: "event",
1380 TIMEOUT: "timeout"
1381};
1382exports.WaitOnType = WaitOnType;
1383function waitOnEventOrTimeout(_ref) {
1384 let {
1385 target,
1386 name,
1387 delay = 0
1388 } = _ref;
1389 return new Promise(function (resolve, reject) {
1390 if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
1391 throw new Error("waitOnEventOrTimeout - invalid parameters.");
1392 }
1393 function handler(type) {
1394 if (target instanceof EventBus) {
1395 target._off(name, eventHandler);
1396 } else {
1397 target.removeEventListener(name, eventHandler);
1398 }
1399 if (timeout) {
1400 clearTimeout(timeout);
1401 }
1402 resolve(type);
1403 }
1404 const eventHandler = handler.bind(null, WaitOnType.EVENT);
1405 if (target instanceof EventBus) {
1406 target._on(name, eventHandler);
1407 } else {
1408 target.addEventListener(name, eventHandler);
1409 }
1410 const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
1411 const timeout = setTimeout(timeoutHandler, delay);
1412 });
1413}
1414class EventBus {
1415 #listeners = Object.create(null);
1416 on(eventName, listener) {
1417 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1418 this._on(eventName, listener, {
1419 external: true,
1420 once: options === null || options === void 0 ? void 0 : options.once
1421 });
1422 }
1423 off(eventName, listener) {
1424 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1425 this._off(eventName, listener, {
1426 external: true,
1427 once: options === null || options === void 0 ? void 0 : options.once
1428 });
1429 }
1430 dispatch(eventName, data) {
1431 const eventListeners = this.#listeners[eventName];
1432 if (!eventListeners || eventListeners.length === 0) {
1433 return;
1434 }
1435 let externalListeners;
1436 for (const {
1437 listener,
1438 external,
1439 once
1440 } of eventListeners.slice(0)) {
1441 if (once) {
1442 this._off(eventName, listener);
1443 }
1444 if (external) {
1445 (externalListeners ||= []).push(listener);
1446 continue;
1447 }
1448 listener(data);
1449 }
1450 if (externalListeners) {
1451 for (const listener of externalListeners) {
1452 listener(data);
1453 }
1454 externalListeners = null;
1455 }
1456 }
1457 _on(eventName, listener) {
1458 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1459 const eventListeners = this.#listeners[eventName] ||= [];
1460 eventListeners.push({
1461 listener,
1462 external: (options === null || options === void 0 ? void 0 : options.external) === true,
1463 once: (options === null || options === void 0 ? void 0 : options.once) === true
1464 });
1465 }
1466 _off(eventName, listener) {
1467 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1468 const eventListeners = this.#listeners[eventName];
1469 if (!eventListeners) {
1470 return;
1471 }
1472 for (let i = 0, ii = eventListeners.length; i < ii; i++) {
1473 if (eventListeners[i].listener === listener) {
1474 eventListeners.splice(i, 1);
1475 return;
1476 }
1477 }
1478 }
1479}
1480exports.EventBus = EventBus;
1481class AutomationEventBus extends EventBus {
1482 dispatch(eventName, data) {
1483 throw new Error("Not implemented: AutomationEventBus.dispatch");
1484 }
1485}
1486exports.AutomationEventBus = AutomationEventBus;
1487
1488/***/ }),
1489/* 8 */
1490/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
1491
1492
1493
1494Object.defineProperty(exports, "__esModule", ({
1495 value: true
1496}));
1497exports.GenericL10n = void 0;
1498__w_pdfjs_require__(9);
1499var _l10n_utils = __w_pdfjs_require__(5);
1500const webL10n = document.webL10n;
1501class GenericL10n {
1502 constructor(lang) {
1503 this._lang = lang;
1504 this._ready = new Promise((resolve, reject) => {
1505 webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
1506 resolve(webL10n);
1507 });
1508 });
1509 }
1510 async getLanguage() {
1511 const l10n = await this._ready;
1512 return l10n.getLanguage();
1513 }
1514 async getDirection() {
1515 const l10n = await this._ready;
1516 return l10n.getDirection();
1517 }
1518 async get(key) {
1519 let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1520 let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _l10n_utils.getL10nFallback)(key, args);
1521 const l10n = await this._ready;
1522 return l10n.get(key, args, fallback);
1523 }
1524 async translate(element) {
1525 const l10n = await this._ready;
1526 return l10n.translate(element);
1527 }
1528}
1529exports.GenericL10n = GenericL10n;
1530
1531/***/ }),
1532/* 9 */
1533/***/ (() => {
1534
1535
1536
1537document.webL10n = function (window, document, undefined) {
1538 var gL10nData = {};
1539 var gTextData = '';
1540 var gTextProp = 'textContent';
1541 var gLanguage = '';
1542 var gMacros = {};
1543 var gReadyState = 'loading';
1544 var gAsyncResourceLoading = true;
1545 function getL10nResourceLinks() {
1546 return document.querySelectorAll('link[type="application/l10n"]');
1547 }
1548 function getL10nDictionary() {
1549 var script = document.querySelector('script[type="application/l10n"]');
1550 return script ? JSON.parse(script.innerHTML) : null;
1551 }
1552 function getTranslatableChildren(element) {
1553 return element ? element.querySelectorAll('*[data-l10n-id]') : [];
1554 }
1555 function getL10nAttributes(element) {
1556 if (!element) return {};
1557 var l10nId = element.getAttribute('data-l10n-id');
1558 var l10nArgs = element.getAttribute('data-l10n-args');
1559 var args = {};
1560 if (l10nArgs) {
1561 try {
1562 args = JSON.parse(l10nArgs);
1563 } catch (e) {
1564 console.warn('could not parse arguments for #' + l10nId);
1565 }
1566 }
1567 return {
1568 id: l10nId,
1569 args: args
1570 };
1571 }
1572 function xhrLoadText(url, onSuccess, onFailure) {
1573 onSuccess = onSuccess || function _onSuccess(data) {};
1574 onFailure = onFailure || function _onFailure() {};
1575 var xhr = new XMLHttpRequest();
1576 xhr.open('GET', url, gAsyncResourceLoading);
1577 if (xhr.overrideMimeType) {
1578 xhr.overrideMimeType('text/plain; charset=utf-8');
1579 }
1580 xhr.onreadystatechange = function () {
1581 if (xhr.readyState == 4) {
1582 if (xhr.status == 200 || xhr.status === 0) {
1583 onSuccess(xhr.responseText);
1584 } else {
1585 onFailure();
1586 }
1587 }
1588 };
1589 xhr.onerror = onFailure;
1590 xhr.ontimeout = onFailure;
1591 try {
1592 xhr.send(null);
1593 } catch (e) {
1594 onFailure();
1595 }
1596 }
1597 function parseResource(href, lang, successCallback, failureCallback) {
1598 var baseURL = href.replace(/[^\/]*$/, '') || './';
1599 function evalString(text) {
1600 if (text.lastIndexOf('\\') < 0) return text;
1601 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, "'");
1602 }
1603 function parseProperties(text, parsedPropertiesCallback) {
1604 var dictionary = {};
1605 var reBlank = /^\s*|\s*$/;
1606 var reComment = /^\s*#|^\s*$/;
1607 var reSection = /^\s*\[(.*)\]\s*$/;
1608 var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
1609 var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
1610 function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
1611 var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
1612 var currentLang = '*';
1613 var genericLang = lang.split('-', 1)[0];
1614 var skipLang = false;
1615 var match = '';
1616 function nextEntry() {
1617 while (true) {
1618 if (!entries.length) {
1619 parsedRawLinesCallback();
1620 return;
1621 }
1622 var line = entries.shift();
1623 if (reComment.test(line)) continue;
1624 if (extendedSyntax) {
1625 match = reSection.exec(line);
1626 if (match) {
1627 currentLang = match[1].toLowerCase();
1628 skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
1629 continue;
1630 } else if (skipLang) {
1631 continue;
1632 }
1633 match = reImport.exec(line);
1634 if (match) {
1635 loadImport(baseURL + match[1], nextEntry);
1636 return;
1637 }
1638 }
1639 var tmp = line.match(reSplit);
1640 if (tmp && tmp.length == 3) {
1641 dictionary[tmp[1]] = evalString(tmp[2]);
1642 }
1643 }
1644 }
1645 nextEntry();
1646 }
1647 function loadImport(url, callback) {
1648 xhrLoadText(url, function (content) {
1649 parseRawLines(content, false, callback);
1650 }, function () {
1651 console.warn(url + ' not found.');
1652 callback();
1653 });
1654 }
1655 parseRawLines(text, true, function () {
1656 parsedPropertiesCallback(dictionary);
1657 });
1658 }
1659 xhrLoadText(href, function (response) {
1660 gTextData += response;
1661 parseProperties(response, function (data) {
1662 for (var key in data) {
1663 var id,
1664 prop,
1665 index = key.lastIndexOf('.');
1666 if (index > 0) {
1667 id = key.substring(0, index);
1668 prop = key.substring(index + 1);
1669 } else {
1670 id = key;
1671 prop = gTextProp;
1672 }
1673 if (!gL10nData[id]) {
1674 gL10nData[id] = {};
1675 }
1676 gL10nData[id][prop] = data[key];
1677 }
1678 if (successCallback) {
1679 successCallback();
1680 }
1681 });
1682 }, failureCallback);
1683 }
1684 function loadLocale(lang, callback) {
1685 if (lang) {
1686 lang = lang.toLowerCase();
1687 }
1688 callback = callback || function _callback() {};
1689 clear();
1690 gLanguage = lang;
1691 var langLinks = getL10nResourceLinks();
1692 var langCount = langLinks.length;
1693 if (langCount === 0) {
1694 var dict = getL10nDictionary();
1695 if (dict && dict.locales && dict.default_locale) {
1696 console.log('using the embedded JSON directory, early way out');
1697 gL10nData = dict.locales[lang];
1698 if (!gL10nData) {
1699 var defaultLocale = dict.default_locale.toLowerCase();
1700 for (var anyCaseLang in dict.locales) {
1701 anyCaseLang = anyCaseLang.toLowerCase();
1702 if (anyCaseLang === lang) {
1703 gL10nData = dict.locales[lang];
1704 break;
1705 } else if (anyCaseLang === defaultLocale) {
1706 gL10nData = dict.locales[defaultLocale];
1707 }
1708 }
1709 }
1710 callback();
1711 } else {
1712 console.log('no resource to load, early way out');
1713 }
1714 gReadyState = 'complete';
1715 return;
1716 }
1717 var onResourceLoaded = null;
1718 var gResourceCount = 0;
1719 onResourceLoaded = function () {
1720 gResourceCount++;
1721 if (gResourceCount >= langCount) {
1722 callback();
1723 gReadyState = 'complete';
1724 }
1725 };
1726 function L10nResourceLink(link) {
1727 var href = link.href;
1728 this.load = function (lang, callback) {
1729 parseResource(href, lang, callback, function () {
1730 console.warn(href + ' not found.');
1731 console.warn('"' + lang + '" resource not found');
1732 gLanguage = '';
1733 callback();
1734 });
1735 };
1736 }
1737 for (var i = 0; i < langCount; i++) {
1738 var resource = new L10nResourceLink(langLinks[i]);
1739 resource.load(lang, onResourceLoaded);
1740 }
1741 }
1742 function clear() {
1743 gL10nData = {};
1744 gTextData = '';
1745 gLanguage = '';
1746 }
1747 function getPluralRules(lang) {
1748 var locales2rules = {
1749 'af': 3,
1750 'ak': 4,
1751 'am': 4,
1752 'ar': 1,
1753 'asa': 3,
1754 'az': 0,
1755 'be': 11,
1756 'bem': 3,
1757 'bez': 3,
1758 'bg': 3,
1759 'bh': 4,
1760 'bm': 0,
1761 'bn': 3,
1762 'bo': 0,
1763 'br': 20,
1764 'brx': 3,
1765 'bs': 11,
1766 'ca': 3,
1767 'cgg': 3,
1768 'chr': 3,
1769 'cs': 12,
1770 'cy': 17,
1771 'da': 3,
1772 'de': 3,
1773 'dv': 3,
1774 'dz': 0,
1775 'ee': 3,
1776 'el': 3,
1777 'en': 3,
1778 'eo': 3,
1779 'es': 3,
1780 'et': 3,
1781 'eu': 3,
1782 'fa': 0,
1783 'ff': 5,
1784 'fi': 3,
1785 'fil': 4,
1786 'fo': 3,
1787 'fr': 5,
1788 'fur': 3,
1789 'fy': 3,
1790 'ga': 8,
1791 'gd': 24,
1792 'gl': 3,
1793 'gsw': 3,
1794 'gu': 3,
1795 'guw': 4,
1796 'gv': 23,
1797 'ha': 3,
1798 'haw': 3,
1799 'he': 2,
1800 'hi': 4,
1801 'hr': 11,
1802 'hu': 0,
1803 'id': 0,
1804 'ig': 0,
1805 'ii': 0,
1806 'is': 3,
1807 'it': 3,
1808 'iu': 7,
1809 'ja': 0,
1810 'jmc': 3,
1811 'jv': 0,
1812 'ka': 0,
1813 'kab': 5,
1814 'kaj': 3,
1815 'kcg': 3,
1816 'kde': 0,
1817 'kea': 0,
1818 'kk': 3,
1819 'kl': 3,
1820 'km': 0,
1821 'kn': 0,
1822 'ko': 0,
1823 'ksb': 3,
1824 'ksh': 21,
1825 'ku': 3,
1826 'kw': 7,
1827 'lag': 18,
1828 'lb': 3,
1829 'lg': 3,
1830 'ln': 4,
1831 'lo': 0,
1832 'lt': 10,
1833 'lv': 6,
1834 'mas': 3,
1835 'mg': 4,
1836 'mk': 16,
1837 'ml': 3,
1838 'mn': 3,
1839 'mo': 9,
1840 'mr': 3,
1841 'ms': 0,
1842 'mt': 15,
1843 'my': 0,
1844 'nah': 3,
1845 'naq': 7,
1846 'nb': 3,
1847 'nd': 3,
1848 'ne': 3,
1849 'nl': 3,
1850 'nn': 3,
1851 'no': 3,
1852 'nr': 3,
1853 'nso': 4,
1854 'ny': 3,
1855 'nyn': 3,
1856 'om': 3,
1857 'or': 3,
1858 'pa': 3,
1859 'pap': 3,
1860 'pl': 13,
1861 'ps': 3,
1862 'pt': 3,
1863 'rm': 3,
1864 'ro': 9,
1865 'rof': 3,
1866 'ru': 11,
1867 'rwk': 3,
1868 'sah': 0,
1869 'saq': 3,
1870 'se': 7,
1871 'seh': 3,
1872 'ses': 0,
1873 'sg': 0,
1874 'sh': 11,
1875 'shi': 19,
1876 'sk': 12,
1877 'sl': 14,
1878 'sma': 7,
1879 'smi': 7,
1880 'smj': 7,
1881 'smn': 7,
1882 'sms': 7,
1883 'sn': 3,
1884 'so': 3,
1885 'sq': 3,
1886 'sr': 11,
1887 'ss': 3,
1888 'ssy': 3,
1889 'st': 3,
1890 'sv': 3,
1891 'sw': 3,
1892 'syr': 3,
1893 'ta': 3,
1894 'te': 3,
1895 'teo': 3,
1896 'th': 0,
1897 'ti': 4,
1898 'tig': 3,
1899 'tk': 3,
1900 'tl': 4,
1901 'tn': 3,
1902 'to': 0,
1903 'tr': 0,
1904 'ts': 3,
1905 'tzm': 22,
1906 'uk': 11,
1907 'ur': 3,
1908 've': 3,
1909 'vi': 0,
1910 'vun': 3,
1911 'wa': 4,
1912 'wae': 3,
1913 'wo': 0,
1914 'xh': 3,
1915 'xog': 3,
1916 'yo': 0,
1917 'zh': 0,
1918 'zu': 3
1919 };
1920 function isIn(n, list) {
1921 return list.indexOf(n) !== -1;
1922 }
1923 function isBetween(n, start, end) {
1924 return start <= n && n <= end;
1925 }
1926 var pluralRules = {
1927 '0': function (n) {
1928 return 'other';
1929 },
1930 '1': function (n) {
1931 if (isBetween(n % 100, 3, 10)) return 'few';
1932 if (n === 0) return 'zero';
1933 if (isBetween(n % 100, 11, 99)) return 'many';
1934 if (n == 2) return 'two';
1935 if (n == 1) return 'one';
1936 return 'other';
1937 },
1938 '2': function (n) {
1939 if (n !== 0 && n % 10 === 0) return 'many';
1940 if (n == 2) return 'two';
1941 if (n == 1) return 'one';
1942 return 'other';
1943 },
1944 '3': function (n) {
1945 if (n == 1) return 'one';
1946 return 'other';
1947 },
1948 '4': function (n) {
1949 if (isBetween(n, 0, 1)) return 'one';
1950 return 'other';
1951 },
1952 '5': function (n) {
1953 if (isBetween(n, 0, 2) && n != 2) return 'one';
1954 return 'other';
1955 },
1956 '6': function (n) {
1957 if (n === 0) return 'zero';
1958 if (n % 10 == 1 && n % 100 != 11) return 'one';
1959 return 'other';
1960 },
1961 '7': function (n) {
1962 if (n == 2) return 'two';
1963 if (n == 1) return 'one';
1964 return 'other';
1965 },
1966 '8': function (n) {
1967 if (isBetween(n, 3, 6)) return 'few';
1968 if (isBetween(n, 7, 10)) return 'many';
1969 if (n == 2) return 'two';
1970 if (n == 1) return 'one';
1971 return 'other';
1972 },
1973 '9': function (n) {
1974 if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
1975 if (n == 1) return 'one';
1976 return 'other';
1977 },
1978 '10': function (n) {
1979 if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
1980 if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
1981 return 'other';
1982 },
1983 '11': function (n) {
1984 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
1985 if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
1986 if (n % 10 == 1 && n % 100 != 11) return 'one';
1987 return 'other';
1988 },
1989 '12': function (n) {
1990 if (isBetween(n, 2, 4)) return 'few';
1991 if (n == 1) return 'one';
1992 return 'other';
1993 },
1994 '13': function (n) {
1995 if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
1996 if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
1997 if (n == 1) return 'one';
1998 return 'other';
1999 },
2000 '14': function (n) {
2001 if (isBetween(n % 100, 3, 4)) return 'few';
2002 if (n % 100 == 2) return 'two';
2003 if (n % 100 == 1) return 'one';
2004 return 'other';
2005 },
2006 '15': function (n) {
2007 if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
2008 if (isBetween(n % 100, 11, 19)) return 'many';
2009 if (n == 1) return 'one';
2010 return 'other';
2011 },
2012 '16': function (n) {
2013 if (n % 10 == 1 && n != 11) return 'one';
2014 return 'other';
2015 },
2016 '17': function (n) {
2017 if (n == 3) return 'few';
2018 if (n === 0) return 'zero';
2019 if (n == 6) return 'many';
2020 if (n == 2) return 'two';
2021 if (n == 1) return 'one';
2022 return 'other';
2023 },
2024 '18': function (n) {
2025 if (n === 0) return 'zero';
2026 if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
2027 return 'other';
2028 },
2029 '19': function (n) {
2030 if (isBetween(n, 2, 10)) return 'few';
2031 if (isBetween(n, 0, 1)) return 'one';
2032 return 'other';
2033 },
2034 '20': function (n) {
2035 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';
2036 if (n % 1000000 === 0 && n !== 0) return 'many';
2037 if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
2038 if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
2039 return 'other';
2040 },
2041 '21': function (n) {
2042 if (n === 0) return 'zero';
2043 if (n == 1) return 'one';
2044 return 'other';
2045 },
2046 '22': function (n) {
2047 if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
2048 return 'other';
2049 },
2050 '23': function (n) {
2051 if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
2052 return 'other';
2053 },
2054 '24': function (n) {
2055 if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
2056 if (isIn(n, [2, 12])) return 'two';
2057 if (isIn(n, [1, 11])) return 'one';
2058 return 'other';
2059 }
2060 };
2061 var index = locales2rules[lang.replace(/-.*$/, '')];
2062 if (!(index in pluralRules)) {
2063 console.warn('plural form unknown for [' + lang + ']');
2064 return function () {
2065 return 'other';
2066 };
2067 }
2068 return pluralRules[index];
2069 }
2070 gMacros.plural = function (str, param, key, prop) {
2071 var n = parseFloat(param);
2072 if (isNaN(n)) return str;
2073 if (prop != gTextProp) return str;
2074 if (!gMacros._pluralRules) {
2075 gMacros._pluralRules = getPluralRules(gLanguage);
2076 }
2077 var index = '[' + gMacros._pluralRules(n) + ']';
2078 if (n === 0 && key + '[zero]' in gL10nData) {
2079 str = gL10nData[key + '[zero]'][prop];
2080 } else if (n == 1 && key + '[one]' in gL10nData) {
2081 str = gL10nData[key + '[one]'][prop];
2082 } else if (n == 2 && key + '[two]' in gL10nData) {
2083 str = gL10nData[key + '[two]'][prop];
2084 } else if (key + index in gL10nData) {
2085 str = gL10nData[key + index][prop];
2086 } else if (key + '[other]' in gL10nData) {
2087 str = gL10nData[key + '[other]'][prop];
2088 }
2089 return str;
2090 };
2091 function getL10nData(key, args, fallback) {
2092 var data = gL10nData[key];
2093 if (!data) {
2094 console.warn('#' + key + ' is undefined.');
2095 if (!fallback) {
2096 return null;
2097 }
2098 data = fallback;
2099 }
2100 var rv = {};
2101 for (var prop in data) {
2102 var str = data[prop];
2103 str = substIndexes(str, args, key, prop);
2104 str = substArguments(str, args, key);
2105 rv[prop] = str;
2106 }
2107 return rv;
2108 }
2109 function substIndexes(str, args, key, prop) {
2110 var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
2111 var reMatch = reIndex.exec(str);
2112 if (!reMatch || !reMatch.length) return str;
2113 var macroName = reMatch[1];
2114 var paramName = reMatch[2];
2115 var param;
2116 if (args && paramName in args) {
2117 param = args[paramName];
2118 } else if (paramName in gL10nData) {
2119 param = gL10nData[paramName];
2120 }
2121 if (macroName in gMacros) {
2122 var macro = gMacros[macroName];
2123 str = macro(str, param, key, prop);
2124 }
2125 return str;
2126 }
2127 function substArguments(str, args, key) {
2128 var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
2129 return str.replace(reArgs, function (matched_text, arg) {
2130 if (args && arg in args) {
2131 return args[arg];
2132 }
2133 if (arg in gL10nData) {
2134 return gL10nData[arg];
2135 }
2136 console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
2137 return matched_text;
2138 });
2139 }
2140 function translateElement(element) {
2141 var l10n = getL10nAttributes(element);
2142 if (!l10n.id) return;
2143 var data = getL10nData(l10n.id, l10n.args);
2144 if (!data) {
2145 console.warn('#' + l10n.id + ' is undefined.');
2146 return;
2147 }
2148 if (data[gTextProp]) {
2149 if (getChildElementCount(element) === 0) {
2150 element[gTextProp] = data[gTextProp];
2151 } else {
2152 var children = element.childNodes;
2153 var found = false;
2154 for (var i = 0, l = children.length; i < l; i++) {
2155 if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
2156 if (found) {
2157 children[i].nodeValue = '';
2158 } else {
2159 children[i].nodeValue = data[gTextProp];
2160 found = true;
2161 }
2162 }
2163 }
2164 if (!found) {
2165 var textNode = document.createTextNode(data[gTextProp]);
2166 element.prepend(textNode);
2167 }
2168 }
2169 delete data[gTextProp];
2170 }
2171 for (var k in data) {
2172 element[k] = data[k];
2173 }
2174 }
2175 function getChildElementCount(element) {
2176 if (element.children) {
2177 return element.children.length;
2178 }
2179 if (typeof element.childElementCount !== 'undefined') {
2180 return element.childElementCount;
2181 }
2182 var count = 0;
2183 for (var i = 0; i < element.childNodes.length; i++) {
2184 count += element.nodeType === 1 ? 1 : 0;
2185 }
2186 return count;
2187 }
2188 function translateFragment(element) {
2189 element = element || document.documentElement;
2190 var children = getTranslatableChildren(element);
2191 var elementCount = children.length;
2192 for (var i = 0; i < elementCount; i++) {
2193 translateElement(children[i]);
2194 }
2195 translateElement(element);
2196 }
2197 return {
2198 get: function (key, args, fallbackString) {
2199 var index = key.lastIndexOf('.');
2200 var prop = gTextProp;
2201 if (index > 0) {
2202 prop = key.substring(index + 1);
2203 key = key.substring(0, index);
2204 }
2205 var fallback;
2206 if (fallbackString) {
2207 fallback = {};
2208 fallback[prop] = fallbackString;
2209 }
2210 var data = getL10nData(key, args, fallback);
2211 if (data && prop in data) {
2212 return data[prop];
2213 }
2214 return '{{' + key + '}}';
2215 },
2216 getData: function () {
2217 return gL10nData;
2218 },
2219 getText: function () {
2220 return gTextData;
2221 },
2222 getLanguage: function () {
2223 return gLanguage;
2224 },
2225 setLanguage: function (lang, callback) {
2226 loadLocale(lang, function () {
2227 if (callback) callback();
2228 });
2229 },
2230 getDirection: function () {
2231 var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
2232 var shortCode = gLanguage.split('-', 1)[0];
2233 return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
2234 },
2235 translate: translateFragment,
2236 getReadyState: function () {
2237 return gReadyState;
2238 },
2239 ready: function (callback) {
2240 if (!callback) {
2241 return;
2242 } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
2243 window.setTimeout(function () {
2244 callback();
2245 });
2246 } else if (document.addEventListener) {
2247 document.addEventListener('localized', function once() {
2248 document.removeEventListener('localized', once);
2249 callback();
2250 });
2251 }
2252 }
2253 };
2254}(window, document);
2255
2256/***/ }),
2257/* 10 */
2258/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
2259
2260
2261
2262Object.defineProperty(exports, "__esModule", ({
2263 value: true
2264}));
2265exports.PDFFindController = exports.FindState = void 0;
2266var _ui_utils = __w_pdfjs_require__(2);
2267var _pdf_find_utils = __w_pdfjs_require__(11);
2268var _pdfjsLib = __w_pdfjs_require__(4);
2269const FindState = {
2270 FOUND: 0,
2271 NOT_FOUND: 1,
2272 WRAPPED: 2,
2273 PENDING: 3
2274};
2275exports.FindState = FindState;
2276const FIND_TIMEOUT = 250;
2277const MATCH_SCROLL_OFFSET_TOP = -50;
2278const MATCH_SCROLL_OFFSET_LEFT = -400;
2279const CHARACTERS_TO_NORMALIZE = {
2280 "\u2010": "-",
2281 "\u2018": "'",
2282 "\u2019": "'",
2283 "\u201A": "'",
2284 "\u201B": "'",
2285 "\u201C": '"',
2286 "\u201D": '"',
2287 "\u201E": '"',
2288 "\u201F": '"',
2289 "\u00BC": "1/4",
2290 "\u00BD": "1/2",
2291 "\u00BE": "3/4"
2292};
2293const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
2294let DIACRITICS_EXCEPTION_STR;
2295const DIACRITICS_REG_EXP = /\p{M}+/gu;
2296const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
2297const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
2298const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
2299const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
2300const SYLLABLES_LENGTHS = new Map();
2301const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
2302const NFKC_CHARS_TO_NORMALIZE = new Map();
2303let noSyllablesRegExp = null;
2304let withSyllablesRegExp = null;
2305function normalize(text) {
2306 const syllablePositions = [];
2307 let m;
2308 while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
2309 let {
2310 index
2311 } = m;
2312 for (const char of m[0]) {
2313 let len = SYLLABLES_LENGTHS.get(char);
2314 if (!len) {
2315 len = char.normalize("NFD").length;
2316 SYLLABLES_LENGTHS.set(char, len);
2317 }
2318 syllablePositions.push([len, index++]);
2319 }
2320 }
2321 let normalizationRegex;
2322 if (syllablePositions.length === 0 && noSyllablesRegExp) {
2323 normalizationRegex = noSyllablesRegExp;
2324 } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
2325 normalizationRegex = withSyllablesRegExp;
2326 } else {
2327 const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
2328 const toNormalizeWithNFKC = (0, _pdf_find_utils.getNormalizeWithNFKC)();
2329 const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
2330 const HKDiacritics = "(?:\u3099|\u309A)";
2331 const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
2332 if (syllablePositions.length === 0) {
2333 normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
2334 } else {
2335 normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
2336 }
2337 }
2338 const rawDiacriticsPositions = [];
2339 while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
2340 rawDiacriticsPositions.push([m[0].length, m.index]);
2341 }
2342 let normalized = text.normalize("NFD");
2343 const positions = [[0, 0]];
2344 let rawDiacriticsIndex = 0;
2345 let syllableIndex = 0;
2346 let shift = 0;
2347 let shiftOrigin = 0;
2348 let eol = 0;
2349 let hasDiacritics = false;
2350 normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
2351 var _syllablePositions$sy;
2352 i -= shiftOrigin;
2353 if (p1) {
2354 const replacement = CHARACTERS_TO_NORMALIZE[p1];
2355 const jj = replacement.length;
2356 for (let j = 1; j < jj; j++) {
2357 positions.push([i - shift + j, shift - j]);
2358 }
2359 shift -= jj - 1;
2360 return replacement;
2361 }
2362 if (p2) {
2363 let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
2364 if (!replacement) {
2365 replacement = p2.normalize("NFKC");
2366 NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
2367 }
2368 const jj = replacement.length;
2369 for (let j = 1; j < jj; j++) {
2370 positions.push([i - shift + j, shift - j]);
2371 }
2372 shift -= jj - 1;
2373 return replacement;
2374 }
2375 if (p3) {
2376 var _rawDiacriticsPositio;
2377 hasDiacritics = true;
2378 if (i + eol === ((_rawDiacriticsPositio = rawDiacriticsPositions[rawDiacriticsIndex]) === null || _rawDiacriticsPositio === void 0 ? void 0 : _rawDiacriticsPositio[1])) {
2379 ++rawDiacriticsIndex;
2380 } else {
2381 positions.push([i - 1 - shift + 1, shift - 1]);
2382 shift -= 1;
2383 shiftOrigin += 1;
2384 }
2385 positions.push([i - shift + 1, shift]);
2386 shiftOrigin += 1;
2387 eol += 1;
2388 return p3.charAt(0);
2389 }
2390 if (p4) {
2391 var _rawDiacriticsPositio2;
2392 const hasTrailingDashEOL = p4.endsWith("\n");
2393 const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
2394 hasDiacritics = true;
2395 let jj = len;
2396 if (i + eol === ((_rawDiacriticsPositio2 = rawDiacriticsPositions[rawDiacriticsIndex]) === null || _rawDiacriticsPositio2 === void 0 ? void 0 : _rawDiacriticsPositio2[1])) {
2397 jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
2398 ++rawDiacriticsIndex;
2399 }
2400 for (let j = 1; j <= jj; j++) {
2401 positions.push([i - 1 - shift + j, shift - j]);
2402 }
2403 shift -= jj;
2404 shiftOrigin += jj;
2405 if (hasTrailingDashEOL) {
2406 i += len - 1;
2407 positions.push([i - shift + 1, 1 + shift]);
2408 shift += 1;
2409 shiftOrigin += 1;
2410 eol += 1;
2411 return p4.slice(0, len);
2412 }
2413 return p4;
2414 }
2415 if (p5) {
2416 const len = p5.length - 2;
2417 positions.push([i - shift + len, 1 + shift]);
2418 shift += 1;
2419 shiftOrigin += 1;
2420 eol += 1;
2421 return p5.slice(0, -2);
2422 }
2423 if (p6) {
2424 const len = p6.length - 1;
2425 positions.push([i - shift + len, shift]);
2426 shiftOrigin += 1;
2427 eol += 1;
2428 return p6.slice(0, -1);
2429 }
2430 if (p7) {
2431 positions.push([i - shift + 1, shift - 1]);
2432 shift -= 1;
2433 shiftOrigin += 1;
2434 eol += 1;
2435 return " ";
2436 }
2437 if (i + eol === ((_syllablePositions$sy = syllablePositions[syllableIndex]) === null || _syllablePositions$sy === void 0 ? void 0 : _syllablePositions$sy[1])) {
2438 const newCharLen = syllablePositions[syllableIndex][0] - 1;
2439 ++syllableIndex;
2440 for (let j = 1; j <= newCharLen; j++) {
2441 positions.push([i - (shift - j), shift - j]);
2442 }
2443 shift -= newCharLen;
2444 shiftOrigin += newCharLen;
2445 }
2446 return p8;
2447 });
2448 positions.push([normalized.length, shift]);
2449 return [normalized, positions, hasDiacritics];
2450}
2451function getOriginalIndex(diffs, pos, len) {
2452 if (!diffs) {
2453 return [pos, len];
2454 }
2455 const start = pos;
2456 const end = pos + len - 1;
2457 let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
2458 if (diffs[i][0] > start) {
2459 --i;
2460 }
2461 let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
2462 if (diffs[j][0] > end) {
2463 --j;
2464 }
2465 const oldStart = start + diffs[i][1];
2466 const oldEnd = end + diffs[j][1];
2467 const oldLen = oldEnd + 1 - oldStart;
2468 return [oldStart, oldLen];
2469}
2470class PDFFindController {
2471 #state = null;
2472 #updateMatchesCountOnProgress = true;
2473 #visitedPagesCount = 0;
2474 constructor(_ref) {
2475 let {
2476 linkService,
2477 eventBus,
2478 updateMatchesCountOnProgress = true
2479 } = _ref;
2480 this._linkService = linkService;
2481 this._eventBus = eventBus;
2482 this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
2483 this.onIsPageVisible = null;
2484 this.#reset();
2485 eventBus._on("find", this.#onFind.bind(this));
2486 eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
2487 }
2488 get highlightMatches() {
2489 return this._highlightMatches;
2490 }
2491 get pageMatches() {
2492 return this._pageMatches;
2493 }
2494 get pageMatchesLength() {
2495 return this._pageMatchesLength;
2496 }
2497 get selected() {
2498 return this._selected;
2499 }
2500 get state() {
2501 return this.#state;
2502 }
2503 setDocument(pdfDocument) {
2504 if (this._pdfDocument) {
2505 this.#reset();
2506 }
2507 if (!pdfDocument) {
2508 return;
2509 }
2510 this._pdfDocument = pdfDocument;
2511 this._firstPageCapability.resolve();
2512 }
2513 #onFind(state) {
2514 if (!state) {
2515 return;
2516 }
2517 if (state.phraseSearch === false) {
2518 console.error("The `phraseSearch`-parameter was removed, please provide " + "an Array of strings in the `query`-parameter instead.");
2519 if (typeof state.query === "string") {
2520 state.query = state.query.match(/\S+/g);
2521 }
2522 }
2523 const pdfDocument = this._pdfDocument;
2524 const {
2525 type
2526 } = state;
2527 if (this.#state === null || this.#shouldDirtyMatch(state)) {
2528 this._dirtyMatch = true;
2529 }
2530 this.#state = state;
2531 if (type !== "highlightallchange") {
2532 this.#updateUIState(FindState.PENDING);
2533 }
2534 this._firstPageCapability.promise.then(() => {
2535 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
2536 return;
2537 }
2538 this.#extractText();
2539 const findbarClosed = !this._highlightMatches;
2540 const pendingTimeout = !!this._findTimeout;
2541 if (this._findTimeout) {
2542 clearTimeout(this._findTimeout);
2543 this._findTimeout = null;
2544 }
2545 if (!type) {
2546 this._findTimeout = setTimeout(() => {
2547 this.#nextMatch();
2548 this._findTimeout = null;
2549 }, FIND_TIMEOUT);
2550 } else if (this._dirtyMatch) {
2551 this.#nextMatch();
2552 } else if (type === "again") {
2553 this.#nextMatch();
2554 if (findbarClosed && this.#state.highlightAll) {
2555 this.#updateAllPages();
2556 }
2557 } else if (type === "highlightallchange") {
2558 if (pendingTimeout) {
2559 this.#nextMatch();
2560 } else {
2561 this._highlightMatches = true;
2562 }
2563 this.#updateAllPages();
2564 } else {
2565 this.#nextMatch();
2566 }
2567 });
2568 }
2569 scrollMatchIntoView(_ref2) {
2570 let {
2571 element = null,
2572 selectedLeft = 0,
2573 pageIndex = -1,
2574 matchIndex = -1
2575 } = _ref2;
2576 if (!this._scrollMatches || !element) {
2577 return;
2578 } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
2579 return;
2580 } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
2581 return;
2582 }
2583 this._scrollMatches = false;
2584 const spot = {
2585 top: MATCH_SCROLL_OFFSET_TOP,
2586 left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
2587 };
2588 (0, _ui_utils.scrollIntoView)(element, spot, true);
2589 }
2590 #reset() {
2591 this._highlightMatches = false;
2592 this._scrollMatches = false;
2593 this._pdfDocument = null;
2594 this._pageMatches = [];
2595 this._pageMatchesLength = [];
2596 this.#visitedPagesCount = 0;
2597 this.#state = null;
2598 this._selected = {
2599 pageIdx: -1,
2600 matchIdx: -1
2601 };
2602 this._offset = {
2603 pageIdx: null,
2604 matchIdx: null,
2605 wrapped: false
2606 };
2607 this._extractTextPromises = [];
2608 this._pageContents = [];
2609 this._pageDiffs = [];
2610 this._hasDiacritics = [];
2611 this._matchesCountTotal = 0;
2612 this._pagesToSearch = null;
2613 this._pendingFindMatches = new Set();
2614 this._resumePageIdx = null;
2615 this._dirtyMatch = false;
2616 clearTimeout(this._findTimeout);
2617 this._findTimeout = null;
2618 this._firstPageCapability = new _pdfjsLib.PromiseCapability();
2619 }
2620 get #query() {
2621 const {
2622 query
2623 } = this.#state;
2624 if (typeof query === "string") {
2625 if (query !== this._rawQuery) {
2626 this._rawQuery = query;
2627 [this._normalizedQuery] = normalize(query);
2628 }
2629 return this._normalizedQuery;
2630 }
2631 return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
2632 }
2633 #shouldDirtyMatch(state) {
2634 var _this$onIsPageVisible;
2635 const newQuery = state.query,
2636 prevQuery = this.#state.query;
2637 const newType = typeof newQuery,
2638 prevType = typeof prevQuery;
2639 if (newType !== prevType) {
2640 return true;
2641 }
2642 if (newType === "string") {
2643 if (newQuery !== prevQuery) {
2644 return true;
2645 }
2646 } else {
2647 if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
2648 return true;
2649 }
2650 }
2651 switch (state.type) {
2652 case "again":
2653 const pageNumber = this._selected.pageIdx + 1;
2654 const linkService = this._linkService;
2655 return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(((_this$onIsPageVisible = this.onIsPageVisible) === null || _this$onIsPageVisible === void 0 ? void 0 : _this$onIsPageVisible.call(this, pageNumber)) ?? true);
2656 case "highlightallchange":
2657 return false;
2658 }
2659 return true;
2660 }
2661 #isEntireWord(content, startIdx, length) {
2662 let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
2663 if (match) {
2664 const first = content.charCodeAt(startIdx);
2665 const limit = match[1].charCodeAt(0);
2666 if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
2667 return false;
2668 }
2669 }
2670 match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
2671 if (match) {
2672 const last = content.charCodeAt(startIdx + length - 1);
2673 const limit = match[1].charCodeAt(0);
2674 if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
2675 return false;
2676 }
2677 }
2678 return true;
2679 }
2680 #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
2681 const matches = this._pageMatches[pageIndex] = [];
2682 const matchesLength = this._pageMatchesLength[pageIndex] = [];
2683 if (!query) {
2684 return;
2685 }
2686 const diffs = this._pageDiffs[pageIndex];
2687 let match;
2688 while ((match = query.exec(pageContent)) !== null) {
2689 if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
2690 continue;
2691 }
2692 const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
2693 if (matchLen) {
2694 matches.push(matchPos);
2695 matchesLength.push(matchLen);
2696 }
2697 }
2698 }
2699 #convertToRegExpString(query, hasDiacritics) {
2700 const {
2701 matchDiacritics
2702 } = this.#state;
2703 let isUnicode = false;
2704 query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
2705 if (p1) {
2706 return `[ ]*\\${p1}[ ]*`;
2707 }
2708 if (p2) {
2709 return `[ ]*${p2}[ ]*`;
2710 }
2711 if (p3) {
2712 return "[ ]+";
2713 }
2714 if (matchDiacritics) {
2715 return p4 || p5;
2716 }
2717 if (p4) {
2718 return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
2719 }
2720 if (hasDiacritics) {
2721 isUnicode = true;
2722 return `${p5}\\p{M}*`;
2723 }
2724 return p5;
2725 });
2726 const trailingSpaces = "[ ]*";
2727 if (query.endsWith(trailingSpaces)) {
2728 query = query.slice(0, query.length - trailingSpaces.length);
2729 }
2730 if (matchDiacritics) {
2731 if (hasDiacritics) {
2732 DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
2733 isUnicode = true;
2734 query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
2735 }
2736 }
2737 return [isUnicode, query];
2738 }
2739 #calculateMatch(pageIndex) {
2740 let query = this.#query;
2741 if (query.length === 0) {
2742 return;
2743 }
2744 const {
2745 caseSensitive,
2746 entireWord
2747 } = this.#state;
2748 const pageContent = this._pageContents[pageIndex];
2749 const hasDiacritics = this._hasDiacritics[pageIndex];
2750 let isUnicode = false;
2751 if (typeof query === "string") {
2752 [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
2753 } else {
2754 query = query.sort().reverse().map(q => {
2755 const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
2756 isUnicode ||= isUnicodePart;
2757 return `(${queryPart})`;
2758 }).join("|");
2759 }
2760 const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
2761 query = query ? new RegExp(query, flags) : null;
2762 this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
2763 if (this.#state.highlightAll) {
2764 this.#updatePage(pageIndex);
2765 }
2766 if (this._resumePageIdx === pageIndex) {
2767 this._resumePageIdx = null;
2768 this.#nextPageMatch();
2769 }
2770 const pageMatchesCount = this._pageMatches[pageIndex].length;
2771 this._matchesCountTotal += pageMatchesCount;
2772 if (this.#updateMatchesCountOnProgress) {
2773 if (pageMatchesCount > 0) {
2774 this.#updateUIResultsCount();
2775 }
2776 } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
2777 this.#updateUIResultsCount();
2778 }
2779 }
2780 #extractText() {
2781 if (this._extractTextPromises.length > 0) {
2782 return;
2783 }
2784 let promise = Promise.resolve();
2785 const textOptions = {
2786 disableNormalization: true
2787 };
2788 for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
2789 const extractTextCapability = new _pdfjsLib.PromiseCapability();
2790 this._extractTextPromises[i] = extractTextCapability.promise;
2791 promise = promise.then(() => {
2792 return this._pdfDocument.getPage(i + 1).then(pdfPage => {
2793 return pdfPage.getTextContent(textOptions);
2794 }).then(textContent => {
2795 const strBuf = [];
2796 for (const textItem of textContent.items) {
2797 strBuf.push(textItem.str);
2798 if (textItem.hasEOL) {
2799 strBuf.push("\n");
2800 }
2801 }
2802 [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
2803 extractTextCapability.resolve();
2804 }, reason => {
2805 console.error(`Unable to get text content for page ${i + 1}`, reason);
2806 this._pageContents[i] = "";
2807 this._pageDiffs[i] = null;
2808 this._hasDiacritics[i] = false;
2809 extractTextCapability.resolve();
2810 });
2811 });
2812 }
2813 }
2814 #updatePage(index) {
2815 if (this._scrollMatches && this._selected.pageIdx === index) {
2816 this._linkService.page = index + 1;
2817 }
2818 this._eventBus.dispatch("updatetextlayermatches", {
2819 source: this,
2820 pageIndex: index
2821 });
2822 }
2823 #updateAllPages() {
2824 this._eventBus.dispatch("updatetextlayermatches", {
2825 source: this,
2826 pageIndex: -1
2827 });
2828 }
2829 #nextMatch() {
2830 const previous = this.#state.findPrevious;
2831 const currentPageIndex = this._linkService.page - 1;
2832 const numPages = this._linkService.pagesCount;
2833 this._highlightMatches = true;
2834 if (this._dirtyMatch) {
2835 this._dirtyMatch = false;
2836 this._selected.pageIdx = this._selected.matchIdx = -1;
2837 this._offset.pageIdx = currentPageIndex;
2838 this._offset.matchIdx = null;
2839 this._offset.wrapped = false;
2840 this._resumePageIdx = null;
2841 this._pageMatches.length = 0;
2842 this._pageMatchesLength.length = 0;
2843 this.#visitedPagesCount = 0;
2844 this._matchesCountTotal = 0;
2845 this.#updateAllPages();
2846 for (let i = 0; i < numPages; i++) {
2847 if (this._pendingFindMatches.has(i)) {
2848 continue;
2849 }
2850 this._pendingFindMatches.add(i);
2851 this._extractTextPromises[i].then(() => {
2852 this._pendingFindMatches.delete(i);
2853 this.#calculateMatch(i);
2854 });
2855 }
2856 }
2857 const query = this.#query;
2858 if (query.length === 0) {
2859 this.#updateUIState(FindState.FOUND);
2860 return;
2861 }
2862 if (this._resumePageIdx) {
2863 return;
2864 }
2865 const offset = this._offset;
2866 this._pagesToSearch = numPages;
2867 if (offset.matchIdx !== null) {
2868 const numPageMatches = this._pageMatches[offset.pageIdx].length;
2869 if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
2870 offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
2871 this.#updateMatch(true);
2872 return;
2873 }
2874 this.#advanceOffsetPage(previous);
2875 }
2876 this.#nextPageMatch();
2877 }
2878 #matchesReady(matches) {
2879 const offset = this._offset;
2880 const numMatches = matches.length;
2881 const previous = this.#state.findPrevious;
2882 if (numMatches) {
2883 offset.matchIdx = previous ? numMatches - 1 : 0;
2884 this.#updateMatch(true);
2885 return true;
2886 }
2887 this.#advanceOffsetPage(previous);
2888 if (offset.wrapped) {
2889 offset.matchIdx = null;
2890 if (this._pagesToSearch < 0) {
2891 this.#updateMatch(false);
2892 return true;
2893 }
2894 }
2895 return false;
2896 }
2897 #nextPageMatch() {
2898 if (this._resumePageIdx !== null) {
2899 console.error("There can only be one pending page.");
2900 }
2901 let matches = null;
2902 do {
2903 const pageIdx = this._offset.pageIdx;
2904 matches = this._pageMatches[pageIdx];
2905 if (!matches) {
2906 this._resumePageIdx = pageIdx;
2907 break;
2908 }
2909 } while (!this.#matchesReady(matches));
2910 }
2911 #advanceOffsetPage(previous) {
2912 const offset = this._offset;
2913 const numPages = this._linkService.pagesCount;
2914 offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
2915 offset.matchIdx = null;
2916 this._pagesToSearch--;
2917 if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
2918 offset.pageIdx = previous ? numPages - 1 : 0;
2919 offset.wrapped = true;
2920 }
2921 }
2922 #updateMatch() {
2923 let found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2924 let state = FindState.NOT_FOUND;
2925 const wrapped = this._offset.wrapped;
2926 this._offset.wrapped = false;
2927 if (found) {
2928 const previousPage = this._selected.pageIdx;
2929 this._selected.pageIdx = this._offset.pageIdx;
2930 this._selected.matchIdx = this._offset.matchIdx;
2931 state = wrapped ? FindState.WRAPPED : FindState.FOUND;
2932 if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
2933 this.#updatePage(previousPage);
2934 }
2935 }
2936 this.#updateUIState(state, this.#state.findPrevious);
2937 if (this._selected.pageIdx !== -1) {
2938 this._scrollMatches = true;
2939 this.#updatePage(this._selected.pageIdx);
2940 }
2941 }
2942 #onFindBarClose(evt) {
2943 const pdfDocument = this._pdfDocument;
2944 this._firstPageCapability.promise.then(() => {
2945 if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
2946 return;
2947 }
2948 if (this._findTimeout) {
2949 clearTimeout(this._findTimeout);
2950 this._findTimeout = null;
2951 }
2952 if (this._resumePageIdx) {
2953 this._resumePageIdx = null;
2954 this._dirtyMatch = true;
2955 }
2956 this.#updateUIState(FindState.FOUND);
2957 this._highlightMatches = false;
2958 this.#updateAllPages();
2959 });
2960 }
2961 #requestMatchesCount() {
2962 const {
2963 pageIdx,
2964 matchIdx
2965 } = this._selected;
2966 let current = 0,
2967 total = this._matchesCountTotal;
2968 if (matchIdx !== -1) {
2969 for (let i = 0; i < pageIdx; i++) {
2970 var _this$_pageMatches$i;
2971 current += ((_this$_pageMatches$i = this._pageMatches[i]) === null || _this$_pageMatches$i === void 0 ? void 0 : _this$_pageMatches$i.length) || 0;
2972 }
2973 current += matchIdx + 1;
2974 }
2975 if (current < 1 || current > total) {
2976 current = total = 0;
2977 }
2978 return {
2979 current,
2980 total
2981 };
2982 }
2983 #updateUIResultsCount() {
2984 this._eventBus.dispatch("updatefindmatchescount", {
2985 source: this,
2986 matchesCount: this.#requestMatchesCount()
2987 });
2988 }
2989 #updateUIState(state) {
2990 var _this$state;
2991 let previous = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2992 if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
2993 return;
2994 }
2995 this._eventBus.dispatch("updatefindcontrolstate", {
2996 source: this,
2997 state,
2998 previous,
2999 matchesCount: this.#requestMatchesCount(),
3000 rawQuery: ((_this$state = this.#state) === null || _this$state === void 0 ? void 0 : _this$state.query) ?? null
3001 });
3002 }
3003}
3004exports.PDFFindController = PDFFindController;
3005
3006/***/ }),
3007/* 11 */
3008/***/ ((__unused_webpack_module, exports) => {
3009
3010
3011
3012Object.defineProperty(exports, "__esModule", ({
3013 value: true
3014}));
3015exports.CharacterType = void 0;
3016exports.getCharacterType = getCharacterType;
3017exports.getNormalizeWithNFKC = getNormalizeWithNFKC;
3018const CharacterType = {
3019 SPACE: 0,
3020 ALPHA_LETTER: 1,
3021 PUNCT: 2,
3022 HAN_LETTER: 3,
3023 KATAKANA_LETTER: 4,
3024 HIRAGANA_LETTER: 5,
3025 HALFWIDTH_KATAKANA_LETTER: 6,
3026 THAI_LETTER: 7
3027};
3028exports.CharacterType = CharacterType;
3029function isAlphabeticalScript(charCode) {
3030 return charCode < 0x2e80;
3031}
3032function isAscii(charCode) {
3033 return (charCode & 0xff80) === 0;
3034}
3035function isAsciiAlpha(charCode) {
3036 return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
3037}
3038function isAsciiDigit(charCode) {
3039 return charCode >= 0x30 && charCode <= 0x39;
3040}
3041function isAsciiSpace(charCode) {
3042 return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
3043}
3044function isHan(charCode) {
3045 return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
3046}
3047function isKatakana(charCode) {
3048 return charCode >= 0x30a0 && charCode <= 0x30ff;
3049}
3050function isHiragana(charCode) {
3051 return charCode >= 0x3040 && charCode <= 0x309f;
3052}
3053function isHalfwidthKatakana(charCode) {
3054 return charCode >= 0xff60 && charCode <= 0xff9f;
3055}
3056function isThai(charCode) {
3057 return (charCode & 0xff80) === 0x0e00;
3058}
3059function getCharacterType(charCode) {
3060 if (isAlphabeticalScript(charCode)) {
3061 if (isAscii(charCode)) {
3062 if (isAsciiSpace(charCode)) {
3063 return CharacterType.SPACE;
3064 } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
3065 return CharacterType.ALPHA_LETTER;
3066 }
3067 return CharacterType.PUNCT;
3068 } else if (isThai(charCode)) {
3069 return CharacterType.THAI_LETTER;
3070 } else if (charCode === 0xa0) {
3071 return CharacterType.SPACE;
3072 }
3073 return CharacterType.ALPHA_LETTER;
3074 }
3075 if (isHan(charCode)) {
3076 return CharacterType.HAN_LETTER;
3077 } else if (isKatakana(charCode)) {
3078 return CharacterType.KATAKANA_LETTER;
3079 } else if (isHiragana(charCode)) {
3080 return CharacterType.HIRAGANA_LETTER;
3081 } else if (isHalfwidthKatakana(charCode)) {
3082 return CharacterType.HALFWIDTH_KATAKANA_LETTER;
3083 }
3084 return CharacterType.ALPHA_LETTER;
3085}
3086let NormalizeWithNFKC;
3087function getNormalizeWithNFKC() {
3088 NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
3089 return NormalizeWithNFKC;
3090}
3091
3092/***/ }),
3093/* 12 */
3094/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
3095
3096
3097
3098Object.defineProperty(exports, "__esModule", ({
3099 value: true
3100}));
3101exports.PDFHistory = void 0;
3102exports.isDestArraysEqual = isDestArraysEqual;
3103exports.isDestHashesEqual = isDestHashesEqual;
3104var _ui_utils = __w_pdfjs_require__(2);
3105var _event_utils = __w_pdfjs_require__(7);
3106const HASH_CHANGE_TIMEOUT = 1000;
3107const POSITION_UPDATED_THRESHOLD = 50;
3108const UPDATE_VIEWAREA_TIMEOUT = 1000;
3109function getCurrentHash() {
3110 return document.location.hash;
3111}
3112class PDFHistory {
3113 constructor(_ref) {
3114 let {
3115 linkService,
3116 eventBus
3117 } = _ref;
3118 this.linkService = linkService;
3119 this.eventBus = eventBus;
3120 this._initialized = false;
3121 this._fingerprint = "";
3122 this.reset();
3123 this._boundEvents = null;
3124 this.eventBus._on("pagesinit", () => {
3125 this._isPagesLoaded = false;
3126 this.eventBus._on("pagesloaded", evt => {
3127 this._isPagesLoaded = !!evt.pagesCount;
3128 }, {
3129 once: true
3130 });
3131 });
3132 }
3133 initialize(_ref2) {
3134 let {
3135 fingerprint,
3136 resetHistory = false,
3137 updateUrl = false
3138 } = _ref2;
3139 if (!fingerprint || typeof fingerprint !== "string") {
3140 console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
3141 return;
3142 }
3143 if (this._initialized) {
3144 this.reset();
3145 }
3146 const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
3147 this._fingerprint = fingerprint;
3148 this._updateUrl = updateUrl === true;
3149 this._initialized = true;
3150 this._bindEvents();
3151 const state = window.history.state;
3152 this._popStateInProgress = false;
3153 this._blockHashChange = 0;
3154 this._currentHash = getCurrentHash();
3155 this._numPositionUpdates = 0;
3156 this._uid = this._maxUid = 0;
3157 this._destination = null;
3158 this._position = null;
3159 if (!this._isValidState(state, true) || resetHistory) {
3160 const {
3161 hash,
3162 page,
3163 rotation
3164 } = this._parseCurrentHash(true);
3165 if (!hash || reInitialized || resetHistory) {
3166 this._pushOrReplaceState(null, true);
3167 return;
3168 }
3169 this._pushOrReplaceState({
3170 hash,
3171 page,
3172 rotation
3173 }, true);
3174 return;
3175 }
3176 const destination = state.destination;
3177 this._updateInternalState(destination, state.uid, true);
3178 if (destination.rotation !== undefined) {
3179 this._initialRotation = destination.rotation;
3180 }
3181 if (destination.dest) {
3182 this._initialBookmark = JSON.stringify(destination.dest);
3183 this._destination.page = null;
3184 } else if (destination.hash) {
3185 this._initialBookmark = destination.hash;
3186 } else if (destination.page) {
3187 this._initialBookmark = `page=${destination.page}`;
3188 }
3189 }
3190 reset() {
3191 if (this._initialized) {
3192 this._pageHide();
3193 this._initialized = false;
3194 this._unbindEvents();
3195 }
3196 if (this._updateViewareaTimeout) {
3197 clearTimeout(this._updateViewareaTimeout);
3198 this._updateViewareaTimeout = null;
3199 }
3200 this._initialBookmark = null;
3201 this._initialRotation = null;
3202 }
3203 push(_ref3) {
3204 let {
3205 namedDest = null,
3206 explicitDest,
3207 pageNumber
3208 } = _ref3;
3209 if (!this._initialized) {
3210 return;
3211 }
3212 if (namedDest && typeof namedDest !== "string") {
3213 console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
3214 return;
3215 } else if (!Array.isArray(explicitDest)) {
3216 console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
3217 return;
3218 } else if (!this._isValidPage(pageNumber)) {
3219 if (pageNumber !== null || this._destination) {
3220 console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
3221 return;
3222 }
3223 }
3224 const hash = namedDest || JSON.stringify(explicitDest);
3225 if (!hash) {
3226 return;
3227 }
3228 let forceReplace = false;
3229 if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
3230 if (this._destination.page) {
3231 return;
3232 }
3233 forceReplace = true;
3234 }
3235 if (this._popStateInProgress && !forceReplace) {
3236 return;
3237 }
3238 this._pushOrReplaceState({
3239 dest: explicitDest,
3240 hash,
3241 page: pageNumber,
3242 rotation: this.linkService.rotation
3243 }, forceReplace);
3244 if (!this._popStateInProgress) {
3245 this._popStateInProgress = true;
3246 Promise.resolve().then(() => {
3247 this._popStateInProgress = false;
3248 });
3249 }
3250 }
3251 pushPage(pageNumber) {
3252 var _this$_destination;
3253 if (!this._initialized) {
3254 return;
3255 }
3256 if (!this._isValidPage(pageNumber)) {
3257 console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
3258 return;
3259 }
3260 if (((_this$_destination = this._destination) === null || _this$_destination === void 0 ? void 0 : _this$_destination.page) === pageNumber) {
3261 return;
3262 }
3263 if (this._popStateInProgress) {
3264 return;
3265 }
3266 this._pushOrReplaceState({
3267 dest: null,
3268 hash: `page=${pageNumber}`,
3269 page: pageNumber,
3270 rotation: this.linkService.rotation
3271 });
3272 if (!this._popStateInProgress) {
3273 this._popStateInProgress = true;
3274 Promise.resolve().then(() => {
3275 this._popStateInProgress = false;
3276 });
3277 }
3278 }
3279 pushCurrentPosition() {
3280 if (!this._initialized || this._popStateInProgress) {
3281 return;
3282 }
3283 this._tryPushCurrentPosition();
3284 }
3285 back() {
3286 if (!this._initialized || this._popStateInProgress) {
3287 return;
3288 }
3289 const state = window.history.state;
3290 if (this._isValidState(state) && state.uid > 0) {
3291 window.history.back();
3292 }
3293 }
3294 forward() {
3295 if (!this._initialized || this._popStateInProgress) {
3296 return;
3297 }
3298 const state = window.history.state;
3299 if (this._isValidState(state) && state.uid < this._maxUid) {
3300 window.history.forward();
3301 }
3302 }
3303 get popStateInProgress() {
3304 return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
3305 }
3306 get initialBookmark() {
3307 return this._initialized ? this._initialBookmark : null;
3308 }
3309 get initialRotation() {
3310 return this._initialized ? this._initialRotation : null;
3311 }
3312 _pushOrReplaceState(destination) {
3313 let forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3314 const shouldReplace = forceReplace || !this._destination;
3315 const newState = {
3316 fingerprint: this._fingerprint,
3317 uid: shouldReplace ? this._uid : this._uid + 1,
3318 destination
3319 };
3320 this._updateInternalState(destination, newState.uid);
3321 let newUrl;
3322 if (this._updateUrl && destination !== null && destination !== void 0 && destination.hash) {
3323 const baseUrl = document.location.href.split("#")[0];
3324 if (!baseUrl.startsWith("file://")) {
3325 newUrl = `${baseUrl}#${destination.hash}`;
3326 }
3327 }
3328 if (shouldReplace) {
3329 window.history.replaceState(newState, "", newUrl);
3330 } else {
3331 window.history.pushState(newState, "", newUrl);
3332 }
3333 }
3334 _tryPushCurrentPosition() {
3335 let temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3336 if (!this._position) {
3337 return;
3338 }
3339 let position = this._position;
3340 if (temporary) {
3341 position = Object.assign(Object.create(null), this._position);
3342 position.temporary = true;
3343 }
3344 if (!this._destination) {
3345 this._pushOrReplaceState(position);
3346 return;
3347 }
3348 if (this._destination.temporary) {
3349 this._pushOrReplaceState(position, true);
3350 return;
3351 }
3352 if (this._destination.hash === position.hash) {
3353 return;
3354 }
3355 if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
3356 return;
3357 }
3358 let forceReplace = false;
3359 if (this._destination.page >= position.first && this._destination.page <= position.page) {
3360 if (this._destination.dest !== undefined || !this._destination.first) {
3361 return;
3362 }
3363 forceReplace = true;
3364 }
3365 this._pushOrReplaceState(position, forceReplace);
3366 }
3367 _isValidPage(val) {
3368 return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
3369 }
3370 _isValidState(state) {
3371 let checkReload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3372 if (!state) {
3373 return false;
3374 }
3375 if (state.fingerprint !== this._fingerprint) {
3376 if (checkReload) {
3377 if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
3378 return false;
3379 }
3380 const [perfEntry] = performance.getEntriesByType("navigation");
3381 if ((perfEntry === null || perfEntry === void 0 ? void 0 : perfEntry.type) !== "reload") {
3382 return false;
3383 }
3384 } else {
3385 return false;
3386 }
3387 }
3388 if (!Number.isInteger(state.uid) || state.uid < 0) {
3389 return false;
3390 }
3391 if (state.destination === null || typeof state.destination !== "object") {
3392 return false;
3393 }
3394 return true;
3395 }
3396 _updateInternalState(destination, uid) {
3397 let removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3398 if (this._updateViewareaTimeout) {
3399 clearTimeout(this._updateViewareaTimeout);
3400 this._updateViewareaTimeout = null;
3401 }
3402 if (removeTemporary && destination !== null && destination !== void 0 && destination.temporary) {
3403 delete destination.temporary;
3404 }
3405 this._destination = destination;
3406 this._uid = uid;
3407 this._maxUid = Math.max(this._maxUid, uid);
3408 this._numPositionUpdates = 0;
3409 }
3410 _parseCurrentHash() {
3411 let checkNameddest = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3412 const hash = unescape(getCurrentHash()).substring(1);
3413 const params = (0, _ui_utils.parseQueryString)(hash);
3414 const nameddest = params.get("nameddest") || "";
3415 let page = params.get("page") | 0;
3416 if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
3417 page = null;
3418 }
3419 return {
3420 hash,
3421 page,
3422 rotation: this.linkService.rotation
3423 };
3424 }
3425 _updateViewarea(_ref4) {
3426 let {
3427 location
3428 } = _ref4;
3429 if (this._updateViewareaTimeout) {
3430 clearTimeout(this._updateViewareaTimeout);
3431 this._updateViewareaTimeout = null;
3432 }
3433 this._position = {
3434 hash: location.pdfOpenParams.substring(1),
3435 page: this.linkService.page,
3436 first: location.pageNumber,
3437 rotation: location.rotation
3438 };
3439 if (this._popStateInProgress) {
3440 return;
3441 }
3442 if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
3443 this._numPositionUpdates++;
3444 }
3445 if (UPDATE_VIEWAREA_TIMEOUT > 0) {
3446 this._updateViewareaTimeout = setTimeout(() => {
3447 if (!this._popStateInProgress) {
3448 this._tryPushCurrentPosition(true);
3449 }
3450 this._updateViewareaTimeout = null;
3451 }, UPDATE_VIEWAREA_TIMEOUT);
3452 }
3453 }
3454 _popState(_ref5) {
3455 let {
3456 state
3457 } = _ref5;
3458 const newHash = getCurrentHash(),
3459 hashChanged = this._currentHash !== newHash;
3460 this._currentHash = newHash;
3461 if (!state) {
3462 this._uid++;
3463 const {
3464 hash,
3465 page,
3466 rotation
3467 } = this._parseCurrentHash();
3468 this._pushOrReplaceState({
3469 hash,
3470 page,
3471 rotation
3472 }, true);
3473 return;
3474 }
3475 if (!this._isValidState(state)) {
3476 return;
3477 }
3478 this._popStateInProgress = true;
3479 if (hashChanged) {
3480 this._blockHashChange++;
3481 (0, _event_utils.waitOnEventOrTimeout)({
3482 target: window,
3483 name: "hashchange",
3484 delay: HASH_CHANGE_TIMEOUT
3485 }).then(() => {
3486 this._blockHashChange--;
3487 });
3488 }
3489 const destination = state.destination;
3490 this._updateInternalState(destination, state.uid, true);
3491 if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
3492 this.linkService.rotation = destination.rotation;
3493 }
3494 if (destination.dest) {
3495 this.linkService.goToDestination(destination.dest);
3496 } else if (destination.hash) {
3497 this.linkService.setHash(destination.hash);
3498 } else if (destination.page) {
3499 this.linkService.page = destination.page;
3500 }
3501 Promise.resolve().then(() => {
3502 this._popStateInProgress = false;
3503 });
3504 }
3505 _pageHide() {
3506 if (!this._destination || this._destination.temporary) {
3507 this._tryPushCurrentPosition();
3508 }
3509 }
3510 _bindEvents() {
3511 if (this._boundEvents) {
3512 return;
3513 }
3514 this._boundEvents = {
3515 updateViewarea: this._updateViewarea.bind(this),
3516 popState: this._popState.bind(this),
3517 pageHide: this._pageHide.bind(this)
3518 };
3519 this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
3520 window.addEventListener("popstate", this._boundEvents.popState);
3521 window.addEventListener("pagehide", this._boundEvents.pageHide);
3522 }
3523 _unbindEvents() {
3524 if (!this._boundEvents) {
3525 return;
3526 }
3527 this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
3528 window.removeEventListener("popstate", this._boundEvents.popState);
3529 window.removeEventListener("pagehide", this._boundEvents.pageHide);
3530 this._boundEvents = null;
3531 }
3532}
3533exports.PDFHistory = PDFHistory;
3534function isDestHashesEqual(destHash, pushHash) {
3535 if (typeof destHash !== "string" || typeof pushHash !== "string") {
3536 return false;
3537 }
3538 if (destHash === pushHash) {
3539 return true;
3540 }
3541 const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
3542 if (nameddest === pushHash) {
3543 return true;
3544 }
3545 return false;
3546}
3547function isDestArraysEqual(firstDest, secondDest) {
3548 function isEntryEqual(first, second) {
3549 if (typeof first !== typeof second) {
3550 return false;
3551 }
3552 if (Array.isArray(first) || Array.isArray(second)) {
3553 return false;
3554 }
3555 if (first !== null && typeof first === "object" && second !== null) {
3556 if (Object.keys(first).length !== Object.keys(second).length) {
3557 return false;
3558 }
3559 for (const key in first) {
3560 if (!isEntryEqual(first[key], second[key])) {
3561 return false;
3562 }
3563 }
3564 return true;
3565 }
3566 return first === second || Number.isNaN(first) && Number.isNaN(second);
3567 }
3568 if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
3569 return false;
3570 }
3571 if (firstDest.length !== secondDest.length) {
3572 return false;
3573 }
3574 for (let i = 0, ii = firstDest.length; i < ii; i++) {
3575 if (!isEntryEqual(firstDest[i], secondDest[i])) {
3576 return false;
3577 }
3578 }
3579 return true;
3580}
3581
3582/***/ }),
3583/* 13 */
3584/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
3585
3586
3587
3588Object.defineProperty(exports, "__esModule", ({
3589 value: true
3590}));
3591exports.PDFPageView = void 0;
3592var _pdfjsLib = __w_pdfjs_require__(4);
3593var _ui_utils = __w_pdfjs_require__(2);
3594var _annotation_editor_layer_builder = __w_pdfjs_require__(14);
3595var _annotation_layer_builder = __w_pdfjs_require__(3);
3596var _app_options = __w_pdfjs_require__(15);
3597var _l10n_utils = __w_pdfjs_require__(5);
3598var _pdf_link_service = __w_pdfjs_require__(1);
3599var _struct_tree_layer_builder = __w_pdfjs_require__(16);
3600var _text_accessibility = __w_pdfjs_require__(17);
3601var _text_highlighter = __w_pdfjs_require__(18);
3602var _text_layer_builder = __w_pdfjs_require__(19);
3603var _xfa_layer_builder = __w_pdfjs_require__(20);
3604const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
3605const DEFAULT_LAYER_PROPERTIES = () => {
3606 return {
3607 annotationEditorUIManager: null,
3608 annotationStorage: null,
3609 downloadManager: null,
3610 enableScripting: false,
3611 fieldObjectsPromise: null,
3612 findController: null,
3613 hasJSActionsPromise: null,
3614 get linkService() {
3615 return new _pdf_link_service.SimpleLinkService();
3616 }
3617 };
3618};
3619class PDFPageView {
3620 #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
3621 #layerProperties = null;
3622 #loadingId = null;
3623 #previousRotation = null;
3624 #renderError = null;
3625 #renderingState = _ui_utils.RenderingStates.INITIAL;
3626 #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
3627 #useThumbnailCanvas = {
3628 initialOptionalContent: true,
3629 regularAnnotations: true
3630 };
3631 #viewportMap = new WeakMap();
3632 constructor(options) {
3633 var _this$renderingQueue;
3634 const container = options.container;
3635 const defaultViewport = options.defaultViewport;
3636 this.id = options.id;
3637 this.renderingId = "page" + this.id;
3638 this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
3639 this.pdfPage = null;
3640 this.pageLabel = null;
3641 this.rotation = 0;
3642 this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
3643 this.viewport = defaultViewport;
3644 this.pdfPageRotate = defaultViewport.rotation;
3645 this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
3646 this.hasRestrictedScaling = false;
3647 this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
3648 this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
3649 this.imageResourcesPath = options.imageResourcesPath || "";
3650 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
3651 this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
3652 this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
3653 this.pageColors = options.pageColors || null;
3654 this.eventBus = options.eventBus;
3655 this.renderingQueue = options.renderingQueue;
3656 this.l10n = options.l10n || _l10n_utils.NullL10n;
3657 this.renderTask = null;
3658 this.resume = null;
3659 this._isStandalone = !((_this$renderingQueue = this.renderingQueue) !== null && _this$renderingQueue !== void 0 && _this$renderingQueue.hasViewer());
3660 this._annotationCanvasMap = null;
3661 this.annotationLayer = null;
3662 this.annotationEditorLayer = null;
3663 this.textLayer = null;
3664 this.zoomLayer = null;
3665 this.xfaLayer = null;
3666 this.structTreeLayer = null;
3667 const div = document.createElement("div");
3668 div.className = "page";
3669 div.setAttribute("data-page-number", this.id);
3670 div.setAttribute("role", "region");
3671 this.l10n.get("page_landmark", {
3672 page: this.id
3673 }).then(msg => {
3674 div.setAttribute("aria-label", msg);
3675 });
3676 this.div = div;
3677 this.#setDimensions();
3678 container === null || container === void 0 ? void 0 : container.append(div);
3679 if (this._isStandalone) {
3680 container === null || container === void 0 ? void 0 : container.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
3681 const {
3682 optionalContentConfigPromise
3683 } = options;
3684 if (optionalContentConfigPromise) {
3685 optionalContentConfigPromise.then(optionalContentConfig => {
3686 if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
3687 return;
3688 }
3689 this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
3690 });
3691 }
3692 }
3693 }
3694 get renderingState() {
3695 return this.#renderingState;
3696 }
3697 set renderingState(state) {
3698 if (state === this.#renderingState) {
3699 return;
3700 }
3701 this.#renderingState = state;
3702 if (this.#loadingId) {
3703 clearTimeout(this.#loadingId);
3704 this.#loadingId = null;
3705 }
3706 switch (state) {
3707 case _ui_utils.RenderingStates.PAUSED:
3708 this.div.classList.remove("loading");
3709 break;
3710 case _ui_utils.RenderingStates.RUNNING:
3711 this.div.classList.add("loadingIcon");
3712 this.#loadingId = setTimeout(() => {
3713 this.div.classList.add("loading");
3714 this.#loadingId = null;
3715 }, 0);
3716 break;
3717 case _ui_utils.RenderingStates.INITIAL:
3718 case _ui_utils.RenderingStates.FINISHED:
3719 this.div.classList.remove("loadingIcon", "loading");
3720 break;
3721 }
3722 }
3723 #setDimensions() {
3724 const {
3725 viewport
3726 } = this;
3727 if (this.pdfPage) {
3728 if (this.#previousRotation === viewport.rotation) {
3729 return;
3730 }
3731 this.#previousRotation = viewport.rotation;
3732 }
3733 (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
3734 }
3735 setPdfPage(pdfPage) {
3736 this.pdfPage = pdfPage;
3737 this.pdfPageRotate = pdfPage.rotate;
3738 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
3739 this.viewport = pdfPage.getViewport({
3740 scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
3741 rotation: totalRotation
3742 });
3743 this.#setDimensions();
3744 this.reset();
3745 }
3746 destroy() {
3747 var _this$pdfPage;
3748 this.reset();
3749 (_this$pdfPage = this.pdfPage) === null || _this$pdfPage === void 0 ? void 0 : _this$pdfPage.cleanup();
3750 }
3751 get _textHighlighter() {
3752 return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
3753 pageIndex: this.id - 1,
3754 eventBus: this.eventBus,
3755 findController: this.#layerProperties().findController
3756 }));
3757 }
3758 async #renderAnnotationLayer() {
3759 let error = null;
3760 try {
3761 await this.annotationLayer.render(this.viewport, "display");
3762 } catch (ex) {
3763 console.error(`#renderAnnotationLayer: "${ex}".`);
3764 error = ex;
3765 } finally {
3766 this.eventBus.dispatch("annotationlayerrendered", {
3767 source: this,
3768 pageNumber: this.id,
3769 error
3770 });
3771 }
3772 }
3773 async #renderAnnotationEditorLayer() {
3774 let error = null;
3775 try {
3776 await this.annotationEditorLayer.render(this.viewport, "display");
3777 } catch (ex) {
3778 console.error(`#renderAnnotationEditorLayer: "${ex}".`);
3779 error = ex;
3780 } finally {
3781 this.eventBus.dispatch("annotationeditorlayerrendered", {
3782 source: this,
3783 pageNumber: this.id,
3784 error
3785 });
3786 }
3787 }
3788 async #renderXfaLayer() {
3789 let error = null;
3790 try {
3791 const result = await this.xfaLayer.render(this.viewport, "display");
3792 if (result !== null && result !== void 0 && result.textDivs && this._textHighlighter) {
3793 this.#buildXfaTextContentItems(result.textDivs);
3794 }
3795 } catch (ex) {
3796 console.error(`#renderXfaLayer: "${ex}".`);
3797 error = ex;
3798 } finally {
3799 this.eventBus.dispatch("xfalayerrendered", {
3800 source: this,
3801 pageNumber: this.id,
3802 error
3803 });
3804 }
3805 }
3806 async #renderTextLayer() {
3807 const {
3808 pdfPage,
3809 textLayer,
3810 viewport
3811 } = this;
3812 if (!textLayer) {
3813 return;
3814 }
3815 let error = null;
3816 try {
3817 if (!textLayer.renderingDone) {
3818 const readableStream = pdfPage.streamTextContent({
3819 includeMarkedContent: true,
3820 disableNormalization: true
3821 });
3822 textLayer.setTextContentSource(readableStream);
3823 }
3824 await textLayer.render(viewport);
3825 } catch (ex) {
3826 if (ex instanceof _pdfjsLib.AbortException) {
3827 return;
3828 }
3829 console.error(`#renderTextLayer: "${ex}".`);
3830 error = ex;
3831 }
3832 this.eventBus.dispatch("textlayerrendered", {
3833 source: this,
3834 pageNumber: this.id,
3835 numTextDivs: textLayer.numTextDivs,
3836 error
3837 });
3838 this.#renderStructTreeLayer();
3839 }
3840 async #renderStructTreeLayer() {
3841 var _this$structTreeLayer, _this$structTreeLayer2;
3842 if (!this.textLayer) {
3843 return;
3844 }
3845 this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
3846 const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
3847 const treeDom = (_this$structTreeLayer = this.structTreeLayer) === null || _this$structTreeLayer === void 0 ? void 0 : _this$structTreeLayer.render(tree);
3848 if (treeDom) {
3849 var _this$canvas;
3850 (_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.append(treeDom);
3851 }
3852 (_this$structTreeLayer2 = this.structTreeLayer) === null || _this$structTreeLayer2 === void 0 ? void 0 : _this$structTreeLayer2.show();
3853 }
3854 async #buildXfaTextContentItems(textDivs) {
3855 const text = await this.pdfPage.getTextContent();
3856 const items = [];
3857 for (const item of text.items) {
3858 items.push(item.str);
3859 }
3860 this._textHighlighter.setTextMapping(textDivs, items);
3861 this._textHighlighter.enable();
3862 }
3863 _resetZoomLayer() {
3864 let removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3865 if (!this.zoomLayer) {
3866 return;
3867 }
3868 const zoomLayerCanvas = this.zoomLayer.firstChild;
3869 this.#viewportMap.delete(zoomLayerCanvas);
3870 zoomLayerCanvas.width = 0;
3871 zoomLayerCanvas.height = 0;
3872 if (removeFromDOM) {
3873 this.zoomLayer.remove();
3874 }
3875 this.zoomLayer = null;
3876 }
3877 reset() {
3878 var _this$annotationLayer, _this$annotationEdito, _this$xfaLayer, _this$textLayer, _this$structTreeLayer3;
3879 let {
3880 keepZoomLayer = false,
3881 keepAnnotationLayer = false,
3882 keepAnnotationEditorLayer = false,
3883 keepXfaLayer = false,
3884 keepTextLayer = false
3885 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3886 this.cancelRendering({
3887 keepAnnotationLayer,
3888 keepAnnotationEditorLayer,
3889 keepXfaLayer,
3890 keepTextLayer
3891 });
3892 this.renderingState = _ui_utils.RenderingStates.INITIAL;
3893 const div = this.div;
3894 const childNodes = div.childNodes,
3895 zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
3896 annotationLayerNode = keepAnnotationLayer && ((_this$annotationLayer = this.annotationLayer) === null || _this$annotationLayer === void 0 ? void 0 : _this$annotationLayer.div) || null,
3897 annotationEditorLayerNode = keepAnnotationEditorLayer && ((_this$annotationEdito = this.annotationEditorLayer) === null || _this$annotationEdito === void 0 ? void 0 : _this$annotationEdito.div) || null,
3898 xfaLayerNode = keepXfaLayer && ((_this$xfaLayer = this.xfaLayer) === null || _this$xfaLayer === void 0 ? void 0 : _this$xfaLayer.div) || null,
3899 textLayerNode = keepTextLayer && ((_this$textLayer = this.textLayer) === null || _this$textLayer === void 0 ? void 0 : _this$textLayer.div) || null;
3900 for (let i = childNodes.length - 1; i >= 0; i--) {
3901 const node = childNodes[i];
3902 switch (node) {
3903 case zoomLayerNode:
3904 case annotationLayerNode:
3905 case annotationEditorLayerNode:
3906 case xfaLayerNode:
3907 case textLayerNode:
3908 continue;
3909 }
3910 node.remove();
3911 }
3912 div.removeAttribute("data-loaded");
3913 if (annotationLayerNode) {
3914 this.annotationLayer.hide();
3915 }
3916 if (annotationEditorLayerNode) {
3917 this.annotationEditorLayer.hide();
3918 }
3919 if (xfaLayerNode) {
3920 this.xfaLayer.hide();
3921 }
3922 if (textLayerNode) {
3923 this.textLayer.hide();
3924 }
3925 (_this$structTreeLayer3 = this.structTreeLayer) === null || _this$structTreeLayer3 === void 0 ? void 0 : _this$structTreeLayer3.hide();
3926 if (!zoomLayerNode) {
3927 if (this.canvas) {
3928 this.#viewportMap.delete(this.canvas);
3929 this.canvas.width = 0;
3930 this.canvas.height = 0;
3931 delete this.canvas;
3932 }
3933 this._resetZoomLayer();
3934 }
3935 }
3936 update(_ref) {
3937 let {
3938 scale = 0,
3939 rotation = null,
3940 optionalContentConfigPromise = null,
3941 drawingDelay = -1
3942 } = _ref;
3943 this.scale = scale || this.scale;
3944 if (typeof rotation === "number") {
3945 this.rotation = rotation;
3946 }
3947 if (optionalContentConfigPromise instanceof Promise) {
3948 this._optionalContentConfigPromise = optionalContentConfigPromise;
3949 optionalContentConfigPromise.then(optionalContentConfig => {
3950 if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
3951 return;
3952 }
3953 this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
3954 });
3955 }
3956 const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
3957 this.viewport = this.viewport.clone({
3958 scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
3959 rotation: totalRotation
3960 });
3961 this.#setDimensions();
3962 if (this._isStandalone) {
3963 var _this$div$parentNode;
3964 (_this$div$parentNode = this.div.parentNode) === null || _this$div$parentNode === void 0 ? void 0 : _this$div$parentNode.style.setProperty("--scale-factor", this.viewport.scale);
3965 }
3966 let isScalingRestricted = false;
3967 if (this.canvas && this.maxCanvasPixels > 0) {
3968 const {
3969 width,
3970 height
3971 } = this.viewport;
3972 const {
3973 sx,
3974 sy
3975 } = this.outputScale;
3976 if ((Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels) {
3977 isScalingRestricted = true;
3978 }
3979 }
3980 const onlyCssZoom = this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted;
3981 const postponeDrawing = !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
3982 if (this.canvas) {
3983 if (postponeDrawing || onlyCssZoom) {
3984 if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
3985 this.cancelRendering({
3986 keepZoomLayer: true,
3987 keepAnnotationLayer: true,
3988 keepAnnotationEditorLayer: true,
3989 keepXfaLayer: true,
3990 keepTextLayer: true,
3991 cancelExtraDelay: drawingDelay
3992 });
3993 this.renderingState = _ui_utils.RenderingStates.FINISHED;
3994 }
3995 this.cssTransform({
3996 target: this.canvas,
3997 redrawAnnotationLayer: true,
3998 redrawAnnotationEditorLayer: true,
3999 redrawXfaLayer: true,
4000 redrawTextLayer: !postponeDrawing,
4001 hideTextLayer: postponeDrawing
4002 });
4003 this.eventBus.dispatch("pagerendered", {
4004 source: this,
4005 pageNumber: this.id,
4006 cssTransform: true,
4007 timestamp: performance.now(),
4008 error: this.#renderError
4009 });
4010 return;
4011 }
4012 if (!this.zoomLayer && !this.canvas.hidden) {
4013 this.zoomLayer = this.canvas.parentNode;
4014 this.zoomLayer.style.position = "absolute";
4015 }
4016 }
4017 if (this.zoomLayer) {
4018 this.cssTransform({
4019 target: this.zoomLayer.firstChild
4020 });
4021 }
4022 this.reset({
4023 keepZoomLayer: true,
4024 keepAnnotationLayer: true,
4025 keepAnnotationEditorLayer: true,
4026 keepXfaLayer: true,
4027 keepTextLayer: true
4028 });
4029 }
4030 cancelRendering() {
4031 let {
4032 keepAnnotationLayer = false,
4033 keepAnnotationEditorLayer = false,
4034 keepXfaLayer = false,
4035 keepTextLayer = false,
4036 cancelExtraDelay = 0
4037 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4038 if (this.renderTask) {
4039 this.renderTask.cancel(cancelExtraDelay);
4040 this.renderTask = null;
4041 }
4042 this.resume = null;
4043 if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
4044 this.textLayer.cancel();
4045 this.textLayer = null;
4046 }
4047 if (this.structTreeLayer && !this.textLayer) {
4048 this.structTreeLayer = null;
4049 }
4050 if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
4051 this.annotationLayer.cancel();
4052 this.annotationLayer = null;
4053 this._annotationCanvasMap = null;
4054 }
4055 if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
4056 this.annotationEditorLayer.cancel();
4057 this.annotationEditorLayer = null;
4058 }
4059 if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
4060 var _this$_textHighlighte;
4061 this.xfaLayer.cancel();
4062 this.xfaLayer = null;
4063 (_this$_textHighlighte = this._textHighlighter) === null || _this$_textHighlighte === void 0 ? void 0 : _this$_textHighlighte.disable();
4064 }
4065 }
4066 cssTransform(_ref2) {
4067 let {
4068 target,
4069 redrawAnnotationLayer = false,
4070 redrawAnnotationEditorLayer = false,
4071 redrawXfaLayer = false,
4072 redrawTextLayer = false,
4073 hideTextLayer = false
4074 } = _ref2;
4075 if (!target.hasAttribute("zooming")) {
4076 target.setAttribute("zooming", true);
4077 const {
4078 style
4079 } = target;
4080 style.width = style.height = "";
4081 }
4082 const originalViewport = this.#viewportMap.get(target);
4083 if (this.viewport !== originalViewport) {
4084 const relativeRotation = this.viewport.rotation - originalViewport.rotation;
4085 const absRotation = Math.abs(relativeRotation);
4086 let scaleX = 1,
4087 scaleY = 1;
4088 if (absRotation === 90 || absRotation === 270) {
4089 const {
4090 width,
4091 height
4092 } = this.viewport;
4093 scaleX = height / width;
4094 scaleY = width / height;
4095 }
4096 target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
4097 }
4098 if (redrawAnnotationLayer && this.annotationLayer) {
4099 this.#renderAnnotationLayer();
4100 }
4101 if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
4102 this.#renderAnnotationEditorLayer();
4103 }
4104 if (redrawXfaLayer && this.xfaLayer) {
4105 this.#renderXfaLayer();
4106 }
4107 if (this.textLayer) {
4108 if (hideTextLayer) {
4109 var _this$structTreeLayer4;
4110 this.textLayer.hide();
4111 (_this$structTreeLayer4 = this.structTreeLayer) === null || _this$structTreeLayer4 === void 0 ? void 0 : _this$structTreeLayer4.hide();
4112 } else if (redrawTextLayer) {
4113 this.#renderTextLayer();
4114 }
4115 }
4116 }
4117 get width() {
4118 return this.viewport.width;
4119 }
4120 get height() {
4121 return this.viewport.height;
4122 }
4123 getPagePoint(x, y) {
4124 return this.viewport.convertToPdfPoint(x, y);
4125 }
4126 async #finishRenderTask(renderTask) {
4127 let error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
4128 if (renderTask === this.renderTask) {
4129 this.renderTask = null;
4130 }
4131 if (error instanceof _pdfjsLib.RenderingCancelledException) {
4132 this.#renderError = null;
4133 return;
4134 }
4135 this.#renderError = error;
4136 this.renderingState = _ui_utils.RenderingStates.FINISHED;
4137 this._resetZoomLayer(true);
4138 this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
4139 this.eventBus.dispatch("pagerendered", {
4140 source: this,
4141 pageNumber: this.id,
4142 cssTransform: false,
4143 timestamp: performance.now(),
4144 error: this.#renderError
4145 });
4146 if (error) {
4147 throw error;
4148 }
4149 }
4150 async draw() {
4151 if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
4152 console.error("Must be in new state before drawing");
4153 this.reset();
4154 }
4155 const {
4156 div,
4157 l10n,
4158 pageColors,
4159 pdfPage,
4160 viewport
4161 } = this;
4162 if (!pdfPage) {
4163 this.renderingState = _ui_utils.RenderingStates.FINISHED;
4164 throw new Error("pdfPage is not loaded");
4165 }
4166 this.renderingState = _ui_utils.RenderingStates.RUNNING;
4167 const canvasWrapper = document.createElement("div");
4168 canvasWrapper.classList.add("canvasWrapper");
4169 div.append(canvasWrapper);
4170 if (!this.textLayer && this.#textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
4171 this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
4172 this.textLayer = new _text_layer_builder.TextLayerBuilder({
4173 highlighter: this._textHighlighter,
4174 accessibilityManager: this._accessibilityManager,
4175 isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
4176 enablePermissions: this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS
4177 });
4178 div.append(this.textLayer.div);
4179 }
4180 if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
4181 const {
4182 annotationStorage,
4183 downloadManager,
4184 enableScripting,
4185 fieldObjectsPromise,
4186 hasJSActionsPromise,
4187 linkService
4188 } = this.#layerProperties();
4189 this._annotationCanvasMap ||= new Map();
4190 this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
4191 pageDiv: div,
4192 pdfPage,
4193 annotationStorage,
4194 imageResourcesPath: this.imageResourcesPath,
4195 renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
4196 linkService,
4197 downloadManager,
4198 l10n,
4199 enableScripting,
4200 hasJSActionsPromise,
4201 fieldObjectsPromise,
4202 annotationCanvasMap: this._annotationCanvasMap,
4203 accessibilityManager: this._accessibilityManager
4204 });
4205 }
4206 const renderContinueCallback = cont => {
4207 var _showCanvas;
4208 (_showCanvas = showCanvas) === null || _showCanvas === void 0 ? void 0 : _showCanvas(false);
4209 if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
4210 this.renderingState = _ui_utils.RenderingStates.PAUSED;
4211 this.resume = () => {
4212 this.renderingState = _ui_utils.RenderingStates.RUNNING;
4213 cont();
4214 };
4215 return;
4216 }
4217 cont();
4218 };
4219 const {
4220 width,
4221 height
4222 } = viewport;
4223 const canvas = document.createElement("canvas");
4224 canvas.setAttribute("role", "presentation");
4225 canvas.hidden = true;
4226 const hasHCM = !!(pageColors !== null && pageColors !== void 0 && pageColors.background && pageColors !== null && pageColors !== void 0 && pageColors.foreground);
4227 let showCanvas = isLastShow => {
4228 if (!hasHCM || isLastShow) {
4229 canvas.hidden = false;
4230 showCanvas = null;
4231 }
4232 };
4233 canvasWrapper.append(canvas);
4234 this.canvas = canvas;
4235 const ctx = canvas.getContext("2d", {
4236 alpha: false
4237 });
4238 const outputScale = this.outputScale = new _ui_utils.OutputScale();
4239 if (this.useOnlyCssZoom) {
4240 const actualSizeViewport = viewport.clone({
4241 scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
4242 });
4243 outputScale.sx *= actualSizeViewport.width / width;
4244 outputScale.sy *= actualSizeViewport.height / height;
4245 }
4246 if (this.maxCanvasPixels > 0) {
4247 const pixelsInViewport = width * height;
4248 const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
4249 if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
4250 outputScale.sx = maxScale;
4251 outputScale.sy = maxScale;
4252 this.hasRestrictedScaling = true;
4253 } else {
4254 this.hasRestrictedScaling = false;
4255 }
4256 }
4257 const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
4258 const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
4259 canvas.width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
4260 canvas.height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
4261 const {
4262 style
4263 } = canvas;
4264 style.width = (0, _ui_utils.roundToDivide)(width, sfx[1]) + "px";
4265 style.height = (0, _ui_utils.roundToDivide)(height, sfy[1]) + "px";
4266 this.#viewportMap.set(canvas, viewport);
4267 const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
4268 const renderContext = {
4269 canvasContext: ctx,
4270 transform,
4271 viewport,
4272 annotationMode: this.#annotationMode,
4273 optionalContentConfigPromise: this._optionalContentConfigPromise,
4274 annotationCanvasMap: this._annotationCanvasMap,
4275 pageColors
4276 };
4277 const renderTask = this.renderTask = this.pdfPage.render(renderContext);
4278 renderTask.onContinue = renderContinueCallback;
4279 const resultPromise = renderTask.promise.then(async () => {
4280 var _showCanvas2;
4281 (_showCanvas2 = showCanvas) === null || _showCanvas2 === void 0 ? void 0 : _showCanvas2(true);
4282 await this.#finishRenderTask(renderTask);
4283 this.#renderTextLayer();
4284 if (this.annotationLayer) {
4285 await this.#renderAnnotationLayer();
4286 }
4287 if (!this.annotationEditorLayer) {
4288 const {
4289 annotationEditorUIManager
4290 } = this.#layerProperties();
4291 if (!annotationEditorUIManager) {
4292 return;
4293 }
4294 this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
4295 uiManager: annotationEditorUIManager,
4296 pageDiv: div,
4297 pdfPage,
4298 l10n,
4299 accessibilityManager: this._accessibilityManager
4300 });
4301 }
4302 this.#renderAnnotationEditorLayer();
4303 }, error => {
4304 if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
4305 var _showCanvas3;
4306 (_showCanvas3 = showCanvas) === null || _showCanvas3 === void 0 ? void 0 : _showCanvas3(true);
4307 }
4308 return this.#finishRenderTask(renderTask, error);
4309 });
4310 if (pdfPage.isPureXfa) {
4311 if (!this.xfaLayer) {
4312 const {
4313 annotationStorage,
4314 linkService
4315 } = this.#layerProperties();
4316 this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
4317 pageDiv: div,
4318 pdfPage,
4319 annotationStorage,
4320 linkService
4321 });
4322 } else if (this.xfaLayer.div) {
4323 div.append(this.xfaLayer.div);
4324 }
4325 this.#renderXfaLayer();
4326 }
4327 div.setAttribute("data-loaded", true);
4328 this.eventBus.dispatch("pagerender", {
4329 source: this,
4330 pageNumber: this.id
4331 });
4332 return resultPromise;
4333 }
4334 setPageLabel(label) {
4335 this.pageLabel = typeof label === "string" ? label : null;
4336 if (this.pageLabel !== null) {
4337 this.div.setAttribute("data-page-label", this.pageLabel);
4338 } else {
4339 this.div.removeAttribute("data-page-label");
4340 }
4341 }
4342 get thumbnailCanvas() {
4343 const {
4344 initialOptionalContent,
4345 regularAnnotations
4346 } = this.#useThumbnailCanvas;
4347 return initialOptionalContent && regularAnnotations ? this.canvas : null;
4348 }
4349}
4350exports.PDFPageView = PDFPageView;
4351
4352/***/ }),
4353/* 14 */
4354/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
4355
4356
4357
4358Object.defineProperty(exports, "__esModule", ({
4359 value: true
4360}));
4361exports.AnnotationEditorLayerBuilder = void 0;
4362var _pdfjsLib = __w_pdfjs_require__(4);
4363var _l10n_utils = __w_pdfjs_require__(5);
4364class AnnotationEditorLayerBuilder {
4365 #uiManager;
4366 constructor(options) {
4367 this.pageDiv = options.pageDiv;
4368 this.pdfPage = options.pdfPage;
4369 this.accessibilityManager = options.accessibilityManager;
4370 this.l10n = options.l10n || _l10n_utils.NullL10n;
4371 this.annotationEditorLayer = null;
4372 this.div = null;
4373 this._cancelled = false;
4374 this.#uiManager = options.uiManager;
4375 }
4376 async render(viewport) {
4377 let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
4378 if (intent !== "display") {
4379 return;
4380 }
4381 if (this._cancelled) {
4382 return;
4383 }
4384 const clonedViewport = viewport.clone({
4385 dontFlip: true
4386 });
4387 if (this.div) {
4388 this.annotationEditorLayer.update({
4389 viewport: clonedViewport
4390 });
4391 this.show();
4392 return;
4393 }
4394 const div = this.div = document.createElement("div");
4395 div.className = "annotationEditorLayer";
4396 div.tabIndex = 0;
4397 div.hidden = true;
4398 this.pageDiv.append(div);
4399 this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
4400 uiManager: this.#uiManager,
4401 div,
4402 accessibilityManager: this.accessibilityManager,
4403 pageIndex: this.pdfPage.pageNumber - 1,
4404 l10n: this.l10n,
4405 viewport: clonedViewport
4406 });
4407 const parameters = {
4408 viewport: clonedViewport,
4409 div,
4410 annotations: null,
4411 intent
4412 };
4413 this.annotationEditorLayer.render(parameters);
4414 this.show();
4415 }
4416 cancel() {
4417 this._cancelled = true;
4418 if (!this.div) {
4419 return;
4420 }
4421 this.pageDiv = null;
4422 this.annotationEditorLayer.destroy();
4423 this.div.remove();
4424 }
4425 hide() {
4426 if (!this.div) {
4427 return;
4428 }
4429 this.div.hidden = true;
4430 }
4431 show() {
4432 if (!this.div || this.annotationEditorLayer.isEmpty) {
4433 return;
4434 }
4435 this.div.hidden = false;
4436 }
4437}
4438exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
4439
4440/***/ }),
4441/* 15 */
4442/***/ ((__unused_webpack_module, exports) => {
4443
4444
4445
4446Object.defineProperty(exports, "__esModule", ({
4447 value: true
4448}));
4449exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
4450const compatibilityParams = Object.create(null);
4451exports.compatibilityParams = compatibilityParams;
4452{
4453 const userAgent = navigator.userAgent || "";
4454 const platform = navigator.platform || "";
4455 const maxTouchPoints = navigator.maxTouchPoints || 1;
4456 const isAndroid = /Android/.test(userAgent);
4457 const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
4458 (function checkCanvasSizeLimitation() {
4459 if (isIOS || isAndroid) {
4460 compatibilityParams.maxCanvasPixels = 5242880;
4461 }
4462 })();
4463}
4464const OptionKind = {
4465 VIEWER: 0x02,
4466 API: 0x04,
4467 WORKER: 0x08,
4468 PREFERENCE: 0x80
4469};
4470exports.OptionKind = OptionKind;
4471const defaultOptions = {
4472 annotationEditorMode: {
4473 value: 0,
4474 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4475 },
4476 annotationMode: {
4477 value: 2,
4478 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4479 },
4480 cursorToolOnLoad: {
4481 value: 0,
4482 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4483 },
4484 defaultZoomDelay: {
4485 value: 400,
4486 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4487 },
4488 defaultZoomValue: {
4489 value: "",
4490 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4491 },
4492 disableHistory: {
4493 value: false,
4494 kind: OptionKind.VIEWER
4495 },
4496 disablePageLabels: {
4497 value: false,
4498 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4499 },
4500 enableFloatingToolbar: {
4501 value: false,
4502 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4503 },
4504 enablePermissions: {
4505 value: false,
4506 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4507 },
4508 enablePrintAutoRotate: {
4509 value: true,
4510 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4511 },
4512 enableScripting: {
4513 value: true,
4514 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4515 },
4516 externalLinkRel: {
4517 value: "noopener noreferrer nofollow",
4518 kind: OptionKind.VIEWER
4519 },
4520 externalLinkTarget: {
4521 value: 0,
4522 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4523 },
4524 historyUpdateUrl: {
4525 value: false,
4526 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4527 },
4528 ignoreDestinationZoom: {
4529 value: false,
4530 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4531 },
4532 imageResourcesPath: {
4533 value: "./images/",
4534 kind: OptionKind.VIEWER
4535 },
4536 maxCanvasPixels: {
4537 value: 16777216,
4538 kind: OptionKind.VIEWER
4539 },
4540 forcePageColors: {
4541 value: false,
4542 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4543 },
4544 pageColorsBackground: {
4545 value: "Canvas",
4546 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4547 },
4548 pageColorsForeground: {
4549 value: "CanvasText",
4550 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4551 },
4552 pdfBugEnabled: {
4553 value: false,
4554 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4555 },
4556 printResolution: {
4557 value: 150,
4558 kind: OptionKind.VIEWER
4559 },
4560 sidebarViewOnLoad: {
4561 value: -1,
4562 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4563 },
4564 scrollModeOnLoad: {
4565 value: -1,
4566 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4567 },
4568 spreadModeOnLoad: {
4569 value: -1,
4570 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4571 },
4572 textLayerMode: {
4573 value: 1,
4574 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4575 },
4576 useOnlyCssZoom: {
4577 value: false,
4578 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4579 },
4580 viewerCssTheme: {
4581 value: 0,
4582 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4583 },
4584 viewOnLoad: {
4585 value: 0,
4586 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
4587 },
4588 cMapPacked: {
4589 value: true,
4590 kind: OptionKind.API
4591 },
4592 cMapUrl: {
4593 value: "../web/cmaps/",
4594 kind: OptionKind.API
4595 },
4596 disableAutoFetch: {
4597 value: false,
4598 kind: OptionKind.API + OptionKind.PREFERENCE
4599 },
4600 disableFontFace: {
4601 value: false,
4602 kind: OptionKind.API + OptionKind.PREFERENCE
4603 },
4604 disableRange: {
4605 value: false,
4606 kind: OptionKind.API + OptionKind.PREFERENCE
4607 },
4608 disableStream: {
4609 value: false,
4610 kind: OptionKind.API + OptionKind.PREFERENCE
4611 },
4612 docBaseUrl: {
4613 value: "",
4614 kind: OptionKind.API
4615 },
4616 enableXfa: {
4617 value: true,
4618 kind: OptionKind.API + OptionKind.PREFERENCE
4619 },
4620 fontExtraProperties: {
4621 value: false,
4622 kind: OptionKind.API
4623 },
4624 isEvalSupported: {
4625 value: true,
4626 kind: OptionKind.API
4627 },
4628 isOffscreenCanvasSupported: {
4629 value: true,
4630 kind: OptionKind.API
4631 },
4632 maxImageSize: {
4633 value: -1,
4634 kind: OptionKind.API
4635 },
4636 pdfBug: {
4637 value: false,
4638 kind: OptionKind.API
4639 },
4640 standardFontDataUrl: {
4641 value: "../web/standard_fonts/",
4642 kind: OptionKind.API
4643 },
4644 verbosity: {
4645 value: 1,
4646 kind: OptionKind.API
4647 },
4648 workerPort: {
4649 value: null,
4650 kind: OptionKind.WORKER
4651 },
4652 workerSrc: {
4653 value: "../build/pdf.worker.js",
4654 kind: OptionKind.WORKER
4655 }
4656};
4657{
4658 defaultOptions.defaultUrl = {
4659 value: "compressed.tracemonkey-pldi-09.pdf",
4660 kind: OptionKind.VIEWER
4661 };
4662 defaultOptions.disablePreferences = {
4663 value: false,
4664 kind: OptionKind.VIEWER
4665 };
4666 defaultOptions.locale = {
4667 value: navigator.language || "en-US",
4668 kind: OptionKind.VIEWER
4669 };
4670 defaultOptions.sandboxBundleSrc = {
4671 value: "../build/pdf.sandbox.js",
4672 kind: OptionKind.VIEWER
4673 };
4674}
4675const userOptions = Object.create(null);
4676class AppOptions {
4677 constructor() {
4678 throw new Error("Cannot initialize AppOptions.");
4679 }
4680 static get(name) {
4681 const userOption = userOptions[name];
4682 if (userOption !== undefined) {
4683 return userOption;
4684 }
4685 const defaultOption = defaultOptions[name];
4686 if (defaultOption !== undefined) {
4687 return compatibilityParams[name] ?? defaultOption.value;
4688 }
4689 return undefined;
4690 }
4691 static getAll() {
4692 let kind = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
4693 const options = Object.create(null);
4694 for (const name in defaultOptions) {
4695 const defaultOption = defaultOptions[name];
4696 if (kind) {
4697 if ((kind & defaultOption.kind) === 0) {
4698 continue;
4699 }
4700 if (kind === OptionKind.PREFERENCE) {
4701 const value = defaultOption.value,
4702 valueType = typeof value;
4703 if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
4704 options[name] = value;
4705 continue;
4706 }
4707 throw new Error(`Invalid type for preference: ${name}`);
4708 }
4709 }
4710 const userOption = userOptions[name];
4711 options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
4712 }
4713 return options;
4714 }
4715 static set(name, value) {
4716 userOptions[name] = value;
4717 }
4718 static setAll(options) {
4719 for (const name in options) {
4720 userOptions[name] = options[name];
4721 }
4722 }
4723 static remove(name) {
4724 delete userOptions[name];
4725 }
4726}
4727exports.AppOptions = AppOptions;
4728{
4729 AppOptions._hasUserOptions = function () {
4730 return Object.keys(userOptions).length > 0;
4731 };
4732}
4733
4734/***/ }),
4735/* 16 */
4736/***/ ((__unused_webpack_module, exports) => {
4737
4738
4739
4740Object.defineProperty(exports, "__esModule", ({
4741 value: true
4742}));
4743exports.StructTreeLayerBuilder = void 0;
4744const PDF_ROLE_TO_HTML_ROLE = {
4745 Document: null,
4746 DocumentFragment: null,
4747 Part: "group",
4748 Sect: "group",
4749 Div: "group",
4750 Aside: "note",
4751 NonStruct: "none",
4752 P: null,
4753 H: "heading",
4754 Title: null,
4755 FENote: "note",
4756 Sub: "group",
4757 Lbl: null,
4758 Span: null,
4759 Em: null,
4760 Strong: null,
4761 Link: "link",
4762 Annot: "note",
4763 Form: "form",
4764 Ruby: null,
4765 RB: null,
4766 RT: null,
4767 RP: null,
4768 Warichu: null,
4769 WT: null,
4770 WP: null,
4771 L: "list",
4772 LI: "listitem",
4773 LBody: null,
4774 Table: "table",
4775 TR: "row",
4776 TH: "columnheader",
4777 TD: "cell",
4778 THead: "columnheader",
4779 TBody: null,
4780 TFoot: null,
4781 Caption: null,
4782 Figure: "figure",
4783 Formula: null,
4784 Artifact: null
4785};
4786const HEADING_PATTERN = /^H(\d+)$/;
4787class StructTreeLayerBuilder {
4788 #treeDom = undefined;
4789 get renderingDone() {
4790 return this.#treeDom !== undefined;
4791 }
4792 render(structTree) {
4793 if (this.#treeDom !== undefined) {
4794 return this.#treeDom;
4795 }
4796 const treeDom = this.#walk(structTree);
4797 treeDom === null || treeDom === void 0 ? void 0 : treeDom.classList.add("structTree");
4798 return this.#treeDom = treeDom;
4799 }
4800 hide() {
4801 if (this.#treeDom && !this.#treeDom.hidden) {
4802 this.#treeDom.hidden = true;
4803 }
4804 }
4805 show() {
4806 var _this$treeDom;
4807 if ((_this$treeDom = this.#treeDom) !== null && _this$treeDom !== void 0 && _this$treeDom.hidden) {
4808 this.#treeDom.hidden = false;
4809 }
4810 }
4811 #setAttributes(structElement, htmlElement) {
4812 if (structElement.alt !== undefined) {
4813 htmlElement.setAttribute("aria-label", structElement.alt);
4814 }
4815 if (structElement.id !== undefined) {
4816 htmlElement.setAttribute("aria-owns", structElement.id);
4817 }
4818 if (structElement.lang !== undefined) {
4819 htmlElement.setAttribute("lang", structElement.lang);
4820 }
4821 }
4822 #walk(node) {
4823 if (!node) {
4824 return null;
4825 }
4826 const element = document.createElement("span");
4827 if ("role" in node) {
4828 const {
4829 role
4830 } = node;
4831 const match = role.match(HEADING_PATTERN);
4832 if (match) {
4833 element.setAttribute("role", "heading");
4834 element.setAttribute("aria-level", match[1]);
4835 } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
4836 element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
4837 }
4838 }
4839 this.#setAttributes(node, element);
4840 if (node.children) {
4841 if (node.children.length === 1 && "id" in node.children[0]) {
4842 this.#setAttributes(node.children[0], element);
4843 } else {
4844 for (const kid of node.children) {
4845 element.append(this.#walk(kid));
4846 }
4847 }
4848 }
4849 return element;
4850 }
4851}
4852exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
4853
4854/***/ }),
4855/* 17 */
4856/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
4857
4858
4859
4860Object.defineProperty(exports, "__esModule", ({
4861 value: true
4862}));
4863exports.TextAccessibilityManager = void 0;
4864var _ui_utils = __w_pdfjs_require__(2);
4865class TextAccessibilityManager {
4866 #enabled = false;
4867 #textChildren = null;
4868 #textNodes = new Map();
4869 #waitingElements = new Map();
4870 setTextMapping(textDivs) {
4871 this.#textChildren = textDivs;
4872 }
4873 static #compareElementPositions(e1, e2) {
4874 const rect1 = e1.getBoundingClientRect();
4875 const rect2 = e2.getBoundingClientRect();
4876 if (rect1.width === 0 && rect1.height === 0) {
4877 return +1;
4878 }
4879 if (rect2.width === 0 && rect2.height === 0) {
4880 return -1;
4881 }
4882 const top1 = rect1.y;
4883 const bot1 = rect1.y + rect1.height;
4884 const mid1 = rect1.y + rect1.height / 2;
4885 const top2 = rect2.y;
4886 const bot2 = rect2.y + rect2.height;
4887 const mid2 = rect2.y + rect2.height / 2;
4888 if (mid1 <= top2 && mid2 >= bot1) {
4889 return -1;
4890 }
4891 if (mid2 <= top1 && mid1 >= bot2) {
4892 return +1;
4893 }
4894 const centerX1 = rect1.x + rect1.width / 2;
4895 const centerX2 = rect2.x + rect2.width / 2;
4896 return centerX1 - centerX2;
4897 }
4898 enable() {
4899 if (this.#enabled) {
4900 throw new Error("TextAccessibilityManager is already enabled.");
4901 }
4902 if (!this.#textChildren) {
4903 throw new Error("Text divs and strings have not been set.");
4904 }
4905 this.#enabled = true;
4906 this.#textChildren = this.#textChildren.slice();
4907 this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
4908 if (this.#textNodes.size > 0) {
4909 const textChildren = this.#textChildren;
4910 for (const [id, nodeIndex] of this.#textNodes) {
4911 const element = document.getElementById(id);
4912 if (!element) {
4913 this.#textNodes.delete(id);
4914 continue;
4915 }
4916 this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
4917 }
4918 }
4919 for (const [element, isRemovable] of this.#waitingElements) {
4920 this.addPointerInTextLayer(element, isRemovable);
4921 }
4922 this.#waitingElements.clear();
4923 }
4924 disable() {
4925 if (!this.#enabled) {
4926 return;
4927 }
4928 this.#waitingElements.clear();
4929 this.#textChildren = null;
4930 this.#enabled = false;
4931 }
4932 removePointerInTextLayer(element) {
4933 var _owns;
4934 if (!this.#enabled) {
4935 this.#waitingElements.delete(element);
4936 return;
4937 }
4938 const children = this.#textChildren;
4939 if (!children || children.length === 0) {
4940 return;
4941 }
4942 const {
4943 id
4944 } = element;
4945 const nodeIndex = this.#textNodes.get(id);
4946 if (nodeIndex === undefined) {
4947 return;
4948 }
4949 const node = children[nodeIndex];
4950 this.#textNodes.delete(id);
4951 let owns = node.getAttribute("aria-owns");
4952 if ((_owns = owns) !== null && _owns !== void 0 && _owns.includes(id)) {
4953 owns = owns.split(" ").filter(x => x !== id).join(" ");
4954 if (owns) {
4955 node.setAttribute("aria-owns", owns);
4956 } else {
4957 node.removeAttribute("aria-owns");
4958 node.setAttribute("role", "presentation");
4959 }
4960 }
4961 }
4962 #addIdToAriaOwns(id, node) {
4963 const owns = node.getAttribute("aria-owns");
4964 if (!(owns !== null && owns !== void 0 && owns.includes(id))) {
4965 node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
4966 }
4967 node.removeAttribute("role");
4968 }
4969 addPointerInTextLayer(element, isRemovable) {
4970 const {
4971 id
4972 } = element;
4973 if (!id) {
4974 return;
4975 }
4976 if (!this.#enabled) {
4977 this.#waitingElements.set(element, isRemovable);
4978 return;
4979 }
4980 if (isRemovable) {
4981 this.removePointerInTextLayer(element);
4982 }
4983 const children = this.#textChildren;
4984 if (!children || children.length === 0) {
4985 return;
4986 }
4987 const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
4988 const nodeIndex = Math.max(0, index - 1);
4989 this.#addIdToAriaOwns(id, children[nodeIndex]);
4990 this.#textNodes.set(id, nodeIndex);
4991 }
4992 moveElementInDOM(container, element, contentElement, isRemovable) {
4993 this.addPointerInTextLayer(contentElement, isRemovable);
4994 if (!container.hasChildNodes()) {
4995 container.append(element);
4996 return;
4997 }
4998 const children = Array.from(container.childNodes).filter(node => node !== element);
4999 if (children.length === 0) {
5000 return;
5001 }
5002 const elementToCompare = contentElement || element;
5003 const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
5004 if (index === 0) {
5005 children[0].before(element);
5006 } else {
5007 children[index - 1].after(element);
5008 }
5009 }
5010}
5011exports.TextAccessibilityManager = TextAccessibilityManager;
5012
5013/***/ }),
5014/* 18 */
5015/***/ ((__unused_webpack_module, exports) => {
5016
5017
5018
5019Object.defineProperty(exports, "__esModule", ({
5020 value: true
5021}));
5022exports.TextHighlighter = void 0;
5023class TextHighlighter {
5024 constructor(_ref) {
5025 let {
5026 findController,
5027 eventBus,
5028 pageIndex
5029 } = _ref;
5030 this.findController = findController;
5031 this.matches = [];
5032 this.eventBus = eventBus;
5033 this.pageIdx = pageIndex;
5034 this._onUpdateTextLayerMatches = null;
5035 this.textDivs = null;
5036 this.textContentItemsStr = null;
5037 this.enabled = false;
5038 }
5039 setTextMapping(divs, texts) {
5040 this.textDivs = divs;
5041 this.textContentItemsStr = texts;
5042 }
5043 enable() {
5044 if (!this.textDivs || !this.textContentItemsStr) {
5045 throw new Error("Text divs and strings have not been set.");
5046 }
5047 if (this.enabled) {
5048 throw new Error("TextHighlighter is already enabled.");
5049 }
5050 this.enabled = true;
5051 if (!this._onUpdateTextLayerMatches) {
5052 this._onUpdateTextLayerMatches = evt => {
5053 if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
5054 this._updateMatches();
5055 }
5056 };
5057 this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
5058 }
5059 this._updateMatches();
5060 }
5061 disable() {
5062 if (!this.enabled) {
5063 return;
5064 }
5065 this.enabled = false;
5066 if (this._onUpdateTextLayerMatches) {
5067 this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
5068 this._onUpdateTextLayerMatches = null;
5069 }
5070 this._updateMatches(true);
5071 }
5072 _convertMatches(matches, matchesLength) {
5073 if (!matches) {
5074 return [];
5075 }
5076 const {
5077 textContentItemsStr
5078 } = this;
5079 let i = 0,
5080 iIndex = 0;
5081 const end = textContentItemsStr.length - 1;
5082 const result = [];
5083 for (let m = 0, mm = matches.length; m < mm; m++) {
5084 let matchIdx = matches[m];
5085 while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
5086 iIndex += textContentItemsStr[i].length;
5087 i++;
5088 }
5089 if (i === textContentItemsStr.length) {
5090 console.error("Could not find a matching mapping");
5091 }
5092 const match = {
5093 begin: {
5094 divIdx: i,
5095 offset: matchIdx - iIndex
5096 }
5097 };
5098 matchIdx += matchesLength[m];
5099 while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
5100 iIndex += textContentItemsStr[i].length;
5101 i++;
5102 }
5103 match.end = {
5104 divIdx: i,
5105 offset: matchIdx - iIndex
5106 };
5107 result.push(match);
5108 }
5109 return result;
5110 }
5111 _renderMatches(matches) {
5112 if (matches.length === 0) {
5113 return;
5114 }
5115 const {
5116 findController,
5117 pageIdx
5118 } = this;
5119 const {
5120 textContentItemsStr,
5121 textDivs
5122 } = this;
5123 const isSelectedPage = pageIdx === findController.selected.pageIdx;
5124 const selectedMatchIdx = findController.selected.matchIdx;
5125 const highlightAll = findController.state.highlightAll;
5126 let prevEnd = null;
5127 const infinity = {
5128 divIdx: -1,
5129 offset: undefined
5130 };
5131 function beginText(begin, className) {
5132 const divIdx = begin.divIdx;
5133 textDivs[divIdx].textContent = "";
5134 return appendTextToDiv(divIdx, 0, begin.offset, className);
5135 }
5136 function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
5137 let div = textDivs[divIdx];
5138 if (div.nodeType === Node.TEXT_NODE) {
5139 const span = document.createElement("span");
5140 div.before(span);
5141 span.append(div);
5142 textDivs[divIdx] = span;
5143 div = span;
5144 }
5145 const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
5146 const node = document.createTextNode(content);
5147 if (className) {
5148 const span = document.createElement("span");
5149 span.className = `${className} appended`;
5150 span.append(node);
5151 div.append(span);
5152 return className.includes("selected") ? span.offsetLeft : 0;
5153 }
5154 div.append(node);
5155 return 0;
5156 }
5157 let i0 = selectedMatchIdx,
5158 i1 = i0 + 1;
5159 if (highlightAll) {
5160 i0 = 0;
5161 i1 = matches.length;
5162 } else if (!isSelectedPage) {
5163 return;
5164 }
5165 let lastDivIdx = -1;
5166 let lastOffset = -1;
5167 for (let i = i0; i < i1; i++) {
5168 const match = matches[i];
5169 const begin = match.begin;
5170 if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
5171 continue;
5172 }
5173 lastDivIdx = begin.divIdx;
5174 lastOffset = begin.offset;
5175 const end = match.end;
5176 const isSelected = isSelectedPage && i === selectedMatchIdx;
5177 const highlightSuffix = isSelected ? " selected" : "";
5178 let selectedLeft = 0;
5179 if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
5180 if (prevEnd !== null) {
5181 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
5182 }
5183 beginText(begin);
5184 } else {
5185 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
5186 }
5187 if (begin.divIdx === end.divIdx) {
5188 selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
5189 } else {
5190 selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
5191 for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
5192 textDivs[n0].className = "highlight middle" + highlightSuffix;
5193 }
5194 beginText(end, "highlight end" + highlightSuffix);
5195 }
5196 prevEnd = end;
5197 if (isSelected) {
5198 findController.scrollMatchIntoView({
5199 element: textDivs[begin.divIdx],
5200 selectedLeft,
5201 pageIndex: pageIdx,
5202 matchIndex: selectedMatchIdx
5203 });
5204 }
5205 }
5206 if (prevEnd) {
5207 appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
5208 }
5209 }
5210 _updateMatches() {
5211 let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
5212 if (!this.enabled && !reset) {
5213 return;
5214 }
5215 const {
5216 findController,
5217 matches,
5218 pageIdx
5219 } = this;
5220 const {
5221 textContentItemsStr,
5222 textDivs
5223 } = this;
5224 let clearedUntilDivIdx = -1;
5225 for (const match of matches) {
5226 const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
5227 for (let n = begin, end = match.end.divIdx; n <= end; n++) {
5228 const div = textDivs[n];
5229 div.textContent = textContentItemsStr[n];
5230 div.className = "";
5231 }
5232 clearedUntilDivIdx = match.end.divIdx + 1;
5233 }
5234 if (!(findController !== null && findController !== void 0 && findController.highlightMatches) || reset) {
5235 return;
5236 }
5237 const pageMatches = findController.pageMatches[pageIdx] || null;
5238 const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
5239 this.matches = this._convertMatches(pageMatches, pageMatchesLength);
5240 this._renderMatches(this.matches);
5241 }
5242}
5243exports.TextHighlighter = TextHighlighter;
5244
5245/***/ }),
5246/* 19 */
5247/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5248
5249
5250
5251Object.defineProperty(exports, "__esModule", ({
5252 value: true
5253}));
5254exports.TextLayerBuilder = void 0;
5255var _pdfjsLib = __w_pdfjs_require__(4);
5256var _ui_utils = __w_pdfjs_require__(2);
5257class TextLayerBuilder {
5258 #enablePermissions = false;
5259 #rotation = 0;
5260 #scale = 0;
5261 #textContentSource = null;
5262 constructor(_ref) {
5263 let {
5264 highlighter = null,
5265 accessibilityManager = null,
5266 isOffscreenCanvasSupported = true,
5267 enablePermissions = false
5268 } = _ref;
5269 this.textContentItemsStr = [];
5270 this.renderingDone = false;
5271 this.textDivs = [];
5272 this.textDivProperties = new WeakMap();
5273 this.textLayerRenderTask = null;
5274 this.highlighter = highlighter;
5275 this.accessibilityManager = accessibilityManager;
5276 this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
5277 this.#enablePermissions = enablePermissions === true;
5278 this.div = document.createElement("div");
5279 this.div.className = "textLayer";
5280 this.hide();
5281 }
5282 #finishRendering() {
5283 this.renderingDone = true;
5284 const endOfContent = document.createElement("div");
5285 endOfContent.className = "endOfContent";
5286 this.div.append(endOfContent);
5287 this.#bindMouse();
5288 }
5289 get numTextDivs() {
5290 return this.textDivs.length;
5291 }
5292 async render(viewport) {
5293 var _this$highlighter, _this$accessibilityMa, _this$accessibilityMa2;
5294 if (!this.#textContentSource) {
5295 throw new Error('No "textContentSource" parameter specified.');
5296 }
5297 const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
5298 const {
5299 rotation
5300 } = viewport;
5301 if (this.renderingDone) {
5302 const mustRotate = rotation !== this.#rotation;
5303 const mustRescale = scale !== this.#scale;
5304 if (mustRotate || mustRescale) {
5305 this.hide();
5306 (0, _pdfjsLib.updateTextLayer)({
5307 container: this.div,
5308 viewport,
5309 textDivs: this.textDivs,
5310 textDivProperties: this.textDivProperties,
5311 isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
5312 mustRescale,
5313 mustRotate
5314 });
5315 this.#scale = scale;
5316 this.#rotation = rotation;
5317 }
5318 this.show();
5319 return;
5320 }
5321 this.cancel();
5322 (_this$highlighter = this.highlighter) === null || _this$highlighter === void 0 ? void 0 : _this$highlighter.setTextMapping(this.textDivs, this.textContentItemsStr);
5323 (_this$accessibilityMa = this.accessibilityManager) === null || _this$accessibilityMa === void 0 ? void 0 : _this$accessibilityMa.setTextMapping(this.textDivs);
5324 this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
5325 textContentSource: this.#textContentSource,
5326 container: this.div,
5327 viewport,
5328 textDivs: this.textDivs,
5329 textDivProperties: this.textDivProperties,
5330 textContentItemsStr: this.textContentItemsStr,
5331 isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
5332 });
5333 await this.textLayerRenderTask.promise;
5334 this.#finishRendering();
5335 this.#scale = scale;
5336 this.#rotation = rotation;
5337 this.show();
5338 (_this$accessibilityMa2 = this.accessibilityManager) === null || _this$accessibilityMa2 === void 0 ? void 0 : _this$accessibilityMa2.enable();
5339 }
5340 hide() {
5341 if (!this.div.hidden) {
5342 var _this$highlighter2;
5343 (_this$highlighter2 = this.highlighter) === null || _this$highlighter2 === void 0 ? void 0 : _this$highlighter2.disable();
5344 this.div.hidden = true;
5345 }
5346 }
5347 show() {
5348 if (this.div.hidden && this.renderingDone) {
5349 var _this$highlighter3;
5350 this.div.hidden = false;
5351 (_this$highlighter3 = this.highlighter) === null || _this$highlighter3 === void 0 ? void 0 : _this$highlighter3.enable();
5352 }
5353 }
5354 cancel() {
5355 var _this$highlighter4, _this$accessibilityMa3;
5356 if (this.textLayerRenderTask) {
5357 this.textLayerRenderTask.cancel();
5358 this.textLayerRenderTask = null;
5359 }
5360 (_this$highlighter4 = this.highlighter) === null || _this$highlighter4 === void 0 ? void 0 : _this$highlighter4.disable();
5361 (_this$accessibilityMa3 = this.accessibilityManager) === null || _this$accessibilityMa3 === void 0 ? void 0 : _this$accessibilityMa3.disable();
5362 this.textContentItemsStr.length = 0;
5363 this.textDivs.length = 0;
5364 this.textDivProperties = new WeakMap();
5365 }
5366 setTextContentSource(source) {
5367 this.cancel();
5368 this.#textContentSource = source;
5369 }
5370 #bindMouse() {
5371 const {
5372 div
5373 } = this;
5374 div.addEventListener("mousedown", evt => {
5375 const end = div.querySelector(".endOfContent");
5376 if (!end) {
5377 return;
5378 }
5379 let adjustTop = evt.target !== div;
5380 adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
5381 if (adjustTop) {
5382 const divBounds = div.getBoundingClientRect();
5383 const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
5384 end.style.top = (r * 100).toFixed(2) + "%";
5385 }
5386 end.classList.add("active");
5387 });
5388 div.addEventListener("mouseup", () => {
5389 const end = div.querySelector(".endOfContent");
5390 if (!end) {
5391 return;
5392 }
5393 end.style.top = "";
5394 end.classList.remove("active");
5395 });
5396 div.addEventListener("copy", event => {
5397 if (!this.#enablePermissions) {
5398 const selection = document.getSelection();
5399 event.clipboardData.setData("text/plain", (0, _ui_utils.removeNullCharacters)((0, _pdfjsLib.normalizeUnicode)(selection.toString())));
5400 }
5401 event.preventDefault();
5402 event.stopPropagation();
5403 });
5404 }
5405}
5406exports.TextLayerBuilder = TextLayerBuilder;
5407
5408/***/ }),
5409/* 20 */
5410/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5411
5412
5413
5414Object.defineProperty(exports, "__esModule", ({
5415 value: true
5416}));
5417exports.XfaLayerBuilder = void 0;
5418var _pdfjsLib = __w_pdfjs_require__(4);
5419class XfaLayerBuilder {
5420 constructor(_ref) {
5421 let {
5422 pageDiv,
5423 pdfPage,
5424 annotationStorage = null,
5425 linkService,
5426 xfaHtml = null
5427 } = _ref;
5428 this.pageDiv = pageDiv;
5429 this.pdfPage = pdfPage;
5430 this.annotationStorage = annotationStorage;
5431 this.linkService = linkService;
5432 this.xfaHtml = xfaHtml;
5433 this.div = null;
5434 this._cancelled = false;
5435 }
5436 async render(viewport) {
5437 let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
5438 if (intent === "print") {
5439 const parameters = {
5440 viewport: viewport.clone({
5441 dontFlip: true
5442 }),
5443 div: this.div,
5444 xfaHtml: this.xfaHtml,
5445 annotationStorage: this.annotationStorage,
5446 linkService: this.linkService,
5447 intent
5448 };
5449 const div = document.createElement("div");
5450 this.pageDiv.append(div);
5451 parameters.div = div;
5452 return _pdfjsLib.XfaLayer.render(parameters);
5453 }
5454 const xfaHtml = await this.pdfPage.getXfa();
5455 if (this._cancelled || !xfaHtml) {
5456 return {
5457 textDivs: []
5458 };
5459 }
5460 const parameters = {
5461 viewport: viewport.clone({
5462 dontFlip: true
5463 }),
5464 div: this.div,
5465 xfaHtml,
5466 annotationStorage: this.annotationStorage,
5467 linkService: this.linkService,
5468 intent
5469 };
5470 if (this.div) {
5471 return _pdfjsLib.XfaLayer.update(parameters);
5472 }
5473 this.div = document.createElement("div");
5474 this.pageDiv.append(this.div);
5475 parameters.div = this.div;
5476 return _pdfjsLib.XfaLayer.render(parameters);
5477 }
5478 cancel() {
5479 this._cancelled = true;
5480 }
5481 hide() {
5482 if (!this.div) {
5483 return;
5484 }
5485 this.div.hidden = true;
5486 }
5487}
5488exports.XfaLayerBuilder = XfaLayerBuilder;
5489
5490/***/ }),
5491/* 21 */
5492/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5493
5494
5495
5496Object.defineProperty(exports, "__esModule", ({
5497 value: true
5498}));
5499exports.PDFScriptingManager = void 0;
5500var _ui_utils = __w_pdfjs_require__(2);
5501var _pdfjsLib = __w_pdfjs_require__(4);
5502class PDFScriptingManager {
5503 constructor(_ref) {
5504 let {
5505 eventBus,
5506 sandboxBundleSrc = null,
5507 scriptingFactory = null,
5508 docPropertiesLookup = null
5509 } = _ref;
5510 this._pdfDocument = null;
5511 this._pdfViewer = null;
5512 this._closeCapability = null;
5513 this._destroyCapability = null;
5514 this._scripting = null;
5515 this._ready = false;
5516 this._eventBus = eventBus;
5517 this._sandboxBundleSrc = sandboxBundleSrc;
5518 this._scriptingFactory = scriptingFactory;
5519 this._docPropertiesLookup = docPropertiesLookup;
5520 if (!this._scriptingFactory) {
5521 window.addEventListener("updatefromsandbox", event => {
5522 this._eventBus.dispatch("updatefromsandbox", {
5523 source: window,
5524 detail: event.detail
5525 });
5526 });
5527 }
5528 }
5529 setViewer(pdfViewer) {
5530 this._pdfViewer = pdfViewer;
5531 }
5532 async setDocument(pdfDocument) {
5533 var _this$_scripting3;
5534 if (this._pdfDocument) {
5535 await this._destroyScripting();
5536 }
5537 this._pdfDocument = pdfDocument;
5538 if (!pdfDocument) {
5539 return;
5540 }
5541 const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
5542 if (!objects && !docActions) {
5543 await this._destroyScripting();
5544 return;
5545 }
5546 if (pdfDocument !== this._pdfDocument) {
5547 return;
5548 }
5549 try {
5550 this._scripting = this._createScripting();
5551 } catch (error) {
5552 console.error(`PDFScriptingManager.setDocument: "${error === null || error === void 0 ? void 0 : error.message}".`);
5553 await this._destroyScripting();
5554 return;
5555 }
5556 this._internalEvents.set("updatefromsandbox", event => {
5557 if ((event === null || event === void 0 ? void 0 : event.source) !== window) {
5558 return;
5559 }
5560 this._updateFromSandbox(event.detail);
5561 });
5562 this._internalEvents.set("dispatcheventinsandbox", event => {
5563 var _this$_scripting;
5564 (_this$_scripting = this._scripting) === null || _this$_scripting === void 0 ? void 0 : _this$_scripting.dispatchEventInSandbox(event.detail);
5565 });
5566 this._internalEvents.set("pagechanging", _ref2 => {
5567 let {
5568 pageNumber,
5569 previous
5570 } = _ref2;
5571 if (pageNumber === previous) {
5572 return;
5573 }
5574 this._dispatchPageClose(previous);
5575 this._dispatchPageOpen(pageNumber);
5576 });
5577 this._internalEvents.set("pagerendered", _ref3 => {
5578 let {
5579 pageNumber
5580 } = _ref3;
5581 if (!this._pageOpenPending.has(pageNumber)) {
5582 return;
5583 }
5584 if (pageNumber !== this._pdfViewer.currentPageNumber) {
5585 return;
5586 }
5587 this._dispatchPageOpen(pageNumber);
5588 });
5589 this._internalEvents.set("pagesdestroy", async event => {
5590 var _this$_scripting2, _this$_closeCapabilit;
5591 await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
5592 await ((_this$_scripting2 = this._scripting) === null || _this$_scripting2 === void 0 ? void 0 : _this$_scripting2.dispatchEventInSandbox({
5593 id: "doc",
5594 name: "WillClose"
5595 }));
5596 (_this$_closeCapabilit = this._closeCapability) === null || _this$_closeCapabilit === void 0 ? void 0 : _this$_closeCapabilit.resolve();
5597 });
5598 for (const [name, listener] of this._internalEvents) {
5599 this._eventBus._on(name, listener);
5600 }
5601 try {
5602 const docProperties = await this._getDocProperties();
5603 if (pdfDocument !== this._pdfDocument) {
5604 return;
5605 }
5606 await this._scripting.createSandbox({
5607 objects,
5608 calculationOrder,
5609 appInfo: {
5610 platform: navigator.platform,
5611 language: navigator.language
5612 },
5613 docInfo: {
5614 ...docProperties,
5615 actions: docActions
5616 }
5617 });
5618 this._eventBus.dispatch("sandboxcreated", {
5619 source: this
5620 });
5621 } catch (error) {
5622 console.error(`PDFScriptingManager.setDocument: "${error === null || error === void 0 ? void 0 : error.message}".`);
5623 await this._destroyScripting();
5624 return;
5625 }
5626 await ((_this$_scripting3 = this._scripting) === null || _this$_scripting3 === void 0 ? void 0 : _this$_scripting3.dispatchEventInSandbox({
5627 id: "doc",
5628 name: "Open"
5629 }));
5630 await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
5631 Promise.resolve().then(() => {
5632 if (pdfDocument === this._pdfDocument) {
5633 this._ready = true;
5634 }
5635 });
5636 }
5637 async dispatchWillSave(detail) {
5638 var _this$_scripting4;
5639 return (_this$_scripting4 = this._scripting) === null || _this$_scripting4 === void 0 ? void 0 : _this$_scripting4.dispatchEventInSandbox({
5640 id: "doc",
5641 name: "WillSave"
5642 });
5643 }
5644 async dispatchDidSave(detail) {
5645 var _this$_scripting5;
5646 return (_this$_scripting5 = this._scripting) === null || _this$_scripting5 === void 0 ? void 0 : _this$_scripting5.dispatchEventInSandbox({
5647 id: "doc",
5648 name: "DidSave"
5649 });
5650 }
5651 async dispatchWillPrint(detail) {
5652 var _this$_scripting6;
5653 return (_this$_scripting6 = this._scripting) === null || _this$_scripting6 === void 0 ? void 0 : _this$_scripting6.dispatchEventInSandbox({
5654 id: "doc",
5655 name: "WillPrint"
5656 });
5657 }
5658 async dispatchDidPrint(detail) {
5659 var _this$_scripting7;
5660 return (_this$_scripting7 = this._scripting) === null || _this$_scripting7 === void 0 ? void 0 : _this$_scripting7.dispatchEventInSandbox({
5661 id: "doc",
5662 name: "DidPrint"
5663 });
5664 }
5665 get destroyPromise() {
5666 var _this$_destroyCapabil;
5667 return ((_this$_destroyCapabil = this._destroyCapability) === null || _this$_destroyCapabil === void 0 ? void 0 : _this$_destroyCapabil.promise) || null;
5668 }
5669 get ready() {
5670 return this._ready;
5671 }
5672 get _internalEvents() {
5673 return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
5674 }
5675 get _pageOpenPending() {
5676 return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
5677 }
5678 get _visitedPages() {
5679 return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
5680 }
5681 async _updateFromSandbox(detail) {
5682 const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
5683 const {
5684 id,
5685 siblings,
5686 command,
5687 value
5688 } = detail;
5689 if (!id) {
5690 switch (command) {
5691 case "clear":
5692 console.clear();
5693 break;
5694 case "error":
5695 console.error(value);
5696 break;
5697 case "layout":
5698 {
5699 if (isInPresentationMode) {
5700 return;
5701 }
5702 const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
5703 this._pdfViewer.spreadMode = modes.spreadMode;
5704 break;
5705 }
5706 case "page-num":
5707 this._pdfViewer.currentPageNumber = value + 1;
5708 break;
5709 case "print":
5710 await this._pdfViewer.pagesPromise;
5711 this._eventBus.dispatch("print", {
5712 source: this
5713 });
5714 break;
5715 case "println":
5716 console.log(value);
5717 break;
5718 case "zoom":
5719 if (isInPresentationMode) {
5720 return;
5721 }
5722 this._pdfViewer.currentScaleValue = value;
5723 break;
5724 case "SaveAs":
5725 this._eventBus.dispatch("download", {
5726 source: this
5727 });
5728 break;
5729 case "FirstPage":
5730 this._pdfViewer.currentPageNumber = 1;
5731 break;
5732 case "LastPage":
5733 this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
5734 break;
5735 case "NextPage":
5736 this._pdfViewer.nextPage();
5737 break;
5738 case "PrevPage":
5739 this._pdfViewer.previousPage();
5740 break;
5741 case "ZoomViewIn":
5742 if (isInPresentationMode) {
5743 return;
5744 }
5745 this._pdfViewer.increaseScale();
5746 break;
5747 case "ZoomViewOut":
5748 if (isInPresentationMode) {
5749 return;
5750 }
5751 this._pdfViewer.decreaseScale();
5752 break;
5753 }
5754 return;
5755 }
5756 if (isInPresentationMode) {
5757 if (detail.focus) {
5758 return;
5759 }
5760 }
5761 delete detail.id;
5762 delete detail.siblings;
5763 const ids = siblings ? [id, ...siblings] : [id];
5764 for (const elementId of ids) {
5765 const element = document.querySelector(`[data-element-id="${elementId}"]`);
5766 if (element) {
5767 element.dispatchEvent(new CustomEvent("updatefromsandbox", {
5768 detail
5769 }));
5770 } else {
5771 var _this$_pdfDocument;
5772 (_this$_pdfDocument = this._pdfDocument) === null || _this$_pdfDocument === void 0 ? void 0 : _this$_pdfDocument.annotationStorage.setValue(elementId, detail);
5773 }
5774 }
5775 }
5776 async _dispatchPageOpen(pageNumber) {
5777 let initialize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5778 const pdfDocument = this._pdfDocument,
5779 visitedPages = this._visitedPages;
5780 if (initialize) {
5781 this._closeCapability = new _pdfjsLib.PromiseCapability();
5782 }
5783 if (!this._closeCapability) {
5784 return;
5785 }
5786 const pageView = this._pdfViewer.getPageView(pageNumber - 1);
5787 if ((pageView === null || pageView === void 0 ? void 0 : pageView.renderingState) !== _ui_utils.RenderingStates.FINISHED) {
5788 this._pageOpenPending.add(pageNumber);
5789 return;
5790 }
5791 this._pageOpenPending.delete(pageNumber);
5792 const actionsPromise = (async () => {
5793 var _pageView$pdfPage, _this$_scripting8;
5794 const actions = await (!visitedPages.has(pageNumber) ? (_pageView$pdfPage = pageView.pdfPage) === null || _pageView$pdfPage === void 0 ? void 0 : _pageView$pdfPage.getJSActions() : null);
5795 if (pdfDocument !== this._pdfDocument) {
5796 return;
5797 }
5798 await ((_this$_scripting8 = this._scripting) === null || _this$_scripting8 === void 0 ? void 0 : _this$_scripting8.dispatchEventInSandbox({
5799 id: "page",
5800 name: "PageOpen",
5801 pageNumber,
5802 actions
5803 }));
5804 })();
5805 visitedPages.set(pageNumber, actionsPromise);
5806 }
5807 async _dispatchPageClose(pageNumber) {
5808 var _this$_scripting9;
5809 const pdfDocument = this._pdfDocument,
5810 visitedPages = this._visitedPages;
5811 if (!this._closeCapability) {
5812 return;
5813 }
5814 if (this._pageOpenPending.has(pageNumber)) {
5815 return;
5816 }
5817 const actionsPromise = visitedPages.get(pageNumber);
5818 if (!actionsPromise) {
5819 return;
5820 }
5821 visitedPages.set(pageNumber, null);
5822 await actionsPromise;
5823 if (pdfDocument !== this._pdfDocument) {
5824 return;
5825 }
5826 await ((_this$_scripting9 = this._scripting) === null || _this$_scripting9 === void 0 ? void 0 : _this$_scripting9.dispatchEventInSandbox({
5827 id: "page",
5828 name: "PageClose",
5829 pageNumber
5830 }));
5831 }
5832 async _getDocProperties() {
5833 if (this._docPropertiesLookup) {
5834 return this._docPropertiesLookup(this._pdfDocument);
5835 }
5836 const {
5837 docPropertiesLookup
5838 } = __w_pdfjs_require__(22);
5839 return docPropertiesLookup(this._pdfDocument);
5840 }
5841 _createScripting() {
5842 this._destroyCapability = new _pdfjsLib.PromiseCapability();
5843 if (this._scripting) {
5844 throw new Error("_createScripting: Scripting already exists.");
5845 }
5846 if (this._scriptingFactory) {
5847 return this._scriptingFactory.createScripting({
5848 sandboxBundleSrc: this._sandboxBundleSrc
5849 });
5850 }
5851 const {
5852 GenericScripting
5853 } = __w_pdfjs_require__(22);
5854 return new GenericScripting(this._sandboxBundleSrc);
5855 }
5856 async _destroyScripting() {
5857 var _this$_destroyCapabil3;
5858 if (!this._scripting) {
5859 var _this$_destroyCapabil2;
5860 this._pdfDocument = null;
5861 (_this$_destroyCapabil2 = this._destroyCapability) === null || _this$_destroyCapabil2 === void 0 ? void 0 : _this$_destroyCapabil2.resolve();
5862 return;
5863 }
5864 if (this._closeCapability) {
5865 await Promise.race([this._closeCapability.promise, new Promise(resolve => {
5866 setTimeout(resolve, 1000);
5867 })]).catch(reason => {});
5868 this._closeCapability = null;
5869 }
5870 this._pdfDocument = null;
5871 try {
5872 await this._scripting.destroySandbox();
5873 } catch (ex) {}
5874 for (const [name, listener] of this._internalEvents) {
5875 this._eventBus._off(name, listener);
5876 }
5877 this._internalEvents.clear();
5878 this._pageOpenPending.clear();
5879 this._visitedPages.clear();
5880 this._scripting = null;
5881 this._ready = false;
5882 (_this$_destroyCapabil3 = this._destroyCapability) === null || _this$_destroyCapabil3 === void 0 ? void 0 : _this$_destroyCapabil3.resolve();
5883 }
5884}
5885exports.PDFScriptingManager = PDFScriptingManager;
5886
5887/***/ }),
5888/* 22 */
5889/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5890
5891
5892
5893Object.defineProperty(exports, "__esModule", ({
5894 value: true
5895}));
5896exports.GenericScripting = void 0;
5897exports.docPropertiesLookup = docPropertiesLookup;
5898var _pdfjsLib = __w_pdfjs_require__(4);
5899async function docPropertiesLookup(pdfDocument) {
5900 const url = "",
5901 baseUrl = url.split("#")[0];
5902 let {
5903 info,
5904 metadata,
5905 contentDispositionFilename,
5906 contentLength
5907 } = await pdfDocument.getMetadata();
5908 if (!contentLength) {
5909 const {
5910 length
5911 } = await pdfDocument.getDownloadInfo();
5912 contentLength = length;
5913 }
5914 return {
5915 ...info,
5916 baseURL: baseUrl,
5917 filesize: contentLength,
5918 filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
5919 metadata: metadata === null || metadata === void 0 ? void 0 : metadata.getRaw(),
5920 authors: metadata === null || metadata === void 0 ? void 0 : metadata.get("dc:creator"),
5921 numPages: pdfDocument.numPages,
5922 URL: url
5923 };
5924}
5925class GenericScripting {
5926 constructor(sandboxBundleSrc) {
5927 this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
5928 return window.pdfjsSandbox.QuickJSSandbox();
5929 });
5930 }
5931 async createSandbox(data) {
5932 const sandbox = await this._ready;
5933 sandbox.create(data);
5934 }
5935 async dispatchEventInSandbox(event) {
5936 const sandbox = await this._ready;
5937 setTimeout(() => sandbox.dispatchEvent(event), 0);
5938 }
5939 async destroySandbox() {
5940 const sandbox = await this._ready;
5941 sandbox.nukeSandbox();
5942 }
5943}
5944exports.GenericScripting = GenericScripting;
5945
5946/***/ }),
5947/* 23 */
5948/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5949
5950
5951
5952Object.defineProperty(exports, "__esModule", ({
5953 value: true
5954}));
5955exports.PDFSinglePageViewer = void 0;
5956var _ui_utils = __w_pdfjs_require__(2);
5957var _pdf_viewer = __w_pdfjs_require__(24);
5958class PDFSinglePageViewer extends _pdf_viewer.PDFViewer {
5959 _resetView() {
5960 super._resetView();
5961 this._scrollMode = _ui_utils.ScrollMode.PAGE;
5962 this._spreadMode = _ui_utils.SpreadMode.NONE;
5963 }
5964 set scrollMode(mode) {}
5965 _updateScrollMode() {}
5966 set spreadMode(mode) {}
5967 _updateSpreadMode() {}
5968}
5969exports.PDFSinglePageViewer = PDFSinglePageViewer;
5970
5971/***/ }),
5972/* 24 */
5973/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
5974
5975
5976
5977Object.defineProperty(exports, "__esModule", ({
5978 value: true
5979}));
5980exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
5981var _pdfjsLib = __w_pdfjs_require__(4);
5982var _ui_utils = __w_pdfjs_require__(2);
5983var _l10n_utils = __w_pdfjs_require__(5);
5984var _pdf_page_view = __w_pdfjs_require__(13);
5985var _pdf_rendering_queue = __w_pdfjs_require__(25);
5986var _pdf_link_service = __w_pdfjs_require__(1);
5987const DEFAULT_CACHE_SIZE = 10;
5988const PagesCountLimit = {
5989 FORCE_SCROLL_MODE_PAGE: 15000,
5990 FORCE_LAZY_PAGE_INIT: 7500,
5991 PAUSE_EAGER_PAGE_INIT: 250
5992};
5993exports.PagesCountLimit = PagesCountLimit;
5994function isValidAnnotationEditorMode(mode) {
5995 return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
5996}
5997class PDFPageViewBuffer {
5998 #buf = new Set();
5999 #size = 0;
6000 constructor(size) {
6001 this.#size = size;
6002 }
6003 push(view) {
6004 const buf = this.#buf;
6005 if (buf.has(view)) {
6006 buf.delete(view);
6007 }
6008 buf.add(view);
6009 if (buf.size > this.#size) {
6010 this.#destroyFirstView();
6011 }
6012 }
6013 resize(newSize) {
6014 let idsToKeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
6015 this.#size = newSize;
6016 const buf = this.#buf;
6017 if (idsToKeep) {
6018 const ii = buf.size;
6019 let i = 1;
6020 for (const view of buf) {
6021 if (idsToKeep.has(view.id)) {
6022 buf.delete(view);
6023 buf.add(view);
6024 }
6025 if (++i > ii) {
6026 break;
6027 }
6028 }
6029 }
6030 while (buf.size > this.#size) {
6031 this.#destroyFirstView();
6032 }
6033 }
6034 has(view) {
6035 return this.#buf.has(view);
6036 }
6037 [Symbol.iterator]() {
6038 return this.#buf.keys();
6039 }
6040 #destroyFirstView() {
6041 const firstView = this.#buf.keys().next().value;
6042 firstView === null || firstView === void 0 ? void 0 : firstView.destroy();
6043 this.#buf.delete(firstView);
6044 }
6045}
6046exports.PDFPageViewBuffer = PDFPageViewBuffer;
6047class PDFViewer {
6048 #buffer = null;
6049 #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
6050 #annotationEditorUIManager = null;
6051 #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
6052 #containerTopLeft = null;
6053 #copyCallbackBound = null;
6054 #enablePermissions = false;
6055 #getAllTextInProgress = false;
6056 #hiddenCopyElement = null;
6057 #interruptCopyCondition = false;
6058 #previousContainerHeight = 0;
6059 #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
6060 #scrollModePageState = null;
6061 #onVisibilityChange = null;
6062 #scaleTimeoutId = null;
6063 #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
6064 constructor(options) {
6065 var _this$container, _this$viewer;
6066 const viewerVersion = '3.7.107';
6067 if (_pdfjsLib.version !== viewerVersion) {
6068 throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
6069 }
6070 this.container = options.container;
6071 this.viewer = options.viewer || options.container.firstElementChild;
6072 if (((_this$container = this.container) === null || _this$container === void 0 ? void 0 : _this$container.tagName) !== "DIV" || ((_this$viewer = this.viewer) === null || _this$viewer === void 0 ? void 0 : _this$viewer.tagName) !== "DIV") {
6073 throw new Error("Invalid `container` and/or `viewer` option.");
6074 }
6075 if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
6076 throw new Error("The `container` must be absolutely positioned.");
6077 }
6078 this.#resizeObserver.observe(this.container);
6079 this.eventBus = options.eventBus;
6080 this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
6081 this.downloadManager = options.downloadManager || null;
6082 this.findController = options.findController || null;
6083 if (this.findController) {
6084 this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
6085 }
6086 this._scriptingManager = options.scriptingManager || null;
6087 this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
6088 this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
6089 this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
6090 this.imageResourcesPath = options.imageResourcesPath || "";
6091 this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
6092 this.removePageBorders = options.removePageBorders || false;
6093 this.useOnlyCssZoom = options.useOnlyCssZoom || false;
6094 this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
6095 this.maxCanvasPixels = options.maxCanvasPixels;
6096 this.l10n = options.l10n || _l10n_utils.NullL10n;
6097 this.#enablePermissions = options.enablePermissions || false;
6098 this.pageColors = options.pageColors || null;
6099 if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
6100 if (this.pageColors.background || this.pageColors.foreground) {
6101 console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
6102 }
6103 this.pageColors = null;
6104 }
6105 this.defaultRenderingQueue = !options.renderingQueue;
6106 if (this.defaultRenderingQueue) {
6107 this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
6108 this.renderingQueue.setViewer(this);
6109 } else {
6110 this.renderingQueue = options.renderingQueue;
6111 }
6112 this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
6113 this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
6114 this._onBeforeDraw = this._onAfterDraw = null;
6115 this._resetView();
6116 if (this.removePageBorders) {
6117 this.viewer.classList.add("removePageBorders");
6118 }
6119 this.#updateContainerHeightCss();
6120 this.eventBus._on("thumbnailrendered", _ref => {
6121 let {
6122 pageNumber,
6123 pdfPage
6124 } = _ref;
6125 const pageView = this._pages[pageNumber - 1];
6126 if (!this.#buffer.has(pageView)) {
6127 pdfPage === null || pdfPage === void 0 ? void 0 : pdfPage.cleanup();
6128 }
6129 });
6130 }
6131 get pagesCount() {
6132 return this._pages.length;
6133 }
6134 getPageView(index) {
6135 return this._pages[index];
6136 }
6137 getCachedPageViews() {
6138 return new Set(this.#buffer);
6139 }
6140 get pageViewsReady() {
6141 return this._pagesCapability.settled && this._pages.every(pageView => pageView === null || pageView === void 0 ? void 0 : pageView.pdfPage);
6142 }
6143 get renderForms() {
6144 return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
6145 }
6146 get enableScripting() {
6147 return !!this._scriptingManager;
6148 }
6149 get currentPageNumber() {
6150 return this._currentPageNumber;
6151 }
6152 set currentPageNumber(val) {
6153 if (!Number.isInteger(val)) {
6154 throw new Error("Invalid page number.");
6155 }
6156 if (!this.pdfDocument) {
6157 return;
6158 }
6159 if (!this._setCurrentPageNumber(val, true)) {
6160 console.error(`currentPageNumber: "${val}" is not a valid page.`);
6161 }
6162 }
6163 _setCurrentPageNumber(val) {
6164 var _this$_pageLabels;
6165 let resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6166 if (this._currentPageNumber === val) {
6167 if (resetCurrentPageView) {
6168 this.#resetCurrentPageView();
6169 }
6170 return true;
6171 }
6172 if (!(0 < val && val <= this.pagesCount)) {
6173 return false;
6174 }
6175 const previous = this._currentPageNumber;
6176 this._currentPageNumber = val;
6177 this.eventBus.dispatch("pagechanging", {
6178 source: this,
6179 pageNumber: val,
6180 pageLabel: ((_this$_pageLabels = this._pageLabels) === null || _this$_pageLabels === void 0 ? void 0 : _this$_pageLabels[val - 1]) ?? null,
6181 previous
6182 });
6183 if (resetCurrentPageView) {
6184 this.#resetCurrentPageView();
6185 }
6186 return true;
6187 }
6188 get currentPageLabel() {
6189 var _this$_pageLabels2;
6190 return ((_this$_pageLabels2 = this._pageLabels) === null || _this$_pageLabels2 === void 0 ? void 0 : _this$_pageLabels2[this._currentPageNumber - 1]) ?? null;
6191 }
6192 set currentPageLabel(val) {
6193 if (!this.pdfDocument) {
6194 return;
6195 }
6196 let page = val | 0;
6197 if (this._pageLabels) {
6198 const i = this._pageLabels.indexOf(val);
6199 if (i >= 0) {
6200 page = i + 1;
6201 }
6202 }
6203 if (!this._setCurrentPageNumber(page, true)) {
6204 console.error(`currentPageLabel: "${val}" is not a valid page.`);
6205 }
6206 }
6207 get currentScale() {
6208 return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
6209 }
6210 set currentScale(val) {
6211 if (isNaN(val)) {
6212 throw new Error("Invalid numeric scale.");
6213 }
6214 if (!this.pdfDocument) {
6215 return;
6216 }
6217 this.#setScale(val, {
6218 noScroll: false
6219 });
6220 }
6221 get currentScaleValue() {
6222 return this._currentScaleValue;
6223 }
6224 set currentScaleValue(val) {
6225 if (!this.pdfDocument) {
6226 return;
6227 }
6228 this.#setScale(val, {
6229 noScroll: false
6230 });
6231 }
6232 get pagesRotation() {
6233 return this._pagesRotation;
6234 }
6235 set pagesRotation(rotation) {
6236 if (!(0, _ui_utils.isValidRotation)(rotation)) {
6237 throw new Error("Invalid pages rotation angle.");
6238 }
6239 if (!this.pdfDocument) {
6240 return;
6241 }
6242 rotation %= 360;
6243 if (rotation < 0) {
6244 rotation += 360;
6245 }
6246 if (this._pagesRotation === rotation) {
6247 return;
6248 }
6249 this._pagesRotation = rotation;
6250 const pageNumber = this._currentPageNumber;
6251 this.refresh(true, {
6252 rotation
6253 });
6254 if (this._currentScaleValue) {
6255 this.#setScale(this._currentScaleValue, {
6256 noScroll: true
6257 });
6258 }
6259 this.eventBus.dispatch("rotationchanging", {
6260 source: this,
6261 pagesRotation: rotation,
6262 pageNumber
6263 });
6264 if (this.defaultRenderingQueue) {
6265 this.update();
6266 }
6267 }
6268 get firstPagePromise() {
6269 return this.pdfDocument ? this._firstPageCapability.promise : null;
6270 }
6271 get onePageRendered() {
6272 return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
6273 }
6274 get pagesPromise() {
6275 return this.pdfDocument ? this._pagesCapability.promise : null;
6276 }
6277 #layerProperties() {
6278 const self = this;
6279 return {
6280 get annotationEditorUIManager() {
6281 return self.#annotationEditorUIManager;
6282 },
6283 get annotationStorage() {
6284 var _self$pdfDocument;
6285 return (_self$pdfDocument = self.pdfDocument) === null || _self$pdfDocument === void 0 ? void 0 : _self$pdfDocument.annotationStorage;
6286 },
6287 get downloadManager() {
6288 return self.downloadManager;
6289 },
6290 get enableScripting() {
6291 return !!self._scriptingManager;
6292 },
6293 get fieldObjectsPromise() {
6294 var _self$pdfDocument2;
6295 return (_self$pdfDocument2 = self.pdfDocument) === null || _self$pdfDocument2 === void 0 ? void 0 : _self$pdfDocument2.getFieldObjects();
6296 },
6297 get findController() {
6298 return self.findController;
6299 },
6300 get hasJSActionsPromise() {
6301 var _self$pdfDocument3;
6302 return (_self$pdfDocument3 = self.pdfDocument) === null || _self$pdfDocument3 === void 0 ? void 0 : _self$pdfDocument3.hasJSActions();
6303 },
6304 get linkService() {
6305 return self.linkService;
6306 }
6307 };
6308 }
6309 #initializePermissions(permissions) {
6310 const params = {
6311 annotationEditorMode: this.#annotationEditorMode,
6312 annotationMode: this.#annotationMode,
6313 textLayerMode: this.#textLayerMode
6314 };
6315 if (!permissions) {
6316 return params;
6317 }
6318 if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY) && this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE) {
6319 params.textLayerMode = _ui_utils.TextLayerMode.ENABLE_PERMISSIONS;
6320 }
6321 if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
6322 params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
6323 }
6324 if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
6325 params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
6326 }
6327 return params;
6328 }
6329 #onePageRenderedOrForceFetch() {
6330 if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
6331 return Promise.resolve();
6332 }
6333 const visibilityChangePromise = new Promise(resolve => {
6334 this.#onVisibilityChange = () => {
6335 if (document.visibilityState !== "hidden") {
6336 return;
6337 }
6338 resolve();
6339 document.removeEventListener("visibilitychange", this.#onVisibilityChange);
6340 this.#onVisibilityChange = null;
6341 };
6342 document.addEventListener("visibilitychange", this.#onVisibilityChange);
6343 });
6344 return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
6345 }
6346 async getAllText() {
6347 const texts = [];
6348 const buffer = [];
6349 for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
6350 if (this.#interruptCopyCondition) {
6351 return null;
6352 }
6353 buffer.length = 0;
6354 const page = await this.pdfDocument.getPage(pageNum);
6355 const {
6356 items
6357 } = await page.getTextContent();
6358 for (const item of items) {
6359 if (item.str) {
6360 buffer.push(item.str);
6361 }
6362 if (item.hasEOL) {
6363 buffer.push("\n");
6364 }
6365 }
6366 texts.push((0, _ui_utils.removeNullCharacters)(buffer.join("")));
6367 }
6368 return texts.join("\n");
6369 }
6370 #copyCallback(textLayerMode, event) {
6371 const selection = document.getSelection();
6372 const {
6373 focusNode,
6374 anchorNode
6375 } = selection;
6376 if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
6377 if (this.#getAllTextInProgress || textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS) {
6378 event.preventDefault();
6379 event.stopPropagation();
6380 return;
6381 }
6382 this.#getAllTextInProgress = true;
6383 const savedCursor = this.container.style.cursor;
6384 this.container.style.cursor = "wait";
6385 const interruptCopy = ev => this.#interruptCopyCondition = ev.key === "Escape";
6386 window.addEventListener("keydown", interruptCopy);
6387 this.getAllText().then(async text => {
6388 if (text !== null) {
6389 await navigator.clipboard.writeText(text);
6390 }
6391 }).catch(reason => {
6392 console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
6393 }).finally(() => {
6394 this.#getAllTextInProgress = false;
6395 this.#interruptCopyCondition = false;
6396 window.removeEventListener("keydown", interruptCopy);
6397 this.container.style.cursor = savedCursor;
6398 });
6399 event.preventDefault();
6400 event.stopPropagation();
6401 }
6402 }
6403 setDocument(pdfDocument) {
6404 if (this.pdfDocument) {
6405 var _this$findController, _this$_scriptingManag;
6406 this.eventBus.dispatch("pagesdestroy", {
6407 source: this
6408 });
6409 this._cancelRendering();
6410 this._resetView();
6411 (_this$findController = this.findController) === null || _this$findController === void 0 ? void 0 : _this$findController.setDocument(null);
6412 (_this$_scriptingManag = this._scriptingManager) === null || _this$_scriptingManag === void 0 ? void 0 : _this$_scriptingManag.setDocument(null);
6413 if (this.#annotationEditorUIManager) {
6414 this.#annotationEditorUIManager.destroy();
6415 this.#annotationEditorUIManager = null;
6416 }
6417 }
6418 this.pdfDocument = pdfDocument;
6419 if (!pdfDocument) {
6420 return;
6421 }
6422 const pagesCount = pdfDocument.numPages;
6423 const firstPagePromise = pdfDocument.getPage(1);
6424 const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
6425 const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
6426 if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
6427 console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
6428 const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
6429 this.eventBus.dispatch("scrollmodechanged", {
6430 source: this,
6431 mode
6432 });
6433 }
6434 this._pagesCapability.promise.then(() => {
6435 this.eventBus.dispatch("pagesloaded", {
6436 source: this,
6437 pagesCount
6438 });
6439 }, () => {});
6440 this._onBeforeDraw = evt => {
6441 const pageView = this._pages[evt.pageNumber - 1];
6442 if (!pageView) {
6443 return;
6444 }
6445 this.#buffer.push(pageView);
6446 };
6447 this.eventBus._on("pagerender", this._onBeforeDraw);
6448 this._onAfterDraw = evt => {
6449 if (evt.cssTransform || this._onePageRenderedCapability.settled) {
6450 return;
6451 }
6452 this._onePageRenderedCapability.resolve({
6453 timestamp: evt.timestamp
6454 });
6455 this.eventBus._off("pagerendered", this._onAfterDraw);
6456 this._onAfterDraw = null;
6457 if (this.#onVisibilityChange) {
6458 document.removeEventListener("visibilitychange", this.#onVisibilityChange);
6459 this.#onVisibilityChange = null;
6460 }
6461 };
6462 this.eventBus._on("pagerendered", this._onAfterDraw);
6463 Promise.all([firstPagePromise, permissionsPromise]).then(_ref2 => {
6464 let [firstPdfPage, permissions] = _ref2;
6465 if (pdfDocument !== this.pdfDocument) {
6466 return;
6467 }
6468 this._firstPageCapability.resolve(firstPdfPage);
6469 this._optionalContentConfigPromise = optionalContentConfigPromise;
6470 const {
6471 annotationEditorMode,
6472 annotationMode,
6473 textLayerMode
6474 } = this.#initializePermissions(permissions);
6475 if (textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
6476 const element = this.#hiddenCopyElement = document.createElement("div");
6477 element.id = "hiddenCopyElement";
6478 this.viewer.before(element);
6479 }
6480 if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
6481 const mode = annotationEditorMode;
6482 if (pdfDocument.isPureXfa) {
6483 console.warn("Warning: XFA-editing is not implemented.");
6484 } else if (isValidAnnotationEditorMode(mode)) {
6485 this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument === null || pdfDocument === void 0 ? void 0 : pdfDocument.annotationStorage);
6486 if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
6487 this.#annotationEditorUIManager.updateMode(mode);
6488 }
6489 } else {
6490 console.error(`Invalid AnnotationEditor mode: ${mode}`);
6491 }
6492 }
6493 const layerProperties = this.#layerProperties.bind(this);
6494 const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
6495 const scale = this.currentScale;
6496 const viewport = firstPdfPage.getViewport({
6497 scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
6498 });
6499 this.viewer.style.setProperty("--scale-factor", viewport.scale);
6500 for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
6501 const pageView = new _pdf_page_view.PDFPageView({
6502 container: viewerElement,
6503 eventBus: this.eventBus,
6504 id: pageNum,
6505 scale,
6506 defaultViewport: viewport.clone(),
6507 optionalContentConfigPromise,
6508 renderingQueue: this.renderingQueue,
6509 textLayerMode,
6510 annotationMode,
6511 imageResourcesPath: this.imageResourcesPath,
6512 useOnlyCssZoom: this.useOnlyCssZoom,
6513 isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
6514 maxCanvasPixels: this.maxCanvasPixels,
6515 pageColors: this.pageColors,
6516 l10n: this.l10n,
6517 layerProperties
6518 });
6519 this._pages.push(pageView);
6520 }
6521 const firstPageView = this._pages[0];
6522 if (firstPageView) {
6523 firstPageView.setPdfPage(firstPdfPage);
6524 this.linkService.cachePageRef(1, firstPdfPage.ref);
6525 }
6526 if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
6527 this.#ensurePageViewVisible();
6528 } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
6529 this._updateSpreadMode();
6530 }
6531 this.#onePageRenderedOrForceFetch().then(async () => {
6532 var _this$findController2, _this$_scriptingManag2;
6533 (_this$findController2 = this.findController) === null || _this$findController2 === void 0 ? void 0 : _this$findController2.setDocument(pdfDocument);
6534 (_this$_scriptingManag2 = this._scriptingManager) === null || _this$_scriptingManag2 === void 0 ? void 0 : _this$_scriptingManag2.setDocument(pdfDocument);
6535 if (this.#hiddenCopyElement) {
6536 this.#copyCallbackBound = this.#copyCallback.bind(this, textLayerMode);
6537 document.addEventListener("copy", this.#copyCallbackBound);
6538 }
6539 if (this.#annotationEditorUIManager) {
6540 this.eventBus.dispatch("annotationeditormodechanged", {
6541 source: this,
6542 mode: this.#annotationEditorMode
6543 });
6544 }
6545 if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
6546 this._pagesCapability.resolve();
6547 return;
6548 }
6549 let getPagesLeft = pagesCount - 1;
6550 if (getPagesLeft <= 0) {
6551 this._pagesCapability.resolve();
6552 return;
6553 }
6554 for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
6555 const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
6556 const pageView = this._pages[pageNum - 1];
6557 if (!pageView.pdfPage) {
6558 pageView.setPdfPage(pdfPage);
6559 }
6560 this.linkService.cachePageRef(pageNum, pdfPage.ref);
6561 if (--getPagesLeft === 0) {
6562 this._pagesCapability.resolve();
6563 }
6564 }, reason => {
6565 console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
6566 if (--getPagesLeft === 0) {
6567 this._pagesCapability.resolve();
6568 }
6569 });
6570 if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
6571 await promise;
6572 }
6573 }
6574 });
6575 this.eventBus.dispatch("pagesinit", {
6576 source: this
6577 });
6578 pdfDocument.getMetadata().then(_ref3 => {
6579 let {
6580 info
6581 } = _ref3;
6582 if (pdfDocument !== this.pdfDocument) {
6583 return;
6584 }
6585 if (info.Language) {
6586 this.viewer.lang = info.Language;
6587 }
6588 });
6589 if (this.defaultRenderingQueue) {
6590 this.update();
6591 }
6592 }).catch(reason => {
6593 console.error("Unable to initialize viewer", reason);
6594 this._pagesCapability.reject(reason);
6595 });
6596 }
6597 setPageLabels(labels) {
6598 if (!this.pdfDocument) {
6599 return;
6600 }
6601 if (!labels) {
6602 this._pageLabels = null;
6603 } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
6604 this._pageLabels = null;
6605 console.error(`setPageLabels: Invalid page labels.`);
6606 } else {
6607 this._pageLabels = labels;
6608 }
6609 for (let i = 0, ii = this._pages.length; i < ii; i++) {
6610 var _this$_pageLabels3;
6611 this._pages[i].setPageLabel(((_this$_pageLabels3 = this._pageLabels) === null || _this$_pageLabels3 === void 0 ? void 0 : _this$_pageLabels3[i]) ?? null);
6612 }
6613 }
6614 _resetView() {
6615 this._pages = [];
6616 this._currentPageNumber = 1;
6617 this._currentScale = _ui_utils.UNKNOWN_SCALE;
6618 this._currentScaleValue = null;
6619 this._pageLabels = null;
6620 this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
6621 this._location = null;
6622 this._pagesRotation = 0;
6623 this._optionalContentConfigPromise = null;
6624 this._firstPageCapability = new _pdfjsLib.PromiseCapability();
6625 this._onePageRenderedCapability = new _pdfjsLib.PromiseCapability();
6626 this._pagesCapability = new _pdfjsLib.PromiseCapability();
6627 this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
6628 this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
6629 this._spreadMode = _ui_utils.SpreadMode.NONE;
6630 this.#scrollModePageState = {
6631 previousPageNumber: 1,
6632 scrollDown: true,
6633 pages: []
6634 };
6635 if (this._onBeforeDraw) {
6636 this.eventBus._off("pagerender", this._onBeforeDraw);
6637 this._onBeforeDraw = null;
6638 }
6639 if (this._onAfterDraw) {
6640 this.eventBus._off("pagerendered", this._onAfterDraw);
6641 this._onAfterDraw = null;
6642 }
6643 if (this.#onVisibilityChange) {
6644 document.removeEventListener("visibilitychange", this.#onVisibilityChange);
6645 this.#onVisibilityChange = null;
6646 }
6647 this.viewer.textContent = "";
6648 this._updateScrollMode();
6649 this.viewer.removeAttribute("lang");
6650 if (this.#hiddenCopyElement) {
6651 document.removeEventListener("copy", this.#copyCallbackBound);
6652 this.#copyCallbackBound = null;
6653 this.#hiddenCopyElement.remove();
6654 this.#hiddenCopyElement = null;
6655 }
6656 }
6657 #ensurePageViewVisible() {
6658 if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
6659 throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
6660 }
6661 const pageNumber = this._currentPageNumber,
6662 state = this.#scrollModePageState,
6663 viewer = this.viewer;
6664 viewer.textContent = "";
6665 state.pages.length = 0;
6666 if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
6667 const pageView = this._pages[pageNumber - 1];
6668 viewer.append(pageView.div);
6669 state.pages.push(pageView);
6670 } else {
6671 const pageIndexSet = new Set(),
6672 parity = this._spreadMode - 1;
6673 if (parity === -1) {
6674 pageIndexSet.add(pageNumber - 1);
6675 } else if (pageNumber % 2 !== parity) {
6676 pageIndexSet.add(pageNumber - 1);
6677 pageIndexSet.add(pageNumber);
6678 } else {
6679 pageIndexSet.add(pageNumber - 2);
6680 pageIndexSet.add(pageNumber - 1);
6681 }
6682 const spread = document.createElement("div");
6683 spread.className = "spread";
6684 if (this.isInPresentationMode) {
6685 const dummyPage = document.createElement("div");
6686 dummyPage.className = "dummyPage";
6687 spread.append(dummyPage);
6688 }
6689 for (const i of pageIndexSet) {
6690 const pageView = this._pages[i];
6691 if (!pageView) {
6692 continue;
6693 }
6694 spread.append(pageView.div);
6695 state.pages.push(pageView);
6696 }
6697 viewer.append(spread);
6698 }
6699 state.scrollDown = pageNumber >= state.previousPageNumber;
6700 state.previousPageNumber = pageNumber;
6701 }
6702 _scrollUpdate() {
6703 if (this.pagesCount === 0) {
6704 return;
6705 }
6706 this.update();
6707 }
6708 #scrollIntoView(pageView) {
6709 let pageSpot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
6710 const {
6711 div,
6712 id
6713 } = pageView;
6714 if (this._currentPageNumber !== id) {
6715 this._setCurrentPageNumber(id);
6716 }
6717 if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
6718 this.#ensurePageViewVisible();
6719 this.update();
6720 }
6721 if (!pageSpot && !this.isInPresentationMode) {
6722 const left = div.offsetLeft + div.clientLeft,
6723 right = left + div.clientWidth;
6724 const {
6725 scrollLeft,
6726 clientWidth
6727 } = this.container;
6728 if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
6729 pageSpot = {
6730 left: 0,
6731 top: 0
6732 };
6733 }
6734 }
6735 (0, _ui_utils.scrollIntoView)(div, pageSpot);
6736 if (!this._currentScaleValue && this._location) {
6737 this._location = null;
6738 }
6739 }
6740 #isSameScale(newScale) {
6741 return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
6742 }
6743 #setScaleUpdatePages(newScale, newValue, _ref4) {
6744 let {
6745 noScroll = false,
6746 preset = false,
6747 drawingDelay = -1
6748 } = _ref4;
6749 this._currentScaleValue = newValue.toString();
6750 if (this.#isSameScale(newScale)) {
6751 if (preset) {
6752 this.eventBus.dispatch("scalechanging", {
6753 source: this,
6754 scale: newScale,
6755 presetValue: newValue
6756 });
6757 }
6758 return;
6759 }
6760 this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
6761 const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
6762 this.refresh(true, {
6763 scale: newScale,
6764 drawingDelay: postponeDrawing ? drawingDelay : -1
6765 });
6766 if (postponeDrawing) {
6767 this.#scaleTimeoutId = setTimeout(() => {
6768 this.#scaleTimeoutId = null;
6769 this.refresh();
6770 }, drawingDelay);
6771 }
6772 this._currentScale = newScale;
6773 if (!noScroll) {
6774 let page = this._currentPageNumber,
6775 dest;
6776 if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
6777 page = this._location.pageNumber;
6778 dest = [null, {
6779 name: "XYZ"
6780 }, this._location.left, this._location.top, null];
6781 }
6782 this.scrollPageIntoView({
6783 pageNumber: page,
6784 destArray: dest,
6785 allowNegativeOffset: true
6786 });
6787 }
6788 this.eventBus.dispatch("scalechanging", {
6789 source: this,
6790 scale: newScale,
6791 presetValue: preset ? newValue : undefined
6792 });
6793 if (this.defaultRenderingQueue) {
6794 this.update();
6795 }
6796 }
6797 get #pageWidthScaleFactor() {
6798 if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
6799 return 2;
6800 }
6801 return 1;
6802 }
6803 #setScale(value, options) {
6804 let scale = parseFloat(value);
6805 if (scale > 0) {
6806 options.preset = false;
6807 this.#setScaleUpdatePages(scale, value, options);
6808 } else {
6809 const currentPage = this._pages[this._currentPageNumber - 1];
6810 if (!currentPage) {
6811 return;
6812 }
6813 let hPadding = _ui_utils.SCROLLBAR_PADDING,
6814 vPadding = _ui_utils.VERTICAL_PADDING;
6815 if (this.isInPresentationMode) {
6816 hPadding = vPadding = 4;
6817 if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
6818 hPadding *= 2;
6819 }
6820 } else if (this.removePageBorders) {
6821 hPadding = vPadding = 0;
6822 } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
6823 [hPadding, vPadding] = [vPadding, hPadding];
6824 }
6825 const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
6826 const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
6827 switch (value) {
6828 case "page-actual":
6829 scale = 1;
6830 break;
6831 case "page-width":
6832 scale = pageWidthScale;
6833 break;
6834 case "page-height":
6835 scale = pageHeightScale;
6836 break;
6837 case "page-fit":
6838 scale = Math.min(pageWidthScale, pageHeightScale);
6839 break;
6840 case "auto":
6841 const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
6842 scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
6843 break;
6844 default:
6845 console.error(`#setScale: "${value}" is an unknown zoom value.`);
6846 return;
6847 }
6848 options.preset = true;
6849 this.#setScaleUpdatePages(scale, value, options);
6850 }
6851 }
6852 #resetCurrentPageView() {
6853 const pageView = this._pages[this._currentPageNumber - 1];
6854 if (this.isInPresentationMode) {
6855 this.#setScale(this._currentScaleValue, {
6856 noScroll: true
6857 });
6858 }
6859 this.#scrollIntoView(pageView);
6860 }
6861 pageLabelToPageNumber(label) {
6862 if (!this._pageLabels) {
6863 return null;
6864 }
6865 const i = this._pageLabels.indexOf(label);
6866 if (i < 0) {
6867 return null;
6868 }
6869 return i + 1;
6870 }
6871 scrollPageIntoView(_ref5) {
6872 let {
6873 pageNumber,
6874 destArray = null,
6875 allowNegativeOffset = false,
6876 ignoreDestinationZoom = false
6877 } = _ref5;
6878 if (!this.pdfDocument) {
6879 return;
6880 }
6881 const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
6882 if (!pageView) {
6883 console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
6884 return;
6885 }
6886 if (this.isInPresentationMode || !destArray) {
6887 this._setCurrentPageNumber(pageNumber, true);
6888 return;
6889 }
6890 let x = 0,
6891 y = 0;
6892 let width = 0,
6893 height = 0,
6894 widthScale,
6895 heightScale;
6896 const changeOrientation = pageView.rotation % 180 !== 0;
6897 const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
6898 const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
6899 let scale = 0;
6900 switch (destArray[1].name) {
6901 case "XYZ":
6902 x = destArray[2];
6903 y = destArray[3];
6904 scale = destArray[4];
6905 x = x !== null ? x : 0;
6906 y = y !== null ? y : pageHeight;
6907 break;
6908 case "Fit":
6909 case "FitB":
6910 scale = "page-fit";
6911 break;
6912 case "FitH":
6913 case "FitBH":
6914 y = destArray[2];
6915 scale = "page-width";
6916 if (y === null && this._location) {
6917 x = this._location.left;
6918 y = this._location.top;
6919 } else if (typeof y !== "number" || y < 0) {
6920 y = pageHeight;
6921 }
6922 break;
6923 case "FitV":
6924 case "FitBV":
6925 x = destArray[2];
6926 width = pageWidth;
6927 height = pageHeight;
6928 scale = "page-height";
6929 break;
6930 case "FitR":
6931 x = destArray[2];
6932 y = destArray[3];
6933 width = destArray[4] - x;
6934 height = destArray[5] - y;
6935 let hPadding = _ui_utils.SCROLLBAR_PADDING,
6936 vPadding = _ui_utils.VERTICAL_PADDING;
6937 if (this.removePageBorders) {
6938 hPadding = vPadding = 0;
6939 }
6940 widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
6941 heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
6942 scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
6943 break;
6944 default:
6945 console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
6946 return;
6947 }
6948 if (!ignoreDestinationZoom) {
6949 if (scale && scale !== this._currentScale) {
6950 this.currentScaleValue = scale;
6951 } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
6952 this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
6953 }
6954 }
6955 if (scale === "page-fit" && !destArray[4]) {
6956 this.#scrollIntoView(pageView);
6957 return;
6958 }
6959 const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
6960 let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
6961 let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
6962 if (!allowNegativeOffset) {
6963 left = Math.max(left, 0);
6964 top = Math.max(top, 0);
6965 }
6966 this.#scrollIntoView(pageView, {
6967 left,
6968 top
6969 });
6970 }
6971 _updateLocation(firstPage) {
6972 const currentScale = this._currentScale;
6973 const currentScaleValue = this._currentScaleValue;
6974 const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
6975 const pageNumber = firstPage.id;
6976 const currentPageView = this._pages[pageNumber - 1];
6977 const container = this.container;
6978 const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
6979 const intLeft = Math.round(topLeft[0]);
6980 const intTop = Math.round(topLeft[1]);
6981 let pdfOpenParams = `#page=${pageNumber}`;
6982 if (!this.isInPresentationMode) {
6983 pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
6984 }
6985 this._location = {
6986 pageNumber,
6987 scale: normalizedScaleValue,
6988 top: intTop,
6989 left: intLeft,
6990 rotation: this._pagesRotation,
6991 pdfOpenParams
6992 };
6993 }
6994 update() {
6995 const visible = this._getVisiblePages();
6996 const visiblePages = visible.views,
6997 numVisiblePages = visiblePages.length;
6998 if (numVisiblePages === 0) {
6999 return;
7000 }
7001 const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
7002 this.#buffer.resize(newCacheSize, visible.ids);
7003 this.renderingQueue.renderHighestPriority(visible);
7004 const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
7005 const currentId = this._currentPageNumber;
7006 let stillFullyVisible = false;
7007 for (const page of visiblePages) {
7008 if (page.percent < 100) {
7009 break;
7010 }
7011 if (page.id === currentId && isSimpleLayout) {
7012 stillFullyVisible = true;
7013 break;
7014 }
7015 }
7016 this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
7017 this._updateLocation(visible.first);
7018 this.eventBus.dispatch("updateviewarea", {
7019 source: this,
7020 location: this._location
7021 });
7022 }
7023 containsElement(element) {
7024 return this.container.contains(element);
7025 }
7026 focus() {
7027 this.container.focus();
7028 }
7029 get _isContainerRtl() {
7030 return getComputedStyle(this.container).direction === "rtl";
7031 }
7032 get isInPresentationMode() {
7033 return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
7034 }
7035 get isChangingPresentationMode() {
7036 return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
7037 }
7038 get isHorizontalScrollbarEnabled() {
7039 return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
7040 }
7041 get isVerticalScrollbarEnabled() {
7042 return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
7043 }
7044 _getVisiblePages() {
7045 const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
7046 horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
7047 rtl = horizontal && this._isContainerRtl;
7048 return (0, _ui_utils.getVisibleElements)({
7049 scrollEl: this.container,
7050 views,
7051 sortByVisibility: true,
7052 horizontal,
7053 rtl
7054 });
7055 }
7056 cleanup() {
7057 for (const pageView of this._pages) {
7058 if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
7059 pageView.reset();
7060 }
7061 }
7062 }
7063 _cancelRendering() {
7064 for (const pageView of this._pages) {
7065 pageView.cancelRendering();
7066 }
7067 }
7068 async #ensurePdfPageLoaded(pageView) {
7069 if (pageView.pdfPage) {
7070 return pageView.pdfPage;
7071 }
7072 try {
7073 var _this$linkService$_ca, _this$linkService;
7074 const pdfPage = await this.pdfDocument.getPage(pageView.id);
7075 if (!pageView.pdfPage) {
7076 pageView.setPdfPage(pdfPage);
7077 }
7078 if (!((_this$linkService$_ca = (_this$linkService = this.linkService)._cachedPageNumber) !== null && _this$linkService$_ca !== void 0 && _this$linkService$_ca.call(_this$linkService, pdfPage.ref))) {
7079 this.linkService.cachePageRef(pageView.id, pdfPage.ref);
7080 }
7081 return pdfPage;
7082 } catch (reason) {
7083 console.error("Unable to get page for page view", reason);
7084 return null;
7085 }
7086 }
7087 #getScrollAhead(visible) {
7088 var _visible$first, _visible$last;
7089 if (((_visible$first = visible.first) === null || _visible$first === void 0 ? void 0 : _visible$first.id) === 1) {
7090 return true;
7091 } else if (((_visible$last = visible.last) === null || _visible$last === void 0 ? void 0 : _visible$last.id) === this.pagesCount) {
7092 return false;
7093 }
7094 switch (this._scrollMode) {
7095 case _ui_utils.ScrollMode.PAGE:
7096 return this.#scrollModePageState.scrollDown;
7097 case _ui_utils.ScrollMode.HORIZONTAL:
7098 return this.scroll.right;
7099 }
7100 return this.scroll.down;
7101 }
7102 forceRendering(currentlyVisiblePages) {
7103 const visiblePages = currentlyVisiblePages || this._getVisiblePages();
7104 const scrollAhead = this.#getScrollAhead(visiblePages);
7105 const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
7106 const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
7107 if (pageView) {
7108 this.#ensurePdfPageLoaded(pageView).then(() => {
7109 this.renderingQueue.renderView(pageView);
7110 });
7111 return true;
7112 }
7113 return false;
7114 }
7115 get hasEqualPageSizes() {
7116 const firstPageView = this._pages[0];
7117 for (let i = 1, ii = this._pages.length; i < ii; ++i) {
7118 const pageView = this._pages[i];
7119 if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
7120 return false;
7121 }
7122 }
7123 return true;
7124 }
7125 getPagesOverview() {
7126 let initialOrientation;
7127 return this._pages.map(pageView => {
7128 const viewport = pageView.pdfPage.getViewport({
7129 scale: 1
7130 });
7131 const orientation = (0, _ui_utils.isPortraitOrientation)(viewport);
7132 if (initialOrientation === undefined) {
7133 initialOrientation = orientation;
7134 } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
7135 return {
7136 width: viewport.height,
7137 height: viewport.width,
7138 rotation: (viewport.rotation - 90) % 360
7139 };
7140 }
7141 return {
7142 width: viewport.width,
7143 height: viewport.height,
7144 rotation: viewport.rotation
7145 };
7146 });
7147 }
7148 get optionalContentConfigPromise() {
7149 if (!this.pdfDocument) {
7150 return Promise.resolve(null);
7151 }
7152 if (!this._optionalContentConfigPromise) {
7153 console.error("optionalContentConfigPromise: Not initialized yet.");
7154 return this.pdfDocument.getOptionalContentConfig();
7155 }
7156 return this._optionalContentConfigPromise;
7157 }
7158 set optionalContentConfigPromise(promise) {
7159 if (!(promise instanceof Promise)) {
7160 throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
7161 }
7162 if (!this.pdfDocument) {
7163 return;
7164 }
7165 if (!this._optionalContentConfigPromise) {
7166 return;
7167 }
7168 this._optionalContentConfigPromise = promise;
7169 this.refresh(false, {
7170 optionalContentConfigPromise: promise
7171 });
7172 this.eventBus.dispatch("optionalcontentconfigchanged", {
7173 source: this,
7174 promise
7175 });
7176 }
7177 get scrollMode() {
7178 return this._scrollMode;
7179 }
7180 set scrollMode(mode) {
7181 if (this._scrollMode === mode) {
7182 return;
7183 }
7184 if (!(0, _ui_utils.isValidScrollMode)(mode)) {
7185 throw new Error(`Invalid scroll mode: ${mode}`);
7186 }
7187 if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
7188 return;
7189 }
7190 this._previousScrollMode = this._scrollMode;
7191 this._scrollMode = mode;
7192 this.eventBus.dispatch("scrollmodechanged", {
7193 source: this,
7194 mode
7195 });
7196 this._updateScrollMode(this._currentPageNumber);
7197 }
7198 _updateScrollMode() {
7199 let pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
7200 const scrollMode = this._scrollMode,
7201 viewer = this.viewer;
7202 viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
7203 viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
7204 if (!this.pdfDocument || !pageNumber) {
7205 return;
7206 }
7207 if (scrollMode === _ui_utils.ScrollMode.PAGE) {
7208 this.#ensurePageViewVisible();
7209 } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
7210 this._updateSpreadMode();
7211 }
7212 if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
7213 this.#setScale(this._currentScaleValue, {
7214 noScroll: true
7215 });
7216 }
7217 this._setCurrentPageNumber(pageNumber, true);
7218 this.update();
7219 }
7220 get spreadMode() {
7221 return this._spreadMode;
7222 }
7223 set spreadMode(mode) {
7224 if (this._spreadMode === mode) {
7225 return;
7226 }
7227 if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
7228 throw new Error(`Invalid spread mode: ${mode}`);
7229 }
7230 this._spreadMode = mode;
7231 this.eventBus.dispatch("spreadmodechanged", {
7232 source: this,
7233 mode
7234 });
7235 this._updateSpreadMode(this._currentPageNumber);
7236 }
7237 _updateSpreadMode() {
7238 let pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
7239 if (!this.pdfDocument) {
7240 return;
7241 }
7242 const viewer = this.viewer,
7243 pages = this._pages;
7244 if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
7245 this.#ensurePageViewVisible();
7246 } else {
7247 viewer.textContent = "";
7248 if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
7249 for (const pageView of this._pages) {
7250 viewer.append(pageView.div);
7251 }
7252 } else {
7253 const parity = this._spreadMode - 1;
7254 let spread = null;
7255 for (let i = 0, ii = pages.length; i < ii; ++i) {
7256 if (spread === null) {
7257 spread = document.createElement("div");
7258 spread.className = "spread";
7259 viewer.append(spread);
7260 } else if (i % 2 === parity) {
7261 spread = spread.cloneNode(false);
7262 viewer.append(spread);
7263 }
7264 spread.append(pages[i].div);
7265 }
7266 }
7267 }
7268 if (!pageNumber) {
7269 return;
7270 }
7271 if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
7272 this.#setScale(this._currentScaleValue, {
7273 noScroll: true
7274 });
7275 }
7276 this._setCurrentPageNumber(pageNumber, true);
7277 this.update();
7278 }
7279 _getPageAdvance(currentPageNumber) {
7280 let previous = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7281 switch (this._scrollMode) {
7282 case _ui_utils.ScrollMode.WRAPPED:
7283 {
7284 const {
7285 views
7286 } = this._getVisiblePages(),
7287 pageLayout = new Map();
7288 for (const {
7289 id,
7290 y,
7291 percent,
7292 widthPercent
7293 } of views) {
7294 if (percent === 0 || widthPercent < 100) {
7295 continue;
7296 }
7297 let yArray = pageLayout.get(y);
7298 if (!yArray) {
7299 pageLayout.set(y, yArray ||= []);
7300 }
7301 yArray.push(id);
7302 }
7303 for (const yArray of pageLayout.values()) {
7304 const currentIndex = yArray.indexOf(currentPageNumber);
7305 if (currentIndex === -1) {
7306 continue;
7307 }
7308 const numPages = yArray.length;
7309 if (numPages === 1) {
7310 break;
7311 }
7312 if (previous) {
7313 for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
7314 const currentId = yArray[i],
7315 expectedId = yArray[i + 1] - 1;
7316 if (currentId < expectedId) {
7317 return currentPageNumber - expectedId;
7318 }
7319 }
7320 } else {
7321 for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
7322 const currentId = yArray[i],
7323 expectedId = yArray[i - 1] + 1;
7324 if (currentId > expectedId) {
7325 return expectedId - currentPageNumber;
7326 }
7327 }
7328 }
7329 if (previous) {
7330 const firstId = yArray[0];
7331 if (firstId < currentPageNumber) {
7332 return currentPageNumber - firstId + 1;
7333 }
7334 } else {
7335 const lastId = yArray[numPages - 1];
7336 if (lastId > currentPageNumber) {
7337 return lastId - currentPageNumber + 1;
7338 }
7339 }
7340 break;
7341 }
7342 break;
7343 }
7344 case _ui_utils.ScrollMode.HORIZONTAL:
7345 {
7346 break;
7347 }
7348 case _ui_utils.ScrollMode.PAGE:
7349 case _ui_utils.ScrollMode.VERTICAL:
7350 {
7351 if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
7352 break;
7353 }
7354 const parity = this._spreadMode - 1;
7355 if (previous && currentPageNumber % 2 !== parity) {
7356 break;
7357 } else if (!previous && currentPageNumber % 2 === parity) {
7358 break;
7359 }
7360 const {
7361 views
7362 } = this._getVisiblePages(),
7363 expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
7364 for (const {
7365 id,
7366 percent,
7367 widthPercent
7368 } of views) {
7369 if (id !== expectedId) {
7370 continue;
7371 }
7372 if (percent > 0 && widthPercent === 100) {
7373 return 2;
7374 }
7375 break;
7376 }
7377 break;
7378 }
7379 }
7380 return 1;
7381 }
7382 nextPage() {
7383 const currentPageNumber = this._currentPageNumber,
7384 pagesCount = this.pagesCount;
7385 if (currentPageNumber >= pagesCount) {
7386 return false;
7387 }
7388 const advance = this._getPageAdvance(currentPageNumber, false) || 1;
7389 this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
7390 return true;
7391 }
7392 previousPage() {
7393 const currentPageNumber = this._currentPageNumber;
7394 if (currentPageNumber <= 1) {
7395 return false;
7396 }
7397 const advance = this._getPageAdvance(currentPageNumber, true) || 1;
7398 this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
7399 return true;
7400 }
7401 increaseScale() {
7402 let {
7403 drawingDelay,
7404 scaleFactor,
7405 steps
7406 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7407 if (!this.pdfDocument) {
7408 return;
7409 }
7410 let newScale = this._currentScale;
7411 if (scaleFactor > 1) {
7412 newScale = Math.round(newScale * scaleFactor * 100) / 100;
7413 } else {
7414 steps ??= 1;
7415 do {
7416 newScale = Math.ceil((newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
7417 } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
7418 }
7419 this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
7420 noScroll: false,
7421 drawingDelay
7422 });
7423 }
7424 decreaseScale() {
7425 let {
7426 drawingDelay,
7427 scaleFactor,
7428 steps
7429 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7430 if (!this.pdfDocument) {
7431 return;
7432 }
7433 let newScale = this._currentScale;
7434 if (scaleFactor > 0 && scaleFactor < 1) {
7435 newScale = Math.round(newScale * scaleFactor * 100) / 100;
7436 } else {
7437 steps ??= 1;
7438 do {
7439 newScale = Math.floor((newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
7440 } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
7441 }
7442 this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
7443 noScroll: false,
7444 drawingDelay
7445 });
7446 }
7447 #updateContainerHeightCss() {
7448 let height = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.container.clientHeight;
7449 if (height !== this.#previousContainerHeight) {
7450 this.#previousContainerHeight = height;
7451 _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
7452 }
7453 }
7454 #resizeObserverCallback(entries) {
7455 for (const entry of entries) {
7456 if (entry.target === this.container) {
7457 this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
7458 this.#containerTopLeft = null;
7459 break;
7460 }
7461 }
7462 }
7463 get containerTopLeft() {
7464 return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
7465 }
7466 get annotationEditorMode() {
7467 return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
7468 }
7469 set annotationEditorMode(mode) {
7470 if (!this.#annotationEditorUIManager) {
7471 throw new Error(`The AnnotationEditor is not enabled.`);
7472 }
7473 if (this.#annotationEditorMode === mode) {
7474 return;
7475 }
7476 if (!isValidAnnotationEditorMode(mode)) {
7477 throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
7478 }
7479 if (!this.pdfDocument) {
7480 return;
7481 }
7482 this.#annotationEditorMode = mode;
7483 this.eventBus.dispatch("annotationeditormodechanged", {
7484 source: this,
7485 mode
7486 });
7487 this.#annotationEditorUIManager.updateMode(mode);
7488 }
7489 set annotationEditorParams(_ref6) {
7490 let {
7491 type,
7492 value
7493 } = _ref6;
7494 if (!this.#annotationEditorUIManager) {
7495 throw new Error(`The AnnotationEditor is not enabled.`);
7496 }
7497 this.#annotationEditorUIManager.updateParams(type, value);
7498 }
7499 refresh() {
7500 let noUpdate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
7501 let updateArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Object.create(null);
7502 if (!this.pdfDocument) {
7503 return;
7504 }
7505 for (const pageView of this._pages) {
7506 pageView.update(updateArgs);
7507 }
7508 if (this.#scaleTimeoutId !== null) {
7509 clearTimeout(this.#scaleTimeoutId);
7510 this.#scaleTimeoutId = null;
7511 }
7512 if (!noUpdate) {
7513 this.update();
7514 }
7515 }
7516}
7517exports.PDFViewer = PDFViewer;
7518
7519/***/ }),
7520/* 25 */
7521/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
7522
7523
7524
7525Object.defineProperty(exports, "__esModule", ({
7526 value: true
7527}));
7528exports.PDFRenderingQueue = void 0;
7529var _pdfjsLib = __w_pdfjs_require__(4);
7530var _ui_utils = __w_pdfjs_require__(2);
7531const CLEANUP_TIMEOUT = 30000;
7532class PDFRenderingQueue {
7533 constructor() {
7534 this.pdfViewer = null;
7535 this.pdfThumbnailViewer = null;
7536 this.onIdle = null;
7537 this.highestPriorityPage = null;
7538 this.idleTimeout = null;
7539 this.printing = false;
7540 this.isThumbnailViewEnabled = false;
7541 }
7542 setViewer(pdfViewer) {
7543 this.pdfViewer = pdfViewer;
7544 }
7545 setThumbnailViewer(pdfThumbnailViewer) {
7546 this.pdfThumbnailViewer = pdfThumbnailViewer;
7547 }
7548 isHighestPriority(view) {
7549 return this.highestPriorityPage === view.renderingId;
7550 }
7551 hasViewer() {
7552 return !!this.pdfViewer;
7553 }
7554 renderHighestPriority(currentlyVisiblePages) {
7555 var _this$pdfThumbnailVie;
7556 if (this.idleTimeout) {
7557 clearTimeout(this.idleTimeout);
7558 this.idleTimeout = null;
7559 }
7560 if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
7561 return;
7562 }
7563 if (this.isThumbnailViewEnabled && (_this$pdfThumbnailVie = this.pdfThumbnailViewer) !== null && _this$pdfThumbnailVie !== void 0 && _this$pdfThumbnailVie.forceRendering()) {
7564 return;
7565 }
7566 if (this.printing) {
7567 return;
7568 }
7569 if (this.onIdle) {
7570 this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
7571 }
7572 }
7573 getHighestPriority(visible, views, scrolledDown) {
7574 let preRenderExtra = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
7575 const visibleViews = visible.views,
7576 numVisible = visibleViews.length;
7577 if (numVisible === 0) {
7578 return null;
7579 }
7580 for (let i = 0; i < numVisible; i++) {
7581 const view = visibleViews[i].view;
7582 if (!this.isViewFinished(view)) {
7583 return view;
7584 }
7585 }
7586 const firstId = visible.first.id,
7587 lastId = visible.last.id;
7588 if (lastId - firstId + 1 > numVisible) {
7589 const visibleIds = visible.ids;
7590 for (let i = 1, ii = lastId - firstId; i < ii; i++) {
7591 const holeId = scrolledDown ? firstId + i : lastId - i;
7592 if (visibleIds.has(holeId)) {
7593 continue;
7594 }
7595 const holeView = views[holeId - 1];
7596 if (!this.isViewFinished(holeView)) {
7597 return holeView;
7598 }
7599 }
7600 }
7601 let preRenderIndex = scrolledDown ? lastId : firstId - 2;
7602 let preRenderView = views[preRenderIndex];
7603 if (preRenderView && !this.isViewFinished(preRenderView)) {
7604 return preRenderView;
7605 }
7606 if (preRenderExtra) {
7607 preRenderIndex += scrolledDown ? 1 : -1;
7608 preRenderView = views[preRenderIndex];
7609 if (preRenderView && !this.isViewFinished(preRenderView)) {
7610 return preRenderView;
7611 }
7612 }
7613 return null;
7614 }
7615 isViewFinished(view) {
7616 return view.renderingState === _ui_utils.RenderingStates.FINISHED;
7617 }
7618 renderView(view) {
7619 switch (view.renderingState) {
7620 case _ui_utils.RenderingStates.FINISHED:
7621 return false;
7622 case _ui_utils.RenderingStates.PAUSED:
7623 this.highestPriorityPage = view.renderingId;
7624 view.resume();
7625 break;
7626 case _ui_utils.RenderingStates.RUNNING:
7627 this.highestPriorityPage = view.renderingId;
7628 break;
7629 case _ui_utils.RenderingStates.INITIAL:
7630 this.highestPriorityPage = view.renderingId;
7631 view.draw().finally(() => {
7632 this.renderHighestPriority();
7633 }).catch(reason => {
7634 if (reason instanceof _pdfjsLib.RenderingCancelledException) {
7635 return;
7636 }
7637 console.error(`renderView: "${reason}"`);
7638 });
7639 break;
7640 }
7641 return true;
7642 }
7643}
7644exports.PDFRenderingQueue = PDFRenderingQueue;
7645
7646/***/ })
7647/******/ ]);
7648/************************************************************************/
7649/******/ // The module cache
7650/******/ var __webpack_module_cache__ = {};
7651/******/
7652/******/ // The require function
7653/******/ function __w_pdfjs_require__(moduleId) {
7654/******/ // Check if module is in cache
7655/******/ var cachedModule = __webpack_module_cache__[moduleId];
7656/******/ if (cachedModule !== undefined) {
7657/******/ return cachedModule.exports;
7658/******/ }
7659/******/ // Create a new module (and put it into the cache)
7660/******/ var module = __webpack_module_cache__[moduleId] = {
7661/******/ // no module.id needed
7662/******/ // no module.loaded needed
7663/******/ exports: {}
7664/******/ };
7665/******/
7666/******/ // Execute the module function
7667/******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
7668/******/
7669/******/ // Return the exports of the module
7670/******/ return module.exports;
7671/******/ }
7672/******/
7673/************************************************************************/
7674var __webpack_exports__ = {};
7675// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
7676(() => {
7677var exports = __webpack_exports__;
7678
7679
7680Object.defineProperty(exports, "__esModule", ({
7681 value: true
7682}));
7683Object.defineProperty(exports, "AnnotationLayerBuilder", ({
7684 enumerable: true,
7685 get: function () {
7686 return _annotation_layer_builder.AnnotationLayerBuilder;
7687 }
7688}));
7689exports.DefaultXfaLayerFactory = exports.DefaultTextLayerFactory = exports.DefaultStructTreeLayerFactory = exports.DefaultAnnotationLayerFactory = void 0;
7690Object.defineProperty(exports, "DownloadManager", ({
7691 enumerable: true,
7692 get: function () {
7693 return _download_manager.DownloadManager;
7694 }
7695}));
7696Object.defineProperty(exports, "EventBus", ({
7697 enumerable: true,
7698 get: function () {
7699 return _event_utils.EventBus;
7700 }
7701}));
7702Object.defineProperty(exports, "GenericL10n", ({
7703 enumerable: true,
7704 get: function () {
7705 return _genericl10n.GenericL10n;
7706 }
7707}));
7708Object.defineProperty(exports, "LinkTarget", ({
7709 enumerable: true,
7710 get: function () {
7711 return _pdf_link_service.LinkTarget;
7712 }
7713}));
7714Object.defineProperty(exports, "NullL10n", ({
7715 enumerable: true,
7716 get: function () {
7717 return _l10n_utils.NullL10n;
7718 }
7719}));
7720Object.defineProperty(exports, "PDFFindController", ({
7721 enumerable: true,
7722 get: function () {
7723 return _pdf_find_controller.PDFFindController;
7724 }
7725}));
7726Object.defineProperty(exports, "PDFHistory", ({
7727 enumerable: true,
7728 get: function () {
7729 return _pdf_history.PDFHistory;
7730 }
7731}));
7732Object.defineProperty(exports, "PDFLinkService", ({
7733 enumerable: true,
7734 get: function () {
7735 return _pdf_link_service.PDFLinkService;
7736 }
7737}));
7738Object.defineProperty(exports, "PDFPageView", ({
7739 enumerable: true,
7740 get: function () {
7741 return _pdf_page_view.PDFPageView;
7742 }
7743}));
7744Object.defineProperty(exports, "PDFScriptingManager", ({
7745 enumerable: true,
7746 get: function () {
7747 return _pdf_scripting_manager.PDFScriptingManager;
7748 }
7749}));
7750Object.defineProperty(exports, "PDFSinglePageViewer", ({
7751 enumerable: true,
7752 get: function () {
7753 return _pdf_single_page_viewer.PDFSinglePageViewer;
7754 }
7755}));
7756Object.defineProperty(exports, "PDFViewer", ({
7757 enumerable: true,
7758 get: function () {
7759 return _pdf_viewer.PDFViewer;
7760 }
7761}));
7762Object.defineProperty(exports, "ProgressBar", ({
7763 enumerable: true,
7764 get: function () {
7765 return _ui_utils.ProgressBar;
7766 }
7767}));
7768Object.defineProperty(exports, "RenderingStates", ({
7769 enumerable: true,
7770 get: function () {
7771 return _ui_utils.RenderingStates;
7772 }
7773}));
7774Object.defineProperty(exports, "ScrollMode", ({
7775 enumerable: true,
7776 get: function () {
7777 return _ui_utils.ScrollMode;
7778 }
7779}));
7780Object.defineProperty(exports, "SimpleLinkService", ({
7781 enumerable: true,
7782 get: function () {
7783 return _pdf_link_service.SimpleLinkService;
7784 }
7785}));
7786Object.defineProperty(exports, "SpreadMode", ({
7787 enumerable: true,
7788 get: function () {
7789 return _ui_utils.SpreadMode;
7790 }
7791}));
7792Object.defineProperty(exports, "StructTreeLayerBuilder", ({
7793 enumerable: true,
7794 get: function () {
7795 return _struct_tree_layer_builder.StructTreeLayerBuilder;
7796 }
7797}));
7798Object.defineProperty(exports, "TextLayerBuilder", ({
7799 enumerable: true,
7800 get: function () {
7801 return _text_layer_builder.TextLayerBuilder;
7802 }
7803}));
7804Object.defineProperty(exports, "XfaLayerBuilder", ({
7805 enumerable: true,
7806 get: function () {
7807 return _xfa_layer_builder.XfaLayerBuilder;
7808 }
7809}));
7810Object.defineProperty(exports, "parseQueryString", ({
7811 enumerable: true,
7812 get: function () {
7813 return _ui_utils.parseQueryString;
7814 }
7815}));
7816var _pdf_link_service = __w_pdfjs_require__(1);
7817var _ui_utils = __w_pdfjs_require__(2);
7818var _annotation_layer_builder = __w_pdfjs_require__(3);
7819var _download_manager = __w_pdfjs_require__(6);
7820var _event_utils = __w_pdfjs_require__(7);
7821var _genericl10n = __w_pdfjs_require__(8);
7822var _l10n_utils = __w_pdfjs_require__(5);
7823var _pdf_find_controller = __w_pdfjs_require__(10);
7824var _pdf_history = __w_pdfjs_require__(12);
7825var _pdf_page_view = __w_pdfjs_require__(13);
7826var _pdf_scripting_manager = __w_pdfjs_require__(21);
7827var _pdf_single_page_viewer = __w_pdfjs_require__(23);
7828var _pdf_viewer = __w_pdfjs_require__(24);
7829var _struct_tree_layer_builder = __w_pdfjs_require__(16);
7830var _text_layer_builder = __w_pdfjs_require__(19);
7831var _xfa_layer_builder = __w_pdfjs_require__(20);
7832const pdfjsVersion = '3.7.107';
7833const pdfjsBuild = '036f855dc';
7834class DefaultAnnotationLayerFactory {
7835 constructor() {
7836 throw new Error("The `DefaultAnnotationLayerFactory` has been removed, " + "please use the `annotationMode` option when initializing " + "the `PDFPageView`-instance to control AnnotationLayer rendering.");
7837 }
7838}
7839exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
7840class DefaultStructTreeLayerFactory {
7841 constructor() {
7842 throw new Error("The `DefaultStructTreeLayerFactory` has been removed, " + "this functionality is automatically enabled when the TextLayer is used.");
7843 }
7844}
7845exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
7846class DefaultTextLayerFactory {
7847 constructor() {
7848 throw new Error("The `DefaultTextLayerFactory` has been removed, " + "please use the `textLayerMode` option when initializing " + "the `PDFPageView`-instance to control TextLayer rendering.");
7849 }
7850}
7851exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
7852class DefaultXfaLayerFactory {
7853 constructor() {
7854 throw new Error("The `DefaultXfaLayerFactory` has been removed, " + "please use the `enableXfa` option when calling " + "the `getDocument`-function to control XfaLayer rendering.");
7855 }
7856}
7857exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
7858})();
7859
7860/******/ return __webpack_exports__;
7861/******/ })()
7862;
7863});
7864//# sourceMappingURL=pdf_viewer.js.map
\No newline at end of file