TungstenVn

viewer.js

Jun 16th, 2021
1,032
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @licstart The following is the entire license notice for the
  3.  * Javascript code in this page
  4.  *
  5.  * Copyright 2021 Mozilla Foundation
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  *
  19.  * @licend The above is the entire license notice for the
  20.  * Javascript code in this page
  21.  */
  22.  
  23. /******/ (() => { // webpackBootstrap
  24. /******/    "use strict";
  25. /******/    var __webpack_modules__ = ([
  26. /* 0 */,
  27. /* 1 */
  28. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  29.  
  30.  
  31.  
  32. Object.defineProperty(exports, "__esModule", ({
  33.   value: true
  34. }));
  35. exports.OptionKind = exports.AppOptions = void 0;
  36.  
  37. var _viewer_compatibility = __webpack_require__(2);
  38.  
  39. const OptionKind = {
  40.   VIEWER: 0x02,
  41.   API: 0x04,
  42.   WORKER: 0x08,
  43.   PREFERENCE: 0x80
  44. };
  45. exports.OptionKind = OptionKind;
  46. const defaultOptions = {
  47.   cursorToolOnLoad: {
  48.     value: 0,
  49.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  50.   },
  51.   defaultUrl: {
  52.     value: "compressed.tracemonkey-pldi-09.pdf",
  53.     kind: OptionKind.VIEWER
  54.   },
  55.   defaultZoomValue: {
  56.     value: "",
  57.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  58.   },
  59.   disableHistory: {
  60.     value: false,
  61.     kind: OptionKind.VIEWER
  62.   },
  63.   disablePageLabels: {
  64.     value: false,
  65.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  66.   },
  67.   enablePermissions: {
  68.     value: false,
  69.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  70.   },
  71.   enablePrintAutoRotate: {
  72.     value: true,
  73.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  74.   },
  75.   enableScripting: {
  76.     value: true,
  77.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  78.   },
  79.   enableWebGL: {
  80.     value: false,
  81.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  82.   },
  83.   externalLinkRel: {
  84.     value: "noopener noreferrer nofollow",
  85.     kind: OptionKind.VIEWER
  86.   },
  87.   externalLinkTarget: {
  88.     value: 0,
  89.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  90.   },
  91.   historyUpdateUrl: {
  92.     value: false,
  93.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  94.   },
  95.   ignoreDestinationZoom: {
  96.     value: false,
  97.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  98.   },
  99.   imageResourcesPath: {
  100.     value: "./images/",
  101.     kind: OptionKind.VIEWER
  102.   },
  103.   maxCanvasPixels: {
  104.     value: 16777216,
  105.     compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  106.     kind: OptionKind.VIEWER
  107.   },
  108.   pdfBugEnabled: {
  109.     value: false,
  110.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  111.   },
  112.   printResolution: {
  113.     value: 150,
  114.     kind: OptionKind.VIEWER
  115.   },
  116.   renderer: {
  117.     value: "canvas",
  118.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  119.   },
  120.   renderInteractiveForms: {
  121.     value: true,
  122.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  123.   },
  124.   sidebarViewOnLoad: {
  125.     value: -1,
  126.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  127.   },
  128.   scrollModeOnLoad: {
  129.     value: -1,
  130.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  131.   },
  132.   spreadModeOnLoad: {
  133.     value: -1,
  134.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  135.   },
  136.   textLayerMode: {
  137.     value: 1,
  138.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  139.   },
  140.   useOnlyCssZoom: {
  141.     value: false,
  142.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  143.   },
  144.   viewerCssTheme: {
  145.     value: 0,
  146.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  147.   },
  148.   viewOnLoad: {
  149.     value: 0,
  150.     kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  151.   },
  152.   cMapPacked: {
  153.     value: true,
  154.     kind: OptionKind.API
  155.   },
  156.   cMapUrl: {
  157.     value: "../web/cmaps/",
  158.     kind: OptionKind.API
  159.   },
  160.   disableAutoFetch: {
  161.     value: false,
  162.     kind: OptionKind.API + OptionKind.PREFERENCE
  163.   },
  164.   disableFontFace: {
  165.     value: false,
  166.     kind: OptionKind.API + OptionKind.PREFERENCE
  167.   },
  168.   disableRange: {
  169.     value: false,
  170.     kind: OptionKind.API + OptionKind.PREFERENCE
  171.   },
  172.   disableStream: {
  173.     value: false,
  174.     kind: OptionKind.API + OptionKind.PREFERENCE
  175.   },
  176.   docBaseUrl: {
  177.     value: "",
  178.     kind: OptionKind.API
  179.   },
  180.   enableXfa: {
  181.     value: false,
  182.     kind: OptionKind.API
  183.   },
  184.   fontExtraProperties: {
  185.     value: false,
  186.     kind: OptionKind.API
  187.   },
  188.   isEvalSupported: {
  189.     value: true,
  190.     kind: OptionKind.API
  191.   },
  192.   maxImageSize: {
  193.     value: -1,
  194.     kind: OptionKind.API
  195.   },
  196.   pdfBug: {
  197.     value: false,
  198.     kind: OptionKind.API
  199.   },
  200.   verbosity: {
  201.     value: 1,
  202.     kind: OptionKind.API
  203.   },
  204.   workerPort: {
  205.     value: null,
  206.     kind: OptionKind.WORKER
  207.   },
  208.   workerSrc: {
  209.     value: "../build/pdf.worker.js",
  210.     kind: OptionKind.WORKER
  211.   }
  212. };
  213. {
  214.   defaultOptions.disablePreferences = {
  215.     value: false,
  216.     kind: OptionKind.VIEWER
  217.   };
  218.   defaultOptions.locale = {
  219.     value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  220.     kind: OptionKind.VIEWER
  221.   };
  222.   defaultOptions.sandboxBundleSrc = {
  223.     value: "../build/pdf.sandbox.js",
  224.     kind: OptionKind.VIEWER
  225.   };
  226. }
  227. const userOptions = Object.create(null);
  228.  
  229. class AppOptions {
  230.   constructor() {
  231.     throw new Error("Cannot initialize AppOptions.");
  232.   }
  233.  
  234.   static get(name) {
  235.     const userOption = userOptions[name];
  236.  
  237.     if (userOption !== undefined) {
  238.       return userOption;
  239.     }
  240.  
  241.     const defaultOption = defaultOptions[name];
  242.  
  243.     if (defaultOption !== undefined) {
  244.       return defaultOption.compatibility ?? defaultOption.value;
  245.     }
  246.  
  247.     return undefined;
  248.   }
  249.  
  250.   static getAll(kind = null) {
  251.     const options = Object.create(null);
  252.  
  253.     for (const name in defaultOptions) {
  254.       const defaultOption = defaultOptions[name];
  255.  
  256.       if (kind) {
  257.         if ((kind & defaultOption.kind) === 0) {
  258.           continue;
  259.         }
  260.  
  261.         if (kind === OptionKind.PREFERENCE) {
  262.           const value = defaultOption.value,
  263.                 valueType = typeof value;
  264.  
  265.           if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  266.             options[name] = value;
  267.             continue;
  268.           }
  269.  
  270.           throw new Error(`Invalid type for preference: ${name}`);
  271.         }
  272.       }
  273.  
  274.       const userOption = userOptions[name];
  275.       options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  276.     }
  277.  
  278.     return options;
  279.   }
  280.  
  281.   static set(name, value) {
  282.     userOptions[name] = value;
  283.   }
  284.  
  285.   static setAll(options) {
  286.     for (const name in options) {
  287.       userOptions[name] = options[name];
  288.     }
  289.   }
  290.  
  291.   static remove(name) {
  292.     delete userOptions[name];
  293.   }
  294.  
  295. }
  296.  
  297. exports.AppOptions = AppOptions;
  298.  
  299. /***/ }),
  300. /* 2 */
  301. /***/ ((__unused_webpack_module, exports) => {
  302.  
  303.  
  304.  
  305. Object.defineProperty(exports, "__esModule", ({
  306.   value: true
  307. }));
  308. exports.viewerCompatibilityParams = void 0;
  309. const compatibilityParams = Object.create(null);
  310. {
  311.   const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  312.   const platform = typeof navigator !== "undefined" && navigator.platform || "";
  313.   const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  314.   const isAndroid = /Android/.test(userAgent);
  315.   const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  316.   const isIOSChrome = /CriOS/.test(userAgent);
  317.  
  318.   (function checkOnBlobSupport() {
  319.     if (isIOSChrome) {
  320.       compatibilityParams.disableCreateObjectURL = true;
  321.     }
  322.   })();
  323.  
  324.   (function checkCanvasSizeLimitation() {
  325.     if (isIOS || isAndroid) {
  326.       compatibilityParams.maxCanvasPixels = 5242880;
  327.     }
  328.   })();
  329. }
  330. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  331. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  332.  
  333. /***/ }),
  334. /* 3 */
  335. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  336.  
  337.  
  338.  
  339. Object.defineProperty(exports, "__esModule", ({
  340.   value: true
  341. }));
  342. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  343.  
  344. var _ui_utils = __webpack_require__(4);
  345.  
  346. var _app_options = __webpack_require__(1);
  347.  
  348. var _pdfjsLib = __webpack_require__(5);
  349.  
  350. var _pdf_cursor_tools = __webpack_require__(6);
  351.  
  352. var _pdf_rendering_queue = __webpack_require__(8);
  353.  
  354. var _overlay_manager = __webpack_require__(9);
  355.  
  356. var _password_prompt = __webpack_require__(10);
  357.  
  358. var _pdf_attachment_viewer = __webpack_require__(11);
  359.  
  360. var _pdf_document_properties = __webpack_require__(13);
  361.  
  362. var _pdf_find_bar = __webpack_require__(14);
  363.  
  364. var _pdf_find_controller = __webpack_require__(15);
  365.  
  366. var _pdf_history = __webpack_require__(17);
  367.  
  368. var _pdf_layer_viewer = __webpack_require__(18);
  369.  
  370. var _pdf_link_service = __webpack_require__(19);
  371.  
  372. var _pdf_outline_viewer = __webpack_require__(20);
  373.  
  374. var _pdf_presentation_mode = __webpack_require__(21);
  375.  
  376. var _pdf_scripting_manager = __webpack_require__(22);
  377.  
  378. var _pdf_sidebar = __webpack_require__(23);
  379.  
  380. var _pdf_sidebar_resizer = __webpack_require__(24);
  381.  
  382. var _pdf_thumbnail_viewer = __webpack_require__(25);
  383.  
  384. var _pdf_viewer = __webpack_require__(27);
  385.  
  386. var _secondary_toolbar = __webpack_require__(34);
  387.  
  388. var _toolbar = __webpack_require__(36);
  389.  
  390. var _viewer_compatibility = __webpack_require__(2);
  391.  
  392. var _view_history = __webpack_require__(37);
  393.  
  394. const DEFAULT_SCALE_DELTA = 1.1;
  395. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  396. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  397. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  398. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  399. const ViewOnLoad = {
  400.   UNKNOWN: -1,
  401.   PREVIOUS: 0,
  402.   INITIAL: 1
  403. };
  404. const ViewerCssTheme = {
  405.   AUTOMATIC: 0,
  406.   LIGHT: 1,
  407.   DARK: 2
  408. };
  409. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  410. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  411.  
  412. class DefaultExternalServices {
  413.   constructor() {
  414.     throw new Error("Cannot initialize DefaultExternalServices.");
  415.   }
  416.  
  417.   static updateFindControlState(data) {}
  418.  
  419.   static updateFindMatchesCount(data) {}
  420.  
  421.   static initPassiveLoading(callbacks) {}
  422.  
  423.   static async fallback(data) {}
  424.  
  425.   static reportTelemetry(data) {}
  426.  
  427.   static createDownloadManager(options) {
  428.     throw new Error("Not implemented: createDownloadManager");
  429.   }
  430.  
  431.   static createPreferences() {
  432.     throw new Error("Not implemented: createPreferences");
  433.   }
  434.  
  435.   static createL10n(options) {
  436.     throw new Error("Not implemented: createL10n");
  437.   }
  438.  
  439.   static createScripting(options) {
  440.     throw new Error("Not implemented: createScripting");
  441.   }
  442.  
  443.   static get supportsIntegratedFind() {
  444.     return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  445.   }
  446.  
  447.   static get supportsDocumentFonts() {
  448.     return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  449.   }
  450.  
  451.   static get supportedMouseWheelZoomModifierKeys() {
  452.     return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  453.       ctrlKey: true,
  454.       metaKey: true
  455.     });
  456.   }
  457.  
  458.   static get isInAutomation() {
  459.     return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  460.   }
  461.  
  462. }
  463.  
  464. exports.DefaultExternalServices = DefaultExternalServices;
  465. const PDFViewerApplication = {
  466.   initialBookmark: document.location.hash.substring(1),
  467.   _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  468.   fellback: false,
  469.   appConfig: null,
  470.   pdfDocument: null,
  471.   pdfLoadingTask: null,
  472.   printService: null,
  473.   pdfViewer: null,
  474.   pdfThumbnailViewer: null,
  475.   pdfRenderingQueue: null,
  476.   pdfPresentationMode: null,
  477.   pdfDocumentProperties: null,
  478.   pdfLinkService: null,
  479.   pdfHistory: null,
  480.   pdfSidebar: null,
  481.   pdfSidebarResizer: null,
  482.   pdfOutlineViewer: null,
  483.   pdfAttachmentViewer: null,
  484.   pdfLayerViewer: null,
  485.   pdfCursorTools: null,
  486.   pdfScriptingManager: null,
  487.   store: null,
  488.   downloadManager: null,
  489.   overlayManager: null,
  490.   preferences: null,
  491.   toolbar: null,
  492.   secondaryToolbar: null,
  493.   eventBus: null,
  494.   l10n: null,
  495.   isInitialViewSet: false,
  496.   downloadComplete: false,
  497.   isViewerEmbedded: window.parent !== window,
  498.   url: "",
  499.   baseUrl: "",
  500.   externalServices: DefaultExternalServices,
  501.   _boundEvents: Object.create(null),
  502.   documentInfo: null,
  503.   metadata: null,
  504.   _contentDispositionFilename: null,
  505.   _contentLength: null,
  506.   triggerDelayedFallback: null,
  507.   _saveInProgress: false,
  508.   _wheelUnusedTicks: 0,
  509.   _idleCallbacks: new Set(),
  510.  
  511.   async initialize(appConfig) {
  512.     this.preferences = this.externalServices.createPreferences();
  513.     this.appConfig = appConfig;
  514.     await this._readPreferences();
  515.     await this._parseHashParameters();
  516.  
  517.     this._forceCssTheme();
  518.  
  519.     await this._initializeL10n();
  520.  
  521.     if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
  522.       _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
  523.     }
  524.  
  525.     await this._initializeViewerComponents();
  526.     this.bindEvents();
  527.     this.bindWindowEvents();
  528.     const appContainer = appConfig.appContainer || document.documentElement;
  529.     this.l10n.translate(appContainer).then(() => {
  530.       this.eventBus.dispatch("localized", {
  531.         source: this
  532.       });
  533.     });
  534.  
  535.     this._initializedCapability.resolve();
  536.   },
  537.  
  538.   async _readPreferences() {
  539.     if (_app_options.AppOptions.get("disablePreferences")) {
  540.       return;
  541.     }
  542.  
  543.     try {
  544.       _app_options.AppOptions.setAll(await this.preferences.getAll());
  545.     } catch (reason) {
  546.       console.error(`_readPreferences: "${reason?.message}".`);
  547.     }
  548.   },
  549.  
  550.   async _parseHashParameters() {
  551.     if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  552.       return undefined;
  553.     }
  554.  
  555.     const hash = document.location.hash.substring(1);
  556.  
  557.     if (!hash) {
  558.       return undefined;
  559.     }
  560.  
  561.     const hashParams = (0, _ui_utils.parseQueryString)(hash),
  562.           waitOn = [];
  563.  
  564.     if ("disableworker" in hashParams && hashParams.disableworker === "true") {
  565.       waitOn.push(loadFakeWorker());
  566.     }
  567.  
  568.     if ("disablerange" in hashParams) {
  569.       _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
  570.     }
  571.  
  572.     if ("disablestream" in hashParams) {
  573.       _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
  574.     }
  575.  
  576.     if ("disableautofetch" in hashParams) {
  577.       _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
  578.     }
  579.  
  580.     if ("disablefontface" in hashParams) {
  581.       _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
  582.     }
  583.  
  584.     if ("disablehistory" in hashParams) {
  585.       _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
  586.     }
  587.  
  588.     if ("webgl" in hashParams) {
  589.       _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true");
  590.     }
  591.  
  592.     if ("verbosity" in hashParams) {
  593.       _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  594.     }
  595.  
  596.     if ("textlayer" in hashParams) {
  597.       switch (hashParams.textlayer) {
  598.         case "off":
  599.           _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  600.  
  601.           break;
  602.  
  603.         case "visible":
  604.         case "shadow":
  605.         case "hover":
  606.           const viewer = this.appConfig.viewerContainer;
  607.           viewer.classList.add("textLayer-" + hashParams.textlayer);
  608.           break;
  609.       }
  610.     }
  611.  
  612.     if ("pdfbug" in hashParams) {
  613.       _app_options.AppOptions.set("pdfBug", true);
  614.  
  615.       _app_options.AppOptions.set("fontExtraProperties", true);
  616.  
  617.       const enabled = hashParams.pdfbug.split(",");
  618.       waitOn.push(loadAndEnablePDFBug(enabled));
  619.     }
  620.  
  621.     if ("locale" in hashParams) {
  622.       _app_options.AppOptions.set("locale", hashParams.locale);
  623.     }
  624.  
  625.     if (waitOn.length === 0) {
  626.       return undefined;
  627.     }
  628.  
  629.     return Promise.all(waitOn).catch(reason => {
  630.       console.error(`_parseHashParameters: "${reason.message}".`);
  631.     });
  632.   },
  633.  
  634.   async _initializeL10n() {
  635.     this.l10n = this.externalServices.createL10n({
  636.       locale: _app_options.AppOptions.get("locale")
  637.     });
  638.     const dir = await this.l10n.getDirection();
  639.     document.getElementsByTagName("html")[0].dir = dir;
  640.   },
  641.  
  642.   _forceCssTheme() {
  643.     const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  644.  
  645.     if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  646.       return;
  647.     }
  648.  
  649.     try {
  650.       const styleSheet = document.styleSheets[0];
  651.       const cssRules = styleSheet?.cssRules || [];
  652.  
  653.       for (let i = 0, ii = cssRules.length; i < ii; i++) {
  654.         const rule = cssRules[i];
  655.  
  656.         if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  657.           if (cssTheme === ViewerCssTheme.LIGHT) {
  658.             styleSheet.deleteRule(i);
  659.             return;
  660.           }
  661.  
  662.           const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  663.  
  664.           if (darkRules?.[1]) {
  665.             styleSheet.deleteRule(i);
  666.             styleSheet.insertRule(darkRules[1], i);
  667.           }
  668.  
  669.           return;
  670.         }
  671.       }
  672.     } catch (reason) {
  673.       console.error(`_forceCssTheme: "${reason?.message}".`);
  674.     }
  675.   },
  676.  
  677.   async _initializeViewerComponents() {
  678.     const appConfig = this.appConfig;
  679.     const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  680.       isInAutomation: this.externalServices.isInAutomation
  681.     });
  682.     this.eventBus = eventBus;
  683.     this.overlayManager = new _overlay_manager.OverlayManager();
  684.     const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  685.     pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  686.     this.pdfRenderingQueue = pdfRenderingQueue;
  687.     const pdfLinkService = new _pdf_link_service.PDFLinkService({
  688.       eventBus,
  689.       externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  690.       externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  691.       ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  692.     });
  693.     this.pdfLinkService = pdfLinkService;
  694.     const downloadManager = this.externalServices.createDownloadManager();
  695.     this.downloadManager = downloadManager;
  696.     const findController = new _pdf_find_controller.PDFFindController({
  697.       linkService: pdfLinkService,
  698.       eventBus
  699.     });
  700.     this.findController = findController;
  701.     const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  702.       eventBus,
  703.       sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  704.       scriptingFactory: this.externalServices,
  705.       docPropertiesLookup: this._scriptingDocProperties.bind(this)
  706.     });
  707.     this.pdfScriptingManager = pdfScriptingManager;
  708.     const container = appConfig.mainContainer;
  709.     const viewer = appConfig.viewerContainer;
  710.     this.pdfViewer = new _pdf_viewer.PDFViewer({
  711.       container,
  712.       viewer,
  713.       eventBus,
  714.       renderingQueue: pdfRenderingQueue,
  715.       linkService: pdfLinkService,
  716.       downloadManager,
  717.       findController,
  718.       scriptingManager: pdfScriptingManager,
  719.       renderer: _app_options.AppOptions.get("renderer"),
  720.       enableWebGL: _app_options.AppOptions.get("enableWebGL"),
  721.       l10n: this.l10n,
  722.       textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  723.       imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  724.       renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  725.       enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  726.       useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  727.       maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  728.       enableScripting: _app_options.AppOptions.get("enableScripting")
  729.     });
  730.     pdfRenderingQueue.setViewer(this.pdfViewer);
  731.     pdfLinkService.setViewer(this.pdfViewer);
  732.     pdfScriptingManager.setViewer(this.pdfViewer);
  733.     this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  734.       container: appConfig.sidebar.thumbnailView,
  735.       eventBus,
  736.       renderingQueue: pdfRenderingQueue,
  737.       linkService: pdfLinkService,
  738.       l10n: this.l10n
  739.     });
  740.     pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  741.     this.pdfHistory = new _pdf_history.PDFHistory({
  742.       linkService: pdfLinkService,
  743.       eventBus
  744.     });
  745.     pdfLinkService.setHistory(this.pdfHistory);
  746.  
  747.     if (!this.supportsIntegratedFind) {
  748.       this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  749.     }
  750.  
  751.     this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  752.     this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  753.       container,
  754.       eventBus,
  755.       cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  756.     });
  757.     this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  758.     this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  759.  
  760.     if (this.supportsFullscreen) {
  761.       this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  762.         container,
  763.         pdfViewer: this.pdfViewer,
  764.         eventBus
  765.       });
  766.     }
  767.  
  768.     this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  769.     this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  770.       container: appConfig.sidebar.outlineView,
  771.       eventBus,
  772.       linkService: pdfLinkService
  773.     });
  774.     this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  775.       container: appConfig.sidebar.attachmentsView,
  776.       eventBus,
  777.       downloadManager
  778.     });
  779.     this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  780.       container: appConfig.sidebar.layersView,
  781.       eventBus,
  782.       l10n: this.l10n
  783.     });
  784.     this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  785.       elements: appConfig.sidebar,
  786.       pdfViewer: this.pdfViewer,
  787.       pdfThumbnailViewer: this.pdfThumbnailViewer,
  788.       eventBus,
  789.       l10n: this.l10n
  790.     });
  791.     this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  792.     this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  793.   },
  794.  
  795.   run(config) {
  796.     this.initialize(config).then(webViewerInitialized);
  797.   },
  798.  
  799.   get initialized() {
  800.     return this._initializedCapability.settled;
  801.   },
  802.  
  803.   get initializedPromise() {
  804.     return this._initializedCapability.promise;
  805.   },
  806.  
  807.   zoomIn(ticks) {
  808.     if (this.pdfViewer.isInPresentationMode) {
  809.       return;
  810.     }
  811.  
  812.     let newScale = this.pdfViewer.currentScale;
  813.  
  814.     do {
  815.       newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  816.       newScale = Math.ceil(newScale * 10) / 10;
  817.       newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  818.     } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  819.  
  820.     this.pdfViewer.currentScaleValue = newScale;
  821.   },
  822.  
  823.   zoomOut(ticks) {
  824.     if (this.pdfViewer.isInPresentationMode) {
  825.       return;
  826.     }
  827.  
  828.     let newScale = this.pdfViewer.currentScale;
  829.  
  830.     do {
  831.       newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  832.       newScale = Math.floor(newScale * 10) / 10;
  833.       newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  834.     } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  835.  
  836.     this.pdfViewer.currentScaleValue = newScale;
  837.   },
  838.  
  839.   zoomReset() {
  840.     if (this.pdfViewer.isInPresentationMode) {
  841.       return;
  842.     }
  843.  
  844.     this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  845.   },
  846.  
  847.   get pagesCount() {
  848.     return this.pdfDocument ? this.pdfDocument.numPages : 0;
  849.   },
  850.  
  851.   get page() {
  852.     return this.pdfViewer.currentPageNumber;
  853.   },
  854.  
  855.   set page(val) {
  856.     this.pdfViewer.currentPageNumber = val;
  857.   },
  858.  
  859.   get supportsPrinting() {
  860.     return PDFPrintServiceFactory.instance.supportsPrinting;
  861.   },
  862.  
  863.   get supportsFullscreen() {
  864.     const doc = document.documentElement;
  865.     let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
  866.  
  867.     if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
  868.       support = false;
  869.     }
  870.  
  871.     return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  872.   },
  873.  
  874.   get supportsIntegratedFind() {
  875.     return this.externalServices.supportsIntegratedFind;
  876.   },
  877.  
  878.   get supportsDocumentFonts() {
  879.     return this.externalServices.supportsDocumentFonts;
  880.   },
  881.  
  882.   get loadingBar() {
  883.     const bar = new _ui_utils.ProgressBar("#loadingBar");
  884.     return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  885.   },
  886.  
  887.   get supportedMouseWheelZoomModifierKeys() {
  888.     return this.externalServices.supportedMouseWheelZoomModifierKeys;
  889.   },
  890.  
  891.   initPassiveLoading() {
  892.     throw new Error("Not implemented: initPassiveLoading");
  893.   },
  894.  
  895.   setTitleUsingUrl(url = "") {
  896.     this.url = url;
  897.     this.baseUrl = url.split("#")[0];
  898.     let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  899.  
  900.     if (!title) {
  901.       try {
  902.         title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  903.       } catch (ex) {
  904.         title = url;
  905.       }
  906.     }
  907.  
  908.     this.setTitle(title);
  909.   },
  910.  
  911.   setTitle(title) {
  912.     if (this.isViewerEmbedded) {
  913.       return;
  914.     }
  915.  
  916.     document.title = title;
  917.   },
  918.  
  919.   get _docFilename() {
  920.     return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  921.   },
  922.  
  923.   _cancelIdleCallbacks() {
  924.     if (!this._idleCallbacks.size) {
  925.       return;
  926.     }
  927.  
  928.     for (const callback of this._idleCallbacks) {
  929.       window.cancelIdleCallback(callback);
  930.     }
  931.  
  932.     this._idleCallbacks.clear();
  933.   },
  934.  
  935.   async close() {
  936.     this._unblockDocumentLoadEvent();
  937.  
  938.     const {
  939.       container
  940.     } = this.appConfig.errorWrapper;
  941.     container.hidden = true;
  942.  
  943.     if (!this.pdfLoadingTask) {
  944.       return;
  945.     }
  946.  
  947.     if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  948.       try {
  949.         await this.save({
  950.           sourceEventType: "save"
  951.         });
  952.       } catch (reason) {}
  953.     }
  954.  
  955.     const promises = [];
  956.     promises.push(this.pdfLoadingTask.destroy());
  957.     this.pdfLoadingTask = null;
  958.  
  959.     if (this.pdfDocument) {
  960.       this.pdfDocument = null;
  961.       this.pdfThumbnailViewer.setDocument(null);
  962.       this.pdfViewer.setDocument(null);
  963.       this.pdfLinkService.setDocument(null);
  964.       this.pdfDocumentProperties.setDocument(null);
  965.     }
  966.  
  967.     webViewerResetPermissions();
  968.     this.store = null;
  969.     this.isInitialViewSet = false;
  970.     this.downloadComplete = false;
  971.     this.url = "";
  972.     this.baseUrl = "";
  973.     this.documentInfo = null;
  974.     this.metadata = null;
  975.     this._contentDispositionFilename = null;
  976.     this._contentLength = null;
  977.     this.triggerDelayedFallback = null;
  978.     this._saveInProgress = false;
  979.  
  980.     this._cancelIdleCallbacks();
  981.  
  982.     promises.push(this.pdfScriptingManager.destroyPromise);
  983.     this.pdfSidebar.reset();
  984.     this.pdfOutlineViewer.reset();
  985.     this.pdfAttachmentViewer.reset();
  986.     this.pdfLayerViewer.reset();
  987.  
  988.     if (this.pdfHistory) {
  989.       this.pdfHistory.reset();
  990.     }
  991.  
  992.     if (this.findBar) {
  993.       this.findBar.reset();
  994.     }
  995.  
  996.     this.toolbar.reset();
  997.     this.secondaryToolbar.reset();
  998.  
  999.     if (typeof PDFBug !== "undefined") {
  1000.       PDFBug.cleanup();
  1001.     }
  1002.  
  1003.     await Promise.all(promises);
  1004.   },
  1005.  
  1006.   async open(file, args) {
  1007.     if (this.pdfLoadingTask) {
  1008.       await this.close();
  1009.     }
  1010.  
  1011.     const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1012.  
  1013.     for (const key in workerParameters) {
  1014.       _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1015.     }
  1016.  
  1017.     const parameters = Object.create(null);
  1018.  
  1019.     if (typeof file === "string") {
  1020.       this.setTitleUsingUrl(file);
  1021.       parameters.url = file;
  1022.     } else if (file && "byteLength" in file) {
  1023.       parameters.data = file;
  1024.     } else if (file.url && file.originalUrl) {
  1025.       this.setTitleUsingUrl(file.originalUrl);
  1026.       parameters.url = file.url;
  1027.     }
  1028.  
  1029.     const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1030.  
  1031.     for (const key in apiParameters) {
  1032.       let value = apiParameters[key];
  1033.  
  1034.       if (key === "docBaseUrl" && !value) {}
  1035.  
  1036.       parameters[key] = value;
  1037.     }
  1038.  
  1039.     if (args) {
  1040.       for (const key in args) {
  1041.         parameters[key] = args[key];
  1042.       }
  1043.     }
  1044.  
  1045.     const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1046.     this.pdfLoadingTask = loadingTask;
  1047.  
  1048.     loadingTask.onPassword = (updateCallback, reason) => {
  1049.       this.pdfLinkService.externalLinkEnabled = false;
  1050.       this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1051.       this.passwordPrompt.open();
  1052.     };
  1053.  
  1054.     loadingTask.onProgress = ({
  1055.       loaded,
  1056.       total
  1057.     }) => {
  1058.       this.progress(loaded / total);
  1059.     };
  1060.  
  1061.     loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1062.     return loadingTask.promise.then(pdfDocument => {
  1063.       this.load(pdfDocument);
  1064.     }, exception => {
  1065.       if (loadingTask !== this.pdfLoadingTask) {
  1066.         return undefined;
  1067.       }
  1068.  
  1069.       let key = "loading_error";
  1070.  
  1071.       if (exception instanceof _pdfjsLib.InvalidPDFException) {
  1072.         key = "invalid_file_error";
  1073.       } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  1074.         key = "missing_file_error";
  1075.       } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  1076.         key = "unexpected_response_error";
  1077.       }
  1078.  
  1079.       return this.l10n.get(key).then(msg => {
  1080.         this._documentError(msg, {
  1081.           message: exception?.message
  1082.         });
  1083.  
  1084.         throw exception;
  1085.       });
  1086.     });
  1087.   },
  1088.  
  1089.   _ensureDownloadComplete() {
  1090.     if (this.pdfDocument && this.downloadComplete) {
  1091.       return;
  1092.     }
  1093.  
  1094.     throw new Error("PDF document not downloaded.");
  1095.   },
  1096.  
  1097.   async download({
  1098.     sourceEventType = "download"
  1099.   } = {}) {
  1100.     const url = this.baseUrl,
  1101.           filename = this._docFilename;
  1102.  
  1103.     try {
  1104.       this._ensureDownloadComplete();
  1105.  
  1106.       const data = await this.pdfDocument.getData();
  1107.       const blob = new Blob([data], {
  1108.         type: "application/pdf"
  1109.       });
  1110.       await this.downloadManager.download(blob, url, filename, sourceEventType);
  1111.     } catch (reason) {
  1112.       await this.downloadManager.downloadUrl(url, filename);
  1113.     }
  1114.   },
  1115.  
  1116.   async save({
  1117.     sourceEventType = "download"
  1118.   } = {}) {
  1119.     if (this._saveInProgress) {
  1120.       return;
  1121.     }
  1122.  
  1123.     this._saveInProgress = true;
  1124.     await this.pdfScriptingManager.dispatchWillSave();
  1125.     const url = this.baseUrl,
  1126.           filename = this._docFilename;
  1127.  
  1128.     try {
  1129.       this._ensureDownloadComplete();
  1130.  
  1131.       const data = await this.pdfDocument.saveDocument(this.pdfDocument.annotationStorage);
  1132.       const blob = new Blob([data], {
  1133.         type: "application/pdf"
  1134.       });
  1135.       await this.downloadManager.download(blob, url, filename, sourceEventType);
  1136.     } catch (reason) {
  1137.       await this.download({
  1138.         sourceEventType
  1139.       });
  1140.     } finally {
  1141.       await this.pdfScriptingManager.dispatchDidSave();
  1142.       this._saveInProgress = false;
  1143.     }
  1144.   },
  1145.  
  1146.   downloadOrSave(options) {
  1147.     if (this.pdfDocument?.annotationStorage.size > 0) {
  1148.       this.save(options);
  1149.     } else {
  1150.       this.download(options);
  1151.     }
  1152.   },
  1153.  
  1154.   _delayedFallback(featureId) {
  1155.     this.externalServices.reportTelemetry({
  1156.       type: "unsupportedFeature",
  1157.       featureId
  1158.     });
  1159.  
  1160.     if (!this.triggerDelayedFallback) {
  1161.       this.triggerDelayedFallback = () => {
  1162.         this.fallback(featureId);
  1163.         this.triggerDelayedFallback = null;
  1164.       };
  1165.     }
  1166.   },
  1167.  
  1168.   fallback(featureId) {
  1169.     this.externalServices.reportTelemetry({
  1170.       type: "unsupportedFeature",
  1171.       featureId
  1172.     });
  1173.  
  1174.     switch (featureId) {
  1175.       case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontLoadNative:
  1176.       case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontMissing:
  1177.         return;
  1178.     }
  1179.  
  1180.     if (this.fellback) {
  1181.       return;
  1182.     }
  1183.  
  1184.     this.fellback = true;
  1185.     this.externalServices.fallback({
  1186.       featureId,
  1187.       url: this.baseUrl
  1188.     }).then(download => {
  1189.       if (!download) {
  1190.         return;
  1191.       }
  1192.  
  1193.       this.download({
  1194.         sourceEventType: "download"
  1195.       });
  1196.     });
  1197.   },
  1198.  
  1199.   _documentError(message, moreInfo = null) {
  1200.     this._unblockDocumentLoadEvent();
  1201.  
  1202.     this._otherError(message, moreInfo);
  1203.   },
  1204.  
  1205.   _otherError(message, moreInfo = null) {
  1206.     const moreInfoText = [this.l10n.get("error_version_info", {
  1207.       version: _pdfjsLib.version || "?",
  1208.       build: _pdfjsLib.build || "?"
  1209.     })];
  1210.  
  1211.     if (moreInfo) {
  1212.       moreInfoText.push(this.l10n.get("error_message", {
  1213.         message: moreInfo.message
  1214.       }));
  1215.  
  1216.       if (moreInfo.stack) {
  1217.         moreInfoText.push(this.l10n.get("error_stack", {
  1218.           stack: moreInfo.stack
  1219.         }));
  1220.       } else {
  1221.         if (moreInfo.filename) {
  1222.           moreInfoText.push(this.l10n.get("error_file", {
  1223.             file: moreInfo.filename
  1224.           }));
  1225.         }
  1226.  
  1227.         if (moreInfo.lineNumber) {
  1228.           moreInfoText.push(this.l10n.get("error_line", {
  1229.             line: moreInfo.lineNumber
  1230.           }));
  1231.         }
  1232.       }
  1233.     }
  1234.  
  1235.     const errorWrapperConfig = this.appConfig.errorWrapper;
  1236.     const errorWrapper = errorWrapperConfig.container;
  1237.     errorWrapper.hidden = false;
  1238.     const errorMessage = errorWrapperConfig.errorMessage;
  1239.     errorMessage.textContent = message;
  1240.     const closeButton = errorWrapperConfig.closeButton;
  1241.  
  1242.     closeButton.onclick = function () {
  1243.       errorWrapper.hidden = true;
  1244.     };
  1245.  
  1246.     const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1247.     const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1248.     const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1249.  
  1250.     moreInfoButton.onclick = function () {
  1251.       errorMoreInfo.hidden = false;
  1252.       moreInfoButton.hidden = true;
  1253.       lessInfoButton.hidden = false;
  1254.       errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1255.     };
  1256.  
  1257.     lessInfoButton.onclick = function () {
  1258.       errorMoreInfo.hidden = true;
  1259.       moreInfoButton.hidden = false;
  1260.       lessInfoButton.hidden = true;
  1261.     };
  1262.  
  1263.     moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1264.     lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1265.     closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1266.     moreInfoButton.hidden = false;
  1267.     lessInfoButton.hidden = true;
  1268.     Promise.all(moreInfoText).then(parts => {
  1269.       errorMoreInfo.value = parts.join("\n");
  1270.     });
  1271.   },
  1272.  
  1273.   progress(level) {
  1274.     if (this.downloadComplete) {
  1275.       return;
  1276.     }
  1277.  
  1278.     const percent = Math.round(level * 100);
  1279.  
  1280.     if (percent > this.loadingBar.percent || isNaN(percent)) {
  1281.       this.loadingBar.percent = percent;
  1282.       const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1283.  
  1284.       if (disableAutoFetch && percent) {
  1285.         if (this.disableAutoFetchLoadingBarTimeout) {
  1286.           clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1287.           this.disableAutoFetchLoadingBarTimeout = null;
  1288.         }
  1289.  
  1290.         this.loadingBar.show();
  1291.         this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1292.           this.loadingBar.hide();
  1293.           this.disableAutoFetchLoadingBarTimeout = null;
  1294.         }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1295.       }
  1296.     }
  1297.   },
  1298.  
  1299.   load(pdfDocument) {
  1300.     this.pdfDocument = pdfDocument;
  1301.     pdfDocument.getDownloadInfo().then(({
  1302.       length
  1303.     }) => {
  1304.       this._contentLength = length;
  1305.       this.downloadComplete = true;
  1306.       this.loadingBar.hide();
  1307.       firstPagePromise.then(() => {
  1308.         this.eventBus.dispatch("documentloaded", {
  1309.           source: this
  1310.         });
  1311.       });
  1312.     });
  1313.     const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1314.     const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1315.     const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1316.     this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1317.     this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1318.     let baseDocumentUrl;
  1319.     baseDocumentUrl = null;
  1320.     this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1321.     this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1322.     const pdfViewer = this.pdfViewer;
  1323.     pdfViewer.setDocument(pdfDocument);
  1324.     const {
  1325.       firstPagePromise,
  1326.       onePageRendered,
  1327.       pagesPromise
  1328.     } = pdfViewer;
  1329.     const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1330.     pdfThumbnailViewer.setDocument(pdfDocument);
  1331.     const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  1332.       page: null,
  1333.       zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1334.       scrollLeft: "0",
  1335.       scrollTop: "0",
  1336.       rotation: null,
  1337.       sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1338.       scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1339.       spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1340.     }).catch(() => {
  1341.       return Object.create(null);
  1342.     });
  1343.     firstPagePromise.then(pdfPage => {
  1344.       this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1345.  
  1346.       this._initializeAnnotationStorageCallbacks(pdfDocument);
  1347.  
  1348.       Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1349.         const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1350.  
  1351.         this._initializePdfHistory({
  1352.           fingerprint: pdfDocument.fingerprint,
  1353.           viewOnLoad,
  1354.           initialDest: openAction?.dest
  1355.         });
  1356.  
  1357.         const initialBookmark = this.initialBookmark;
  1358.  
  1359.         const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1360.  
  1361.         let hash = zoom ? `zoom=${zoom}` : null;
  1362.         let rotation = null;
  1363.  
  1364.         let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1365.  
  1366.         let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1367.  
  1368.         let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1369.  
  1370.         if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1371.           hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1372.           rotation = parseInt(stored.rotation, 10);
  1373.  
  1374.           if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1375.             sidebarView = stored.sidebarView | 0;
  1376.           }
  1377.  
  1378.           if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1379.             scrollMode = stored.scrollMode | 0;
  1380.           }
  1381.  
  1382.           if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1383.             spreadMode = stored.spreadMode | 0;
  1384.           }
  1385.         }
  1386.  
  1387.         if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1388.           sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1389.         }
  1390.  
  1391.         if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1392.           spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1393.         }
  1394.  
  1395.         this.setInitialView(hash, {
  1396.           rotation,
  1397.           sidebarView,
  1398.           scrollMode,
  1399.           spreadMode
  1400.         });
  1401.         this.eventBus.dispatch("documentinit", {
  1402.           source: this
  1403.         });
  1404.  
  1405.         if (!this.isViewerEmbedded) {
  1406.           pdfViewer.focus();
  1407.         }
  1408.  
  1409.         this._initializePermissions(pdfDocument);
  1410.  
  1411.         await Promise.race([pagesPromise, new Promise(resolve => {
  1412.           setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1413.         })]);
  1414.  
  1415.         if (!initialBookmark && !hash) {
  1416.           return;
  1417.         }
  1418.  
  1419.         if (pdfViewer.hasEqualPageSizes) {
  1420.           return;
  1421.         }
  1422.  
  1423.         this.initialBookmark = initialBookmark;
  1424.         pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1425.         this.setInitialView(hash);
  1426.       }).catch(() => {
  1427.         this.setInitialView();
  1428.       }).then(function () {
  1429.         pdfViewer.update();
  1430.       });
  1431.     });
  1432.     pagesPromise.then(() => {
  1433.       this._unblockDocumentLoadEvent();
  1434.  
  1435.       this._initializeAutoPrint(pdfDocument, openActionPromise);
  1436.     });
  1437.     onePageRendered.then(() => {
  1438.       pdfDocument.getOutline().then(outline => {
  1439.         this.pdfOutlineViewer.render({
  1440.           outline,
  1441.           pdfDocument
  1442.         });
  1443.       });
  1444.       pdfDocument.getAttachments().then(attachments => {
  1445.         this.pdfAttachmentViewer.render({
  1446.           attachments
  1447.         });
  1448.       });
  1449.       pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1450.         this.pdfLayerViewer.render({
  1451.           optionalContentConfig,
  1452.           pdfDocument
  1453.         });
  1454.       });
  1455.  
  1456.       if ("requestIdleCallback" in window) {
  1457.         const callback = window.requestIdleCallback(() => {
  1458.           this._collectTelemetry(pdfDocument);
  1459.  
  1460.           this._idleCallbacks.delete(callback);
  1461.         }, {
  1462.           timeout: 1000
  1463.         });
  1464.  
  1465.         this._idleCallbacks.add(callback);
  1466.       }
  1467.     });
  1468.  
  1469.     this._initializePageLabels(pdfDocument);
  1470.  
  1471.     this._initializeMetadata(pdfDocument);
  1472.   },
  1473.  
  1474.   async _scriptingDocProperties(pdfDocument) {
  1475.     if (!this.documentInfo) {
  1476.       await new Promise(resolve => {
  1477.         this.eventBus._on("metadataloaded", resolve, {
  1478.           once: true
  1479.         });
  1480.       });
  1481.  
  1482.       if (pdfDocument !== this.pdfDocument) {
  1483.         return null;
  1484.       }
  1485.     }
  1486.  
  1487.     if (!this._contentLength) {
  1488.       await new Promise(resolve => {
  1489.         this.eventBus._on("documentloaded", resolve, {
  1490.           once: true
  1491.         });
  1492.       });
  1493.  
  1494.       if (pdfDocument !== this.pdfDocument) {
  1495.         return null;
  1496.       }
  1497.     }
  1498.  
  1499.     return { ...this.documentInfo,
  1500.       baseURL: this.baseUrl,
  1501.       filesize: this._contentLength,
  1502.       filename: this._docFilename,
  1503.       metadata: this.metadata?.getRaw(),
  1504.       authors: this.metadata?.get("dc:creator"),
  1505.       numPages: this.pagesCount,
  1506.       URL: this.url
  1507.     };
  1508.   },
  1509.  
  1510.   async _collectTelemetry(pdfDocument) {
  1511.     const markInfo = await this.pdfDocument.getMarkInfo();
  1512.  
  1513.     if (pdfDocument !== this.pdfDocument) {
  1514.       return;
  1515.     }
  1516.  
  1517.     const tagged = markInfo?.Marked || false;
  1518.     this.externalServices.reportTelemetry({
  1519.       type: "tagged",
  1520.       tagged
  1521.     });
  1522.   },
  1523.  
  1524.   async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1525.     const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1526.  
  1527.     if (pdfDocument !== this.pdfDocument) {
  1528.       return;
  1529.     }
  1530.  
  1531.     let triggerAutoPrint = false;
  1532.  
  1533.     if (openAction?.action === "Print") {
  1534.       triggerAutoPrint = true;
  1535.     }
  1536.  
  1537.     if (javaScript) {
  1538.       javaScript.some(js => {
  1539.         if (!js) {
  1540.           return false;
  1541.         }
  1542.  
  1543.         console.warn("Warning: JavaScript is not supported");
  1544.  
  1545.         this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1546.  
  1547.         return true;
  1548.       });
  1549.  
  1550.       if (!triggerAutoPrint) {
  1551.         for (const js of javaScript) {
  1552.           if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1553.             triggerAutoPrint = true;
  1554.             break;
  1555.           }
  1556.         }
  1557.       }
  1558.     }
  1559.  
  1560.     if (triggerAutoPrint) {
  1561.       this.triggerPrinting();
  1562.     }
  1563.   },
  1564.  
  1565.   async _initializeMetadata(pdfDocument) {
  1566.     const {
  1567.       info,
  1568.       metadata,
  1569.       contentDispositionFilename,
  1570.       contentLength
  1571.     } = await pdfDocument.getMetadata();
  1572.  
  1573.     if (pdfDocument !== this.pdfDocument) {
  1574.       return;
  1575.     }
  1576.  
  1577.     this.documentInfo = info;
  1578.     this.metadata = metadata;
  1579.     this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1580.     this._contentLength ?? (this._contentLength = contentLength);
  1581.     console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
  1582.     let pdfTitle = info?.Title;
  1583.     const metadataTitle = metadata?.get("dc:title");
  1584.  
  1585.     if (metadataTitle) {
  1586.       if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1587.         pdfTitle = metadataTitle;
  1588.       }
  1589.     }
  1590.  
  1591.     if (pdfTitle) {
  1592.       this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1593.     } else if (contentDispositionFilename) {
  1594.       this.setTitle(contentDispositionFilename);
  1595.     }
  1596.  
  1597.     if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1598.       console.warn("Warning: XFA is not supported");
  1599.  
  1600.       this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1601.     } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1602.       console.warn("Warning: Interactive form support is not enabled");
  1603.  
  1604.       this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1605.     }
  1606.  
  1607.     let versionId = "other";
  1608.  
  1609.     if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1610.       versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1611.     }
  1612.  
  1613.     let generatorId = "other";
  1614.  
  1615.     if (info.Producer) {
  1616.       const producer = info.Producer.toLowerCase();
  1617.       KNOWN_GENERATORS.some(function (generator) {
  1618.         if (!producer.includes(generator)) {
  1619.           return false;
  1620.         }
  1621.  
  1622.         generatorId = generator.replace(/[ .-]/g, "_");
  1623.         return true;
  1624.       });
  1625.     }
  1626.  
  1627.     let formType = null;
  1628.  
  1629.     if (info.IsXFAPresent) {
  1630.       formType = "xfa";
  1631.     } else if (info.IsAcroFormPresent) {
  1632.       formType = "acroform";
  1633.     }
  1634.  
  1635.     this.externalServices.reportTelemetry({
  1636.       type: "documentInfo",
  1637.       version: versionId,
  1638.       generator: generatorId,
  1639.       formType
  1640.     });
  1641.     this.eventBus.dispatch("metadataloaded", {
  1642.       source: this
  1643.     });
  1644.   },
  1645.  
  1646.   async _initializePageLabels(pdfDocument) {
  1647.     const labels = await pdfDocument.getPageLabels();
  1648.  
  1649.     if (pdfDocument !== this.pdfDocument) {
  1650.       return;
  1651.     }
  1652.  
  1653.     if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1654.       return;
  1655.     }
  1656.  
  1657.     const numLabels = labels.length;
  1658.  
  1659.     if (numLabels !== this.pagesCount) {
  1660.       console.error("The number of Page Labels does not match the number of pages in the document.");
  1661.       return;
  1662.     }
  1663.  
  1664.     let i = 0;
  1665.  
  1666.     while (i < numLabels && labels[i] === (i + 1).toString()) {
  1667.       i++;
  1668.     }
  1669.  
  1670.     if (i === numLabels) {
  1671.       return;
  1672.     }
  1673.  
  1674.     const {
  1675.       pdfViewer,
  1676.       pdfThumbnailViewer,
  1677.       toolbar
  1678.     } = this;
  1679.     pdfViewer.setPageLabels(labels);
  1680.     pdfThumbnailViewer.setPageLabels(labels);
  1681.     toolbar.setPagesCount(numLabels, true);
  1682.     toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1683.   },
  1684.  
  1685.   _initializePdfHistory({
  1686.     fingerprint,
  1687.     viewOnLoad,
  1688.     initialDest = null
  1689.   }) {
  1690.     if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1691.       return;
  1692.     }
  1693.  
  1694.     this.pdfHistory.initialize({
  1695.       fingerprint,
  1696.       resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1697.       updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1698.     });
  1699.  
  1700.     if (this.pdfHistory.initialBookmark) {
  1701.       this.initialBookmark = this.pdfHistory.initialBookmark;
  1702.       this.initialRotation = this.pdfHistory.initialRotation;
  1703.     }
  1704.  
  1705.     if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1706.       this.initialBookmark = JSON.stringify(initialDest);
  1707.       this.pdfHistory.push({
  1708.         explicitDest: initialDest,
  1709.         pageNumber: null
  1710.       });
  1711.     }
  1712.   },
  1713.  
  1714.   async _initializePermissions(pdfDocument) {
  1715.     const permissions = await pdfDocument.getPermissions();
  1716.  
  1717.     if (pdfDocument !== this.pdfDocument) {
  1718.       return;
  1719.     }
  1720.  
  1721.     if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1722.       return;
  1723.     }
  1724.  
  1725.     if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1726.       this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1727.     }
  1728.   },
  1729.  
  1730.   _initializeAnnotationStorageCallbacks(pdfDocument) {
  1731.     if (pdfDocument !== this.pdfDocument) {
  1732.       return;
  1733.     }
  1734.  
  1735.     const {
  1736.       annotationStorage
  1737.     } = pdfDocument;
  1738.  
  1739.     annotationStorage.onSetModified = () => {
  1740.       window.addEventListener("beforeunload", beforeUnload);
  1741.       this._annotationStorageModified = true;
  1742.     };
  1743.  
  1744.     annotationStorage.onResetModified = () => {
  1745.       window.removeEventListener("beforeunload", beforeUnload);
  1746.       delete this._annotationStorageModified;
  1747.     };
  1748.   },
  1749.  
  1750.   setInitialView(storedHash, {
  1751.     rotation,
  1752.     sidebarView,
  1753.     scrollMode,
  1754.     spreadMode
  1755.   } = {}) {
  1756.     const setRotation = angle => {
  1757.       if ((0, _ui_utils.isValidRotation)(angle)) {
  1758.         this.pdfViewer.pagesRotation = angle;
  1759.       }
  1760.     };
  1761.  
  1762.     const setViewerModes = (scroll, spread) => {
  1763.       if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1764.         this.pdfViewer.scrollMode = scroll;
  1765.       }
  1766.  
  1767.       if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1768.         this.pdfViewer.spreadMode = spread;
  1769.       }
  1770.     };
  1771.  
  1772.     this.isInitialViewSet = true;
  1773.     this.pdfSidebar.setInitialView(sidebarView);
  1774.     setViewerModes(scrollMode, spreadMode);
  1775.  
  1776.     if (this.initialBookmark) {
  1777.       setRotation(this.initialRotation);
  1778.       delete this.initialRotation;
  1779.       this.pdfLinkService.setHash(this.initialBookmark);
  1780.       this.initialBookmark = null;
  1781.     } else if (storedHash) {
  1782.       setRotation(rotation);
  1783.       this.pdfLinkService.setHash(storedHash);
  1784.     }
  1785.  
  1786.     this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1787.     this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1788.  
  1789.     if (!this.pdfViewer.currentScaleValue) {
  1790.       this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1791.     }
  1792.   },
  1793.  
  1794.   _cleanup() {
  1795.     if (!this.pdfDocument) {
  1796.       return;
  1797.     }
  1798.  
  1799.     this.pdfViewer.cleanup();
  1800.     this.pdfThumbnailViewer.cleanup();
  1801.     this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1802.   },
  1803.  
  1804.   forceRendering() {
  1805.     this.pdfRenderingQueue.printing = !!this.printService;
  1806.     this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1807.     this.pdfRenderingQueue.renderHighestPriority();
  1808.   },
  1809.  
  1810.   beforePrint() {
  1811.     this.pdfScriptingManager.dispatchWillPrint();
  1812.  
  1813.     if (this.printService) {
  1814.       return;
  1815.     }
  1816.  
  1817.     if (!this.supportsPrinting) {
  1818.       this.l10n.get("printing_not_supported").then(msg => {
  1819.         this._otherError(msg);
  1820.       });
  1821.       return;
  1822.     }
  1823.  
  1824.     if (!this.pdfViewer.pageViewsReady) {
  1825.       this.l10n.get("printing_not_ready").then(msg => {
  1826.         window.alert(msg);
  1827.       });
  1828.       return;
  1829.     }
  1830.  
  1831.     const pagesOverview = this.pdfViewer.getPagesOverview();
  1832.     const printContainer = this.appConfig.printContainer;
  1833.  
  1834.     const printResolution = _app_options.AppOptions.get("printResolution");
  1835.  
  1836.     const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1837.     const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1838.     this.printService = printService;
  1839.     this.forceRendering();
  1840.     printService.layout();
  1841.     this.externalServices.reportTelemetry({
  1842.       type: "print"
  1843.     });
  1844.   },
  1845.  
  1846.   afterPrint() {
  1847.     this.pdfScriptingManager.dispatchDidPrint();
  1848.  
  1849.     if (this.printService) {
  1850.       this.printService.destroy();
  1851.       this.printService = null;
  1852.  
  1853.       if (this.pdfDocument) {
  1854.         this.pdfDocument.annotationStorage.resetModified();
  1855.       }
  1856.     }
  1857.  
  1858.     this.forceRendering();
  1859.   },
  1860.  
  1861.   rotatePages(delta) {
  1862.     this.pdfViewer.pagesRotation += delta;
  1863.   },
  1864.  
  1865.   requestPresentationMode() {
  1866.     if (!this.pdfPresentationMode) {
  1867.       return;
  1868.     }
  1869.  
  1870.     this.pdfPresentationMode.request();
  1871.   },
  1872.  
  1873.   triggerPrinting() {
  1874.     if (!this.supportsPrinting) {
  1875.       return;
  1876.     }
  1877.  
  1878.     window.print();
  1879.   },
  1880.  
  1881.   bindEvents() {
  1882.     const {
  1883.       eventBus,
  1884.       _boundEvents
  1885.     } = this;
  1886.     _boundEvents.beforePrint = this.beforePrint.bind(this);
  1887.     _boundEvents.afterPrint = this.afterPrint.bind(this);
  1888.  
  1889.     eventBus._on("resize", webViewerResize);
  1890.  
  1891.     eventBus._on("hashchange", webViewerHashchange);
  1892.  
  1893.     eventBus._on("beforeprint", _boundEvents.beforePrint);
  1894.  
  1895.     eventBus._on("afterprint", _boundEvents.afterPrint);
  1896.  
  1897.     eventBus._on("pagerendered", webViewerPageRendered);
  1898.  
  1899.     eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1900.  
  1901.     eventBus._on("pagechanging", webViewerPageChanging);
  1902.  
  1903.     eventBus._on("scalechanging", webViewerScaleChanging);
  1904.  
  1905.     eventBus._on("rotationchanging", webViewerRotationChanging);
  1906.  
  1907.     eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1908.  
  1909.     eventBus._on("pagemode", webViewerPageMode);
  1910.  
  1911.     eventBus._on("namedaction", webViewerNamedAction);
  1912.  
  1913.     eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1914.  
  1915.     eventBus._on("presentationmode", webViewerPresentationMode);
  1916.  
  1917.     eventBus._on("print", webViewerPrint);
  1918.  
  1919.     eventBus._on("download", webViewerDownload);
  1920.  
  1921.     eventBus._on("save", webViewerSave);
  1922.  
  1923.     eventBus._on("firstpage", webViewerFirstPage);
  1924.  
  1925.     eventBus._on("lastpage", webViewerLastPage);
  1926.  
  1927.     eventBus._on("nextpage", webViewerNextPage);
  1928.  
  1929.     eventBus._on("previouspage", webViewerPreviousPage);
  1930.  
  1931.     eventBus._on("zoomin", webViewerZoomIn);
  1932.  
  1933.     eventBus._on("zoomout", webViewerZoomOut);
  1934.  
  1935.     eventBus._on("zoomreset", webViewerZoomReset);
  1936.  
  1937.     eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1938.  
  1939.     eventBus._on("scalechanged", webViewerScaleChanged);
  1940.  
  1941.     eventBus._on("rotatecw", webViewerRotateCw);
  1942.  
  1943.     eventBus._on("rotateccw", webViewerRotateCcw);
  1944.  
  1945.     eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1946.  
  1947.     eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1948.  
  1949.     eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1950.  
  1951.     eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1952.  
  1953.     eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1954.  
  1955.     eventBus._on("documentproperties", webViewerDocumentProperties);
  1956.  
  1957.     eventBus._on("find", webViewerFind);
  1958.  
  1959.     eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1960.  
  1961.     eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1962.  
  1963.     eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1964.  
  1965.     if (_app_options.AppOptions.get("pdfBug")) {
  1966.       _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1967.  
  1968.       eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1969.  
  1970.       eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1971.     }
  1972.  
  1973.     eventBus._on("fileinputchange", webViewerFileInputChange);
  1974.  
  1975.     eventBus._on("openfile", webViewerOpenFile);
  1976.   },
  1977.  
  1978.   bindWindowEvents() {
  1979.     const {
  1980.       eventBus,
  1981.       _boundEvents
  1982.     } = this;
  1983.  
  1984.     _boundEvents.windowResize = () => {
  1985.       eventBus.dispatch("resize", {
  1986.         source: window
  1987.       });
  1988.     };
  1989.  
  1990.     _boundEvents.windowHashChange = () => {
  1991.       eventBus.dispatch("hashchange", {
  1992.         source: window,
  1993.         hash: document.location.hash.substring(1)
  1994.       });
  1995.     };
  1996.  
  1997.     _boundEvents.windowBeforePrint = () => {
  1998.       eventBus.dispatch("beforeprint", {
  1999.         source: window
  2000.       });
  2001.     };
  2002.  
  2003.     _boundEvents.windowAfterPrint = () => {
  2004.       eventBus.dispatch("afterprint", {
  2005.         source: window
  2006.       });
  2007.     };
  2008.  
  2009.     _boundEvents.windowUpdateFromSandbox = event => {
  2010.       eventBus.dispatch("updatefromsandbox", {
  2011.         source: window,
  2012.         detail: event.detail
  2013.       });
  2014.     };
  2015.  
  2016.     window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2017.     window.addEventListener("wheel", webViewerWheel, {
  2018.       passive: false
  2019.     });
  2020.     window.addEventListener("touchstart", webViewerTouchStart, {
  2021.       passive: false
  2022.     });
  2023.     window.addEventListener("click", webViewerClick);
  2024.     window.addEventListener("keydown", webViewerKeyDown);
  2025.     window.addEventListener("keyup", webViewerKeyUp);
  2026.     window.addEventListener("resize", _boundEvents.windowResize);
  2027.     window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2028.     window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2029.     window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2030.     window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2031.   },
  2032.  
  2033.   unbindEvents() {
  2034.     const {
  2035.       eventBus,
  2036.       _boundEvents
  2037.     } = this;
  2038.  
  2039.     eventBus._off("resize", webViewerResize);
  2040.  
  2041.     eventBus._off("hashchange", webViewerHashchange);
  2042.  
  2043.     eventBus._off("beforeprint", _boundEvents.beforePrint);
  2044.  
  2045.     eventBus._off("afterprint", _boundEvents.afterPrint);
  2046.  
  2047.     eventBus._off("pagerendered", webViewerPageRendered);
  2048.  
  2049.     eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2050.  
  2051.     eventBus._off("pagechanging", webViewerPageChanging);
  2052.  
  2053.     eventBus._off("scalechanging", webViewerScaleChanging);
  2054.  
  2055.     eventBus._off("rotationchanging", webViewerRotationChanging);
  2056.  
  2057.     eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2058.  
  2059.     eventBus._off("pagemode", webViewerPageMode);
  2060.  
  2061.     eventBus._off("namedaction", webViewerNamedAction);
  2062.  
  2063.     eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2064.  
  2065.     eventBus._off("presentationmode", webViewerPresentationMode);
  2066.  
  2067.     eventBus._off("print", webViewerPrint);
  2068.  
  2069.     eventBus._off("download", webViewerDownload);
  2070.  
  2071.     eventBus._off("save", webViewerSave);
  2072.  
  2073.     eventBus._off("firstpage", webViewerFirstPage);
  2074.  
  2075.     eventBus._off("lastpage", webViewerLastPage);
  2076.  
  2077.     eventBus._off("nextpage", webViewerNextPage);
  2078.  
  2079.     eventBus._off("previouspage", webViewerPreviousPage);
  2080.  
  2081.     eventBus._off("zoomin", webViewerZoomIn);
  2082.  
  2083.     eventBus._off("zoomout", webViewerZoomOut);
  2084.  
  2085.     eventBus._off("zoomreset", webViewerZoomReset);
  2086.  
  2087.     eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2088.  
  2089.     eventBus._off("scalechanged", webViewerScaleChanged);
  2090.  
  2091.     eventBus._off("rotatecw", webViewerRotateCw);
  2092.  
  2093.     eventBus._off("rotateccw", webViewerRotateCcw);
  2094.  
  2095.     eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2096.  
  2097.     eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2098.  
  2099.     eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2100.  
  2101.     eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2102.  
  2103.     eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2104.  
  2105.     eventBus._off("documentproperties", webViewerDocumentProperties);
  2106.  
  2107.     eventBus._off("find", webViewerFind);
  2108.  
  2109.     eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2110.  
  2111.     eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2112.  
  2113.     eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2114.  
  2115.     if (_boundEvents.reportPageStatsPDFBug) {
  2116.       eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2117.  
  2118.       eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2119.  
  2120.       _boundEvents.reportPageStatsPDFBug = null;
  2121.     }
  2122.  
  2123.     eventBus._off("fileinputchange", webViewerFileInputChange);
  2124.  
  2125.     eventBus._off("openfile", webViewerOpenFile);
  2126.  
  2127.     _boundEvents.beforePrint = null;
  2128.     _boundEvents.afterPrint = null;
  2129.   },
  2130.  
  2131.   unbindWindowEvents() {
  2132.     const {
  2133.       _boundEvents
  2134.     } = this;
  2135.     window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2136.     window.removeEventListener("wheel", webViewerWheel, {
  2137.       passive: false
  2138.     });
  2139.     window.removeEventListener("touchstart", webViewerTouchStart, {
  2140.       passive: false
  2141.     });
  2142.     window.removeEventListener("click", webViewerClick);
  2143.     window.removeEventListener("keydown", webViewerKeyDown);
  2144.     window.removeEventListener("keyup", webViewerKeyUp);
  2145.     window.removeEventListener("resize", _boundEvents.windowResize);
  2146.     window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2147.     window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2148.     window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2149.     window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2150.     _boundEvents.windowResize = null;
  2151.     _boundEvents.windowHashChange = null;
  2152.     _boundEvents.windowBeforePrint = null;
  2153.     _boundEvents.windowAfterPrint = null;
  2154.     _boundEvents.windowUpdateFromSandbox = null;
  2155.   },
  2156.  
  2157.   accumulateWheelTicks(ticks) {
  2158.     if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2159.       this._wheelUnusedTicks = 0;
  2160.     }
  2161.  
  2162.     this._wheelUnusedTicks += ticks;
  2163.     const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2164.     this._wheelUnusedTicks -= wholeTicks;
  2165.     return wholeTicks;
  2166.   },
  2167.  
  2168.   _unblockDocumentLoadEvent() {
  2169.     if (document.blockUnblockOnload) {
  2170.       document.blockUnblockOnload(false);
  2171.     }
  2172.  
  2173.     this._unblockDocumentLoadEvent = () => {};
  2174.   },
  2175.  
  2176.   get scriptingReady() {
  2177.     return this.pdfScriptingManager.ready;
  2178.   }
  2179.  
  2180. };
  2181. exports.PDFViewerApplication = PDFViewerApplication;
  2182. let validateFileURL;
  2183. {
  2184.   const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2185.  
  2186.   validateFileURL = function (file) {
  2187.     if (file === undefined) {
  2188.       return;
  2189.     }
  2190.  
  2191.     try {
  2192.       const viewerOrigin = new URL(window.location.href).origin || "null";
  2193.  
  2194.       if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2195.         return;
  2196.       }
  2197.  
  2198.       const {
  2199.         origin,
  2200.         protocol
  2201.       } = new URL(file, window.location.href);
  2202.  
  2203.       if (origin !== viewerOrigin && protocol !== "blob:") {
  2204.         throw new Error("file origin does not match viewer's");
  2205.       }
  2206.     } catch (ex) {
  2207.       PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2208.         PDFViewerApplication._documentError(msg, {
  2209.           message: ex?.message
  2210.         });
  2211.       });
  2212.       throw ex;
  2213.     }
  2214.   };
  2215. }
  2216.  
  2217. async function loadFakeWorker() {
  2218.   if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  2219.     _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  2220.   }
  2221.  
  2222.   return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  2223. }
  2224.  
  2225. function loadAndEnablePDFBug(enabledTabs) {
  2226.   const appConfig = PDFViewerApplication.appConfig;
  2227.   return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  2228.     PDFBug.enable(enabledTabs);
  2229.     PDFBug.init({
  2230.       OPS: _pdfjsLib.OPS
  2231.     }, appConfig.mainContainer);
  2232.   });
  2233. }
  2234.  
  2235. function reportPageStatsPDFBug({
  2236.   pageNumber
  2237. }) {
  2238.   if (typeof Stats === "undefined" || !Stats.enabled) {
  2239.     return;
  2240.   }
  2241.  
  2242.   const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2243.   const pageStats = pageView?.pdfPage?.stats;
  2244.  
  2245.   if (!pageStats) {
  2246.     return;
  2247.   }
  2248.  
  2249.   Stats.add(pageNumber, pageStats);
  2250. }
  2251.  
  2252. function webViewerInitialized() {
  2253.   const appConfig = PDFViewerApplication.appConfig;
  2254.   let file;
  2255.   const queryString = document.location.search.substring(1);
  2256.   const params = (0, _ui_utils.parseQueryString)(queryString);
  2257.   file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  2258.   validateFileURL(file);
  2259.   const fileInput = document.createElement("input");
  2260.   fileInput.id = appConfig.openFileInputName;
  2261.   fileInput.className = "fileInput";
  2262.   fileInput.setAttribute("type", "file");
  2263.   fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  2264.   document.body.appendChild(fileInput);
  2265.  
  2266.   if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  2267.     appConfig.toolbar.openFile.hidden = true;
  2268.     appConfig.secondaryToolbar.openFileButton.hidden = true;
  2269.   } else {
  2270.     fileInput.value = null;
  2271.   }
  2272.  
  2273.   fileInput.addEventListener("change", function (evt) {
  2274.     const files = evt.target.files;
  2275.  
  2276.     if (!files || files.length === 0) {
  2277.       return;
  2278.     }
  2279.  
  2280.     PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  2281.       source: this,
  2282.       fileInput: evt.target
  2283.     });
  2284.   });
  2285.   appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2286.     evt.preventDefault();
  2287.     evt.dataTransfer.dropEffect = "move";
  2288.   });
  2289.   appConfig.mainContainer.addEventListener("drop", function (evt) {
  2290.     evt.preventDefault();
  2291.     const files = evt.dataTransfer.files;
  2292.  
  2293.     if (!files || files.length === 0) {
  2294.       return;
  2295.     }
  2296.  
  2297.     PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  2298.       source: this,
  2299.       fileInput: evt.dataTransfer
  2300.     });
  2301.   });
  2302.  
  2303.   if (!PDFViewerApplication.supportsDocumentFonts) {
  2304.     _app_options.AppOptions.set("disableFontFace", true);
  2305.  
  2306.     PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2307.       console.warn(msg);
  2308.     });
  2309.   }
  2310.  
  2311.   if (!PDFViewerApplication.supportsPrinting) {
  2312.     appConfig.toolbar.print.classList.add("hidden");
  2313.     appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2314.   }
  2315.  
  2316.   if (!PDFViewerApplication.supportsFullscreen) {
  2317.     appConfig.toolbar.presentationModeButton.classList.add("hidden");
  2318.     appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2319.   }
  2320.  
  2321.   if (PDFViewerApplication.supportsIntegratedFind) {
  2322.     appConfig.toolbar.viewFind.classList.add("hidden");
  2323.   }
  2324.  
  2325.   appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2326.     if (evt.target === this) {
  2327.       PDFViewerApplication.eventBus.dispatch("resize", {
  2328.         source: this
  2329.       });
  2330.     }
  2331.   }, true);
  2332.  
  2333.   try {
  2334.     webViewerOpenFileViaURL(file);
  2335.   } catch (reason) {
  2336.     PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2337.       PDFViewerApplication._documentError(msg, reason);
  2338.     });
  2339.   }
  2340. }
  2341.  
  2342. function webViewerOpenFileViaURL(file) {
  2343.   if (file) {
  2344.     PDFViewerApplication.open(file);
  2345.   }
  2346. }
  2347.  
  2348. function webViewerResetPermissions() {
  2349.   const {
  2350.     appConfig
  2351.   } = PDFViewerApplication;
  2352.  
  2353.   if (!appConfig) {
  2354.     return;
  2355.   }
  2356.  
  2357.   appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  2358. }
  2359.  
  2360. function webViewerPageRendered({
  2361.   pageNumber,
  2362.   timestamp,
  2363.   error
  2364. }) {
  2365.   if (pageNumber === PDFViewerApplication.page) {
  2366.     PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2367.   }
  2368.  
  2369.   if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2370.     const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2371.     const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2372.  
  2373.     if (pageView && thumbnailView) {
  2374.       thumbnailView.setImage(pageView);
  2375.     }
  2376.   }
  2377.  
  2378.   if (error) {
  2379.     PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2380.       PDFViewerApplication._otherError(msg, error);
  2381.     });
  2382.   }
  2383.  
  2384.   PDFViewerApplication.externalServices.reportTelemetry({
  2385.     type: "pageInfo",
  2386.     timestamp
  2387.   });
  2388.   PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  2389.     PDFViewerApplication.externalServices.reportTelemetry({
  2390.       type: "documentStats",
  2391.       stats
  2392.     });
  2393.   });
  2394. }
  2395.  
  2396. function webViewerPageMode({
  2397.   mode
  2398. }) {
  2399.   let view;
  2400.  
  2401.   switch (mode) {
  2402.     case "thumbs":
  2403.       view = _ui_utils.SidebarView.THUMBS;
  2404.       break;
  2405.  
  2406.     case "bookmarks":
  2407.     case "outline":
  2408.       view = _ui_utils.SidebarView.OUTLINE;
  2409.       break;
  2410.  
  2411.     case "attachments":
  2412.       view = _ui_utils.SidebarView.ATTACHMENTS;
  2413.       break;
  2414.  
  2415.     case "layers":
  2416.       view = _ui_utils.SidebarView.LAYERS;
  2417.       break;
  2418.  
  2419.     case "none":
  2420.       view = _ui_utils.SidebarView.NONE;
  2421.       break;
  2422.  
  2423.     default:
  2424.       console.error('Invalid "pagemode" hash parameter: ' + mode);
  2425.       return;
  2426.   }
  2427.  
  2428.   PDFViewerApplication.pdfSidebar.switchView(view, true);
  2429. }
  2430.  
  2431. function webViewerNamedAction(evt) {
  2432.   switch (evt.action) {
  2433.     case "GoToPage":
  2434.       PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2435.       break;
  2436.  
  2437.     case "Find":
  2438.       if (!PDFViewerApplication.supportsIntegratedFind) {
  2439.         PDFViewerApplication.findBar.toggle();
  2440.       }
  2441.  
  2442.       break;
  2443.  
  2444.     case "Print":
  2445.       PDFViewerApplication.triggerPrinting();
  2446.       break;
  2447.  
  2448.     case "SaveAs":
  2449.       webViewerSave();
  2450.       break;
  2451.   }
  2452. }
  2453.  
  2454. function webViewerPresentationModeChanged(evt) {
  2455.   PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2456. }
  2457.  
  2458. function webViewerSidebarViewChanged(evt) {
  2459.   PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  2460.   const store = PDFViewerApplication.store;
  2461.  
  2462.   if (store && PDFViewerApplication.isInitialViewSet) {
  2463.     store.set("sidebarView", evt.view).catch(function () {});
  2464.   }
  2465. }
  2466.  
  2467. function webViewerUpdateViewarea(evt) {
  2468.   const location = evt.location,
  2469.         store = PDFViewerApplication.store;
  2470.  
  2471.   if (store && PDFViewerApplication.isInitialViewSet) {
  2472.     store.setMultiple({
  2473.       page: location.pageNumber,
  2474.       zoom: location.scale,
  2475.       scrollLeft: location.left,
  2476.       scrollTop: location.top,
  2477.       rotation: location.rotation
  2478.     }).catch(function () {});
  2479.   }
  2480.  
  2481.   const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2482.   PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  2483.   PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2484.   const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2485.   const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  2486.   PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2487. }
  2488.  
  2489. function webViewerScrollModeChanged(evt) {
  2490.   const store = PDFViewerApplication.store;
  2491.  
  2492.   if (store && PDFViewerApplication.isInitialViewSet) {
  2493.     store.set("scrollMode", evt.mode).catch(function () {});
  2494.   }
  2495. }
  2496.  
  2497. function webViewerSpreadModeChanged(evt) {
  2498.   const store = PDFViewerApplication.store;
  2499.  
  2500.   if (store && PDFViewerApplication.isInitialViewSet) {
  2501.     store.set("spreadMode", evt.mode).catch(function () {});
  2502.   }
  2503. }
  2504.  
  2505. function webViewerResize() {
  2506.   const {
  2507.     pdfDocument,
  2508.     pdfViewer
  2509.   } = PDFViewerApplication;
  2510.  
  2511.   if (!pdfDocument) {
  2512.     return;
  2513.   }
  2514.  
  2515.   const currentScaleValue = pdfViewer.currentScaleValue;
  2516.  
  2517.   if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2518.     pdfViewer.currentScaleValue = currentScaleValue;
  2519.   }
  2520.  
  2521.   pdfViewer.update();
  2522. }
  2523.  
  2524. function webViewerHashchange(evt) {
  2525.   const hash = evt.hash;
  2526.  
  2527.   if (!hash) {
  2528.     return;
  2529.   }
  2530.  
  2531.   if (!PDFViewerApplication.isInitialViewSet) {
  2532.     PDFViewerApplication.initialBookmark = hash;
  2533.   } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2534.     PDFViewerApplication.pdfLinkService.setHash(hash);
  2535.   }
  2536. }
  2537.  
  2538. let webViewerFileInputChange, webViewerOpenFile;
  2539. {
  2540.   webViewerFileInputChange = function (evt) {
  2541.     if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2542.       return;
  2543.     }
  2544.  
  2545.     const file = evt.fileInput.files[0];
  2546.  
  2547.     if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2548.       let url = URL.createObjectURL(file);
  2549.  
  2550.       if (file.name) {
  2551.         url = {
  2552.           url,
  2553.           originalUrl: file.name
  2554.         };
  2555.       }
  2556.  
  2557.       PDFViewerApplication.open(url);
  2558.     } else {
  2559.       PDFViewerApplication.setTitleUsingUrl(file.name);
  2560.       const fileReader = new FileReader();
  2561.  
  2562.       fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2563.         const buffer = event.target.result;
  2564.         PDFViewerApplication.open(new Uint8Array(buffer));
  2565.       };
  2566.  
  2567.       fileReader.readAsArrayBuffer(file);
  2568.     }
  2569.  
  2570.     const appConfig = PDFViewerApplication.appConfig;
  2571.     appConfig.toolbar.viewBookmark.hidden = true;
  2572.     appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2573.     appConfig.toolbar.download.hidden = true;
  2574.     appConfig.secondaryToolbar.downloadButton.hidden = true;
  2575.   };
  2576.  
  2577.   webViewerOpenFile = function (evt) {
  2578.     const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2579.     document.getElementById(openFileInputName).click();
  2580.   };
  2581. }
  2582.  
  2583. function webViewerPresentationMode() {
  2584.   PDFViewerApplication.requestPresentationMode();
  2585. }
  2586.  
  2587. function webViewerPrint() {
  2588.   PDFViewerApplication.triggerPrinting();
  2589. }
  2590.  
  2591. function webViewerDownload() {
  2592.   PDFViewerApplication.downloadOrSave({
  2593.     sourceEventType: "download"
  2594.   });
  2595. }
  2596.  
  2597. function webViewerSave() {
  2598.   PDFViewerApplication.downloadOrSave({
  2599.     sourceEventType: "save"
  2600.   });
  2601. }
  2602.  
  2603. function webViewerFirstPage() {
  2604.   if (PDFViewerApplication.pdfDocument) {
  2605.     PDFViewerApplication.page = 1;
  2606.   }
  2607. }
  2608.  
  2609. function webViewerLastPage() {
  2610.   if (PDFViewerApplication.pdfDocument) {
  2611.     PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2612.   }
  2613. }
  2614.  
  2615. function webViewerNextPage() {
  2616.   PDFViewerApplication.pdfViewer.nextPage();
  2617. }
  2618.  
  2619. function webViewerPreviousPage() {
  2620.   PDFViewerApplication.pdfViewer.previousPage();
  2621. }
  2622.  
  2623. function webViewerZoomIn() {
  2624.   PDFViewerApplication.zoomIn();
  2625. }
  2626.  
  2627. function webViewerZoomOut() {
  2628.   PDFViewerApplication.zoomOut();
  2629. }
  2630.  
  2631. function webViewerZoomReset() {
  2632.   PDFViewerApplication.zoomReset();
  2633. }
  2634.  
  2635. function webViewerPageNumberChanged(evt) {
  2636.   const pdfViewer = PDFViewerApplication.pdfViewer;
  2637.  
  2638.   if (evt.value !== "") {
  2639.     PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2640.   }
  2641.  
  2642.   if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2643.     PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2644.   }
  2645. }
  2646.  
  2647. function webViewerScaleChanged(evt) {
  2648.   PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2649. }
  2650.  
  2651. function webViewerRotateCw() {
  2652.   PDFViewerApplication.rotatePages(90);
  2653. }
  2654.  
  2655. function webViewerRotateCcw() {
  2656.   PDFViewerApplication.rotatePages(-90);
  2657. }
  2658.  
  2659. function webViewerOptionalContentConfig(evt) {
  2660.   PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2661. }
  2662.  
  2663. function webViewerSwitchScrollMode(evt) {
  2664.   PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2665. }
  2666.  
  2667. function webViewerSwitchSpreadMode(evt) {
  2668.   PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2669. }
  2670.  
  2671. function webViewerDocumentProperties() {
  2672.   PDFViewerApplication.pdfDocumentProperties.open();
  2673. }
  2674.  
  2675. function webViewerFind(evt) {
  2676.   PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2677.     query: evt.query,
  2678.     phraseSearch: evt.phraseSearch,
  2679.     caseSensitive: evt.caseSensitive,
  2680.     entireWord: evt.entireWord,
  2681.     highlightAll: evt.highlightAll,
  2682.     findPrevious: evt.findPrevious
  2683.   });
  2684. }
  2685.  
  2686. function webViewerFindFromUrlHash(evt) {
  2687.   PDFViewerApplication.findController.executeCommand("find", {
  2688.     query: evt.query,
  2689.     phraseSearch: evt.phraseSearch,
  2690.     caseSensitive: false,
  2691.     entireWord: false,
  2692.     highlightAll: true,
  2693.     findPrevious: false
  2694.   });
  2695. }
  2696.  
  2697. function webViewerUpdateFindMatchesCount({
  2698.   matchesCount
  2699. }) {
  2700.   if (PDFViewerApplication.supportsIntegratedFind) {
  2701.     PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2702.   } else {
  2703.     PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2704.   }
  2705. }
  2706.  
  2707. function webViewerUpdateFindControlState({
  2708.   state,
  2709.   previous,
  2710.   matchesCount,
  2711.   rawQuery
  2712. }) {
  2713.   if (PDFViewerApplication.supportsIntegratedFind) {
  2714.     PDFViewerApplication.externalServices.updateFindControlState({
  2715.       result: state,
  2716.       findPrevious: previous,
  2717.       matchesCount,
  2718.       rawQuery
  2719.     });
  2720.   } else {
  2721.     PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2722.   }
  2723. }
  2724.  
  2725. function webViewerScaleChanging(evt) {
  2726.   PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2727.   PDFViewerApplication.pdfViewer.update();
  2728. }
  2729.  
  2730. function webViewerRotationChanging(evt) {
  2731.   PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2732.   PDFViewerApplication.forceRendering();
  2733.   PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2734. }
  2735.  
  2736. function webViewerPageChanging({
  2737.   pageNumber,
  2738.   pageLabel
  2739. }) {
  2740.   PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2741.   PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2742.  
  2743.   if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2744.     PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2745.   }
  2746. }
  2747.  
  2748. function webViewerVisibilityChange(evt) {
  2749.   if (document.visibilityState === "visible") {
  2750.     setZoomDisabledTimeout();
  2751.   }
  2752. }
  2753.  
  2754. let zoomDisabledTimeout = null;
  2755.  
  2756. function setZoomDisabledTimeout() {
  2757.   if (zoomDisabledTimeout) {
  2758.     clearTimeout(zoomDisabledTimeout);
  2759.   }
  2760.  
  2761.   zoomDisabledTimeout = setTimeout(function () {
  2762.     zoomDisabledTimeout = null;
  2763.   }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2764. }
  2765.  
  2766. function webViewerWheel(evt) {
  2767.   const {
  2768.     pdfViewer,
  2769.     supportedMouseWheelZoomModifierKeys
  2770.   } = PDFViewerApplication;
  2771.  
  2772.   if (pdfViewer.isInPresentationMode) {
  2773.     return;
  2774.   }
  2775.  
  2776.   if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2777.     evt.preventDefault();
  2778.  
  2779.     if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2780.       return;
  2781.     }
  2782.  
  2783.     const previousScale = pdfViewer.currentScale;
  2784.     const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2785.     let ticks = 0;
  2786.  
  2787.     if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2788.       if (Math.abs(delta) >= 1) {
  2789.         ticks = Math.sign(delta);
  2790.       } else {
  2791.         ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2792.       }
  2793.     } else {
  2794.       const PIXELS_PER_LINE_SCALE = 30;
  2795.       ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2796.     }
  2797.  
  2798.     if (ticks < 0) {
  2799.       PDFViewerApplication.zoomOut(-ticks);
  2800.     } else if (ticks > 0) {
  2801.       PDFViewerApplication.zoomIn(ticks);
  2802.     }
  2803.  
  2804.     const currentScale = pdfViewer.currentScale;
  2805.  
  2806.     if (previousScale !== currentScale) {
  2807.       const scaleCorrectionFactor = currentScale / previousScale - 1;
  2808.       const rect = pdfViewer.container.getBoundingClientRect();
  2809.       const dx = evt.clientX - rect.left;
  2810.       const dy = evt.clientY - rect.top;
  2811.       pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2812.       pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2813.     }
  2814.   } else {
  2815.     setZoomDisabledTimeout();
  2816.   }
  2817. }
  2818.  
  2819. function webViewerTouchStart(evt) {
  2820.   if (evt.touches.length > 1) {
  2821.     evt.preventDefault();
  2822.   }
  2823. }
  2824.  
  2825. function webViewerClick(evt) {
  2826.   if (PDFViewerApplication.triggerDelayedFallback && PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
  2827.     PDFViewerApplication.triggerDelayedFallback();
  2828.   }
  2829.  
  2830.   if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2831.     return;
  2832.   }
  2833.  
  2834.   const appConfig = PDFViewerApplication.appConfig;
  2835.  
  2836.   if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2837.     PDFViewerApplication.secondaryToolbar.close();
  2838.   }
  2839. }
  2840.  
  2841. function webViewerKeyUp(evt) {
  2842.   if (evt.keyCode === 9) {
  2843.     if (PDFViewerApplication.triggerDelayedFallback) {
  2844.       PDFViewerApplication.triggerDelayedFallback();
  2845.     }
  2846.   }
  2847. }
  2848.  
  2849. function webViewerKeyDown(evt) {
  2850.   if (PDFViewerApplication.overlayManager.active) {
  2851.     return;
  2852.   }
  2853.  
  2854.   let handled = false,
  2855.       ensureViewerFocused = false;
  2856.   const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2857.   const pdfViewer = PDFViewerApplication.pdfViewer;
  2858.   const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2859.  
  2860.   if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2861.     switch (evt.keyCode) {
  2862.       case 70:
  2863.         if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2864.           PDFViewerApplication.findBar.open();
  2865.           handled = true;
  2866.         }
  2867.  
  2868.         break;
  2869.  
  2870.       case 71:
  2871.         if (!PDFViewerApplication.supportsIntegratedFind) {
  2872.           const findState = PDFViewerApplication.findController.state;
  2873.  
  2874.           if (findState) {
  2875.             PDFViewerApplication.findController.executeCommand("findagain", {
  2876.               query: findState.query,
  2877.               phraseSearch: findState.phraseSearch,
  2878.               caseSensitive: findState.caseSensitive,
  2879.               entireWord: findState.entireWord,
  2880.               highlightAll: findState.highlightAll,
  2881.               findPrevious: cmd === 5 || cmd === 12
  2882.             });
  2883.           }
  2884.  
  2885.           handled = true;
  2886.         }
  2887.  
  2888.         break;
  2889.  
  2890.       case 61:
  2891.       case 107:
  2892.       case 187:
  2893.       case 171:
  2894.         if (!isViewerInPresentationMode) {
  2895.           PDFViewerApplication.zoomIn();
  2896.         }
  2897.  
  2898.         handled = true;
  2899.         break;
  2900.  
  2901.       case 173:
  2902.       case 109:
  2903.       case 189:
  2904.         if (!isViewerInPresentationMode) {
  2905.           PDFViewerApplication.zoomOut();
  2906.         }
  2907.  
  2908.         handled = true;
  2909.         break;
  2910.  
  2911.       case 48:
  2912.       case 96:
  2913.         if (!isViewerInPresentationMode) {
  2914.           setTimeout(function () {
  2915.             PDFViewerApplication.zoomReset();
  2916.           });
  2917.           handled = false;
  2918.         }
  2919.  
  2920.         break;
  2921.  
  2922.       case 38:
  2923.         if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2924.           PDFViewerApplication.page = 1;
  2925.           handled = true;
  2926.           ensureViewerFocused = true;
  2927.         }
  2928.  
  2929.         break;
  2930.  
  2931.       case 40:
  2932.         if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2933.           PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2934.           handled = true;
  2935.           ensureViewerFocused = true;
  2936.         }
  2937.  
  2938.         break;
  2939.     }
  2940.   }
  2941.  
  2942.   const {
  2943.     eventBus
  2944.   } = PDFViewerApplication;
  2945.  
  2946.   if (cmd === 1 || cmd === 8) {
  2947.     switch (evt.keyCode) {
  2948.       case 83:
  2949.         eventBus.dispatch("download", {
  2950.           source: window
  2951.         });
  2952.         handled = true;
  2953.         break;
  2954.  
  2955.       case 79:
  2956.         {
  2957.           eventBus.dispatch("openfile", {
  2958.             source: window
  2959.           });
  2960.           handled = true;
  2961.         }
  2962.         break;
  2963.     }
  2964.   }
  2965.  
  2966.   if (cmd === 3 || cmd === 10) {
  2967.     switch (evt.keyCode) {
  2968.       case 80:
  2969.         PDFViewerApplication.requestPresentationMode();
  2970.         handled = true;
  2971.         break;
  2972.  
  2973.       case 71:
  2974.         PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2975.         handled = true;
  2976.         break;
  2977.     }
  2978.   }
  2979.  
  2980.   if (handled) {
  2981.     if (ensureViewerFocused && !isViewerInPresentationMode) {
  2982.       pdfViewer.focus();
  2983.     }
  2984.  
  2985.     evt.preventDefault();
  2986.     return;
  2987.   }
  2988.  
  2989.   const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2990.   const curElementTagName = curElement?.tagName.toUpperCase();
  2991.  
  2992.   if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2993.     if (evt.keyCode !== 27) {
  2994.       return;
  2995.     }
  2996.   }
  2997.  
  2998.   if (cmd === 0) {
  2999.     let turnPage = 0,
  3000.         turnOnlyIfPageFit = false;
  3001.  
  3002.     switch (evt.keyCode) {
  3003.       case 38:
  3004.       case 33:
  3005.         if (pdfViewer.isVerticalScrollbarEnabled) {
  3006.           turnOnlyIfPageFit = true;
  3007.         }
  3008.  
  3009.         turnPage = -1;
  3010.         break;
  3011.  
  3012.       case 8:
  3013.         if (!isViewerInPresentationMode) {
  3014.           turnOnlyIfPageFit = true;
  3015.         }
  3016.  
  3017.         turnPage = -1;
  3018.         break;
  3019.  
  3020.       case 37:
  3021.         if (pdfViewer.isHorizontalScrollbarEnabled) {
  3022.           turnOnlyIfPageFit = true;
  3023.         }
  3024.  
  3025.       case 75:
  3026.       case 80:
  3027.         turnPage = -1;
  3028.         break;
  3029.  
  3030.       case 27:
  3031.         if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3032.           PDFViewerApplication.secondaryToolbar.close();
  3033.           handled = true;
  3034.         }
  3035.  
  3036.         if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3037.           PDFViewerApplication.findBar.close();
  3038.           handled = true;
  3039.         }
  3040.  
  3041.         break;
  3042.  
  3043.       case 40:
  3044.       case 34:
  3045.         if (pdfViewer.isVerticalScrollbarEnabled) {
  3046.           turnOnlyIfPageFit = true;
  3047.         }
  3048.  
  3049.         turnPage = 1;
  3050.         break;
  3051.  
  3052.       case 13:
  3053.       case 32:
  3054.         if (!isViewerInPresentationMode) {
  3055.           turnOnlyIfPageFit = true;
  3056.         }
  3057.  
  3058.         turnPage = 1;
  3059.         break;
  3060.  
  3061.       case 39:
  3062.         if (pdfViewer.isHorizontalScrollbarEnabled) {
  3063.           turnOnlyIfPageFit = true;
  3064.         }
  3065.  
  3066.       case 74:
  3067.       case 78:
  3068.         turnPage = 1;
  3069.         break;
  3070.  
  3071.       case 36:
  3072.         if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3073.           PDFViewerApplication.page = 1;
  3074.           handled = true;
  3075.           ensureViewerFocused = true;
  3076.         }
  3077.  
  3078.         break;
  3079.  
  3080.       case 35:
  3081.         if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3082.           PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3083.           handled = true;
  3084.           ensureViewerFocused = true;
  3085.         }
  3086.  
  3087.         break;
  3088.  
  3089.       case 83:
  3090.         PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3091.         break;
  3092.  
  3093.       case 72:
  3094.         PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3095.         break;
  3096.  
  3097.       case 82:
  3098.         PDFViewerApplication.rotatePages(90);
  3099.         break;
  3100.  
  3101.       case 115:
  3102.         PDFViewerApplication.pdfSidebar.toggle();
  3103.         break;
  3104.     }
  3105.  
  3106.     if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3107.       if (turnPage > 0) {
  3108.         pdfViewer.nextPage();
  3109.       } else {
  3110.         pdfViewer.previousPage();
  3111.       }
  3112.  
  3113.       handled = true;
  3114.     }
  3115.   }
  3116.  
  3117.   if (cmd === 4) {
  3118.     switch (evt.keyCode) {
  3119.       case 13:
  3120.       case 32:
  3121.         if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3122.           break;
  3123.         }
  3124.  
  3125.         if (PDFViewerApplication.page > 1) {
  3126.           PDFViewerApplication.page--;
  3127.         }
  3128.  
  3129.         handled = true;
  3130.         break;
  3131.  
  3132.       case 82:
  3133.         PDFViewerApplication.rotatePages(-90);
  3134.         break;
  3135.     }
  3136.   }
  3137.  
  3138.   if (!handled && !isViewerInPresentationMode) {
  3139.     if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3140.       ensureViewerFocused = true;
  3141.     }
  3142.   }
  3143.  
  3144.   if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3145.     pdfViewer.focus();
  3146.   }
  3147.  
  3148.   if (handled) {
  3149.     evt.preventDefault();
  3150.   }
  3151. }
  3152.  
  3153. function beforeUnload(evt) {
  3154.   evt.preventDefault();
  3155.   evt.returnValue = "";
  3156.   return false;
  3157. }
  3158.  
  3159. const PDFPrintServiceFactory = {
  3160.   instance: {
  3161.     supportsPrinting: false,
  3162.  
  3163.     createPrintService() {
  3164.       throw new Error("Not implemented: createPrintService");
  3165.     }
  3166.  
  3167.   }
  3168. };
  3169. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3170.  
  3171. /***/ }),
  3172. /* 4 */
  3173. /***/ ((__unused_webpack_module, exports) => {
  3174.  
  3175.  
  3176.  
  3177. Object.defineProperty(exports, "__esModule", ({
  3178.   value: true
  3179. }));
  3180. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  3181. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  3182. exports.approximateFraction = approximateFraction;
  3183. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  3184. exports.binarySearchFirstItem = binarySearchFirstItem;
  3185. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  3186. exports.getOutputScale = getOutputScale;
  3187. exports.getPageSizeInches = getPageSizeInches;
  3188. exports.getVisibleElements = getVisibleElements;
  3189. exports.isPortraitOrientation = isPortraitOrientation;
  3190. exports.isValidRotation = isValidRotation;
  3191. exports.isValidScrollMode = isValidScrollMode;
  3192. exports.isValidSpreadMode = isValidSpreadMode;
  3193. exports.moveToEndOfArray = moveToEndOfArray;
  3194. exports.noContextMenuHandler = noContextMenuHandler;
  3195. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  3196. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  3197. exports.parseQueryString = parseQueryString;
  3198. exports.roundToDivide = roundToDivide;
  3199. exports.scrollIntoView = scrollIntoView;
  3200. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3201. exports.watchScroll = watchScroll;
  3202. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  3203. const CSS_UNITS = 96.0 / 72.0;
  3204. exports.CSS_UNITS = CSS_UNITS;
  3205. const DEFAULT_SCALE_VALUE = "auto";
  3206. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  3207. const DEFAULT_SCALE = 1.0;
  3208. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  3209. const MIN_SCALE = 0.1;
  3210. exports.MIN_SCALE = MIN_SCALE;
  3211. const MAX_SCALE = 10.0;
  3212. exports.MAX_SCALE = MAX_SCALE;
  3213. const UNKNOWN_SCALE = 0;
  3214. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  3215. const MAX_AUTO_SCALE = 1.25;
  3216. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  3217. const SCROLLBAR_PADDING = 40;
  3218. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  3219. const VERTICAL_PADDING = 5;
  3220. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  3221. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  3222. const PresentationModeState = {
  3223.   UNKNOWN: 0,
  3224.   NORMAL: 1,
  3225.   CHANGING: 2,
  3226.   FULLSCREEN: 3
  3227. };
  3228. exports.PresentationModeState = PresentationModeState;
  3229. const SidebarView = {
  3230.   UNKNOWN: -1,
  3231.   NONE: 0,
  3232.   THUMBS: 1,
  3233.   OUTLINE: 2,
  3234.   ATTACHMENTS: 3,
  3235.   LAYERS: 4
  3236. };
  3237. exports.SidebarView = SidebarView;
  3238. const RendererType = {
  3239.   CANVAS: "canvas",
  3240.   SVG: "svg"
  3241. };
  3242. exports.RendererType = RendererType;
  3243. const TextLayerMode = {
  3244.   DISABLE: 0,
  3245.   ENABLE: 1,
  3246.   ENABLE_ENHANCE: 2
  3247. };
  3248. exports.TextLayerMode = TextLayerMode;
  3249. const ScrollMode = {
  3250.   UNKNOWN: -1,
  3251.   VERTICAL: 0,
  3252.   HORIZONTAL: 1,
  3253.   WRAPPED: 2
  3254. };
  3255. exports.ScrollMode = ScrollMode;
  3256. const SpreadMode = {
  3257.   UNKNOWN: -1,
  3258.   NONE: 0,
  3259.   ODD: 1,
  3260.   EVEN: 2
  3261. };
  3262. exports.SpreadMode = SpreadMode;
  3263. const AutoPrintRegExp = /\bprint\s*\(/;
  3264. exports.AutoPrintRegExp = AutoPrintRegExp;
  3265.  
  3266. function getOutputScale(ctx) {
  3267.   const devicePixelRatio = window.devicePixelRatio || 1;
  3268.   const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  3269.   const pixelRatio = devicePixelRatio / backingStoreRatio;
  3270.   return {
  3271.     sx: pixelRatio,
  3272.     sy: pixelRatio,
  3273.     scaled: pixelRatio !== 1
  3274.   };
  3275. }
  3276.  
  3277. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  3278.   let parent = element.offsetParent;
  3279.  
  3280.   if (!parent) {
  3281.     console.error("offsetParent is not set -- cannot scroll");
  3282.     return;
  3283.   }
  3284.  
  3285.   let offsetY = element.offsetTop + element.clientTop;
  3286.   let offsetX = element.offsetLeft + element.clientLeft;
  3287.  
  3288.   while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  3289.     if (parent.dataset._scaleY) {
  3290.       offsetY /= parent.dataset._scaleY;
  3291.       offsetX /= parent.dataset._scaleX;
  3292.     }
  3293.  
  3294.     offsetY += parent.offsetTop;
  3295.     offsetX += parent.offsetLeft;
  3296.     parent = parent.offsetParent;
  3297.  
  3298.     if (!parent) {
  3299.       return;
  3300.     }
  3301.   }
  3302.  
  3303.   if (spot) {
  3304.     if (spot.top !== undefined) {
  3305.       offsetY += spot.top;
  3306.     }
  3307.  
  3308.     if (spot.left !== undefined) {
  3309.       offsetX += spot.left;
  3310.       parent.scrollLeft = offsetX;
  3311.     }
  3312.   }
  3313.  
  3314.   parent.scrollTop = offsetY;
  3315. }
  3316.  
  3317. function watchScroll(viewAreaElement, callback) {
  3318.   const debounceScroll = function (evt) {
  3319.     if (rAF) {
  3320.       return;
  3321.     }
  3322.  
  3323.     rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  3324.       rAF = null;
  3325.       const currentX = viewAreaElement.scrollLeft;
  3326.       const lastX = state.lastX;
  3327.  
  3328.       if (currentX !== lastX) {
  3329.         state.right = currentX > lastX;
  3330.       }
  3331.  
  3332.       state.lastX = currentX;
  3333.       const currentY = viewAreaElement.scrollTop;
  3334.       const lastY = state.lastY;
  3335.  
  3336.       if (currentY !== lastY) {
  3337.         state.down = currentY > lastY;
  3338.       }
  3339.  
  3340.       state.lastY = currentY;
  3341.       callback(state);
  3342.     });
  3343.   };
  3344.  
  3345.   const state = {
  3346.     right: true,
  3347.     down: true,
  3348.     lastX: viewAreaElement.scrollLeft,
  3349.     lastY: viewAreaElement.scrollTop,
  3350.     _eventHandler: debounceScroll
  3351.   };
  3352.   let rAF = null;
  3353.   viewAreaElement.addEventListener("scroll", debounceScroll, true);
  3354.   return state;
  3355. }
  3356.  
  3357. function parseQueryString(query) {
  3358.   const parts = query.split("&");
  3359.   const params = Object.create(null);
  3360.  
  3361.   for (let i = 0, ii = parts.length; i < ii; ++i) {
  3362.     const param = parts[i].split("=");
  3363.     const key = param[0].toLowerCase();
  3364.     const value = param.length > 1 ? param[1] : null;
  3365.     params[decodeURIComponent(key)] = decodeURIComponent(value);
  3366.   }
  3367.  
  3368.   return params;
  3369. }
  3370.  
  3371. function binarySearchFirstItem(items, condition) {
  3372.   let minIndex = 0;
  3373.   let maxIndex = items.length - 1;
  3374.  
  3375.   if (maxIndex < 0 || !condition(items[maxIndex])) {
  3376.     return items.length;
  3377.   }
  3378.  
  3379.   if (condition(items[minIndex])) {
  3380.     return minIndex;
  3381.   }
  3382.  
  3383.   while (minIndex < maxIndex) {
  3384.     const currentIndex = minIndex + maxIndex >> 1;
  3385.     const currentItem = items[currentIndex];
  3386.  
  3387.     if (condition(currentItem)) {
  3388.       maxIndex = currentIndex;
  3389.     } else {
  3390.       minIndex = currentIndex + 1;
  3391.     }
  3392.   }
  3393.  
  3394.   return minIndex;
  3395. }
  3396.  
  3397. function approximateFraction(x) {
  3398.   if (Math.floor(x) === x) {
  3399.     return [x, 1];
  3400.   }
  3401.  
  3402.   const xinv = 1 / x;
  3403.   const limit = 8;
  3404.  
  3405.   if (xinv > limit) {
  3406.     return [1, limit];
  3407.   } else if (Math.floor(xinv) === xinv) {
  3408.     return [1, xinv];
  3409.   }
  3410.  
  3411.   const x_ = x > 1 ? xinv : x;
  3412.   let a = 0,
  3413.       b = 1,
  3414.       c = 1,
  3415.       d = 1;
  3416.  
  3417.   while (true) {
  3418.     const p = a + c,
  3419.           q = b + d;
  3420.  
  3421.     if (q > limit) {
  3422.       break;
  3423.     }
  3424.  
  3425.     if (x_ <= p / q) {
  3426.       c = p;
  3427.       d = q;
  3428.     } else {
  3429.       a = p;
  3430.       b = q;
  3431.     }
  3432.   }
  3433.  
  3434.   let result;
  3435.  
  3436.   if (x_ - a / b < c / d - x_) {
  3437.     result = x_ === x ? [a, b] : [b, a];
  3438.   } else {
  3439.     result = x_ === x ? [c, d] : [d, c];
  3440.   }
  3441.  
  3442.   return result;
  3443. }
  3444.  
  3445. function roundToDivide(x, div) {
  3446.   const r = x % div;
  3447.   return r === 0 ? x : Math.round(x - r + div);
  3448. }
  3449.  
  3450. function getPageSizeInches({
  3451.   view,
  3452.   userUnit,
  3453.   rotate
  3454. }) {
  3455.   const [x1, y1, x2, y2] = view;
  3456.   const changeOrientation = rotate % 180 !== 0;
  3457.   const width = (x2 - x1) / 72 * userUnit;
  3458.   const height = (y2 - y1) / 72 * userUnit;
  3459.   return {
  3460.     width: changeOrientation ? height : width,
  3461.     height: changeOrientation ? width : height
  3462.   };
  3463. }
  3464.  
  3465. function backtrackBeforeAllVisibleElements(index, views, top) {
  3466.   if (index < 2) {
  3467.     return index;
  3468.   }
  3469.  
  3470.   let elt = views[index].div;
  3471.   let pageTop = elt.offsetTop + elt.clientTop;
  3472.  
  3473.   if (pageTop >= top) {
  3474.     elt = views[index - 1].div;
  3475.     pageTop = elt.offsetTop + elt.clientTop;
  3476.   }
  3477.  
  3478.   for (let i = index - 2; i >= 0; --i) {
  3479.     elt = views[i].div;
  3480.  
  3481.     if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  3482.       break;
  3483.     }
  3484.  
  3485.     index = i;
  3486.   }
  3487.  
  3488.   return index;
  3489. }
  3490.  
  3491. function getVisibleElements({
  3492.   scrollEl,
  3493.   views,
  3494.   sortByVisibility = false,
  3495.   horizontal = false,
  3496.   rtl = false
  3497. }) {
  3498.   const top = scrollEl.scrollTop,
  3499.         bottom = top + scrollEl.clientHeight;
  3500.   const left = scrollEl.scrollLeft,
  3501.         right = left + scrollEl.clientWidth;
  3502.  
  3503.   function isElementBottomAfterViewTop(view) {
  3504.     const element = view.div;
  3505.     const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  3506.     return elementBottom > top;
  3507.   }
  3508.  
  3509.   function isElementNextAfterViewHorizontally(view) {
  3510.     const element = view.div;
  3511.     const elementLeft = element.offsetLeft + element.clientLeft;
  3512.     const elementRight = elementLeft + element.clientWidth;
  3513.     return rtl ? elementLeft < right : elementRight > left;
  3514.   }
  3515.  
  3516.   const visible = [],
  3517.         numViews = views.length;
  3518.   let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  3519.  
  3520.   if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  3521.     firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  3522.   }
  3523.  
  3524.   let lastEdge = horizontal ? right : -1;
  3525.  
  3526.   for (let i = firstVisibleElementInd; i < numViews; i++) {
  3527.     const view = views[i],
  3528.           element = view.div;
  3529.     const currentWidth = element.offsetLeft + element.clientLeft;
  3530.     const currentHeight = element.offsetTop + element.clientTop;
  3531.     const viewWidth = element.clientWidth,
  3532.           viewHeight = element.clientHeight;
  3533.     const viewRight = currentWidth + viewWidth;
  3534.     const viewBottom = currentHeight + viewHeight;
  3535.  
  3536.     if (lastEdge === -1) {
  3537.       if (viewBottom >= bottom) {
  3538.         lastEdge = viewBottom;
  3539.       }
  3540.     } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  3541.       break;
  3542.     }
  3543.  
  3544.     if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  3545.       continue;
  3546.     }
  3547.  
  3548.     const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  3549.     const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  3550.     const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  3551.           fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  3552.     const percent = fractionHeight * fractionWidth * 100 | 0;
  3553.     visible.push({
  3554.       id: view.id,
  3555.       x: currentWidth,
  3556.       y: currentHeight,
  3557.       view,
  3558.       percent,
  3559.       widthPercent: fractionWidth * 100 | 0
  3560.     });
  3561.   }
  3562.  
  3563.   const first = visible[0],
  3564.         last = visible[visible.length - 1];
  3565.  
  3566.   if (sortByVisibility) {
  3567.     visible.sort(function (a, b) {
  3568.       const pc = a.percent - b.percent;
  3569.  
  3570.       if (Math.abs(pc) > 0.001) {
  3571.         return -pc;
  3572.       }
  3573.  
  3574.       return a.id - b.id;
  3575.     });
  3576.   }
  3577.  
  3578.   return {
  3579.     first,
  3580.     last,
  3581.     views: visible
  3582.   };
  3583. }
  3584.  
  3585. function noContextMenuHandler(evt) {
  3586.   evt.preventDefault();
  3587. }
  3588.  
  3589. function normalizeWheelEventDirection(evt) {
  3590.   let delta = Math.hypot(evt.deltaX, evt.deltaY);
  3591.   const angle = Math.atan2(evt.deltaY, evt.deltaX);
  3592.  
  3593.   if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  3594.     delta = -delta;
  3595.   }
  3596.  
  3597.   return delta;
  3598. }
  3599.  
  3600. function normalizeWheelEventDelta(evt) {
  3601.   let delta = normalizeWheelEventDirection(evt);
  3602.   const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  3603.   const MOUSE_DOM_DELTA_LINE_MODE = 1;
  3604.   const MOUSE_PIXELS_PER_LINE = 30;
  3605.   const MOUSE_LINES_PER_PAGE = 30;
  3606.  
  3607.   if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  3608.     delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  3609.   } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  3610.     delta /= MOUSE_LINES_PER_PAGE;
  3611.   }
  3612.  
  3613.   return delta;
  3614. }
  3615.  
  3616. function isValidRotation(angle) {
  3617.   return Number.isInteger(angle) && angle % 90 === 0;
  3618. }
  3619.  
  3620. function isValidScrollMode(mode) {
  3621.   return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  3622. }
  3623.  
  3624. function isValidSpreadMode(mode) {
  3625.   return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  3626. }
  3627.  
  3628. function isPortraitOrientation(size) {
  3629.   return size.width <= size.height;
  3630. }
  3631.  
  3632. const WaitOnType = {
  3633.   EVENT: "event",
  3634.   TIMEOUT: "timeout"
  3635. };
  3636. exports.WaitOnType = WaitOnType;
  3637.  
  3638. function waitOnEventOrTimeout({
  3639.   target,
  3640.   name,
  3641.   delay = 0
  3642. }) {
  3643.   return new Promise(function (resolve, reject) {
  3644.     if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3645.       throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3646.     }
  3647.  
  3648.     function handler(type) {
  3649.       if (target instanceof EventBus) {
  3650.         target._off(name, eventHandler);
  3651.       } else {
  3652.         target.removeEventListener(name, eventHandler);
  3653.       }
  3654.  
  3655.       if (timeout) {
  3656.         clearTimeout(timeout);
  3657.       }
  3658.  
  3659.       resolve(type);
  3660.     }
  3661.  
  3662.     const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3663.  
  3664.     if (target instanceof EventBus) {
  3665.       target._on(name, eventHandler);
  3666.     } else {
  3667.       target.addEventListener(name, eventHandler);
  3668.     }
  3669.  
  3670.     const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3671.     const timeout = setTimeout(timeoutHandler, delay);
  3672.   });
  3673. }
  3674.  
  3675. const animationStarted = new Promise(function (resolve) {
  3676.   window.requestAnimationFrame(resolve);
  3677. });
  3678. exports.animationStarted = animationStarted;
  3679.  
  3680. function dispatchDOMEvent(eventName, args = null) {
  3681.   throw new Error("Not implemented: dispatchDOMEvent");
  3682. }
  3683.  
  3684. class EventBus {
  3685.   constructor(options) {
  3686.     this._listeners = Object.create(null);
  3687.   }
  3688.  
  3689.   on(eventName, listener, options = null) {
  3690.     this._on(eventName, listener, {
  3691.       external: true,
  3692.       once: options?.once
  3693.     });
  3694.   }
  3695.  
  3696.   off(eventName, listener, options = null) {
  3697.     this._off(eventName, listener, {
  3698.       external: true,
  3699.       once: options?.once
  3700.     });
  3701.   }
  3702.  
  3703.   dispatch(eventName) {
  3704.     const eventListeners = this._listeners[eventName];
  3705.  
  3706.     if (!eventListeners || eventListeners.length === 0) {
  3707.       return;
  3708.     }
  3709.  
  3710.     const args = Array.prototype.slice.call(arguments, 1);
  3711.     let externalListeners;
  3712.     eventListeners.slice(0).forEach(({
  3713.       listener,
  3714.       external,
  3715.       once
  3716.     }) => {
  3717.       if (once) {
  3718.         this._off(eventName, listener);
  3719.       }
  3720.  
  3721.       if (external) {
  3722.         (externalListeners || (externalListeners = [])).push(listener);
  3723.         return;
  3724.       }
  3725.  
  3726.       listener.apply(null, args);
  3727.     });
  3728.  
  3729.     if (externalListeners) {
  3730.       externalListeners.forEach(listener => {
  3731.         listener.apply(null, args);
  3732.       });
  3733.       externalListeners = null;
  3734.     }
  3735.   }
  3736.  
  3737.   _on(eventName, listener, options = null) {
  3738.     var _this$_listeners;
  3739.  
  3740.     const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  3741.     eventListeners.push({
  3742.       listener,
  3743.       external: options?.external === true,
  3744.       once: options?.once === true
  3745.     });
  3746.   }
  3747.  
  3748.   _off(eventName, listener, options = null) {
  3749.     const eventListeners = this._listeners[eventName];
  3750.  
  3751.     if (!eventListeners) {
  3752.       return;
  3753.     }
  3754.  
  3755.     for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3756.       if (eventListeners[i].listener === listener) {
  3757.         eventListeners.splice(i, 1);
  3758.         return;
  3759.       }
  3760.     }
  3761.   }
  3762.  
  3763. }
  3764.  
  3765. exports.EventBus = EventBus;
  3766.  
  3767. function clamp(v, min, max) {
  3768.   return Math.min(Math.max(v, min), max);
  3769. }
  3770.  
  3771. class ProgressBar {
  3772.   constructor(id, {
  3773.     height,
  3774.     width,
  3775.     units
  3776.   } = {}) {
  3777.     this.visible = true;
  3778.     this.div = document.querySelector(id + " .progress");
  3779.     this.bar = this.div.parentNode;
  3780.     this.height = height || 100;
  3781.     this.width = width || 100;
  3782.     this.units = units || "%";
  3783.     this.div.style.height = this.height + this.units;
  3784.     this.percent = 0;
  3785.   }
  3786.  
  3787.   _updateBar() {
  3788.     if (this._indeterminate) {
  3789.       this.div.classList.add("indeterminate");
  3790.       this.div.style.width = this.width + this.units;
  3791.       return;
  3792.     }
  3793.  
  3794.     this.div.classList.remove("indeterminate");
  3795.     const progressSize = this.width * this._percent / 100;
  3796.     this.div.style.width = progressSize + this.units;
  3797.   }
  3798.  
  3799.   get percent() {
  3800.     return this._percent;
  3801.   }
  3802.  
  3803.   set percent(val) {
  3804.     this._indeterminate = isNaN(val);
  3805.     this._percent = clamp(val, 0, 100);
  3806.  
  3807.     this._updateBar();
  3808.   }
  3809.  
  3810.   setWidth(viewer) {
  3811.     if (!viewer) {
  3812.       return;
  3813.     }
  3814.  
  3815.     const container = viewer.parentNode;
  3816.     const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3817.  
  3818.     if (scrollbarWidth > 0) {
  3819.       const doc = document.documentElement;
  3820.       doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3821.     }
  3822.   }
  3823.  
  3824.   hide() {
  3825.     if (!this.visible) {
  3826.       return;
  3827.     }
  3828.  
  3829.     this.visible = false;
  3830.     this.bar.classList.add("hidden");
  3831.   }
  3832.  
  3833.   show() {
  3834.     if (this.visible) {
  3835.       return;
  3836.     }
  3837.  
  3838.     this.visible = true;
  3839.     this.bar.classList.remove("hidden");
  3840.   }
  3841.  
  3842. }
  3843.  
  3844. exports.ProgressBar = ProgressBar;
  3845.  
  3846. function moveToEndOfArray(arr, condition) {
  3847.   const moved = [],
  3848.         len = arr.length;
  3849.   let write = 0;
  3850.  
  3851.   for (let read = 0; read < len; ++read) {
  3852.     if (condition(arr[read])) {
  3853.       moved.push(arr[read]);
  3854.     } else {
  3855.       arr[write] = arr[read];
  3856.       ++write;
  3857.     }
  3858.   }
  3859.  
  3860.   for (let read = 0; write < len; ++read, ++write) {
  3861.     arr[write] = moved[read];
  3862.   }
  3863. }
  3864.  
  3865. function getActiveOrFocusedElement() {
  3866.   let curRoot = document;
  3867.   let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3868.  
  3869.   while (curActiveOrFocused?.shadowRoot) {
  3870.     curRoot = curActiveOrFocused.shadowRoot;
  3871.     curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3872.   }
  3873.  
  3874.   return curActiveOrFocused;
  3875. }
  3876.  
  3877. function apiPageLayoutToSpreadMode(layout) {
  3878.   switch (layout) {
  3879.     case "SinglePage":
  3880.     case "OneColumn":
  3881.       return SpreadMode.NONE;
  3882.  
  3883.     case "TwoColumnLeft":
  3884.     case "TwoPageLeft":
  3885.       return SpreadMode.ODD;
  3886.  
  3887.     case "TwoColumnRight":
  3888.     case "TwoPageRight":
  3889.       return SpreadMode.EVEN;
  3890.   }
  3891.  
  3892.   return SpreadMode.NONE;
  3893. }
  3894.  
  3895. function apiPageModeToSidebarView(mode) {
  3896.   switch (mode) {
  3897.     case "UseNone":
  3898.       return SidebarView.NONE;
  3899.  
  3900.     case "UseThumbs":
  3901.       return SidebarView.THUMBS;
  3902.  
  3903.     case "UseOutlines":
  3904.       return SidebarView.OUTLINE;
  3905.  
  3906.     case "UseAttachments":
  3907.       return SidebarView.ATTACHMENTS;
  3908.  
  3909.     case "UseOC":
  3910.       return SidebarView.LAYERS;
  3911.   }
  3912.  
  3913.   return SidebarView.NONE;
  3914. }
  3915.  
  3916. /***/ }),
  3917. /* 5 */
  3918. /***/ ((module) => {
  3919.  
  3920.  
  3921.  
  3922. let pdfjsLib;
  3923.  
  3924. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3925.   pdfjsLib = window["pdfjs-dist/build/pdf"];
  3926. } else {
  3927.   pdfjsLib = require("../build/pdf.js");
  3928. }
  3929.  
  3930. module.exports = pdfjsLib;
  3931.  
  3932. /***/ }),
  3933. /* 6 */
  3934. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3935.  
  3936.  
  3937.  
  3938. Object.defineProperty(exports, "__esModule", ({
  3939.   value: true
  3940. }));
  3941. exports.PDFCursorTools = exports.CursorTool = void 0;
  3942.  
  3943. var _grab_to_pan = __webpack_require__(7);
  3944.  
  3945. var _ui_utils = __webpack_require__(4);
  3946.  
  3947. const CursorTool = {
  3948.   SELECT: 0,
  3949.   HAND: 1,
  3950.   ZOOM: 2
  3951. };
  3952. exports.CursorTool = CursorTool;
  3953.  
  3954. class PDFCursorTools {
  3955.   constructor({
  3956.     container,
  3957.     eventBus,
  3958.     cursorToolOnLoad = CursorTool.SELECT
  3959.   }) {
  3960.     this.container = container;
  3961.     this.eventBus = eventBus;
  3962.     this.active = CursorTool.SELECT;
  3963.     this.activeBeforePresentationMode = null;
  3964.     this.handTool = new _grab_to_pan.GrabToPan({
  3965.       element: this.container
  3966.     });
  3967.  
  3968.     this._addEventListeners();
  3969.  
  3970.     Promise.resolve().then(() => {
  3971.       this.switchTool(cursorToolOnLoad);
  3972.     });
  3973.   }
  3974.  
  3975.   get activeTool() {
  3976.     return this.active;
  3977.   }
  3978.  
  3979.   switchTool(tool) {
  3980.     if (this.activeBeforePresentationMode !== null) {
  3981.       return;
  3982.     }
  3983.  
  3984.     if (tool === this.active) {
  3985.       return;
  3986.     }
  3987.  
  3988.     const disableActiveTool = () => {
  3989.       switch (this.active) {
  3990.         case CursorTool.SELECT:
  3991.           break;
  3992.  
  3993.         case CursorTool.HAND:
  3994.           this.handTool.deactivate();
  3995.           break;
  3996.  
  3997.         case CursorTool.ZOOM:
  3998.       }
  3999.     };
  4000.  
  4001.     switch (tool) {
  4002.       case CursorTool.SELECT:
  4003.         disableActiveTool();
  4004.         break;
  4005.  
  4006.       case CursorTool.HAND:
  4007.         disableActiveTool();
  4008.         this.handTool.activate();
  4009.         break;
  4010.  
  4011.       case CursorTool.ZOOM:
  4012.       default:
  4013.         console.error(`switchTool: "${tool}" is an unsupported value.`);
  4014.         return;
  4015.     }
  4016.  
  4017.     this.active = tool;
  4018.  
  4019.     this._dispatchEvent();
  4020.   }
  4021.  
  4022.   _dispatchEvent() {
  4023.     this.eventBus.dispatch("cursortoolchanged", {
  4024.       source: this,
  4025.       tool: this.active
  4026.     });
  4027.   }
  4028.  
  4029.   _addEventListeners() {
  4030.     this.eventBus._on("switchcursortool", evt => {
  4031.       this.switchTool(evt.tool);
  4032.     });
  4033.  
  4034.     this.eventBus._on("presentationmodechanged", evt => {
  4035.       switch (evt.state) {
  4036.         case _ui_utils.PresentationModeState.FULLSCREEN:
  4037.           {
  4038.             const previouslyActive = this.active;
  4039.             this.switchTool(CursorTool.SELECT);
  4040.             this.activeBeforePresentationMode = previouslyActive;
  4041.             break;
  4042.           }
  4043.  
  4044.         case _ui_utils.PresentationModeState.NORMAL:
  4045.           {
  4046.             const previouslyActive = this.activeBeforePresentationMode;
  4047.             this.activeBeforePresentationMode = null;
  4048.             this.switchTool(previouslyActive);
  4049.             break;
  4050.           }
  4051.       }
  4052.     });
  4053.   }
  4054.  
  4055. }
  4056.  
  4057. exports.PDFCursorTools = PDFCursorTools;
  4058.  
  4059. /***/ }),
  4060. /* 7 */
  4061. /***/ ((__unused_webpack_module, exports) => {
  4062.  
  4063.  
  4064.  
  4065. Object.defineProperty(exports, "__esModule", ({
  4066.   value: true
  4067. }));
  4068. exports.GrabToPan = GrabToPan;
  4069.  
  4070. function GrabToPan(options) {
  4071.   this.element = options.element;
  4072.   this.document = options.element.ownerDocument;
  4073.  
  4074.   if (typeof options.ignoreTarget === "function") {
  4075.     this.ignoreTarget = options.ignoreTarget;
  4076.   }
  4077.  
  4078.   this.onActiveChanged = options.onActiveChanged;
  4079.   this.activate = this.activate.bind(this);
  4080.   this.deactivate = this.deactivate.bind(this);
  4081.   this.toggle = this.toggle.bind(this);
  4082.   this._onmousedown = this._onmousedown.bind(this);
  4083.   this._onmousemove = this._onmousemove.bind(this);
  4084.   this._endPan = this._endPan.bind(this);
  4085.   const overlay = this.overlay = document.createElement("div");
  4086.   overlay.className = "grab-to-pan-grabbing";
  4087. }
  4088.  
  4089. GrabToPan.prototype = {
  4090.   CSS_CLASS_GRAB: "grab-to-pan-grab",
  4091.   activate: function GrabToPan_activate() {
  4092.     if (!this.active) {
  4093.       this.active = true;
  4094.       this.element.addEventListener("mousedown", this._onmousedown, true);
  4095.       this.element.classList.add(this.CSS_CLASS_GRAB);
  4096.  
  4097.       if (this.onActiveChanged) {
  4098.         this.onActiveChanged(true);
  4099.       }
  4100.     }
  4101.   },
  4102.   deactivate: function GrabToPan_deactivate() {
  4103.     if (this.active) {
  4104.       this.active = false;
  4105.       this.element.removeEventListener("mousedown", this._onmousedown, true);
  4106.  
  4107.       this._endPan();
  4108.  
  4109.       this.element.classList.remove(this.CSS_CLASS_GRAB);
  4110.  
  4111.       if (this.onActiveChanged) {
  4112.         this.onActiveChanged(false);
  4113.       }
  4114.     }
  4115.   },
  4116.   toggle: function GrabToPan_toggle() {
  4117.     if (this.active) {
  4118.       this.deactivate();
  4119.     } else {
  4120.       this.activate();
  4121.     }
  4122.   },
  4123.   ignoreTarget: function GrabToPan_ignoreTarget(node) {
  4124.     return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4125.   },
  4126.   _onmousedown: function GrabToPan__onmousedown(event) {
  4127.     if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4128.       return;
  4129.     }
  4130.  
  4131.     if (event.originalTarget) {
  4132.       try {
  4133.         event.originalTarget.tagName;
  4134.       } catch (e) {
  4135.         return;
  4136.       }
  4137.     }
  4138.  
  4139.     this.scrollLeftStart = this.element.scrollLeft;
  4140.     this.scrollTopStart = this.element.scrollTop;
  4141.     this.clientXStart = event.clientX;
  4142.     this.clientYStart = event.clientY;
  4143.     this.document.addEventListener("mousemove", this._onmousemove, true);
  4144.     this.document.addEventListener("mouseup", this._endPan, true);
  4145.     this.element.addEventListener("scroll", this._endPan, true);
  4146.     event.preventDefault();
  4147.     event.stopPropagation();
  4148.     const focusedElement = document.activeElement;
  4149.  
  4150.     if (focusedElement && !focusedElement.contains(event.target)) {
  4151.       focusedElement.blur();
  4152.     }
  4153.   },
  4154.   _onmousemove: function GrabToPan__onmousemove(event) {
  4155.     this.element.removeEventListener("scroll", this._endPan, true);
  4156.  
  4157.     if (isLeftMouseReleased(event)) {
  4158.       this._endPan();
  4159.  
  4160.       return;
  4161.     }
  4162.  
  4163.     const xDiff = event.clientX - this.clientXStart;
  4164.     const yDiff = event.clientY - this.clientYStart;
  4165.     const scrollTop = this.scrollTopStart - yDiff;
  4166.     const scrollLeft = this.scrollLeftStart - xDiff;
  4167.  
  4168.     if (this.element.scrollTo) {
  4169.       this.element.scrollTo({
  4170.         top: scrollTop,
  4171.         left: scrollLeft,
  4172.         behavior: "instant"
  4173.       });
  4174.     } else {
  4175.       this.element.scrollTop = scrollTop;
  4176.       this.element.scrollLeft = scrollLeft;
  4177.     }
  4178.  
  4179.     if (!this.overlay.parentNode) {
  4180.       document.body.appendChild(this.overlay);
  4181.     }
  4182.   },
  4183.   _endPan: function GrabToPan__endPan() {
  4184.     this.element.removeEventListener("scroll", this._endPan, true);
  4185.     this.document.removeEventListener("mousemove", this._onmousemove, true);
  4186.     this.document.removeEventListener("mouseup", this._endPan, true);
  4187.     this.overlay.remove();
  4188.   }
  4189. };
  4190.  
  4191. function isLeftMouseReleased(event) {
  4192.   if ("buttons" in event) {
  4193.     return !(event.buttons & 1);
  4194.   }
  4195.  
  4196.   const chrome = window.chrome;
  4197.   const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  4198.   const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  4199.  
  4200.   if (isChrome15OrOpera15plus || isSafari6plus) {
  4201.     return event.which === 0;
  4202.   }
  4203.  
  4204.   return false;
  4205. }
  4206.  
  4207. /***/ }),
  4208. /* 8 */
  4209. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4210.  
  4211.  
  4212.  
  4213. Object.defineProperty(exports, "__esModule", ({
  4214.   value: true
  4215. }));
  4216. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  4217.  
  4218. var _pdfjsLib = __webpack_require__(5);
  4219.  
  4220. const CLEANUP_TIMEOUT = 30000;
  4221. const RenderingStates = {
  4222.   INITIAL: 0,
  4223.   RUNNING: 1,
  4224.   PAUSED: 2,
  4225.   FINISHED: 3
  4226. };
  4227. exports.RenderingStates = RenderingStates;
  4228.  
  4229. class PDFRenderingQueue {
  4230.   constructor() {
  4231.     this.pdfViewer = null;
  4232.     this.pdfThumbnailViewer = null;
  4233.     this.onIdle = null;
  4234.     this.highestPriorityPage = null;
  4235.     this.idleTimeout = null;
  4236.     this.printing = false;
  4237.     this.isThumbnailViewEnabled = false;
  4238.   }
  4239.  
  4240.   setViewer(pdfViewer) {
  4241.     this.pdfViewer = pdfViewer;
  4242.   }
  4243.  
  4244.   setThumbnailViewer(pdfThumbnailViewer) {
  4245.     this.pdfThumbnailViewer = pdfThumbnailViewer;
  4246.   }
  4247.  
  4248.   isHighestPriority(view) {
  4249.     return this.highestPriorityPage === view.renderingId;
  4250.   }
  4251.  
  4252.   renderHighestPriority(currentlyVisiblePages) {
  4253.     if (this.idleTimeout) {
  4254.       clearTimeout(this.idleTimeout);
  4255.       this.idleTimeout = null;
  4256.     }
  4257.  
  4258.     if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  4259.       return;
  4260.     }
  4261.  
  4262.     if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  4263.       if (this.pdfThumbnailViewer.forceRendering()) {
  4264.         return;
  4265.       }
  4266.     }
  4267.  
  4268.     if (this.printing) {
  4269.       return;
  4270.     }
  4271.  
  4272.     if (this.onIdle) {
  4273.       this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  4274.     }
  4275.   }
  4276.  
  4277.   getHighestPriority(visible, views, scrolledDown) {
  4278.     const visibleViews = visible.views;
  4279.     const numVisible = visibleViews.length;
  4280.  
  4281.     if (numVisible === 0) {
  4282.       return null;
  4283.     }
  4284.  
  4285.     for (let i = 0; i < numVisible; ++i) {
  4286.       const view = visibleViews[i].view;
  4287.  
  4288.       if (!this.isViewFinished(view)) {
  4289.         return view;
  4290.       }
  4291.     }
  4292.  
  4293.     if (scrolledDown) {
  4294.       const nextPageIndex = visible.last.id;
  4295.  
  4296.       if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  4297.         return views[nextPageIndex];
  4298.       }
  4299.     } else {
  4300.       const previousPageIndex = visible.first.id - 2;
  4301.  
  4302.       if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  4303.         return views[previousPageIndex];
  4304.       }
  4305.     }
  4306.  
  4307.     return null;
  4308.   }
  4309.  
  4310.   isViewFinished(view) {
  4311.     return view.renderingState === RenderingStates.FINISHED;
  4312.   }
  4313.  
  4314.   renderView(view) {
  4315.     switch (view.renderingState) {
  4316.       case RenderingStates.FINISHED:
  4317.         return false;
  4318.  
  4319.       case RenderingStates.PAUSED:
  4320.         this.highestPriorityPage = view.renderingId;
  4321.         view.resume();
  4322.         break;
  4323.  
  4324.       case RenderingStates.RUNNING:
  4325.         this.highestPriorityPage = view.renderingId;
  4326.         break;
  4327.  
  4328.       case RenderingStates.INITIAL:
  4329.         this.highestPriorityPage = view.renderingId;
  4330.         view.draw().finally(() => {
  4331.           this.renderHighestPriority();
  4332.         }).catch(reason => {
  4333.           if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  4334.             return;
  4335.           }
  4336.  
  4337.           console.error(`renderView: "${reason}"`);
  4338.         });
  4339.         break;
  4340.     }
  4341.  
  4342.     return true;
  4343.   }
  4344.  
  4345. }
  4346.  
  4347. exports.PDFRenderingQueue = PDFRenderingQueue;
  4348.  
  4349. /***/ }),
  4350. /* 9 */
  4351. /***/ ((__unused_webpack_module, exports) => {
  4352.  
  4353.  
  4354.  
  4355. Object.defineProperty(exports, "__esModule", ({
  4356.   value: true
  4357. }));
  4358. exports.OverlayManager = void 0;
  4359.  
  4360. class OverlayManager {
  4361.   constructor() {
  4362.     this._overlays = {};
  4363.     this._active = null;
  4364.     this._keyDownBound = this._keyDown.bind(this);
  4365.   }
  4366.  
  4367.   get active() {
  4368.     return this._active;
  4369.   }
  4370.  
  4371.   async register(name, element, callerCloseMethod = null, canForceClose = false) {
  4372.     let container;
  4373.  
  4374.     if (!name || !element || !(container = element.parentNode)) {
  4375.       throw new Error("Not enough parameters.");
  4376.     } else if (this._overlays[name]) {
  4377.       throw new Error("The overlay is already registered.");
  4378.     }
  4379.  
  4380.     this._overlays[name] = {
  4381.       element,
  4382.       container,
  4383.       callerCloseMethod,
  4384.       canForceClose
  4385.     };
  4386.   }
  4387.  
  4388.   async unregister(name) {
  4389.     if (!this._overlays[name]) {
  4390.       throw new Error("The overlay does not exist.");
  4391.     } else if (this._active === name) {
  4392.       throw new Error("The overlay cannot be removed while it is active.");
  4393.     }
  4394.  
  4395.     delete this._overlays[name];
  4396.   }
  4397.  
  4398.   async open(name) {
  4399.     if (!this._overlays[name]) {
  4400.       throw new Error("The overlay does not exist.");
  4401.     } else if (this._active) {
  4402.       if (this._overlays[name].canForceClose) {
  4403.         this._closeThroughCaller();
  4404.       } else if (this._active === name) {
  4405.         throw new Error("The overlay is already active.");
  4406.       } else {
  4407.         throw new Error("Another overlay is currently active.");
  4408.       }
  4409.     }
  4410.  
  4411.     this._active = name;
  4412.  
  4413.     this._overlays[this._active].element.classList.remove("hidden");
  4414.  
  4415.     this._overlays[this._active].container.classList.remove("hidden");
  4416.  
  4417.     window.addEventListener("keydown", this._keyDownBound);
  4418.   }
  4419.  
  4420.   async close(name) {
  4421.     if (!this._overlays[name]) {
  4422.       throw new Error("The overlay does not exist.");
  4423.     } else if (!this._active) {
  4424.       throw new Error("The overlay is currently not active.");
  4425.     } else if (this._active !== name) {
  4426.       throw new Error("Another overlay is currently active.");
  4427.     }
  4428.  
  4429.     this._overlays[this._active].container.classList.add("hidden");
  4430.  
  4431.     this._overlays[this._active].element.classList.add("hidden");
  4432.  
  4433.     this._active = null;
  4434.     window.removeEventListener("keydown", this._keyDownBound);
  4435.   }
  4436.  
  4437.   _keyDown(evt) {
  4438.     if (this._active && evt.keyCode === 27) {
  4439.       this._closeThroughCaller();
  4440.  
  4441.       evt.preventDefault();
  4442.     }
  4443.   }
  4444.  
  4445.   _closeThroughCaller() {
  4446.     if (this._overlays[this._active].callerCloseMethod) {
  4447.       this._overlays[this._active].callerCloseMethod();
  4448.     }
  4449.  
  4450.     if (this._active) {
  4451.       this.close(this._active);
  4452.     }
  4453.   }
  4454.  
  4455. }
  4456.  
  4457. exports.OverlayManager = OverlayManager;
  4458.  
  4459. /***/ }),
  4460. /* 10 */
  4461. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4462.  
  4463.  
  4464.  
  4465. Object.defineProperty(exports, "__esModule", ({
  4466.   value: true
  4467. }));
  4468. exports.PasswordPrompt = void 0;
  4469.  
  4470. var _pdfjsLib = __webpack_require__(5);
  4471.  
  4472. class PasswordPrompt {
  4473.   constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  4474.     this.overlayName = options.overlayName;
  4475.     this.container = options.container;
  4476.     this.label = options.label;
  4477.     this.input = options.input;
  4478.     this.submitButton = options.submitButton;
  4479.     this.cancelButton = options.cancelButton;
  4480.     this.overlayManager = overlayManager;
  4481.     this.l10n = l10n;
  4482.     this._isViewerEmbedded = isViewerEmbedded;
  4483.     this.updateCallback = null;
  4484.     this.reason = null;
  4485.     this.submitButton.addEventListener("click", this.verify.bind(this));
  4486.     this.cancelButton.addEventListener("click", this.close.bind(this));
  4487.     this.input.addEventListener("keydown", e => {
  4488.       if (e.keyCode === 13) {
  4489.         this.verify();
  4490.       }
  4491.     });
  4492.     this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  4493.   }
  4494.  
  4495.   async open() {
  4496.     await this.overlayManager.open(this.overlayName);
  4497.     const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4498.  
  4499.     if (!this._isViewerEmbedded || passwordIncorrect) {
  4500.       this.input.focus();
  4501.     }
  4502.  
  4503.     this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4504.   }
  4505.  
  4506.   close() {
  4507.     this.overlayManager.close(this.overlayName).then(() => {
  4508.       this.input.value = "";
  4509.     });
  4510.   }
  4511.  
  4512.   verify() {
  4513.     const password = this.input.value;
  4514.  
  4515.     if (password?.length > 0) {
  4516.       this.close();
  4517.       this.updateCallback(password);
  4518.     }
  4519.   }
  4520.  
  4521.   setUpdateCallback(updateCallback, reason) {
  4522.     this.updateCallback = updateCallback;
  4523.     this.reason = reason;
  4524.   }
  4525.  
  4526. }
  4527.  
  4528. exports.PasswordPrompt = PasswordPrompt;
  4529.  
  4530. /***/ }),
  4531. /* 11 */
  4532. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4533.  
  4534.  
  4535.  
  4536. Object.defineProperty(exports, "__esModule", ({
  4537.   value: true
  4538. }));
  4539. exports.PDFAttachmentViewer = void 0;
  4540.  
  4541. var _pdfjsLib = __webpack_require__(5);
  4542.  
  4543. var _base_tree_viewer = __webpack_require__(12);
  4544.  
  4545. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4546.   constructor(options) {
  4547.     super(options);
  4548.     this.downloadManager = options.downloadManager;
  4549.  
  4550.     this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  4551.   }
  4552.  
  4553.   reset(keepRenderedCapability = false) {
  4554.     super.reset();
  4555.     this._attachments = null;
  4556.  
  4557.     if (!keepRenderedCapability) {
  4558.       this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4559.     }
  4560.  
  4561.     if (this._pendingDispatchEvent) {
  4562.       clearTimeout(this._pendingDispatchEvent);
  4563.     }
  4564.  
  4565.     this._pendingDispatchEvent = null;
  4566.   }
  4567.  
  4568.   _dispatchEvent(attachmentsCount) {
  4569.     this._renderedCapability.resolve();
  4570.  
  4571.     if (this._pendingDispatchEvent) {
  4572.       clearTimeout(this._pendingDispatchEvent);
  4573.       this._pendingDispatchEvent = null;
  4574.     }
  4575.  
  4576.     if (attachmentsCount === 0) {
  4577.       this._pendingDispatchEvent = setTimeout(() => {
  4578.         this.eventBus.dispatch("attachmentsloaded", {
  4579.           source: this,
  4580.           attachmentsCount: 0
  4581.         });
  4582.         this._pendingDispatchEvent = null;
  4583.       });
  4584.       return;
  4585.     }
  4586.  
  4587.     this.eventBus.dispatch("attachmentsloaded", {
  4588.       source: this,
  4589.       attachmentsCount
  4590.     });
  4591.   }
  4592.  
  4593.   _bindLink(element, {
  4594.     content,
  4595.     filename
  4596.   }) {
  4597.     element.onclick = () => {
  4598.       this.downloadManager.openOrDownloadData(element, content, filename);
  4599.       return false;
  4600.     };
  4601.   }
  4602.  
  4603.   render({
  4604.     attachments,
  4605.     keepRenderedCapability = false
  4606.   }) {
  4607.     if (this._attachments) {
  4608.       this.reset(keepRenderedCapability);
  4609.     }
  4610.  
  4611.     this._attachments = attachments || null;
  4612.  
  4613.     if (!attachments) {
  4614.       this._dispatchEvent(0);
  4615.  
  4616.       return;
  4617.     }
  4618.  
  4619.     const names = Object.keys(attachments).sort(function (a, b) {
  4620.       return a.toLowerCase().localeCompare(b.toLowerCase());
  4621.     });
  4622.     const fragment = document.createDocumentFragment();
  4623.     let attachmentsCount = 0;
  4624.  
  4625.     for (const name of names) {
  4626.       const item = attachments[name];
  4627.       const content = item.content,
  4628.             filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  4629.       const div = document.createElement("div");
  4630.       div.className = "treeItem";
  4631.       const element = document.createElement("a");
  4632.  
  4633.       this._bindLink(element, {
  4634.         content,
  4635.         filename
  4636.       });
  4637.  
  4638.       element.textContent = this._normalizeTextContent(filename);
  4639.       div.appendChild(element);
  4640.       fragment.appendChild(div);
  4641.       attachmentsCount++;
  4642.     }
  4643.  
  4644.     this._finishRendering(fragment, attachmentsCount);
  4645.   }
  4646.  
  4647.   _appendAttachment({
  4648.     id,
  4649.     filename,
  4650.     content
  4651.   }) {
  4652.     const renderedPromise = this._renderedCapability.promise;
  4653.     renderedPromise.then(() => {
  4654.       if (renderedPromise !== this._renderedCapability.promise) {
  4655.         return;
  4656.       }
  4657.  
  4658.       let attachments = this._attachments;
  4659.  
  4660.       if (!attachments) {
  4661.         attachments = Object.create(null);
  4662.       } else {
  4663.         for (const name in attachments) {
  4664.           if (id === name) {
  4665.             return;
  4666.           }
  4667.         }
  4668.       }
  4669.  
  4670.       attachments[id] = {
  4671.         filename,
  4672.         content
  4673.       };
  4674.       this.render({
  4675.         attachments,
  4676.         keepRenderedCapability: true
  4677.       });
  4678.     });
  4679.   }
  4680.  
  4681. }
  4682.  
  4683. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4684.  
  4685. /***/ }),
  4686. /* 12 */
  4687. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4688.  
  4689.  
  4690.  
  4691. Object.defineProperty(exports, "__esModule", ({
  4692.   value: true
  4693. }));
  4694. exports.BaseTreeViewer = void 0;
  4695.  
  4696. var _pdfjsLib = __webpack_require__(5);
  4697.  
  4698. const TREEITEM_OFFSET_TOP = -100;
  4699. const TREEITEM_SELECTED_CLASS = "selected";
  4700.  
  4701. class BaseTreeViewer {
  4702.   constructor(options) {
  4703.     if (this.constructor === BaseTreeViewer) {
  4704.       throw new Error("Cannot initialize BaseTreeViewer.");
  4705.     }
  4706.  
  4707.     this.container = options.container;
  4708.     this.eventBus = options.eventBus;
  4709.     this.reset();
  4710.   }
  4711.  
  4712.   reset() {
  4713.     this._pdfDocument = null;
  4714.     this._lastToggleIsShow = true;
  4715.     this._currentTreeItem = null;
  4716.     this.container.textContent = "";
  4717.     this.container.classList.remove("treeWithDeepNesting");
  4718.   }
  4719.  
  4720.   _dispatchEvent(count) {
  4721.     throw new Error("Not implemented: _dispatchEvent");
  4722.   }
  4723.  
  4724.   _bindLink(element, params) {
  4725.     throw new Error("Not implemented: _bindLink");
  4726.   }
  4727.  
  4728.   _normalizeTextContent(str) {
  4729.     return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  4730.   }
  4731.  
  4732.   _addToggleButton(div, hidden = false) {
  4733.     const toggler = document.createElement("div");
  4734.     toggler.className = "treeItemToggler";
  4735.  
  4736.     if (hidden) {
  4737.       toggler.classList.add("treeItemsHidden");
  4738.     }
  4739.  
  4740.     toggler.onclick = evt => {
  4741.       evt.stopPropagation();
  4742.       toggler.classList.toggle("treeItemsHidden");
  4743.  
  4744.       if (evt.shiftKey) {
  4745.         const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4746.  
  4747.         this._toggleTreeItem(div, shouldShowAll);
  4748.       }
  4749.     };
  4750.  
  4751.     div.insertBefore(toggler, div.firstChild);
  4752.   }
  4753.  
  4754.   _toggleTreeItem(root, show = false) {
  4755.     this._lastToggleIsShow = show;
  4756.  
  4757.     for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4758.       toggler.classList.toggle("treeItemsHidden", !show);
  4759.     }
  4760.   }
  4761.  
  4762.   _toggleAllTreeItems() {
  4763.     this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4764.   }
  4765.  
  4766.   _finishRendering(fragment, count, hasAnyNesting = false) {
  4767.     if (hasAnyNesting) {
  4768.       this.container.classList.add("treeWithDeepNesting");
  4769.       this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4770.     }
  4771.  
  4772.     this.container.appendChild(fragment);
  4773.  
  4774.     this._dispatchEvent(count);
  4775.   }
  4776.  
  4777.   render(params) {
  4778.     throw new Error("Not implemented: render");
  4779.   }
  4780.  
  4781.   _updateCurrentTreeItem(treeItem = null) {
  4782.     if (this._currentTreeItem) {
  4783.       this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4784.  
  4785.       this._currentTreeItem = null;
  4786.     }
  4787.  
  4788.     if (treeItem) {
  4789.       treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4790.       this._currentTreeItem = treeItem;
  4791.     }
  4792.   }
  4793.  
  4794.   _scrollToCurrentTreeItem(treeItem) {
  4795.     if (!treeItem) {
  4796.       return;
  4797.     }
  4798.  
  4799.     let currentNode = treeItem.parentNode;
  4800.  
  4801.     while (currentNode && currentNode !== this.container) {
  4802.       if (currentNode.classList.contains("treeItem")) {
  4803.         const toggler = currentNode.firstElementChild;
  4804.         toggler?.classList.remove("treeItemsHidden");
  4805.       }
  4806.  
  4807.       currentNode = currentNode.parentNode;
  4808.     }
  4809.  
  4810.     this._updateCurrentTreeItem(treeItem);
  4811.  
  4812.     this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4813.   }
  4814.  
  4815. }
  4816.  
  4817. exports.BaseTreeViewer = BaseTreeViewer;
  4818.  
  4819. /***/ }),
  4820. /* 13 */
  4821. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4822.  
  4823.  
  4824.  
  4825. Object.defineProperty(exports, "__esModule", ({
  4826.   value: true
  4827. }));
  4828. exports.PDFDocumentProperties = void 0;
  4829.  
  4830. var _pdfjsLib = __webpack_require__(5);
  4831.  
  4832. var _ui_utils = __webpack_require__(4);
  4833.  
  4834. const DEFAULT_FIELD_CONTENT = "-";
  4835. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4836. const US_PAGE_NAMES = {
  4837.   "8.5x11": "Letter",
  4838.   "8.5x14": "Legal"
  4839. };
  4840. const METRIC_PAGE_NAMES = {
  4841.   "297x420": "A3",
  4842.   "210x297": "A4"
  4843. };
  4844.  
  4845. function getPageName(size, isPortrait, pageNames) {
  4846.   const width = isPortrait ? size.width : size.height;
  4847.   const height = isPortrait ? size.height : size.width;
  4848.   return pageNames[`${width}x${height}`];
  4849. }
  4850.  
  4851. class PDFDocumentProperties {
  4852.   constructor({
  4853.     overlayName,
  4854.     fields,
  4855.     container,
  4856.     closeButton
  4857.   }, overlayManager, eventBus, l10n) {
  4858.     this.overlayName = overlayName;
  4859.     this.fields = fields;
  4860.     this.container = container;
  4861.     this.overlayManager = overlayManager;
  4862.     this.l10n = l10n;
  4863.  
  4864.     this._reset();
  4865.  
  4866.     closeButton.addEventListener("click", this.close.bind(this));
  4867.     this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  4868.  
  4869.     eventBus._on("pagechanging", evt => {
  4870.       this._currentPageNumber = evt.pageNumber;
  4871.     });
  4872.  
  4873.     eventBus._on("rotationchanging", evt => {
  4874.       this._pagesRotation = evt.pagesRotation;
  4875.     });
  4876.  
  4877.     this._isNonMetricLocale = true;
  4878.     l10n.getLanguage().then(locale => {
  4879.       this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4880.     });
  4881.   }
  4882.  
  4883.   async open() {
  4884.     const freezeFieldData = data => {
  4885.       Object.defineProperty(this, "fieldData", {
  4886.         value: Object.freeze(data),
  4887.         writable: false,
  4888.         enumerable: true,
  4889.         configurable: true
  4890.       });
  4891.     };
  4892.  
  4893.     await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  4894.     const currentPageNumber = this._currentPageNumber;
  4895.     const pagesRotation = this._pagesRotation;
  4896.  
  4897.     if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  4898.       this._updateUI();
  4899.  
  4900.       return;
  4901.     }
  4902.  
  4903.     const {
  4904.       info,
  4905.       contentDispositionFilename,
  4906.       contentLength
  4907.     } = await this.pdfDocument.getMetadata();
  4908.     const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url), this._parseFileSize(contentLength), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4909.       return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4910.     }), this._parseLinearization(info.IsLinearized)]);
  4911.     freezeFieldData({
  4912.       fileName,
  4913.       fileSize,
  4914.       title: info.Title,
  4915.       author: info.Author,
  4916.       subject: info.Subject,
  4917.       keywords: info.Keywords,
  4918.       creationDate,
  4919.       modificationDate,
  4920.       creator: info.Creator,
  4921.       producer: info.Producer,
  4922.       version: info.PDFFormatVersion,
  4923.       pageCount: this.pdfDocument.numPages,
  4924.       pageSize,
  4925.       linearized: isLinearized,
  4926.       _currentPageNumber: currentPageNumber,
  4927.       _pagesRotation: pagesRotation
  4928.     });
  4929.  
  4930.     this._updateUI();
  4931.  
  4932.     const {
  4933.       length
  4934.     } = await this.pdfDocument.getDownloadInfo();
  4935.  
  4936.     if (contentLength === length) {
  4937.       return;
  4938.     }
  4939.  
  4940.     const data = Object.assign(Object.create(null), this.fieldData);
  4941.     data.fileSize = await this._parseFileSize(length);
  4942.     freezeFieldData(data);
  4943.  
  4944.     this._updateUI();
  4945.   }
  4946.  
  4947.   close() {
  4948.     this.overlayManager.close(this.overlayName);
  4949.   }
  4950.  
  4951.   setDocument(pdfDocument, url = null) {
  4952.     if (this.pdfDocument) {
  4953.       this._reset();
  4954.  
  4955.       this._updateUI(true);
  4956.     }
  4957.  
  4958.     if (!pdfDocument) {
  4959.       return;
  4960.     }
  4961.  
  4962.     this.pdfDocument = pdfDocument;
  4963.     this.url = url;
  4964.  
  4965.     this._dataAvailableCapability.resolve();
  4966.   }
  4967.  
  4968.   _reset() {
  4969.     this.pdfDocument = null;
  4970.     this.url = null;
  4971.     delete this.fieldData;
  4972.     this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4973.     this._currentPageNumber = 1;
  4974.     this._pagesRotation = 0;
  4975.   }
  4976.  
  4977.   _updateUI(reset = false) {
  4978.     if (reset || !this.fieldData) {
  4979.       for (const id in this.fields) {
  4980.         this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4981.       }
  4982.  
  4983.       return;
  4984.     }
  4985.  
  4986.     if (this.overlayManager.active !== this.overlayName) {
  4987.       return;
  4988.     }
  4989.  
  4990.     for (const id in this.fields) {
  4991.       const content = this.fieldData[id];
  4992.       this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4993.     }
  4994.   }
  4995.  
  4996.   async _parseFileSize(fileSize = 0) {
  4997.     const kb = fileSize / 1024,
  4998.           mb = kb / 1024;
  4999.  
  5000.     if (!kb) {
  5001.       return undefined;
  5002.     }
  5003.  
  5004.     return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  5005.       size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  5006.       size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  5007.       size_b: fileSize.toLocaleString()
  5008.     });
  5009.   }
  5010.  
  5011.   async _parsePageSize(pageSizeInches, pagesRotation) {
  5012.     if (!pageSizeInches) {
  5013.       return undefined;
  5014.     }
  5015.  
  5016.     if (pagesRotation % 180 !== 0) {
  5017.       pageSizeInches = {
  5018.         width: pageSizeInches.height,
  5019.         height: pageSizeInches.width
  5020.       };
  5021.     }
  5022.  
  5023.     const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  5024.     let sizeInches = {
  5025.       width: Math.round(pageSizeInches.width * 100) / 100,
  5026.       height: Math.round(pageSizeInches.height * 100) / 100
  5027.     };
  5028.     let sizeMillimeters = {
  5029.       width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  5030.       height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  5031.     };
  5032.     let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5033.  
  5034.     if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  5035.       const exactMillimeters = {
  5036.         width: pageSizeInches.width * 25.4,
  5037.         height: pageSizeInches.height * 25.4
  5038.       };
  5039.       const intMillimeters = {
  5040.         width: Math.round(sizeMillimeters.width),
  5041.         height: Math.round(sizeMillimeters.height)
  5042.       };
  5043.  
  5044.       if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  5045.         rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5046.  
  5047.         if (rawName) {
  5048.           sizeInches = {
  5049.             width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  5050.             height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  5051.           };
  5052.           sizeMillimeters = intMillimeters;
  5053.         }
  5054.       }
  5055.     }
  5056.  
  5057.     const [{
  5058.       width,
  5059.       height
  5060.     }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  5061.     return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  5062.       width: width.toLocaleString(),
  5063.       height: height.toLocaleString(),
  5064.       unit,
  5065.       name,
  5066.       orientation
  5067.     });
  5068.   }
  5069.  
  5070.   async _parseDate(inputDate) {
  5071.     const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  5072.  
  5073.     if (!dateObject) {
  5074.       return undefined;
  5075.     }
  5076.  
  5077.     return this.l10n.get("document_properties_date_string", {
  5078.       date: dateObject.toLocaleDateString(),
  5079.       time: dateObject.toLocaleTimeString()
  5080.     });
  5081.   }
  5082.  
  5083.   _parseLinearization(isLinearized) {
  5084.     return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  5085.   }
  5086.  
  5087. }
  5088.  
  5089. exports.PDFDocumentProperties = PDFDocumentProperties;
  5090.  
  5091. /***/ }),
  5092. /* 14 */
  5093. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5094.  
  5095.  
  5096.  
  5097. Object.defineProperty(exports, "__esModule", ({
  5098.   value: true
  5099. }));
  5100. exports.PDFFindBar = void 0;
  5101.  
  5102. var _pdf_find_controller = __webpack_require__(15);
  5103.  
  5104. const MATCHES_COUNT_LIMIT = 1000;
  5105.  
  5106. class PDFFindBar {
  5107.   constructor(options, eventBus, l10n) {
  5108.     this.opened = false;
  5109.     this.bar = options.bar;
  5110.     this.toggleButton = options.toggleButton;
  5111.     this.findField = options.findField;
  5112.     this.highlightAll = options.highlightAllCheckbox;
  5113.     this.caseSensitive = options.caseSensitiveCheckbox;
  5114.     this.entireWord = options.entireWordCheckbox;
  5115.     this.findMsg = options.findMsg;
  5116.     this.findResultsCount = options.findResultsCount;
  5117.     this.findPreviousButton = options.findPreviousButton;
  5118.     this.findNextButton = options.findNextButton;
  5119.     this.eventBus = eventBus;
  5120.     this.l10n = l10n;
  5121.     this.toggleButton.addEventListener("click", () => {
  5122.       this.toggle();
  5123.     });
  5124.     this.findField.addEventListener("input", () => {
  5125.       this.dispatchEvent("");
  5126.     });
  5127.     this.bar.addEventListener("keydown", e => {
  5128.       switch (e.keyCode) {
  5129.         case 13:
  5130.           if (e.target === this.findField) {
  5131.             this.dispatchEvent("again", e.shiftKey);
  5132.           }
  5133.  
  5134.           break;
  5135.  
  5136.         case 27:
  5137.           this.close();
  5138.           break;
  5139.       }
  5140.     });
  5141.     this.findPreviousButton.addEventListener("click", () => {
  5142.       this.dispatchEvent("again", true);
  5143.     });
  5144.     this.findNextButton.addEventListener("click", () => {
  5145.       this.dispatchEvent("again", false);
  5146.     });
  5147.     this.highlightAll.addEventListener("click", () => {
  5148.       this.dispatchEvent("highlightallchange");
  5149.     });
  5150.     this.caseSensitive.addEventListener("click", () => {
  5151.       this.dispatchEvent("casesensitivitychange");
  5152.     });
  5153.     this.entireWord.addEventListener("click", () => {
  5154.       this.dispatchEvent("entirewordchange");
  5155.     });
  5156.  
  5157.     this.eventBus._on("resize", this._adjustWidth.bind(this));
  5158.   }
  5159.  
  5160.   reset() {
  5161.     this.updateUIState();
  5162.   }
  5163.  
  5164.   dispatchEvent(type, findPrev) {
  5165.     this.eventBus.dispatch("find", {
  5166.       source: this,
  5167.       type,
  5168.       query: this.findField.value,
  5169.       phraseSearch: true,
  5170.       caseSensitive: this.caseSensitive.checked,
  5171.       entireWord: this.entireWord.checked,
  5172.       highlightAll: this.highlightAll.checked,
  5173.       findPrevious: findPrev
  5174.     });
  5175.   }
  5176.  
  5177.   updateUIState(state, previous, matchesCount) {
  5178.     let findMsg = Promise.resolve("");
  5179.     let status = "";
  5180.  
  5181.     switch (state) {
  5182.       case _pdf_find_controller.FindState.FOUND:
  5183.         break;
  5184.  
  5185.       case _pdf_find_controller.FindState.PENDING:
  5186.         status = "pending";
  5187.         break;
  5188.  
  5189.       case _pdf_find_controller.FindState.NOT_FOUND:
  5190.         findMsg = this.l10n.get("find_not_found");
  5191.         status = "notFound";
  5192.         break;
  5193.  
  5194.       case _pdf_find_controller.FindState.WRAPPED:
  5195.         findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  5196.         break;
  5197.     }
  5198.  
  5199.     this.findField.setAttribute("data-status", status);
  5200.     findMsg.then(msg => {
  5201.       this.findMsg.textContent = msg;
  5202.  
  5203.       this._adjustWidth();
  5204.     });
  5205.     this.updateResultsCount(matchesCount);
  5206.   }
  5207.  
  5208.   updateResultsCount({
  5209.     current = 0,
  5210.     total = 0
  5211.   } = {}) {
  5212.     const limit = MATCHES_COUNT_LIMIT;
  5213.     let matchCountMsg = Promise.resolve("");
  5214.  
  5215.     if (total > 0) {
  5216.       if (total > limit) {
  5217.         let key = "find_match_count_limit";
  5218.         matchCountMsg = this.l10n.get(key, {
  5219.           limit
  5220.         });
  5221.       } else {
  5222.         let key = "find_match_count";
  5223.         matchCountMsg = this.l10n.get(key, {
  5224.           current,
  5225.           total
  5226.         });
  5227.       }
  5228.     }
  5229.  
  5230.     matchCountMsg.then(msg => {
  5231.       this.findResultsCount.textContent = msg;
  5232.       this.findResultsCount.classList.toggle("hidden", !total);
  5233.  
  5234.       this._adjustWidth();
  5235.     });
  5236.   }
  5237.  
  5238.   open() {
  5239.     if (!this.opened) {
  5240.       this.opened = true;
  5241.       this.toggleButton.classList.add("toggled");
  5242.       this.toggleButton.setAttribute("aria-expanded", "true");
  5243.       this.bar.classList.remove("hidden");
  5244.     }
  5245.  
  5246.     this.findField.select();
  5247.     this.findField.focus();
  5248.  
  5249.     this._adjustWidth();
  5250.   }
  5251.  
  5252.   close() {
  5253.     if (!this.opened) {
  5254.       return;
  5255.     }
  5256.  
  5257.     this.opened = false;
  5258.     this.toggleButton.classList.remove("toggled");
  5259.     this.toggleButton.setAttribute("aria-expanded", "false");
  5260.     this.bar.classList.add("hidden");
  5261.     this.eventBus.dispatch("findbarclose", {
  5262.       source: this
  5263.     });
  5264.   }
  5265.  
  5266.   toggle() {
  5267.     if (this.opened) {
  5268.       this.close();
  5269.     } else {
  5270.       this.open();
  5271.     }
  5272.   }
  5273.  
  5274.   _adjustWidth() {
  5275.     if (!this.opened) {
  5276.       return;
  5277.     }
  5278.  
  5279.     this.bar.classList.remove("wrapContainers");
  5280.     const findbarHeight = this.bar.clientHeight;
  5281.     const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  5282.  
  5283.     if (findbarHeight > inputContainerHeight) {
  5284.       this.bar.classList.add("wrapContainers");
  5285.     }
  5286.   }
  5287.  
  5288. }
  5289.  
  5290. exports.PDFFindBar = PDFFindBar;
  5291.  
  5292. /***/ }),
  5293. /* 15 */
  5294. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5295.  
  5296.  
  5297.  
  5298. Object.defineProperty(exports, "__esModule", ({
  5299.   value: true
  5300. }));
  5301. exports.PDFFindController = exports.FindState = void 0;
  5302.  
  5303. var _pdfjsLib = __webpack_require__(5);
  5304.  
  5305. var _pdf_find_utils = __webpack_require__(16);
  5306.  
  5307. var _ui_utils = __webpack_require__(4);
  5308.  
  5309. const FindState = {
  5310.   FOUND: 0,
  5311.   NOT_FOUND: 1,
  5312.   WRAPPED: 2,
  5313.   PENDING: 3
  5314. };
  5315. exports.FindState = FindState;
  5316. const FIND_TIMEOUT = 250;
  5317. const MATCH_SCROLL_OFFSET_TOP = -50;
  5318. const MATCH_SCROLL_OFFSET_LEFT = -400;
  5319. const CHARACTERS_TO_NORMALIZE = {
  5320.   "\u2018": "'",
  5321.   "\u2019": "'",
  5322.   "\u201A": "'",
  5323.   "\u201B": "'",
  5324.   "\u201C": '"',
  5325.   "\u201D": '"',
  5326.   "\u201E": '"',
  5327.   "\u201F": '"',
  5328.   "\u00BC": "1/4",
  5329.   "\u00BD": "1/2",
  5330.   "\u00BE": "3/4"
  5331. };
  5332. let normalizationRegex = null;
  5333.  
  5334. function normalize(text) {
  5335.   if (!normalizationRegex) {
  5336.     const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  5337.     normalizationRegex = new RegExp(`[${replace}]`, "g");
  5338.   }
  5339.  
  5340.   let diffs = null;
  5341.   const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  5342.     const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  5343.           diff = normalizedCh.length - ch.length;
  5344.  
  5345.     if (diff !== 0) {
  5346.       (diffs || (diffs = [])).push([index, diff]);
  5347.     }
  5348.  
  5349.     return normalizedCh;
  5350.   });
  5351.   return [normalizedText, diffs];
  5352. }
  5353.  
  5354. function getOriginalIndex(matchIndex, diffs = null) {
  5355.   if (!diffs) {
  5356.     return matchIndex;
  5357.   }
  5358.  
  5359.   let totalDiff = 0;
  5360.  
  5361.   for (const [index, diff] of diffs) {
  5362.     const currentIndex = index + totalDiff;
  5363.  
  5364.     if (currentIndex >= matchIndex) {
  5365.       break;
  5366.     }
  5367.  
  5368.     if (currentIndex + diff > matchIndex) {
  5369.       totalDiff += matchIndex - currentIndex;
  5370.       break;
  5371.     }
  5372.  
  5373.     totalDiff += diff;
  5374.   }
  5375.  
  5376.   return matchIndex - totalDiff;
  5377. }
  5378.  
  5379. class PDFFindController {
  5380.   constructor({
  5381.     linkService,
  5382.     eventBus
  5383.   }) {
  5384.     this._linkService = linkService;
  5385.     this._eventBus = eventBus;
  5386.  
  5387.     this._reset();
  5388.  
  5389.     eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  5390.   }
  5391.  
  5392.   get highlightMatches() {
  5393.     return this._highlightMatches;
  5394.   }
  5395.  
  5396.   get pageMatches() {
  5397.     return this._pageMatches;
  5398.   }
  5399.  
  5400.   get pageMatchesLength() {
  5401.     return this._pageMatchesLength;
  5402.   }
  5403.  
  5404.   get selected() {
  5405.     return this._selected;
  5406.   }
  5407.  
  5408.   get state() {
  5409.     return this._state;
  5410.   }
  5411.  
  5412.   setDocument(pdfDocument) {
  5413.     if (this._pdfDocument) {
  5414.       this._reset();
  5415.     }
  5416.  
  5417.     if (!pdfDocument) {
  5418.       return;
  5419.     }
  5420.  
  5421.     this._pdfDocument = pdfDocument;
  5422.  
  5423.     this._firstPageCapability.resolve();
  5424.   }
  5425.  
  5426.   executeCommand(cmd, state) {
  5427.     if (!state) {
  5428.       return;
  5429.     }
  5430.  
  5431.     const pdfDocument = this._pdfDocument;
  5432.  
  5433.     if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  5434.       this._dirtyMatch = true;
  5435.     }
  5436.  
  5437.     this._state = state;
  5438.  
  5439.     if (cmd !== "findhighlightallchange") {
  5440.       this._updateUIState(FindState.PENDING);
  5441.     }
  5442.  
  5443.     this._firstPageCapability.promise.then(() => {
  5444.       if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5445.         return;
  5446.       }
  5447.  
  5448.       this._extractText();
  5449.  
  5450.       const findbarClosed = !this._highlightMatches;
  5451.       const pendingTimeout = !!this._findTimeout;
  5452.  
  5453.       if (this._findTimeout) {
  5454.         clearTimeout(this._findTimeout);
  5455.         this._findTimeout = null;
  5456.       }
  5457.  
  5458.       if (cmd === "find") {
  5459.         this._findTimeout = setTimeout(() => {
  5460.           this._nextMatch();
  5461.  
  5462.           this._findTimeout = null;
  5463.         }, FIND_TIMEOUT);
  5464.       } else if (this._dirtyMatch) {
  5465.         this._nextMatch();
  5466.       } else if (cmd === "findagain") {
  5467.         this._nextMatch();
  5468.  
  5469.         if (findbarClosed && this._state.highlightAll) {
  5470.           this._updateAllPages();
  5471.         }
  5472.       } else if (cmd === "findhighlightallchange") {
  5473.         if (pendingTimeout) {
  5474.           this._nextMatch();
  5475.         } else {
  5476.           this._highlightMatches = true;
  5477.         }
  5478.  
  5479.         this._updateAllPages();
  5480.       } else {
  5481.         this._nextMatch();
  5482.       }
  5483.     });
  5484.   }
  5485.  
  5486.   scrollMatchIntoView({
  5487.     element = null,
  5488.     pageIndex = -1,
  5489.     matchIndex = -1
  5490.   }) {
  5491.     if (!this._scrollMatches || !element) {
  5492.       return;
  5493.     } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5494.       return;
  5495.     } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5496.       return;
  5497.     }
  5498.  
  5499.     this._scrollMatches = false;
  5500.     const spot = {
  5501.       top: MATCH_SCROLL_OFFSET_TOP,
  5502.       left: MATCH_SCROLL_OFFSET_LEFT
  5503.     };
  5504.     (0, _ui_utils.scrollIntoView)(element, spot, true);
  5505.   }
  5506.  
  5507.   _reset() {
  5508.     this._highlightMatches = false;
  5509.     this._scrollMatches = false;
  5510.     this._pdfDocument = null;
  5511.     this._pageMatches = [];
  5512.     this._pageMatchesLength = [];
  5513.     this._state = null;
  5514.     this._selected = {
  5515.       pageIdx: -1,
  5516.       matchIdx: -1
  5517.     };
  5518.     this._offset = {
  5519.       pageIdx: null,
  5520.       matchIdx: null,
  5521.       wrapped: false
  5522.     };
  5523.     this._extractTextPromises = [];
  5524.     this._pageContents = [];
  5525.     this._pageDiffs = [];
  5526.     this._matchesCountTotal = 0;
  5527.     this._pagesToSearch = null;
  5528.     this._pendingFindMatches = Object.create(null);
  5529.     this._resumePageIdx = null;
  5530.     this._dirtyMatch = false;
  5531.     clearTimeout(this._findTimeout);
  5532.     this._findTimeout = null;
  5533.     this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5534.   }
  5535.  
  5536.   get _query() {
  5537.     if (this._state.query !== this._rawQuery) {
  5538.       this._rawQuery = this._state.query;
  5539.       [this._normalizedQuery] = normalize(this._state.query);
  5540.     }
  5541.  
  5542.     return this._normalizedQuery;
  5543.   }
  5544.  
  5545.   _shouldDirtyMatch(cmd, state) {
  5546.     if (state.query !== this._state.query) {
  5547.       return true;
  5548.     }
  5549.  
  5550.     switch (cmd) {
  5551.       case "findagain":
  5552.         const pageNumber = this._selected.pageIdx + 1;
  5553.         const linkService = this._linkService;
  5554.  
  5555.         if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  5556.           return true;
  5557.         }
  5558.  
  5559.         return false;
  5560.  
  5561.       case "findhighlightallchange":
  5562.         return false;
  5563.     }
  5564.  
  5565.     return true;
  5566.   }
  5567.  
  5568.   _prepareMatches(matchesWithLength, matches, matchesLength) {
  5569.     function isSubTerm(currentIndex) {
  5570.       const currentElem = matchesWithLength[currentIndex];
  5571.       const nextElem = matchesWithLength[currentIndex + 1];
  5572.  
  5573.       if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  5574.         currentElem.skipped = true;
  5575.         return true;
  5576.       }
  5577.  
  5578.       for (let i = currentIndex - 1; i >= 0; i--) {
  5579.         const prevElem = matchesWithLength[i];
  5580.  
  5581.         if (prevElem.skipped) {
  5582.           continue;
  5583.         }
  5584.  
  5585.         if (prevElem.match + prevElem.matchLength < currentElem.match) {
  5586.           break;
  5587.         }
  5588.  
  5589.         if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  5590.           currentElem.skipped = true;
  5591.           return true;
  5592.         }
  5593.       }
  5594.  
  5595.       return false;
  5596.     }
  5597.  
  5598.     matchesWithLength.sort(function (a, b) {
  5599.       return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  5600.     });
  5601.  
  5602.     for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  5603.       if (isSubTerm(i)) {
  5604.         continue;
  5605.       }
  5606.  
  5607.       matches.push(matchesWithLength[i].match);
  5608.       matchesLength.push(matchesWithLength[i].matchLength);
  5609.     }
  5610.   }
  5611.  
  5612.   _isEntireWord(content, startIdx, length) {
  5613.     if (startIdx > 0) {
  5614.       const first = content.charCodeAt(startIdx);
  5615.       const limit = content.charCodeAt(startIdx - 1);
  5616.  
  5617.       if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5618.         return false;
  5619.       }
  5620.     }
  5621.  
  5622.     const endIdx = startIdx + length - 1;
  5623.  
  5624.     if (endIdx < content.length - 1) {
  5625.       const last = content.charCodeAt(endIdx);
  5626.       const limit = content.charCodeAt(endIdx + 1);
  5627.  
  5628.       if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5629.         return false;
  5630.       }
  5631.     }
  5632.  
  5633.     return true;
  5634.   }
  5635.  
  5636.   _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  5637.     const matches = [],
  5638.           matchesLength = [];
  5639.     const queryLen = query.length;
  5640.     let matchIdx = -queryLen;
  5641.  
  5642.     while (true) {
  5643.       matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  5644.  
  5645.       if (matchIdx === -1) {
  5646.         break;
  5647.       }
  5648.  
  5649.       if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  5650.         continue;
  5651.       }
  5652.  
  5653.       const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  5654.             matchEnd = matchIdx + queryLen - 1,
  5655.             originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  5656.       matches.push(originalMatchIdx);
  5657.       matchesLength.push(originalQueryLen);
  5658.     }
  5659.  
  5660.     this._pageMatches[pageIndex] = matches;
  5661.     this._pageMatchesLength[pageIndex] = matchesLength;
  5662.   }
  5663.  
  5664.   _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  5665.     const matchesWithLength = [];
  5666.     const queryArray = query.match(/\S+/g);
  5667.  
  5668.     for (let i = 0, len = queryArray.length; i < len; i++) {
  5669.       const subquery = queryArray[i];
  5670.       const subqueryLen = subquery.length;
  5671.       let matchIdx = -subqueryLen;
  5672.  
  5673.       while (true) {
  5674.         matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  5675.  
  5676.         if (matchIdx === -1) {
  5677.           break;
  5678.         }
  5679.  
  5680.         if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  5681.           continue;
  5682.         }
  5683.  
  5684.         const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  5685.               matchEnd = matchIdx + subqueryLen - 1,
  5686.               originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  5687.         matchesWithLength.push({
  5688.           match: originalMatchIdx,
  5689.           matchLength: originalQueryLen,
  5690.           skipped: false
  5691.         });
  5692.       }
  5693.     }
  5694.  
  5695.     this._pageMatchesLength[pageIndex] = [];
  5696.     this._pageMatches[pageIndex] = [];
  5697.  
  5698.     this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  5699.   }
  5700.  
  5701.   _calculateMatch(pageIndex) {
  5702.     let pageContent = this._pageContents[pageIndex];
  5703.     const pageDiffs = this._pageDiffs[pageIndex];
  5704.     let query = this._query;
  5705.     const {
  5706.       caseSensitive,
  5707.       entireWord,
  5708.       phraseSearch
  5709.     } = this._state;
  5710.  
  5711.     if (query.length === 0) {
  5712.       return;
  5713.     }
  5714.  
  5715.     if (!caseSensitive) {
  5716.       pageContent = pageContent.toLowerCase();
  5717.       query = query.toLowerCase();
  5718.     }
  5719.  
  5720.     if (phraseSearch) {
  5721.       this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  5722.     } else {
  5723.       this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  5724.     }
  5725.  
  5726.     if (this._state.highlightAll) {
  5727.       this._updatePage(pageIndex);
  5728.     }
  5729.  
  5730.     if (this._resumePageIdx === pageIndex) {
  5731.       this._resumePageIdx = null;
  5732.  
  5733.       this._nextPageMatch();
  5734.     }
  5735.  
  5736.     const pageMatchesCount = this._pageMatches[pageIndex].length;
  5737.  
  5738.     if (pageMatchesCount > 0) {
  5739.       this._matchesCountTotal += pageMatchesCount;
  5740.  
  5741.       this._updateUIResultsCount();
  5742.     }
  5743.   }
  5744.  
  5745.   _extractText() {
  5746.     if (this._extractTextPromises.length > 0) {
  5747.       return;
  5748.     }
  5749.  
  5750.     let promise = Promise.resolve();
  5751.  
  5752.     for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5753.       const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5754.       this._extractTextPromises[i] = extractTextCapability.promise;
  5755.       promise = promise.then(() => {
  5756.         return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5757.           return pdfPage.getTextContent({
  5758.             normalizeWhitespace: true
  5759.           });
  5760.         }).then(textContent => {
  5761.           const textItems = textContent.items;
  5762.           const strBuf = [];
  5763.  
  5764.           for (let j = 0, jj = textItems.length; j < jj; j++) {
  5765.             strBuf.push(textItems[j].str);
  5766.           }
  5767.  
  5768.           [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  5769.           extractTextCapability.resolve(i);
  5770.         }, reason => {
  5771.           console.error(`Unable to get text content for page ${i + 1}`, reason);
  5772.           this._pageContents[i] = "";
  5773.           this._pageDiffs[i] = null;
  5774.           extractTextCapability.resolve(i);
  5775.         });
  5776.       });
  5777.     }
  5778.   }
  5779.  
  5780.   _updatePage(index) {
  5781.     if (this._scrollMatches && this._selected.pageIdx === index) {
  5782.       this._linkService.page = index + 1;
  5783.     }
  5784.  
  5785.     this._eventBus.dispatch("updatetextlayermatches", {
  5786.       source: this,
  5787.       pageIndex: index
  5788.     });
  5789.   }
  5790.  
  5791.   _updateAllPages() {
  5792.     this._eventBus.dispatch("updatetextlayermatches", {
  5793.       source: this,
  5794.       pageIndex: -1
  5795.     });
  5796.   }
  5797.  
  5798.   _nextMatch() {
  5799.     const previous = this._state.findPrevious;
  5800.     const currentPageIndex = this._linkService.page - 1;
  5801.     const numPages = this._linkService.pagesCount;
  5802.     this._highlightMatches = true;
  5803.  
  5804.     if (this._dirtyMatch) {
  5805.       this._dirtyMatch = false;
  5806.       this._selected.pageIdx = this._selected.matchIdx = -1;
  5807.       this._offset.pageIdx = currentPageIndex;
  5808.       this._offset.matchIdx = null;
  5809.       this._offset.wrapped = false;
  5810.       this._resumePageIdx = null;
  5811.       this._pageMatches.length = 0;
  5812.       this._pageMatchesLength.length = 0;
  5813.       this._matchesCountTotal = 0;
  5814.  
  5815.       this._updateAllPages();
  5816.  
  5817.       for (let i = 0; i < numPages; i++) {
  5818.         if (this._pendingFindMatches[i] === true) {
  5819.           continue;
  5820.         }
  5821.  
  5822.         this._pendingFindMatches[i] = true;
  5823.  
  5824.         this._extractTextPromises[i].then(pageIdx => {
  5825.           delete this._pendingFindMatches[pageIdx];
  5826.  
  5827.           this._calculateMatch(pageIdx);
  5828.         });
  5829.       }
  5830.     }
  5831.  
  5832.     if (this._query === "") {
  5833.       this._updateUIState(FindState.FOUND);
  5834.  
  5835.       return;
  5836.     }
  5837.  
  5838.     if (this._resumePageIdx) {
  5839.       return;
  5840.     }
  5841.  
  5842.     const offset = this._offset;
  5843.     this._pagesToSearch = numPages;
  5844.  
  5845.     if (offset.matchIdx !== null) {
  5846.       const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5847.  
  5848.       if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5849.         offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5850.  
  5851.         this._updateMatch(true);
  5852.  
  5853.         return;
  5854.       }
  5855.  
  5856.       this._advanceOffsetPage(previous);
  5857.     }
  5858.  
  5859.     this._nextPageMatch();
  5860.   }
  5861.  
  5862.   _matchesReady(matches) {
  5863.     const offset = this._offset;
  5864.     const numMatches = matches.length;
  5865.     const previous = this._state.findPrevious;
  5866.  
  5867.     if (numMatches) {
  5868.       offset.matchIdx = previous ? numMatches - 1 : 0;
  5869.  
  5870.       this._updateMatch(true);
  5871.  
  5872.       return true;
  5873.     }
  5874.  
  5875.     this._advanceOffsetPage(previous);
  5876.  
  5877.     if (offset.wrapped) {
  5878.       offset.matchIdx = null;
  5879.  
  5880.       if (this._pagesToSearch < 0) {
  5881.         this._updateMatch(false);
  5882.  
  5883.         return true;
  5884.       }
  5885.     }
  5886.  
  5887.     return false;
  5888.   }
  5889.  
  5890.   _nextPageMatch() {
  5891.     if (this._resumePageIdx !== null) {
  5892.       console.error("There can only be one pending page.");
  5893.     }
  5894.  
  5895.     let matches = null;
  5896.  
  5897.     do {
  5898.       const pageIdx = this._offset.pageIdx;
  5899.       matches = this._pageMatches[pageIdx];
  5900.  
  5901.       if (!matches) {
  5902.         this._resumePageIdx = pageIdx;
  5903.         break;
  5904.       }
  5905.     } while (!this._matchesReady(matches));
  5906.   }
  5907.  
  5908.   _advanceOffsetPage(previous) {
  5909.     const offset = this._offset;
  5910.     const numPages = this._linkService.pagesCount;
  5911.     offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5912.     offset.matchIdx = null;
  5913.     this._pagesToSearch--;
  5914.  
  5915.     if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5916.       offset.pageIdx = previous ? numPages - 1 : 0;
  5917.       offset.wrapped = true;
  5918.     }
  5919.   }
  5920.  
  5921.   _updateMatch(found = false) {
  5922.     let state = FindState.NOT_FOUND;
  5923.     const wrapped = this._offset.wrapped;
  5924.     this._offset.wrapped = false;
  5925.  
  5926.     if (found) {
  5927.       const previousPage = this._selected.pageIdx;
  5928.       this._selected.pageIdx = this._offset.pageIdx;
  5929.       this._selected.matchIdx = this._offset.matchIdx;
  5930.       state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5931.  
  5932.       if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5933.         this._updatePage(previousPage);
  5934.       }
  5935.     }
  5936.  
  5937.     this._updateUIState(state, this._state.findPrevious);
  5938.  
  5939.     if (this._selected.pageIdx !== -1) {
  5940.       this._scrollMatches = true;
  5941.  
  5942.       this._updatePage(this._selected.pageIdx);
  5943.     }
  5944.   }
  5945.  
  5946.   _onFindBarClose(evt) {
  5947.     const pdfDocument = this._pdfDocument;
  5948.  
  5949.     this._firstPageCapability.promise.then(() => {
  5950.       if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5951.         return;
  5952.       }
  5953.  
  5954.       if (this._findTimeout) {
  5955.         clearTimeout(this._findTimeout);
  5956.         this._findTimeout = null;
  5957.       }
  5958.  
  5959.       if (this._resumePageIdx) {
  5960.         this._resumePageIdx = null;
  5961.         this._dirtyMatch = true;
  5962.       }
  5963.  
  5964.       this._updateUIState(FindState.FOUND);
  5965.  
  5966.       this._highlightMatches = false;
  5967.  
  5968.       this._updateAllPages();
  5969.     });
  5970.   }
  5971.  
  5972.   _requestMatchesCount() {
  5973.     const {
  5974.       pageIdx,
  5975.       matchIdx
  5976.     } = this._selected;
  5977.     let current = 0,
  5978.         total = this._matchesCountTotal;
  5979.  
  5980.     if (matchIdx !== -1) {
  5981.       for (let i = 0; i < pageIdx; i++) {
  5982.         current += this._pageMatches[i]?.length || 0;
  5983.       }
  5984.  
  5985.       current += matchIdx + 1;
  5986.     }
  5987.  
  5988.     if (current < 1 || current > total) {
  5989.       current = total = 0;
  5990.     }
  5991.  
  5992.     return {
  5993.       current,
  5994.       total
  5995.     };
  5996.   }
  5997.  
  5998.   _updateUIResultsCount() {
  5999.     this._eventBus.dispatch("updatefindmatchescount", {
  6000.       source: this,
  6001.       matchesCount: this._requestMatchesCount()
  6002.     });
  6003.   }
  6004.  
  6005.   _updateUIState(state, previous) {
  6006.     this._eventBus.dispatch("updatefindcontrolstate", {
  6007.       source: this,
  6008.       state,
  6009.       previous,
  6010.       matchesCount: this._requestMatchesCount(),
  6011.       rawQuery: this._state?.query ?? null
  6012.     });
  6013.   }
  6014.  
  6015. }
  6016.  
  6017. exports.PDFFindController = PDFFindController;
  6018.  
  6019. /***/ }),
  6020. /* 16 */
  6021. /***/ ((__unused_webpack_module, exports) => {
  6022.  
  6023.  
  6024.  
  6025. Object.defineProperty(exports, "__esModule", ({
  6026.   value: true
  6027. }));
  6028. exports.getCharacterType = getCharacterType;
  6029. exports.CharacterType = void 0;
  6030. const CharacterType = {
  6031.   SPACE: 0,
  6032.   ALPHA_LETTER: 1,
  6033.   PUNCT: 2,
  6034.   HAN_LETTER: 3,
  6035.   KATAKANA_LETTER: 4,
  6036.   HIRAGANA_LETTER: 5,
  6037.   HALFWIDTH_KATAKANA_LETTER: 6,
  6038.   THAI_LETTER: 7
  6039. };
  6040. exports.CharacterType = CharacterType;
  6041.  
  6042. function isAlphabeticalScript(charCode) {
  6043.   return charCode < 0x2e80;
  6044. }
  6045.  
  6046. function isAscii(charCode) {
  6047.   return (charCode & 0xff80) === 0;
  6048. }
  6049.  
  6050. function isAsciiAlpha(charCode) {
  6051.   return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  6052. }
  6053.  
  6054. function isAsciiDigit(charCode) {
  6055.   return charCode >= 0x30 && charCode <= 0x39;
  6056. }
  6057.  
  6058. function isAsciiSpace(charCode) {
  6059.   return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  6060. }
  6061.  
  6062. function isHan(charCode) {
  6063.   return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  6064. }
  6065.  
  6066. function isKatakana(charCode) {
  6067.   return charCode >= 0x30a0 && charCode <= 0x30ff;
  6068. }
  6069.  
  6070. function isHiragana(charCode) {
  6071.   return charCode >= 0x3040 && charCode <= 0x309f;
  6072. }
  6073.  
  6074. function isHalfwidthKatakana(charCode) {
  6075.   return charCode >= 0xff60 && charCode <= 0xff9f;
  6076. }
  6077.  
  6078. function isThai(charCode) {
  6079.   return (charCode & 0xff80) === 0x0e00;
  6080. }
  6081.  
  6082. function getCharacterType(charCode) {
  6083.   if (isAlphabeticalScript(charCode)) {
  6084.     if (isAscii(charCode)) {
  6085.       if (isAsciiSpace(charCode)) {
  6086.         return CharacterType.SPACE;
  6087.       } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  6088.         return CharacterType.ALPHA_LETTER;
  6089.       }
  6090.  
  6091.       return CharacterType.PUNCT;
  6092.     } else if (isThai(charCode)) {
  6093.       return CharacterType.THAI_LETTER;
  6094.     } else if (charCode === 0xa0) {
  6095.       return CharacterType.SPACE;
  6096.     }
  6097.  
  6098.     return CharacterType.ALPHA_LETTER;
  6099.   }
  6100.  
  6101.   if (isHan(charCode)) {
  6102.     return CharacterType.HAN_LETTER;
  6103.   } else if (isKatakana(charCode)) {
  6104.     return CharacterType.KATAKANA_LETTER;
  6105.   } else if (isHiragana(charCode)) {
  6106.     return CharacterType.HIRAGANA_LETTER;
  6107.   } else if (isHalfwidthKatakana(charCode)) {
  6108.     return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  6109.   }
  6110.  
  6111.   return CharacterType.ALPHA_LETTER;
  6112. }
  6113.  
  6114. /***/ }),
  6115. /* 17 */
  6116. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6117.  
  6118.  
  6119.  
  6120. Object.defineProperty(exports, "__esModule", ({
  6121.   value: true
  6122. }));
  6123. exports.isDestArraysEqual = isDestArraysEqual;
  6124. exports.isDestHashesEqual = isDestHashesEqual;
  6125. exports.PDFHistory = void 0;
  6126.  
  6127. var _ui_utils = __webpack_require__(4);
  6128.  
  6129. const HASH_CHANGE_TIMEOUT = 1000;
  6130. const POSITION_UPDATED_THRESHOLD = 50;
  6131. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  6132.  
  6133. function getCurrentHash() {
  6134.   return document.location.hash;
  6135. }
  6136.  
  6137. class PDFHistory {
  6138.   constructor({
  6139.     linkService,
  6140.     eventBus
  6141.   }) {<