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