UNPKG

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