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