You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14595 lines
441KB

  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2024 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. /******/ // The require scope
  23. /******/ var __webpack_require__ = {};
  24. /******/
  25. /************************************************************************/
  26. /******/ /* webpack/runtime/define property getters */
  27. /******/ (() => {
  28. /******/ // define getter functions for harmony exports
  29. /******/ __webpack_require__.d = (exports, definition) => {
  30. /******/ for(var key in definition) {
  31. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  32. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  33. /******/ }
  34. /******/ }
  35. /******/ };
  36. /******/ })();
  37. /******/
  38. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  39. /******/ (() => {
  40. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  41. /******/ })();
  42. /******/
  43. /************************************************************************/
  44. var __webpack_exports__ = {};
  45. // EXPORTS
  46. __webpack_require__.d(__webpack_exports__, {
  47. PDFViewerApplication: () => (/* reexport */ PDFViewerApplication),
  48. PDFViewerApplicationConstants: () => (/* binding */ AppConstants),
  49. PDFViewerApplicationOptions: () => (/* reexport */ AppOptions)
  50. });
  51. ;// CONCATENATED MODULE: ./web/ui_utils.js
  52. const DEFAULT_SCALE_VALUE = "auto";
  53. const DEFAULT_SCALE = 1.0;
  54. const DEFAULT_SCALE_DELTA = 1.1;
  55. const MIN_SCALE = 0.1;
  56. const MAX_SCALE = 10.0;
  57. const UNKNOWN_SCALE = 0;
  58. const MAX_AUTO_SCALE = 1.25;
  59. const SCROLLBAR_PADDING = 40;
  60. const VERTICAL_PADDING = 5;
  61. const RenderingStates = {
  62. INITIAL: 0,
  63. RUNNING: 1,
  64. PAUSED: 2,
  65. FINISHED: 3
  66. };
  67. const PresentationModeState = {
  68. UNKNOWN: 0,
  69. NORMAL: 1,
  70. CHANGING: 2,
  71. FULLSCREEN: 3
  72. };
  73. const SidebarView = {
  74. UNKNOWN: -1,
  75. NONE: 0,
  76. THUMBS: 1,
  77. OUTLINE: 2,
  78. ATTACHMENTS: 3,
  79. LAYERS: 4
  80. };
  81. const TextLayerMode = {
  82. DISABLE: 0,
  83. ENABLE: 1,
  84. ENABLE_PERMISSIONS: 2
  85. };
  86. const ScrollMode = {
  87. UNKNOWN: -1,
  88. VERTICAL: 0,
  89. HORIZONTAL: 1,
  90. WRAPPED: 2,
  91. PAGE: 3
  92. };
  93. const SpreadMode = {
  94. UNKNOWN: -1,
  95. NONE: 0,
  96. ODD: 1,
  97. EVEN: 2
  98. };
  99. const CursorTool = {
  100. SELECT: 0,
  101. HAND: 1,
  102. ZOOM: 2
  103. };
  104. const AutoPrintRegExp = /\bprint\s*\(/;
  105. class OutputScale {
  106. constructor() {
  107. const pixelRatio = window.devicePixelRatio || 1;
  108. this.sx = pixelRatio;
  109. this.sy = pixelRatio;
  110. }
  111. get scaled() {
  112. return this.sx !== 1 || this.sy !== 1;
  113. }
  114. }
  115. function scrollIntoView(element, spot, scrollMatches = false) {
  116. let parent = element.offsetParent;
  117. if (!parent) {
  118. console.error("offsetParent is not set -- cannot scroll");
  119. return;
  120. }
  121. let offsetY = element.offsetTop + element.clientTop;
  122. let offsetX = element.offsetLeft + element.clientLeft;
  123. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  124. offsetY += parent.offsetTop;
  125. offsetX += parent.offsetLeft;
  126. parent = parent.offsetParent;
  127. if (!parent) {
  128. return;
  129. }
  130. }
  131. if (spot) {
  132. if (spot.top !== undefined) {
  133. offsetY += spot.top;
  134. }
  135. if (spot.left !== undefined) {
  136. offsetX += spot.left;
  137. parent.scrollLeft = offsetX;
  138. }
  139. }
  140. parent.scrollTop = offsetY;
  141. }
  142. function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
  143. const debounceScroll = function (evt) {
  144. if (rAF) {
  145. return;
  146. }
  147. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  148. rAF = null;
  149. const currentX = viewAreaElement.scrollLeft;
  150. const lastX = state.lastX;
  151. if (currentX !== lastX) {
  152. state.right = currentX > lastX;
  153. }
  154. state.lastX = currentX;
  155. const currentY = viewAreaElement.scrollTop;
  156. const lastY = state.lastY;
  157. if (currentY !== lastY) {
  158. state.down = currentY > lastY;
  159. }
  160. state.lastY = currentY;
  161. callback(state);
  162. });
  163. };
  164. const state = {
  165. right: true,
  166. down: true,
  167. lastX: viewAreaElement.scrollLeft,
  168. lastY: viewAreaElement.scrollTop,
  169. _eventHandler: debounceScroll
  170. };
  171. let rAF = null;
  172. viewAreaElement.addEventListener("scroll", debounceScroll, {
  173. useCapture: true,
  174. signal: abortSignal
  175. });
  176. abortSignal?.addEventListener("abort", () => window.cancelAnimationFrame(rAF), {
  177. once: true
  178. });
  179. return state;
  180. }
  181. function parseQueryString(query) {
  182. const params = new Map();
  183. for (const [key, value] of new URLSearchParams(query)) {
  184. params.set(key.toLowerCase(), value);
  185. }
  186. return params;
  187. }
  188. const InvisibleCharsRegExp = /[\x00-\x1F]/g;
  189. function removeNullCharacters(str, replaceInvisible = false) {
  190. if (!InvisibleCharsRegExp.test(str)) {
  191. return str;
  192. }
  193. if (replaceInvisible) {
  194. return str.replaceAll(InvisibleCharsRegExp, m => m === "\x00" ? "" : " ");
  195. }
  196. return str.replaceAll("\x00", "");
  197. }
  198. function binarySearchFirstItem(items, condition, start = 0) {
  199. let minIndex = start;
  200. let maxIndex = items.length - 1;
  201. if (maxIndex < 0 || !condition(items[maxIndex])) {
  202. return items.length;
  203. }
  204. if (condition(items[minIndex])) {
  205. return minIndex;
  206. }
  207. while (minIndex < maxIndex) {
  208. const currentIndex = minIndex + maxIndex >> 1;
  209. const currentItem = items[currentIndex];
  210. if (condition(currentItem)) {
  211. maxIndex = currentIndex;
  212. } else {
  213. minIndex = currentIndex + 1;
  214. }
  215. }
  216. return minIndex;
  217. }
  218. function approximateFraction(x) {
  219. if (Math.floor(x) === x) {
  220. return [x, 1];
  221. }
  222. const xinv = 1 / x;
  223. const limit = 8;
  224. if (xinv > limit) {
  225. return [1, limit];
  226. } else if (Math.floor(xinv) === xinv) {
  227. return [1, xinv];
  228. }
  229. const x_ = x > 1 ? xinv : x;
  230. let a = 0,
  231. b = 1,
  232. c = 1,
  233. d = 1;
  234. while (true) {
  235. const p = a + c,
  236. q = b + d;
  237. if (q > limit) {
  238. break;
  239. }
  240. if (x_ <= p / q) {
  241. c = p;
  242. d = q;
  243. } else {
  244. a = p;
  245. b = q;
  246. }
  247. }
  248. let result;
  249. if (x_ - a / b < c / d - x_) {
  250. result = x_ === x ? [a, b] : [b, a];
  251. } else {
  252. result = x_ === x ? [c, d] : [d, c];
  253. }
  254. return result;
  255. }
  256. function floorToDivide(x, div) {
  257. return x - x % div;
  258. }
  259. function getPageSizeInches({
  260. view,
  261. userUnit,
  262. rotate
  263. }) {
  264. const [x1, y1, x2, y2] = view;
  265. const changeOrientation = rotate % 180 !== 0;
  266. const width = (x2 - x1) / 72 * userUnit;
  267. const height = (y2 - y1) / 72 * userUnit;
  268. return {
  269. width: changeOrientation ? height : width,
  270. height: changeOrientation ? width : height
  271. };
  272. }
  273. function backtrackBeforeAllVisibleElements(index, views, top) {
  274. if (index < 2) {
  275. return index;
  276. }
  277. let elt = views[index].div;
  278. let pageTop = elt.offsetTop + elt.clientTop;
  279. if (pageTop >= top) {
  280. elt = views[index - 1].div;
  281. pageTop = elt.offsetTop + elt.clientTop;
  282. }
  283. for (let i = index - 2; i >= 0; --i) {
  284. elt = views[i].div;
  285. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  286. break;
  287. }
  288. index = i;
  289. }
  290. return index;
  291. }
  292. function getVisibleElements({
  293. scrollEl,
  294. views,
  295. sortByVisibility = false,
  296. horizontal = false,
  297. rtl = false
  298. }) {
  299. const top = scrollEl.scrollTop,
  300. bottom = top + scrollEl.clientHeight;
  301. const left = scrollEl.scrollLeft,
  302. right = left + scrollEl.clientWidth;
  303. function isElementBottomAfterViewTop(view) {
  304. const element = view.div;
  305. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  306. return elementBottom > top;
  307. }
  308. function isElementNextAfterViewHorizontally(view) {
  309. const element = view.div;
  310. const elementLeft = element.offsetLeft + element.clientLeft;
  311. const elementRight = elementLeft + element.clientWidth;
  312. return rtl ? elementLeft < right : elementRight > left;
  313. }
  314. const visible = [],
  315. ids = new Set(),
  316. numViews = views.length;
  317. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  318. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  319. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  320. }
  321. let lastEdge = horizontal ? right : -1;
  322. for (let i = firstVisibleElementInd; i < numViews; i++) {
  323. const view = views[i],
  324. element = view.div;
  325. const currentWidth = element.offsetLeft + element.clientLeft;
  326. const currentHeight = element.offsetTop + element.clientTop;
  327. const viewWidth = element.clientWidth,
  328. viewHeight = element.clientHeight;
  329. const viewRight = currentWidth + viewWidth;
  330. const viewBottom = currentHeight + viewHeight;
  331. if (lastEdge === -1) {
  332. if (viewBottom >= bottom) {
  333. lastEdge = viewBottom;
  334. }
  335. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  336. break;
  337. }
  338. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  339. continue;
  340. }
  341. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  342. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  343. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  344. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  345. const percent = fractionHeight * fractionWidth * 100 | 0;
  346. visible.push({
  347. id: view.id,
  348. x: currentWidth,
  349. y: currentHeight,
  350. view,
  351. percent,
  352. widthPercent: fractionWidth * 100 | 0
  353. });
  354. ids.add(view.id);
  355. }
  356. const first = visible[0],
  357. last = visible.at(-1);
  358. if (sortByVisibility) {
  359. visible.sort(function (a, b) {
  360. const pc = a.percent - b.percent;
  361. if (Math.abs(pc) > 0.001) {
  362. return -pc;
  363. }
  364. return a.id - b.id;
  365. });
  366. }
  367. return {
  368. first,
  369. last,
  370. views: visible,
  371. ids
  372. };
  373. }
  374. function normalizeWheelEventDirection(evt) {
  375. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  376. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  377. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  378. delta = -delta;
  379. }
  380. return delta;
  381. }
  382. function normalizeWheelEventDelta(evt) {
  383. const deltaMode = evt.deltaMode;
  384. let delta = normalizeWheelEventDirection(evt);
  385. const MOUSE_PIXELS_PER_LINE = 30;
  386. const MOUSE_LINES_PER_PAGE = 30;
  387. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  388. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  389. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  390. delta /= MOUSE_LINES_PER_PAGE;
  391. }
  392. return delta;
  393. }
  394. function isValidRotation(angle) {
  395. return Number.isInteger(angle) && angle % 90 === 0;
  396. }
  397. function isValidScrollMode(mode) {
  398. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  399. }
  400. function isValidSpreadMode(mode) {
  401. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  402. }
  403. function isPortraitOrientation(size) {
  404. return size.width <= size.height;
  405. }
  406. const animationStarted = new Promise(function (resolve) {
  407. window.requestAnimationFrame(resolve);
  408. });
  409. const docStyle = document.documentElement.style;
  410. function clamp(v, min, max) {
  411. return Math.min(Math.max(v, min), max);
  412. }
  413. class ProgressBar {
  414. #classList = null;
  415. #disableAutoFetchTimeout = null;
  416. #percent = 0;
  417. #style = null;
  418. #visible = true;
  419. constructor(bar) {
  420. this.#classList = bar.classList;
  421. this.#style = bar.style;
  422. }
  423. get percent() {
  424. return this.#percent;
  425. }
  426. set percent(val) {
  427. this.#percent = clamp(val, 0, 100);
  428. if (isNaN(val)) {
  429. this.#classList.add("indeterminate");
  430. return;
  431. }
  432. this.#classList.remove("indeterminate");
  433. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  434. }
  435. setWidth(viewer) {
  436. if (!viewer) {
  437. return;
  438. }
  439. const container = viewer.parentNode;
  440. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  441. if (scrollbarWidth > 0) {
  442. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  443. }
  444. }
  445. setDisableAutoFetch(delay = 5000) {
  446. if (this.#percent === 100 || isNaN(this.#percent)) {
  447. return;
  448. }
  449. if (this.#disableAutoFetchTimeout) {
  450. clearTimeout(this.#disableAutoFetchTimeout);
  451. }
  452. this.show();
  453. this.#disableAutoFetchTimeout = setTimeout(() => {
  454. this.#disableAutoFetchTimeout = null;
  455. this.hide();
  456. }, delay);
  457. }
  458. hide() {
  459. if (!this.#visible) {
  460. return;
  461. }
  462. this.#visible = false;
  463. this.#classList.add("hidden");
  464. }
  465. show() {
  466. if (this.#visible) {
  467. return;
  468. }
  469. this.#visible = true;
  470. this.#classList.remove("hidden");
  471. }
  472. }
  473. function getActiveOrFocusedElement() {
  474. let curRoot = document;
  475. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  476. while (curActiveOrFocused?.shadowRoot) {
  477. curRoot = curActiveOrFocused.shadowRoot;
  478. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  479. }
  480. return curActiveOrFocused;
  481. }
  482. function apiPageLayoutToViewerModes(layout) {
  483. let scrollMode = ScrollMode.VERTICAL,
  484. spreadMode = SpreadMode.NONE;
  485. switch (layout) {
  486. case "SinglePage":
  487. scrollMode = ScrollMode.PAGE;
  488. break;
  489. case "OneColumn":
  490. break;
  491. case "TwoPageLeft":
  492. scrollMode = ScrollMode.PAGE;
  493. case "TwoColumnLeft":
  494. spreadMode = SpreadMode.ODD;
  495. break;
  496. case "TwoPageRight":
  497. scrollMode = ScrollMode.PAGE;
  498. case "TwoColumnRight":
  499. spreadMode = SpreadMode.EVEN;
  500. break;
  501. }
  502. return {
  503. scrollMode,
  504. spreadMode
  505. };
  506. }
  507. function apiPageModeToSidebarView(mode) {
  508. switch (mode) {
  509. case "UseNone":
  510. return SidebarView.NONE;
  511. case "UseThumbs":
  512. return SidebarView.THUMBS;
  513. case "UseOutlines":
  514. return SidebarView.OUTLINE;
  515. case "UseAttachments":
  516. return SidebarView.ATTACHMENTS;
  517. case "UseOC":
  518. return SidebarView.LAYERS;
  519. }
  520. return SidebarView.NONE;
  521. }
  522. function toggleCheckedBtn(button, toggle, view = null) {
  523. button.classList.toggle("toggled", toggle);
  524. button.setAttribute("aria-checked", toggle);
  525. view?.classList.toggle("hidden", !toggle);
  526. }
  527. function toggleExpandedBtn(button, toggle, view = null) {
  528. button.classList.toggle("toggled", toggle);
  529. button.setAttribute("aria-expanded", toggle);
  530. view?.classList.toggle("hidden", !toggle);
  531. }
  532. ;// CONCATENATED MODULE: ./web/app_options.js
  533. {
  534. var compatParams = new Map();
  535. const userAgent = navigator.userAgent || "";
  536. const platform = navigator.platform || "";
  537. const maxTouchPoints = navigator.maxTouchPoints || 1;
  538. const isAndroid = /Android/.test(userAgent);
  539. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  540. (function () {
  541. if (isIOS || isAndroid) {
  542. compatParams.set("maxCanvasPixels", 5242880);
  543. }
  544. })();
  545. (function () {
  546. if (isAndroid) {
  547. compatParams.set("useSystemFonts", false);
  548. }
  549. })();
  550. }
  551. const OptionKind = {
  552. BROWSER: 0x01,
  553. VIEWER: 0x02,
  554. API: 0x04,
  555. WORKER: 0x08,
  556. EVENT_DISPATCH: 0x10,
  557. PREFERENCE: 0x80
  558. };
  559. const Type = {
  560. BOOLEAN: 0x01,
  561. NUMBER: 0x02,
  562. OBJECT: 0x04,
  563. STRING: 0x08,
  564. UNDEFINED: 0x10
  565. };
  566. const defaultOptions = {
  567. allowedGlobalEvents: {
  568. value: null,
  569. kind: OptionKind.BROWSER
  570. },
  571. canvasMaxAreaInBytes: {
  572. value: -1,
  573. kind: OptionKind.BROWSER + OptionKind.API
  574. },
  575. isInAutomation: {
  576. value: false,
  577. kind: OptionKind.BROWSER
  578. },
  579. localeProperties: {
  580. value: {
  581. lang: navigator.language || "en-US"
  582. },
  583. kind: OptionKind.BROWSER
  584. },
  585. nimbusDataStr: {
  586. value: "",
  587. kind: OptionKind.BROWSER
  588. },
  589. supportsCaretBrowsingMode: {
  590. value: false,
  591. kind: OptionKind.BROWSER
  592. },
  593. supportsDocumentFonts: {
  594. value: true,
  595. kind: OptionKind.BROWSER
  596. },
  597. supportsIntegratedFind: {
  598. value: false,
  599. kind: OptionKind.BROWSER
  600. },
  601. supportsMouseWheelZoomCtrlKey: {
  602. value: true,
  603. kind: OptionKind.BROWSER
  604. },
  605. supportsMouseWheelZoomMetaKey: {
  606. value: true,
  607. kind: OptionKind.BROWSER
  608. },
  609. supportsPinchToZoom: {
  610. value: true,
  611. kind: OptionKind.BROWSER
  612. },
  613. toolbarDensity: {
  614. value: 0,
  615. kind: OptionKind.BROWSER + OptionKind.EVENT_DISPATCH
  616. },
  617. altTextLearnMoreUrl: {
  618. value: "",
  619. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  620. },
  621. annotationEditorMode: {
  622. value: 0,
  623. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  624. },
  625. annotationMode: {
  626. value: 2,
  627. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  628. },
  629. cursorToolOnLoad: {
  630. value: 0,
  631. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  632. },
  633. debuggerSrc: {
  634. value: "./debugger.mjs",
  635. kind: OptionKind.VIEWER
  636. },
  637. defaultZoomDelay: {
  638. value: 400,
  639. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  640. },
  641. defaultZoomValue: {
  642. value: "",
  643. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  644. },
  645. disableHistory: {
  646. value: false,
  647. kind: OptionKind.VIEWER
  648. },
  649. disablePageLabels: {
  650. value: false,
  651. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  652. },
  653. enableAltText: {
  654. value: false,
  655. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  656. },
  657. enableGuessAltText: {
  658. value: true,
  659. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  660. },
  661. enableHighlightEditor: {
  662. value: false,
  663. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  664. },
  665. enableHighlightFloatingButton: {
  666. value: false,
  667. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  668. },
  669. enablePermissions: {
  670. value: false,
  671. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  672. },
  673. enablePrintAutoRotate: {
  674. value: true,
  675. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  676. },
  677. enableScripting: {
  678. value: true,
  679. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  680. },
  681. enableUpdatedAddImage: {
  682. value: false,
  683. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  684. },
  685. externalLinkRel: {
  686. value: "noopener noreferrer nofollow",
  687. kind: OptionKind.VIEWER
  688. },
  689. externalLinkTarget: {
  690. value: 0,
  691. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  692. },
  693. highlightEditorColors: {
  694. value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
  695. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  696. },
  697. historyUpdateUrl: {
  698. value: false,
  699. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  700. },
  701. ignoreDestinationZoom: {
  702. value: false,
  703. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  704. },
  705. imageResourcesPath: {
  706. value: "./images/",
  707. kind: OptionKind.VIEWER
  708. },
  709. maxCanvasPixels: {
  710. value: 2 ** 25,
  711. kind: OptionKind.VIEWER
  712. },
  713. forcePageColors: {
  714. value: false,
  715. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  716. },
  717. pageColorsBackground: {
  718. value: "Canvas",
  719. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  720. },
  721. pageColorsForeground: {
  722. value: "CanvasText",
  723. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  724. },
  725. pdfBugEnabled: {
  726. value: false,
  727. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  728. },
  729. printResolution: {
  730. value: 150,
  731. kind: OptionKind.VIEWER
  732. },
  733. sidebarViewOnLoad: {
  734. value: -1,
  735. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  736. },
  737. scrollModeOnLoad: {
  738. value: -1,
  739. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  740. },
  741. spreadModeOnLoad: {
  742. value: -1,
  743. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  744. },
  745. textLayerMode: {
  746. value: 1,
  747. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  748. },
  749. viewOnLoad: {
  750. value: 0,
  751. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  752. },
  753. cMapPacked: {
  754. value: true,
  755. kind: OptionKind.API
  756. },
  757. cMapUrl: {
  758. value: "../web/cmaps/",
  759. kind: OptionKind.API
  760. },
  761. disableAutoFetch: {
  762. value: false,
  763. kind: OptionKind.API + OptionKind.PREFERENCE
  764. },
  765. disableFontFace: {
  766. value: false,
  767. kind: OptionKind.API + OptionKind.PREFERENCE
  768. },
  769. disableRange: {
  770. value: false,
  771. kind: OptionKind.API + OptionKind.PREFERENCE
  772. },
  773. disableStream: {
  774. value: false,
  775. kind: OptionKind.API + OptionKind.PREFERENCE
  776. },
  777. docBaseUrl: {
  778. value: "",
  779. kind: OptionKind.API
  780. },
  781. enableHWA: {
  782. value: true,
  783. kind: OptionKind.API + OptionKind.VIEWER + OptionKind.PREFERENCE
  784. },
  785. enableXfa: {
  786. value: true,
  787. kind: OptionKind.API + OptionKind.PREFERENCE
  788. },
  789. fontExtraProperties: {
  790. value: false,
  791. kind: OptionKind.API
  792. },
  793. isEvalSupported: {
  794. value: true,
  795. kind: OptionKind.API
  796. },
  797. isOffscreenCanvasSupported: {
  798. value: true,
  799. kind: OptionKind.API
  800. },
  801. maxImageSize: {
  802. value: -1,
  803. kind: OptionKind.API
  804. },
  805. pdfBug: {
  806. value: false,
  807. kind: OptionKind.API
  808. },
  809. standardFontDataUrl: {
  810. value: "../web/standard_fonts/",
  811. kind: OptionKind.API
  812. },
  813. useSystemFonts: {
  814. value: undefined,
  815. kind: OptionKind.API,
  816. type: Type.BOOLEAN + Type.UNDEFINED
  817. },
  818. verbosity: {
  819. value: 1,
  820. kind: OptionKind.API
  821. },
  822. workerPort: {
  823. value: null,
  824. kind: OptionKind.WORKER
  825. },
  826. workerSrc: {
  827. value: "../build/pdf.worker.mjs",
  828. kind: OptionKind.WORKER
  829. }
  830. };
  831. {
  832. defaultOptions.defaultUrl = {
  833. value: "compressed.tracemonkey-pldi-09.pdf",
  834. kind: OptionKind.VIEWER
  835. };
  836. defaultOptions.sandboxBundleSrc = {
  837. value: "../build/pdf.sandbox.mjs",
  838. kind: OptionKind.VIEWER
  839. };
  840. defaultOptions.viewerCssTheme = {
  841. value: 0,
  842. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  843. };
  844. }
  845. {
  846. defaultOptions.disablePreferences = {
  847. value: false,
  848. kind: OptionKind.VIEWER
  849. };
  850. }
  851. const userOptions = new Map();
  852. {
  853. for (const [name, value] of compatParams) {
  854. userOptions.set(name, value);
  855. }
  856. }
  857. class AppOptions {
  858. static eventBus;
  859. constructor() {
  860. throw new Error("Cannot initialize AppOptions.");
  861. }
  862. static get(name) {
  863. return userOptions.has(name) ? userOptions.get(name) : defaultOptions[name]?.value;
  864. }
  865. static getAll(kind = null, defaultOnly = false) {
  866. const options = Object.create(null);
  867. for (const name in defaultOptions) {
  868. const defaultOpt = defaultOptions[name];
  869. if (kind && !(kind & defaultOpt.kind)) {
  870. continue;
  871. }
  872. options[name] = !defaultOnly && userOptions.has(name) ? userOptions.get(name) : defaultOpt.value;
  873. }
  874. return options;
  875. }
  876. static set(name, value) {
  877. this.setAll({
  878. [name]: value
  879. });
  880. }
  881. static setAll(options, prefs = false) {
  882. let events;
  883. for (const name in options) {
  884. const defaultOpt = defaultOptions[name],
  885. userOpt = options[name];
  886. if (!defaultOpt || !(typeof userOpt === typeof defaultOpt.value || Type[(typeof userOpt).toUpperCase()] & defaultOpt.type)) {
  887. continue;
  888. }
  889. const {
  890. kind
  891. } = defaultOpt;
  892. if (prefs && !(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
  893. continue;
  894. }
  895. if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
  896. (events ||= new Map()).set(name, userOpt);
  897. }
  898. userOptions.set(name, userOpt);
  899. }
  900. if (events) {
  901. for (const [name, value] of events) {
  902. this.eventBus.dispatch(name.toLowerCase(), {
  903. source: this,
  904. value
  905. });
  906. }
  907. }
  908. }
  909. }
  910. {
  911. AppOptions._checkDisablePreferences = () => {
  912. if (AppOptions.get("disablePreferences")) {
  913. return true;
  914. }
  915. for (const [name] of userOptions) {
  916. if (compatParams.has(name)) {
  917. continue;
  918. }
  919. console.warn("The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option to prevent that.');
  920. break;
  921. }
  922. return false;
  923. };
  924. }
  925. ;// CONCATENATED MODULE: ./web/pdf_link_service.js
  926. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  927. const LinkTarget = {
  928. NONE: 0,
  929. SELF: 1,
  930. BLANK: 2,
  931. PARENT: 3,
  932. TOP: 4
  933. };
  934. class PDFLinkService {
  935. externalLinkEnabled = true;
  936. constructor({
  937. eventBus,
  938. externalLinkTarget = null,
  939. externalLinkRel = null,
  940. ignoreDestinationZoom = false
  941. } = {}) {
  942. this.eventBus = eventBus;
  943. this.externalLinkTarget = externalLinkTarget;
  944. this.externalLinkRel = externalLinkRel;
  945. this._ignoreDestinationZoom = ignoreDestinationZoom;
  946. this.baseUrl = null;
  947. this.pdfDocument = null;
  948. this.pdfViewer = null;
  949. this.pdfHistory = null;
  950. }
  951. setDocument(pdfDocument, baseUrl = null) {
  952. this.baseUrl = baseUrl;
  953. this.pdfDocument = pdfDocument;
  954. }
  955. setViewer(pdfViewer) {
  956. this.pdfViewer = pdfViewer;
  957. }
  958. setHistory(pdfHistory) {
  959. this.pdfHistory = pdfHistory;
  960. }
  961. get pagesCount() {
  962. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  963. }
  964. get page() {
  965. return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1;
  966. }
  967. set page(value) {
  968. if (this.pdfDocument) {
  969. this.pdfViewer.currentPageNumber = value;
  970. }
  971. }
  972. get rotation() {
  973. return this.pdfDocument ? this.pdfViewer.pagesRotation : 0;
  974. }
  975. set rotation(value) {
  976. if (this.pdfDocument) {
  977. this.pdfViewer.pagesRotation = value;
  978. }
  979. }
  980. get isInPresentationMode() {
  981. return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false;
  982. }
  983. async goToDestination(dest) {
  984. if (!this.pdfDocument) {
  985. return;
  986. }
  987. let namedDest, explicitDest, pageNumber;
  988. if (typeof dest === "string") {
  989. namedDest = dest;
  990. explicitDest = await this.pdfDocument.getDestination(dest);
  991. } else {
  992. namedDest = null;
  993. explicitDest = await dest;
  994. }
  995. if (!Array.isArray(explicitDest)) {
  996. console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`);
  997. return;
  998. }
  999. const [destRef] = explicitDest;
  1000. if (destRef && typeof destRef === "object") {
  1001. pageNumber = this.pdfDocument.cachedPageNumber(destRef);
  1002. if (!pageNumber) {
  1003. try {
  1004. pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1;
  1005. } catch {
  1006. console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`);
  1007. return;
  1008. }
  1009. }
  1010. } else if (Number.isInteger(destRef)) {
  1011. pageNumber = destRef + 1;
  1012. }
  1013. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  1014. console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`);
  1015. return;
  1016. }
  1017. if (this.pdfHistory) {
  1018. this.pdfHistory.pushCurrentPosition();
  1019. this.pdfHistory.push({
  1020. namedDest,
  1021. explicitDest,
  1022. pageNumber
  1023. });
  1024. }
  1025. this.pdfViewer.scrollPageIntoView({
  1026. pageNumber,
  1027. destArray: explicitDest,
  1028. ignoreDestinationZoom: this._ignoreDestinationZoom
  1029. });
  1030. }
  1031. goToPage(val) {
  1032. if (!this.pdfDocument) {
  1033. return;
  1034. }
  1035. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  1036. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  1037. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  1038. return;
  1039. }
  1040. if (this.pdfHistory) {
  1041. this.pdfHistory.pushCurrentPosition();
  1042. this.pdfHistory.pushPage(pageNumber);
  1043. }
  1044. this.pdfViewer.scrollPageIntoView({
  1045. pageNumber
  1046. });
  1047. }
  1048. addLinkAttributes(link, url, newWindow = false) {
  1049. if (!url || typeof url !== "string") {
  1050. throw new Error('A valid "url" parameter must provided.');
  1051. }
  1052. const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  1053. rel = this.externalLinkRel;
  1054. if (this.externalLinkEnabled) {
  1055. link.href = link.title = url;
  1056. } else {
  1057. link.href = "";
  1058. link.title = `Disabled: ${url}`;
  1059. link.onclick = () => false;
  1060. }
  1061. let targetStr = "";
  1062. switch (target) {
  1063. case LinkTarget.NONE:
  1064. break;
  1065. case LinkTarget.SELF:
  1066. targetStr = "_self";
  1067. break;
  1068. case LinkTarget.BLANK:
  1069. targetStr = "_blank";
  1070. break;
  1071. case LinkTarget.PARENT:
  1072. targetStr = "_parent";
  1073. break;
  1074. case LinkTarget.TOP:
  1075. targetStr = "_top";
  1076. break;
  1077. }
  1078. link.target = targetStr;
  1079. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  1080. }
  1081. getDestinationHash(dest) {
  1082. if (typeof dest === "string") {
  1083. if (dest.length > 0) {
  1084. return this.getAnchorUrl("#" + escape(dest));
  1085. }
  1086. } else if (Array.isArray(dest)) {
  1087. const str = JSON.stringify(dest);
  1088. if (str.length > 0) {
  1089. return this.getAnchorUrl("#" + escape(str));
  1090. }
  1091. }
  1092. return this.getAnchorUrl("");
  1093. }
  1094. getAnchorUrl(anchor) {
  1095. return this.baseUrl ? this.baseUrl + anchor : anchor;
  1096. }
  1097. setHash(hash) {
  1098. if (!this.pdfDocument) {
  1099. return;
  1100. }
  1101. let pageNumber, dest;
  1102. if (hash.includes("=")) {
  1103. const params = parseQueryString(hash);
  1104. if (params.has("search")) {
  1105. const query = params.get("search").replaceAll('"', ""),
  1106. phrase = params.get("phrase") === "true";
  1107. this.eventBus.dispatch("findfromurlhash", {
  1108. source: this,
  1109. query: phrase ? query : query.match(/\S+/g)
  1110. });
  1111. }
  1112. if (params.has("page")) {
  1113. pageNumber = params.get("page") | 0 || 1;
  1114. }
  1115. if (params.has("zoom")) {
  1116. const zoomArgs = params.get("zoom").split(",");
  1117. const zoomArg = zoomArgs[0];
  1118. const zoomArgNumber = parseFloat(zoomArg);
  1119. if (!zoomArg.includes("Fit")) {
  1120. dest = [null, {
  1121. name: "XYZ"
  1122. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1123. } else if (zoomArg === "Fit" || zoomArg === "FitB") {
  1124. dest = [null, {
  1125. name: zoomArg
  1126. }];
  1127. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1128. dest = [null, {
  1129. name: zoomArg
  1130. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1131. } else if (zoomArg === "FitR") {
  1132. if (zoomArgs.length !== 5) {
  1133. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1134. } else {
  1135. dest = [null, {
  1136. name: zoomArg
  1137. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1138. }
  1139. } else {
  1140. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1141. }
  1142. }
  1143. if (dest) {
  1144. this.pdfViewer.scrollPageIntoView({
  1145. pageNumber: pageNumber || this.page,
  1146. destArray: dest,
  1147. allowNegativeOffset: true
  1148. });
  1149. } else if (pageNumber) {
  1150. this.page = pageNumber;
  1151. }
  1152. if (params.has("pagemode")) {
  1153. this.eventBus.dispatch("pagemode", {
  1154. source: this,
  1155. mode: params.get("pagemode")
  1156. });
  1157. }
  1158. if (params.has("nameddest")) {
  1159. this.goToDestination(params.get("nameddest"));
  1160. }
  1161. return;
  1162. }
  1163. dest = unescape(hash);
  1164. try {
  1165. dest = JSON.parse(dest);
  1166. if (!Array.isArray(dest)) {
  1167. dest = dest.toString();
  1168. }
  1169. } catch {}
  1170. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDest(dest)) {
  1171. this.goToDestination(dest);
  1172. return;
  1173. }
  1174. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1175. }
  1176. executeNamedAction(action) {
  1177. if (!this.pdfDocument) {
  1178. return;
  1179. }
  1180. switch (action) {
  1181. case "GoBack":
  1182. this.pdfHistory?.back();
  1183. break;
  1184. case "GoForward":
  1185. this.pdfHistory?.forward();
  1186. break;
  1187. case "NextPage":
  1188. this.pdfViewer.nextPage();
  1189. break;
  1190. case "PrevPage":
  1191. this.pdfViewer.previousPage();
  1192. break;
  1193. case "LastPage":
  1194. this.page = this.pagesCount;
  1195. break;
  1196. case "FirstPage":
  1197. this.page = 1;
  1198. break;
  1199. default:
  1200. break;
  1201. }
  1202. this.eventBus.dispatch("namedaction", {
  1203. source: this,
  1204. action
  1205. });
  1206. }
  1207. async executeSetOCGState(action) {
  1208. if (!this.pdfDocument) {
  1209. return;
  1210. }
  1211. const pdfDocument = this.pdfDocument,
  1212. optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1213. if (pdfDocument !== this.pdfDocument) {
  1214. return;
  1215. }
  1216. optionalContentConfig.setOCGState(action);
  1217. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1218. }
  1219. static #isValidExplicitDest(dest) {
  1220. if (!Array.isArray(dest) || dest.length < 2) {
  1221. return false;
  1222. }
  1223. const [page, zoom, ...args] = dest;
  1224. if (!(typeof page === "object" && Number.isInteger(page?.num) && Number.isInteger(page?.gen)) && !Number.isInteger(page)) {
  1225. return false;
  1226. }
  1227. if (!(typeof zoom === "object" && typeof zoom?.name === "string")) {
  1228. return false;
  1229. }
  1230. const argsLen = args.length;
  1231. let allowNull = true;
  1232. switch (zoom.name) {
  1233. case "XYZ":
  1234. if (argsLen < 2 || argsLen > 3) {
  1235. return false;
  1236. }
  1237. break;
  1238. case "Fit":
  1239. case "FitB":
  1240. return argsLen === 0;
  1241. case "FitH":
  1242. case "FitBH":
  1243. case "FitV":
  1244. case "FitBV":
  1245. if (argsLen > 1) {
  1246. return false;
  1247. }
  1248. break;
  1249. case "FitR":
  1250. if (argsLen !== 4) {
  1251. return false;
  1252. }
  1253. allowNull = false;
  1254. break;
  1255. default:
  1256. return false;
  1257. }
  1258. for (const arg of args) {
  1259. if (!(typeof arg === "number" || allowNull && arg === null)) {
  1260. return false;
  1261. }
  1262. }
  1263. return true;
  1264. }
  1265. }
  1266. class SimpleLinkService extends PDFLinkService {
  1267. setDocument(pdfDocument, baseUrl = null) {}
  1268. }
  1269. ;// CONCATENATED MODULE: ./web/pdfjs.js
  1270. const {
  1271. AbortException,
  1272. AnnotationEditorLayer,
  1273. AnnotationEditorParamsType,
  1274. AnnotationEditorType,
  1275. AnnotationEditorUIManager,
  1276. AnnotationLayer,
  1277. AnnotationMode,
  1278. build,
  1279. CMapCompressionType,
  1280. ColorPicker,
  1281. createValidAbsoluteUrl,
  1282. DOMSVGFactory,
  1283. DrawLayer,
  1284. FeatureTest,
  1285. fetchData,
  1286. getDocument,
  1287. getFilenameFromUrl,
  1288. getPdfFilenameFromUrl: pdfjs_getPdfFilenameFromUrl,
  1289. getXfaPageViewport,
  1290. GlobalWorkerOptions,
  1291. ImageKind,
  1292. InvalidPDFException,
  1293. isDataScheme,
  1294. isPdfFile,
  1295. MissingPDFException,
  1296. noContextMenu,
  1297. normalizeUnicode,
  1298. OPS,
  1299. PasswordResponses,
  1300. PDFDataRangeTransport,
  1301. PDFDateString,
  1302. PDFWorker,
  1303. PermissionFlag,
  1304. PixelsPerInch,
  1305. RenderingCancelledException,
  1306. setLayerDimensions,
  1307. shadow,
  1308. TextLayer,
  1309. UnexpectedResponseException,
  1310. Util,
  1311. VerbosityLevel,
  1312. version,
  1313. XfaLayer
  1314. } = globalThis.pdfjsLib;
  1315. ;// CONCATENATED MODULE: ./web/event_utils.js
  1316. const WaitOnType = {
  1317. EVENT: "event",
  1318. TIMEOUT: "timeout"
  1319. };
  1320. async function waitOnEventOrTimeout({
  1321. target,
  1322. name,
  1323. delay = 0
  1324. }) {
  1325. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  1326. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  1327. }
  1328. const {
  1329. promise,
  1330. resolve
  1331. } = Promise.withResolvers();
  1332. const ac = new AbortController();
  1333. function handler(type) {
  1334. ac.abort();
  1335. clearTimeout(timeout);
  1336. resolve(type);
  1337. }
  1338. const evtMethod = target instanceof EventBus ? "_on" : "addEventListener";
  1339. target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), {
  1340. signal: ac.signal
  1341. });
  1342. const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay);
  1343. return promise;
  1344. }
  1345. class EventBus {
  1346. #listeners = Object.create(null);
  1347. on(eventName, listener, options = null) {
  1348. this._on(eventName, listener, {
  1349. external: true,
  1350. once: options?.once,
  1351. signal: options?.signal
  1352. });
  1353. }
  1354. off(eventName, listener, options = null) {
  1355. this._off(eventName, listener);
  1356. }
  1357. dispatch(eventName, data) {
  1358. const eventListeners = this.#listeners[eventName];
  1359. if (!eventListeners || eventListeners.length === 0) {
  1360. return;
  1361. }
  1362. let externalListeners;
  1363. for (const {
  1364. listener,
  1365. external,
  1366. once
  1367. } of eventListeners.slice(0)) {
  1368. if (once) {
  1369. this._off(eventName, listener);
  1370. }
  1371. if (external) {
  1372. (externalListeners ||= []).push(listener);
  1373. continue;
  1374. }
  1375. listener(data);
  1376. }
  1377. if (externalListeners) {
  1378. for (const listener of externalListeners) {
  1379. listener(data);
  1380. }
  1381. externalListeners = null;
  1382. }
  1383. }
  1384. _on(eventName, listener, options = null) {
  1385. let rmAbort = null;
  1386. if (options?.signal instanceof AbortSignal) {
  1387. const {
  1388. signal
  1389. } = options;
  1390. if (signal.aborted) {
  1391. console.error("Cannot use an `aborted` signal.");
  1392. return;
  1393. }
  1394. const onAbort = () => this._off(eventName, listener);
  1395. rmAbort = () => signal.removeEventListener("abort", onAbort);
  1396. signal.addEventListener("abort", onAbort);
  1397. }
  1398. const eventListeners = this.#listeners[eventName] ||= [];
  1399. eventListeners.push({
  1400. listener,
  1401. external: options?.external === true,
  1402. once: options?.once === true,
  1403. rmAbort
  1404. });
  1405. }
  1406. _off(eventName, listener, options = null) {
  1407. const eventListeners = this.#listeners[eventName];
  1408. if (!eventListeners) {
  1409. return;
  1410. }
  1411. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  1412. const evt = eventListeners[i];
  1413. if (evt.listener === listener) {
  1414. evt.rmAbort?.();
  1415. eventListeners.splice(i, 1);
  1416. return;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. class FirefoxEventBus extends EventBus {
  1422. #externalServices;
  1423. #globalEventNames;
  1424. #isInAutomation;
  1425. constructor(globalEventNames, externalServices, isInAutomation) {
  1426. super();
  1427. this.#globalEventNames = globalEventNames;
  1428. this.#externalServices = externalServices;
  1429. this.#isInAutomation = isInAutomation;
  1430. }
  1431. dispatch(eventName, data) {
  1432. throw new Error("Not implemented: FirefoxEventBus.dispatch");
  1433. }
  1434. }
  1435. ;// CONCATENATED MODULE: ./web/external_services.js
  1436. class BaseExternalServices {
  1437. constructor() {
  1438. if (this.constructor === BaseExternalServices) {
  1439. throw new Error("Cannot initialize BaseExternalServices.");
  1440. }
  1441. }
  1442. updateFindControlState(data) {}
  1443. updateFindMatchesCount(data) {}
  1444. initPassiveLoading() {}
  1445. reportTelemetry(data) {}
  1446. async createL10n() {
  1447. throw new Error("Not implemented: createL10n");
  1448. }
  1449. createScripting() {
  1450. throw new Error("Not implemented: createScripting");
  1451. }
  1452. updateEditorStates(data) {
  1453. throw new Error("Not implemented: updateEditorStates");
  1454. }
  1455. dispatchGlobalEvent(_event) {}
  1456. }
  1457. ;// CONCATENATED MODULE: ./web/preferences.js
  1458. class BasePreferences {
  1459. #defaults = Object.freeze({
  1460. altTextLearnMoreUrl: "",
  1461. annotationEditorMode: 0,
  1462. annotationMode: 2,
  1463. cursorToolOnLoad: 0,
  1464. defaultZoomDelay: 400,
  1465. defaultZoomValue: "",
  1466. disablePageLabels: false,
  1467. enableAltText: false,
  1468. enableGuessAltText: true,
  1469. enableHighlightEditor: false,
  1470. enableHighlightFloatingButton: false,
  1471. enablePermissions: false,
  1472. enablePrintAutoRotate: true,
  1473. enableScripting: true,
  1474. enableUpdatedAddImage: false,
  1475. externalLinkTarget: 0,
  1476. highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
  1477. historyUpdateUrl: false,
  1478. ignoreDestinationZoom: false,
  1479. forcePageColors: false,
  1480. pageColorsBackground: "Canvas",
  1481. pageColorsForeground: "CanvasText",
  1482. pdfBugEnabled: false,
  1483. sidebarViewOnLoad: -1,
  1484. scrollModeOnLoad: -1,
  1485. spreadModeOnLoad: -1,
  1486. textLayerMode: 1,
  1487. viewOnLoad: 0,
  1488. disableAutoFetch: false,
  1489. disableFontFace: false,
  1490. disableRange: false,
  1491. disableStream: false,
  1492. enableHWA: true,
  1493. enableXfa: true,
  1494. viewerCssTheme: 0
  1495. });
  1496. #initializedPromise = null;
  1497. constructor() {
  1498. if (this.constructor === BasePreferences) {
  1499. throw new Error("Cannot initialize BasePreferences.");
  1500. }
  1501. this.#initializedPromise = this._readFromStorage(this.#defaults).then(({
  1502. browserPrefs,
  1503. prefs
  1504. }) => {
  1505. if (AppOptions._checkDisablePreferences()) {
  1506. return;
  1507. }
  1508. AppOptions.setAll({
  1509. ...browserPrefs,
  1510. ...prefs
  1511. }, true);
  1512. });
  1513. }
  1514. async _writeToStorage(prefObj) {
  1515. throw new Error("Not implemented: _writeToStorage");
  1516. }
  1517. async _readFromStorage(prefObj) {
  1518. throw new Error("Not implemented: _readFromStorage");
  1519. }
  1520. async reset() {
  1521. await this.#initializedPromise;
  1522. AppOptions.setAll(this.#defaults, true);
  1523. await this._writeToStorage(this.#defaults);
  1524. }
  1525. async set(name, value) {
  1526. await this.#initializedPromise;
  1527. AppOptions.setAll({
  1528. [name]: value
  1529. }, true);
  1530. await this._writeToStorage(AppOptions.getAll(OptionKind.PREFERENCE));
  1531. }
  1532. async get(name) {
  1533. await this.#initializedPromise;
  1534. return AppOptions.get(name);
  1535. }
  1536. get initializedPromise() {
  1537. return this.#initializedPromise;
  1538. }
  1539. }
  1540. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/types.js
  1541. class FluentType {
  1542. constructor(value) {
  1543. this.value = value;
  1544. }
  1545. valueOf() {
  1546. return this.value;
  1547. }
  1548. }
  1549. class FluentNone extends FluentType {
  1550. constructor(value = "???") {
  1551. super(value);
  1552. }
  1553. toString(scope) {
  1554. return `{${this.value}}`;
  1555. }
  1556. }
  1557. class FluentNumber extends FluentType {
  1558. constructor(value, opts = {}) {
  1559. super(value);
  1560. this.opts = opts;
  1561. }
  1562. toString(scope) {
  1563. try {
  1564. const nf = scope.memoizeIntlObject(Intl.NumberFormat, this.opts);
  1565. return nf.format(this.value);
  1566. } catch (err) {
  1567. scope.reportError(err);
  1568. return this.value.toString(10);
  1569. }
  1570. }
  1571. }
  1572. class FluentDateTime extends FluentType {
  1573. constructor(value, opts = {}) {
  1574. super(value);
  1575. this.opts = opts;
  1576. }
  1577. toString(scope) {
  1578. try {
  1579. const dtf = scope.memoizeIntlObject(Intl.DateTimeFormat, this.opts);
  1580. return dtf.format(this.value);
  1581. } catch (err) {
  1582. scope.reportError(err);
  1583. return new Date(this.value).toISOString();
  1584. }
  1585. }
  1586. }
  1587. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/resolver.js
  1588. const MAX_PLACEABLES = 100;
  1589. const FSI = "\u2068";
  1590. const PDI = "\u2069";
  1591. function match(scope, selector, key) {
  1592. if (key === selector) {
  1593. return true;
  1594. }
  1595. if (key instanceof FluentNumber && selector instanceof FluentNumber && key.value === selector.value) {
  1596. return true;
  1597. }
  1598. if (selector instanceof FluentNumber && typeof key === "string") {
  1599. let category = scope.memoizeIntlObject(Intl.PluralRules, selector.opts).select(selector.value);
  1600. if (key === category) {
  1601. return true;
  1602. }
  1603. }
  1604. return false;
  1605. }
  1606. function getDefault(scope, variants, star) {
  1607. if (variants[star]) {
  1608. return resolvePattern(scope, variants[star].value);
  1609. }
  1610. scope.reportError(new RangeError("No default"));
  1611. return new FluentNone();
  1612. }
  1613. function getArguments(scope, args) {
  1614. const positional = [];
  1615. const named = Object.create(null);
  1616. for (const arg of args) {
  1617. if (arg.type === "narg") {
  1618. named[arg.name] = resolveExpression(scope, arg.value);
  1619. } else {
  1620. positional.push(resolveExpression(scope, arg));
  1621. }
  1622. }
  1623. return {
  1624. positional,
  1625. named
  1626. };
  1627. }
  1628. function resolveExpression(scope, expr) {
  1629. switch (expr.type) {
  1630. case "str":
  1631. return expr.value;
  1632. case "num":
  1633. return new FluentNumber(expr.value, {
  1634. minimumFractionDigits: expr.precision
  1635. });
  1636. case "var":
  1637. return resolveVariableReference(scope, expr);
  1638. case "mesg":
  1639. return resolveMessageReference(scope, expr);
  1640. case "term":
  1641. return resolveTermReference(scope, expr);
  1642. case "func":
  1643. return resolveFunctionReference(scope, expr);
  1644. case "select":
  1645. return resolveSelectExpression(scope, expr);
  1646. default:
  1647. return new FluentNone();
  1648. }
  1649. }
  1650. function resolveVariableReference(scope, {
  1651. name
  1652. }) {
  1653. let arg;
  1654. if (scope.params) {
  1655. if (Object.prototype.hasOwnProperty.call(scope.params, name)) {
  1656. arg = scope.params[name];
  1657. } else {
  1658. return new FluentNone(`$${name}`);
  1659. }
  1660. } else if (scope.args && Object.prototype.hasOwnProperty.call(scope.args, name)) {
  1661. arg = scope.args[name];
  1662. } else {
  1663. scope.reportError(new ReferenceError(`Unknown variable: $${name}`));
  1664. return new FluentNone(`$${name}`);
  1665. }
  1666. if (arg instanceof FluentType) {
  1667. return arg;
  1668. }
  1669. switch (typeof arg) {
  1670. case "string":
  1671. return arg;
  1672. case "number":
  1673. return new FluentNumber(arg);
  1674. case "object":
  1675. if (arg instanceof Date) {
  1676. return new FluentDateTime(arg.getTime());
  1677. }
  1678. default:
  1679. scope.reportError(new TypeError(`Variable type not supported: $${name}, ${typeof arg}`));
  1680. return new FluentNone(`$${name}`);
  1681. }
  1682. }
  1683. function resolveMessageReference(scope, {
  1684. name,
  1685. attr
  1686. }) {
  1687. const message = scope.bundle._messages.get(name);
  1688. if (!message) {
  1689. scope.reportError(new ReferenceError(`Unknown message: ${name}`));
  1690. return new FluentNone(name);
  1691. }
  1692. if (attr) {
  1693. const attribute = message.attributes[attr];
  1694. if (attribute) {
  1695. return resolvePattern(scope, attribute);
  1696. }
  1697. scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`));
  1698. return new FluentNone(`${name}.${attr}`);
  1699. }
  1700. if (message.value) {
  1701. return resolvePattern(scope, message.value);
  1702. }
  1703. scope.reportError(new ReferenceError(`No value: ${name}`));
  1704. return new FluentNone(name);
  1705. }
  1706. function resolveTermReference(scope, {
  1707. name,
  1708. attr,
  1709. args
  1710. }) {
  1711. const id = `-${name}`;
  1712. const term = scope.bundle._terms.get(id);
  1713. if (!term) {
  1714. scope.reportError(new ReferenceError(`Unknown term: ${id}`));
  1715. return new FluentNone(id);
  1716. }
  1717. if (attr) {
  1718. const attribute = term.attributes[attr];
  1719. if (attribute) {
  1720. scope.params = getArguments(scope, args).named;
  1721. const resolved = resolvePattern(scope, attribute);
  1722. scope.params = null;
  1723. return resolved;
  1724. }
  1725. scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`));
  1726. return new FluentNone(`${id}.${attr}`);
  1727. }
  1728. scope.params = getArguments(scope, args).named;
  1729. const resolved = resolvePattern(scope, term.value);
  1730. scope.params = null;
  1731. return resolved;
  1732. }
  1733. function resolveFunctionReference(scope, {
  1734. name,
  1735. args
  1736. }) {
  1737. let func = scope.bundle._functions[name];
  1738. if (!func) {
  1739. scope.reportError(new ReferenceError(`Unknown function: ${name}()`));
  1740. return new FluentNone(`${name}()`);
  1741. }
  1742. if (typeof func !== "function") {
  1743. scope.reportError(new TypeError(`Function ${name}() is not callable`));
  1744. return new FluentNone(`${name}()`);
  1745. }
  1746. try {
  1747. let resolved = getArguments(scope, args);
  1748. return func(resolved.positional, resolved.named);
  1749. } catch (err) {
  1750. scope.reportError(err);
  1751. return new FluentNone(`${name}()`);
  1752. }
  1753. }
  1754. function resolveSelectExpression(scope, {
  1755. selector,
  1756. variants,
  1757. star
  1758. }) {
  1759. let sel = resolveExpression(scope, selector);
  1760. if (sel instanceof FluentNone) {
  1761. return getDefault(scope, variants, star);
  1762. }
  1763. for (const variant of variants) {
  1764. const key = resolveExpression(scope, variant.key);
  1765. if (match(scope, sel, key)) {
  1766. return resolvePattern(scope, variant.value);
  1767. }
  1768. }
  1769. return getDefault(scope, variants, star);
  1770. }
  1771. function resolveComplexPattern(scope, ptn) {
  1772. if (scope.dirty.has(ptn)) {
  1773. scope.reportError(new RangeError("Cyclic reference"));
  1774. return new FluentNone();
  1775. }
  1776. scope.dirty.add(ptn);
  1777. const result = [];
  1778. const useIsolating = scope.bundle._useIsolating && ptn.length > 1;
  1779. for (const elem of ptn) {
  1780. if (typeof elem === "string") {
  1781. result.push(scope.bundle._transform(elem));
  1782. continue;
  1783. }
  1784. scope.placeables++;
  1785. if (scope.placeables > MAX_PLACEABLES) {
  1786. scope.dirty.delete(ptn);
  1787. throw new RangeError(`Too many placeables expanded: ${scope.placeables}, ` + `max allowed is ${MAX_PLACEABLES}`);
  1788. }
  1789. if (useIsolating) {
  1790. result.push(FSI);
  1791. }
  1792. result.push(resolveExpression(scope, elem).toString(scope));
  1793. if (useIsolating) {
  1794. result.push(PDI);
  1795. }
  1796. }
  1797. scope.dirty.delete(ptn);
  1798. return result.join("");
  1799. }
  1800. function resolvePattern(scope, value) {
  1801. if (typeof value === "string") {
  1802. return scope.bundle._transform(value);
  1803. }
  1804. return resolveComplexPattern(scope, value);
  1805. }
  1806. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/scope.js
  1807. class Scope {
  1808. constructor(bundle, errors, args) {
  1809. this.dirty = new WeakSet();
  1810. this.params = null;
  1811. this.placeables = 0;
  1812. this.bundle = bundle;
  1813. this.errors = errors;
  1814. this.args = args;
  1815. }
  1816. reportError(error) {
  1817. if (!this.errors || !(error instanceof Error)) {
  1818. throw error;
  1819. }
  1820. this.errors.push(error);
  1821. }
  1822. memoizeIntlObject(ctor, opts) {
  1823. let cache = this.bundle._intls.get(ctor);
  1824. if (!cache) {
  1825. cache = {};
  1826. this.bundle._intls.set(ctor, cache);
  1827. }
  1828. let id = JSON.stringify(opts);
  1829. if (!cache[id]) {
  1830. cache[id] = new ctor(this.bundle.locales, opts);
  1831. }
  1832. return cache[id];
  1833. }
  1834. }
  1835. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/builtins.js
  1836. function values(opts, allowed) {
  1837. const unwrapped = Object.create(null);
  1838. for (const [name, opt] of Object.entries(opts)) {
  1839. if (allowed.includes(name)) {
  1840. unwrapped[name] = opt.valueOf();
  1841. }
  1842. }
  1843. return unwrapped;
  1844. }
  1845. const NUMBER_ALLOWED = ["unitDisplay", "currencyDisplay", "useGrouping", "minimumIntegerDigits", "minimumFractionDigits", "maximumFractionDigits", "minimumSignificantDigits", "maximumSignificantDigits"];
  1846. function NUMBER(args, opts) {
  1847. let arg = args[0];
  1848. if (arg instanceof FluentNone) {
  1849. return new FluentNone(`NUMBER(${arg.valueOf()})`);
  1850. }
  1851. if (arg instanceof FluentNumber) {
  1852. return new FluentNumber(arg.valueOf(), {
  1853. ...arg.opts,
  1854. ...values(opts, NUMBER_ALLOWED)
  1855. });
  1856. }
  1857. if (arg instanceof FluentDateTime) {
  1858. return new FluentNumber(arg.valueOf(), {
  1859. ...values(opts, NUMBER_ALLOWED)
  1860. });
  1861. }
  1862. throw new TypeError("Invalid argument to NUMBER");
  1863. }
  1864. const DATETIME_ALLOWED = ["dateStyle", "timeStyle", "fractionalSecondDigits", "dayPeriod", "hour12", "weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"];
  1865. function DATETIME(args, opts) {
  1866. let arg = args[0];
  1867. if (arg instanceof FluentNone) {
  1868. return new FluentNone(`DATETIME(${arg.valueOf()})`);
  1869. }
  1870. if (arg instanceof FluentDateTime) {
  1871. return new FluentDateTime(arg.valueOf(), {
  1872. ...arg.opts,
  1873. ...values(opts, DATETIME_ALLOWED)
  1874. });
  1875. }
  1876. if (arg instanceof FluentNumber) {
  1877. return new FluentDateTime(arg.valueOf(), {
  1878. ...values(opts, DATETIME_ALLOWED)
  1879. });
  1880. }
  1881. throw new TypeError("Invalid argument to DATETIME");
  1882. }
  1883. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/memoizer.js
  1884. const cache = new Map();
  1885. function getMemoizerForLocale(locales) {
  1886. const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales;
  1887. let memoizer = cache.get(stringLocale);
  1888. if (memoizer === undefined) {
  1889. memoizer = new Map();
  1890. cache.set(stringLocale, memoizer);
  1891. }
  1892. return memoizer;
  1893. }
  1894. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/bundle.js
  1895. class FluentBundle {
  1896. constructor(locales, {
  1897. functions,
  1898. useIsolating = true,
  1899. transform = v => v
  1900. } = {}) {
  1901. this._terms = new Map();
  1902. this._messages = new Map();
  1903. this.locales = Array.isArray(locales) ? locales : [locales];
  1904. this._functions = {
  1905. NUMBER: NUMBER,
  1906. DATETIME: DATETIME,
  1907. ...functions
  1908. };
  1909. this._useIsolating = useIsolating;
  1910. this._transform = transform;
  1911. this._intls = getMemoizerForLocale(locales);
  1912. }
  1913. hasMessage(id) {
  1914. return this._messages.has(id);
  1915. }
  1916. getMessage(id) {
  1917. return this._messages.get(id);
  1918. }
  1919. addResource(res, {
  1920. allowOverrides = false
  1921. } = {}) {
  1922. const errors = [];
  1923. for (let i = 0; i < res.body.length; i++) {
  1924. let entry = res.body[i];
  1925. if (entry.id.startsWith("-")) {
  1926. if (allowOverrides === false && this._terms.has(entry.id)) {
  1927. errors.push(new Error(`Attempt to override an existing term: "${entry.id}"`));
  1928. continue;
  1929. }
  1930. this._terms.set(entry.id, entry);
  1931. } else {
  1932. if (allowOverrides === false && this._messages.has(entry.id)) {
  1933. errors.push(new Error(`Attempt to override an existing message: "${entry.id}"`));
  1934. continue;
  1935. }
  1936. this._messages.set(entry.id, entry);
  1937. }
  1938. }
  1939. return errors;
  1940. }
  1941. formatPattern(pattern, args = null, errors = null) {
  1942. if (typeof pattern === "string") {
  1943. return this._transform(pattern);
  1944. }
  1945. let scope = new Scope(this, errors, args);
  1946. try {
  1947. let value = resolveComplexPattern(scope, pattern);
  1948. return value.toString(scope);
  1949. } catch (err) {
  1950. if (scope.errors && err instanceof Error) {
  1951. scope.errors.push(err);
  1952. return new FluentNone().toString(scope);
  1953. }
  1954. throw err;
  1955. }
  1956. }
  1957. }
  1958. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/resource.js
  1959. const RE_MESSAGE_START = /^(-?[a-zA-Z][\w-]*) *= */gm;
  1960. const RE_ATTRIBUTE_START = /\.([a-zA-Z][\w-]*) *= */y;
  1961. const RE_VARIANT_START = /\*?\[/y;
  1962. const RE_NUMBER_LITERAL = /(-?[0-9]+(?:\.([0-9]+))?)/y;
  1963. const RE_IDENTIFIER = /([a-zA-Z][\w-]*)/y;
  1964. const RE_REFERENCE = /([$-])?([a-zA-Z][\w-]*)(?:\.([a-zA-Z][\w-]*))?/y;
  1965. const RE_FUNCTION_NAME = /^[A-Z][A-Z0-9_-]*$/;
  1966. const RE_TEXT_RUN = /([^{}\n\r]+)/y;
  1967. const RE_STRING_RUN = /([^\\"\n\r]*)/y;
  1968. const RE_STRING_ESCAPE = /\\([\\"])/y;
  1969. const RE_UNICODE_ESCAPE = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{6})/y;
  1970. const RE_LEADING_NEWLINES = /^\n+/;
  1971. const RE_TRAILING_SPACES = / +$/;
  1972. const RE_BLANK_LINES = / *\r?\n/g;
  1973. const RE_INDENT = /( *)$/;
  1974. const TOKEN_BRACE_OPEN = /{\s*/y;
  1975. const TOKEN_BRACE_CLOSE = /\s*}/y;
  1976. const TOKEN_BRACKET_OPEN = /\[\s*/y;
  1977. const TOKEN_BRACKET_CLOSE = /\s*] */y;
  1978. const TOKEN_PAREN_OPEN = /\s*\(\s*/y;
  1979. const TOKEN_ARROW = /\s*->\s*/y;
  1980. const TOKEN_COLON = /\s*:\s*/y;
  1981. const TOKEN_COMMA = /\s*,?\s*/y;
  1982. const TOKEN_BLANK = /\s+/y;
  1983. class FluentResource {
  1984. constructor(source) {
  1985. this.body = [];
  1986. RE_MESSAGE_START.lastIndex = 0;
  1987. let cursor = 0;
  1988. while (true) {
  1989. let next = RE_MESSAGE_START.exec(source);
  1990. if (next === null) {
  1991. break;
  1992. }
  1993. cursor = RE_MESSAGE_START.lastIndex;
  1994. try {
  1995. this.body.push(parseMessage(next[1]));
  1996. } catch (err) {
  1997. if (err instanceof SyntaxError) {
  1998. continue;
  1999. }
  2000. throw err;
  2001. }
  2002. }
  2003. function test(re) {
  2004. re.lastIndex = cursor;
  2005. return re.test(source);
  2006. }
  2007. function consumeChar(char, errorClass) {
  2008. if (source[cursor] === char) {
  2009. cursor++;
  2010. return true;
  2011. }
  2012. if (errorClass) {
  2013. throw new errorClass(`Expected ${char}`);
  2014. }
  2015. return false;
  2016. }
  2017. function consumeToken(re, errorClass) {
  2018. if (test(re)) {
  2019. cursor = re.lastIndex;
  2020. return true;
  2021. }
  2022. if (errorClass) {
  2023. throw new errorClass(`Expected ${re.toString()}`);
  2024. }
  2025. return false;
  2026. }
  2027. function match(re) {
  2028. re.lastIndex = cursor;
  2029. let result = re.exec(source);
  2030. if (result === null) {
  2031. throw new SyntaxError(`Expected ${re.toString()}`);
  2032. }
  2033. cursor = re.lastIndex;
  2034. return result;
  2035. }
  2036. function match1(re) {
  2037. return match(re)[1];
  2038. }
  2039. function parseMessage(id) {
  2040. let value = parsePattern();
  2041. let attributes = parseAttributes();
  2042. if (value === null && Object.keys(attributes).length === 0) {
  2043. throw new SyntaxError("Expected message value or attributes");
  2044. }
  2045. return {
  2046. id,
  2047. value,
  2048. attributes
  2049. };
  2050. }
  2051. function parseAttributes() {
  2052. let attrs = Object.create(null);
  2053. while (test(RE_ATTRIBUTE_START)) {
  2054. let name = match1(RE_ATTRIBUTE_START);
  2055. let value = parsePattern();
  2056. if (value === null) {
  2057. throw new SyntaxError("Expected attribute value");
  2058. }
  2059. attrs[name] = value;
  2060. }
  2061. return attrs;
  2062. }
  2063. function parsePattern() {
  2064. let first;
  2065. if (test(RE_TEXT_RUN)) {
  2066. first = match1(RE_TEXT_RUN);
  2067. }
  2068. if (source[cursor] === "{" || source[cursor] === "}") {
  2069. return parsePatternElements(first ? [first] : [], Infinity);
  2070. }
  2071. let indent = parseIndent();
  2072. if (indent) {
  2073. if (first) {
  2074. return parsePatternElements([first, indent], indent.length);
  2075. }
  2076. indent.value = trim(indent.value, RE_LEADING_NEWLINES);
  2077. return parsePatternElements([indent], indent.length);
  2078. }
  2079. if (first) {
  2080. return trim(first, RE_TRAILING_SPACES);
  2081. }
  2082. return null;
  2083. }
  2084. function parsePatternElements(elements = [], commonIndent) {
  2085. while (true) {
  2086. if (test(RE_TEXT_RUN)) {
  2087. elements.push(match1(RE_TEXT_RUN));
  2088. continue;
  2089. }
  2090. if (source[cursor] === "{") {
  2091. elements.push(parsePlaceable());
  2092. continue;
  2093. }
  2094. if (source[cursor] === "}") {
  2095. throw new SyntaxError("Unbalanced closing brace");
  2096. }
  2097. let indent = parseIndent();
  2098. if (indent) {
  2099. elements.push(indent);
  2100. commonIndent = Math.min(commonIndent, indent.length);
  2101. continue;
  2102. }
  2103. break;
  2104. }
  2105. let lastIndex = elements.length - 1;
  2106. let lastElement = elements[lastIndex];
  2107. if (typeof lastElement === "string") {
  2108. elements[lastIndex] = trim(lastElement, RE_TRAILING_SPACES);
  2109. }
  2110. let baked = [];
  2111. for (let element of elements) {
  2112. if (element instanceof Indent) {
  2113. element = element.value.slice(0, element.value.length - commonIndent);
  2114. }
  2115. if (element) {
  2116. baked.push(element);
  2117. }
  2118. }
  2119. return baked;
  2120. }
  2121. function parsePlaceable() {
  2122. consumeToken(TOKEN_BRACE_OPEN, SyntaxError);
  2123. let selector = parseInlineExpression();
  2124. if (consumeToken(TOKEN_BRACE_CLOSE)) {
  2125. return selector;
  2126. }
  2127. if (consumeToken(TOKEN_ARROW)) {
  2128. let variants = parseVariants();
  2129. consumeToken(TOKEN_BRACE_CLOSE, SyntaxError);
  2130. return {
  2131. type: "select",
  2132. selector,
  2133. ...variants
  2134. };
  2135. }
  2136. throw new SyntaxError("Unclosed placeable");
  2137. }
  2138. function parseInlineExpression() {
  2139. if (source[cursor] === "{") {
  2140. return parsePlaceable();
  2141. }
  2142. if (test(RE_REFERENCE)) {
  2143. let [, sigil, name, attr = null] = match(RE_REFERENCE);
  2144. if (sigil === "$") {
  2145. return {
  2146. type: "var",
  2147. name
  2148. };
  2149. }
  2150. if (consumeToken(TOKEN_PAREN_OPEN)) {
  2151. let args = parseArguments();
  2152. if (sigil === "-") {
  2153. return {
  2154. type: "term",
  2155. name,
  2156. attr,
  2157. args
  2158. };
  2159. }
  2160. if (RE_FUNCTION_NAME.test(name)) {
  2161. return {
  2162. type: "func",
  2163. name,
  2164. args
  2165. };
  2166. }
  2167. throw new SyntaxError("Function names must be all upper-case");
  2168. }
  2169. if (sigil === "-") {
  2170. return {
  2171. type: "term",
  2172. name,
  2173. attr,
  2174. args: []
  2175. };
  2176. }
  2177. return {
  2178. type: "mesg",
  2179. name,
  2180. attr
  2181. };
  2182. }
  2183. return parseLiteral();
  2184. }
  2185. function parseArguments() {
  2186. let args = [];
  2187. while (true) {
  2188. switch (source[cursor]) {
  2189. case ")":
  2190. cursor++;
  2191. return args;
  2192. case undefined:
  2193. throw new SyntaxError("Unclosed argument list");
  2194. }
  2195. args.push(parseArgument());
  2196. consumeToken(TOKEN_COMMA);
  2197. }
  2198. }
  2199. function parseArgument() {
  2200. let expr = parseInlineExpression();
  2201. if (expr.type !== "mesg") {
  2202. return expr;
  2203. }
  2204. if (consumeToken(TOKEN_COLON)) {
  2205. return {
  2206. type: "narg",
  2207. name: expr.name,
  2208. value: parseLiteral()
  2209. };
  2210. }
  2211. return expr;
  2212. }
  2213. function parseVariants() {
  2214. let variants = [];
  2215. let count = 0;
  2216. let star;
  2217. while (test(RE_VARIANT_START)) {
  2218. if (consumeChar("*")) {
  2219. star = count;
  2220. }
  2221. let key = parseVariantKey();
  2222. let value = parsePattern();
  2223. if (value === null) {
  2224. throw new SyntaxError("Expected variant value");
  2225. }
  2226. variants[count++] = {
  2227. key,
  2228. value
  2229. };
  2230. }
  2231. if (count === 0) {
  2232. return null;
  2233. }
  2234. if (star === undefined) {
  2235. throw new SyntaxError("Expected default variant");
  2236. }
  2237. return {
  2238. variants,
  2239. star
  2240. };
  2241. }
  2242. function parseVariantKey() {
  2243. consumeToken(TOKEN_BRACKET_OPEN, SyntaxError);
  2244. let key;
  2245. if (test(RE_NUMBER_LITERAL)) {
  2246. key = parseNumberLiteral();
  2247. } else {
  2248. key = {
  2249. type: "str",
  2250. value: match1(RE_IDENTIFIER)
  2251. };
  2252. }
  2253. consumeToken(TOKEN_BRACKET_CLOSE, SyntaxError);
  2254. return key;
  2255. }
  2256. function parseLiteral() {
  2257. if (test(RE_NUMBER_LITERAL)) {
  2258. return parseNumberLiteral();
  2259. }
  2260. if (source[cursor] === '"') {
  2261. return parseStringLiteral();
  2262. }
  2263. throw new SyntaxError("Invalid expression");
  2264. }
  2265. function parseNumberLiteral() {
  2266. let [, value, fraction = ""] = match(RE_NUMBER_LITERAL);
  2267. let precision = fraction.length;
  2268. return {
  2269. type: "num",
  2270. value: parseFloat(value),
  2271. precision
  2272. };
  2273. }
  2274. function parseStringLiteral() {
  2275. consumeChar('"', SyntaxError);
  2276. let value = "";
  2277. while (true) {
  2278. value += match1(RE_STRING_RUN);
  2279. if (source[cursor] === "\\") {
  2280. value += parseEscapeSequence();
  2281. continue;
  2282. }
  2283. if (consumeChar('"')) {
  2284. return {
  2285. type: "str",
  2286. value
  2287. };
  2288. }
  2289. throw new SyntaxError("Unclosed string literal");
  2290. }
  2291. }
  2292. function parseEscapeSequence() {
  2293. if (test(RE_STRING_ESCAPE)) {
  2294. return match1(RE_STRING_ESCAPE);
  2295. }
  2296. if (test(RE_UNICODE_ESCAPE)) {
  2297. let [, codepoint4, codepoint6] = match(RE_UNICODE_ESCAPE);
  2298. let codepoint = parseInt(codepoint4 || codepoint6, 16);
  2299. return codepoint <= 0xd7ff || 0xe000 <= codepoint ? String.fromCodePoint(codepoint) : "�";
  2300. }
  2301. throw new SyntaxError("Unknown escape sequence");
  2302. }
  2303. function parseIndent() {
  2304. let start = cursor;
  2305. consumeToken(TOKEN_BLANK);
  2306. switch (source[cursor]) {
  2307. case ".":
  2308. case "[":
  2309. case "*":
  2310. case "}":
  2311. case undefined:
  2312. return false;
  2313. case "{":
  2314. return makeIndent(source.slice(start, cursor));
  2315. }
  2316. if (source[cursor - 1] === " ") {
  2317. return makeIndent(source.slice(start, cursor));
  2318. }
  2319. return false;
  2320. }
  2321. function trim(text, re) {
  2322. return text.replace(re, "");
  2323. }
  2324. function makeIndent(blank) {
  2325. let value = blank.replace(RE_BLANK_LINES, "\n");
  2326. let length = RE_INDENT.exec(blank)[1].length;
  2327. return new Indent(value, length);
  2328. }
  2329. }
  2330. }
  2331. class Indent {
  2332. constructor(value, length) {
  2333. this.value = value;
  2334. this.length = length;
  2335. }
  2336. }
  2337. ;// CONCATENATED MODULE: ./node_modules/@fluent/bundle/esm/index.js
  2338. ;// CONCATENATED MODULE: ./node_modules/@fluent/dom/esm/overlay.js
  2339. const reOverlay = /<|&#?\w+;/;
  2340. const TEXT_LEVEL_ELEMENTS = {
  2341. "http://www.w3.org/1999/xhtml": ["em", "strong", "small", "s", "cite", "q", "dfn", "abbr", "data", "time", "code", "var", "samp", "kbd", "sub", "sup", "i", "b", "u", "mark", "bdi", "bdo", "span", "br", "wbr"]
  2342. };
  2343. const LOCALIZABLE_ATTRIBUTES = {
  2344. "http://www.w3.org/1999/xhtml": {
  2345. global: ["title", "aria-label", "aria-valuetext"],
  2346. a: ["download"],
  2347. area: ["download", "alt"],
  2348. input: ["alt", "placeholder"],
  2349. menuitem: ["label"],
  2350. menu: ["label"],
  2351. optgroup: ["label"],
  2352. option: ["label"],
  2353. track: ["label"],
  2354. img: ["alt"],
  2355. textarea: ["placeholder"],
  2356. th: ["abbr"]
  2357. },
  2358. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul": {
  2359. global: ["accesskey", "aria-label", "aria-valuetext", "label", "title", "tooltiptext"],
  2360. description: ["value"],
  2361. key: ["key", "keycode"],
  2362. label: ["value"],
  2363. textbox: ["placeholder", "value"]
  2364. }
  2365. };
  2366. function translateElement(element, translation) {
  2367. const {
  2368. value
  2369. } = translation;
  2370. if (typeof value === "string") {
  2371. if (element.localName === "title" && element.namespaceURI === "http://www.w3.org/1999/xhtml") {
  2372. element.textContent = value;
  2373. } else if (!reOverlay.test(value)) {
  2374. element.textContent = value;
  2375. } else {
  2376. const templateElement = element.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml", "template");
  2377. templateElement.innerHTML = value;
  2378. overlayChildNodes(templateElement.content, element);
  2379. }
  2380. }
  2381. overlayAttributes(translation, element);
  2382. }
  2383. function overlayChildNodes(fromFragment, toElement) {
  2384. for (const childNode of fromFragment.childNodes) {
  2385. if (childNode.nodeType === childNode.TEXT_NODE) {
  2386. continue;
  2387. }
  2388. if (childNode.hasAttribute("data-l10n-name")) {
  2389. const sanitized = getNodeForNamedElement(toElement, childNode);
  2390. fromFragment.replaceChild(sanitized, childNode);
  2391. continue;
  2392. }
  2393. if (isElementAllowed(childNode)) {
  2394. const sanitized = createSanitizedElement(childNode);
  2395. fromFragment.replaceChild(sanitized, childNode);
  2396. continue;
  2397. }
  2398. console.warn(`An element of forbidden type "${childNode.localName}" was found in ` + "the translation. Only safe text-level elements and elements with " + "data-l10n-name are allowed.");
  2399. fromFragment.replaceChild(createTextNodeFromTextContent(childNode), childNode);
  2400. }
  2401. toElement.textContent = "";
  2402. toElement.appendChild(fromFragment);
  2403. }
  2404. function hasAttribute(attributes, name) {
  2405. if (!attributes) {
  2406. return false;
  2407. }
  2408. for (let attr of attributes) {
  2409. if (attr.name === name) {
  2410. return true;
  2411. }
  2412. }
  2413. return false;
  2414. }
  2415. function overlayAttributes(fromElement, toElement) {
  2416. const explicitlyAllowed = toElement.hasAttribute("data-l10n-attrs") ? toElement.getAttribute("data-l10n-attrs").split(",").map(i => i.trim()) : null;
  2417. for (const attr of Array.from(toElement.attributes)) {
  2418. if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && !hasAttribute(fromElement.attributes, attr.name)) {
  2419. toElement.removeAttribute(attr.name);
  2420. }
  2421. }
  2422. if (!fromElement.attributes) {
  2423. return;
  2424. }
  2425. for (const attr of Array.from(fromElement.attributes)) {
  2426. if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && toElement.getAttribute(attr.name) !== attr.value) {
  2427. toElement.setAttribute(attr.name, attr.value);
  2428. }
  2429. }
  2430. }
  2431. function getNodeForNamedElement(sourceElement, translatedChild) {
  2432. const childName = translatedChild.getAttribute("data-l10n-name");
  2433. const sourceChild = sourceElement.querySelector(`[data-l10n-name="${childName}"]`);
  2434. if (!sourceChild) {
  2435. console.warn(`An element named "${childName}" wasn't found in the source.`);
  2436. return createTextNodeFromTextContent(translatedChild);
  2437. }
  2438. if (sourceChild.localName !== translatedChild.localName) {
  2439. console.warn(`An element named "${childName}" was found in the translation ` + `but its type ${translatedChild.localName} didn't match the ` + `element found in the source (${sourceChild.localName}).`);
  2440. return createTextNodeFromTextContent(translatedChild);
  2441. }
  2442. sourceElement.removeChild(sourceChild);
  2443. const clone = sourceChild.cloneNode(false);
  2444. return shallowPopulateUsing(translatedChild, clone);
  2445. }
  2446. function createSanitizedElement(element) {
  2447. const clone = element.ownerDocument.createElement(element.localName);
  2448. return shallowPopulateUsing(element, clone);
  2449. }
  2450. function createTextNodeFromTextContent(element) {
  2451. return element.ownerDocument.createTextNode(element.textContent);
  2452. }
  2453. function isElementAllowed(element) {
  2454. const allowed = TEXT_LEVEL_ELEMENTS[element.namespaceURI];
  2455. return allowed && allowed.includes(element.localName);
  2456. }
  2457. function isAttrNameLocalizable(name, element, explicitlyAllowed = null) {
  2458. if (explicitlyAllowed && explicitlyAllowed.includes(name)) {
  2459. return true;
  2460. }
  2461. const allowed = LOCALIZABLE_ATTRIBUTES[element.namespaceURI];
  2462. if (!allowed) {
  2463. return false;
  2464. }
  2465. const attrName = name.toLowerCase();
  2466. const elemName = element.localName;
  2467. if (allowed.global.includes(attrName)) {
  2468. return true;
  2469. }
  2470. if (!allowed[elemName]) {
  2471. return false;
  2472. }
  2473. if (allowed[elemName].includes(attrName)) {
  2474. return true;
  2475. }
  2476. if (element.namespaceURI === "http://www.w3.org/1999/xhtml" && elemName === "input" && attrName === "value") {
  2477. const type = element.type.toLowerCase();
  2478. if (type === "submit" || type === "button" || type === "reset") {
  2479. return true;
  2480. }
  2481. }
  2482. return false;
  2483. }
  2484. function shallowPopulateUsing(fromElement, toElement) {
  2485. toElement.textContent = fromElement.textContent;
  2486. overlayAttributes(fromElement, toElement);
  2487. return toElement;
  2488. }
  2489. ;// CONCATENATED MODULE: ./node_modules/cached-iterable/src/cached_iterable.mjs
  2490. class CachedIterable extends Array {
  2491. static from(iterable) {
  2492. if (iterable instanceof this) {
  2493. return iterable;
  2494. }
  2495. return new this(iterable);
  2496. }
  2497. }
  2498. ;// CONCATENATED MODULE: ./node_modules/cached-iterable/src/cached_sync_iterable.mjs
  2499. class CachedSyncIterable extends CachedIterable {
  2500. constructor(iterable) {
  2501. super();
  2502. if (Symbol.iterator in Object(iterable)) {
  2503. this.iterator = iterable[Symbol.iterator]();
  2504. } else {
  2505. throw new TypeError("Argument must implement the iteration protocol.");
  2506. }
  2507. }
  2508. [Symbol.iterator]() {
  2509. const cached = this;
  2510. let cur = 0;
  2511. return {
  2512. next() {
  2513. if (cached.length <= cur) {
  2514. cached.push(cached.iterator.next());
  2515. }
  2516. return cached[cur++];
  2517. }
  2518. };
  2519. }
  2520. touchNext(count = 1) {
  2521. let idx = 0;
  2522. while (idx++ < count) {
  2523. const last = this[this.length - 1];
  2524. if (last && last.done) {
  2525. break;
  2526. }
  2527. this.push(this.iterator.next());
  2528. }
  2529. return this[this.length - 1];
  2530. }
  2531. }
  2532. ;// CONCATENATED MODULE: ./node_modules/cached-iterable/src/cached_async_iterable.mjs
  2533. class CachedAsyncIterable extends CachedIterable {
  2534. constructor(iterable) {
  2535. super();
  2536. if (Symbol.asyncIterator in Object(iterable)) {
  2537. this.iterator = iterable[Symbol.asyncIterator]();
  2538. } else if (Symbol.iterator in Object(iterable)) {
  2539. this.iterator = iterable[Symbol.iterator]();
  2540. } else {
  2541. throw new TypeError("Argument must implement the iteration protocol.");
  2542. }
  2543. }
  2544. [Symbol.asyncIterator]() {
  2545. const cached = this;
  2546. let cur = 0;
  2547. return {
  2548. async next() {
  2549. if (cached.length <= cur) {
  2550. cached.push(cached.iterator.next());
  2551. }
  2552. return cached[cur++];
  2553. }
  2554. };
  2555. }
  2556. async touchNext(count = 1) {
  2557. let idx = 0;
  2558. while (idx++ < count) {
  2559. const last = this[this.length - 1];
  2560. if (last && (await last).done) {
  2561. break;
  2562. }
  2563. this.push(this.iterator.next());
  2564. }
  2565. return this[this.length - 1];
  2566. }
  2567. }
  2568. ;// CONCATENATED MODULE: ./node_modules/cached-iterable/src/index.mjs
  2569. ;// CONCATENATED MODULE: ./node_modules/@fluent/dom/esm/localization.js
  2570. class Localization {
  2571. constructor(resourceIds = [], generateBundles) {
  2572. this.resourceIds = resourceIds;
  2573. this.generateBundles = generateBundles;
  2574. this.onChange(true);
  2575. }
  2576. addResourceIds(resourceIds, eager = false) {
  2577. this.resourceIds.push(...resourceIds);
  2578. this.onChange(eager);
  2579. return this.resourceIds.length;
  2580. }
  2581. removeResourceIds(resourceIds) {
  2582. this.resourceIds = this.resourceIds.filter(r => !resourceIds.includes(r));
  2583. this.onChange();
  2584. return this.resourceIds.length;
  2585. }
  2586. async formatWithFallback(keys, method) {
  2587. const translations = [];
  2588. let hasAtLeastOneBundle = false;
  2589. for await (const bundle of this.bundles) {
  2590. hasAtLeastOneBundle = true;
  2591. const missingIds = keysFromBundle(method, bundle, keys, translations);
  2592. if (missingIds.size === 0) {
  2593. break;
  2594. }
  2595. if (typeof console !== "undefined") {
  2596. const locale = bundle.locales[0];
  2597. const ids = Array.from(missingIds).join(", ");
  2598. console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);
  2599. }
  2600. }
  2601. if (!hasAtLeastOneBundle && typeof console !== "undefined") {
  2602. console.warn(`[fluent] Request for keys failed because no resource bundles got generated.
  2603. keys: ${JSON.stringify(keys)}.
  2604. resourceIds: ${JSON.stringify(this.resourceIds)}.`);
  2605. }
  2606. return translations;
  2607. }
  2608. formatMessages(keys) {
  2609. return this.formatWithFallback(keys, messageFromBundle);
  2610. }
  2611. formatValues(keys) {
  2612. return this.formatWithFallback(keys, valueFromBundle);
  2613. }
  2614. async formatValue(id, args) {
  2615. const [val] = await this.formatValues([{
  2616. id,
  2617. args
  2618. }]);
  2619. return val;
  2620. }
  2621. handleEvent() {
  2622. this.onChange();
  2623. }
  2624. onChange(eager = false) {
  2625. this.bundles = CachedAsyncIterable.from(this.generateBundles(this.resourceIds));
  2626. if (eager) {
  2627. this.bundles.touchNext(2);
  2628. }
  2629. }
  2630. }
  2631. function valueFromBundle(bundle, errors, message, args) {
  2632. if (message.value) {
  2633. return bundle.formatPattern(message.value, args, errors);
  2634. }
  2635. return null;
  2636. }
  2637. function messageFromBundle(bundle, errors, message, args) {
  2638. const formatted = {
  2639. value: null,
  2640. attributes: null
  2641. };
  2642. if (message.value) {
  2643. formatted.value = bundle.formatPattern(message.value, args, errors);
  2644. }
  2645. let attrNames = Object.keys(message.attributes);
  2646. if (attrNames.length > 0) {
  2647. formatted.attributes = new Array(attrNames.length);
  2648. for (let [i, name] of attrNames.entries()) {
  2649. let value = bundle.formatPattern(message.attributes[name], args, errors);
  2650. formatted.attributes[i] = {
  2651. name,
  2652. value
  2653. };
  2654. }
  2655. }
  2656. return formatted;
  2657. }
  2658. function keysFromBundle(method, bundle, keys, translations) {
  2659. const messageErrors = [];
  2660. const missingIds = new Set();
  2661. keys.forEach(({
  2662. id,
  2663. args
  2664. }, i) => {
  2665. if (translations[i] !== undefined) {
  2666. return;
  2667. }
  2668. let message = bundle.getMessage(id);
  2669. if (message) {
  2670. messageErrors.length = 0;
  2671. translations[i] = method(bundle, messageErrors, message, args);
  2672. if (messageErrors.length > 0 && typeof console !== "undefined") {
  2673. const locale = bundle.locales[0];
  2674. const errors = messageErrors.join(", ");
  2675. console.warn(`[fluent][resolver] errors in ${locale}/${id}: ${errors}.`);
  2676. }
  2677. } else {
  2678. missingIds.add(id);
  2679. }
  2680. });
  2681. return missingIds;
  2682. }
  2683. ;// CONCATENATED MODULE: ./node_modules/@fluent/dom/esm/dom_localization.js
  2684. const L10NID_ATTR_NAME = "data-l10n-id";
  2685. const L10NARGS_ATTR_NAME = "data-l10n-args";
  2686. const L10N_ELEMENT_QUERY = `[${L10NID_ATTR_NAME}]`;
  2687. class DOMLocalization extends Localization {
  2688. constructor(resourceIds, generateBundles) {
  2689. super(resourceIds, generateBundles);
  2690. this.roots = new Set();
  2691. this.pendingrAF = null;
  2692. this.pendingElements = new Set();
  2693. this.windowElement = null;
  2694. this.mutationObserver = null;
  2695. this.observerConfig = {
  2696. attributes: true,
  2697. characterData: false,
  2698. childList: true,
  2699. subtree: true,
  2700. attributeFilter: [L10NID_ATTR_NAME, L10NARGS_ATTR_NAME]
  2701. };
  2702. }
  2703. onChange(eager = false) {
  2704. super.onChange(eager);
  2705. if (this.roots) {
  2706. this.translateRoots();
  2707. }
  2708. }
  2709. setAttributes(element, id, args) {
  2710. element.setAttribute(L10NID_ATTR_NAME, id);
  2711. if (args) {
  2712. element.setAttribute(L10NARGS_ATTR_NAME, JSON.stringify(args));
  2713. } else {
  2714. element.removeAttribute(L10NARGS_ATTR_NAME);
  2715. }
  2716. return element;
  2717. }
  2718. getAttributes(element) {
  2719. return {
  2720. id: element.getAttribute(L10NID_ATTR_NAME),
  2721. args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null)
  2722. };
  2723. }
  2724. connectRoot(newRoot) {
  2725. for (const root of this.roots) {
  2726. if (root === newRoot || root.contains(newRoot) || newRoot.contains(root)) {
  2727. throw new Error("Cannot add a root that overlaps with existing root.");
  2728. }
  2729. }
  2730. if (this.windowElement) {
  2731. if (this.windowElement !== newRoot.ownerDocument.defaultView) {
  2732. throw new Error(`Cannot connect a root:
  2733. DOMLocalization already has a root from a different window.`);
  2734. }
  2735. } else {
  2736. this.windowElement = newRoot.ownerDocument.defaultView;
  2737. this.mutationObserver = new this.windowElement.MutationObserver(mutations => this.translateMutations(mutations));
  2738. }
  2739. this.roots.add(newRoot);
  2740. this.mutationObserver.observe(newRoot, this.observerConfig);
  2741. }
  2742. disconnectRoot(root) {
  2743. this.roots.delete(root);
  2744. this.pauseObserving();
  2745. if (this.roots.size === 0) {
  2746. this.mutationObserver = null;
  2747. if (this.windowElement && this.pendingrAF) {
  2748. this.windowElement.cancelAnimationFrame(this.pendingrAF);
  2749. }
  2750. this.windowElement = null;
  2751. this.pendingrAF = null;
  2752. this.pendingElements.clear();
  2753. return true;
  2754. }
  2755. this.resumeObserving();
  2756. return false;
  2757. }
  2758. translateRoots() {
  2759. const roots = Array.from(this.roots);
  2760. return Promise.all(roots.map(root => this.translateFragment(root)));
  2761. }
  2762. pauseObserving() {
  2763. if (!this.mutationObserver) {
  2764. return;
  2765. }
  2766. this.translateMutations(this.mutationObserver.takeRecords());
  2767. this.mutationObserver.disconnect();
  2768. }
  2769. resumeObserving() {
  2770. if (!this.mutationObserver) {
  2771. return;
  2772. }
  2773. for (const root of this.roots) {
  2774. this.mutationObserver.observe(root, this.observerConfig);
  2775. }
  2776. }
  2777. translateMutations(mutations) {
  2778. for (const mutation of mutations) {
  2779. switch (mutation.type) {
  2780. case "attributes":
  2781. if (mutation.target.hasAttribute("data-l10n-id")) {
  2782. this.pendingElements.add(mutation.target);
  2783. }
  2784. break;
  2785. case "childList":
  2786. for (const addedNode of mutation.addedNodes) {
  2787. if (addedNode.nodeType === addedNode.ELEMENT_NODE) {
  2788. if (addedNode.childElementCount) {
  2789. for (const element of this.getTranslatables(addedNode)) {
  2790. this.pendingElements.add(element);
  2791. }
  2792. } else if (addedNode.hasAttribute(L10NID_ATTR_NAME)) {
  2793. this.pendingElements.add(addedNode);
  2794. }
  2795. }
  2796. }
  2797. break;
  2798. }
  2799. }
  2800. if (this.pendingElements.size > 0) {
  2801. if (this.pendingrAF === null) {
  2802. this.pendingrAF = this.windowElement.requestAnimationFrame(() => {
  2803. this.translateElements(Array.from(this.pendingElements));
  2804. this.pendingElements.clear();
  2805. this.pendingrAF = null;
  2806. });
  2807. }
  2808. }
  2809. }
  2810. translateFragment(frag) {
  2811. return this.translateElements(this.getTranslatables(frag));
  2812. }
  2813. async translateElements(elements) {
  2814. if (!elements.length) {
  2815. return undefined;
  2816. }
  2817. const keys = elements.map(this.getKeysForElement);
  2818. const translations = await this.formatMessages(keys);
  2819. return this.applyTranslations(elements, translations);
  2820. }
  2821. applyTranslations(elements, translations) {
  2822. this.pauseObserving();
  2823. for (let i = 0; i < elements.length; i++) {
  2824. if (translations[i] !== undefined) {
  2825. translateElement(elements[i], translations[i]);
  2826. }
  2827. }
  2828. this.resumeObserving();
  2829. }
  2830. getTranslatables(element) {
  2831. const nodes = Array.from(element.querySelectorAll(L10N_ELEMENT_QUERY));
  2832. if (typeof element.hasAttribute === "function" && element.hasAttribute(L10NID_ATTR_NAME)) {
  2833. nodes.push(element);
  2834. }
  2835. return nodes;
  2836. }
  2837. getKeysForElement(element) {
  2838. return {
  2839. id: element.getAttribute(L10NID_ATTR_NAME),
  2840. args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null)
  2841. };
  2842. }
  2843. }
  2844. ;// CONCATENATED MODULE: ./node_modules/@fluent/dom/esm/index.js
  2845. ;// CONCATENATED MODULE: ./web/l10n.js
  2846. class L10n {
  2847. #dir;
  2848. #elements = new Set();
  2849. #lang;
  2850. #l10n;
  2851. constructor({
  2852. lang,
  2853. isRTL
  2854. }, l10n = null) {
  2855. this.#lang = L10n.#fixupLangCode(lang);
  2856. this.#l10n = l10n;
  2857. this.#dir = isRTL ?? L10n.#isRTL(this.#lang) ? "rtl" : "ltr";
  2858. }
  2859. _setL10n(l10n) {
  2860. this.#l10n = l10n;
  2861. }
  2862. getLanguage() {
  2863. return this.#lang;
  2864. }
  2865. getDirection() {
  2866. return this.#dir;
  2867. }
  2868. async get(ids, args = null, fallback) {
  2869. if (Array.isArray(ids)) {
  2870. ids = ids.map(id => ({
  2871. id
  2872. }));
  2873. const messages = await this.#l10n.formatMessages(ids);
  2874. return messages.map(message => message.value);
  2875. }
  2876. const messages = await this.#l10n.formatMessages([{
  2877. id: ids,
  2878. args
  2879. }]);
  2880. return messages?.[0].value || fallback;
  2881. }
  2882. async translate(element) {
  2883. this.#elements.add(element);
  2884. try {
  2885. this.#l10n.connectRoot(element);
  2886. await this.#l10n.translateRoots();
  2887. } catch {}
  2888. }
  2889. async destroy() {
  2890. for (const element of this.#elements) {
  2891. this.#l10n.disconnectRoot(element);
  2892. }
  2893. this.#elements.clear();
  2894. this.#l10n.pauseObserving();
  2895. }
  2896. pause() {
  2897. this.#l10n.pauseObserving();
  2898. }
  2899. resume() {
  2900. this.#l10n.resumeObserving();
  2901. }
  2902. static #fixupLangCode(langCode) {
  2903. langCode = langCode?.toLowerCase() || "en-us";
  2904. const PARTIAL_LANG_CODES = {
  2905. en: "en-us",
  2906. es: "es-es",
  2907. fy: "fy-nl",
  2908. ga: "ga-ie",
  2909. gu: "gu-in",
  2910. hi: "hi-in",
  2911. hy: "hy-am",
  2912. nb: "nb-no",
  2913. ne: "ne-np",
  2914. nn: "nn-no",
  2915. pa: "pa-in",
  2916. pt: "pt-pt",
  2917. sv: "sv-se",
  2918. zh: "zh-cn"
  2919. };
  2920. return PARTIAL_LANG_CODES[langCode] || langCode;
  2921. }
  2922. static #isRTL(lang) {
  2923. const shortCode = lang.split("-", 1)[0];
  2924. return ["ar", "he", "fa", "ps", "ur"].includes(shortCode);
  2925. }
  2926. }
  2927. const GenericL10n = null;
  2928. ;// CONCATENATED MODULE: ./web/genericl10n.js
  2929. function createBundle(lang, text) {
  2930. const resource = new FluentResource(text);
  2931. const bundle = new FluentBundle(lang);
  2932. const errors = bundle.addResource(resource);
  2933. if (errors.length) {
  2934. console.error("L10n errors", errors);
  2935. }
  2936. return bundle;
  2937. }
  2938. class genericl10n_GenericL10n extends L10n {
  2939. constructor(lang) {
  2940. super({
  2941. lang
  2942. });
  2943. const generateBundles = !lang ? genericl10n_GenericL10n.#generateBundlesFallback.bind(genericl10n_GenericL10n, this.getLanguage()) : genericl10n_GenericL10n.#generateBundles.bind(genericl10n_GenericL10n, "en-us", this.getLanguage());
  2944. this._setL10n(new DOMLocalization([], generateBundles));
  2945. }
  2946. static async *#generateBundles(defaultLang, baseLang) {
  2947. const {
  2948. baseURL,
  2949. paths
  2950. } = await this.#getPaths();
  2951. const langs = [baseLang];
  2952. if (defaultLang !== baseLang) {
  2953. const shortLang = baseLang.split("-", 1)[0];
  2954. if (shortLang !== baseLang) {
  2955. langs.push(shortLang);
  2956. }
  2957. langs.push(defaultLang);
  2958. }
  2959. for (const lang of langs) {
  2960. const bundle = await this.#createBundle(lang, baseURL, paths);
  2961. if (bundle) {
  2962. yield bundle;
  2963. } else if (lang === "en-us") {
  2964. yield this.#createBundleFallback(lang);
  2965. }
  2966. }
  2967. }
  2968. static async #createBundle(lang, baseURL, paths) {
  2969. const path = paths[lang];
  2970. if (!path) {
  2971. return null;
  2972. }
  2973. const url = new URL(path, baseURL);
  2974. const text = await fetchData(url, "text");
  2975. return createBundle(lang, text);
  2976. }
  2977. static async #getPaths() {
  2978. try {
  2979. const {
  2980. href
  2981. } = document.querySelector(`link[type="application/l10n"]`);
  2982. const paths = await fetchData(href, "json");
  2983. return {
  2984. baseURL: href.replace(/[^/]*$/, "") || "./",
  2985. paths
  2986. };
  2987. } catch {}
  2988. return {
  2989. baseURL: "./",
  2990. paths: Object.create(null)
  2991. };
  2992. }
  2993. static async *#generateBundlesFallback(lang) {
  2994. yield this.#createBundleFallback(lang);
  2995. }
  2996. static async #createBundleFallback(lang) {
  2997. const text = "pdfjs-previous-button =\n .title = Previous Page\npdfjs-previous-button-label = Previous\npdfjs-next-button =\n .title = Next Page\npdfjs-next-button-label = Next\npdfjs-page-input =\n .title = Page\npdfjs-of-pages = of { $pagesCount }\npdfjs-page-of-pages = ({ $pageNumber } of { $pagesCount })\npdfjs-zoom-out-button =\n .title = Zoom Out\npdfjs-zoom-out-button-label = Zoom Out\npdfjs-zoom-in-button =\n .title = Zoom In\npdfjs-zoom-in-button-label = Zoom In\npdfjs-zoom-select =\n .title = Zoom\npdfjs-presentation-mode-button =\n .title = Switch to Presentation Mode\npdfjs-presentation-mode-button-label = Presentation Mode\npdfjs-open-file-button =\n .title = Open File\npdfjs-open-file-button-label = Open\npdfjs-print-button =\n .title = Print\npdfjs-print-button-label = Print\npdfjs-save-button =\n .title = Save\npdfjs-save-button-label = Save\npdfjs-download-button =\n .title = Download\npdfjs-download-button-label = Download\npdfjs-bookmark-button =\n .title = Current Page (View URL from Current Page)\npdfjs-bookmark-button-label = Current Page\npdfjs-tools-button =\n .title = Tools\npdfjs-tools-button-label = Tools\npdfjs-first-page-button =\n .title = Go to First Page\npdfjs-first-page-button-label = Go to First Page\npdfjs-last-page-button =\n .title = Go to Last Page\npdfjs-last-page-button-label = Go to Last Page\npdfjs-page-rotate-cw-button =\n .title = Rotate Clockwise\npdfjs-page-rotate-cw-button-label = Rotate Clockwise\npdfjs-page-rotate-ccw-button =\n .title = Rotate Counterclockwise\npdfjs-page-rotate-ccw-button-label = Rotate Counterclockwise\npdfjs-cursor-text-select-tool-button =\n .title = Enable Text Selection Tool\npdfjs-cursor-text-select-tool-button-label = Text Selection Tool\npdfjs-cursor-hand-tool-button =\n .title = Enable Hand Tool\npdfjs-cursor-hand-tool-button-label = Hand Tool\npdfjs-scroll-page-button =\n .title = Use Page Scrolling\npdfjs-scroll-page-button-label = Page Scrolling\npdfjs-scroll-vertical-button =\n .title = Use Vertical Scrolling\npdfjs-scroll-vertical-button-label = Vertical Scrolling\npdfjs-scroll-horizontal-button =\n .title = Use Horizontal Scrolling\npdfjs-scroll-horizontal-button-label = Horizontal Scrolling\npdfjs-scroll-wrapped-button =\n .title = Use Wrapped Scrolling\npdfjs-scroll-wrapped-button-label = Wrapped Scrolling\npdfjs-spread-none-button =\n .title = Do not join page spreads\npdfjs-spread-none-button-label = No Spreads\npdfjs-spread-odd-button =\n .title = Join page spreads starting with odd-numbered pages\npdfjs-spread-odd-button-label = Odd Spreads\npdfjs-spread-even-button =\n .title = Join page spreads starting with even-numbered pages\npdfjs-spread-even-button-label = Even Spreads\npdfjs-document-properties-button =\n .title = Document Properties\u2026\npdfjs-document-properties-button-label = Document Properties\u2026\npdfjs-document-properties-file-name = File name:\npdfjs-document-properties-file-size = File size:\npdfjs-document-properties-kb = { $size_kb } KB ({ $size_b } bytes)\npdfjs-document-properties-mb = { $size_mb } MB ({ $size_b } bytes)\npdfjs-document-properties-title = Title:\npdfjs-document-properties-author = Author:\npdfjs-document-properties-subject = Subject:\npdfjs-document-properties-keywords = Keywords:\npdfjs-document-properties-creation-date = Creation Date:\npdfjs-document-properties-modification-date = Modification Date:\npdfjs-document-properties-date-string = { $date }, { $time }\npdfjs-document-properties-creator = Creator:\npdfjs-document-properties-producer = PDF Producer:\npdfjs-document-properties-version = PDF Version:\npdfjs-document-properties-page-count = Page Count:\npdfjs-document-properties-page-size = Page Size:\npdfjs-document-properties-page-size-unit-inches = in\npdfjs-document-properties-page-size-unit-millimeters = mm\npdfjs-document-properties-page-size-orientation-portrait = portrait\npdfjs-document-properties-page-size-orientation-landscape = landscape\npdfjs-document-properties-page-size-name-a-three = A3\npdfjs-document-properties-page-size-name-a-four = A4\npdfjs-document-properties-page-size-name-letter = Letter\npdfjs-document-properties-page-size-name-legal = Legal\npdfjs-document-properties-page-size-dimension-string = { $width } \xD7 { $height } { $unit } ({ $orientation })\npdfjs-document-properties-page-size-dimension-name-string = { $width } \xD7 { $height } { $unit } ({ $name }, { $orientation })\npdfjs-document-properties-linearized = Fast Web View:\npdfjs-document-properties-linearized-yes = Yes\npdfjs-document-properties-linearized-no = No\npdfjs-document-properties-close-button = Close\npdfjs-print-progress-message = Preparing document for printing\u2026\npdfjs-print-progress-percent = { $progress }%\npdfjs-print-progress-close-button = Cancel\npdfjs-printing-not-supported = Warning: Printing is not fully supported by this browser.\npdfjs-printing-not-ready = Warning: The PDF is not fully loaded for printing.\npdfjs-toggle-sidebar-button =\n .title = Toggle Sidebar\npdfjs-toggle-sidebar-notification-button =\n .title = Toggle Sidebar (document contains outline/attachments/layers)\npdfjs-toggle-sidebar-button-label = Toggle Sidebar\npdfjs-document-outline-button =\n .title = Show Document Outline (double-click to expand/collapse all items)\npdfjs-document-outline-button-label = Document Outline\npdfjs-attachments-button =\n .title = Show Attachments\npdfjs-attachments-button-label = Attachments\npdfjs-layers-button =\n .title = Show Layers (double-click to reset all layers to the default state)\npdfjs-layers-button-label = Layers\npdfjs-thumbs-button =\n .title = Show Thumbnails\npdfjs-thumbs-button-label = Thumbnails\npdfjs-current-outline-item-button =\n .title = Find Current Outline Item\npdfjs-current-outline-item-button-label = Current Outline Item\npdfjs-findbar-button =\n .title = Find in Document\npdfjs-findbar-button-label = Find\npdfjs-additional-layers = Additional Layers\npdfjs-thumb-page-title =\n .title = Page { $page }\npdfjs-thumb-page-canvas =\n .aria-label = Thumbnail of Page { $page }\npdfjs-find-input =\n .title = Find\n .placeholder = Find in document\u2026\npdfjs-find-previous-button =\n .title = Find the previous occurrence of the phrase\npdfjs-find-previous-button-label = Previous\npdfjs-find-next-button =\n .title = Find the next occurrence of the phrase\npdfjs-find-next-button-label = Next\npdfjs-find-highlight-checkbox = Highlight All\npdfjs-find-match-case-checkbox-label = Match Case\npdfjs-find-match-diacritics-checkbox-label = Match Diacritics\npdfjs-find-entire-word-checkbox-label = Whole Words\npdfjs-find-reached-top = Reached top of document, continued from bottom\npdfjs-find-reached-bottom = Reached end of document, continued from top\npdfjs-find-match-count =\n { $total ->\n [one] { $current } of { $total } match\n *[other] { $current } of { $total } matches\n }\npdfjs-find-match-count-limit =\n { $limit ->\n [one] More than { $limit } match\n *[other] More than { $limit } matches\n }\npdfjs-find-not-found = Phrase not found\npdfjs-page-scale-width = Page Width\npdfjs-page-scale-fit = Page Fit\npdfjs-page-scale-auto = Automatic Zoom\npdfjs-page-scale-actual = Actual Size\npdfjs-page-scale-percent = { $scale }%\npdfjs-page-landmark =\n .aria-label = Page { $page }\npdfjs-loading-error = An error occurred while loading the PDF.\npdfjs-invalid-file-error = Invalid or corrupted PDF file.\npdfjs-missing-file-error = Missing PDF file.\npdfjs-unexpected-response-error = Unexpected server response.\npdfjs-rendering-error = An error occurred while rendering the page.\npdfjs-annotation-date-string = { $date }, { $time }\npdfjs-text-annotation-type =\n .alt = [{ $type } Annotation]\npdfjs-password-label = Enter the password to open this PDF file.\npdfjs-password-invalid = Invalid password. Please try again.\npdfjs-password-ok-button = OK\npdfjs-password-cancel-button = Cancel\npdfjs-web-fonts-disabled = Web fonts are disabled: unable to use embedded PDF fonts.\npdfjs-editor-free-text-button =\n .title = Text\npdfjs-editor-free-text-button-label = Text\npdfjs-editor-ink-button =\n .title = Draw\npdfjs-editor-ink-button-label = Draw\npdfjs-editor-stamp-button =\n .title = Add or edit images\npdfjs-editor-stamp-button-label = Add or edit images\npdfjs-editor-highlight-button =\n .title = Highlight\npdfjs-editor-highlight-button-label = Highlight\npdfjs-highlight-floating-button1 =\n .title = Highlight\n .aria-label = Highlight\npdfjs-highlight-floating-button-label = Highlight\npdfjs-editor-remove-ink-button =\n .title = Remove drawing\npdfjs-editor-remove-freetext-button =\n .title = Remove text\npdfjs-editor-remove-stamp-button =\n .title = Remove image\npdfjs-editor-remove-highlight-button =\n .title = Remove highlight\npdfjs-editor-free-text-color-input = Color\npdfjs-editor-free-text-size-input = Size\npdfjs-editor-ink-color-input = Color\npdfjs-editor-ink-thickness-input = Thickness\npdfjs-editor-ink-opacity-input = Opacity\npdfjs-editor-stamp-add-image-button =\n .title = Add image\npdfjs-editor-stamp-add-image-button-label = Add image\npdfjs-editor-free-highlight-thickness-input = Thickness\npdfjs-editor-free-highlight-thickness-title =\n .title = Change thickness when highlighting items other than text\npdfjs-free-text =\n .aria-label = Text Editor\npdfjs-free-text-default-content = Start typing\u2026\npdfjs-ink =\n .aria-label = Draw Editor\npdfjs-ink-canvas =\n .aria-label = User-created image\npdfjs-editor-alt-text-button-label = Alt text\npdfjs-editor-alt-text-edit-button-label = Edit alt text\npdfjs-editor-alt-text-dialog-label = Choose an option\npdfjs-editor-alt-text-dialog-description = Alt text (alternative text) helps when people can\u2019t see the image or when it doesn\u2019t load.\npdfjs-editor-alt-text-add-description-label = Add a description\npdfjs-editor-alt-text-add-description-description = Aim for 1-2 sentences that describe the subject, setting, or actions.\npdfjs-editor-alt-text-mark-decorative-label = Mark as decorative\npdfjs-editor-alt-text-mark-decorative-description = This is used for ornamental images, like borders or watermarks.\npdfjs-editor-alt-text-cancel-button = Cancel\npdfjs-editor-alt-text-save-button = Save\npdfjs-editor-alt-text-decorative-tooltip = Marked as decorative\npdfjs-editor-alt-text-textarea =\n .placeholder = For example, \u201CA young man sits down at a table to eat a meal\u201D\npdfjs-editor-resizer-label-top-left = Top left corner \u2014 resize\npdfjs-editor-resizer-label-top-middle = Top middle \u2014 resize\npdfjs-editor-resizer-label-top-right = Top right corner \u2014 resize\npdfjs-editor-resizer-label-middle-right = Middle right \u2014 resize\npdfjs-editor-resizer-label-bottom-right = Bottom right corner \u2014 resize\npdfjs-editor-resizer-label-bottom-middle = Bottom middle \u2014 resize\npdfjs-editor-resizer-label-bottom-left = Bottom left corner \u2014 resize\npdfjs-editor-resizer-label-middle-left = Middle left \u2014 resize\npdfjs-editor-highlight-colorpicker-label = Highlight color\npdfjs-editor-colorpicker-button =\n .title = Change color\npdfjs-editor-colorpicker-dropdown =\n .aria-label = Color choices\npdfjs-editor-colorpicker-yellow =\n .title = Yellow\npdfjs-editor-colorpicker-green =\n .title = Green\npdfjs-editor-colorpicker-blue =\n .title = Blue\npdfjs-editor-colorpicker-pink =\n .title = Pink\npdfjs-editor-colorpicker-red =\n .title = Red\npdfjs-editor-highlight-show-all-button-label = Show all\npdfjs-editor-highlight-show-all-button =\n .title = Show all";
  2998. return createBundle(lang, text);
  2999. }
  3000. }
  3001. ;// CONCATENATED MODULE: ./web/generic_scripting.js
  3002. async function docProperties(pdfDocument) {
  3003. const url = "",
  3004. baseUrl = url.split("#", 1)[0];
  3005. let {
  3006. info,
  3007. metadata,
  3008. contentDispositionFilename,
  3009. contentLength
  3010. } = await pdfDocument.getMetadata();
  3011. if (!contentLength) {
  3012. const {
  3013. length
  3014. } = await pdfDocument.getDownloadInfo();
  3015. contentLength = length;
  3016. }
  3017. return {
  3018. ...info,
  3019. baseURL: baseUrl,
  3020. filesize: contentLength,
  3021. filename: contentDispositionFilename || getPdfFilenameFromUrl(url),
  3022. metadata: metadata?.getRaw(),
  3023. authors: metadata?.get("dc:creator"),
  3024. numPages: pdfDocument.numPages,
  3025. URL: url
  3026. };
  3027. }
  3028. class GenericScripting {
  3029. constructor(sandboxBundleSrc) {
  3030. this._ready = new Promise((resolve, reject) => {
  3031. const sandbox = import( /*webpackIgnore: true*/sandboxBundleSrc);
  3032. sandbox.then(pdfjsSandbox => {
  3033. resolve(pdfjsSandbox.QuickJSSandbox());
  3034. }).catch(reject);
  3035. });
  3036. }
  3037. async createSandbox(data) {
  3038. const sandbox = await this._ready;
  3039. sandbox.create(data);
  3040. }
  3041. async dispatchEventInSandbox(event) {
  3042. const sandbox = await this._ready;
  3043. setTimeout(() => sandbox.dispatchEvent(event), 0);
  3044. }
  3045. async destroySandbox() {
  3046. const sandbox = await this._ready;
  3047. sandbox.nukeSandbox();
  3048. }
  3049. }
  3050. ;// CONCATENATED MODULE: ./web/genericcom.js
  3051. function initCom(app) {}
  3052. class Preferences extends BasePreferences {
  3053. async _writeToStorage(prefObj) {
  3054. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  3055. }
  3056. async _readFromStorage(prefObj) {
  3057. return {
  3058. prefs: JSON.parse(localStorage.getItem("pdfjs.preferences"))
  3059. };
  3060. }
  3061. }
  3062. class ExternalServices extends BaseExternalServices {
  3063. async createL10n() {
  3064. return new genericl10n_GenericL10n(AppOptions.get("localeProperties")?.lang);
  3065. }
  3066. createScripting() {
  3067. return new GenericScripting(AppOptions.get("sandboxBundleSrc"));
  3068. }
  3069. }
  3070. class MLManager {
  3071. async isEnabledFor(_name) {
  3072. return false;
  3073. }
  3074. async deleteModel(_service) {
  3075. return null;
  3076. }
  3077. async guess() {
  3078. return null;
  3079. }
  3080. }
  3081. ;// CONCATENATED MODULE: ./web/alt_text_manager.js
  3082. class AltTextManager {
  3083. #boundUpdateUIState = this.#updateUIState.bind(this);
  3084. #boundSetPosition = this.#setPosition.bind(this);
  3085. #boundOnClick = this.#onClick.bind(this);
  3086. #currentEditor = null;
  3087. #cancelButton;
  3088. #dialog;
  3089. #eventBus;
  3090. #hasUsedPointer = false;
  3091. #optionDescription;
  3092. #optionDecorative;
  3093. #overlayManager;
  3094. #saveButton;
  3095. #textarea;
  3096. #uiManager;
  3097. #previousAltText = null;
  3098. #svgElement = null;
  3099. #rectElement = null;
  3100. #container;
  3101. #telemetryData = null;
  3102. constructor({
  3103. dialog,
  3104. optionDescription,
  3105. optionDecorative,
  3106. textarea,
  3107. cancelButton,
  3108. saveButton
  3109. }, container, overlayManager, eventBus) {
  3110. this.#dialog = dialog;
  3111. this.#optionDescription = optionDescription;
  3112. this.#optionDecorative = optionDecorative;
  3113. this.#textarea = textarea;
  3114. this.#cancelButton = cancelButton;
  3115. this.#saveButton = saveButton;
  3116. this.#overlayManager = overlayManager;
  3117. this.#eventBus = eventBus;
  3118. this.#container = container;
  3119. dialog.addEventListener("close", this.#close.bind(this));
  3120. dialog.addEventListener("contextmenu", event => {
  3121. if (event.target !== this.#textarea) {
  3122. event.preventDefault();
  3123. }
  3124. });
  3125. cancelButton.addEventListener("click", this.#finish.bind(this));
  3126. saveButton.addEventListener("click", this.#save.bind(this));
  3127. optionDescription.addEventListener("change", this.#boundUpdateUIState);
  3128. optionDecorative.addEventListener("change", this.#boundUpdateUIState);
  3129. this.#overlayManager.register(dialog);
  3130. }
  3131. get _elements() {
  3132. return shadow(this, "_elements", [this.#optionDescription, this.#optionDecorative, this.#textarea, this.#saveButton, this.#cancelButton]);
  3133. }
  3134. #createSVGElement() {
  3135. if (this.#svgElement) {
  3136. return;
  3137. }
  3138. const svgFactory = new DOMSVGFactory();
  3139. const svg = this.#svgElement = svgFactory.createElement("svg");
  3140. svg.setAttribute("width", "0");
  3141. svg.setAttribute("height", "0");
  3142. const defs = svgFactory.createElement("defs");
  3143. svg.append(defs);
  3144. const mask = svgFactory.createElement("mask");
  3145. defs.append(mask);
  3146. mask.setAttribute("id", "alttext-manager-mask");
  3147. mask.setAttribute("maskContentUnits", "objectBoundingBox");
  3148. let rect = svgFactory.createElement("rect");
  3149. mask.append(rect);
  3150. rect.setAttribute("fill", "white");
  3151. rect.setAttribute("width", "1");
  3152. rect.setAttribute("height", "1");
  3153. rect.setAttribute("x", "0");
  3154. rect.setAttribute("y", "0");
  3155. rect = this.#rectElement = svgFactory.createElement("rect");
  3156. mask.append(rect);
  3157. rect.setAttribute("fill", "black");
  3158. this.#dialog.append(svg);
  3159. }
  3160. async editAltText(uiManager, editor) {
  3161. if (this.#currentEditor || !editor) {
  3162. return;
  3163. }
  3164. this.#createSVGElement();
  3165. this.#hasUsedPointer = false;
  3166. for (const element of this._elements) {
  3167. element.addEventListener("click", this.#boundOnClick);
  3168. }
  3169. const {
  3170. altText,
  3171. decorative
  3172. } = editor.altTextData;
  3173. if (decorative === true) {
  3174. this.#optionDecorative.checked = true;
  3175. this.#optionDescription.checked = false;
  3176. } else {
  3177. this.#optionDecorative.checked = false;
  3178. this.#optionDescription.checked = true;
  3179. }
  3180. this.#previousAltText = this.#textarea.value = altText?.trim() || "";
  3181. this.#updateUIState();
  3182. this.#currentEditor = editor;
  3183. this.#uiManager = uiManager;
  3184. this.#uiManager.removeEditListeners();
  3185. this.#eventBus._on("resize", this.#boundSetPosition);
  3186. try {
  3187. await this.#overlayManager.open(this.#dialog);
  3188. this.#setPosition();
  3189. } catch (ex) {
  3190. this.#close();
  3191. throw ex;
  3192. }
  3193. }
  3194. #setPosition() {
  3195. if (!this.#currentEditor) {
  3196. return;
  3197. }
  3198. const dialog = this.#dialog;
  3199. const {
  3200. style
  3201. } = dialog;
  3202. const {
  3203. x: containerX,
  3204. y: containerY,
  3205. width: containerW,
  3206. height: containerH
  3207. } = this.#container.getBoundingClientRect();
  3208. const {
  3209. innerWidth: windowW,
  3210. innerHeight: windowH
  3211. } = window;
  3212. const {
  3213. width: dialogW,
  3214. height: dialogH
  3215. } = dialog.getBoundingClientRect();
  3216. const {
  3217. x,
  3218. y,
  3219. width,
  3220. height
  3221. } = this.#currentEditor.getClientDimensions();
  3222. const MARGIN = 10;
  3223. const isLTR = this.#uiManager.direction === "ltr";
  3224. const xs = Math.max(x, containerX);
  3225. const xe = Math.min(x + width, containerX + containerW);
  3226. const ys = Math.max(y, containerY);
  3227. const ye = Math.min(y + height, containerY + containerH);
  3228. this.#rectElement.setAttribute("width", `${(xe - xs) / windowW}`);
  3229. this.#rectElement.setAttribute("height", `${(ye - ys) / windowH}`);
  3230. this.#rectElement.setAttribute("x", `${xs / windowW}`);
  3231. this.#rectElement.setAttribute("y", `${ys / windowH}`);
  3232. let left = null;
  3233. let top = Math.max(y, 0);
  3234. top += Math.min(windowH - (top + dialogH), 0);
  3235. if (isLTR) {
  3236. if (x + width + MARGIN + dialogW < windowW) {
  3237. left = x + width + MARGIN;
  3238. } else if (x > dialogW + MARGIN) {
  3239. left = x - dialogW - MARGIN;
  3240. }
  3241. } else if (x > dialogW + MARGIN) {
  3242. left = x - dialogW - MARGIN;
  3243. } else if (x + width + MARGIN + dialogW < windowW) {
  3244. left = x + width + MARGIN;
  3245. }
  3246. if (left === null) {
  3247. top = null;
  3248. left = Math.max(x, 0);
  3249. left += Math.min(windowW - (left + dialogW), 0);
  3250. if (y > dialogH + MARGIN) {
  3251. top = y - dialogH - MARGIN;
  3252. } else if (y + height + MARGIN + dialogH < windowH) {
  3253. top = y + height + MARGIN;
  3254. }
  3255. }
  3256. if (top !== null) {
  3257. dialog.classList.add("positioned");
  3258. if (isLTR) {
  3259. style.left = `${left}px`;
  3260. } else {
  3261. style.right = `${windowW - left - dialogW}px`;
  3262. }
  3263. style.top = `${top}px`;
  3264. } else {
  3265. dialog.classList.remove("positioned");
  3266. style.left = "";
  3267. style.top = "";
  3268. }
  3269. }
  3270. #finish() {
  3271. if (this.#overlayManager.active === this.#dialog) {
  3272. this.#overlayManager.close(this.#dialog);
  3273. }
  3274. }
  3275. #close() {
  3276. this.#currentEditor._reportTelemetry(this.#telemetryData || {
  3277. action: "alt_text_cancel",
  3278. alt_text_keyboard: !this.#hasUsedPointer
  3279. });
  3280. this.#telemetryData = null;
  3281. this.#removeOnClickListeners();
  3282. this.#uiManager?.addEditListeners();
  3283. this.#eventBus._off("resize", this.#boundSetPosition);
  3284. this.#currentEditor.altTextFinish();
  3285. this.#currentEditor = null;
  3286. this.#uiManager = null;
  3287. }
  3288. #updateUIState() {
  3289. this.#textarea.disabled = this.#optionDecorative.checked;
  3290. }
  3291. #save() {
  3292. const altText = this.#textarea.value.trim();
  3293. const decorative = this.#optionDecorative.checked;
  3294. this.#currentEditor.altTextData = {
  3295. altText,
  3296. decorative
  3297. };
  3298. this.#telemetryData = {
  3299. action: "alt_text_save",
  3300. alt_text_description: !!altText,
  3301. alt_text_edit: !!this.#previousAltText && this.#previousAltText !== altText,
  3302. alt_text_decorative: decorative,
  3303. alt_text_keyboard: !this.#hasUsedPointer
  3304. };
  3305. this.#finish();
  3306. }
  3307. #onClick(evt) {
  3308. if (evt.detail === 0) {
  3309. return;
  3310. }
  3311. this.#hasUsedPointer = true;
  3312. this.#removeOnClickListeners();
  3313. }
  3314. #removeOnClickListeners() {
  3315. for (const element of this._elements) {
  3316. element.removeEventListener("click", this.#boundOnClick);
  3317. }
  3318. }
  3319. destroy() {
  3320. this.#uiManager = null;
  3321. this.#finish();
  3322. this.#svgElement?.remove();
  3323. this.#svgElement = this.#rectElement = null;
  3324. }
  3325. }
  3326. ;// CONCATENATED MODULE: ./web/annotation_editor_params.js
  3327. class AnnotationEditorParams {
  3328. constructor(options, eventBus) {
  3329. this.eventBus = eventBus;
  3330. this.#bindListeners(options);
  3331. }
  3332. #bindListeners({
  3333. editorFreeTextFontSize,
  3334. editorFreeTextColor,
  3335. editorInkColor,
  3336. editorInkThickness,
  3337. editorInkOpacity,
  3338. editorStampAddImage,
  3339. editorFreeHighlightThickness,
  3340. editorHighlightShowAll
  3341. }) {
  3342. const dispatchEvent = (typeStr, value) => {
  3343. this.eventBus.dispatch("switchannotationeditorparams", {
  3344. source: this,
  3345. type: AnnotationEditorParamsType[typeStr],
  3346. value
  3347. });
  3348. };
  3349. editorFreeTextFontSize.addEventListener("input", function () {
  3350. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  3351. });
  3352. editorFreeTextColor.addEventListener("input", function () {
  3353. dispatchEvent("FREETEXT_COLOR", this.value);
  3354. });
  3355. editorInkColor.addEventListener("input", function () {
  3356. dispatchEvent("INK_COLOR", this.value);
  3357. });
  3358. editorInkThickness.addEventListener("input", function () {
  3359. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  3360. });
  3361. editorInkOpacity.addEventListener("input", function () {
  3362. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  3363. });
  3364. editorStampAddImage.addEventListener("click", () => {
  3365. dispatchEvent("CREATE");
  3366. });
  3367. editorFreeHighlightThickness.addEventListener("input", function () {
  3368. dispatchEvent("HIGHLIGHT_THICKNESS", this.valueAsNumber);
  3369. });
  3370. editorHighlightShowAll.addEventListener("click", function () {
  3371. const checked = this.getAttribute("aria-pressed") === "true";
  3372. this.setAttribute("aria-pressed", !checked);
  3373. dispatchEvent("HIGHLIGHT_SHOW_ALL", !checked);
  3374. });
  3375. this.eventBus._on("annotationeditorparamschanged", evt => {
  3376. for (const [type, value] of evt.details) {
  3377. switch (type) {
  3378. case AnnotationEditorParamsType.FREETEXT_SIZE:
  3379. editorFreeTextFontSize.value = value;
  3380. break;
  3381. case AnnotationEditorParamsType.FREETEXT_COLOR:
  3382. editorFreeTextColor.value = value;
  3383. break;
  3384. case AnnotationEditorParamsType.INK_COLOR:
  3385. editorInkColor.value = value;
  3386. break;
  3387. case AnnotationEditorParamsType.INK_THICKNESS:
  3388. editorInkThickness.value = value;
  3389. break;
  3390. case AnnotationEditorParamsType.INK_OPACITY:
  3391. editorInkOpacity.value = value;
  3392. break;
  3393. case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  3394. editorFreeHighlightThickness.value = value;
  3395. break;
  3396. case AnnotationEditorParamsType.HIGHLIGHT_FREE:
  3397. editorFreeHighlightThickness.disabled = !value;
  3398. break;
  3399. case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
  3400. editorHighlightShowAll.setAttribute("aria-pressed", value);
  3401. break;
  3402. }
  3403. }
  3404. });
  3405. }
  3406. }
  3407. ;// CONCATENATED MODULE: ./web/caret_browsing.js
  3408. const PRECISION = 1e-1;
  3409. class CaretBrowsingMode {
  3410. #mainContainer;
  3411. #toolBarHeight;
  3412. #viewerContainer;
  3413. constructor(mainContainer, viewerContainer, toolbarContainer) {
  3414. this.#mainContainer = mainContainer;
  3415. this.#viewerContainer = viewerContainer;
  3416. this.#toolBarHeight = toolbarContainer?.getBoundingClientRect().height ?? 0;
  3417. }
  3418. #isOnSameLine(rect1, rect2) {
  3419. const top1 = rect1.y;
  3420. const bot1 = rect1.bottom;
  3421. const mid1 = rect1.y + rect1.height / 2;
  3422. const top2 = rect2.y;
  3423. const bot2 = rect2.bottom;
  3424. const mid2 = rect2.y + rect2.height / 2;
  3425. return top1 <= mid2 && mid2 <= bot1 || top2 <= mid1 && mid1 <= bot2;
  3426. }
  3427. #isUnderOver(rect, x, y, isUp) {
  3428. const midY = rect.y + rect.height / 2;
  3429. return (isUp ? y >= midY : y <= midY) && rect.x - PRECISION <= x && x <= rect.right + PRECISION;
  3430. }
  3431. #isVisible(rect) {
  3432. return rect.top >= this.#toolBarHeight && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
  3433. }
  3434. #getCaretPosition(selection, isUp) {
  3435. const {
  3436. focusNode,
  3437. focusOffset
  3438. } = selection;
  3439. const range = document.createRange();
  3440. range.setStart(focusNode, focusOffset);
  3441. range.setEnd(focusNode, focusOffset);
  3442. const rect = range.getBoundingClientRect();
  3443. return [rect.x, isUp ? rect.top : rect.bottom];
  3444. }
  3445. static #caretPositionFromPoint(x, y) {
  3446. if (!document.caretPositionFromPoint) {
  3447. const {
  3448. startContainer: offsetNode,
  3449. startOffset: offset
  3450. } = document.caretRangeFromPoint(x, y);
  3451. return {
  3452. offsetNode,
  3453. offset
  3454. };
  3455. }
  3456. return document.caretPositionFromPoint(x, y);
  3457. }
  3458. #setCaretPositionHelper(selection, caretX, select, element, rect) {
  3459. rect ||= element.getBoundingClientRect();
  3460. if (caretX <= rect.x + PRECISION) {
  3461. if (select) {
  3462. selection.extend(element.firstChild, 0);
  3463. } else {
  3464. selection.setPosition(element.firstChild, 0);
  3465. }
  3466. return;
  3467. }
  3468. if (rect.right - PRECISION <= caretX) {
  3469. const {
  3470. lastChild
  3471. } = element;
  3472. if (select) {
  3473. selection.extend(lastChild, lastChild.length);
  3474. } else {
  3475. selection.setPosition(lastChild, lastChild.length);
  3476. }
  3477. return;
  3478. }
  3479. const midY = rect.y + rect.height / 2;
  3480. let caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY);
  3481. let parentElement = caretPosition.offsetNode?.parentElement;
  3482. if (parentElement && parentElement !== element) {
  3483. const elementsAtPoint = document.elementsFromPoint(caretX, midY);
  3484. const savedVisibilities = [];
  3485. for (const el of elementsAtPoint) {
  3486. if (el === element) {
  3487. break;
  3488. }
  3489. const {
  3490. style
  3491. } = el;
  3492. savedVisibilities.push([el, style.visibility]);
  3493. style.visibility = "hidden";
  3494. }
  3495. caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY);
  3496. parentElement = caretPosition.offsetNode?.parentElement;
  3497. for (const [el, visibility] of savedVisibilities) {
  3498. el.style.visibility = visibility;
  3499. }
  3500. }
  3501. if (parentElement !== element) {
  3502. if (select) {
  3503. selection.extend(element.firstChild, 0);
  3504. } else {
  3505. selection.setPosition(element.firstChild, 0);
  3506. }
  3507. return;
  3508. }
  3509. if (select) {
  3510. selection.extend(caretPosition.offsetNode, caretPosition.offset);
  3511. } else {
  3512. selection.setPosition(caretPosition.offsetNode, caretPosition.offset);
  3513. }
  3514. }
  3515. #setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX) {
  3516. if (this.#isVisible(newLineElementRect)) {
  3517. this.#setCaretPositionHelper(selection, caretX, select, newLineElement, newLineElementRect);
  3518. return;
  3519. }
  3520. this.#mainContainer.addEventListener("scrollend", this.#setCaretPositionHelper.bind(this, selection, caretX, select, newLineElement, null), {
  3521. once: true
  3522. });
  3523. newLineElement.scrollIntoView();
  3524. }
  3525. #getNodeOnNextPage(textLayer, isUp) {
  3526. while (true) {
  3527. const page = textLayer.closest(".page");
  3528. const pageNumber = parseInt(page.getAttribute("data-page-number"));
  3529. const nextPage = isUp ? pageNumber - 1 : pageNumber + 1;
  3530. textLayer = this.#viewerContainer.querySelector(`.page[data-page-number="${nextPage}"] .textLayer`);
  3531. if (!textLayer) {
  3532. return null;
  3533. }
  3534. const walker = document.createTreeWalker(textLayer, NodeFilter.SHOW_TEXT);
  3535. const node = isUp ? walker.lastChild() : walker.firstChild();
  3536. if (node) {
  3537. return node;
  3538. }
  3539. }
  3540. }
  3541. moveCaret(isUp, select) {
  3542. const selection = document.getSelection();
  3543. if (selection.rangeCount === 0) {
  3544. return;
  3545. }
  3546. const {
  3547. focusNode
  3548. } = selection;
  3549. const focusElement = focusNode.nodeType !== Node.ELEMENT_NODE ? focusNode.parentElement : focusNode;
  3550. const root = focusElement.closest(".textLayer");
  3551. if (!root) {
  3552. return;
  3553. }
  3554. const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
  3555. walker.currentNode = focusNode;
  3556. const focusRect = focusElement.getBoundingClientRect();
  3557. let newLineElement = null;
  3558. const nodeIterator = (isUp ? walker.previousSibling : walker.nextSibling).bind(walker);
  3559. while (nodeIterator()) {
  3560. const element = walker.currentNode.parentElement;
  3561. if (!this.#isOnSameLine(focusRect, element.getBoundingClientRect())) {
  3562. newLineElement = element;
  3563. break;
  3564. }
  3565. }
  3566. if (!newLineElement) {
  3567. const node = this.#getNodeOnNextPage(root, isUp);
  3568. if (!node) {
  3569. return;
  3570. }
  3571. if (select) {
  3572. const lastNode = (isUp ? walker.firstChild() : walker.lastChild()) || focusNode;
  3573. selection.extend(lastNode, isUp ? 0 : lastNode.length);
  3574. const range = document.createRange();
  3575. range.setStart(node, isUp ? node.length : 0);
  3576. range.setEnd(node, isUp ? node.length : 0);
  3577. selection.addRange(range);
  3578. return;
  3579. }
  3580. const [caretX] = this.#getCaretPosition(selection, isUp);
  3581. const {
  3582. parentElement
  3583. } = node;
  3584. this.#setCaretPosition(select, selection, parentElement, parentElement.getBoundingClientRect(), caretX);
  3585. return;
  3586. }
  3587. const [caretX, caretY] = this.#getCaretPosition(selection, isUp);
  3588. const newLineElementRect = newLineElement.getBoundingClientRect();
  3589. if (this.#isUnderOver(newLineElementRect, caretX, caretY, isUp)) {
  3590. this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX);
  3591. return;
  3592. }
  3593. while (nodeIterator()) {
  3594. const element = walker.currentNode.parentElement;
  3595. const elementRect = element.getBoundingClientRect();
  3596. if (!this.#isOnSameLine(newLineElementRect, elementRect)) {
  3597. break;
  3598. }
  3599. if (this.#isUnderOver(elementRect, caretX, caretY, isUp)) {
  3600. this.#setCaretPosition(select, selection, element, elementRect, caretX);
  3601. return;
  3602. }
  3603. }
  3604. this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX);
  3605. }
  3606. }
  3607. ;// CONCATENATED MODULE: ./web/download_manager.js
  3608. function download(blobUrl, filename) {
  3609. const a = document.createElement("a");
  3610. if (!a.click) {
  3611. throw new Error('DownloadManager: "a.click()" is not supported.');
  3612. }
  3613. a.href = blobUrl;
  3614. a.target = "_parent";
  3615. if ("download" in a) {
  3616. a.download = filename;
  3617. }
  3618. (document.body || document.documentElement).append(a);
  3619. a.click();
  3620. a.remove();
  3621. }
  3622. class DownloadManager {
  3623. #openBlobUrls = new WeakMap();
  3624. downloadData(data, filename, contentType) {
  3625. const blobUrl = URL.createObjectURL(new Blob([data], {
  3626. type: contentType
  3627. }));
  3628. download(blobUrl, filename);
  3629. }
  3630. openOrDownloadData(data, filename, dest = null) {
  3631. const isPdfData = isPdfFile(filename);
  3632. const contentType = isPdfData ? "application/pdf" : "";
  3633. if (isPdfData) {
  3634. let blobUrl = this.#openBlobUrls.get(data);
  3635. if (!blobUrl) {
  3636. blobUrl = URL.createObjectURL(new Blob([data], {
  3637. type: contentType
  3638. }));
  3639. this.#openBlobUrls.set(data, blobUrl);
  3640. }
  3641. let viewerUrl;
  3642. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  3643. if (dest) {
  3644. viewerUrl += `#${escape(dest)}`;
  3645. }
  3646. try {
  3647. window.open(viewerUrl);
  3648. return true;
  3649. } catch (ex) {
  3650. console.error(`openOrDownloadData: ${ex}`);
  3651. URL.revokeObjectURL(blobUrl);
  3652. this.#openBlobUrls.delete(data);
  3653. }
  3654. }
  3655. this.downloadData(data, filename, contentType);
  3656. return false;
  3657. }
  3658. download(data, url, filename, _options) {
  3659. let blobUrl;
  3660. if (data) {
  3661. blobUrl = URL.createObjectURL(new Blob([data], {
  3662. type: "application/pdf"
  3663. }));
  3664. } else {
  3665. if (!createValidAbsoluteUrl(url, "http://example.com")) {
  3666. console.error(`download - not a valid URL: ${url}`);
  3667. return;
  3668. }
  3669. blobUrl = url + "#pdfjs.action=download";
  3670. }
  3671. download(blobUrl, filename);
  3672. }
  3673. }
  3674. ;// CONCATENATED MODULE: ./web/overlay_manager.js
  3675. class OverlayManager {
  3676. #overlays = new WeakMap();
  3677. #active = null;
  3678. get active() {
  3679. return this.#active;
  3680. }
  3681. async register(dialog, canForceClose = false) {
  3682. if (typeof dialog !== "object") {
  3683. throw new Error("Not enough parameters.");
  3684. } else if (this.#overlays.has(dialog)) {
  3685. throw new Error("The overlay is already registered.");
  3686. }
  3687. this.#overlays.set(dialog, {
  3688. canForceClose
  3689. });
  3690. dialog.addEventListener("cancel", evt => {
  3691. this.#active = null;
  3692. });
  3693. }
  3694. async open(dialog) {
  3695. if (!this.#overlays.has(dialog)) {
  3696. throw new Error("The overlay does not exist.");
  3697. } else if (this.#active) {
  3698. if (this.#active === dialog) {
  3699. throw new Error("The overlay is already active.");
  3700. } else if (this.#overlays.get(dialog).canForceClose) {
  3701. await this.close();
  3702. } else {
  3703. throw new Error("Another overlay is currently active.");
  3704. }
  3705. }
  3706. this.#active = dialog;
  3707. dialog.showModal();
  3708. }
  3709. async close(dialog = this.#active) {
  3710. if (!this.#overlays.has(dialog)) {
  3711. throw new Error("The overlay does not exist.");
  3712. } else if (!this.#active) {
  3713. throw new Error("The overlay is currently not active.");
  3714. } else if (this.#active !== dialog) {
  3715. throw new Error("Another overlay is currently active.");
  3716. }
  3717. dialog.close();
  3718. this.#active = null;
  3719. }
  3720. }
  3721. ;// CONCATENATED MODULE: ./web/password_prompt.js
  3722. class PasswordPrompt {
  3723. #activeCapability = null;
  3724. #updateCallback = null;
  3725. #reason = null;
  3726. constructor(options, overlayManager, isViewerEmbedded = false) {
  3727. this.dialog = options.dialog;
  3728. this.label = options.label;
  3729. this.input = options.input;
  3730. this.submitButton = options.submitButton;
  3731. this.cancelButton = options.cancelButton;
  3732. this.overlayManager = overlayManager;
  3733. this._isViewerEmbedded = isViewerEmbedded;
  3734. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3735. this.cancelButton.addEventListener("click", this.close.bind(this));
  3736. this.input.addEventListener("keydown", e => {
  3737. if (e.keyCode === 13) {
  3738. this.#verify();
  3739. }
  3740. });
  3741. this.overlayManager.register(this.dialog, true);
  3742. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3743. }
  3744. async open() {
  3745. await this.#activeCapability?.promise;
  3746. this.#activeCapability = Promise.withResolvers();
  3747. try {
  3748. await this.overlayManager.open(this.dialog);
  3749. } catch (ex) {
  3750. this.#activeCapability.resolve();
  3751. throw ex;
  3752. }
  3753. const passwordIncorrect = this.#reason === PasswordResponses.INCORRECT_PASSWORD;
  3754. if (!this._isViewerEmbedded || passwordIncorrect) {
  3755. this.input.focus();
  3756. }
  3757. this.label.setAttribute("data-l10n-id", `pdfjs-password-${passwordIncorrect ? "invalid" : "label"}`);
  3758. }
  3759. async close() {
  3760. if (this.overlayManager.active === this.dialog) {
  3761. this.overlayManager.close(this.dialog);
  3762. }
  3763. }
  3764. #verify() {
  3765. const password = this.input.value;
  3766. if (password?.length > 0) {
  3767. this.#invokeCallback(password);
  3768. }
  3769. }
  3770. #cancel() {
  3771. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  3772. this.#activeCapability.resolve();
  3773. }
  3774. #invokeCallback(password) {
  3775. if (!this.#updateCallback) {
  3776. return;
  3777. }
  3778. this.close();
  3779. this.input.value = "";
  3780. this.#updateCallback(password);
  3781. this.#updateCallback = null;
  3782. }
  3783. async setUpdateCallback(updateCallback, reason) {
  3784. if (this.#activeCapability) {
  3785. await this.#activeCapability.promise;
  3786. }
  3787. this.#updateCallback = updateCallback;
  3788. this.#reason = reason;
  3789. }
  3790. }
  3791. ;// CONCATENATED MODULE: ./web/base_tree_viewer.js
  3792. const TREEITEM_OFFSET_TOP = -100;
  3793. const TREEITEM_SELECTED_CLASS = "selected";
  3794. class BaseTreeViewer {
  3795. constructor(options) {
  3796. if (this.constructor === BaseTreeViewer) {
  3797. throw new Error("Cannot initialize BaseTreeViewer.");
  3798. }
  3799. this.container = options.container;
  3800. this.eventBus = options.eventBus;
  3801. this._l10n = options.l10n;
  3802. this.reset();
  3803. }
  3804. reset() {
  3805. this._pdfDocument = null;
  3806. this._lastToggleIsShow = true;
  3807. this._currentTreeItem = null;
  3808. this.container.textContent = "";
  3809. this.container.classList.remove("treeWithDeepNesting");
  3810. }
  3811. _dispatchEvent(count) {
  3812. throw new Error("Not implemented: _dispatchEvent");
  3813. }
  3814. _bindLink(element, params) {
  3815. throw new Error("Not implemented: _bindLink");
  3816. }
  3817. _normalizeTextContent(str) {
  3818. return removeNullCharacters(str, true) || "\u2013";
  3819. }
  3820. _addToggleButton(div, hidden = false) {
  3821. const toggler = document.createElement("div");
  3822. toggler.className = "treeItemToggler";
  3823. if (hidden) {
  3824. toggler.classList.add("treeItemsHidden");
  3825. }
  3826. toggler.onclick = evt => {
  3827. evt.stopPropagation();
  3828. toggler.classList.toggle("treeItemsHidden");
  3829. if (evt.shiftKey) {
  3830. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3831. this._toggleTreeItem(div, shouldShowAll);
  3832. }
  3833. };
  3834. div.prepend(toggler);
  3835. }
  3836. _toggleTreeItem(root, show = false) {
  3837. this._l10n.pause();
  3838. this._lastToggleIsShow = show;
  3839. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3840. toggler.classList.toggle("treeItemsHidden", !show);
  3841. }
  3842. this._l10n.resume();
  3843. }
  3844. _toggleAllTreeItems() {
  3845. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3846. }
  3847. _finishRendering(fragment, count, hasAnyNesting = false) {
  3848. if (hasAnyNesting) {
  3849. this.container.classList.add("treeWithDeepNesting");
  3850. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3851. }
  3852. this._l10n.pause();
  3853. this.container.append(fragment);
  3854. this._l10n.resume();
  3855. this._dispatchEvent(count);
  3856. }
  3857. render(params) {
  3858. throw new Error("Not implemented: render");
  3859. }
  3860. _updateCurrentTreeItem(treeItem = null) {
  3861. if (this._currentTreeItem) {
  3862. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3863. this._currentTreeItem = null;
  3864. }
  3865. if (treeItem) {
  3866. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3867. this._currentTreeItem = treeItem;
  3868. }
  3869. }
  3870. _scrollToCurrentTreeItem(treeItem) {
  3871. if (!treeItem) {
  3872. return;
  3873. }
  3874. this._l10n.pause();
  3875. let currentNode = treeItem.parentNode;
  3876. while (currentNode && currentNode !== this.container) {
  3877. if (currentNode.classList.contains("treeItem")) {
  3878. const toggler = currentNode.firstElementChild;
  3879. toggler?.classList.remove("treeItemsHidden");
  3880. }
  3881. currentNode = currentNode.parentNode;
  3882. }
  3883. this._l10n.resume();
  3884. this._updateCurrentTreeItem(treeItem);
  3885. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3886. }
  3887. }
  3888. ;// CONCATENATED MODULE: ./web/pdf_attachment_viewer.js
  3889. class PDFAttachmentViewer extends BaseTreeViewer {
  3890. constructor(options) {
  3891. super(options);
  3892. this.downloadManager = options.downloadManager;
  3893. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  3894. }
  3895. reset(keepRenderedCapability = false) {
  3896. super.reset();
  3897. this._attachments = null;
  3898. if (!keepRenderedCapability) {
  3899. this._renderedCapability = Promise.withResolvers();
  3900. }
  3901. this._pendingDispatchEvent = false;
  3902. }
  3903. async _dispatchEvent(attachmentsCount) {
  3904. this._renderedCapability.resolve();
  3905. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  3906. this._pendingDispatchEvent = true;
  3907. await waitOnEventOrTimeout({
  3908. target: this.eventBus,
  3909. name: "annotationlayerrendered",
  3910. delay: 1000
  3911. });
  3912. if (!this._pendingDispatchEvent) {
  3913. return;
  3914. }
  3915. }
  3916. this._pendingDispatchEvent = false;
  3917. this.eventBus.dispatch("attachmentsloaded", {
  3918. source: this,
  3919. attachmentsCount
  3920. });
  3921. }
  3922. _bindLink(element, {
  3923. content,
  3924. description,
  3925. filename
  3926. }) {
  3927. if (description) {
  3928. element.title = description;
  3929. }
  3930. element.onclick = () => {
  3931. this.downloadManager.openOrDownloadData(content, filename);
  3932. return false;
  3933. };
  3934. }
  3935. render({
  3936. attachments,
  3937. keepRenderedCapability = false
  3938. }) {
  3939. if (this._attachments) {
  3940. this.reset(keepRenderedCapability);
  3941. }
  3942. this._attachments = attachments || null;
  3943. if (!attachments) {
  3944. this._dispatchEvent(0);
  3945. return;
  3946. }
  3947. const fragment = document.createDocumentFragment();
  3948. let attachmentsCount = 0;
  3949. for (const name in attachments) {
  3950. const item = attachments[name];
  3951. const div = document.createElement("div");
  3952. div.className = "treeItem";
  3953. const element = document.createElement("a");
  3954. this._bindLink(element, item);
  3955. element.textContent = this._normalizeTextContent(item.filename);
  3956. div.append(element);
  3957. fragment.append(div);
  3958. attachmentsCount++;
  3959. }
  3960. this._finishRendering(fragment, attachmentsCount);
  3961. }
  3962. #appendAttachment(item) {
  3963. const renderedPromise = this._renderedCapability.promise;
  3964. renderedPromise.then(() => {
  3965. if (renderedPromise !== this._renderedCapability.promise) {
  3966. return;
  3967. }
  3968. const attachments = this._attachments || Object.create(null);
  3969. for (const name in attachments) {
  3970. if (item.filename === name) {
  3971. return;
  3972. }
  3973. }
  3974. attachments[item.filename] = item;
  3975. this.render({
  3976. attachments,
  3977. keepRenderedCapability: true
  3978. });
  3979. });
  3980. }
  3981. }
  3982. ;// CONCATENATED MODULE: ./web/grab_to_pan.js
  3983. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3984. class GrabToPan {
  3985. constructor({
  3986. element
  3987. }) {
  3988. this.element = element;
  3989. this.document = element.ownerDocument;
  3990. this.activate = this.activate.bind(this);
  3991. this.deactivate = this.deactivate.bind(this);
  3992. this.toggle = this.toggle.bind(this);
  3993. this._onMouseDown = this.#onMouseDown.bind(this);
  3994. this._onMouseMove = this.#onMouseMove.bind(this);
  3995. this._endPan = this.#endPan.bind(this);
  3996. const overlay = this.overlay = document.createElement("div");
  3997. overlay.className = "grab-to-pan-grabbing";
  3998. }
  3999. activate() {
  4000. if (!this.active) {
  4001. this.active = true;
  4002. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4003. this.element.classList.add(CSS_CLASS_GRAB);
  4004. }
  4005. }
  4006. deactivate() {
  4007. if (this.active) {
  4008. this.active = false;
  4009. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  4010. this._endPan();
  4011. this.element.classList.remove(CSS_CLASS_GRAB);
  4012. }
  4013. }
  4014. toggle() {
  4015. if (this.active) {
  4016. this.deactivate();
  4017. } else {
  4018. this.activate();
  4019. }
  4020. }
  4021. ignoreTarget(node) {
  4022. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4023. }
  4024. #onMouseDown(event) {
  4025. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4026. return;
  4027. }
  4028. if (event.originalTarget) {
  4029. try {
  4030. event.originalTarget.tagName;
  4031. } catch {
  4032. return;
  4033. }
  4034. }
  4035. this.scrollLeftStart = this.element.scrollLeft;
  4036. this.scrollTopStart = this.element.scrollTop;
  4037. this.clientXStart = event.clientX;
  4038. this.clientYStart = event.clientY;
  4039. this.document.addEventListener("mousemove", this._onMouseMove, true);
  4040. this.document.addEventListener("mouseup", this._endPan, true);
  4041. this.element.addEventListener("scroll", this._endPan, true);
  4042. event.preventDefault();
  4043. event.stopPropagation();
  4044. const focusedElement = document.activeElement;
  4045. if (focusedElement && !focusedElement.contains(event.target)) {
  4046. focusedElement.blur();
  4047. }
  4048. }
  4049. #onMouseMove(event) {
  4050. this.element.removeEventListener("scroll", this._endPan, true);
  4051. if (!(event.buttons & 1)) {
  4052. this._endPan();
  4053. return;
  4054. }
  4055. const xDiff = event.clientX - this.clientXStart;
  4056. const yDiff = event.clientY - this.clientYStart;
  4057. this.element.scrollTo({
  4058. top: this.scrollTopStart - yDiff,
  4059. left: this.scrollLeftStart - xDiff,
  4060. behavior: "instant"
  4061. });
  4062. if (!this.overlay.parentNode) {
  4063. document.body.append(this.overlay);
  4064. }
  4065. }
  4066. #endPan() {
  4067. this.element.removeEventListener("scroll", this._endPan, true);
  4068. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4069. this.document.removeEventListener("mouseup", this._endPan, true);
  4070. this.overlay.remove();
  4071. }
  4072. }
  4073. ;// CONCATENATED MODULE: ./web/pdf_cursor_tools.js
  4074. class PDFCursorTools {
  4075. #active = CursorTool.SELECT;
  4076. #prevActive = null;
  4077. constructor({
  4078. container,
  4079. eventBus,
  4080. cursorToolOnLoad = CursorTool.SELECT
  4081. }) {
  4082. this.container = container;
  4083. this.eventBus = eventBus;
  4084. this.#addEventListeners();
  4085. Promise.resolve().then(() => {
  4086. this.switchTool(cursorToolOnLoad);
  4087. });
  4088. }
  4089. get activeTool() {
  4090. return this.#active;
  4091. }
  4092. switchTool(tool) {
  4093. if (this.#prevActive !== null) {
  4094. return;
  4095. }
  4096. if (tool === this.#active) {
  4097. return;
  4098. }
  4099. const disableActiveTool = () => {
  4100. switch (this.#active) {
  4101. case CursorTool.SELECT:
  4102. break;
  4103. case CursorTool.HAND:
  4104. this._handTool.deactivate();
  4105. break;
  4106. case CursorTool.ZOOM:
  4107. }
  4108. };
  4109. switch (tool) {
  4110. case CursorTool.SELECT:
  4111. disableActiveTool();
  4112. break;
  4113. case CursorTool.HAND:
  4114. disableActiveTool();
  4115. this._handTool.activate();
  4116. break;
  4117. case CursorTool.ZOOM:
  4118. default:
  4119. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4120. return;
  4121. }
  4122. this.#active = tool;
  4123. this.eventBus.dispatch("cursortoolchanged", {
  4124. source: this,
  4125. tool
  4126. });
  4127. }
  4128. #addEventListeners() {
  4129. this.eventBus._on("switchcursortool", evt => {
  4130. if (!evt.reset) {
  4131. this.switchTool(evt.tool);
  4132. } else if (this.#prevActive !== null) {
  4133. annotationEditorMode = AnnotationEditorType.NONE;
  4134. presentationModeState = PresentationModeState.NORMAL;
  4135. enableActive();
  4136. }
  4137. });
  4138. let annotationEditorMode = AnnotationEditorType.NONE,
  4139. presentationModeState = PresentationModeState.NORMAL;
  4140. const disableActive = () => {
  4141. const prevActive = this.#active;
  4142. this.switchTool(CursorTool.SELECT);
  4143. this.#prevActive ??= prevActive;
  4144. };
  4145. const enableActive = () => {
  4146. const prevActive = this.#prevActive;
  4147. if (prevActive !== null && annotationEditorMode === AnnotationEditorType.NONE && presentationModeState === PresentationModeState.NORMAL) {
  4148. this.#prevActive = null;
  4149. this.switchTool(prevActive);
  4150. }
  4151. };
  4152. this.eventBus._on("annotationeditormodechanged", ({
  4153. mode
  4154. }) => {
  4155. annotationEditorMode = mode;
  4156. if (mode === AnnotationEditorType.NONE) {
  4157. enableActive();
  4158. } else {
  4159. disableActive();
  4160. }
  4161. });
  4162. this.eventBus._on("presentationmodechanged", ({
  4163. state
  4164. }) => {
  4165. presentationModeState = state;
  4166. if (state === PresentationModeState.NORMAL) {
  4167. enableActive();
  4168. } else if (state === PresentationModeState.FULLSCREEN) {
  4169. disableActive();
  4170. }
  4171. });
  4172. }
  4173. get _handTool() {
  4174. return shadow(this, "_handTool", new GrabToPan({
  4175. element: this.container
  4176. }));
  4177. }
  4178. }
  4179. ;// CONCATENATED MODULE: ./web/pdf_document_properties.js
  4180. const DEFAULT_FIELD_CONTENT = "-";
  4181. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4182. const US_PAGE_NAMES = {
  4183. "8.5x11": "letter",
  4184. "8.5x14": "legal"
  4185. };
  4186. const METRIC_PAGE_NAMES = {
  4187. "297x420": "a-three",
  4188. "210x297": "a-four"
  4189. };
  4190. function getPageName(size, isPortrait, pageNames) {
  4191. const width = isPortrait ? size.width : size.height;
  4192. const height = isPortrait ? size.height : size.width;
  4193. return pageNames[`${width}x${height}`];
  4194. }
  4195. class PDFDocumentProperties {
  4196. #fieldData = null;
  4197. constructor({
  4198. dialog,
  4199. fields,
  4200. closeButton
  4201. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4202. this.dialog = dialog;
  4203. this.fields = fields;
  4204. this.overlayManager = overlayManager;
  4205. this.l10n = l10n;
  4206. this._fileNameLookup = fileNameLookup;
  4207. this.#reset();
  4208. closeButton.addEventListener("click", this.close.bind(this));
  4209. this.overlayManager.register(this.dialog);
  4210. eventBus._on("pagechanging", evt => {
  4211. this._currentPageNumber = evt.pageNumber;
  4212. });
  4213. eventBus._on("rotationchanging", evt => {
  4214. this._pagesRotation = evt.pagesRotation;
  4215. });
  4216. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(l10n.getLanguage());
  4217. }
  4218. async open() {
  4219. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4220. const currentPageNumber = this._currentPageNumber;
  4221. const pagesRotation = this._pagesRotation;
  4222. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4223. this.#updateUI();
  4224. return;
  4225. }
  4226. const {
  4227. info,
  4228. contentLength
  4229. } = await this.pdfDocument.getMetadata();
  4230. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4231. return this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation);
  4232. }), this.#parseLinearization(info.IsLinearized)]);
  4233. this.#fieldData = Object.freeze({
  4234. fileName,
  4235. fileSize,
  4236. title: info.Title,
  4237. author: info.Author,
  4238. subject: info.Subject,
  4239. keywords: info.Keywords,
  4240. creationDate,
  4241. modificationDate,
  4242. creator: info.Creator,
  4243. producer: info.Producer,
  4244. version: info.PDFFormatVersion,
  4245. pageCount: this.pdfDocument.numPages,
  4246. pageSize,
  4247. linearized: isLinearized,
  4248. _currentPageNumber: currentPageNumber,
  4249. _pagesRotation: pagesRotation
  4250. });
  4251. this.#updateUI();
  4252. const {
  4253. length
  4254. } = await this.pdfDocument.getDownloadInfo();
  4255. if (contentLength === length) {
  4256. return;
  4257. }
  4258. const data = Object.assign(Object.create(null), this.#fieldData);
  4259. data.fileSize = await this.#parseFileSize(length);
  4260. this.#fieldData = Object.freeze(data);
  4261. this.#updateUI();
  4262. }
  4263. async close() {
  4264. this.overlayManager.close(this.dialog);
  4265. }
  4266. setDocument(pdfDocument) {
  4267. if (this.pdfDocument) {
  4268. this.#reset();
  4269. this.#updateUI(true);
  4270. }
  4271. if (!pdfDocument) {
  4272. return;
  4273. }
  4274. this.pdfDocument = pdfDocument;
  4275. this._dataAvailableCapability.resolve();
  4276. }
  4277. #reset() {
  4278. this.pdfDocument = null;
  4279. this.#fieldData = null;
  4280. this._dataAvailableCapability = Promise.withResolvers();
  4281. this._currentPageNumber = 1;
  4282. this._pagesRotation = 0;
  4283. }
  4284. #updateUI(reset = false) {
  4285. if (reset || !this.#fieldData) {
  4286. for (const id in this.fields) {
  4287. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4288. }
  4289. return;
  4290. }
  4291. if (this.overlayManager.active !== this.dialog) {
  4292. return;
  4293. }
  4294. for (const id in this.fields) {
  4295. const content = this.#fieldData[id];
  4296. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4297. }
  4298. }
  4299. async #parseFileSize(fileSize = 0) {
  4300. const kb = fileSize / 1024,
  4301. mb = kb / 1024;
  4302. if (!kb) {
  4303. return undefined;
  4304. }
  4305. return this.l10n.get(`pdfjs-document-properties-${mb >= 1 ? "mb" : "kb"}`, {
  4306. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4307. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4308. size_b: fileSize.toLocaleString()
  4309. });
  4310. }
  4311. async #parsePageSize(pageSizeInches, pagesRotation) {
  4312. if (!pageSizeInches) {
  4313. return undefined;
  4314. }
  4315. if (pagesRotation % 180 !== 0) {
  4316. pageSizeInches = {
  4317. width: pageSizeInches.height,
  4318. height: pageSizeInches.width
  4319. };
  4320. }
  4321. const isPortrait = isPortraitOrientation(pageSizeInches);
  4322. let sizeInches = {
  4323. width: Math.round(pageSizeInches.width * 100) / 100,
  4324. height: Math.round(pageSizeInches.height * 100) / 100
  4325. };
  4326. let sizeMillimeters = {
  4327. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4328. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4329. };
  4330. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4331. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4332. const exactMillimeters = {
  4333. width: pageSizeInches.width * 25.4,
  4334. height: pageSizeInches.height * 25.4
  4335. };
  4336. const intMillimeters = {
  4337. width: Math.round(sizeMillimeters.width),
  4338. height: Math.round(sizeMillimeters.height)
  4339. };
  4340. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4341. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4342. if (rawName) {
  4343. sizeInches = {
  4344. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4345. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4346. };
  4347. sizeMillimeters = intMillimeters;
  4348. }
  4349. }
  4350. }
  4351. const [{
  4352. width,
  4353. height
  4354. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`pdfjs-document-properties-page-size-unit-${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`pdfjs-document-properties-page-size-name-${rawName}`), this.l10n.get(`pdfjs-document-properties-page-size-orientation-${isPortrait ? "portrait" : "landscape"}`)]);
  4355. return this.l10n.get(`pdfjs-document-properties-page-size-dimension-${name ? "name-" : ""}string`, {
  4356. width: width.toLocaleString(),
  4357. height: height.toLocaleString(),
  4358. unit,
  4359. name,
  4360. orientation
  4361. });
  4362. }
  4363. async #parseDate(inputDate) {
  4364. const dateObject = PDFDateString.toDateObject(inputDate);
  4365. if (!dateObject) {
  4366. return undefined;
  4367. }
  4368. return this.l10n.get("pdfjs-document-properties-date-string", {
  4369. date: dateObject.toLocaleDateString(),
  4370. time: dateObject.toLocaleTimeString()
  4371. });
  4372. }
  4373. #parseLinearization(isLinearized) {
  4374. return this.l10n.get(`pdfjs-document-properties-linearized-${isLinearized ? "yes" : "no"}`);
  4375. }
  4376. }
  4377. ;// CONCATENATED MODULE: ./web/pdf_find_utils.js
  4378. const CharacterType = {
  4379. SPACE: 0,
  4380. ALPHA_LETTER: 1,
  4381. PUNCT: 2,
  4382. HAN_LETTER: 3,
  4383. KATAKANA_LETTER: 4,
  4384. HIRAGANA_LETTER: 5,
  4385. HALFWIDTH_KATAKANA_LETTER: 6,
  4386. THAI_LETTER: 7
  4387. };
  4388. function isAlphabeticalScript(charCode) {
  4389. return charCode < 0x2e80;
  4390. }
  4391. function isAscii(charCode) {
  4392. return (charCode & 0xff80) === 0;
  4393. }
  4394. function isAsciiAlpha(charCode) {
  4395. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4396. }
  4397. function isAsciiDigit(charCode) {
  4398. return charCode >= 0x30 && charCode <= 0x39;
  4399. }
  4400. function isAsciiSpace(charCode) {
  4401. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4402. }
  4403. function isHan(charCode) {
  4404. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4405. }
  4406. function isKatakana(charCode) {
  4407. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4408. }
  4409. function isHiragana(charCode) {
  4410. return charCode >= 0x3040 && charCode <= 0x309f;
  4411. }
  4412. function isHalfwidthKatakana(charCode) {
  4413. return charCode >= 0xff60 && charCode <= 0xff9f;
  4414. }
  4415. function isThai(charCode) {
  4416. return (charCode & 0xff80) === 0x0e00;
  4417. }
  4418. function getCharacterType(charCode) {
  4419. if (isAlphabeticalScript(charCode)) {
  4420. if (isAscii(charCode)) {
  4421. if (isAsciiSpace(charCode)) {
  4422. return CharacterType.SPACE;
  4423. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4424. return CharacterType.ALPHA_LETTER;
  4425. }
  4426. return CharacterType.PUNCT;
  4427. } else if (isThai(charCode)) {
  4428. return CharacterType.THAI_LETTER;
  4429. } else if (charCode === 0xa0) {
  4430. return CharacterType.SPACE;
  4431. }
  4432. return CharacterType.ALPHA_LETTER;
  4433. }
  4434. if (isHan(charCode)) {
  4435. return CharacterType.HAN_LETTER;
  4436. } else if (isKatakana(charCode)) {
  4437. return CharacterType.KATAKANA_LETTER;
  4438. } else if (isHiragana(charCode)) {
  4439. return CharacterType.HIRAGANA_LETTER;
  4440. } else if (isHalfwidthKatakana(charCode)) {
  4441. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4442. }
  4443. return CharacterType.ALPHA_LETTER;
  4444. }
  4445. let NormalizeWithNFKC;
  4446. function getNormalizeWithNFKC() {
  4447. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  4448. return NormalizeWithNFKC;
  4449. }
  4450. ;// CONCATENATED MODULE: ./web/pdf_find_controller.js
  4451. const FindState = {
  4452. FOUND: 0,
  4453. NOT_FOUND: 1,
  4454. WRAPPED: 2,
  4455. PENDING: 3
  4456. };
  4457. const FIND_TIMEOUT = 250;
  4458. const MATCH_SCROLL_OFFSET_TOP = -50;
  4459. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4460. const CHARACTERS_TO_NORMALIZE = {
  4461. "\u2010": "-",
  4462. "\u2018": "'",
  4463. "\u2019": "'",
  4464. "\u201A": "'",
  4465. "\u201B": "'",
  4466. "\u201C": '"',
  4467. "\u201D": '"',
  4468. "\u201E": '"',
  4469. "\u201F": '"',
  4470. "\u00BC": "1/4",
  4471. "\u00BD": "1/2",
  4472. "\u00BE": "3/4"
  4473. };
  4474. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  4475. let DIACRITICS_EXCEPTION_STR;
  4476. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4477. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4478. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4479. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4480. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4481. const SYLLABLES_LENGTHS = new Map();
  4482. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4483. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4484. let noSyllablesRegExp = null;
  4485. let withSyllablesRegExp = null;
  4486. function normalize(text) {
  4487. const syllablePositions = [];
  4488. let m;
  4489. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4490. let {
  4491. index
  4492. } = m;
  4493. for (const char of m[0]) {
  4494. let len = SYLLABLES_LENGTHS.get(char);
  4495. if (!len) {
  4496. len = char.normalize("NFD").length;
  4497. SYLLABLES_LENGTHS.set(char, len);
  4498. }
  4499. syllablePositions.push([len, index++]);
  4500. }
  4501. }
  4502. let normalizationRegex;
  4503. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4504. normalizationRegex = noSyllablesRegExp;
  4505. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4506. normalizationRegex = withSyllablesRegExp;
  4507. } else {
  4508. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4509. const toNormalizeWithNFKC = getNormalizeWithNFKC();
  4510. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4511. const HKDiacritics = "(?:\u3099|\u309A)";
  4512. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4513. if (syllablePositions.length === 0) {
  4514. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4515. } else {
  4516. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4517. }
  4518. }
  4519. const rawDiacriticsPositions = [];
  4520. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4521. rawDiacriticsPositions.push([m[0].length, m.index]);
  4522. }
  4523. let normalized = text.normalize("NFD");
  4524. const positions = [[0, 0]];
  4525. let rawDiacriticsIndex = 0;
  4526. let syllableIndex = 0;
  4527. let shift = 0;
  4528. let shiftOrigin = 0;
  4529. let eol = 0;
  4530. let hasDiacritics = false;
  4531. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  4532. i -= shiftOrigin;
  4533. if (p1) {
  4534. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4535. const jj = replacement.length;
  4536. for (let j = 1; j < jj; j++) {
  4537. positions.push([i - shift + j, shift - j]);
  4538. }
  4539. shift -= jj - 1;
  4540. return replacement;
  4541. }
  4542. if (p2) {
  4543. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4544. if (!replacement) {
  4545. replacement = p2.normalize("NFKC");
  4546. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4547. }
  4548. const jj = replacement.length;
  4549. for (let j = 1; j < jj; j++) {
  4550. positions.push([i - shift + j, shift - j]);
  4551. }
  4552. shift -= jj - 1;
  4553. return replacement;
  4554. }
  4555. if (p3) {
  4556. hasDiacritics = true;
  4557. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4558. ++rawDiacriticsIndex;
  4559. } else {
  4560. positions.push([i - 1 - shift + 1, shift - 1]);
  4561. shift -= 1;
  4562. shiftOrigin += 1;
  4563. }
  4564. positions.push([i - shift + 1, shift]);
  4565. shiftOrigin += 1;
  4566. eol += 1;
  4567. return p3.charAt(0);
  4568. }
  4569. if (p4) {
  4570. const hasTrailingDashEOL = p4.endsWith("\n");
  4571. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  4572. hasDiacritics = true;
  4573. let jj = len;
  4574. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4575. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4576. ++rawDiacriticsIndex;
  4577. }
  4578. for (let j = 1; j <= jj; j++) {
  4579. positions.push([i - 1 - shift + j, shift - j]);
  4580. }
  4581. shift -= jj;
  4582. shiftOrigin += jj;
  4583. if (hasTrailingDashEOL) {
  4584. i += len - 1;
  4585. positions.push([i - shift + 1, 1 + shift]);
  4586. shift += 1;
  4587. shiftOrigin += 1;
  4588. eol += 1;
  4589. return p4.slice(0, len);
  4590. }
  4591. return p4;
  4592. }
  4593. if (p5) {
  4594. const len = p5.length - 2;
  4595. positions.push([i - shift + len, 1 + shift]);
  4596. shift += 1;
  4597. shiftOrigin += 1;
  4598. eol += 1;
  4599. return p5.slice(0, -2);
  4600. }
  4601. if (p6) {
  4602. const len = p6.length - 1;
  4603. positions.push([i - shift + len, shift]);
  4604. shiftOrigin += 1;
  4605. eol += 1;
  4606. return p6.slice(0, -1);
  4607. }
  4608. if (p7) {
  4609. positions.push([i - shift + 1, shift - 1]);
  4610. shift -= 1;
  4611. shiftOrigin += 1;
  4612. eol += 1;
  4613. return " ";
  4614. }
  4615. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4616. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4617. ++syllableIndex;
  4618. for (let j = 1; j <= newCharLen; j++) {
  4619. positions.push([i - (shift - j), shift - j]);
  4620. }
  4621. shift -= newCharLen;
  4622. shiftOrigin += newCharLen;
  4623. }
  4624. return p8;
  4625. });
  4626. positions.push([normalized.length, shift]);
  4627. return [normalized, positions, hasDiacritics];
  4628. }
  4629. function getOriginalIndex(diffs, pos, len) {
  4630. if (!diffs) {
  4631. return [pos, len];
  4632. }
  4633. const start = pos;
  4634. const end = pos + len - 1;
  4635. let i = binarySearchFirstItem(diffs, x => x[0] >= start);
  4636. if (diffs[i][0] > start) {
  4637. --i;
  4638. }
  4639. let j = binarySearchFirstItem(diffs, x => x[0] >= end, i);
  4640. if (diffs[j][0] > end) {
  4641. --j;
  4642. }
  4643. const oldStart = start + diffs[i][1];
  4644. const oldEnd = end + diffs[j][1];
  4645. const oldLen = oldEnd + 1 - oldStart;
  4646. return [oldStart, oldLen];
  4647. }
  4648. class PDFFindController {
  4649. #state = null;
  4650. #updateMatchesCountOnProgress = true;
  4651. #visitedPagesCount = 0;
  4652. constructor({
  4653. linkService,
  4654. eventBus,
  4655. updateMatchesCountOnProgress = true
  4656. }) {
  4657. this._linkService = linkService;
  4658. this._eventBus = eventBus;
  4659. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  4660. this.onIsPageVisible = null;
  4661. this.#reset();
  4662. eventBus._on("find", this.#onFind.bind(this));
  4663. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4664. }
  4665. get highlightMatches() {
  4666. return this._highlightMatches;
  4667. }
  4668. get pageMatches() {
  4669. return this._pageMatches;
  4670. }
  4671. get pageMatchesLength() {
  4672. return this._pageMatchesLength;
  4673. }
  4674. get selected() {
  4675. return this._selected;
  4676. }
  4677. get state() {
  4678. return this.#state;
  4679. }
  4680. setDocument(pdfDocument) {
  4681. if (this._pdfDocument) {
  4682. this.#reset();
  4683. }
  4684. if (!pdfDocument) {
  4685. return;
  4686. }
  4687. this._pdfDocument = pdfDocument;
  4688. this._firstPageCapability.resolve();
  4689. }
  4690. #onFind(state) {
  4691. if (!state) {
  4692. return;
  4693. }
  4694. const pdfDocument = this._pdfDocument;
  4695. const {
  4696. type
  4697. } = state;
  4698. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  4699. this._dirtyMatch = true;
  4700. }
  4701. this.#state = state;
  4702. if (type !== "highlightallchange") {
  4703. this.#updateUIState(FindState.PENDING);
  4704. }
  4705. this._firstPageCapability.promise.then(() => {
  4706. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4707. return;
  4708. }
  4709. this.#extractText();
  4710. const findbarClosed = !this._highlightMatches;
  4711. const pendingTimeout = !!this._findTimeout;
  4712. if (this._findTimeout) {
  4713. clearTimeout(this._findTimeout);
  4714. this._findTimeout = null;
  4715. }
  4716. if (!type) {
  4717. this._findTimeout = setTimeout(() => {
  4718. this.#nextMatch();
  4719. this._findTimeout = null;
  4720. }, FIND_TIMEOUT);
  4721. } else if (this._dirtyMatch) {
  4722. this.#nextMatch();
  4723. } else if (type === "again") {
  4724. this.#nextMatch();
  4725. if (findbarClosed && this.#state.highlightAll) {
  4726. this.#updateAllPages();
  4727. }
  4728. } else if (type === "highlightallchange") {
  4729. if (pendingTimeout) {
  4730. this.#nextMatch();
  4731. } else {
  4732. this._highlightMatches = true;
  4733. }
  4734. this.#updateAllPages();
  4735. } else {
  4736. this.#nextMatch();
  4737. }
  4738. });
  4739. }
  4740. scrollMatchIntoView({
  4741. element = null,
  4742. selectedLeft = 0,
  4743. pageIndex = -1,
  4744. matchIndex = -1
  4745. }) {
  4746. if (!this._scrollMatches || !element) {
  4747. return;
  4748. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4749. return;
  4750. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4751. return;
  4752. }
  4753. this._scrollMatches = false;
  4754. const spot = {
  4755. top: MATCH_SCROLL_OFFSET_TOP,
  4756. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4757. };
  4758. scrollIntoView(element, spot, true);
  4759. }
  4760. #reset() {
  4761. this._highlightMatches = false;
  4762. this._scrollMatches = false;
  4763. this._pdfDocument = null;
  4764. this._pageMatches = [];
  4765. this._pageMatchesLength = [];
  4766. this.#visitedPagesCount = 0;
  4767. this.#state = null;
  4768. this._selected = {
  4769. pageIdx: -1,
  4770. matchIdx: -1
  4771. };
  4772. this._offset = {
  4773. pageIdx: null,
  4774. matchIdx: null,
  4775. wrapped: false
  4776. };
  4777. this._extractTextPromises = [];
  4778. this._pageContents = [];
  4779. this._pageDiffs = [];
  4780. this._hasDiacritics = [];
  4781. this._matchesCountTotal = 0;
  4782. this._pagesToSearch = null;
  4783. this._pendingFindMatches = new Set();
  4784. this._resumePageIdx = null;
  4785. this._dirtyMatch = false;
  4786. clearTimeout(this._findTimeout);
  4787. this._findTimeout = null;
  4788. this._firstPageCapability = Promise.withResolvers();
  4789. }
  4790. get #query() {
  4791. const {
  4792. query
  4793. } = this.#state;
  4794. if (typeof query === "string") {
  4795. if (query !== this._rawQuery) {
  4796. this._rawQuery = query;
  4797. [this._normalizedQuery] = normalize(query);
  4798. }
  4799. return this._normalizedQuery;
  4800. }
  4801. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  4802. }
  4803. #shouldDirtyMatch(state) {
  4804. const newQuery = state.query,
  4805. prevQuery = this.#state.query;
  4806. const newType = typeof newQuery,
  4807. prevType = typeof prevQuery;
  4808. if (newType !== prevType) {
  4809. return true;
  4810. }
  4811. if (newType === "string") {
  4812. if (newQuery !== prevQuery) {
  4813. return true;
  4814. }
  4815. } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  4816. return true;
  4817. }
  4818. switch (state.type) {
  4819. case "again":
  4820. const pageNumber = this._selected.pageIdx + 1;
  4821. const linkService = this._linkService;
  4822. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  4823. case "highlightallchange":
  4824. return false;
  4825. }
  4826. return true;
  4827. }
  4828. #isEntireWord(content, startIdx, length) {
  4829. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4830. if (match) {
  4831. const first = content.charCodeAt(startIdx);
  4832. const limit = match[1].charCodeAt(0);
  4833. if (getCharacterType(first) === getCharacterType(limit)) {
  4834. return false;
  4835. }
  4836. }
  4837. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4838. if (match) {
  4839. const last = content.charCodeAt(startIdx + length - 1);
  4840. const limit = match[1].charCodeAt(0);
  4841. if (getCharacterType(last) === getCharacterType(limit)) {
  4842. return false;
  4843. }
  4844. }
  4845. return true;
  4846. }
  4847. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4848. const matches = this._pageMatches[pageIndex] = [];
  4849. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  4850. if (!query) {
  4851. return;
  4852. }
  4853. const diffs = this._pageDiffs[pageIndex];
  4854. let match;
  4855. while ((match = query.exec(pageContent)) !== null) {
  4856. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  4857. continue;
  4858. }
  4859. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  4860. if (matchLen) {
  4861. matches.push(matchPos);
  4862. matchesLength.push(matchLen);
  4863. }
  4864. }
  4865. }
  4866. #convertToRegExpString(query, hasDiacritics) {
  4867. const {
  4868. matchDiacritics
  4869. } = this.#state;
  4870. let isUnicode = false;
  4871. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  4872. if (p1) {
  4873. return `[ ]*\\${p1}[ ]*`;
  4874. }
  4875. if (p2) {
  4876. return `[ ]*${p2}[ ]*`;
  4877. }
  4878. if (p3) {
  4879. return "[ ]+";
  4880. }
  4881. if (matchDiacritics) {
  4882. return p4 || p5;
  4883. }
  4884. if (p4) {
  4885. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  4886. }
  4887. if (hasDiacritics) {
  4888. isUnicode = true;
  4889. return `${p5}\\p{M}*`;
  4890. }
  4891. return p5;
  4892. });
  4893. const trailingSpaces = "[ ]*";
  4894. if (query.endsWith(trailingSpaces)) {
  4895. query = query.slice(0, query.length - trailingSpaces.length);
  4896. }
  4897. if (matchDiacritics) {
  4898. if (hasDiacritics) {
  4899. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  4900. isUnicode = true;
  4901. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  4902. }
  4903. }
  4904. return [isUnicode, query];
  4905. }
  4906. #calculateMatch(pageIndex) {
  4907. let query = this.#query;
  4908. if (query.length === 0) {
  4909. return;
  4910. }
  4911. const {
  4912. caseSensitive,
  4913. entireWord
  4914. } = this.#state;
  4915. const pageContent = this._pageContents[pageIndex];
  4916. const hasDiacritics = this._hasDiacritics[pageIndex];
  4917. let isUnicode = false;
  4918. if (typeof query === "string") {
  4919. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  4920. } else {
  4921. query = query.sort().reverse().map(q => {
  4922. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  4923. isUnicode ||= isUnicodePart;
  4924. return `(${queryPart})`;
  4925. }).join("|");
  4926. }
  4927. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  4928. query = query ? new RegExp(query, flags) : null;
  4929. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  4930. if (this.#state.highlightAll) {
  4931. this.#updatePage(pageIndex);
  4932. }
  4933. if (this._resumePageIdx === pageIndex) {
  4934. this._resumePageIdx = null;
  4935. this.#nextPageMatch();
  4936. }
  4937. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4938. this._matchesCountTotal += pageMatchesCount;
  4939. if (this.#updateMatchesCountOnProgress) {
  4940. if (pageMatchesCount > 0) {
  4941. this.#updateUIResultsCount();
  4942. }
  4943. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  4944. this.#updateUIResultsCount();
  4945. }
  4946. }
  4947. #extractText() {
  4948. if (this._extractTextPromises.length > 0) {
  4949. return;
  4950. }
  4951. let deferred = Promise.resolve();
  4952. const textOptions = {
  4953. disableNormalization: true
  4954. };
  4955. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4956. const {
  4957. promise,
  4958. resolve
  4959. } = Promise.withResolvers();
  4960. this._extractTextPromises[i] = promise;
  4961. deferred = deferred.then(() => {
  4962. return this._pdfDocument.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => {
  4963. const strBuf = [];
  4964. for (const textItem of textContent.items) {
  4965. strBuf.push(textItem.str);
  4966. if (textItem.hasEOL) {
  4967. strBuf.push("\n");
  4968. }
  4969. }
  4970. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  4971. resolve();
  4972. }, reason => {
  4973. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4974. this._pageContents[i] = "";
  4975. this._pageDiffs[i] = null;
  4976. this._hasDiacritics[i] = false;
  4977. resolve();
  4978. });
  4979. });
  4980. }
  4981. }
  4982. #updatePage(index) {
  4983. if (this._scrollMatches && this._selected.pageIdx === index) {
  4984. this._linkService.page = index + 1;
  4985. }
  4986. this._eventBus.dispatch("updatetextlayermatches", {
  4987. source: this,
  4988. pageIndex: index
  4989. });
  4990. }
  4991. #updateAllPages() {
  4992. this._eventBus.dispatch("updatetextlayermatches", {
  4993. source: this,
  4994. pageIndex: -1
  4995. });
  4996. }
  4997. #nextMatch() {
  4998. const previous = this.#state.findPrevious;
  4999. const currentPageIndex = this._linkService.page - 1;
  5000. const numPages = this._linkService.pagesCount;
  5001. this._highlightMatches = true;
  5002. if (this._dirtyMatch) {
  5003. this._dirtyMatch = false;
  5004. this._selected.pageIdx = this._selected.matchIdx = -1;
  5005. this._offset.pageIdx = currentPageIndex;
  5006. this._offset.matchIdx = null;
  5007. this._offset.wrapped = false;
  5008. this._resumePageIdx = null;
  5009. this._pageMatches.length = 0;
  5010. this._pageMatchesLength.length = 0;
  5011. this.#visitedPagesCount = 0;
  5012. this._matchesCountTotal = 0;
  5013. this.#updateAllPages();
  5014. for (let i = 0; i < numPages; i++) {
  5015. if (this._pendingFindMatches.has(i)) {
  5016. continue;
  5017. }
  5018. this._pendingFindMatches.add(i);
  5019. this._extractTextPromises[i].then(() => {
  5020. this._pendingFindMatches.delete(i);
  5021. this.#calculateMatch(i);
  5022. });
  5023. }
  5024. }
  5025. const query = this.#query;
  5026. if (query.length === 0) {
  5027. this.#updateUIState(FindState.FOUND);
  5028. return;
  5029. }
  5030. if (this._resumePageIdx) {
  5031. return;
  5032. }
  5033. const offset = this._offset;
  5034. this._pagesToSearch = numPages;
  5035. if (offset.matchIdx !== null) {
  5036. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5037. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5038. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5039. this.#updateMatch(true);
  5040. return;
  5041. }
  5042. this.#advanceOffsetPage(previous);
  5043. }
  5044. this.#nextPageMatch();
  5045. }
  5046. #matchesReady(matches) {
  5047. const offset = this._offset;
  5048. const numMatches = matches.length;
  5049. const previous = this.#state.findPrevious;
  5050. if (numMatches) {
  5051. offset.matchIdx = previous ? numMatches - 1 : 0;
  5052. this.#updateMatch(true);
  5053. return true;
  5054. }
  5055. this.#advanceOffsetPage(previous);
  5056. if (offset.wrapped) {
  5057. offset.matchIdx = null;
  5058. if (this._pagesToSearch < 0) {
  5059. this.#updateMatch(false);
  5060. return true;
  5061. }
  5062. }
  5063. return false;
  5064. }
  5065. #nextPageMatch() {
  5066. if (this._resumePageIdx !== null) {
  5067. console.error("There can only be one pending page.");
  5068. }
  5069. let matches = null;
  5070. do {
  5071. const pageIdx = this._offset.pageIdx;
  5072. matches = this._pageMatches[pageIdx];
  5073. if (!matches) {
  5074. this._resumePageIdx = pageIdx;
  5075. break;
  5076. }
  5077. } while (!this.#matchesReady(matches));
  5078. }
  5079. #advanceOffsetPage(previous) {
  5080. const offset = this._offset;
  5081. const numPages = this._linkService.pagesCount;
  5082. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5083. offset.matchIdx = null;
  5084. this._pagesToSearch--;
  5085. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5086. offset.pageIdx = previous ? numPages - 1 : 0;
  5087. offset.wrapped = true;
  5088. }
  5089. }
  5090. #updateMatch(found = false) {
  5091. let state = FindState.NOT_FOUND;
  5092. const wrapped = this._offset.wrapped;
  5093. this._offset.wrapped = false;
  5094. if (found) {
  5095. const previousPage = this._selected.pageIdx;
  5096. this._selected.pageIdx = this._offset.pageIdx;
  5097. this._selected.matchIdx = this._offset.matchIdx;
  5098. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5099. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5100. this.#updatePage(previousPage);
  5101. }
  5102. }
  5103. this.#updateUIState(state, this.#state.findPrevious);
  5104. if (this._selected.pageIdx !== -1) {
  5105. this._scrollMatches = true;
  5106. this.#updatePage(this._selected.pageIdx);
  5107. }
  5108. }
  5109. #onFindBarClose(evt) {
  5110. const pdfDocument = this._pdfDocument;
  5111. this._firstPageCapability.promise.then(() => {
  5112. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5113. return;
  5114. }
  5115. if (this._findTimeout) {
  5116. clearTimeout(this._findTimeout);
  5117. this._findTimeout = null;
  5118. }
  5119. if (this._resumePageIdx) {
  5120. this._resumePageIdx = null;
  5121. this._dirtyMatch = true;
  5122. }
  5123. this.#updateUIState(FindState.FOUND);
  5124. this._highlightMatches = false;
  5125. this.#updateAllPages();
  5126. });
  5127. }
  5128. #requestMatchesCount() {
  5129. const {
  5130. pageIdx,
  5131. matchIdx
  5132. } = this._selected;
  5133. let current = 0,
  5134. total = this._matchesCountTotal;
  5135. if (matchIdx !== -1) {
  5136. for (let i = 0; i < pageIdx; i++) {
  5137. current += this._pageMatches[i]?.length || 0;
  5138. }
  5139. current += matchIdx + 1;
  5140. }
  5141. if (current < 1 || current > total) {
  5142. current = total = 0;
  5143. }
  5144. return {
  5145. current,
  5146. total
  5147. };
  5148. }
  5149. #updateUIResultsCount() {
  5150. this._eventBus.dispatch("updatefindmatchescount", {
  5151. source: this,
  5152. matchesCount: this.#requestMatchesCount()
  5153. });
  5154. }
  5155. #updateUIState(state, previous = false) {
  5156. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5157. return;
  5158. }
  5159. this._eventBus.dispatch("updatefindcontrolstate", {
  5160. source: this,
  5161. state,
  5162. previous,
  5163. entireWord: this.#state?.entireWord ?? null,
  5164. matchesCount: this.#requestMatchesCount(),
  5165. rawQuery: this.#state?.query ?? null
  5166. });
  5167. }
  5168. }
  5169. ;// CONCATENATED MODULE: ./web/pdf_find_bar.js
  5170. const MATCHES_COUNT_LIMIT = 1000;
  5171. class PDFFindBar {
  5172. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  5173. constructor(options, eventBus) {
  5174. this.opened = false;
  5175. this.bar = options.bar;
  5176. this.toggleButton = options.toggleButton;
  5177. this.findField = options.findField;
  5178. this.highlightAll = options.highlightAllCheckbox;
  5179. this.caseSensitive = options.caseSensitiveCheckbox;
  5180. this.matchDiacritics = options.matchDiacriticsCheckbox;
  5181. this.entireWord = options.entireWordCheckbox;
  5182. this.findMsg = options.findMsg;
  5183. this.findResultsCount = options.findResultsCount;
  5184. this.findPreviousButton = options.findPreviousButton;
  5185. this.findNextButton = options.findNextButton;
  5186. this.eventBus = eventBus;
  5187. this.toggleButton.addEventListener("click", () => {
  5188. this.toggle();
  5189. });
  5190. this.findField.addEventListener("input", () => {
  5191. this.dispatchEvent("");
  5192. });
  5193. this.bar.addEventListener("keydown", e => {
  5194. switch (e.keyCode) {
  5195. case 13:
  5196. if (e.target === this.findField) {
  5197. this.dispatchEvent("again", e.shiftKey);
  5198. }
  5199. break;
  5200. case 27:
  5201. this.close();
  5202. break;
  5203. }
  5204. });
  5205. this.findPreviousButton.addEventListener("click", () => {
  5206. this.dispatchEvent("again", true);
  5207. });
  5208. this.findNextButton.addEventListener("click", () => {
  5209. this.dispatchEvent("again", false);
  5210. });
  5211. this.highlightAll.addEventListener("click", () => {
  5212. this.dispatchEvent("highlightallchange");
  5213. });
  5214. this.caseSensitive.addEventListener("click", () => {
  5215. this.dispatchEvent("casesensitivitychange");
  5216. });
  5217. this.entireWord.addEventListener("click", () => {
  5218. this.dispatchEvent("entirewordchange");
  5219. });
  5220. this.matchDiacritics.addEventListener("click", () => {
  5221. this.dispatchEvent("diacriticmatchingchange");
  5222. });
  5223. }
  5224. reset() {
  5225. this.updateUIState();
  5226. }
  5227. dispatchEvent(type, findPrev = false) {
  5228. this.eventBus.dispatch("find", {
  5229. source: this,
  5230. type,
  5231. query: this.findField.value,
  5232. caseSensitive: this.caseSensitive.checked,
  5233. entireWord: this.entireWord.checked,
  5234. highlightAll: this.highlightAll.checked,
  5235. findPrevious: findPrev,
  5236. matchDiacritics: this.matchDiacritics.checked
  5237. });
  5238. }
  5239. updateUIState(state, previous, matchesCount) {
  5240. const {
  5241. findField,
  5242. findMsg
  5243. } = this;
  5244. let findMsgId = "",
  5245. status = "";
  5246. switch (state) {
  5247. case FindState.FOUND:
  5248. break;
  5249. case FindState.PENDING:
  5250. status = "pending";
  5251. break;
  5252. case FindState.NOT_FOUND:
  5253. findMsgId = "pdfjs-find-not-found";
  5254. status = "notFound";
  5255. break;
  5256. case FindState.WRAPPED:
  5257. findMsgId = `pdfjs-find-reached-${previous ? "top" : "bottom"}`;
  5258. break;
  5259. }
  5260. findField.setAttribute("data-status", status);
  5261. findField.setAttribute("aria-invalid", state === FindState.NOT_FOUND);
  5262. findMsg.setAttribute("data-status", status);
  5263. if (findMsgId) {
  5264. findMsg.setAttribute("data-l10n-id", findMsgId);
  5265. } else {
  5266. findMsg.removeAttribute("data-l10n-id");
  5267. findMsg.textContent = "";
  5268. }
  5269. this.updateResultsCount(matchesCount);
  5270. }
  5271. updateResultsCount({
  5272. current = 0,
  5273. total = 0
  5274. } = {}) {
  5275. const {
  5276. findResultsCount
  5277. } = this;
  5278. if (total > 0) {
  5279. const limit = MATCHES_COUNT_LIMIT;
  5280. findResultsCount.setAttribute("data-l10n-id", `pdfjs-find-match-count${total > limit ? "-limit" : ""}`);
  5281. findResultsCount.setAttribute("data-l10n-args", JSON.stringify({
  5282. limit,
  5283. current,
  5284. total
  5285. }));
  5286. } else {
  5287. findResultsCount.removeAttribute("data-l10n-id");
  5288. findResultsCount.textContent = "";
  5289. }
  5290. }
  5291. open() {
  5292. if (!this.opened) {
  5293. this.#resizeObserver.observe(this.bar.parentNode);
  5294. this.#resizeObserver.observe(this.bar);
  5295. this.opened = true;
  5296. toggleExpandedBtn(this.toggleButton, true, this.bar);
  5297. }
  5298. this.findField.select();
  5299. this.findField.focus();
  5300. }
  5301. close() {
  5302. if (!this.opened) {
  5303. return;
  5304. }
  5305. this.#resizeObserver.disconnect();
  5306. this.opened = false;
  5307. toggleExpandedBtn(this.toggleButton, false, this.bar);
  5308. this.eventBus.dispatch("findbarclose", {
  5309. source: this
  5310. });
  5311. }
  5312. toggle() {
  5313. if (this.opened) {
  5314. this.close();
  5315. } else {
  5316. this.open();
  5317. }
  5318. }
  5319. #resizeObserverCallback(entries) {
  5320. const {
  5321. bar
  5322. } = this;
  5323. bar.classList.remove("wrapContainers");
  5324. const findbarHeight = bar.clientHeight;
  5325. const inputContainerHeight = bar.firstElementChild.clientHeight;
  5326. if (findbarHeight > inputContainerHeight) {
  5327. bar.classList.add("wrapContainers");
  5328. }
  5329. }
  5330. }
  5331. ;// CONCATENATED MODULE: ./web/pdf_history.js
  5332. const HASH_CHANGE_TIMEOUT = 1000;
  5333. const POSITION_UPDATED_THRESHOLD = 50;
  5334. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5335. function getCurrentHash() {
  5336. return document.location.hash;
  5337. }
  5338. class PDFHistory {
  5339. #eventAbortController = null;
  5340. constructor({
  5341. linkService,
  5342. eventBus
  5343. }) {
  5344. this.linkService = linkService;
  5345. this.eventBus = eventBus;
  5346. this._initialized = false;
  5347. this._fingerprint = "";
  5348. this.reset();
  5349. this.eventBus._on("pagesinit", () => {
  5350. this._isPagesLoaded = false;
  5351. this.eventBus._on("pagesloaded", evt => {
  5352. this._isPagesLoaded = !!evt.pagesCount;
  5353. }, {
  5354. once: true
  5355. });
  5356. });
  5357. }
  5358. initialize({
  5359. fingerprint,
  5360. resetHistory = false,
  5361. updateUrl = false
  5362. }) {
  5363. if (!fingerprint || typeof fingerprint !== "string") {
  5364. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5365. return;
  5366. }
  5367. if (this._initialized) {
  5368. this.reset();
  5369. }
  5370. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5371. this._fingerprint = fingerprint;
  5372. this._updateUrl = updateUrl === true;
  5373. this._initialized = true;
  5374. this.#bindEvents();
  5375. const state = window.history.state;
  5376. this._popStateInProgress = false;
  5377. this._blockHashChange = 0;
  5378. this._currentHash = getCurrentHash();
  5379. this._numPositionUpdates = 0;
  5380. this._uid = this._maxUid = 0;
  5381. this._destination = null;
  5382. this._position = null;
  5383. if (!this.#isValidState(state, true) || resetHistory) {
  5384. const {
  5385. hash,
  5386. page,
  5387. rotation
  5388. } = this.#parseCurrentHash(true);
  5389. if (!hash || reInitialized || resetHistory) {
  5390. this.#pushOrReplaceState(null, true);
  5391. return;
  5392. }
  5393. this.#pushOrReplaceState({
  5394. hash,
  5395. page,
  5396. rotation
  5397. }, true);
  5398. return;
  5399. }
  5400. const destination = state.destination;
  5401. this.#updateInternalState(destination, state.uid, true);
  5402. if (destination.rotation !== undefined) {
  5403. this._initialRotation = destination.rotation;
  5404. }
  5405. if (destination.dest) {
  5406. this._initialBookmark = JSON.stringify(destination.dest);
  5407. this._destination.page = null;
  5408. } else if (destination.hash) {
  5409. this._initialBookmark = destination.hash;
  5410. } else if (destination.page) {
  5411. this._initialBookmark = `page=${destination.page}`;
  5412. }
  5413. }
  5414. reset() {
  5415. if (this._initialized) {
  5416. this.#pageHide();
  5417. this._initialized = false;
  5418. this.#unbindEvents();
  5419. }
  5420. if (this._updateViewareaTimeout) {
  5421. clearTimeout(this._updateViewareaTimeout);
  5422. this._updateViewareaTimeout = null;
  5423. }
  5424. this._initialBookmark = null;
  5425. this._initialRotation = null;
  5426. }
  5427. push({
  5428. namedDest = null,
  5429. explicitDest,
  5430. pageNumber
  5431. }) {
  5432. if (!this._initialized) {
  5433. return;
  5434. }
  5435. if (namedDest && typeof namedDest !== "string") {
  5436. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5437. return;
  5438. } else if (!Array.isArray(explicitDest)) {
  5439. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5440. return;
  5441. } else if (!this.#isValidPage(pageNumber)) {
  5442. if (pageNumber !== null || this._destination) {
  5443. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5444. return;
  5445. }
  5446. }
  5447. const hash = namedDest || JSON.stringify(explicitDest);
  5448. if (!hash) {
  5449. return;
  5450. }
  5451. let forceReplace = false;
  5452. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5453. if (this._destination.page) {
  5454. return;
  5455. }
  5456. forceReplace = true;
  5457. }
  5458. if (this._popStateInProgress && !forceReplace) {
  5459. return;
  5460. }
  5461. this.#pushOrReplaceState({
  5462. dest: explicitDest,
  5463. hash,
  5464. page: pageNumber,
  5465. rotation: this.linkService.rotation
  5466. }, forceReplace);
  5467. if (!this._popStateInProgress) {
  5468. this._popStateInProgress = true;
  5469. Promise.resolve().then(() => {
  5470. this._popStateInProgress = false;
  5471. });
  5472. }
  5473. }
  5474. pushPage(pageNumber) {
  5475. if (!this._initialized) {
  5476. return;
  5477. }
  5478. if (!this.#isValidPage(pageNumber)) {
  5479. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5480. return;
  5481. }
  5482. if (this._destination?.page === pageNumber) {
  5483. return;
  5484. }
  5485. if (this._popStateInProgress) {
  5486. return;
  5487. }
  5488. this.#pushOrReplaceState({
  5489. dest: null,
  5490. hash: `page=${pageNumber}`,
  5491. page: pageNumber,
  5492. rotation: this.linkService.rotation
  5493. });
  5494. if (!this._popStateInProgress) {
  5495. this._popStateInProgress = true;
  5496. Promise.resolve().then(() => {
  5497. this._popStateInProgress = false;
  5498. });
  5499. }
  5500. }
  5501. pushCurrentPosition() {
  5502. if (!this._initialized || this._popStateInProgress) {
  5503. return;
  5504. }
  5505. this.#tryPushCurrentPosition();
  5506. }
  5507. back() {
  5508. if (!this._initialized || this._popStateInProgress) {
  5509. return;
  5510. }
  5511. const state = window.history.state;
  5512. if (this.#isValidState(state) && state.uid > 0) {
  5513. window.history.back();
  5514. }
  5515. }
  5516. forward() {
  5517. if (!this._initialized || this._popStateInProgress) {
  5518. return;
  5519. }
  5520. const state = window.history.state;
  5521. if (this.#isValidState(state) && state.uid < this._maxUid) {
  5522. window.history.forward();
  5523. }
  5524. }
  5525. get popStateInProgress() {
  5526. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5527. }
  5528. get initialBookmark() {
  5529. return this._initialized ? this._initialBookmark : null;
  5530. }
  5531. get initialRotation() {
  5532. return this._initialized ? this._initialRotation : null;
  5533. }
  5534. #pushOrReplaceState(destination, forceReplace = false) {
  5535. const shouldReplace = forceReplace || !this._destination;
  5536. const newState = {
  5537. fingerprint: this._fingerprint,
  5538. uid: shouldReplace ? this._uid : this._uid + 1,
  5539. destination
  5540. };
  5541. this.#updateInternalState(destination, newState.uid);
  5542. let newUrl;
  5543. if (this._updateUrl && destination?.hash) {
  5544. const baseUrl = document.location.href.split("#", 1)[0];
  5545. if (!baseUrl.startsWith("file://")) {
  5546. newUrl = `${baseUrl}#${destination.hash}`;
  5547. }
  5548. }
  5549. if (shouldReplace) {
  5550. window.history.replaceState(newState, "", newUrl);
  5551. } else {
  5552. window.history.pushState(newState, "", newUrl);
  5553. }
  5554. }
  5555. #tryPushCurrentPosition(temporary = false) {
  5556. if (!this._position) {
  5557. return;
  5558. }
  5559. let position = this._position;
  5560. if (temporary) {
  5561. position = Object.assign(Object.create(null), this._position);
  5562. position.temporary = true;
  5563. }
  5564. if (!this._destination) {
  5565. this.#pushOrReplaceState(position);
  5566. return;
  5567. }
  5568. if (this._destination.temporary) {
  5569. this.#pushOrReplaceState(position, true);
  5570. return;
  5571. }
  5572. if (this._destination.hash === position.hash) {
  5573. return;
  5574. }
  5575. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5576. return;
  5577. }
  5578. let forceReplace = false;
  5579. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5580. if (this._destination.dest !== undefined || !this._destination.first) {
  5581. return;
  5582. }
  5583. forceReplace = true;
  5584. }
  5585. this.#pushOrReplaceState(position, forceReplace);
  5586. }
  5587. #isValidPage(val) {
  5588. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5589. }
  5590. #isValidState(state, checkReload = false) {
  5591. if (!state) {
  5592. return false;
  5593. }
  5594. if (state.fingerprint !== this._fingerprint) {
  5595. if (checkReload) {
  5596. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5597. return false;
  5598. }
  5599. const [perfEntry] = performance.getEntriesByType("navigation");
  5600. if (perfEntry?.type !== "reload") {
  5601. return false;
  5602. }
  5603. } else {
  5604. return false;
  5605. }
  5606. }
  5607. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5608. return false;
  5609. }
  5610. if (state.destination === null || typeof state.destination !== "object") {
  5611. return false;
  5612. }
  5613. return true;
  5614. }
  5615. #updateInternalState(destination, uid, removeTemporary = false) {
  5616. if (this._updateViewareaTimeout) {
  5617. clearTimeout(this._updateViewareaTimeout);
  5618. this._updateViewareaTimeout = null;
  5619. }
  5620. if (removeTemporary && destination?.temporary) {
  5621. delete destination.temporary;
  5622. }
  5623. this._destination = destination;
  5624. this._uid = uid;
  5625. this._maxUid = Math.max(this._maxUid, uid);
  5626. this._numPositionUpdates = 0;
  5627. }
  5628. #parseCurrentHash(checkNameddest = false) {
  5629. const hash = unescape(getCurrentHash()).substring(1);
  5630. const params = parseQueryString(hash);
  5631. const nameddest = params.get("nameddest") || "";
  5632. let page = params.get("page") | 0;
  5633. if (!this.#isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5634. page = null;
  5635. }
  5636. return {
  5637. hash,
  5638. page,
  5639. rotation: this.linkService.rotation
  5640. };
  5641. }
  5642. #updateViewarea({
  5643. location
  5644. }) {
  5645. if (this._updateViewareaTimeout) {
  5646. clearTimeout(this._updateViewareaTimeout);
  5647. this._updateViewareaTimeout = null;
  5648. }
  5649. this._position = {
  5650. hash: location.pdfOpenParams.substring(1),
  5651. page: this.linkService.page,
  5652. first: location.pageNumber,
  5653. rotation: location.rotation
  5654. };
  5655. if (this._popStateInProgress) {
  5656. return;
  5657. }
  5658. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5659. this._numPositionUpdates++;
  5660. }
  5661. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5662. this._updateViewareaTimeout = setTimeout(() => {
  5663. if (!this._popStateInProgress) {
  5664. this.#tryPushCurrentPosition(true);
  5665. }
  5666. this._updateViewareaTimeout = null;
  5667. }, UPDATE_VIEWAREA_TIMEOUT);
  5668. }
  5669. }
  5670. #popState({
  5671. state
  5672. }) {
  5673. const newHash = getCurrentHash(),
  5674. hashChanged = this._currentHash !== newHash;
  5675. this._currentHash = newHash;
  5676. if (!state) {
  5677. this._uid++;
  5678. const {
  5679. hash,
  5680. page,
  5681. rotation
  5682. } = this.#parseCurrentHash();
  5683. this.#pushOrReplaceState({
  5684. hash,
  5685. page,
  5686. rotation
  5687. }, true);
  5688. return;
  5689. }
  5690. if (!this.#isValidState(state)) {
  5691. return;
  5692. }
  5693. this._popStateInProgress = true;
  5694. if (hashChanged) {
  5695. this._blockHashChange++;
  5696. waitOnEventOrTimeout({
  5697. target: window,
  5698. name: "hashchange",
  5699. delay: HASH_CHANGE_TIMEOUT
  5700. }).then(() => {
  5701. this._blockHashChange--;
  5702. });
  5703. }
  5704. const destination = state.destination;
  5705. this.#updateInternalState(destination, state.uid, true);
  5706. if (isValidRotation(destination.rotation)) {
  5707. this.linkService.rotation = destination.rotation;
  5708. }
  5709. if (destination.dest) {
  5710. this.linkService.goToDestination(destination.dest);
  5711. } else if (destination.hash) {
  5712. this.linkService.setHash(destination.hash);
  5713. } else if (destination.page) {
  5714. this.linkService.page = destination.page;
  5715. }
  5716. Promise.resolve().then(() => {
  5717. this._popStateInProgress = false;
  5718. });
  5719. }
  5720. #pageHide() {
  5721. if (!this._destination || this._destination.temporary) {
  5722. this.#tryPushCurrentPosition();
  5723. }
  5724. }
  5725. #bindEvents() {
  5726. if (this.#eventAbortController) {
  5727. return;
  5728. }
  5729. this.#eventAbortController = new AbortController();
  5730. const {
  5731. signal
  5732. } = this.#eventAbortController;
  5733. this.eventBus._on("updateviewarea", this.#updateViewarea.bind(this), {
  5734. signal
  5735. });
  5736. window.addEventListener("popstate", this.#popState.bind(this), {
  5737. signal
  5738. });
  5739. window.addEventListener("pagehide", this.#pageHide.bind(this), {
  5740. signal
  5741. });
  5742. }
  5743. #unbindEvents() {
  5744. this.#eventAbortController?.abort();
  5745. this.#eventAbortController = null;
  5746. }
  5747. }
  5748. function isDestHashesEqual(destHash, pushHash) {
  5749. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5750. return false;
  5751. }
  5752. if (destHash === pushHash) {
  5753. return true;
  5754. }
  5755. const nameddest = parseQueryString(destHash).get("nameddest");
  5756. if (nameddest === pushHash) {
  5757. return true;
  5758. }
  5759. return false;
  5760. }
  5761. function isDestArraysEqual(firstDest, secondDest) {
  5762. function isEntryEqual(first, second) {
  5763. if (typeof first !== typeof second) {
  5764. return false;
  5765. }
  5766. if (Array.isArray(first) || Array.isArray(second)) {
  5767. return false;
  5768. }
  5769. if (first !== null && typeof first === "object" && second !== null) {
  5770. if (Object.keys(first).length !== Object.keys(second).length) {
  5771. return false;
  5772. }
  5773. for (const key in first) {
  5774. if (!isEntryEqual(first[key], second[key])) {
  5775. return false;
  5776. }
  5777. }
  5778. return true;
  5779. }
  5780. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5781. }
  5782. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5783. return false;
  5784. }
  5785. if (firstDest.length !== secondDest.length) {
  5786. return false;
  5787. }
  5788. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5789. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5790. return false;
  5791. }
  5792. }
  5793. return true;
  5794. }
  5795. ;// CONCATENATED MODULE: ./web/pdf_layer_viewer.js
  5796. class PDFLayerViewer extends BaseTreeViewer {
  5797. constructor(options) {
  5798. super(options);
  5799. this.eventBus._on("optionalcontentconfigchanged", evt => {
  5800. this.#updateLayers(evt.promise);
  5801. });
  5802. this.eventBus._on("resetlayers", () => {
  5803. this.#updateLayers();
  5804. });
  5805. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5806. }
  5807. reset() {
  5808. super.reset();
  5809. this._optionalContentConfig = null;
  5810. this._optionalContentHash = null;
  5811. }
  5812. _dispatchEvent(layersCount) {
  5813. this.eventBus.dispatch("layersloaded", {
  5814. source: this,
  5815. layersCount
  5816. });
  5817. }
  5818. _bindLink(element, {
  5819. groupId,
  5820. input
  5821. }) {
  5822. const setVisibility = () => {
  5823. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5824. this._optionalContentHash = this._optionalContentConfig.getHash();
  5825. this.eventBus.dispatch("optionalcontentconfig", {
  5826. source: this,
  5827. promise: Promise.resolve(this._optionalContentConfig)
  5828. });
  5829. };
  5830. element.onclick = evt => {
  5831. if (evt.target === input) {
  5832. setVisibility();
  5833. return true;
  5834. } else if (evt.target !== element) {
  5835. return true;
  5836. }
  5837. input.checked = !input.checked;
  5838. setVisibility();
  5839. return false;
  5840. };
  5841. }
  5842. async _setNestedName(element, {
  5843. name = null
  5844. }) {
  5845. if (typeof name === "string") {
  5846. element.textContent = this._normalizeTextContent(name);
  5847. return;
  5848. }
  5849. element.textContent = await this._l10n.get("pdfjs-additional-layers");
  5850. element.style.fontStyle = "italic";
  5851. }
  5852. _addToggleButton(div, {
  5853. name = null
  5854. }) {
  5855. super._addToggleButton(div, name === null);
  5856. }
  5857. _toggleAllTreeItems() {
  5858. if (!this._optionalContentConfig) {
  5859. return;
  5860. }
  5861. super._toggleAllTreeItems();
  5862. }
  5863. render({
  5864. optionalContentConfig,
  5865. pdfDocument
  5866. }) {
  5867. if (this._optionalContentConfig) {
  5868. this.reset();
  5869. }
  5870. this._optionalContentConfig = optionalContentConfig || null;
  5871. this._pdfDocument = pdfDocument || null;
  5872. const groups = optionalContentConfig?.getOrder();
  5873. if (!groups) {
  5874. this._dispatchEvent(0);
  5875. return;
  5876. }
  5877. this._optionalContentHash = optionalContentConfig.getHash();
  5878. const fragment = document.createDocumentFragment(),
  5879. queue = [{
  5880. parent: fragment,
  5881. groups
  5882. }];
  5883. let layersCount = 0,
  5884. hasAnyNesting = false;
  5885. while (queue.length > 0) {
  5886. const levelData = queue.shift();
  5887. for (const groupId of levelData.groups) {
  5888. const div = document.createElement("div");
  5889. div.className = "treeItem";
  5890. const element = document.createElement("a");
  5891. div.append(element);
  5892. if (typeof groupId === "object") {
  5893. hasAnyNesting = true;
  5894. this._addToggleButton(div, groupId);
  5895. this._setNestedName(element, groupId);
  5896. const itemsDiv = document.createElement("div");
  5897. itemsDiv.className = "treeItems";
  5898. div.append(itemsDiv);
  5899. queue.push({
  5900. parent: itemsDiv,
  5901. groups: groupId.order
  5902. });
  5903. } else {
  5904. const group = optionalContentConfig.getGroup(groupId);
  5905. const input = document.createElement("input");
  5906. this._bindLink(element, {
  5907. groupId,
  5908. input
  5909. });
  5910. input.type = "checkbox";
  5911. input.checked = group.visible;
  5912. const label = document.createElement("label");
  5913. label.textContent = this._normalizeTextContent(group.name);
  5914. label.append(input);
  5915. element.append(label);
  5916. layersCount++;
  5917. }
  5918. levelData.parent.append(div);
  5919. }
  5920. }
  5921. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5922. }
  5923. async #updateLayers(promise = null) {
  5924. if (!this._optionalContentConfig) {
  5925. return;
  5926. }
  5927. const pdfDocument = this._pdfDocument;
  5928. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig({
  5929. intent: "display"
  5930. }));
  5931. if (pdfDocument !== this._pdfDocument) {
  5932. return;
  5933. }
  5934. if (promise) {
  5935. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  5936. return;
  5937. }
  5938. } else {
  5939. this.eventBus.dispatch("optionalcontentconfig", {
  5940. source: this,
  5941. promise: Promise.resolve(optionalContentConfig)
  5942. });
  5943. }
  5944. this.render({
  5945. optionalContentConfig,
  5946. pdfDocument: this._pdfDocument
  5947. });
  5948. }
  5949. }
  5950. ;// CONCATENATED MODULE: ./web/pdf_outline_viewer.js
  5951. class PDFOutlineViewer extends BaseTreeViewer {
  5952. constructor(options) {
  5953. super(options);
  5954. this.linkService = options.linkService;
  5955. this.downloadManager = options.downloadManager;
  5956. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5957. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5958. this.eventBus._on("pagechanging", evt => {
  5959. this._currentPageNumber = evt.pageNumber;
  5960. });
  5961. this.eventBus._on("pagesloaded", evt => {
  5962. this._isPagesLoaded = !!evt.pagesCount;
  5963. this._currentOutlineItemCapability?.resolve(this._isPagesLoaded);
  5964. });
  5965. this.eventBus._on("sidebarviewchanged", evt => {
  5966. this._sidebarView = evt.view;
  5967. });
  5968. }
  5969. reset() {
  5970. super.reset();
  5971. this._outline = null;
  5972. this._pageNumberToDestHashCapability = null;
  5973. this._currentPageNumber = 1;
  5974. this._isPagesLoaded = null;
  5975. this._currentOutlineItemCapability?.resolve(false);
  5976. this._currentOutlineItemCapability = null;
  5977. }
  5978. _dispatchEvent(outlineCount) {
  5979. this._currentOutlineItemCapability = Promise.withResolvers();
  5980. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5981. this._currentOutlineItemCapability.resolve(false);
  5982. } else if (this._isPagesLoaded !== null) {
  5983. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5984. }
  5985. this.eventBus.dispatch("outlineloaded", {
  5986. source: this,
  5987. outlineCount,
  5988. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5989. });
  5990. }
  5991. _bindLink(element, {
  5992. url,
  5993. newWindow,
  5994. action,
  5995. attachment,
  5996. dest,
  5997. setOCGState
  5998. }) {
  5999. const {
  6000. linkService
  6001. } = this;
  6002. if (url) {
  6003. linkService.addLinkAttributes(element, url, newWindow);
  6004. return;
  6005. }
  6006. if (action) {
  6007. element.href = linkService.getAnchorUrl("");
  6008. element.onclick = () => {
  6009. linkService.executeNamedAction(action);
  6010. return false;
  6011. };
  6012. return;
  6013. }
  6014. if (attachment) {
  6015. element.href = linkService.getAnchorUrl("");
  6016. element.onclick = () => {
  6017. this.downloadManager.openOrDownloadData(attachment.content, attachment.filename);
  6018. return false;
  6019. };
  6020. return;
  6021. }
  6022. if (setOCGState) {
  6023. element.href = linkService.getAnchorUrl("");
  6024. element.onclick = () => {
  6025. linkService.executeSetOCGState(setOCGState);
  6026. return false;
  6027. };
  6028. return;
  6029. }
  6030. element.href = linkService.getDestinationHash(dest);
  6031. element.onclick = evt => {
  6032. this._updateCurrentTreeItem(evt.target.parentNode);
  6033. if (dest) {
  6034. linkService.goToDestination(dest);
  6035. }
  6036. return false;
  6037. };
  6038. }
  6039. _setStyles(element, {
  6040. bold,
  6041. italic
  6042. }) {
  6043. if (bold) {
  6044. element.style.fontWeight = "bold";
  6045. }
  6046. if (italic) {
  6047. element.style.fontStyle = "italic";
  6048. }
  6049. }
  6050. _addToggleButton(div, {
  6051. count,
  6052. items
  6053. }) {
  6054. let hidden = false;
  6055. if (count < 0) {
  6056. let totalCount = items.length;
  6057. if (totalCount > 0) {
  6058. const queue = [...items];
  6059. while (queue.length > 0) {
  6060. const {
  6061. count: nestedCount,
  6062. items: nestedItems
  6063. } = queue.shift();
  6064. if (nestedCount > 0 && nestedItems.length > 0) {
  6065. totalCount += nestedItems.length;
  6066. queue.push(...nestedItems);
  6067. }
  6068. }
  6069. }
  6070. if (Math.abs(count) === totalCount) {
  6071. hidden = true;
  6072. }
  6073. }
  6074. super._addToggleButton(div, hidden);
  6075. }
  6076. _toggleAllTreeItems() {
  6077. if (!this._outline) {
  6078. return;
  6079. }
  6080. super._toggleAllTreeItems();
  6081. }
  6082. render({
  6083. outline,
  6084. pdfDocument
  6085. }) {
  6086. if (this._outline) {
  6087. this.reset();
  6088. }
  6089. this._outline = outline || null;
  6090. this._pdfDocument = pdfDocument || null;
  6091. if (!outline) {
  6092. this._dispatchEvent(0);
  6093. return;
  6094. }
  6095. const fragment = document.createDocumentFragment();
  6096. const queue = [{
  6097. parent: fragment,
  6098. items: outline
  6099. }];
  6100. let outlineCount = 0,
  6101. hasAnyNesting = false;
  6102. while (queue.length > 0) {
  6103. const levelData = queue.shift();
  6104. for (const item of levelData.items) {
  6105. const div = document.createElement("div");
  6106. div.className = "treeItem";
  6107. const element = document.createElement("a");
  6108. this._bindLink(element, item);
  6109. this._setStyles(element, item);
  6110. element.textContent = this._normalizeTextContent(item.title);
  6111. div.append(element);
  6112. if (item.items.length > 0) {
  6113. hasAnyNesting = true;
  6114. this._addToggleButton(div, item);
  6115. const itemsDiv = document.createElement("div");
  6116. itemsDiv.className = "treeItems";
  6117. div.append(itemsDiv);
  6118. queue.push({
  6119. parent: itemsDiv,
  6120. items: item.items
  6121. });
  6122. }
  6123. levelData.parent.append(div);
  6124. outlineCount++;
  6125. }
  6126. }
  6127. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6128. }
  6129. async _currentOutlineItem() {
  6130. if (!this._isPagesLoaded) {
  6131. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6132. }
  6133. if (!this._outline || !this._pdfDocument) {
  6134. return;
  6135. }
  6136. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6137. if (!pageNumberToDestHash) {
  6138. return;
  6139. }
  6140. this._updateCurrentTreeItem(null);
  6141. if (this._sidebarView !== SidebarView.OUTLINE) {
  6142. return;
  6143. }
  6144. for (let i = this._currentPageNumber; i > 0; i--) {
  6145. const destHash = pageNumberToDestHash.get(i);
  6146. if (!destHash) {
  6147. continue;
  6148. }
  6149. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6150. if (!linkElement) {
  6151. continue;
  6152. }
  6153. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6154. break;
  6155. }
  6156. }
  6157. async _getPageNumberToDestHash(pdfDocument) {
  6158. if (this._pageNumberToDestHashCapability) {
  6159. return this._pageNumberToDestHashCapability.promise;
  6160. }
  6161. this._pageNumberToDestHashCapability = Promise.withResolvers();
  6162. const pageNumberToDestHash = new Map(),
  6163. pageNumberNesting = new Map();
  6164. const queue = [{
  6165. nesting: 0,
  6166. items: this._outline
  6167. }];
  6168. while (queue.length > 0) {
  6169. const levelData = queue.shift(),
  6170. currentNesting = levelData.nesting;
  6171. for (const {
  6172. dest,
  6173. items
  6174. } of levelData.items) {
  6175. let explicitDest, pageNumber;
  6176. if (typeof dest === "string") {
  6177. explicitDest = await pdfDocument.getDestination(dest);
  6178. if (pdfDocument !== this._pdfDocument) {
  6179. return null;
  6180. }
  6181. } else {
  6182. explicitDest = dest;
  6183. }
  6184. if (Array.isArray(explicitDest)) {
  6185. const [destRef] = explicitDest;
  6186. if (destRef && typeof destRef === "object") {
  6187. pageNumber = pdfDocument.cachedPageNumber(destRef);
  6188. } else if (Number.isInteger(destRef)) {
  6189. pageNumber = destRef + 1;
  6190. }
  6191. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6192. const destHash = this.linkService.getDestinationHash(dest);
  6193. pageNumberToDestHash.set(pageNumber, destHash);
  6194. pageNumberNesting.set(pageNumber, currentNesting);
  6195. }
  6196. }
  6197. if (items.length > 0) {
  6198. queue.push({
  6199. nesting: currentNesting + 1,
  6200. items
  6201. });
  6202. }
  6203. }
  6204. }
  6205. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6206. return this._pageNumberToDestHashCapability.promise;
  6207. }
  6208. }
  6209. ;// CONCATENATED MODULE: ./web/pdf_presentation_mode.js
  6210. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6211. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6212. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6213. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6214. const PAGE_SWITCH_THRESHOLD = 0.1;
  6215. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6216. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6217. class PDFPresentationMode {
  6218. #state = PresentationModeState.UNKNOWN;
  6219. #args = null;
  6220. #fullscreenChangeAbortController = null;
  6221. #windowAbortController = null;
  6222. constructor({
  6223. container,
  6224. pdfViewer,
  6225. eventBus
  6226. }) {
  6227. this.container = container;
  6228. this.pdfViewer = pdfViewer;
  6229. this.eventBus = eventBus;
  6230. this.contextMenuOpen = false;
  6231. this.mouseScrollTimeStamp = 0;
  6232. this.mouseScrollDelta = 0;
  6233. this.touchSwipeState = null;
  6234. }
  6235. async request() {
  6236. const {
  6237. container,
  6238. pdfViewer
  6239. } = this;
  6240. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6241. return false;
  6242. }
  6243. this.#addFullscreenChangeListeners();
  6244. this.#notifyStateChange(PresentationModeState.CHANGING);
  6245. const promise = container.requestFullscreen();
  6246. this.#args = {
  6247. pageNumber: pdfViewer.currentPageNumber,
  6248. scaleValue: pdfViewer.currentScaleValue,
  6249. scrollMode: pdfViewer.scrollMode,
  6250. spreadMode: null,
  6251. annotationEditorMode: null
  6252. };
  6253. if (pdfViewer.spreadMode !== SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6254. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6255. this.#args.spreadMode = pdfViewer.spreadMode;
  6256. }
  6257. if (pdfViewer.annotationEditorMode !== AnnotationEditorType.DISABLE) {
  6258. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6259. }
  6260. try {
  6261. await promise;
  6262. pdfViewer.focus();
  6263. return true;
  6264. } catch {
  6265. this.#removeFullscreenChangeListeners();
  6266. this.#notifyStateChange(PresentationModeState.NORMAL);
  6267. }
  6268. return false;
  6269. }
  6270. get active() {
  6271. return this.#state === PresentationModeState.CHANGING || this.#state === PresentationModeState.FULLSCREEN;
  6272. }
  6273. #mouseWheel(evt) {
  6274. if (!this.active) {
  6275. return;
  6276. }
  6277. evt.preventDefault();
  6278. const delta = normalizeWheelEventDelta(evt);
  6279. const currentTime = Date.now();
  6280. const storedTime = this.mouseScrollTimeStamp;
  6281. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6282. return;
  6283. }
  6284. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6285. this.#resetMouseScrollState();
  6286. }
  6287. this.mouseScrollDelta += delta;
  6288. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6289. const totalDelta = this.mouseScrollDelta;
  6290. this.#resetMouseScrollState();
  6291. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6292. if (success) {
  6293. this.mouseScrollTimeStamp = currentTime;
  6294. }
  6295. }
  6296. }
  6297. #notifyStateChange(state) {
  6298. this.#state = state;
  6299. this.eventBus.dispatch("presentationmodechanged", {
  6300. source: this,
  6301. state
  6302. });
  6303. }
  6304. #enter() {
  6305. this.#notifyStateChange(PresentationModeState.FULLSCREEN);
  6306. this.container.classList.add(ACTIVE_SELECTOR);
  6307. setTimeout(() => {
  6308. this.pdfViewer.scrollMode = ScrollMode.PAGE;
  6309. if (this.#args.spreadMode !== null) {
  6310. this.pdfViewer.spreadMode = SpreadMode.NONE;
  6311. }
  6312. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6313. this.pdfViewer.currentScaleValue = "page-fit";
  6314. if (this.#args.annotationEditorMode !== null) {
  6315. this.pdfViewer.annotationEditorMode = {
  6316. mode: AnnotationEditorType.NONE
  6317. };
  6318. }
  6319. }, 0);
  6320. this.#addWindowListeners();
  6321. this.#showControls();
  6322. this.contextMenuOpen = false;
  6323. document.getSelection().empty();
  6324. }
  6325. #exit() {
  6326. const pageNumber = this.pdfViewer.currentPageNumber;
  6327. this.container.classList.remove(ACTIVE_SELECTOR);
  6328. setTimeout(() => {
  6329. this.#removeFullscreenChangeListeners();
  6330. this.#notifyStateChange(PresentationModeState.NORMAL);
  6331. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6332. if (this.#args.spreadMode !== null) {
  6333. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6334. }
  6335. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6336. this.pdfViewer.currentPageNumber = pageNumber;
  6337. if (this.#args.annotationEditorMode !== null) {
  6338. this.pdfViewer.annotationEditorMode = {
  6339. mode: this.#args.annotationEditorMode
  6340. };
  6341. }
  6342. this.#args = null;
  6343. }, 0);
  6344. this.#removeWindowListeners();
  6345. this.#hideControls();
  6346. this.#resetMouseScrollState();
  6347. this.contextMenuOpen = false;
  6348. }
  6349. #mouseDown(evt) {
  6350. if (this.contextMenuOpen) {
  6351. this.contextMenuOpen = false;
  6352. evt.preventDefault();
  6353. return;
  6354. }
  6355. if (evt.button !== 0) {
  6356. return;
  6357. }
  6358. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6359. return;
  6360. }
  6361. evt.preventDefault();
  6362. if (evt.shiftKey) {
  6363. this.pdfViewer.previousPage();
  6364. } else {
  6365. this.pdfViewer.nextPage();
  6366. }
  6367. }
  6368. #contextMenu() {
  6369. this.contextMenuOpen = true;
  6370. }
  6371. #showControls() {
  6372. if (this.controlsTimeout) {
  6373. clearTimeout(this.controlsTimeout);
  6374. } else {
  6375. this.container.classList.add(CONTROLS_SELECTOR);
  6376. }
  6377. this.controlsTimeout = setTimeout(() => {
  6378. this.container.classList.remove(CONTROLS_SELECTOR);
  6379. delete this.controlsTimeout;
  6380. }, DELAY_BEFORE_HIDING_CONTROLS);
  6381. }
  6382. #hideControls() {
  6383. if (!this.controlsTimeout) {
  6384. return;
  6385. }
  6386. clearTimeout(this.controlsTimeout);
  6387. this.container.classList.remove(CONTROLS_SELECTOR);
  6388. delete this.controlsTimeout;
  6389. }
  6390. #resetMouseScrollState() {
  6391. this.mouseScrollTimeStamp = 0;
  6392. this.mouseScrollDelta = 0;
  6393. }
  6394. #touchSwipe(evt) {
  6395. if (!this.active) {
  6396. return;
  6397. }
  6398. if (evt.touches.length > 1) {
  6399. this.touchSwipeState = null;
  6400. return;
  6401. }
  6402. switch (evt.type) {
  6403. case "touchstart":
  6404. this.touchSwipeState = {
  6405. startX: evt.touches[0].pageX,
  6406. startY: evt.touches[0].pageY,
  6407. endX: evt.touches[0].pageX,
  6408. endY: evt.touches[0].pageY
  6409. };
  6410. break;
  6411. case "touchmove":
  6412. if (this.touchSwipeState === null) {
  6413. return;
  6414. }
  6415. this.touchSwipeState.endX = evt.touches[0].pageX;
  6416. this.touchSwipeState.endY = evt.touches[0].pageY;
  6417. evt.preventDefault();
  6418. break;
  6419. case "touchend":
  6420. if (this.touchSwipeState === null) {
  6421. return;
  6422. }
  6423. let delta = 0;
  6424. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6425. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6426. const absAngle = Math.abs(Math.atan2(dy, dx));
  6427. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6428. delta = dx;
  6429. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6430. delta = dy;
  6431. }
  6432. if (delta > 0) {
  6433. this.pdfViewer.previousPage();
  6434. } else if (delta < 0) {
  6435. this.pdfViewer.nextPage();
  6436. }
  6437. break;
  6438. }
  6439. }
  6440. #addWindowListeners() {
  6441. if (this.#windowAbortController) {
  6442. return;
  6443. }
  6444. this.#windowAbortController = new AbortController();
  6445. const {
  6446. signal
  6447. } = this.#windowAbortController;
  6448. const touchSwipeBind = this.#touchSwipe.bind(this);
  6449. window.addEventListener("mousemove", this.#showControls.bind(this), {
  6450. signal
  6451. });
  6452. window.addEventListener("mousedown", this.#mouseDown.bind(this), {
  6453. signal
  6454. });
  6455. window.addEventListener("wheel", this.#mouseWheel.bind(this), {
  6456. passive: false,
  6457. signal
  6458. });
  6459. window.addEventListener("keydown", this.#resetMouseScrollState.bind(this), {
  6460. signal
  6461. });
  6462. window.addEventListener("contextmenu", this.#contextMenu.bind(this), {
  6463. signal
  6464. });
  6465. window.addEventListener("touchstart", touchSwipeBind, {
  6466. signal
  6467. });
  6468. window.addEventListener("touchmove", touchSwipeBind, {
  6469. signal
  6470. });
  6471. window.addEventListener("touchend", touchSwipeBind, {
  6472. signal
  6473. });
  6474. }
  6475. #removeWindowListeners() {
  6476. this.#windowAbortController?.abort();
  6477. this.#windowAbortController = null;
  6478. }
  6479. #addFullscreenChangeListeners() {
  6480. if (this.#fullscreenChangeAbortController) {
  6481. return;
  6482. }
  6483. this.#fullscreenChangeAbortController = new AbortController();
  6484. window.addEventListener("fullscreenchange", () => {
  6485. if (document.fullscreenElement) {
  6486. this.#enter();
  6487. } else {
  6488. this.#exit();
  6489. }
  6490. }, {
  6491. signal: this.#fullscreenChangeAbortController.signal
  6492. });
  6493. }
  6494. #removeFullscreenChangeListeners() {
  6495. this.#fullscreenChangeAbortController?.abort();
  6496. this.#fullscreenChangeAbortController = null;
  6497. }
  6498. }
  6499. ;// CONCATENATED MODULE: ./web/xfa_layer_builder.js
  6500. class XfaLayerBuilder {
  6501. constructor({
  6502. pdfPage,
  6503. annotationStorage = null,
  6504. linkService,
  6505. xfaHtml = null
  6506. }) {
  6507. this.pdfPage = pdfPage;
  6508. this.annotationStorage = annotationStorage;
  6509. this.linkService = linkService;
  6510. this.xfaHtml = xfaHtml;
  6511. this.div = null;
  6512. this._cancelled = false;
  6513. }
  6514. async render(viewport, intent = "display") {
  6515. if (intent === "print") {
  6516. const parameters = {
  6517. viewport: viewport.clone({
  6518. dontFlip: true
  6519. }),
  6520. div: this.div,
  6521. xfaHtml: this.xfaHtml,
  6522. annotationStorage: this.annotationStorage,
  6523. linkService: this.linkService,
  6524. intent
  6525. };
  6526. this.div = document.createElement("div");
  6527. parameters.div = this.div;
  6528. return XfaLayer.render(parameters);
  6529. }
  6530. const xfaHtml = await this.pdfPage.getXfa();
  6531. if (this._cancelled || !xfaHtml) {
  6532. return {
  6533. textDivs: []
  6534. };
  6535. }
  6536. const parameters = {
  6537. viewport: viewport.clone({
  6538. dontFlip: true
  6539. }),
  6540. div: this.div,
  6541. xfaHtml,
  6542. annotationStorage: this.annotationStorage,
  6543. linkService: this.linkService,
  6544. intent
  6545. };
  6546. if (this.div) {
  6547. return XfaLayer.update(parameters);
  6548. }
  6549. this.div = document.createElement("div");
  6550. parameters.div = this.div;
  6551. return XfaLayer.render(parameters);
  6552. }
  6553. cancel() {
  6554. this._cancelled = true;
  6555. }
  6556. hide() {
  6557. if (!this.div) {
  6558. return;
  6559. }
  6560. this.div.hidden = true;
  6561. }
  6562. }
  6563. ;// CONCATENATED MODULE: ./web/print_utils.js
  6564. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  6565. const xfaHtml = pdfDocument.allXfaHtml;
  6566. const linkService = new SimpleLinkService();
  6567. const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  6568. for (const xfaPage of xfaHtml.children) {
  6569. const page = document.createElement("div");
  6570. page.className = "xfaPrintedPage";
  6571. printContainer.append(page);
  6572. const builder = new XfaLayerBuilder({
  6573. pdfPage: null,
  6574. annotationStorage: pdfDocument.annotationStorage,
  6575. linkService,
  6576. xfaHtml: xfaPage
  6577. });
  6578. const viewport = getXfaPageViewport(xfaPage, {
  6579. scale
  6580. });
  6581. builder.render(viewport, "print");
  6582. page.append(builder.div);
  6583. }
  6584. }
  6585. ;// CONCATENATED MODULE: ./web/pdf_print_service.js
  6586. let activeService = null;
  6587. let dialog = null;
  6588. let overlayManager = null;
  6589. let viewerApp = {
  6590. initialized: false
  6591. };
  6592. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  6593. const scratchCanvas = activeService.scratchCanvas;
  6594. const PRINT_UNITS = printResolution / PixelsPerInch.PDF;
  6595. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  6596. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  6597. const ctx = scratchCanvas.getContext("2d");
  6598. ctx.save();
  6599. ctx.fillStyle = "rgb(255, 255, 255)";
  6600. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  6601. ctx.restore();
  6602. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  6603. const renderContext = {
  6604. canvasContext: ctx,
  6605. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  6606. viewport: pdfPage.getViewport({
  6607. scale: 1,
  6608. rotation: size.rotation
  6609. }),
  6610. intent: "print",
  6611. annotationMode: AnnotationMode.ENABLE_STORAGE,
  6612. optionalContentConfigPromise,
  6613. printAnnotationStorage
  6614. };
  6615. const renderTask = pdfPage.render(renderContext);
  6616. return renderTask.promise.catch(reason => {
  6617. if (!(reason instanceof RenderingCancelledException)) {
  6618. console.error(reason);
  6619. }
  6620. throw reason;
  6621. });
  6622. });
  6623. }
  6624. class PDFPrintService {
  6625. constructor({
  6626. pdfDocument,
  6627. pagesOverview,
  6628. printContainer,
  6629. printResolution,
  6630. printAnnotationStoragePromise = null
  6631. }) {
  6632. this.pdfDocument = pdfDocument;
  6633. this.pagesOverview = pagesOverview;
  6634. this.printContainer = printContainer;
  6635. this._printResolution = printResolution || 150;
  6636. this._optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  6637. intent: "print"
  6638. });
  6639. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  6640. this.currentPage = -1;
  6641. this.scratchCanvas = document.createElement("canvas");
  6642. }
  6643. layout() {
  6644. this.throwIfInactive();
  6645. const body = document.querySelector("body");
  6646. body.setAttribute("data-pdfjsprinting", true);
  6647. const {
  6648. width,
  6649. height
  6650. } = this.pagesOverview[0];
  6651. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  6652. if (!hasEqualPageSizes) {
  6653. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  6654. }
  6655. this.pageStyleSheet = document.createElement("style");
  6656. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  6657. body.append(this.pageStyleSheet);
  6658. }
  6659. destroy() {
  6660. if (activeService !== this) {
  6661. return;
  6662. }
  6663. this.printContainer.textContent = "";
  6664. const body = document.querySelector("body");
  6665. body.removeAttribute("data-pdfjsprinting");
  6666. if (this.pageStyleSheet) {
  6667. this.pageStyleSheet.remove();
  6668. this.pageStyleSheet = null;
  6669. }
  6670. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  6671. this.scratchCanvas = null;
  6672. activeService = null;
  6673. ensureOverlay().then(function () {
  6674. if (overlayManager.active === dialog) {
  6675. overlayManager.close(dialog);
  6676. }
  6677. });
  6678. }
  6679. renderPages() {
  6680. if (this.pdfDocument.isPureXfa) {
  6681. getXfaHtmlForPrinting(this.printContainer, this.pdfDocument);
  6682. return Promise.resolve();
  6683. }
  6684. const pageCount = this.pagesOverview.length;
  6685. const renderNextPage = (resolve, reject) => {
  6686. this.throwIfInactive();
  6687. if (++this.currentPage >= pageCount) {
  6688. renderProgress(pageCount, pageCount);
  6689. resolve();
  6690. return;
  6691. }
  6692. const index = this.currentPage;
  6693. renderProgress(index, pageCount);
  6694. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  6695. renderNextPage(resolve, reject);
  6696. }, reject);
  6697. };
  6698. return new Promise(renderNextPage);
  6699. }
  6700. useRenderedPage() {
  6701. this.throwIfInactive();
  6702. const img = document.createElement("img");
  6703. const scratchCanvas = this.scratchCanvas;
  6704. if ("toBlob" in scratchCanvas) {
  6705. scratchCanvas.toBlob(function (blob) {
  6706. img.src = URL.createObjectURL(blob);
  6707. });
  6708. } else {
  6709. img.src = scratchCanvas.toDataURL();
  6710. }
  6711. const wrapper = document.createElement("div");
  6712. wrapper.className = "printedPage";
  6713. wrapper.append(img);
  6714. this.printContainer.append(wrapper);
  6715. return new Promise(function (resolve, reject) {
  6716. img.onload = resolve;
  6717. img.onerror = reject;
  6718. });
  6719. }
  6720. performPrint() {
  6721. this.throwIfInactive();
  6722. return new Promise(resolve => {
  6723. setTimeout(() => {
  6724. if (!this.active) {
  6725. resolve();
  6726. return;
  6727. }
  6728. print.call(window);
  6729. setTimeout(resolve, 20);
  6730. }, 0);
  6731. });
  6732. }
  6733. get active() {
  6734. return this === activeService;
  6735. }
  6736. throwIfInactive() {
  6737. if (!this.active) {
  6738. throw new Error("This print request was cancelled or completed.");
  6739. }
  6740. }
  6741. }
  6742. const print = window.print;
  6743. window.print = function () {
  6744. if (activeService) {
  6745. console.warn("Ignored window.print() because of a pending print job.");
  6746. return;
  6747. }
  6748. ensureOverlay().then(function () {
  6749. if (activeService) {
  6750. overlayManager.open(dialog);
  6751. }
  6752. });
  6753. try {
  6754. dispatchEvent("beforeprint");
  6755. } finally {
  6756. if (!activeService) {
  6757. console.error("Expected print service to be initialized.");
  6758. ensureOverlay().then(function () {
  6759. if (overlayManager.active === dialog) {
  6760. overlayManager.close(dialog);
  6761. }
  6762. });
  6763. return;
  6764. }
  6765. const activeServiceOnEntry = activeService;
  6766. activeService.renderPages().then(function () {
  6767. return activeServiceOnEntry.performPrint();
  6768. }).catch(function () {}).then(function () {
  6769. if (activeServiceOnEntry.active) {
  6770. abort();
  6771. }
  6772. });
  6773. }
  6774. };
  6775. function dispatchEvent(eventType) {
  6776. const event = new CustomEvent(eventType, {
  6777. bubbles: false,
  6778. cancelable: false,
  6779. detail: "custom"
  6780. });
  6781. window.dispatchEvent(event);
  6782. }
  6783. function abort() {
  6784. if (activeService) {
  6785. activeService.destroy();
  6786. dispatchEvent("afterprint");
  6787. }
  6788. }
  6789. function renderProgress(index, total) {
  6790. dialog ||= document.getElementById("printServiceDialog");
  6791. const progress = Math.round(100 * index / total);
  6792. const progressBar = dialog.querySelector("progress");
  6793. const progressPerc = dialog.querySelector(".relative-progress");
  6794. progressBar.value = progress;
  6795. progressPerc.setAttribute("data-l10n-args", JSON.stringify({
  6796. progress
  6797. }));
  6798. }
  6799. window.addEventListener("keydown", function (event) {
  6800. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  6801. window.print();
  6802. event.preventDefault();
  6803. event.stopImmediatePropagation();
  6804. }
  6805. }, true);
  6806. if ("onbeforeprint" in window) {
  6807. const stopPropagationIfNeeded = function (event) {
  6808. if (event.detail !== "custom") {
  6809. event.stopImmediatePropagation();
  6810. }
  6811. };
  6812. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  6813. window.addEventListener("afterprint", stopPropagationIfNeeded);
  6814. }
  6815. let overlayPromise;
  6816. function ensureOverlay() {
  6817. if (!overlayPromise) {
  6818. overlayManager = viewerApp.overlayManager;
  6819. if (!overlayManager) {
  6820. throw new Error("The overlay manager has not yet been initialized.");
  6821. }
  6822. dialog ||= document.getElementById("printServiceDialog");
  6823. overlayPromise = overlayManager.register(dialog, true);
  6824. document.getElementById("printCancel").onclick = abort;
  6825. dialog.addEventListener("close", abort);
  6826. }
  6827. return overlayPromise;
  6828. }
  6829. class PDFPrintServiceFactory {
  6830. static initGlobals(app) {
  6831. viewerApp = app;
  6832. }
  6833. static get supportsPrinting() {
  6834. return shadow(this, "supportsPrinting", true);
  6835. }
  6836. static createPrintService(params) {
  6837. if (activeService) {
  6838. throw new Error("The print service is created and active.");
  6839. }
  6840. return activeService = new PDFPrintService(params);
  6841. }
  6842. }
  6843. ;// CONCATENATED MODULE: ./web/pdf_rendering_queue.js
  6844. const CLEANUP_TIMEOUT = 30000;
  6845. class PDFRenderingQueue {
  6846. constructor() {
  6847. this.pdfViewer = null;
  6848. this.pdfThumbnailViewer = null;
  6849. this.onIdle = null;
  6850. this.highestPriorityPage = null;
  6851. this.idleTimeout = null;
  6852. this.printing = false;
  6853. this.isThumbnailViewEnabled = false;
  6854. Object.defineProperty(this, "hasViewer", {
  6855. value: () => !!this.pdfViewer
  6856. });
  6857. }
  6858. setViewer(pdfViewer) {
  6859. this.pdfViewer = pdfViewer;
  6860. }
  6861. setThumbnailViewer(pdfThumbnailViewer) {
  6862. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6863. }
  6864. isHighestPriority(view) {
  6865. return this.highestPriorityPage === view.renderingId;
  6866. }
  6867. renderHighestPriority(currentlyVisiblePages) {
  6868. if (this.idleTimeout) {
  6869. clearTimeout(this.idleTimeout);
  6870. this.idleTimeout = null;
  6871. }
  6872. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6873. return;
  6874. }
  6875. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6876. return;
  6877. }
  6878. if (this.printing) {
  6879. return;
  6880. }
  6881. if (this.onIdle) {
  6882. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6883. }
  6884. }
  6885. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6886. const visibleViews = visible.views,
  6887. numVisible = visibleViews.length;
  6888. if (numVisible === 0) {
  6889. return null;
  6890. }
  6891. for (let i = 0; i < numVisible; i++) {
  6892. const view = visibleViews[i].view;
  6893. if (!this.isViewFinished(view)) {
  6894. return view;
  6895. }
  6896. }
  6897. const firstId = visible.first.id,
  6898. lastId = visible.last.id;
  6899. if (lastId - firstId + 1 > numVisible) {
  6900. const visibleIds = visible.ids;
  6901. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6902. const holeId = scrolledDown ? firstId + i : lastId - i;
  6903. if (visibleIds.has(holeId)) {
  6904. continue;
  6905. }
  6906. const holeView = views[holeId - 1];
  6907. if (!this.isViewFinished(holeView)) {
  6908. return holeView;
  6909. }
  6910. }
  6911. }
  6912. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6913. let preRenderView = views[preRenderIndex];
  6914. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6915. return preRenderView;
  6916. }
  6917. if (preRenderExtra) {
  6918. preRenderIndex += scrolledDown ? 1 : -1;
  6919. preRenderView = views[preRenderIndex];
  6920. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6921. return preRenderView;
  6922. }
  6923. }
  6924. return null;
  6925. }
  6926. isViewFinished(view) {
  6927. return view.renderingState === RenderingStates.FINISHED;
  6928. }
  6929. renderView(view) {
  6930. switch (view.renderingState) {
  6931. case RenderingStates.FINISHED:
  6932. return false;
  6933. case RenderingStates.PAUSED:
  6934. this.highestPriorityPage = view.renderingId;
  6935. view.resume();
  6936. break;
  6937. case RenderingStates.RUNNING:
  6938. this.highestPriorityPage = view.renderingId;
  6939. break;
  6940. case RenderingStates.INITIAL:
  6941. this.highestPriorityPage = view.renderingId;
  6942. view.draw().finally(() => {
  6943. this.renderHighestPriority();
  6944. }).catch(reason => {
  6945. if (reason instanceof RenderingCancelledException) {
  6946. return;
  6947. }
  6948. console.error(`renderView: "${reason}"`);
  6949. });
  6950. break;
  6951. }
  6952. return true;
  6953. }
  6954. }
  6955. ;// CONCATENATED MODULE: ./web/pdf_scripting_manager.js
  6956. class PDFScriptingManager {
  6957. #closeCapability = null;
  6958. #destroyCapability = null;
  6959. #docProperties = null;
  6960. #eventAbortController = null;
  6961. #eventBus = null;
  6962. #externalServices = null;
  6963. #pdfDocument = null;
  6964. #pdfViewer = null;
  6965. #ready = false;
  6966. #scripting = null;
  6967. #willPrintCapability = null;
  6968. constructor({
  6969. eventBus,
  6970. externalServices = null,
  6971. docProperties = null
  6972. }) {
  6973. this.#eventBus = eventBus;
  6974. this.#externalServices = externalServices;
  6975. this.#docProperties = docProperties;
  6976. }
  6977. setViewer(pdfViewer) {
  6978. this.#pdfViewer = pdfViewer;
  6979. }
  6980. async setDocument(pdfDocument) {
  6981. if (this.#pdfDocument) {
  6982. await this.#destroyScripting();
  6983. }
  6984. this.#pdfDocument = pdfDocument;
  6985. if (!pdfDocument) {
  6986. return;
  6987. }
  6988. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6989. if (!objects && !docActions) {
  6990. await this.#destroyScripting();
  6991. return;
  6992. }
  6993. if (pdfDocument !== this.#pdfDocument) {
  6994. return;
  6995. }
  6996. try {
  6997. this.#scripting = this.#initScripting();
  6998. } catch (error) {
  6999. console.error(`setDocument: "${error.message}".`);
  7000. await this.#destroyScripting();
  7001. return;
  7002. }
  7003. const eventBus = this.#eventBus;
  7004. this.#eventAbortController = new AbortController();
  7005. const {
  7006. signal
  7007. } = this.#eventAbortController;
  7008. eventBus._on("updatefromsandbox", event => {
  7009. if (event?.source === window) {
  7010. this.#updateFromSandbox(event.detail);
  7011. }
  7012. }, {
  7013. signal
  7014. });
  7015. eventBus._on("dispatcheventinsandbox", event => {
  7016. this.#scripting?.dispatchEventInSandbox(event.detail);
  7017. }, {
  7018. signal
  7019. });
  7020. eventBus._on("pagechanging", ({
  7021. pageNumber,
  7022. previous
  7023. }) => {
  7024. if (pageNumber === previous) {
  7025. return;
  7026. }
  7027. this.#dispatchPageClose(previous);
  7028. this.#dispatchPageOpen(pageNumber);
  7029. }, {
  7030. signal
  7031. });
  7032. eventBus._on("pagerendered", ({
  7033. pageNumber
  7034. }) => {
  7035. if (!this._pageOpenPending.has(pageNumber)) {
  7036. return;
  7037. }
  7038. if (pageNumber !== this.#pdfViewer.currentPageNumber) {
  7039. return;
  7040. }
  7041. this.#dispatchPageOpen(pageNumber);
  7042. }, {
  7043. signal
  7044. });
  7045. eventBus._on("pagesdestroy", async () => {
  7046. await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
  7047. await this.#scripting?.dispatchEventInSandbox({
  7048. id: "doc",
  7049. name: "WillClose"
  7050. });
  7051. this.#closeCapability?.resolve();
  7052. }, {
  7053. signal
  7054. });
  7055. try {
  7056. const docProperties = await this.#docProperties(pdfDocument);
  7057. if (pdfDocument !== this.#pdfDocument) {
  7058. return;
  7059. }
  7060. await this.#scripting.createSandbox({
  7061. objects,
  7062. calculationOrder,
  7063. appInfo: {
  7064. platform: navigator.platform,
  7065. language: navigator.language
  7066. },
  7067. docInfo: {
  7068. ...docProperties,
  7069. actions: docActions
  7070. }
  7071. });
  7072. eventBus.dispatch("sandboxcreated", {
  7073. source: this
  7074. });
  7075. } catch (error) {
  7076. console.error(`setDocument: "${error.message}".`);
  7077. await this.#destroyScripting();
  7078. return;
  7079. }
  7080. await this.#scripting?.dispatchEventInSandbox({
  7081. id: "doc",
  7082. name: "Open"
  7083. });
  7084. await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
  7085. Promise.resolve().then(() => {
  7086. if (pdfDocument === this.#pdfDocument) {
  7087. this.#ready = true;
  7088. }
  7089. });
  7090. }
  7091. async dispatchWillSave() {
  7092. return this.#scripting?.dispatchEventInSandbox({
  7093. id: "doc",
  7094. name: "WillSave"
  7095. });
  7096. }
  7097. async dispatchDidSave() {
  7098. return this.#scripting?.dispatchEventInSandbox({
  7099. id: "doc",
  7100. name: "DidSave"
  7101. });
  7102. }
  7103. async dispatchWillPrint() {
  7104. if (!this.#scripting) {
  7105. return;
  7106. }
  7107. await this.#willPrintCapability?.promise;
  7108. this.#willPrintCapability = Promise.withResolvers();
  7109. try {
  7110. await this.#scripting.dispatchEventInSandbox({
  7111. id: "doc",
  7112. name: "WillPrint"
  7113. });
  7114. } catch (ex) {
  7115. this.#willPrintCapability.resolve();
  7116. this.#willPrintCapability = null;
  7117. throw ex;
  7118. }
  7119. await this.#willPrintCapability.promise;
  7120. }
  7121. async dispatchDidPrint() {
  7122. return this.#scripting?.dispatchEventInSandbox({
  7123. id: "doc",
  7124. name: "DidPrint"
  7125. });
  7126. }
  7127. get destroyPromise() {
  7128. return this.#destroyCapability?.promise || null;
  7129. }
  7130. get ready() {
  7131. return this.#ready;
  7132. }
  7133. get _pageOpenPending() {
  7134. return shadow(this, "_pageOpenPending", new Set());
  7135. }
  7136. get _visitedPages() {
  7137. return shadow(this, "_visitedPages", new Map());
  7138. }
  7139. async #updateFromSandbox(detail) {
  7140. const pdfViewer = this.#pdfViewer;
  7141. const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
  7142. const {
  7143. id,
  7144. siblings,
  7145. command,
  7146. value
  7147. } = detail;
  7148. if (!id) {
  7149. switch (command) {
  7150. case "clear":
  7151. console.clear();
  7152. break;
  7153. case "error":
  7154. console.error(value);
  7155. break;
  7156. case "layout":
  7157. if (!isInPresentationMode) {
  7158. const modes = apiPageLayoutToViewerModes(value);
  7159. pdfViewer.spreadMode = modes.spreadMode;
  7160. }
  7161. break;
  7162. case "page-num":
  7163. pdfViewer.currentPageNumber = value + 1;
  7164. break;
  7165. case "print":
  7166. await pdfViewer.pagesPromise;
  7167. this.#eventBus.dispatch("print", {
  7168. source: this
  7169. });
  7170. break;
  7171. case "println":
  7172. console.log(value);
  7173. break;
  7174. case "zoom":
  7175. if (!isInPresentationMode) {
  7176. pdfViewer.currentScaleValue = value;
  7177. }
  7178. break;
  7179. case "SaveAs":
  7180. this.#eventBus.dispatch("download", {
  7181. source: this
  7182. });
  7183. break;
  7184. case "FirstPage":
  7185. pdfViewer.currentPageNumber = 1;
  7186. break;
  7187. case "LastPage":
  7188. pdfViewer.currentPageNumber = pdfViewer.pagesCount;
  7189. break;
  7190. case "NextPage":
  7191. pdfViewer.nextPage();
  7192. break;
  7193. case "PrevPage":
  7194. pdfViewer.previousPage();
  7195. break;
  7196. case "ZoomViewIn":
  7197. if (!isInPresentationMode) {
  7198. pdfViewer.increaseScale();
  7199. }
  7200. break;
  7201. case "ZoomViewOut":
  7202. if (!isInPresentationMode) {
  7203. pdfViewer.decreaseScale();
  7204. }
  7205. break;
  7206. case "WillPrintFinished":
  7207. this.#willPrintCapability?.resolve();
  7208. this.#willPrintCapability = null;
  7209. break;
  7210. }
  7211. return;
  7212. }
  7213. if (isInPresentationMode && detail.focus) {
  7214. return;
  7215. }
  7216. delete detail.id;
  7217. delete detail.siblings;
  7218. const ids = siblings ? [id, ...siblings] : [id];
  7219. for (const elementId of ids) {
  7220. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7221. if (element) {
  7222. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7223. detail
  7224. }));
  7225. } else {
  7226. this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
  7227. }
  7228. }
  7229. }
  7230. async #dispatchPageOpen(pageNumber, initialize = false) {
  7231. const pdfDocument = this.#pdfDocument,
  7232. visitedPages = this._visitedPages;
  7233. if (initialize) {
  7234. this.#closeCapability = Promise.withResolvers();
  7235. }
  7236. if (!this.#closeCapability) {
  7237. return;
  7238. }
  7239. const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
  7240. if (pageView?.renderingState !== RenderingStates.FINISHED) {
  7241. this._pageOpenPending.add(pageNumber);
  7242. return;
  7243. }
  7244. this._pageOpenPending.delete(pageNumber);
  7245. const actionsPromise = (async () => {
  7246. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7247. if (pdfDocument !== this.#pdfDocument) {
  7248. return;
  7249. }
  7250. await this.#scripting?.dispatchEventInSandbox({
  7251. id: "page",
  7252. name: "PageOpen",
  7253. pageNumber,
  7254. actions
  7255. });
  7256. })();
  7257. visitedPages.set(pageNumber, actionsPromise);
  7258. }
  7259. async #dispatchPageClose(pageNumber) {
  7260. const pdfDocument = this.#pdfDocument,
  7261. visitedPages = this._visitedPages;
  7262. if (!this.#closeCapability) {
  7263. return;
  7264. }
  7265. if (this._pageOpenPending.has(pageNumber)) {
  7266. return;
  7267. }
  7268. const actionsPromise = visitedPages.get(pageNumber);
  7269. if (!actionsPromise) {
  7270. return;
  7271. }
  7272. visitedPages.set(pageNumber, null);
  7273. await actionsPromise;
  7274. if (pdfDocument !== this.#pdfDocument) {
  7275. return;
  7276. }
  7277. await this.#scripting?.dispatchEventInSandbox({
  7278. id: "page",
  7279. name: "PageClose",
  7280. pageNumber
  7281. });
  7282. }
  7283. #initScripting() {
  7284. this.#destroyCapability = Promise.withResolvers();
  7285. if (this.#scripting) {
  7286. throw new Error("#initScripting: Scripting already exists.");
  7287. }
  7288. return this.#externalServices.createScripting();
  7289. }
  7290. async #destroyScripting() {
  7291. if (!this.#scripting) {
  7292. this.#pdfDocument = null;
  7293. this.#destroyCapability?.resolve();
  7294. return;
  7295. }
  7296. if (this.#closeCapability) {
  7297. await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
  7298. setTimeout(resolve, 1000);
  7299. })]).catch(() => {});
  7300. this.#closeCapability = null;
  7301. }
  7302. this.#pdfDocument = null;
  7303. try {
  7304. await this.#scripting.destroySandbox();
  7305. } catch {}
  7306. this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
  7307. this.#willPrintCapability = null;
  7308. this.#eventAbortController?.abort();
  7309. this.#eventAbortController = null;
  7310. this._pageOpenPending.clear();
  7311. this._visitedPages.clear();
  7312. this.#scripting = null;
  7313. this.#ready = false;
  7314. this.#destroyCapability?.resolve();
  7315. }
  7316. }
  7317. ;// CONCATENATED MODULE: ./web/pdf_sidebar.js
  7318. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7319. const SIDEBAR_MIN_WIDTH = 200;
  7320. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7321. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7322. class PDFSidebar {
  7323. #isRTL = false;
  7324. #mouseMoveBound = this.#mouseMove.bind(this);
  7325. #mouseUpBound = this.#mouseUp.bind(this);
  7326. #outerContainerWidth = null;
  7327. #width = null;
  7328. constructor({
  7329. elements,
  7330. eventBus,
  7331. l10n
  7332. }) {
  7333. this.isOpen = false;
  7334. this.active = SidebarView.THUMBS;
  7335. this.isInitialViewSet = false;
  7336. this.isInitialEventDispatched = false;
  7337. this.onToggled = null;
  7338. this.onUpdateThumbnails = null;
  7339. this.outerContainer = elements.outerContainer;
  7340. this.sidebarContainer = elements.sidebarContainer;
  7341. this.toggleButton = elements.toggleButton;
  7342. this.resizer = elements.resizer;
  7343. this.thumbnailButton = elements.thumbnailButton;
  7344. this.outlineButton = elements.outlineButton;
  7345. this.attachmentsButton = elements.attachmentsButton;
  7346. this.layersButton = elements.layersButton;
  7347. this.thumbnailView = elements.thumbnailView;
  7348. this.outlineView = elements.outlineView;
  7349. this.attachmentsView = elements.attachmentsView;
  7350. this.layersView = elements.layersView;
  7351. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7352. this.eventBus = eventBus;
  7353. this.#isRTL = l10n.getDirection() === "rtl";
  7354. this.#addEventListeners();
  7355. }
  7356. reset() {
  7357. this.isInitialViewSet = false;
  7358. this.isInitialEventDispatched = false;
  7359. this.#hideUINotification(true);
  7360. this.switchView(SidebarView.THUMBS);
  7361. this.outlineButton.disabled = false;
  7362. this.attachmentsButton.disabled = false;
  7363. this.layersButton.disabled = false;
  7364. this._currentOutlineItemButton.disabled = true;
  7365. }
  7366. get visibleView() {
  7367. return this.isOpen ? this.active : SidebarView.NONE;
  7368. }
  7369. setInitialView(view = SidebarView.NONE) {
  7370. if (this.isInitialViewSet) {
  7371. return;
  7372. }
  7373. this.isInitialViewSet = true;
  7374. if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
  7375. this.#dispatchEvent();
  7376. return;
  7377. }
  7378. this.switchView(view, true);
  7379. if (!this.isInitialEventDispatched) {
  7380. this.#dispatchEvent();
  7381. }
  7382. }
  7383. switchView(view, forceOpen = false) {
  7384. const isViewChanged = view !== this.active;
  7385. let forceRendering = false;
  7386. switch (view) {
  7387. case SidebarView.NONE:
  7388. if (this.isOpen) {
  7389. this.close();
  7390. }
  7391. return;
  7392. case SidebarView.THUMBS:
  7393. if (this.isOpen && isViewChanged) {
  7394. forceRendering = true;
  7395. }
  7396. break;
  7397. case SidebarView.OUTLINE:
  7398. if (this.outlineButton.disabled) {
  7399. return;
  7400. }
  7401. break;
  7402. case SidebarView.ATTACHMENTS:
  7403. if (this.attachmentsButton.disabled) {
  7404. return;
  7405. }
  7406. break;
  7407. case SidebarView.LAYERS:
  7408. if (this.layersButton.disabled) {
  7409. return;
  7410. }
  7411. break;
  7412. default:
  7413. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7414. return;
  7415. }
  7416. this.active = view;
  7417. toggleCheckedBtn(this.thumbnailButton, view === SidebarView.THUMBS, this.thumbnailView);
  7418. toggleCheckedBtn(this.outlineButton, view === SidebarView.OUTLINE, this.outlineView);
  7419. toggleCheckedBtn(this.attachmentsButton, view === SidebarView.ATTACHMENTS, this.attachmentsView);
  7420. toggleCheckedBtn(this.layersButton, view === SidebarView.LAYERS, this.layersView);
  7421. if (forceOpen && !this.isOpen) {
  7422. this.open();
  7423. return;
  7424. }
  7425. if (forceRendering) {
  7426. this.onUpdateThumbnails();
  7427. this.onToggled();
  7428. }
  7429. if (isViewChanged) {
  7430. this.#dispatchEvent();
  7431. }
  7432. }
  7433. open() {
  7434. if (this.isOpen) {
  7435. return;
  7436. }
  7437. this.isOpen = true;
  7438. toggleExpandedBtn(this.toggleButton, true);
  7439. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7440. if (this.active === SidebarView.THUMBS) {
  7441. this.onUpdateThumbnails();
  7442. }
  7443. this.onToggled();
  7444. this.#dispatchEvent();
  7445. this.#hideUINotification();
  7446. }
  7447. close(evt = null) {
  7448. if (!this.isOpen) {
  7449. return;
  7450. }
  7451. this.isOpen = false;
  7452. toggleExpandedBtn(this.toggleButton, false);
  7453. this.outerContainer.classList.add("sidebarMoving");
  7454. this.outerContainer.classList.remove("sidebarOpen");
  7455. this.onToggled();
  7456. this.#dispatchEvent();
  7457. if (evt?.detail > 0) {
  7458. this.toggleButton.blur();
  7459. }
  7460. }
  7461. toggle(evt = null) {
  7462. if (this.isOpen) {
  7463. this.close(evt);
  7464. } else {
  7465. this.open();
  7466. }
  7467. }
  7468. #dispatchEvent() {
  7469. if (this.isInitialViewSet) {
  7470. this.isInitialEventDispatched ||= true;
  7471. }
  7472. this.eventBus.dispatch("sidebarviewchanged", {
  7473. source: this,
  7474. view: this.visibleView
  7475. });
  7476. }
  7477. #showUINotification() {
  7478. this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-notification-button");
  7479. if (!this.isOpen) {
  7480. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7481. }
  7482. }
  7483. #hideUINotification(reset = false) {
  7484. if (this.isOpen || reset) {
  7485. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7486. }
  7487. if (reset) {
  7488. this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-button");
  7489. }
  7490. }
  7491. #addEventListeners() {
  7492. this.sidebarContainer.addEventListener("transitionend", evt => {
  7493. if (evt.target === this.sidebarContainer) {
  7494. this.outerContainer.classList.remove("sidebarMoving");
  7495. this.eventBus.dispatch("resize", {
  7496. source: this
  7497. });
  7498. }
  7499. });
  7500. this.toggleButton.addEventListener("click", evt => {
  7501. this.toggle(evt);
  7502. });
  7503. this.thumbnailButton.addEventListener("click", () => {
  7504. this.switchView(SidebarView.THUMBS);
  7505. });
  7506. this.outlineButton.addEventListener("click", () => {
  7507. this.switchView(SidebarView.OUTLINE);
  7508. });
  7509. this.outlineButton.addEventListener("dblclick", () => {
  7510. this.eventBus.dispatch("toggleoutlinetree", {
  7511. source: this
  7512. });
  7513. });
  7514. this.attachmentsButton.addEventListener("click", () => {
  7515. this.switchView(SidebarView.ATTACHMENTS);
  7516. });
  7517. this.layersButton.addEventListener("click", () => {
  7518. this.switchView(SidebarView.LAYERS);
  7519. });
  7520. this.layersButton.addEventListener("dblclick", () => {
  7521. this.eventBus.dispatch("resetlayers", {
  7522. source: this
  7523. });
  7524. });
  7525. this._currentOutlineItemButton.addEventListener("click", () => {
  7526. this.eventBus.dispatch("currentoutlineitem", {
  7527. source: this
  7528. });
  7529. });
  7530. const onTreeLoaded = (count, button, view) => {
  7531. button.disabled = !count;
  7532. if (count) {
  7533. this.#showUINotification();
  7534. } else if (this.active === view) {
  7535. this.switchView(SidebarView.THUMBS);
  7536. }
  7537. };
  7538. this.eventBus._on("outlineloaded", evt => {
  7539. onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
  7540. evt.currentOutlineItemPromise.then(enabled => {
  7541. if (!this.isInitialViewSet) {
  7542. return;
  7543. }
  7544. this._currentOutlineItemButton.disabled = !enabled;
  7545. });
  7546. });
  7547. this.eventBus._on("attachmentsloaded", evt => {
  7548. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, SidebarView.ATTACHMENTS);
  7549. });
  7550. this.eventBus._on("layersloaded", evt => {
  7551. onTreeLoaded(evt.layersCount, this.layersButton, SidebarView.LAYERS);
  7552. });
  7553. this.eventBus._on("presentationmodechanged", evt => {
  7554. if (evt.state === PresentationModeState.NORMAL && this.visibleView === SidebarView.THUMBS) {
  7555. this.onUpdateThumbnails();
  7556. }
  7557. });
  7558. this.resizer.addEventListener("mousedown", evt => {
  7559. if (evt.button !== 0) {
  7560. return;
  7561. }
  7562. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7563. window.addEventListener("mousemove", this.#mouseMoveBound);
  7564. window.addEventListener("mouseup", this.#mouseUpBound);
  7565. });
  7566. this.eventBus._on("resize", evt => {
  7567. if (evt.source !== window) {
  7568. return;
  7569. }
  7570. this.#outerContainerWidth = null;
  7571. if (!this.#width) {
  7572. return;
  7573. }
  7574. if (!this.isOpen) {
  7575. this.#updateWidth(this.#width);
  7576. return;
  7577. }
  7578. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7579. const updated = this.#updateWidth(this.#width);
  7580. Promise.resolve().then(() => {
  7581. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7582. if (updated) {
  7583. this.eventBus.dispatch("resize", {
  7584. source: this
  7585. });
  7586. }
  7587. });
  7588. });
  7589. }
  7590. get outerContainerWidth() {
  7591. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  7592. }
  7593. #updateWidth(width = 0) {
  7594. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7595. if (width > maxWidth) {
  7596. width = maxWidth;
  7597. }
  7598. if (width < SIDEBAR_MIN_WIDTH) {
  7599. width = SIDEBAR_MIN_WIDTH;
  7600. }
  7601. if (width === this.#width) {
  7602. return false;
  7603. }
  7604. this.#width = width;
  7605. docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7606. return true;
  7607. }
  7608. #mouseMove(evt) {
  7609. let width = evt.clientX;
  7610. if (this.#isRTL) {
  7611. width = this.outerContainerWidth - width;
  7612. }
  7613. this.#updateWidth(width);
  7614. }
  7615. #mouseUp(evt) {
  7616. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7617. this.eventBus.dispatch("resize", {
  7618. source: this
  7619. });
  7620. window.removeEventListener("mousemove", this.#mouseMoveBound);
  7621. window.removeEventListener("mouseup", this.#mouseUpBound);
  7622. }
  7623. }
  7624. ;// CONCATENATED MODULE: ./web/pdf_thumbnail_view.js
  7625. const DRAW_UPSCALE_FACTOR = 2;
  7626. const MAX_NUM_SCALING_STEPS = 3;
  7627. const THUMBNAIL_WIDTH = 98;
  7628. class TempImageFactory {
  7629. static #tempCanvas = null;
  7630. static getCanvas(width, height) {
  7631. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7632. tempCanvas.width = width;
  7633. tempCanvas.height = height;
  7634. const ctx = tempCanvas.getContext("2d", {
  7635. alpha: false
  7636. });
  7637. ctx.save();
  7638. ctx.fillStyle = "rgb(255, 255, 255)";
  7639. ctx.fillRect(0, 0, width, height);
  7640. ctx.restore();
  7641. return [tempCanvas, tempCanvas.getContext("2d")];
  7642. }
  7643. static destroyCanvas() {
  7644. const tempCanvas = this.#tempCanvas;
  7645. if (tempCanvas) {
  7646. tempCanvas.width = 0;
  7647. tempCanvas.height = 0;
  7648. }
  7649. this.#tempCanvas = null;
  7650. }
  7651. }
  7652. class PDFThumbnailView {
  7653. constructor({
  7654. container,
  7655. eventBus,
  7656. id,
  7657. defaultViewport,
  7658. optionalContentConfigPromise,
  7659. linkService,
  7660. renderingQueue,
  7661. pageColors,
  7662. enableHWA
  7663. }) {
  7664. this.id = id;
  7665. this.renderingId = "thumbnail" + id;
  7666. this.pageLabel = null;
  7667. this.pdfPage = null;
  7668. this.rotation = 0;
  7669. this.viewport = defaultViewport;
  7670. this.pdfPageRotate = defaultViewport.rotation;
  7671. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7672. this.pageColors = pageColors || null;
  7673. this.enableHWA = enableHWA || false;
  7674. this.eventBus = eventBus;
  7675. this.linkService = linkService;
  7676. this.renderingQueue = renderingQueue;
  7677. this.renderTask = null;
  7678. this.renderingState = RenderingStates.INITIAL;
  7679. this.resume = null;
  7680. const anchor = document.createElement("a");
  7681. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7682. anchor.setAttribute("data-l10n-id", "pdfjs-thumb-page-title");
  7683. anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
  7684. anchor.onclick = function () {
  7685. linkService.goToPage(id);
  7686. return false;
  7687. };
  7688. this.anchor = anchor;
  7689. const div = document.createElement("div");
  7690. div.className = "thumbnail";
  7691. div.setAttribute("data-page-number", this.id);
  7692. this.div = div;
  7693. this.#updateDims();
  7694. const img = document.createElement("div");
  7695. img.className = "thumbnailImage";
  7696. this._placeholderImg = img;
  7697. div.append(img);
  7698. anchor.append(div);
  7699. container.append(anchor);
  7700. }
  7701. #updateDims() {
  7702. const {
  7703. width,
  7704. height
  7705. } = this.viewport;
  7706. const ratio = width / height;
  7707. this.canvasWidth = THUMBNAIL_WIDTH;
  7708. this.canvasHeight = this.canvasWidth / ratio | 0;
  7709. this.scale = this.canvasWidth / width;
  7710. const {
  7711. style
  7712. } = this.div;
  7713. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  7714. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  7715. }
  7716. setPdfPage(pdfPage) {
  7717. this.pdfPage = pdfPage;
  7718. this.pdfPageRotate = pdfPage.rotate;
  7719. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7720. this.viewport = pdfPage.getViewport({
  7721. scale: 1,
  7722. rotation: totalRotation
  7723. });
  7724. this.reset();
  7725. }
  7726. reset() {
  7727. this.cancelRendering();
  7728. this.renderingState = RenderingStates.INITIAL;
  7729. this.div.removeAttribute("data-loaded");
  7730. this.image?.replaceWith(this._placeholderImg);
  7731. this.#updateDims();
  7732. if (this.image) {
  7733. this.image.removeAttribute("src");
  7734. delete this.image;
  7735. }
  7736. }
  7737. update({
  7738. rotation = null
  7739. }) {
  7740. if (typeof rotation === "number") {
  7741. this.rotation = rotation;
  7742. }
  7743. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7744. this.viewport = this.viewport.clone({
  7745. scale: 1,
  7746. rotation: totalRotation
  7747. });
  7748. this.reset();
  7749. }
  7750. cancelRendering() {
  7751. if (this.renderTask) {
  7752. this.renderTask.cancel();
  7753. this.renderTask = null;
  7754. }
  7755. this.resume = null;
  7756. }
  7757. #getPageDrawContext(upscaleFactor = 1, enableHWA = this.enableHWA) {
  7758. const canvas = document.createElement("canvas");
  7759. const ctx = canvas.getContext("2d", {
  7760. alpha: false,
  7761. willReadFrequently: !enableHWA
  7762. });
  7763. const outputScale = new OutputScale();
  7764. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7765. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7766. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7767. return {
  7768. ctx,
  7769. canvas,
  7770. transform
  7771. };
  7772. }
  7773. #convertCanvasToImage(canvas) {
  7774. if (this.renderingState !== RenderingStates.FINISHED) {
  7775. throw new Error("#convertCanvasToImage: Rendering has not finished.");
  7776. }
  7777. const reducedCanvas = this.#reduceImage(canvas);
  7778. const image = document.createElement("img");
  7779. image.className = "thumbnailImage";
  7780. image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
  7781. image.setAttribute("data-l10n-args", this.#pageL10nArgs);
  7782. image.src = reducedCanvas.toDataURL();
  7783. this.image = image;
  7784. this.div.setAttribute("data-loaded", true);
  7785. this._placeholderImg.replaceWith(image);
  7786. reducedCanvas.width = 0;
  7787. reducedCanvas.height = 0;
  7788. }
  7789. async #finishRenderTask(renderTask, canvas, error = null) {
  7790. if (renderTask === this.renderTask) {
  7791. this.renderTask = null;
  7792. }
  7793. if (error instanceof RenderingCancelledException) {
  7794. return;
  7795. }
  7796. this.renderingState = RenderingStates.FINISHED;
  7797. this.#convertCanvasToImage(canvas);
  7798. if (error) {
  7799. throw error;
  7800. }
  7801. }
  7802. async draw() {
  7803. if (this.renderingState !== RenderingStates.INITIAL) {
  7804. console.error("Must be in new state before drawing");
  7805. return undefined;
  7806. }
  7807. const {
  7808. pdfPage
  7809. } = this;
  7810. if (!pdfPage) {
  7811. this.renderingState = RenderingStates.FINISHED;
  7812. throw new Error("pdfPage is not loaded");
  7813. }
  7814. this.renderingState = RenderingStates.RUNNING;
  7815. const {
  7816. ctx,
  7817. canvas,
  7818. transform
  7819. } = this.#getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7820. const drawViewport = this.viewport.clone({
  7821. scale: DRAW_UPSCALE_FACTOR * this.scale
  7822. });
  7823. const renderContinueCallback = cont => {
  7824. if (!this.renderingQueue.isHighestPriority(this)) {
  7825. this.renderingState = RenderingStates.PAUSED;
  7826. this.resume = () => {
  7827. this.renderingState = RenderingStates.RUNNING;
  7828. cont();
  7829. };
  7830. return;
  7831. }
  7832. cont();
  7833. };
  7834. const renderContext = {
  7835. canvasContext: ctx,
  7836. transform,
  7837. viewport: drawViewport,
  7838. optionalContentConfigPromise: this._optionalContentConfigPromise,
  7839. pageColors: this.pageColors
  7840. };
  7841. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7842. renderTask.onContinue = renderContinueCallback;
  7843. const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
  7844. resultPromise.finally(() => {
  7845. canvas.width = 0;
  7846. canvas.height = 0;
  7847. this.eventBus.dispatch("thumbnailrendered", {
  7848. source: this,
  7849. pageNumber: this.id,
  7850. pdfPage: this.pdfPage
  7851. });
  7852. });
  7853. return resultPromise;
  7854. }
  7855. setImage(pageView) {
  7856. if (this.renderingState !== RenderingStates.INITIAL) {
  7857. return;
  7858. }
  7859. const {
  7860. thumbnailCanvas: canvas,
  7861. pdfPage,
  7862. scale
  7863. } = pageView;
  7864. if (!canvas) {
  7865. return;
  7866. }
  7867. if (!this.pdfPage) {
  7868. this.setPdfPage(pdfPage);
  7869. }
  7870. if (scale < this.scale) {
  7871. return;
  7872. }
  7873. this.renderingState = RenderingStates.FINISHED;
  7874. this.#convertCanvasToImage(canvas);
  7875. }
  7876. #reduceImage(img) {
  7877. const {
  7878. ctx,
  7879. canvas
  7880. } = this.#getPageDrawContext(1, true);
  7881. if (img.width <= 2 * canvas.width) {
  7882. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7883. return canvas;
  7884. }
  7885. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7886. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7887. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7888. while (reducedWidth > img.width || reducedHeight > img.height) {
  7889. reducedWidth >>= 1;
  7890. reducedHeight >>= 1;
  7891. }
  7892. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7893. while (reducedWidth > 2 * canvas.width) {
  7894. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7895. reducedWidth >>= 1;
  7896. reducedHeight >>= 1;
  7897. }
  7898. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7899. return canvas;
  7900. }
  7901. get #pageL10nArgs() {
  7902. return JSON.stringify({
  7903. page: this.pageLabel ?? this.id
  7904. });
  7905. }
  7906. setPageLabel(label) {
  7907. this.pageLabel = typeof label === "string" ? label : null;
  7908. this.anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
  7909. if (this.renderingState !== RenderingStates.FINISHED) {
  7910. return;
  7911. }
  7912. this.image?.setAttribute("data-l10n-args", this.#pageL10nArgs);
  7913. }
  7914. }
  7915. ;// CONCATENATED MODULE: ./web/pdf_thumbnail_viewer.js
  7916. const THUMBNAIL_SCROLL_MARGIN = -19;
  7917. const THUMBNAIL_SELECTED_CLASS = "selected";
  7918. class PDFThumbnailViewer {
  7919. constructor({
  7920. container,
  7921. eventBus,
  7922. linkService,
  7923. renderingQueue,
  7924. pageColors,
  7925. abortSignal,
  7926. enableHWA
  7927. }) {
  7928. this.container = container;
  7929. this.eventBus = eventBus;
  7930. this.linkService = linkService;
  7931. this.renderingQueue = renderingQueue;
  7932. this.pageColors = pageColors || null;
  7933. this.enableHWA = enableHWA || false;
  7934. this.scroll = watchScroll(this.container, this.#scrollUpdated.bind(this), abortSignal);
  7935. this.#resetView();
  7936. }
  7937. #scrollUpdated() {
  7938. this.renderingQueue.renderHighestPriority();
  7939. }
  7940. getThumbnail(index) {
  7941. return this._thumbnails[index];
  7942. }
  7943. #getVisibleThumbs() {
  7944. return getVisibleElements({
  7945. scrollEl: this.container,
  7946. views: this._thumbnails
  7947. });
  7948. }
  7949. scrollThumbnailIntoView(pageNumber) {
  7950. if (!this.pdfDocument) {
  7951. return;
  7952. }
  7953. const thumbnailView = this._thumbnails[pageNumber - 1];
  7954. if (!thumbnailView) {
  7955. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7956. return;
  7957. }
  7958. if (pageNumber !== this._currentPageNumber) {
  7959. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7960. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7961. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7962. }
  7963. const {
  7964. first,
  7965. last,
  7966. views
  7967. } = this.#getVisibleThumbs();
  7968. if (views.length > 0) {
  7969. let shouldScroll = false;
  7970. if (pageNumber <= first.id || pageNumber >= last.id) {
  7971. shouldScroll = true;
  7972. } else {
  7973. for (const {
  7974. id,
  7975. percent
  7976. } of views) {
  7977. if (id !== pageNumber) {
  7978. continue;
  7979. }
  7980. shouldScroll = percent < 100;
  7981. break;
  7982. }
  7983. }
  7984. if (shouldScroll) {
  7985. scrollIntoView(thumbnailView.div, {
  7986. top: THUMBNAIL_SCROLL_MARGIN
  7987. });
  7988. }
  7989. }
  7990. this._currentPageNumber = pageNumber;
  7991. }
  7992. get pagesRotation() {
  7993. return this._pagesRotation;
  7994. }
  7995. set pagesRotation(rotation) {
  7996. if (!isValidRotation(rotation)) {
  7997. throw new Error("Invalid thumbnails rotation angle.");
  7998. }
  7999. if (!this.pdfDocument) {
  8000. return;
  8001. }
  8002. if (this._pagesRotation === rotation) {
  8003. return;
  8004. }
  8005. this._pagesRotation = rotation;
  8006. const updateArgs = {
  8007. rotation
  8008. };
  8009. for (const thumbnail of this._thumbnails) {
  8010. thumbnail.update(updateArgs);
  8011. }
  8012. }
  8013. cleanup() {
  8014. for (const thumbnail of this._thumbnails) {
  8015. if (thumbnail.renderingState !== RenderingStates.FINISHED) {
  8016. thumbnail.reset();
  8017. }
  8018. }
  8019. TempImageFactory.destroyCanvas();
  8020. }
  8021. #resetView() {
  8022. this._thumbnails = [];
  8023. this._currentPageNumber = 1;
  8024. this._pageLabels = null;
  8025. this._pagesRotation = 0;
  8026. this.container.textContent = "";
  8027. }
  8028. setDocument(pdfDocument) {
  8029. if (this.pdfDocument) {
  8030. this.#cancelRendering();
  8031. this.#resetView();
  8032. }
  8033. this.pdfDocument = pdfDocument;
  8034. if (!pdfDocument) {
  8035. return;
  8036. }
  8037. const firstPagePromise = pdfDocument.getPage(1);
  8038. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  8039. intent: "display"
  8040. });
  8041. firstPagePromise.then(firstPdfPage => {
  8042. const pagesCount = pdfDocument.numPages;
  8043. const viewport = firstPdfPage.getViewport({
  8044. scale: 1
  8045. });
  8046. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8047. const thumbnail = new PDFThumbnailView({
  8048. container: this.container,
  8049. eventBus: this.eventBus,
  8050. id: pageNum,
  8051. defaultViewport: viewport.clone(),
  8052. optionalContentConfigPromise,
  8053. linkService: this.linkService,
  8054. renderingQueue: this.renderingQueue,
  8055. pageColors: this.pageColors,
  8056. enableHWA: this.enableHWA
  8057. });
  8058. this._thumbnails.push(thumbnail);
  8059. }
  8060. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  8061. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  8062. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  8063. }).catch(reason => {
  8064. console.error("Unable to initialize thumbnail viewer", reason);
  8065. });
  8066. }
  8067. #cancelRendering() {
  8068. for (const thumbnail of this._thumbnails) {
  8069. thumbnail.cancelRendering();
  8070. }
  8071. }
  8072. setPageLabels(labels) {
  8073. if (!this.pdfDocument) {
  8074. return;
  8075. }
  8076. if (!labels) {
  8077. this._pageLabels = null;
  8078. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8079. this._pageLabels = null;
  8080. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  8081. } else {
  8082. this._pageLabels = labels;
  8083. }
  8084. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  8085. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8086. }
  8087. }
  8088. async #ensurePdfPageLoaded(thumbView) {
  8089. if (thumbView.pdfPage) {
  8090. return thumbView.pdfPage;
  8091. }
  8092. try {
  8093. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  8094. if (!thumbView.pdfPage) {
  8095. thumbView.setPdfPage(pdfPage);
  8096. }
  8097. return pdfPage;
  8098. } catch (reason) {
  8099. console.error("Unable to get page for thumb view", reason);
  8100. return null;
  8101. }
  8102. }
  8103. #getScrollAhead(visible) {
  8104. if (visible.first?.id === 1) {
  8105. return true;
  8106. } else if (visible.last?.id === this._thumbnails.length) {
  8107. return false;
  8108. }
  8109. return this.scroll.down;
  8110. }
  8111. forceRendering() {
  8112. const visibleThumbs = this.#getVisibleThumbs();
  8113. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  8114. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  8115. if (thumbView) {
  8116. this.#ensurePdfPageLoaded(thumbView).then(() => {
  8117. this.renderingQueue.renderView(thumbView);
  8118. });
  8119. return true;
  8120. }
  8121. return false;
  8122. }
  8123. }
  8124. ;// CONCATENATED MODULE: ./web/annotation_editor_layer_builder.js
  8125. class AnnotationEditorLayerBuilder {
  8126. #annotationLayer = null;
  8127. #drawLayer = null;
  8128. #onAppend = null;
  8129. #textLayer = null;
  8130. #uiManager;
  8131. constructor(options) {
  8132. this.pdfPage = options.pdfPage;
  8133. this.accessibilityManager = options.accessibilityManager;
  8134. this.l10n = options.l10n;
  8135. this.l10n ||= new genericl10n_GenericL10n();
  8136. this.annotationEditorLayer = null;
  8137. this.div = null;
  8138. this._cancelled = false;
  8139. this.#uiManager = options.uiManager;
  8140. this.#annotationLayer = options.annotationLayer || null;
  8141. this.#textLayer = options.textLayer || null;
  8142. this.#drawLayer = options.drawLayer || null;
  8143. this.#onAppend = options.onAppend || null;
  8144. }
  8145. async render(viewport, intent = "display") {
  8146. if (intent !== "display") {
  8147. return;
  8148. }
  8149. if (this._cancelled) {
  8150. return;
  8151. }
  8152. const clonedViewport = viewport.clone({
  8153. dontFlip: true
  8154. });
  8155. if (this.div) {
  8156. this.annotationEditorLayer.update({
  8157. viewport: clonedViewport
  8158. });
  8159. this.show();
  8160. return;
  8161. }
  8162. const div = this.div = document.createElement("div");
  8163. div.className = "annotationEditorLayer";
  8164. div.hidden = true;
  8165. div.dir = this.#uiManager.direction;
  8166. this.#onAppend?.(div);
  8167. this.annotationEditorLayer = new AnnotationEditorLayer({
  8168. uiManager: this.#uiManager,
  8169. div,
  8170. accessibilityManager: this.accessibilityManager,
  8171. pageIndex: this.pdfPage.pageNumber - 1,
  8172. l10n: this.l10n,
  8173. viewport: clonedViewport,
  8174. annotationLayer: this.#annotationLayer,
  8175. textLayer: this.#textLayer,
  8176. drawLayer: this.#drawLayer
  8177. });
  8178. const parameters = {
  8179. viewport: clonedViewport,
  8180. div,
  8181. annotations: null,
  8182. intent
  8183. };
  8184. this.annotationEditorLayer.render(parameters);
  8185. this.show();
  8186. }
  8187. cancel() {
  8188. this._cancelled = true;
  8189. if (!this.div) {
  8190. return;
  8191. }
  8192. this.annotationEditorLayer.destroy();
  8193. }
  8194. hide() {
  8195. if (!this.div) {
  8196. return;
  8197. }
  8198. this.div.hidden = true;
  8199. }
  8200. show() {
  8201. if (!this.div || this.annotationEditorLayer.isInvisible) {
  8202. return;
  8203. }
  8204. this.div.hidden = false;
  8205. }
  8206. }
  8207. ;// CONCATENATED MODULE: ./web/annotation_layer_builder.js
  8208. class AnnotationLayerBuilder {
  8209. #onAppend = null;
  8210. #eventAbortController = null;
  8211. constructor({
  8212. pdfPage,
  8213. linkService,
  8214. downloadManager,
  8215. annotationStorage = null,
  8216. imageResourcesPath = "",
  8217. renderForms = true,
  8218. enableScripting = false,
  8219. hasJSActionsPromise = null,
  8220. fieldObjectsPromise = null,
  8221. annotationCanvasMap = null,
  8222. accessibilityManager = null,
  8223. annotationEditorUIManager = null,
  8224. onAppend = null
  8225. }) {
  8226. this.pdfPage = pdfPage;
  8227. this.linkService = linkService;
  8228. this.downloadManager = downloadManager;
  8229. this.imageResourcesPath = imageResourcesPath;
  8230. this.renderForms = renderForms;
  8231. this.annotationStorage = annotationStorage;
  8232. this.enableScripting = enableScripting;
  8233. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  8234. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  8235. this._annotationCanvasMap = annotationCanvasMap;
  8236. this._accessibilityManager = accessibilityManager;
  8237. this._annotationEditorUIManager = annotationEditorUIManager;
  8238. this.#onAppend = onAppend;
  8239. this.annotationLayer = null;
  8240. this.div = null;
  8241. this._cancelled = false;
  8242. this._eventBus = linkService.eventBus;
  8243. }
  8244. async render(viewport, intent = "display") {
  8245. if (this.div) {
  8246. if (this._cancelled || !this.annotationLayer) {
  8247. return;
  8248. }
  8249. this.annotationLayer.update({
  8250. viewport: viewport.clone({
  8251. dontFlip: true
  8252. })
  8253. });
  8254. return;
  8255. }
  8256. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  8257. intent
  8258. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  8259. if (this._cancelled) {
  8260. return;
  8261. }
  8262. const div = this.div = document.createElement("div");
  8263. div.className = "annotationLayer";
  8264. this.#onAppend?.(div);
  8265. if (annotations.length === 0) {
  8266. this.hide();
  8267. return;
  8268. }
  8269. this.annotationLayer = new AnnotationLayer({
  8270. div,
  8271. accessibilityManager: this._accessibilityManager,
  8272. annotationCanvasMap: this._annotationCanvasMap,
  8273. annotationEditorUIManager: this._annotationEditorUIManager,
  8274. page: this.pdfPage,
  8275. viewport: viewport.clone({
  8276. dontFlip: true
  8277. })
  8278. });
  8279. await this.annotationLayer.render({
  8280. annotations,
  8281. imageResourcesPath: this.imageResourcesPath,
  8282. renderForms: this.renderForms,
  8283. linkService: this.linkService,
  8284. downloadManager: this.downloadManager,
  8285. annotationStorage: this.annotationStorage,
  8286. enableScripting: this.enableScripting,
  8287. hasJSActions,
  8288. fieldObjects
  8289. });
  8290. if (this.linkService.isInPresentationMode) {
  8291. this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
  8292. }
  8293. if (!this.#eventAbortController) {
  8294. this.#eventAbortController = new AbortController();
  8295. this._eventBus?._on("presentationmodechanged", evt => {
  8296. this.#updatePresentationModeState(evt.state);
  8297. }, {
  8298. signal: this.#eventAbortController.signal
  8299. });
  8300. }
  8301. }
  8302. cancel() {
  8303. this._cancelled = true;
  8304. this.#eventAbortController?.abort();
  8305. this.#eventAbortController = null;
  8306. }
  8307. hide() {
  8308. if (!this.div) {
  8309. return;
  8310. }
  8311. this.div.hidden = true;
  8312. }
  8313. hasEditableAnnotations() {
  8314. return !!this.annotationLayer?.hasEditableAnnotations();
  8315. }
  8316. #updatePresentationModeState(state) {
  8317. if (!this.div) {
  8318. return;
  8319. }
  8320. let disableFormElements = false;
  8321. switch (state) {
  8322. case PresentationModeState.FULLSCREEN:
  8323. disableFormElements = true;
  8324. break;
  8325. case PresentationModeState.NORMAL:
  8326. break;
  8327. default:
  8328. return;
  8329. }
  8330. for (const section of this.div.childNodes) {
  8331. if (section.hasAttribute("data-internal-link")) {
  8332. continue;
  8333. }
  8334. section.inert = disableFormElements;
  8335. }
  8336. }
  8337. }
  8338. ;// CONCATENATED MODULE: ./web/draw_layer_builder.js
  8339. class DrawLayerBuilder {
  8340. #drawLayer = null;
  8341. constructor(options) {
  8342. this.pageIndex = options.pageIndex;
  8343. }
  8344. async render(intent = "display") {
  8345. if (intent !== "display" || this.#drawLayer || this._cancelled) {
  8346. return;
  8347. }
  8348. this.#drawLayer = new DrawLayer({
  8349. pageIndex: this.pageIndex
  8350. });
  8351. }
  8352. cancel() {
  8353. this._cancelled = true;
  8354. if (!this.#drawLayer) {
  8355. return;
  8356. }
  8357. this.#drawLayer.destroy();
  8358. this.#drawLayer = null;
  8359. }
  8360. setParent(parent) {
  8361. this.#drawLayer?.setParent(parent);
  8362. }
  8363. getDrawLayer() {
  8364. return this.#drawLayer;
  8365. }
  8366. }
  8367. ;// CONCATENATED MODULE: ./web/struct_tree_layer_builder.js
  8368. const PDF_ROLE_TO_HTML_ROLE = {
  8369. Document: null,
  8370. DocumentFragment: null,
  8371. Part: "group",
  8372. Sect: "group",
  8373. Div: "group",
  8374. Aside: "note",
  8375. NonStruct: "none",
  8376. P: null,
  8377. H: "heading",
  8378. Title: null,
  8379. FENote: "note",
  8380. Sub: "group",
  8381. Lbl: null,
  8382. Span: null,
  8383. Em: null,
  8384. Strong: null,
  8385. Link: "link",
  8386. Annot: "note",
  8387. Form: "form",
  8388. Ruby: null,
  8389. RB: null,
  8390. RT: null,
  8391. RP: null,
  8392. Warichu: null,
  8393. WT: null,
  8394. WP: null,
  8395. L: "list",
  8396. LI: "listitem",
  8397. LBody: null,
  8398. Table: "table",
  8399. TR: "row",
  8400. TH: "columnheader",
  8401. TD: "cell",
  8402. THead: "columnheader",
  8403. TBody: null,
  8404. TFoot: null,
  8405. Caption: null,
  8406. Figure: "figure",
  8407. Formula: null,
  8408. Artifact: null
  8409. };
  8410. const HEADING_PATTERN = /^H(\d+)$/;
  8411. class StructTreeLayerBuilder {
  8412. #treeDom = undefined;
  8413. get renderingDone() {
  8414. return this.#treeDom !== undefined;
  8415. }
  8416. render(structTree) {
  8417. if (this.#treeDom !== undefined) {
  8418. return this.#treeDom;
  8419. }
  8420. const treeDom = this.#walk(structTree);
  8421. treeDom?.classList.add("structTree");
  8422. return this.#treeDom = treeDom;
  8423. }
  8424. hide() {
  8425. if (this.#treeDom && !this.#treeDom.hidden) {
  8426. this.#treeDom.hidden = true;
  8427. }
  8428. }
  8429. show() {
  8430. if (this.#treeDom?.hidden) {
  8431. this.#treeDom.hidden = false;
  8432. }
  8433. }
  8434. #setAttributes(structElement, htmlElement) {
  8435. const {
  8436. alt,
  8437. id,
  8438. lang
  8439. } = structElement;
  8440. if (alt !== undefined) {
  8441. htmlElement.setAttribute("aria-label", removeNullCharacters(alt));
  8442. }
  8443. if (id !== undefined) {
  8444. htmlElement.setAttribute("aria-owns", id);
  8445. }
  8446. if (lang !== undefined) {
  8447. htmlElement.setAttribute("lang", removeNullCharacters(lang, true));
  8448. }
  8449. }
  8450. #walk(node) {
  8451. if (!node) {
  8452. return null;
  8453. }
  8454. const element = document.createElement("span");
  8455. if ("role" in node) {
  8456. const {
  8457. role
  8458. } = node;
  8459. const match = role.match(HEADING_PATTERN);
  8460. if (match) {
  8461. element.setAttribute("role", "heading");
  8462. element.setAttribute("aria-level", match[1]);
  8463. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  8464. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  8465. }
  8466. }
  8467. this.#setAttributes(node, element);
  8468. if (node.children) {
  8469. if (node.children.length === 1 && "id" in node.children[0]) {
  8470. this.#setAttributes(node.children[0], element);
  8471. } else {
  8472. for (const kid of node.children) {
  8473. element.append(this.#walk(kid));
  8474. }
  8475. }
  8476. }
  8477. return element;
  8478. }
  8479. }
  8480. ;// CONCATENATED MODULE: ./web/text_accessibility.js
  8481. class TextAccessibilityManager {
  8482. #enabled = false;
  8483. #textChildren = null;
  8484. #textNodes = new Map();
  8485. #waitingElements = new Map();
  8486. setTextMapping(textDivs) {
  8487. this.#textChildren = textDivs;
  8488. }
  8489. static #compareElementPositions(e1, e2) {
  8490. const rect1 = e1.getBoundingClientRect();
  8491. const rect2 = e2.getBoundingClientRect();
  8492. if (rect1.width === 0 && rect1.height === 0) {
  8493. return +1;
  8494. }
  8495. if (rect2.width === 0 && rect2.height === 0) {
  8496. return -1;
  8497. }
  8498. const top1 = rect1.y;
  8499. const bot1 = rect1.y + rect1.height;
  8500. const mid1 = rect1.y + rect1.height / 2;
  8501. const top2 = rect2.y;
  8502. const bot2 = rect2.y + rect2.height;
  8503. const mid2 = rect2.y + rect2.height / 2;
  8504. if (mid1 <= top2 && mid2 >= bot1) {
  8505. return -1;
  8506. }
  8507. if (mid2 <= top1 && mid1 >= bot2) {
  8508. return +1;
  8509. }
  8510. const centerX1 = rect1.x + rect1.width / 2;
  8511. const centerX2 = rect2.x + rect2.width / 2;
  8512. return centerX1 - centerX2;
  8513. }
  8514. enable() {
  8515. if (this.#enabled) {
  8516. throw new Error("TextAccessibilityManager is already enabled.");
  8517. }
  8518. if (!this.#textChildren) {
  8519. throw new Error("Text divs and strings have not been set.");
  8520. }
  8521. this.#enabled = true;
  8522. this.#textChildren = this.#textChildren.slice();
  8523. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  8524. if (this.#textNodes.size > 0) {
  8525. const textChildren = this.#textChildren;
  8526. for (const [id, nodeIndex] of this.#textNodes) {
  8527. const element = document.getElementById(id);
  8528. if (!element) {
  8529. this.#textNodes.delete(id);
  8530. continue;
  8531. }
  8532. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  8533. }
  8534. }
  8535. for (const [element, isRemovable] of this.#waitingElements) {
  8536. this.addPointerInTextLayer(element, isRemovable);
  8537. }
  8538. this.#waitingElements.clear();
  8539. }
  8540. disable() {
  8541. if (!this.#enabled) {
  8542. return;
  8543. }
  8544. this.#waitingElements.clear();
  8545. this.#textChildren = null;
  8546. this.#enabled = false;
  8547. }
  8548. removePointerInTextLayer(element) {
  8549. if (!this.#enabled) {
  8550. this.#waitingElements.delete(element);
  8551. return;
  8552. }
  8553. const children = this.#textChildren;
  8554. if (!children || children.length === 0) {
  8555. return;
  8556. }
  8557. const {
  8558. id
  8559. } = element;
  8560. const nodeIndex = this.#textNodes.get(id);
  8561. if (nodeIndex === undefined) {
  8562. return;
  8563. }
  8564. const node = children[nodeIndex];
  8565. this.#textNodes.delete(id);
  8566. let owns = node.getAttribute("aria-owns");
  8567. if (owns?.includes(id)) {
  8568. owns = owns.split(" ").filter(x => x !== id).join(" ");
  8569. if (owns) {
  8570. node.setAttribute("aria-owns", owns);
  8571. } else {
  8572. node.removeAttribute("aria-owns");
  8573. node.setAttribute("role", "presentation");
  8574. }
  8575. }
  8576. }
  8577. #addIdToAriaOwns(id, node) {
  8578. const owns = node.getAttribute("aria-owns");
  8579. if (!owns?.includes(id)) {
  8580. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  8581. }
  8582. node.removeAttribute("role");
  8583. }
  8584. addPointerInTextLayer(element, isRemovable) {
  8585. const {
  8586. id
  8587. } = element;
  8588. if (!id) {
  8589. return null;
  8590. }
  8591. if (!this.#enabled) {
  8592. this.#waitingElements.set(element, isRemovable);
  8593. return null;
  8594. }
  8595. if (isRemovable) {
  8596. this.removePointerInTextLayer(element);
  8597. }
  8598. const children = this.#textChildren;
  8599. if (!children || children.length === 0) {
  8600. return null;
  8601. }
  8602. const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  8603. const nodeIndex = Math.max(0, index - 1);
  8604. const child = children[nodeIndex];
  8605. this.#addIdToAriaOwns(id, child);
  8606. this.#textNodes.set(id, nodeIndex);
  8607. const parent = child.parentNode;
  8608. return parent?.classList.contains("markedContent") ? parent.id : null;
  8609. }
  8610. moveElementInDOM(container, element, contentElement, isRemovable) {
  8611. const id = this.addPointerInTextLayer(contentElement, isRemovable);
  8612. if (!container.hasChildNodes()) {
  8613. container.append(element);
  8614. return id;
  8615. }
  8616. const children = Array.from(container.childNodes).filter(node => node !== element);
  8617. if (children.length === 0) {
  8618. return id;
  8619. }
  8620. const elementToCompare = contentElement || element;
  8621. const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  8622. if (index === 0) {
  8623. children[0].before(element);
  8624. } else {
  8625. children[index - 1].after(element);
  8626. }
  8627. return id;
  8628. }
  8629. }
  8630. ;// CONCATENATED MODULE: ./web/text_highlighter.js
  8631. class TextHighlighter {
  8632. #eventAbortController = null;
  8633. constructor({
  8634. findController,
  8635. eventBus,
  8636. pageIndex
  8637. }) {
  8638. this.findController = findController;
  8639. this.matches = [];
  8640. this.eventBus = eventBus;
  8641. this.pageIdx = pageIndex;
  8642. this.textDivs = null;
  8643. this.textContentItemsStr = null;
  8644. this.enabled = false;
  8645. }
  8646. setTextMapping(divs, texts) {
  8647. this.textDivs = divs;
  8648. this.textContentItemsStr = texts;
  8649. }
  8650. enable() {
  8651. if (!this.textDivs || !this.textContentItemsStr) {
  8652. throw new Error("Text divs and strings have not been set.");
  8653. }
  8654. if (this.enabled) {
  8655. throw new Error("TextHighlighter is already enabled.");
  8656. }
  8657. this.enabled = true;
  8658. if (!this.#eventAbortController) {
  8659. this.#eventAbortController = new AbortController();
  8660. this.eventBus._on("updatetextlayermatches", evt => {
  8661. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  8662. this._updateMatches();
  8663. }
  8664. }, {
  8665. signal: this.#eventAbortController.signal
  8666. });
  8667. }
  8668. this._updateMatches();
  8669. }
  8670. disable() {
  8671. if (!this.enabled) {
  8672. return;
  8673. }
  8674. this.enabled = false;
  8675. this.#eventAbortController?.abort();
  8676. this.#eventAbortController = null;
  8677. this._updateMatches(true);
  8678. }
  8679. _convertMatches(matches, matchesLength) {
  8680. if (!matches) {
  8681. return [];
  8682. }
  8683. const {
  8684. textContentItemsStr
  8685. } = this;
  8686. let i = 0,
  8687. iIndex = 0;
  8688. const end = textContentItemsStr.length - 1;
  8689. const result = [];
  8690. for (let m = 0, mm = matches.length; m < mm; m++) {
  8691. let matchIdx = matches[m];
  8692. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  8693. iIndex += textContentItemsStr[i].length;
  8694. i++;
  8695. }
  8696. if (i === textContentItemsStr.length) {
  8697. console.error("Could not find a matching mapping");
  8698. }
  8699. const match = {
  8700. begin: {
  8701. divIdx: i,
  8702. offset: matchIdx - iIndex
  8703. }
  8704. };
  8705. matchIdx += matchesLength[m];
  8706. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  8707. iIndex += textContentItemsStr[i].length;
  8708. i++;
  8709. }
  8710. match.end = {
  8711. divIdx: i,
  8712. offset: matchIdx - iIndex
  8713. };
  8714. result.push(match);
  8715. }
  8716. return result;
  8717. }
  8718. _renderMatches(matches) {
  8719. if (matches.length === 0) {
  8720. return;
  8721. }
  8722. const {
  8723. findController,
  8724. pageIdx
  8725. } = this;
  8726. const {
  8727. textContentItemsStr,
  8728. textDivs
  8729. } = this;
  8730. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  8731. const selectedMatchIdx = findController.selected.matchIdx;
  8732. const highlightAll = findController.state.highlightAll;
  8733. let prevEnd = null;
  8734. const infinity = {
  8735. divIdx: -1,
  8736. offset: undefined
  8737. };
  8738. function beginText(begin, className) {
  8739. const divIdx = begin.divIdx;
  8740. textDivs[divIdx].textContent = "";
  8741. return appendTextToDiv(divIdx, 0, begin.offset, className);
  8742. }
  8743. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  8744. let div = textDivs[divIdx];
  8745. if (div.nodeType === Node.TEXT_NODE) {
  8746. const span = document.createElement("span");
  8747. div.before(span);
  8748. span.append(div);
  8749. textDivs[divIdx] = span;
  8750. div = span;
  8751. }
  8752. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  8753. const node = document.createTextNode(content);
  8754. if (className) {
  8755. const span = document.createElement("span");
  8756. span.className = `${className} appended`;
  8757. span.append(node);
  8758. div.append(span);
  8759. return className.includes("selected") ? span.offsetLeft : 0;
  8760. }
  8761. div.append(node);
  8762. return 0;
  8763. }
  8764. let i0 = selectedMatchIdx,
  8765. i1 = i0 + 1;
  8766. if (highlightAll) {
  8767. i0 = 0;
  8768. i1 = matches.length;
  8769. } else if (!isSelectedPage) {
  8770. return;
  8771. }
  8772. let lastDivIdx = -1;
  8773. let lastOffset = -1;
  8774. for (let i = i0; i < i1; i++) {
  8775. const match = matches[i];
  8776. const begin = match.begin;
  8777. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  8778. continue;
  8779. }
  8780. lastDivIdx = begin.divIdx;
  8781. lastOffset = begin.offset;
  8782. const end = match.end;
  8783. const isSelected = isSelectedPage && i === selectedMatchIdx;
  8784. const highlightSuffix = isSelected ? " selected" : "";
  8785. let selectedLeft = 0;
  8786. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  8787. if (prevEnd !== null) {
  8788. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  8789. }
  8790. beginText(begin);
  8791. } else {
  8792. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  8793. }
  8794. if (begin.divIdx === end.divIdx) {
  8795. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  8796. } else {
  8797. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  8798. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  8799. textDivs[n0].className = "highlight middle" + highlightSuffix;
  8800. }
  8801. beginText(end, "highlight end" + highlightSuffix);
  8802. }
  8803. prevEnd = end;
  8804. if (isSelected) {
  8805. findController.scrollMatchIntoView({
  8806. element: textDivs[begin.divIdx],
  8807. selectedLeft,
  8808. pageIndex: pageIdx,
  8809. matchIndex: selectedMatchIdx
  8810. });
  8811. }
  8812. }
  8813. if (prevEnd) {
  8814. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  8815. }
  8816. }
  8817. _updateMatches(reset = false) {
  8818. if (!this.enabled && !reset) {
  8819. return;
  8820. }
  8821. const {
  8822. findController,
  8823. matches,
  8824. pageIdx
  8825. } = this;
  8826. const {
  8827. textContentItemsStr,
  8828. textDivs
  8829. } = this;
  8830. let clearedUntilDivIdx = -1;
  8831. for (const match of matches) {
  8832. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  8833. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  8834. const div = textDivs[n];
  8835. div.textContent = textContentItemsStr[n];
  8836. div.className = "";
  8837. }
  8838. clearedUntilDivIdx = match.end.divIdx + 1;
  8839. }
  8840. if (!findController?.highlightMatches || reset) {
  8841. return;
  8842. }
  8843. const pageMatches = findController.pageMatches[pageIdx] || null;
  8844. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  8845. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  8846. this._renderMatches(this.matches);
  8847. }
  8848. }
  8849. ;// CONCATENATED MODULE: ./web/text_layer_builder.js
  8850. class TextLayerBuilder {
  8851. #enablePermissions = false;
  8852. #onAppend = null;
  8853. #renderingDone = false;
  8854. #textLayer = null;
  8855. static #textLayers = new Map();
  8856. static #selectionChangeAbortController = null;
  8857. constructor({
  8858. pdfPage,
  8859. highlighter = null,
  8860. accessibilityManager = null,
  8861. enablePermissions = false,
  8862. onAppend = null
  8863. }) {
  8864. this.pdfPage = pdfPage;
  8865. this.highlighter = highlighter;
  8866. this.accessibilityManager = accessibilityManager;
  8867. this.#enablePermissions = enablePermissions === true;
  8868. this.#onAppend = onAppend;
  8869. this.div = document.createElement("div");
  8870. this.div.tabIndex = 0;
  8871. this.div.className = "textLayer";
  8872. }
  8873. async render(viewport, textContentParams = null) {
  8874. if (this.#renderingDone && this.#textLayer) {
  8875. this.#textLayer.update({
  8876. viewport,
  8877. onBefore: this.hide.bind(this)
  8878. });
  8879. this.show();
  8880. return;
  8881. }
  8882. this.cancel();
  8883. this.#textLayer = new TextLayer({
  8884. textContentSource: this.pdfPage.streamTextContent(textContentParams || {
  8885. includeMarkedContent: true,
  8886. disableNormalization: true
  8887. }),
  8888. container: this.div,
  8889. viewport
  8890. });
  8891. const {
  8892. textDivs,
  8893. textContentItemsStr
  8894. } = this.#textLayer;
  8895. this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
  8896. this.accessibilityManager?.setTextMapping(textDivs);
  8897. await this.#textLayer.render();
  8898. this.#renderingDone = true;
  8899. const endOfContent = document.createElement("div");
  8900. endOfContent.className = "endOfContent";
  8901. this.div.append(endOfContent);
  8902. this.#bindMouse(endOfContent);
  8903. this.#onAppend?.(this.div);
  8904. this.highlighter?.enable();
  8905. this.accessibilityManager?.enable();
  8906. }
  8907. hide() {
  8908. if (!this.div.hidden && this.#renderingDone) {
  8909. this.highlighter?.disable();
  8910. this.div.hidden = true;
  8911. }
  8912. }
  8913. show() {
  8914. if (this.div.hidden && this.#renderingDone) {
  8915. this.div.hidden = false;
  8916. this.highlighter?.enable();
  8917. }
  8918. }
  8919. cancel() {
  8920. this.#textLayer?.cancel();
  8921. this.#textLayer = null;
  8922. this.highlighter?.disable();
  8923. this.accessibilityManager?.disable();
  8924. TextLayerBuilder.#removeGlobalSelectionListener(this.div);
  8925. }
  8926. #bindMouse(end) {
  8927. const {
  8928. div
  8929. } = this;
  8930. div.addEventListener("mousedown", evt => {
  8931. end.classList.add("active");
  8932. });
  8933. div.addEventListener("copy", event => {
  8934. if (!this.#enablePermissions) {
  8935. const selection = document.getSelection();
  8936. event.clipboardData.setData("text/plain", removeNullCharacters(normalizeUnicode(selection.toString())));
  8937. }
  8938. event.preventDefault();
  8939. event.stopPropagation();
  8940. });
  8941. TextLayerBuilder.#textLayers.set(div, end);
  8942. TextLayerBuilder.#enableGlobalSelectionListener();
  8943. }
  8944. static #removeGlobalSelectionListener(textLayerDiv) {
  8945. this.#textLayers.delete(textLayerDiv);
  8946. if (this.#textLayers.size === 0) {
  8947. this.#selectionChangeAbortController?.abort();
  8948. this.#selectionChangeAbortController = null;
  8949. }
  8950. }
  8951. static #enableGlobalSelectionListener() {
  8952. if (this.#selectionChangeAbortController) {
  8953. return;
  8954. }
  8955. this.#selectionChangeAbortController = new AbortController();
  8956. const {
  8957. signal
  8958. } = this.#selectionChangeAbortController;
  8959. const reset = (end, textLayer) => {
  8960. textLayer.append(end);
  8961. end.style.width = "";
  8962. end.style.height = "";
  8963. end.classList.remove("active");
  8964. };
  8965. document.addEventListener("pointerup", () => {
  8966. this.#textLayers.forEach(reset);
  8967. }, {
  8968. signal
  8969. });
  8970. var isFirefox, prevRange;
  8971. document.addEventListener("selectionchange", () => {
  8972. const selection = document.getSelection();
  8973. if (selection.rangeCount === 0) {
  8974. this.#textLayers.forEach(reset);
  8975. return;
  8976. }
  8977. const activeTextLayers = new Set();
  8978. for (let i = 0; i < selection.rangeCount; i++) {
  8979. const range = selection.getRangeAt(i);
  8980. for (const textLayerDiv of this.#textLayers.keys()) {
  8981. if (!activeTextLayers.has(textLayerDiv) && range.intersectsNode(textLayerDiv)) {
  8982. activeTextLayers.add(textLayerDiv);
  8983. }
  8984. }
  8985. }
  8986. for (const [textLayerDiv, endDiv] of this.#textLayers) {
  8987. if (activeTextLayers.has(textLayerDiv)) {
  8988. endDiv.classList.add("active");
  8989. } else {
  8990. reset(endDiv, textLayerDiv);
  8991. }
  8992. }
  8993. isFirefox ??= getComputedStyle(this.#textLayers.values().next().value).getPropertyValue("-moz-user-select") === "none";
  8994. if (isFirefox) {
  8995. return;
  8996. }
  8997. const range = selection.getRangeAt(0);
  8998. const modifyStart = prevRange && (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 || range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0);
  8999. let anchor = modifyStart ? range.startContainer : range.endContainer;
  9000. if (anchor.nodeType === Node.TEXT_NODE) {
  9001. anchor = anchor.parentNode;
  9002. }
  9003. const parentTextLayer = anchor.parentElement.closest(".textLayer");
  9004. const endDiv = this.#textLayers.get(parentTextLayer);
  9005. if (endDiv) {
  9006. endDiv.style.width = parentTextLayer.style.width;
  9007. endDiv.style.height = parentTextLayer.style.height;
  9008. anchor.parentElement.insertBefore(endDiv, modifyStart ? anchor : anchor.nextSibling);
  9009. }
  9010. prevRange = range.cloneRange();
  9011. }, {
  9012. signal
  9013. });
  9014. }
  9015. }
  9016. ;// CONCATENATED MODULE: ./web/pdf_page_view.js
  9017. const DEFAULT_LAYER_PROPERTIES = null;
  9018. const LAYERS_ORDER = new Map([["canvasWrapper", 0], ["textLayer", 1], ["annotationLayer", 2], ["annotationEditorLayer", 3], ["xfaLayer", 3]]);
  9019. class PDFPageView {
  9020. #annotationMode = AnnotationMode.ENABLE_FORMS;
  9021. #enableHWA = false;
  9022. #hasRestrictedScaling = false;
  9023. #isEditing = false;
  9024. #layerProperties = null;
  9025. #loadingId = null;
  9026. #previousRotation = null;
  9027. #renderError = null;
  9028. #renderingState = RenderingStates.INITIAL;
  9029. #textLayerMode = TextLayerMode.ENABLE;
  9030. #useThumbnailCanvas = {
  9031. directDrawing: true,
  9032. initialOptionalContent: true,
  9033. regularAnnotations: true
  9034. };
  9035. #viewportMap = new WeakMap();
  9036. #layers = [null, null, null, null];
  9037. constructor(options) {
  9038. const container = options.container;
  9039. const defaultViewport = options.defaultViewport;
  9040. this.id = options.id;
  9041. this.renderingId = "page" + this.id;
  9042. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9043. this.pdfPage = null;
  9044. this.pageLabel = null;
  9045. this.rotation = 0;
  9046. this.scale = options.scale || DEFAULT_SCALE;
  9047. this.viewport = defaultViewport;
  9048. this.pdfPageRotate = defaultViewport.rotation;
  9049. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9050. this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
  9051. this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
  9052. this.imageResourcesPath = options.imageResourcesPath || "";
  9053. this.maxCanvasPixels = options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
  9054. this.pageColors = options.pageColors || null;
  9055. this.#enableHWA = options.enableHWA || false;
  9056. this.eventBus = options.eventBus;
  9057. this.renderingQueue = options.renderingQueue;
  9058. this.l10n = options.l10n;
  9059. this.l10n ||= new genericl10n_GenericL10n();
  9060. this.renderTask = null;
  9061. this.resume = null;
  9062. this._isStandalone = !this.renderingQueue?.hasViewer();
  9063. this._container = container;
  9064. this._annotationCanvasMap = null;
  9065. this.annotationLayer = null;
  9066. this.annotationEditorLayer = null;
  9067. this.textLayer = null;
  9068. this.zoomLayer = null;
  9069. this.xfaLayer = null;
  9070. this.structTreeLayer = null;
  9071. this.drawLayer = null;
  9072. const div = document.createElement("div");
  9073. div.className = "page";
  9074. div.setAttribute("data-page-number", this.id);
  9075. div.setAttribute("role", "region");
  9076. div.setAttribute("data-l10n-id", "pdfjs-page-landmark");
  9077. div.setAttribute("data-l10n-args", JSON.stringify({
  9078. page: this.id
  9079. }));
  9080. this.div = div;
  9081. this.#setDimensions();
  9082. container?.append(div);
  9083. if (this._isStandalone) {
  9084. container?.style.setProperty("--scale-factor", this.scale * PixelsPerInch.PDF_TO_CSS_UNITS);
  9085. const {
  9086. optionalContentConfigPromise
  9087. } = options;
  9088. if (optionalContentConfigPromise) {
  9089. optionalContentConfigPromise.then(optionalContentConfig => {
  9090. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9091. return;
  9092. }
  9093. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9094. });
  9095. }
  9096. if (!options.l10n) {
  9097. this.l10n.translate(this.div);
  9098. }
  9099. }
  9100. }
  9101. #addLayer(div, name) {
  9102. const pos = LAYERS_ORDER.get(name);
  9103. const oldDiv = this.#layers[pos];
  9104. this.#layers[pos] = div;
  9105. if (oldDiv) {
  9106. oldDiv.replaceWith(div);
  9107. return;
  9108. }
  9109. for (let i = pos - 1; i >= 0; i--) {
  9110. const layer = this.#layers[i];
  9111. if (layer) {
  9112. layer.after(div);
  9113. return;
  9114. }
  9115. }
  9116. this.div.prepend(div);
  9117. }
  9118. get renderingState() {
  9119. return this.#renderingState;
  9120. }
  9121. set renderingState(state) {
  9122. if (state === this.#renderingState) {
  9123. return;
  9124. }
  9125. this.#renderingState = state;
  9126. if (this.#loadingId) {
  9127. clearTimeout(this.#loadingId);
  9128. this.#loadingId = null;
  9129. }
  9130. switch (state) {
  9131. case RenderingStates.PAUSED:
  9132. this.div.classList.remove("loading");
  9133. break;
  9134. case RenderingStates.RUNNING:
  9135. this.div.classList.add("loadingIcon");
  9136. this.#loadingId = setTimeout(() => {
  9137. this.div.classList.add("loading");
  9138. this.#loadingId = null;
  9139. }, 0);
  9140. break;
  9141. case RenderingStates.INITIAL:
  9142. case RenderingStates.FINISHED:
  9143. this.div.classList.remove("loadingIcon", "loading");
  9144. break;
  9145. }
  9146. }
  9147. #setDimensions() {
  9148. const {
  9149. viewport
  9150. } = this;
  9151. if (this.pdfPage) {
  9152. if (this.#previousRotation === viewport.rotation) {
  9153. return;
  9154. }
  9155. this.#previousRotation = viewport.rotation;
  9156. }
  9157. setLayerDimensions(this.div, viewport, true, false);
  9158. }
  9159. setPdfPage(pdfPage) {
  9160. if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
  9161. this._container?.style.setProperty("--hcm-highlight-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  9162. this._container?.style.setProperty("--hcm-highlight-selected-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  9163. }
  9164. this.pdfPage = pdfPage;
  9165. this.pdfPageRotate = pdfPage.rotate;
  9166. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9167. this.viewport = pdfPage.getViewport({
  9168. scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
  9169. rotation: totalRotation
  9170. });
  9171. this.#setDimensions();
  9172. this.reset();
  9173. }
  9174. destroy() {
  9175. this.reset();
  9176. this.pdfPage?.cleanup();
  9177. }
  9178. hasEditableAnnotations() {
  9179. return !!this.annotationLayer?.hasEditableAnnotations();
  9180. }
  9181. get _textHighlighter() {
  9182. return shadow(this, "_textHighlighter", new TextHighlighter({
  9183. pageIndex: this.id - 1,
  9184. eventBus: this.eventBus,
  9185. findController: this.#layerProperties.findController
  9186. }));
  9187. }
  9188. #dispatchLayerRendered(name, error) {
  9189. this.eventBus.dispatch(name, {
  9190. source: this,
  9191. pageNumber: this.id,
  9192. error
  9193. });
  9194. }
  9195. async #renderAnnotationLayer() {
  9196. let error = null;
  9197. try {
  9198. await this.annotationLayer.render(this.viewport, "display");
  9199. } catch (ex) {
  9200. console.error(`#renderAnnotationLayer: "${ex}".`);
  9201. error = ex;
  9202. } finally {
  9203. this.#dispatchLayerRendered("annotationlayerrendered", error);
  9204. }
  9205. }
  9206. async #renderAnnotationEditorLayer() {
  9207. let error = null;
  9208. try {
  9209. await this.annotationEditorLayer.render(this.viewport, "display");
  9210. } catch (ex) {
  9211. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9212. error = ex;
  9213. } finally {
  9214. this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
  9215. }
  9216. }
  9217. async #renderDrawLayer() {
  9218. try {
  9219. await this.drawLayer.render("display");
  9220. } catch (ex) {
  9221. console.error(`#renderDrawLayer: "${ex}".`);
  9222. }
  9223. }
  9224. async #renderXfaLayer() {
  9225. let error = null;
  9226. try {
  9227. const result = await this.xfaLayer.render(this.viewport, "display");
  9228. if (result?.textDivs && this._textHighlighter) {
  9229. this.#buildXfaTextContentItems(result.textDivs);
  9230. }
  9231. } catch (ex) {
  9232. console.error(`#renderXfaLayer: "${ex}".`);
  9233. error = ex;
  9234. } finally {
  9235. if (this.xfaLayer?.div) {
  9236. this.l10n.pause();
  9237. this.#addLayer(this.xfaLayer.div, "xfaLayer");
  9238. this.l10n.resume();
  9239. }
  9240. this.#dispatchLayerRendered("xfalayerrendered", error);
  9241. }
  9242. }
  9243. async #renderTextLayer() {
  9244. if (!this.textLayer) {
  9245. return;
  9246. }
  9247. let error = null;
  9248. try {
  9249. await this.textLayer.render(this.viewport);
  9250. } catch (ex) {
  9251. if (ex instanceof AbortException) {
  9252. return;
  9253. }
  9254. console.error(`#renderTextLayer: "${ex}".`);
  9255. error = ex;
  9256. }
  9257. this.#dispatchLayerRendered("textlayerrendered", error);
  9258. this.#renderStructTreeLayer();
  9259. }
  9260. async #renderStructTreeLayer() {
  9261. if (!this.textLayer) {
  9262. return;
  9263. }
  9264. this.structTreeLayer ||= new StructTreeLayerBuilder();
  9265. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  9266. const treeDom = this.structTreeLayer?.render(tree);
  9267. if (treeDom) {
  9268. this.l10n.pause();
  9269. this.canvas?.append(treeDom);
  9270. this.l10n.resume();
  9271. }
  9272. this.structTreeLayer?.show();
  9273. }
  9274. async #buildXfaTextContentItems(textDivs) {
  9275. const text = await this.pdfPage.getTextContent();
  9276. const items = [];
  9277. for (const item of text.items) {
  9278. items.push(item.str);
  9279. }
  9280. this._textHighlighter.setTextMapping(textDivs, items);
  9281. this._textHighlighter.enable();
  9282. }
  9283. _resetZoomLayer(removeFromDOM = false) {
  9284. if (!this.zoomLayer) {
  9285. return;
  9286. }
  9287. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9288. this.#viewportMap.delete(zoomLayerCanvas);
  9289. zoomLayerCanvas.width = 0;
  9290. zoomLayerCanvas.height = 0;
  9291. if (removeFromDOM) {
  9292. this.zoomLayer.remove();
  9293. }
  9294. this.zoomLayer = null;
  9295. }
  9296. reset({
  9297. keepZoomLayer = false,
  9298. keepAnnotationLayer = false,
  9299. keepAnnotationEditorLayer = false,
  9300. keepXfaLayer = false,
  9301. keepTextLayer = false
  9302. } = {}) {
  9303. this.cancelRendering({
  9304. keepAnnotationLayer,
  9305. keepAnnotationEditorLayer,
  9306. keepXfaLayer,
  9307. keepTextLayer
  9308. });
  9309. this.renderingState = RenderingStates.INITIAL;
  9310. const div = this.div;
  9311. const childNodes = div.childNodes,
  9312. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9313. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9314. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  9315. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  9316. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  9317. for (let i = childNodes.length - 1; i >= 0; i--) {
  9318. const node = childNodes[i];
  9319. switch (node) {
  9320. case zoomLayerNode:
  9321. case annotationLayerNode:
  9322. case annotationEditorLayerNode:
  9323. case xfaLayerNode:
  9324. case textLayerNode:
  9325. continue;
  9326. }
  9327. node.remove();
  9328. const layerIndex = this.#layers.indexOf(node);
  9329. if (layerIndex >= 0) {
  9330. this.#layers[layerIndex] = null;
  9331. }
  9332. }
  9333. div.removeAttribute("data-loaded");
  9334. if (annotationLayerNode) {
  9335. this.annotationLayer.hide();
  9336. }
  9337. if (annotationEditorLayerNode) {
  9338. this.annotationEditorLayer.hide();
  9339. }
  9340. if (xfaLayerNode) {
  9341. this.xfaLayer.hide();
  9342. }
  9343. if (textLayerNode) {
  9344. this.textLayer.hide();
  9345. }
  9346. this.structTreeLayer?.hide();
  9347. if (!zoomLayerNode) {
  9348. if (this.canvas) {
  9349. this.#viewportMap.delete(this.canvas);
  9350. this.canvas.width = 0;
  9351. this.canvas.height = 0;
  9352. delete this.canvas;
  9353. }
  9354. this._resetZoomLayer();
  9355. }
  9356. }
  9357. toggleEditingMode(isEditing) {
  9358. if (!this.hasEditableAnnotations()) {
  9359. return;
  9360. }
  9361. this.#isEditing = isEditing;
  9362. this.reset({
  9363. keepZoomLayer: true,
  9364. keepAnnotationLayer: true,
  9365. keepAnnotationEditorLayer: true,
  9366. keepXfaLayer: true,
  9367. keepTextLayer: true
  9368. });
  9369. }
  9370. update({
  9371. scale = 0,
  9372. rotation = null,
  9373. optionalContentConfigPromise = null,
  9374. drawingDelay = -1
  9375. }) {
  9376. this.scale = scale || this.scale;
  9377. if (typeof rotation === "number") {
  9378. this.rotation = rotation;
  9379. }
  9380. if (optionalContentConfigPromise instanceof Promise) {
  9381. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9382. optionalContentConfigPromise.then(optionalContentConfig => {
  9383. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9384. return;
  9385. }
  9386. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9387. });
  9388. }
  9389. this.#useThumbnailCanvas.directDrawing = true;
  9390. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9391. this.viewport = this.viewport.clone({
  9392. scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
  9393. rotation: totalRotation
  9394. });
  9395. this.#setDimensions();
  9396. if (this._isStandalone) {
  9397. this._container?.style.setProperty("--scale-factor", this.viewport.scale);
  9398. }
  9399. if (this.canvas) {
  9400. let onlyCssZoom = false;
  9401. if (this.#hasRestrictedScaling) {
  9402. if (this.maxCanvasPixels === 0) {
  9403. onlyCssZoom = true;
  9404. } else if (this.maxCanvasPixels > 0) {
  9405. const {
  9406. width,
  9407. height
  9408. } = this.viewport;
  9409. const {
  9410. sx,
  9411. sy
  9412. } = this.outputScale;
  9413. onlyCssZoom = (Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels;
  9414. }
  9415. }
  9416. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  9417. if (postponeDrawing || onlyCssZoom) {
  9418. if (postponeDrawing && !onlyCssZoom && this.renderingState !== RenderingStates.FINISHED) {
  9419. this.cancelRendering({
  9420. keepZoomLayer: true,
  9421. keepAnnotationLayer: true,
  9422. keepAnnotationEditorLayer: true,
  9423. keepXfaLayer: true,
  9424. keepTextLayer: true,
  9425. cancelExtraDelay: drawingDelay
  9426. });
  9427. this.renderingState = RenderingStates.FINISHED;
  9428. this.#useThumbnailCanvas.directDrawing = false;
  9429. }
  9430. this.cssTransform({
  9431. target: this.canvas,
  9432. redrawAnnotationLayer: true,
  9433. redrawAnnotationEditorLayer: true,
  9434. redrawXfaLayer: true,
  9435. redrawTextLayer: !postponeDrawing,
  9436. hideTextLayer: postponeDrawing
  9437. });
  9438. if (postponeDrawing) {
  9439. return;
  9440. }
  9441. this.eventBus.dispatch("pagerendered", {
  9442. source: this,
  9443. pageNumber: this.id,
  9444. cssTransform: true,
  9445. timestamp: performance.now(),
  9446. error: this.#renderError
  9447. });
  9448. return;
  9449. }
  9450. if (!this.zoomLayer && !this.canvas.hidden) {
  9451. this.zoomLayer = this.canvas.parentNode;
  9452. this.zoomLayer.style.position = "absolute";
  9453. }
  9454. }
  9455. if (this.zoomLayer) {
  9456. this.cssTransform({
  9457. target: this.zoomLayer.firstChild
  9458. });
  9459. }
  9460. this.reset({
  9461. keepZoomLayer: true,
  9462. keepAnnotationLayer: true,
  9463. keepAnnotationEditorLayer: true,
  9464. keepXfaLayer: true,
  9465. keepTextLayer: true
  9466. });
  9467. }
  9468. cancelRendering({
  9469. keepAnnotationLayer = false,
  9470. keepAnnotationEditorLayer = false,
  9471. keepXfaLayer = false,
  9472. keepTextLayer = false,
  9473. cancelExtraDelay = 0
  9474. } = {}) {
  9475. if (this.renderTask) {
  9476. this.renderTask.cancel(cancelExtraDelay);
  9477. this.renderTask = null;
  9478. }
  9479. this.resume = null;
  9480. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  9481. this.textLayer.cancel();
  9482. this.textLayer = null;
  9483. }
  9484. if (this.structTreeLayer && !this.textLayer) {
  9485. this.structTreeLayer = null;
  9486. }
  9487. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  9488. this.annotationLayer.cancel();
  9489. this.annotationLayer = null;
  9490. this._annotationCanvasMap = null;
  9491. }
  9492. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  9493. if (this.drawLayer) {
  9494. this.drawLayer.cancel();
  9495. this.drawLayer = null;
  9496. }
  9497. this.annotationEditorLayer.cancel();
  9498. this.annotationEditorLayer = null;
  9499. }
  9500. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  9501. this.xfaLayer.cancel();
  9502. this.xfaLayer = null;
  9503. this._textHighlighter?.disable();
  9504. }
  9505. }
  9506. cssTransform({
  9507. target,
  9508. redrawAnnotationLayer = false,
  9509. redrawAnnotationEditorLayer = false,
  9510. redrawXfaLayer = false,
  9511. redrawTextLayer = false,
  9512. hideTextLayer = false
  9513. }) {
  9514. if (!target.hasAttribute("zooming")) {
  9515. target.setAttribute("zooming", true);
  9516. const {
  9517. style
  9518. } = target;
  9519. style.width = style.height = "";
  9520. }
  9521. const originalViewport = this.#viewportMap.get(target);
  9522. if (this.viewport !== originalViewport) {
  9523. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  9524. const absRotation = Math.abs(relativeRotation);
  9525. let scaleX = 1,
  9526. scaleY = 1;
  9527. if (absRotation === 90 || absRotation === 270) {
  9528. const {
  9529. width,
  9530. height
  9531. } = this.viewport;
  9532. scaleX = height / width;
  9533. scaleY = width / height;
  9534. }
  9535. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9536. }
  9537. if (redrawAnnotationLayer && this.annotationLayer) {
  9538. this.#renderAnnotationLayer();
  9539. }
  9540. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  9541. if (this.drawLayer) {
  9542. this.#renderDrawLayer();
  9543. }
  9544. this.#renderAnnotationEditorLayer();
  9545. }
  9546. if (redrawXfaLayer && this.xfaLayer) {
  9547. this.#renderXfaLayer();
  9548. }
  9549. if (this.textLayer) {
  9550. if (hideTextLayer) {
  9551. this.textLayer.hide();
  9552. this.structTreeLayer?.hide();
  9553. } else if (redrawTextLayer) {
  9554. this.#renderTextLayer();
  9555. }
  9556. }
  9557. }
  9558. get width() {
  9559. return this.viewport.width;
  9560. }
  9561. get height() {
  9562. return this.viewport.height;
  9563. }
  9564. getPagePoint(x, y) {
  9565. return this.viewport.convertToPdfPoint(x, y);
  9566. }
  9567. async #finishRenderTask(renderTask, error = null) {
  9568. if (renderTask === this.renderTask) {
  9569. this.renderTask = null;
  9570. }
  9571. if (error instanceof RenderingCancelledException) {
  9572. this.#renderError = null;
  9573. return;
  9574. }
  9575. this.#renderError = error;
  9576. this.renderingState = RenderingStates.FINISHED;
  9577. this._resetZoomLayer(true);
  9578. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  9579. this.eventBus.dispatch("pagerendered", {
  9580. source: this,
  9581. pageNumber: this.id,
  9582. cssTransform: false,
  9583. timestamp: performance.now(),
  9584. error: this.#renderError
  9585. });
  9586. if (error) {
  9587. throw error;
  9588. }
  9589. }
  9590. async draw() {
  9591. if (this.renderingState !== RenderingStates.INITIAL) {
  9592. console.error("Must be in new state before drawing");
  9593. this.reset();
  9594. }
  9595. const {
  9596. div,
  9597. l10n,
  9598. pageColors,
  9599. pdfPage,
  9600. viewport
  9601. } = this;
  9602. if (!pdfPage) {
  9603. this.renderingState = RenderingStates.FINISHED;
  9604. throw new Error("pdfPage is not loaded");
  9605. }
  9606. this.renderingState = RenderingStates.RUNNING;
  9607. const canvasWrapper = document.createElement("div");
  9608. canvasWrapper.classList.add("canvasWrapper");
  9609. this.#addLayer(canvasWrapper, "canvasWrapper");
  9610. if (!this.textLayer && this.#textLayerMode !== TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  9611. this._accessibilityManager ||= new TextAccessibilityManager();
  9612. this.textLayer = new TextLayerBuilder({
  9613. pdfPage,
  9614. highlighter: this._textHighlighter,
  9615. accessibilityManager: this._accessibilityManager,
  9616. enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
  9617. onAppend: textLayerDiv => {
  9618. this.l10n.pause();
  9619. this.#addLayer(textLayerDiv, "textLayer");
  9620. this.l10n.resume();
  9621. }
  9622. });
  9623. }
  9624. if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) {
  9625. const {
  9626. annotationStorage,
  9627. annotationEditorUIManager,
  9628. downloadManager,
  9629. enableScripting,
  9630. fieldObjectsPromise,
  9631. hasJSActionsPromise,
  9632. linkService
  9633. } = this.#layerProperties;
  9634. this._annotationCanvasMap ||= new Map();
  9635. this.annotationLayer = new AnnotationLayerBuilder({
  9636. pdfPage,
  9637. annotationStorage,
  9638. imageResourcesPath: this.imageResourcesPath,
  9639. renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS,
  9640. linkService,
  9641. downloadManager,
  9642. enableScripting,
  9643. hasJSActionsPromise,
  9644. fieldObjectsPromise,
  9645. annotationCanvasMap: this._annotationCanvasMap,
  9646. accessibilityManager: this._accessibilityManager,
  9647. annotationEditorUIManager,
  9648. onAppend: annotationLayerDiv => {
  9649. this.#addLayer(annotationLayerDiv, "annotationLayer");
  9650. }
  9651. });
  9652. }
  9653. const renderContinueCallback = cont => {
  9654. showCanvas?.(false);
  9655. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  9656. this.renderingState = RenderingStates.PAUSED;
  9657. this.resume = () => {
  9658. this.renderingState = RenderingStates.RUNNING;
  9659. cont();
  9660. };
  9661. return;
  9662. }
  9663. cont();
  9664. };
  9665. const {
  9666. width,
  9667. height
  9668. } = viewport;
  9669. const canvas = document.createElement("canvas");
  9670. canvas.setAttribute("role", "presentation");
  9671. canvas.hidden = true;
  9672. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  9673. let showCanvas = isLastShow => {
  9674. if (!hasHCM || isLastShow) {
  9675. canvas.hidden = false;
  9676. showCanvas = null;
  9677. }
  9678. };
  9679. canvasWrapper.append(canvas);
  9680. this.canvas = canvas;
  9681. const ctx = canvas.getContext("2d", {
  9682. alpha: false,
  9683. willReadFrequently: !this.#enableHWA
  9684. });
  9685. const outputScale = this.outputScale = new OutputScale();
  9686. if (this.maxCanvasPixels === 0) {
  9687. const invScale = 1 / this.scale;
  9688. outputScale.sx *= invScale;
  9689. outputScale.sy *= invScale;
  9690. this.#hasRestrictedScaling = true;
  9691. } else if (this.maxCanvasPixels > 0) {
  9692. const pixelsInViewport = width * height;
  9693. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9694. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9695. outputScale.sx = maxScale;
  9696. outputScale.sy = maxScale;
  9697. this.#hasRestrictedScaling = true;
  9698. } else {
  9699. this.#hasRestrictedScaling = false;
  9700. }
  9701. }
  9702. const sfx = approximateFraction(outputScale.sx);
  9703. const sfy = approximateFraction(outputScale.sy);
  9704. canvas.width = floorToDivide(width * outputScale.sx, sfx[0]);
  9705. canvas.height = floorToDivide(height * outputScale.sy, sfy[0]);
  9706. const {
  9707. style
  9708. } = canvas;
  9709. style.width = floorToDivide(width, sfx[1]) + "px";
  9710. style.height = floorToDivide(height, sfy[1]) + "px";
  9711. this.#viewportMap.set(canvas, viewport);
  9712. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  9713. const renderContext = {
  9714. canvasContext: ctx,
  9715. transform,
  9716. viewport,
  9717. annotationMode: this.#annotationMode,
  9718. optionalContentConfigPromise: this._optionalContentConfigPromise,
  9719. annotationCanvasMap: this._annotationCanvasMap,
  9720. pageColors,
  9721. isEditing: this.#isEditing
  9722. };
  9723. const renderTask = this.renderTask = pdfPage.render(renderContext);
  9724. renderTask.onContinue = renderContinueCallback;
  9725. const resultPromise = renderTask.promise.then(async () => {
  9726. showCanvas?.(true);
  9727. await this.#finishRenderTask(renderTask);
  9728. this.#renderTextLayer();
  9729. if (this.annotationLayer) {
  9730. await this.#renderAnnotationLayer();
  9731. }
  9732. const {
  9733. annotationEditorUIManager
  9734. } = this.#layerProperties;
  9735. if (!annotationEditorUIManager) {
  9736. return;
  9737. }
  9738. this.drawLayer ||= new DrawLayerBuilder({
  9739. pageIndex: this.id
  9740. });
  9741. await this.#renderDrawLayer();
  9742. this.drawLayer.setParent(canvasWrapper);
  9743. if (!this.annotationEditorLayer) {
  9744. this.annotationEditorLayer = new AnnotationEditorLayerBuilder({
  9745. uiManager: annotationEditorUIManager,
  9746. pdfPage,
  9747. l10n,
  9748. accessibilityManager: this._accessibilityManager,
  9749. annotationLayer: this.annotationLayer?.annotationLayer,
  9750. textLayer: this.textLayer,
  9751. drawLayer: this.drawLayer.getDrawLayer(),
  9752. onAppend: annotationEditorLayerDiv => {
  9753. this.#addLayer(annotationEditorLayerDiv, "annotationEditorLayer");
  9754. }
  9755. });
  9756. }
  9757. this.#renderAnnotationEditorLayer();
  9758. }, error => {
  9759. if (!(error instanceof RenderingCancelledException)) {
  9760. showCanvas?.(true);
  9761. }
  9762. return this.#finishRenderTask(renderTask, error);
  9763. });
  9764. if (pdfPage.isPureXfa) {
  9765. if (!this.xfaLayer) {
  9766. const {
  9767. annotationStorage,
  9768. linkService
  9769. } = this.#layerProperties;
  9770. this.xfaLayer = new XfaLayerBuilder({
  9771. pdfPage,
  9772. annotationStorage,
  9773. linkService
  9774. });
  9775. }
  9776. this.#renderXfaLayer();
  9777. }
  9778. div.setAttribute("data-loaded", true);
  9779. this.eventBus.dispatch("pagerender", {
  9780. source: this,
  9781. pageNumber: this.id
  9782. });
  9783. return resultPromise;
  9784. }
  9785. setPageLabel(label) {
  9786. this.pageLabel = typeof label === "string" ? label : null;
  9787. this.div.setAttribute("data-l10n-args", JSON.stringify({
  9788. page: this.pageLabel ?? this.id
  9789. }));
  9790. if (this.pageLabel !== null) {
  9791. this.div.setAttribute("data-page-label", this.pageLabel);
  9792. } else {
  9793. this.div.removeAttribute("data-page-label");
  9794. }
  9795. }
  9796. get thumbnailCanvas() {
  9797. const {
  9798. directDrawing,
  9799. initialOptionalContent,
  9800. regularAnnotations
  9801. } = this.#useThumbnailCanvas;
  9802. return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
  9803. }
  9804. }
  9805. ;// CONCATENATED MODULE: ./web/pdf_viewer.js
  9806. const DEFAULT_CACHE_SIZE = 10;
  9807. const PagesCountLimit = {
  9808. FORCE_SCROLL_MODE_PAGE: 10000,
  9809. FORCE_LAZY_PAGE_INIT: 5000,
  9810. PAUSE_EAGER_PAGE_INIT: 250
  9811. };
  9812. function isValidAnnotationEditorMode(mode) {
  9813. return Object.values(AnnotationEditorType).includes(mode) && mode !== AnnotationEditorType.DISABLE;
  9814. }
  9815. class PDFPageViewBuffer {
  9816. #buf = new Set();
  9817. #size = 0;
  9818. constructor(size) {
  9819. this.#size = size;
  9820. }
  9821. push(view) {
  9822. const buf = this.#buf;
  9823. if (buf.has(view)) {
  9824. buf.delete(view);
  9825. }
  9826. buf.add(view);
  9827. if (buf.size > this.#size) {
  9828. this.#destroyFirstView();
  9829. }
  9830. }
  9831. resize(newSize, idsToKeep = null) {
  9832. this.#size = newSize;
  9833. const buf = this.#buf;
  9834. if (idsToKeep) {
  9835. const ii = buf.size;
  9836. let i = 1;
  9837. for (const view of buf) {
  9838. if (idsToKeep.has(view.id)) {
  9839. buf.delete(view);
  9840. buf.add(view);
  9841. }
  9842. if (++i > ii) {
  9843. break;
  9844. }
  9845. }
  9846. }
  9847. while (buf.size > this.#size) {
  9848. this.#destroyFirstView();
  9849. }
  9850. }
  9851. has(view) {
  9852. return this.#buf.has(view);
  9853. }
  9854. [Symbol.iterator]() {
  9855. return this.#buf.keys();
  9856. }
  9857. #destroyFirstView() {
  9858. const firstView = this.#buf.keys().next().value;
  9859. firstView?.destroy();
  9860. this.#buf.delete(firstView);
  9861. }
  9862. }
  9863. class PDFViewer {
  9864. #buffer = null;
  9865. #altTextManager = null;
  9866. #annotationEditorHighlightColors = null;
  9867. #annotationEditorMode = AnnotationEditorType.NONE;
  9868. #annotationEditorUIManager = null;
  9869. #annotationMode = AnnotationMode.ENABLE_FORMS;
  9870. #containerTopLeft = null;
  9871. #enableHWA = false;
  9872. #enableHighlightFloatingButton = false;
  9873. #enablePermissions = false;
  9874. #enableUpdatedAddImage = false;
  9875. #eventAbortController = null;
  9876. #mlManager = null;
  9877. #onPageRenderedCallback = null;
  9878. #switchAnnotationEditorModeTimeoutId = null;
  9879. #getAllTextInProgress = false;
  9880. #hiddenCopyElement = null;
  9881. #interruptCopyCondition = false;
  9882. #previousContainerHeight = 0;
  9883. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  9884. #scrollModePageState = null;
  9885. #scaleTimeoutId = null;
  9886. #textLayerMode = TextLayerMode.ENABLE;
  9887. constructor(options) {
  9888. const viewerVersion = "4.5.136";
  9889. if (version !== viewerVersion) {
  9890. throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`);
  9891. }
  9892. this.container = options.container;
  9893. this.viewer = options.viewer || options.container.firstElementChild;
  9894. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  9895. throw new Error("Invalid `container` and/or `viewer` option.");
  9896. }
  9897. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  9898. throw new Error("The `container` must be absolutely positioned.");
  9899. }
  9900. this.#resizeObserver.observe(this.container);
  9901. this.eventBus = options.eventBus;
  9902. this.linkService = options.linkService || new SimpleLinkService();
  9903. this.downloadManager = options.downloadManager || null;
  9904. this.findController = options.findController || null;
  9905. this.#altTextManager = options.altTextManager || null;
  9906. if (this.findController) {
  9907. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  9908. }
  9909. this._scriptingManager = options.scriptingManager || null;
  9910. this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
  9911. this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
  9912. this.#annotationEditorMode = options.annotationEditorMode ?? AnnotationEditorType.NONE;
  9913. this.#annotationEditorHighlightColors = options.annotationEditorHighlightColors || null;
  9914. this.#enableHighlightFloatingButton = options.enableHighlightFloatingButton === true;
  9915. this.#enableUpdatedAddImage = options.enableUpdatedAddImage === true;
  9916. this.imageResourcesPath = options.imageResourcesPath || "";
  9917. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  9918. this.removePageBorders = options.removePageBorders || false;
  9919. this.maxCanvasPixels = options.maxCanvasPixels;
  9920. this.l10n = options.l10n;
  9921. this.l10n ||= new genericl10n_GenericL10n();
  9922. this.#enablePermissions = options.enablePermissions || false;
  9923. this.pageColors = options.pageColors || null;
  9924. this.#mlManager = options.mlManager || null;
  9925. this.#enableHWA = options.enableHWA || false;
  9926. this.defaultRenderingQueue = !options.renderingQueue;
  9927. if (this.defaultRenderingQueue) {
  9928. this.renderingQueue = new PDFRenderingQueue();
  9929. this.renderingQueue.setViewer(this);
  9930. } else {
  9931. this.renderingQueue = options.renderingQueue;
  9932. }
  9933. const {
  9934. abortSignal
  9935. } = options;
  9936. abortSignal?.addEventListener("abort", () => {
  9937. this.#resizeObserver.disconnect();
  9938. this.#resizeObserver = null;
  9939. }, {
  9940. once: true
  9941. });
  9942. this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this), abortSignal);
  9943. this.presentationModeState = PresentationModeState.UNKNOWN;
  9944. this._resetView();
  9945. if (this.removePageBorders) {
  9946. this.viewer.classList.add("removePageBorders");
  9947. }
  9948. this.#updateContainerHeightCss();
  9949. this.eventBus._on("thumbnailrendered", ({
  9950. pageNumber,
  9951. pdfPage
  9952. }) => {
  9953. const pageView = this._pages[pageNumber - 1];
  9954. if (!this.#buffer.has(pageView)) {
  9955. pdfPage?.cleanup();
  9956. }
  9957. });
  9958. if (!options.l10n) {
  9959. this.l10n.translate(this.container);
  9960. }
  9961. }
  9962. get pagesCount() {
  9963. return this._pages.length;
  9964. }
  9965. getPageView(index) {
  9966. return this._pages[index];
  9967. }
  9968. getCachedPageViews() {
  9969. return new Set(this.#buffer);
  9970. }
  9971. get pageViewsReady() {
  9972. return this._pages.every(pageView => pageView?.pdfPage);
  9973. }
  9974. get renderForms() {
  9975. return this.#annotationMode === AnnotationMode.ENABLE_FORMS;
  9976. }
  9977. get enableScripting() {
  9978. return !!this._scriptingManager;
  9979. }
  9980. get currentPageNumber() {
  9981. return this._currentPageNumber;
  9982. }
  9983. set currentPageNumber(val) {
  9984. if (!Number.isInteger(val)) {
  9985. throw new Error("Invalid page number.");
  9986. }
  9987. if (!this.pdfDocument) {
  9988. return;
  9989. }
  9990. if (!this._setCurrentPageNumber(val, true)) {
  9991. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  9992. }
  9993. }
  9994. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  9995. if (this._currentPageNumber === val) {
  9996. if (resetCurrentPageView) {
  9997. this.#resetCurrentPageView();
  9998. }
  9999. return true;
  10000. }
  10001. if (!(0 < val && val <= this.pagesCount)) {
  10002. return false;
  10003. }
  10004. const previous = this._currentPageNumber;
  10005. this._currentPageNumber = val;
  10006. this.eventBus.dispatch("pagechanging", {
  10007. source: this,
  10008. pageNumber: val,
  10009. pageLabel: this._pageLabels?.[val - 1] ?? null,
  10010. previous
  10011. });
  10012. if (resetCurrentPageView) {
  10013. this.#resetCurrentPageView();
  10014. }
  10015. return true;
  10016. }
  10017. get currentPageLabel() {
  10018. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  10019. }
  10020. set currentPageLabel(val) {
  10021. if (!this.pdfDocument) {
  10022. return;
  10023. }
  10024. let page = val | 0;
  10025. if (this._pageLabels) {
  10026. const i = this._pageLabels.indexOf(val);
  10027. if (i >= 0) {
  10028. page = i + 1;
  10029. }
  10030. }
  10031. if (!this._setCurrentPageNumber(page, true)) {
  10032. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  10033. }
  10034. }
  10035. get currentScale() {
  10036. return this._currentScale !== UNKNOWN_SCALE ? this._currentScale : DEFAULT_SCALE;
  10037. }
  10038. set currentScale(val) {
  10039. if (isNaN(val)) {
  10040. throw new Error("Invalid numeric scale.");
  10041. }
  10042. if (!this.pdfDocument) {
  10043. return;
  10044. }
  10045. this.#setScale(val, {
  10046. noScroll: false
  10047. });
  10048. }
  10049. get currentScaleValue() {
  10050. return this._currentScaleValue;
  10051. }
  10052. set currentScaleValue(val) {
  10053. if (!this.pdfDocument) {
  10054. return;
  10055. }
  10056. this.#setScale(val, {
  10057. noScroll: false
  10058. });
  10059. }
  10060. get pagesRotation() {
  10061. return this._pagesRotation;
  10062. }
  10063. set pagesRotation(rotation) {
  10064. if (!isValidRotation(rotation)) {
  10065. throw new Error("Invalid pages rotation angle.");
  10066. }
  10067. if (!this.pdfDocument) {
  10068. return;
  10069. }
  10070. rotation %= 360;
  10071. if (rotation < 0) {
  10072. rotation += 360;
  10073. }
  10074. if (this._pagesRotation === rotation) {
  10075. return;
  10076. }
  10077. this._pagesRotation = rotation;
  10078. const pageNumber = this._currentPageNumber;
  10079. this.refresh(true, {
  10080. rotation
  10081. });
  10082. if (this._currentScaleValue) {
  10083. this.#setScale(this._currentScaleValue, {
  10084. noScroll: true
  10085. });
  10086. }
  10087. this.eventBus.dispatch("rotationchanging", {
  10088. source: this,
  10089. pagesRotation: rotation,
  10090. pageNumber
  10091. });
  10092. if (this.defaultRenderingQueue) {
  10093. this.update();
  10094. }
  10095. }
  10096. get firstPagePromise() {
  10097. return this.pdfDocument ? this._firstPageCapability.promise : null;
  10098. }
  10099. get onePageRendered() {
  10100. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  10101. }
  10102. get pagesPromise() {
  10103. return this.pdfDocument ? this._pagesCapability.promise : null;
  10104. }
  10105. get _layerProperties() {
  10106. const self = this;
  10107. return shadow(this, "_layerProperties", {
  10108. get annotationEditorUIManager() {
  10109. return self.#annotationEditorUIManager;
  10110. },
  10111. get annotationStorage() {
  10112. return self.pdfDocument?.annotationStorage;
  10113. },
  10114. get downloadManager() {
  10115. return self.downloadManager;
  10116. },
  10117. get enableScripting() {
  10118. return !!self._scriptingManager;
  10119. },
  10120. get fieldObjectsPromise() {
  10121. return self.pdfDocument?.getFieldObjects();
  10122. },
  10123. get findController() {
  10124. return self.findController;
  10125. },
  10126. get hasJSActionsPromise() {
  10127. return self.pdfDocument?.hasJSActions();
  10128. },
  10129. get linkService() {
  10130. return self.linkService;
  10131. }
  10132. });
  10133. }
  10134. #initializePermissions(permissions) {
  10135. const params = {
  10136. annotationEditorMode: this.#annotationEditorMode,
  10137. annotationMode: this.#annotationMode,
  10138. textLayerMode: this.#textLayerMode
  10139. };
  10140. if (!permissions) {
  10141. return params;
  10142. }
  10143. if (!permissions.includes(PermissionFlag.COPY) && this.#textLayerMode === TextLayerMode.ENABLE) {
  10144. params.textLayerMode = TextLayerMode.ENABLE_PERMISSIONS;
  10145. }
  10146. if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) {
  10147. params.annotationEditorMode = AnnotationEditorType.DISABLE;
  10148. }
  10149. if (!permissions.includes(PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === AnnotationMode.ENABLE_FORMS) {
  10150. params.annotationMode = AnnotationMode.ENABLE;
  10151. }
  10152. return params;
  10153. }
  10154. async #onePageRenderedOrForceFetch(signal) {
  10155. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  10156. return;
  10157. }
  10158. const hiddenCapability = Promise.withResolvers();
  10159. function onVisibilityChange() {
  10160. if (document.visibilityState === "hidden") {
  10161. hiddenCapability.resolve();
  10162. }
  10163. }
  10164. document.addEventListener("visibilitychange", onVisibilityChange, {
  10165. signal
  10166. });
  10167. await Promise.race([this._onePageRenderedCapability.promise, hiddenCapability.promise]);
  10168. document.removeEventListener("visibilitychange", onVisibilityChange);
  10169. }
  10170. async getAllText() {
  10171. const texts = [];
  10172. const buffer = [];
  10173. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  10174. if (this.#interruptCopyCondition) {
  10175. return null;
  10176. }
  10177. buffer.length = 0;
  10178. const page = await this.pdfDocument.getPage(pageNum);
  10179. const {
  10180. items
  10181. } = await page.getTextContent();
  10182. for (const item of items) {
  10183. if (item.str) {
  10184. buffer.push(item.str);
  10185. }
  10186. if (item.hasEOL) {
  10187. buffer.push("\n");
  10188. }
  10189. }
  10190. texts.push(removeNullCharacters(buffer.join("")));
  10191. }
  10192. return texts.join("\n");
  10193. }
  10194. #copyCallback(textLayerMode, event) {
  10195. const selection = document.getSelection();
  10196. const {
  10197. focusNode,
  10198. anchorNode
  10199. } = selection;
  10200. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  10201. if (this.#getAllTextInProgress || textLayerMode === TextLayerMode.ENABLE_PERMISSIONS) {
  10202. event.preventDefault();
  10203. event.stopPropagation();
  10204. return;
  10205. }
  10206. this.#getAllTextInProgress = true;
  10207. const {
  10208. classList
  10209. } = this.viewer;
  10210. classList.add("copyAll");
  10211. const ac = new AbortController();
  10212. window.addEventListener("keydown", ev => this.#interruptCopyCondition = ev.key === "Escape", {
  10213. signal: ac.signal
  10214. });
  10215. this.getAllText().then(async text => {
  10216. if (text !== null) {
  10217. await navigator.clipboard.writeText(text);
  10218. }
  10219. }).catch(reason => {
  10220. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  10221. }).finally(() => {
  10222. this.#getAllTextInProgress = false;
  10223. this.#interruptCopyCondition = false;
  10224. ac.abort();
  10225. classList.remove("copyAll");
  10226. });
  10227. event.preventDefault();
  10228. event.stopPropagation();
  10229. }
  10230. }
  10231. setDocument(pdfDocument) {
  10232. if (this.pdfDocument) {
  10233. this.eventBus.dispatch("pagesdestroy", {
  10234. source: this
  10235. });
  10236. this._cancelRendering();
  10237. this._resetView();
  10238. this.findController?.setDocument(null);
  10239. this._scriptingManager?.setDocument(null);
  10240. if (this.#annotationEditorUIManager) {
  10241. this.#annotationEditorUIManager.destroy();
  10242. this.#annotationEditorUIManager = null;
  10243. }
  10244. }
  10245. this.pdfDocument = pdfDocument;
  10246. if (!pdfDocument) {
  10247. return;
  10248. }
  10249. const pagesCount = pdfDocument.numPages;
  10250. const firstPagePromise = pdfDocument.getPage(1);
  10251. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  10252. intent: "display"
  10253. });
  10254. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  10255. const {
  10256. eventBus,
  10257. pageColors,
  10258. viewer
  10259. } = this;
  10260. this.#eventAbortController = new AbortController();
  10261. const {
  10262. signal
  10263. } = this.#eventAbortController;
  10264. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  10265. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  10266. const mode = this._scrollMode = ScrollMode.PAGE;
  10267. eventBus.dispatch("scrollmodechanged", {
  10268. source: this,
  10269. mode
  10270. });
  10271. }
  10272. this._pagesCapability.promise.then(() => {
  10273. eventBus.dispatch("pagesloaded", {
  10274. source: this,
  10275. pagesCount
  10276. });
  10277. }, () => {});
  10278. const onBeforeDraw = evt => {
  10279. const pageView = this._pages[evt.pageNumber - 1];
  10280. if (!pageView) {
  10281. return;
  10282. }
  10283. this.#buffer.push(pageView);
  10284. };
  10285. eventBus._on("pagerender", onBeforeDraw, {
  10286. signal
  10287. });
  10288. const onAfterDraw = evt => {
  10289. if (evt.cssTransform) {
  10290. return;
  10291. }
  10292. this._onePageRenderedCapability.resolve({
  10293. timestamp: evt.timestamp
  10294. });
  10295. eventBus._off("pagerendered", onAfterDraw);
  10296. };
  10297. eventBus._on("pagerendered", onAfterDraw, {
  10298. signal
  10299. });
  10300. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  10301. if (pdfDocument !== this.pdfDocument) {
  10302. return;
  10303. }
  10304. this._firstPageCapability.resolve(firstPdfPage);
  10305. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10306. const {
  10307. annotationEditorMode,
  10308. annotationMode,
  10309. textLayerMode
  10310. } = this.#initializePermissions(permissions);
  10311. if (textLayerMode !== TextLayerMode.DISABLE) {
  10312. const element = this.#hiddenCopyElement = document.createElement("div");
  10313. element.id = "hiddenCopyElement";
  10314. viewer.before(element);
  10315. }
  10316. if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
  10317. const mode = annotationEditorMode;
  10318. if (pdfDocument.isPureXfa) {
  10319. console.warn("Warning: XFA-editing is not implemented.");
  10320. } else if (isValidAnnotationEditorMode(mode)) {
  10321. this.#annotationEditorUIManager = new AnnotationEditorUIManager(this.container, viewer, this.#altTextManager, eventBus, pdfDocument, pageColors, this.#annotationEditorHighlightColors, this.#enableHighlightFloatingButton, this.#enableUpdatedAddImage, this.#mlManager);
  10322. eventBus.dispatch("annotationeditoruimanager", {
  10323. source: this,
  10324. uiManager: this.#annotationEditorUIManager
  10325. });
  10326. if (mode !== AnnotationEditorType.NONE) {
  10327. this.#annotationEditorUIManager.updateMode(mode);
  10328. }
  10329. } else {
  10330. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  10331. }
  10332. }
  10333. const viewerElement = this._scrollMode === ScrollMode.PAGE ? null : viewer;
  10334. const scale = this.currentScale;
  10335. const viewport = firstPdfPage.getViewport({
  10336. scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS
  10337. });
  10338. viewer.style.setProperty("--scale-factor", viewport.scale);
  10339. if (pageColors?.foreground === "CanvasText" || pageColors?.background === "Canvas") {
  10340. viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  10341. viewer.style.setProperty("--hcm-highlight-selected-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "ButtonText"));
  10342. }
  10343. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  10344. const pageView = new PDFPageView({
  10345. container: viewerElement,
  10346. eventBus,
  10347. id: pageNum,
  10348. scale,
  10349. defaultViewport: viewport.clone(),
  10350. optionalContentConfigPromise,
  10351. renderingQueue: this.renderingQueue,
  10352. textLayerMode,
  10353. annotationMode,
  10354. imageResourcesPath: this.imageResourcesPath,
  10355. maxCanvasPixels: this.maxCanvasPixels,
  10356. pageColors,
  10357. l10n: this.l10n,
  10358. layerProperties: this._layerProperties,
  10359. enableHWA: this.#enableHWA
  10360. });
  10361. this._pages.push(pageView);
  10362. }
  10363. this._pages[0]?.setPdfPage(firstPdfPage);
  10364. if (this._scrollMode === ScrollMode.PAGE) {
  10365. this.#ensurePageViewVisible();
  10366. } else if (this._spreadMode !== SpreadMode.NONE) {
  10367. this._updateSpreadMode();
  10368. }
  10369. this.#onePageRenderedOrForceFetch(signal).then(async () => {
  10370. if (pdfDocument !== this.pdfDocument) {
  10371. return;
  10372. }
  10373. this.findController?.setDocument(pdfDocument);
  10374. this._scriptingManager?.setDocument(pdfDocument);
  10375. if (this.#hiddenCopyElement) {
  10376. document.addEventListener("copy", this.#copyCallback.bind(this, textLayerMode), {
  10377. signal
  10378. });
  10379. }
  10380. if (this.#annotationEditorUIManager) {
  10381. eventBus.dispatch("annotationeditormodechanged", {
  10382. source: this,
  10383. mode: this.#annotationEditorMode
  10384. });
  10385. }
  10386. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  10387. this._pagesCapability.resolve();
  10388. return;
  10389. }
  10390. let getPagesLeft = pagesCount - 1;
  10391. if (getPagesLeft <= 0) {
  10392. this._pagesCapability.resolve();
  10393. return;
  10394. }
  10395. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  10396. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  10397. const pageView = this._pages[pageNum - 1];
  10398. if (!pageView.pdfPage) {
  10399. pageView.setPdfPage(pdfPage);
  10400. }
  10401. if (--getPagesLeft === 0) {
  10402. this._pagesCapability.resolve();
  10403. }
  10404. }, reason => {
  10405. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  10406. if (--getPagesLeft === 0) {
  10407. this._pagesCapability.resolve();
  10408. }
  10409. });
  10410. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  10411. await promise;
  10412. }
  10413. }
  10414. });
  10415. eventBus.dispatch("pagesinit", {
  10416. source: this
  10417. });
  10418. pdfDocument.getMetadata().then(({
  10419. info
  10420. }) => {
  10421. if (pdfDocument !== this.pdfDocument) {
  10422. return;
  10423. }
  10424. if (info.Language) {
  10425. viewer.lang = info.Language;
  10426. }
  10427. });
  10428. if (this.defaultRenderingQueue) {
  10429. this.update();
  10430. }
  10431. }).catch(reason => {
  10432. console.error("Unable to initialize viewer", reason);
  10433. this._pagesCapability.reject(reason);
  10434. });
  10435. }
  10436. setPageLabels(labels) {
  10437. if (!this.pdfDocument) {
  10438. return;
  10439. }
  10440. if (!labels) {
  10441. this._pageLabels = null;
  10442. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  10443. this._pageLabels = null;
  10444. console.error(`setPageLabels: Invalid page labels.`);
  10445. } else {
  10446. this._pageLabels = labels;
  10447. }
  10448. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  10449. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  10450. }
  10451. }
  10452. _resetView() {
  10453. this._pages = [];
  10454. this._currentPageNumber = 1;
  10455. this._currentScale = UNKNOWN_SCALE;
  10456. this._currentScaleValue = null;
  10457. this._pageLabels = null;
  10458. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  10459. this._location = null;
  10460. this._pagesRotation = 0;
  10461. this._optionalContentConfigPromise = null;
  10462. this._firstPageCapability = Promise.withResolvers();
  10463. this._onePageRenderedCapability = Promise.withResolvers();
  10464. this._pagesCapability = Promise.withResolvers();
  10465. this._scrollMode = ScrollMode.VERTICAL;
  10466. this._previousScrollMode = ScrollMode.UNKNOWN;
  10467. this._spreadMode = SpreadMode.NONE;
  10468. this.#scrollModePageState = {
  10469. previousPageNumber: 1,
  10470. scrollDown: true,
  10471. pages: []
  10472. };
  10473. this.#eventAbortController?.abort();
  10474. this.#eventAbortController = null;
  10475. this.viewer.textContent = "";
  10476. this._updateScrollMode();
  10477. this.viewer.removeAttribute("lang");
  10478. this.#hiddenCopyElement?.remove();
  10479. this.#hiddenCopyElement = null;
  10480. this.#cleanupSwitchAnnotationEditorMode();
  10481. }
  10482. #ensurePageViewVisible() {
  10483. if (this._scrollMode !== ScrollMode.PAGE) {
  10484. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  10485. }
  10486. const pageNumber = this._currentPageNumber,
  10487. state = this.#scrollModePageState,
  10488. viewer = this.viewer;
  10489. viewer.textContent = "";
  10490. state.pages.length = 0;
  10491. if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) {
  10492. const pageView = this._pages[pageNumber - 1];
  10493. viewer.append(pageView.div);
  10494. state.pages.push(pageView);
  10495. } else {
  10496. const pageIndexSet = new Set(),
  10497. parity = this._spreadMode - 1;
  10498. if (parity === -1) {
  10499. pageIndexSet.add(pageNumber - 1);
  10500. } else if (pageNumber % 2 !== parity) {
  10501. pageIndexSet.add(pageNumber - 1);
  10502. pageIndexSet.add(pageNumber);
  10503. } else {
  10504. pageIndexSet.add(pageNumber - 2);
  10505. pageIndexSet.add(pageNumber - 1);
  10506. }
  10507. const spread = document.createElement("div");
  10508. spread.className = "spread";
  10509. if (this.isInPresentationMode) {
  10510. const dummyPage = document.createElement("div");
  10511. dummyPage.className = "dummyPage";
  10512. spread.append(dummyPage);
  10513. }
  10514. for (const i of pageIndexSet) {
  10515. const pageView = this._pages[i];
  10516. if (!pageView) {
  10517. continue;
  10518. }
  10519. spread.append(pageView.div);
  10520. state.pages.push(pageView);
  10521. }
  10522. viewer.append(spread);
  10523. }
  10524. state.scrollDown = pageNumber >= state.previousPageNumber;
  10525. state.previousPageNumber = pageNumber;
  10526. }
  10527. _scrollUpdate() {
  10528. if (this.pagesCount === 0) {
  10529. return;
  10530. }
  10531. this.update();
  10532. }
  10533. #scrollIntoView(pageView, pageSpot = null) {
  10534. const {
  10535. div,
  10536. id
  10537. } = pageView;
  10538. if (this._currentPageNumber !== id) {
  10539. this._setCurrentPageNumber(id);
  10540. }
  10541. if (this._scrollMode === ScrollMode.PAGE) {
  10542. this.#ensurePageViewVisible();
  10543. this.update();
  10544. }
  10545. if (!pageSpot && !this.isInPresentationMode) {
  10546. const left = div.offsetLeft + div.clientLeft,
  10547. right = left + div.clientWidth;
  10548. const {
  10549. scrollLeft,
  10550. clientWidth
  10551. } = this.container;
  10552. if (this._scrollMode === ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  10553. pageSpot = {
  10554. left: 0,
  10555. top: 0
  10556. };
  10557. }
  10558. }
  10559. scrollIntoView(div, pageSpot);
  10560. if (!this._currentScaleValue && this._location) {
  10561. this._location = null;
  10562. }
  10563. }
  10564. #isSameScale(newScale) {
  10565. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  10566. }
  10567. #setScaleUpdatePages(newScale, newValue, {
  10568. noScroll = false,
  10569. preset = false,
  10570. drawingDelay = -1,
  10571. origin = null
  10572. }) {
  10573. this._currentScaleValue = newValue.toString();
  10574. if (this.#isSameScale(newScale)) {
  10575. if (preset) {
  10576. this.eventBus.dispatch("scalechanging", {
  10577. source: this,
  10578. scale: newScale,
  10579. presetValue: newValue
  10580. });
  10581. }
  10582. return;
  10583. }
  10584. this.viewer.style.setProperty("--scale-factor", newScale * PixelsPerInch.PDF_TO_CSS_UNITS);
  10585. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  10586. this.refresh(true, {
  10587. scale: newScale,
  10588. drawingDelay: postponeDrawing ? drawingDelay : -1
  10589. });
  10590. if (postponeDrawing) {
  10591. this.#scaleTimeoutId = setTimeout(() => {
  10592. this.#scaleTimeoutId = null;
  10593. this.refresh();
  10594. }, drawingDelay);
  10595. }
  10596. const previousScale = this._currentScale;
  10597. this._currentScale = newScale;
  10598. if (!noScroll) {
  10599. let page = this._currentPageNumber,
  10600. dest;
  10601. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  10602. page = this._location.pageNumber;
  10603. dest = [null, {
  10604. name: "XYZ"
  10605. }, this._location.left, this._location.top, null];
  10606. }
  10607. this.scrollPageIntoView({
  10608. pageNumber: page,
  10609. destArray: dest,
  10610. allowNegativeOffset: true
  10611. });
  10612. if (Array.isArray(origin)) {
  10613. const scaleDiff = newScale / previousScale - 1;
  10614. const [top, left] = this.containerTopLeft;
  10615. this.container.scrollLeft += (origin[0] - left) * scaleDiff;
  10616. this.container.scrollTop += (origin[1] - top) * scaleDiff;
  10617. }
  10618. }
  10619. this.eventBus.dispatch("scalechanging", {
  10620. source: this,
  10621. scale: newScale,
  10622. presetValue: preset ? newValue : undefined
  10623. });
  10624. if (this.defaultRenderingQueue) {
  10625. this.update();
  10626. }
  10627. }
  10628. get #pageWidthScaleFactor() {
  10629. if (this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL) {
  10630. return 2;
  10631. }
  10632. return 1;
  10633. }
  10634. #setScale(value, options) {
  10635. let scale = parseFloat(value);
  10636. if (scale > 0) {
  10637. options.preset = false;
  10638. this.#setScaleUpdatePages(scale, value, options);
  10639. } else {
  10640. const currentPage = this._pages[this._currentPageNumber - 1];
  10641. if (!currentPage) {
  10642. return;
  10643. }
  10644. let hPadding = SCROLLBAR_PADDING,
  10645. vPadding = VERTICAL_PADDING;
  10646. if (this.isInPresentationMode) {
  10647. hPadding = vPadding = 4;
  10648. if (this._spreadMode !== SpreadMode.NONE) {
  10649. hPadding *= 2;
  10650. }
  10651. } else if (this.removePageBorders) {
  10652. hPadding = vPadding = 0;
  10653. } else if (this._scrollMode === ScrollMode.HORIZONTAL) {
  10654. [hPadding, vPadding] = [vPadding, hPadding];
  10655. }
  10656. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  10657. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  10658. switch (value) {
  10659. case "page-actual":
  10660. scale = 1;
  10661. break;
  10662. case "page-width":
  10663. scale = pageWidthScale;
  10664. break;
  10665. case "page-height":
  10666. scale = pageHeightScale;
  10667. break;
  10668. case "page-fit":
  10669. scale = Math.min(pageWidthScale, pageHeightScale);
  10670. break;
  10671. case "auto":
  10672. const horizontalScale = isPortraitOrientation(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  10673. scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
  10674. break;
  10675. default:
  10676. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  10677. return;
  10678. }
  10679. options.preset = true;
  10680. this.#setScaleUpdatePages(scale, value, options);
  10681. }
  10682. }
  10683. #resetCurrentPageView() {
  10684. const pageView = this._pages[this._currentPageNumber - 1];
  10685. if (this.isInPresentationMode) {
  10686. this.#setScale(this._currentScaleValue, {
  10687. noScroll: true
  10688. });
  10689. }
  10690. this.#scrollIntoView(pageView);
  10691. }
  10692. pageLabelToPageNumber(label) {
  10693. if (!this._pageLabels) {
  10694. return null;
  10695. }
  10696. const i = this._pageLabels.indexOf(label);
  10697. if (i < 0) {
  10698. return null;
  10699. }
  10700. return i + 1;
  10701. }
  10702. scrollPageIntoView({
  10703. pageNumber,
  10704. destArray = null,
  10705. allowNegativeOffset = false,
  10706. ignoreDestinationZoom = false
  10707. }) {
  10708. if (!this.pdfDocument) {
  10709. return;
  10710. }
  10711. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  10712. if (!pageView) {
  10713. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  10714. return;
  10715. }
  10716. if (this.isInPresentationMode || !destArray) {
  10717. this._setCurrentPageNumber(pageNumber, true);
  10718. return;
  10719. }
  10720. let x = 0,
  10721. y = 0;
  10722. let width = 0,
  10723. height = 0,
  10724. widthScale,
  10725. heightScale;
  10726. const changeOrientation = pageView.rotation % 180 !== 0;
  10727. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
  10728. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
  10729. let scale = 0;
  10730. switch (destArray[1].name) {
  10731. case "XYZ":
  10732. x = destArray[2];
  10733. y = destArray[3];
  10734. scale = destArray[4];
  10735. x = x !== null ? x : 0;
  10736. y = y !== null ? y : pageHeight;
  10737. break;
  10738. case "Fit":
  10739. case "FitB":
  10740. scale = "page-fit";
  10741. break;
  10742. case "FitH":
  10743. case "FitBH":
  10744. y = destArray[2];
  10745. scale = "page-width";
  10746. if (y === null && this._location) {
  10747. x = this._location.left;
  10748. y = this._location.top;
  10749. } else if (typeof y !== "number" || y < 0) {
  10750. y = pageHeight;
  10751. }
  10752. break;
  10753. case "FitV":
  10754. case "FitBV":
  10755. x = destArray[2];
  10756. width = pageWidth;
  10757. height = pageHeight;
  10758. scale = "page-height";
  10759. break;
  10760. case "FitR":
  10761. x = destArray[2];
  10762. y = destArray[3];
  10763. width = destArray[4] - x;
  10764. height = destArray[5] - y;
  10765. let hPadding = SCROLLBAR_PADDING,
  10766. vPadding = VERTICAL_PADDING;
  10767. if (this.removePageBorders) {
  10768. hPadding = vPadding = 0;
  10769. }
  10770. widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS;
  10771. heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS;
  10772. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  10773. break;
  10774. default:
  10775. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  10776. return;
  10777. }
  10778. if (!ignoreDestinationZoom) {
  10779. if (scale && scale !== this._currentScale) {
  10780. this.currentScaleValue = scale;
  10781. } else if (this._currentScale === UNKNOWN_SCALE) {
  10782. this.currentScaleValue = DEFAULT_SCALE_VALUE;
  10783. }
  10784. }
  10785. if (scale === "page-fit" && !destArray[4]) {
  10786. this.#scrollIntoView(pageView);
  10787. return;
  10788. }
  10789. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  10790. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  10791. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  10792. if (!allowNegativeOffset) {
  10793. left = Math.max(left, 0);
  10794. top = Math.max(top, 0);
  10795. }
  10796. this.#scrollIntoView(pageView, {
  10797. left,
  10798. top
  10799. });
  10800. }
  10801. _updateLocation(firstPage) {
  10802. const currentScale = this._currentScale;
  10803. const currentScaleValue = this._currentScaleValue;
  10804. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  10805. const pageNumber = firstPage.id;
  10806. const currentPageView = this._pages[pageNumber - 1];
  10807. const container = this.container;
  10808. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  10809. const intLeft = Math.round(topLeft[0]);
  10810. const intTop = Math.round(topLeft[1]);
  10811. let pdfOpenParams = `#page=${pageNumber}`;
  10812. if (!this.isInPresentationMode) {
  10813. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  10814. }
  10815. this._location = {
  10816. pageNumber,
  10817. scale: normalizedScaleValue,
  10818. top: intTop,
  10819. left: intLeft,
  10820. rotation: this._pagesRotation,
  10821. pdfOpenParams
  10822. };
  10823. }
  10824. update() {
  10825. const visible = this._getVisiblePages();
  10826. const visiblePages = visible.views,
  10827. numVisiblePages = visiblePages.length;
  10828. if (numVisiblePages === 0) {
  10829. return;
  10830. }
  10831. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  10832. this.#buffer.resize(newCacheSize, visible.ids);
  10833. this.renderingQueue.renderHighestPriority(visible);
  10834. const isSimpleLayout = this._spreadMode === SpreadMode.NONE && (this._scrollMode === ScrollMode.PAGE || this._scrollMode === ScrollMode.VERTICAL);
  10835. const currentId = this._currentPageNumber;
  10836. let stillFullyVisible = false;
  10837. for (const page of visiblePages) {
  10838. if (page.percent < 100) {
  10839. break;
  10840. }
  10841. if (page.id === currentId && isSimpleLayout) {
  10842. stillFullyVisible = true;
  10843. break;
  10844. }
  10845. }
  10846. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  10847. this._updateLocation(visible.first);
  10848. this.eventBus.dispatch("updateviewarea", {
  10849. source: this,
  10850. location: this._location
  10851. });
  10852. }
  10853. #switchToEditAnnotationMode() {
  10854. const visible = this._getVisiblePages();
  10855. const pagesToRefresh = [];
  10856. const {
  10857. ids,
  10858. views
  10859. } = visible;
  10860. for (const page of views) {
  10861. const {
  10862. view
  10863. } = page;
  10864. if (!view.hasEditableAnnotations()) {
  10865. ids.delete(view.id);
  10866. continue;
  10867. }
  10868. pagesToRefresh.push(page);
  10869. }
  10870. if (pagesToRefresh.length === 0) {
  10871. return null;
  10872. }
  10873. this.renderingQueue.renderHighestPriority({
  10874. first: pagesToRefresh[0],
  10875. last: pagesToRefresh.at(-1),
  10876. views: pagesToRefresh,
  10877. ids
  10878. });
  10879. return ids;
  10880. }
  10881. containsElement(element) {
  10882. return this.container.contains(element);
  10883. }
  10884. focus() {
  10885. this.container.focus();
  10886. }
  10887. get _isContainerRtl() {
  10888. return getComputedStyle(this.container).direction === "rtl";
  10889. }
  10890. get isInPresentationMode() {
  10891. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  10892. }
  10893. get isChangingPresentationMode() {
  10894. return this.presentationModeState === PresentationModeState.CHANGING;
  10895. }
  10896. get isHorizontalScrollbarEnabled() {
  10897. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  10898. }
  10899. get isVerticalScrollbarEnabled() {
  10900. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  10901. }
  10902. _getVisiblePages() {
  10903. const views = this._scrollMode === ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  10904. horizontal = this._scrollMode === ScrollMode.HORIZONTAL,
  10905. rtl = horizontal && this._isContainerRtl;
  10906. return getVisibleElements({
  10907. scrollEl: this.container,
  10908. views,
  10909. sortByVisibility: true,
  10910. horizontal,
  10911. rtl
  10912. });
  10913. }
  10914. cleanup() {
  10915. for (const pageView of this._pages) {
  10916. if (pageView.renderingState !== RenderingStates.FINISHED) {
  10917. pageView.reset();
  10918. }
  10919. }
  10920. }
  10921. _cancelRendering() {
  10922. for (const pageView of this._pages) {
  10923. pageView.cancelRendering();
  10924. }
  10925. }
  10926. async #ensurePdfPageLoaded(pageView) {
  10927. if (pageView.pdfPage) {
  10928. return pageView.pdfPage;
  10929. }
  10930. try {
  10931. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  10932. if (!pageView.pdfPage) {
  10933. pageView.setPdfPage(pdfPage);
  10934. }
  10935. return pdfPage;
  10936. } catch (reason) {
  10937. console.error("Unable to get page for page view", reason);
  10938. return null;
  10939. }
  10940. }
  10941. #getScrollAhead(visible) {
  10942. if (visible.first?.id === 1) {
  10943. return true;
  10944. } else if (visible.last?.id === this.pagesCount) {
  10945. return false;
  10946. }
  10947. switch (this._scrollMode) {
  10948. case ScrollMode.PAGE:
  10949. return this.#scrollModePageState.scrollDown;
  10950. case ScrollMode.HORIZONTAL:
  10951. return this.scroll.right;
  10952. }
  10953. return this.scroll.down;
  10954. }
  10955. forceRendering(currentlyVisiblePages) {
  10956. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  10957. const scrollAhead = this.#getScrollAhead(visiblePages);
  10958. const preRenderExtra = this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL;
  10959. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  10960. if (pageView) {
  10961. this.#ensurePdfPageLoaded(pageView).then(() => {
  10962. this.renderingQueue.renderView(pageView);
  10963. });
  10964. return true;
  10965. }
  10966. return false;
  10967. }
  10968. get hasEqualPageSizes() {
  10969. const firstPageView = this._pages[0];
  10970. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  10971. const pageView = this._pages[i];
  10972. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  10973. return false;
  10974. }
  10975. }
  10976. return true;
  10977. }
  10978. getPagesOverview() {
  10979. let initialOrientation;
  10980. return this._pages.map(pageView => {
  10981. const viewport = pageView.pdfPage.getViewport({
  10982. scale: 1
  10983. });
  10984. const orientation = isPortraitOrientation(viewport);
  10985. if (initialOrientation === undefined) {
  10986. initialOrientation = orientation;
  10987. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  10988. return {
  10989. width: viewport.height,
  10990. height: viewport.width,
  10991. rotation: (viewport.rotation - 90) % 360
  10992. };
  10993. }
  10994. return {
  10995. width: viewport.width,
  10996. height: viewport.height,
  10997. rotation: viewport.rotation
  10998. };
  10999. });
  11000. }
  11001. get optionalContentConfigPromise() {
  11002. if (!this.pdfDocument) {
  11003. return Promise.resolve(null);
  11004. }
  11005. if (!this._optionalContentConfigPromise) {
  11006. console.error("optionalContentConfigPromise: Not initialized yet.");
  11007. return this.pdfDocument.getOptionalContentConfig({
  11008. intent: "display"
  11009. });
  11010. }
  11011. return this._optionalContentConfigPromise;
  11012. }
  11013. set optionalContentConfigPromise(promise) {
  11014. if (!(promise instanceof Promise)) {
  11015. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  11016. }
  11017. if (!this.pdfDocument) {
  11018. return;
  11019. }
  11020. if (!this._optionalContentConfigPromise) {
  11021. return;
  11022. }
  11023. this._optionalContentConfigPromise = promise;
  11024. this.refresh(false, {
  11025. optionalContentConfigPromise: promise
  11026. });
  11027. this.eventBus.dispatch("optionalcontentconfigchanged", {
  11028. source: this,
  11029. promise
  11030. });
  11031. }
  11032. get scrollMode() {
  11033. return this._scrollMode;
  11034. }
  11035. set scrollMode(mode) {
  11036. if (this._scrollMode === mode) {
  11037. return;
  11038. }
  11039. if (!isValidScrollMode(mode)) {
  11040. throw new Error(`Invalid scroll mode: ${mode}`);
  11041. }
  11042. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  11043. return;
  11044. }
  11045. this._previousScrollMode = this._scrollMode;
  11046. this._scrollMode = mode;
  11047. this.eventBus.dispatch("scrollmodechanged", {
  11048. source: this,
  11049. mode
  11050. });
  11051. this._updateScrollMode(this._currentPageNumber);
  11052. }
  11053. _updateScrollMode(pageNumber = null) {
  11054. const scrollMode = this._scrollMode,
  11055. viewer = this.viewer;
  11056. viewer.classList.toggle("scrollHorizontal", scrollMode === ScrollMode.HORIZONTAL);
  11057. viewer.classList.toggle("scrollWrapped", scrollMode === ScrollMode.WRAPPED);
  11058. if (!this.pdfDocument || !pageNumber) {
  11059. return;
  11060. }
  11061. if (scrollMode === ScrollMode.PAGE) {
  11062. this.#ensurePageViewVisible();
  11063. } else if (this._previousScrollMode === ScrollMode.PAGE) {
  11064. this._updateSpreadMode();
  11065. }
  11066. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  11067. this.#setScale(this._currentScaleValue, {
  11068. noScroll: true
  11069. });
  11070. }
  11071. this._setCurrentPageNumber(pageNumber, true);
  11072. this.update();
  11073. }
  11074. get spreadMode() {
  11075. return this._spreadMode;
  11076. }
  11077. set spreadMode(mode) {
  11078. if (this._spreadMode === mode) {
  11079. return;
  11080. }
  11081. if (!isValidSpreadMode(mode)) {
  11082. throw new Error(`Invalid spread mode: ${mode}`);
  11083. }
  11084. this._spreadMode = mode;
  11085. this.eventBus.dispatch("spreadmodechanged", {
  11086. source: this,
  11087. mode
  11088. });
  11089. this._updateSpreadMode(this._currentPageNumber);
  11090. }
  11091. _updateSpreadMode(pageNumber = null) {
  11092. if (!this.pdfDocument) {
  11093. return;
  11094. }
  11095. const viewer = this.viewer,
  11096. pages = this._pages;
  11097. if (this._scrollMode === ScrollMode.PAGE) {
  11098. this.#ensurePageViewVisible();
  11099. } else {
  11100. viewer.textContent = "";
  11101. if (this._spreadMode === SpreadMode.NONE) {
  11102. for (const pageView of this._pages) {
  11103. viewer.append(pageView.div);
  11104. }
  11105. } else {
  11106. const parity = this._spreadMode - 1;
  11107. let spread = null;
  11108. for (let i = 0, ii = pages.length; i < ii; ++i) {
  11109. if (spread === null) {
  11110. spread = document.createElement("div");
  11111. spread.className = "spread";
  11112. viewer.append(spread);
  11113. } else if (i % 2 === parity) {
  11114. spread = spread.cloneNode(false);
  11115. viewer.append(spread);
  11116. }
  11117. spread.append(pages[i].div);
  11118. }
  11119. }
  11120. }
  11121. if (!pageNumber) {
  11122. return;
  11123. }
  11124. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  11125. this.#setScale(this._currentScaleValue, {
  11126. noScroll: true
  11127. });
  11128. }
  11129. this._setCurrentPageNumber(pageNumber, true);
  11130. this.update();
  11131. }
  11132. _getPageAdvance(currentPageNumber, previous = false) {
  11133. switch (this._scrollMode) {
  11134. case ScrollMode.WRAPPED:
  11135. {
  11136. const {
  11137. views
  11138. } = this._getVisiblePages(),
  11139. pageLayout = new Map();
  11140. for (const {
  11141. id,
  11142. y,
  11143. percent,
  11144. widthPercent
  11145. } of views) {
  11146. if (percent === 0 || widthPercent < 100) {
  11147. continue;
  11148. }
  11149. let yArray = pageLayout.get(y);
  11150. if (!yArray) {
  11151. pageLayout.set(y, yArray ||= []);
  11152. }
  11153. yArray.push(id);
  11154. }
  11155. for (const yArray of pageLayout.values()) {
  11156. const currentIndex = yArray.indexOf(currentPageNumber);
  11157. if (currentIndex === -1) {
  11158. continue;
  11159. }
  11160. const numPages = yArray.length;
  11161. if (numPages === 1) {
  11162. break;
  11163. }
  11164. if (previous) {
  11165. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  11166. const currentId = yArray[i],
  11167. expectedId = yArray[i + 1] - 1;
  11168. if (currentId < expectedId) {
  11169. return currentPageNumber - expectedId;
  11170. }
  11171. }
  11172. } else {
  11173. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  11174. const currentId = yArray[i],
  11175. expectedId = yArray[i - 1] + 1;
  11176. if (currentId > expectedId) {
  11177. return expectedId - currentPageNumber;
  11178. }
  11179. }
  11180. }
  11181. if (previous) {
  11182. const firstId = yArray[0];
  11183. if (firstId < currentPageNumber) {
  11184. return currentPageNumber - firstId + 1;
  11185. }
  11186. } else {
  11187. const lastId = yArray[numPages - 1];
  11188. if (lastId > currentPageNumber) {
  11189. return lastId - currentPageNumber + 1;
  11190. }
  11191. }
  11192. break;
  11193. }
  11194. break;
  11195. }
  11196. case ScrollMode.HORIZONTAL:
  11197. {
  11198. break;
  11199. }
  11200. case ScrollMode.PAGE:
  11201. case ScrollMode.VERTICAL:
  11202. {
  11203. if (this._spreadMode === SpreadMode.NONE) {
  11204. break;
  11205. }
  11206. const parity = this._spreadMode - 1;
  11207. if (previous && currentPageNumber % 2 !== parity) {
  11208. break;
  11209. } else if (!previous && currentPageNumber % 2 === parity) {
  11210. break;
  11211. }
  11212. const {
  11213. views
  11214. } = this._getVisiblePages(),
  11215. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  11216. for (const {
  11217. id,
  11218. percent,
  11219. widthPercent
  11220. } of views) {
  11221. if (id !== expectedId) {
  11222. continue;
  11223. }
  11224. if (percent > 0 && widthPercent === 100) {
  11225. return 2;
  11226. }
  11227. break;
  11228. }
  11229. break;
  11230. }
  11231. }
  11232. return 1;
  11233. }
  11234. nextPage() {
  11235. const currentPageNumber = this._currentPageNumber,
  11236. pagesCount = this.pagesCount;
  11237. if (currentPageNumber >= pagesCount) {
  11238. return false;
  11239. }
  11240. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  11241. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  11242. return true;
  11243. }
  11244. previousPage() {
  11245. const currentPageNumber = this._currentPageNumber;
  11246. if (currentPageNumber <= 1) {
  11247. return false;
  11248. }
  11249. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  11250. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  11251. return true;
  11252. }
  11253. updateScale({
  11254. drawingDelay,
  11255. scaleFactor = null,
  11256. steps = null,
  11257. origin
  11258. }) {
  11259. if (steps === null && scaleFactor === null) {
  11260. throw new Error("Invalid updateScale options: either `steps` or `scaleFactor` must be provided.");
  11261. }
  11262. if (!this.pdfDocument) {
  11263. return;
  11264. }
  11265. let newScale = this._currentScale;
  11266. if (scaleFactor > 0 && scaleFactor !== 1) {
  11267. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  11268. } else if (steps) {
  11269. const delta = steps > 0 ? DEFAULT_SCALE_DELTA : 1 / DEFAULT_SCALE_DELTA;
  11270. const round = steps > 0 ? Math.ceil : Math.floor;
  11271. steps = Math.abs(steps);
  11272. do {
  11273. newScale = round((newScale * delta).toFixed(2) * 10) / 10;
  11274. } while (--steps > 0);
  11275. }
  11276. newScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, newScale));
  11277. this.#setScale(newScale, {
  11278. noScroll: false,
  11279. drawingDelay,
  11280. origin
  11281. });
  11282. }
  11283. increaseScale(options = {}) {
  11284. this.updateScale({
  11285. ...options,
  11286. steps: options.steps ?? 1
  11287. });
  11288. }
  11289. decreaseScale(options = {}) {
  11290. this.updateScale({
  11291. ...options,
  11292. steps: -(options.steps ?? 1)
  11293. });
  11294. }
  11295. #updateContainerHeightCss(height = this.container.clientHeight) {
  11296. if (height !== this.#previousContainerHeight) {
  11297. this.#previousContainerHeight = height;
  11298. docStyle.setProperty("--viewer-container-height", `${height}px`);
  11299. }
  11300. }
  11301. #resizeObserverCallback(entries) {
  11302. for (const entry of entries) {
  11303. if (entry.target === this.container) {
  11304. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  11305. this.#containerTopLeft = null;
  11306. break;
  11307. }
  11308. }
  11309. }
  11310. get containerTopLeft() {
  11311. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  11312. }
  11313. #cleanupSwitchAnnotationEditorMode() {
  11314. if (this.#onPageRenderedCallback) {
  11315. this.eventBus._off("pagerendered", this.#onPageRenderedCallback);
  11316. this.#onPageRenderedCallback = null;
  11317. }
  11318. if (this.#switchAnnotationEditorModeTimeoutId !== null) {
  11319. clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
  11320. this.#switchAnnotationEditorModeTimeoutId = null;
  11321. }
  11322. }
  11323. get annotationEditorMode() {
  11324. return this.#annotationEditorUIManager ? this.#annotationEditorMode : AnnotationEditorType.DISABLE;
  11325. }
  11326. set annotationEditorMode({
  11327. mode,
  11328. editId = null,
  11329. isFromKeyboard = false
  11330. }) {
  11331. if (!this.#annotationEditorUIManager) {
  11332. throw new Error(`The AnnotationEditor is not enabled.`);
  11333. }
  11334. if (this.#annotationEditorMode === mode) {
  11335. return;
  11336. }
  11337. if (!isValidAnnotationEditorMode(mode)) {
  11338. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  11339. }
  11340. if (!this.pdfDocument) {
  11341. return;
  11342. }
  11343. const {
  11344. eventBus
  11345. } = this;
  11346. const updater = () => {
  11347. this.#cleanupSwitchAnnotationEditorMode();
  11348. this.#annotationEditorMode = mode;
  11349. this.#annotationEditorUIManager.updateMode(mode, editId, isFromKeyboard);
  11350. eventBus.dispatch("annotationeditormodechanged", {
  11351. source: this,
  11352. mode
  11353. });
  11354. };
  11355. if (mode === AnnotationEditorType.NONE || this.#annotationEditorMode === AnnotationEditorType.NONE) {
  11356. const isEditing = mode !== AnnotationEditorType.NONE;
  11357. if (!isEditing) {
  11358. this.pdfDocument.annotationStorage.resetModifiedIds();
  11359. }
  11360. for (const pageView of this._pages) {
  11361. pageView.toggleEditingMode(isEditing);
  11362. }
  11363. const idsToRefresh = this.#switchToEditAnnotationMode();
  11364. if (isEditing && idsToRefresh) {
  11365. this.#cleanupSwitchAnnotationEditorMode();
  11366. this.#onPageRenderedCallback = ({
  11367. pageNumber
  11368. }) => {
  11369. idsToRefresh.delete(pageNumber);
  11370. if (idsToRefresh.size === 0) {
  11371. this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0);
  11372. }
  11373. };
  11374. const {
  11375. signal
  11376. } = this.#eventAbortController;
  11377. eventBus._on("pagerendered", this.#onPageRenderedCallback, {
  11378. signal
  11379. });
  11380. return;
  11381. }
  11382. }
  11383. updater();
  11384. }
  11385. set annotationEditorParams({
  11386. type,
  11387. value
  11388. }) {
  11389. if (!this.#annotationEditorUIManager) {
  11390. throw new Error(`The AnnotationEditor is not enabled.`);
  11391. }
  11392. this.#annotationEditorUIManager.updateParams(type, value);
  11393. }
  11394. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  11395. if (!this.pdfDocument) {
  11396. return;
  11397. }
  11398. for (const pageView of this._pages) {
  11399. pageView.update(updateArgs);
  11400. }
  11401. if (this.#scaleTimeoutId !== null) {
  11402. clearTimeout(this.#scaleTimeoutId);
  11403. this.#scaleTimeoutId = null;
  11404. }
  11405. if (!noUpdate) {
  11406. this.update();
  11407. }
  11408. }
  11409. }
  11410. ;// CONCATENATED MODULE: ./web/secondary_toolbar.js
  11411. class SecondaryToolbar {
  11412. #opts;
  11413. constructor(options, eventBus) {
  11414. this.#opts = options;
  11415. const buttons = [{
  11416. element: options.presentationModeButton,
  11417. eventName: "presentationmode",
  11418. close: true
  11419. }, {
  11420. element: options.printButton,
  11421. eventName: "print",
  11422. close: true
  11423. }, {
  11424. element: options.downloadButton,
  11425. eventName: "download",
  11426. close: true
  11427. }, {
  11428. element: options.viewBookmarkButton,
  11429. eventName: null,
  11430. close: true
  11431. }, {
  11432. element: options.firstPageButton,
  11433. eventName: "firstpage",
  11434. close: true
  11435. }, {
  11436. element: options.lastPageButton,
  11437. eventName: "lastpage",
  11438. close: true
  11439. }, {
  11440. element: options.pageRotateCwButton,
  11441. eventName: "rotatecw",
  11442. close: false
  11443. }, {
  11444. element: options.pageRotateCcwButton,
  11445. eventName: "rotateccw",
  11446. close: false
  11447. }, {
  11448. element: options.cursorSelectToolButton,
  11449. eventName: "switchcursortool",
  11450. eventDetails: {
  11451. tool: CursorTool.SELECT
  11452. },
  11453. close: true
  11454. }, {
  11455. element: options.cursorHandToolButton,
  11456. eventName: "switchcursortool",
  11457. eventDetails: {
  11458. tool: CursorTool.HAND
  11459. },
  11460. close: true
  11461. }, {
  11462. element: options.scrollPageButton,
  11463. eventName: "switchscrollmode",
  11464. eventDetails: {
  11465. mode: ScrollMode.PAGE
  11466. },
  11467. close: true
  11468. }, {
  11469. element: options.scrollVerticalButton,
  11470. eventName: "switchscrollmode",
  11471. eventDetails: {
  11472. mode: ScrollMode.VERTICAL
  11473. },
  11474. close: true
  11475. }, {
  11476. element: options.scrollHorizontalButton,
  11477. eventName: "switchscrollmode",
  11478. eventDetails: {
  11479. mode: ScrollMode.HORIZONTAL
  11480. },
  11481. close: true
  11482. }, {
  11483. element: options.scrollWrappedButton,
  11484. eventName: "switchscrollmode",
  11485. eventDetails: {
  11486. mode: ScrollMode.WRAPPED
  11487. },
  11488. close: true
  11489. }, {
  11490. element: options.spreadNoneButton,
  11491. eventName: "switchspreadmode",
  11492. eventDetails: {
  11493. mode: SpreadMode.NONE
  11494. },
  11495. close: true
  11496. }, {
  11497. element: options.spreadOddButton,
  11498. eventName: "switchspreadmode",
  11499. eventDetails: {
  11500. mode: SpreadMode.ODD
  11501. },
  11502. close: true
  11503. }, {
  11504. element: options.spreadEvenButton,
  11505. eventName: "switchspreadmode",
  11506. eventDetails: {
  11507. mode: SpreadMode.EVEN
  11508. },
  11509. close: true
  11510. }, {
  11511. element: options.documentPropertiesButton,
  11512. eventName: "documentproperties",
  11513. close: true
  11514. }];
  11515. buttons.push({
  11516. element: options.openFileButton,
  11517. eventName: "openfile",
  11518. close: true
  11519. });
  11520. this.eventBus = eventBus;
  11521. this.opened = false;
  11522. this.#bindListeners(buttons);
  11523. this.reset();
  11524. }
  11525. get isOpen() {
  11526. return this.opened;
  11527. }
  11528. setPageNumber(pageNumber) {
  11529. this.pageNumber = pageNumber;
  11530. this.#updateUIState();
  11531. }
  11532. setPagesCount(pagesCount) {
  11533. this.pagesCount = pagesCount;
  11534. this.#updateUIState();
  11535. }
  11536. reset() {
  11537. this.pageNumber = 0;
  11538. this.pagesCount = 0;
  11539. this.#updateUIState();
  11540. this.eventBus.dispatch("switchcursortool", {
  11541. source: this,
  11542. reset: true
  11543. });
  11544. this.#scrollModeChanged({
  11545. mode: ScrollMode.VERTICAL
  11546. });
  11547. this.#spreadModeChanged({
  11548. mode: SpreadMode.NONE
  11549. });
  11550. }
  11551. #updateUIState() {
  11552. const {
  11553. firstPageButton,
  11554. lastPageButton,
  11555. pageRotateCwButton,
  11556. pageRotateCcwButton
  11557. } = this.#opts;
  11558. firstPageButton.disabled = this.pageNumber <= 1;
  11559. lastPageButton.disabled = this.pageNumber >= this.pagesCount;
  11560. pageRotateCwButton.disabled = this.pagesCount === 0;
  11561. pageRotateCcwButton.disabled = this.pagesCount === 0;
  11562. }
  11563. #bindListeners(buttons) {
  11564. const {
  11565. eventBus
  11566. } = this;
  11567. const {
  11568. toggleButton
  11569. } = this.#opts;
  11570. toggleButton.addEventListener("click", this.toggle.bind(this));
  11571. for (const {
  11572. element,
  11573. eventName,
  11574. close,
  11575. eventDetails
  11576. } of buttons) {
  11577. element.addEventListener("click", evt => {
  11578. if (eventName !== null) {
  11579. eventBus.dispatch(eventName, {
  11580. source: this,
  11581. ...eventDetails
  11582. });
  11583. }
  11584. if (close) {
  11585. this.close();
  11586. }
  11587. eventBus.dispatch("reporttelemetry", {
  11588. source: this,
  11589. details: {
  11590. type: "buttons",
  11591. data: {
  11592. id: element.id
  11593. }
  11594. }
  11595. });
  11596. });
  11597. }
  11598. eventBus._on("cursortoolchanged", this.#cursorToolChanged.bind(this));
  11599. eventBus._on("scrollmodechanged", this.#scrollModeChanged.bind(this));
  11600. eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this));
  11601. }
  11602. #cursorToolChanged({
  11603. tool
  11604. }) {
  11605. const {
  11606. cursorSelectToolButton,
  11607. cursorHandToolButton
  11608. } = this.#opts;
  11609. toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT);
  11610. toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND);
  11611. }
  11612. #scrollModeChanged({
  11613. mode
  11614. }) {
  11615. const {
  11616. scrollPageButton,
  11617. scrollVerticalButton,
  11618. scrollHorizontalButton,
  11619. scrollWrappedButton,
  11620. spreadNoneButton,
  11621. spreadOddButton,
  11622. spreadEvenButton
  11623. } = this.#opts;
  11624. toggleCheckedBtn(scrollPageButton, mode === ScrollMode.PAGE);
  11625. toggleCheckedBtn(scrollVerticalButton, mode === ScrollMode.VERTICAL);
  11626. toggleCheckedBtn(scrollHorizontalButton, mode === ScrollMode.HORIZONTAL);
  11627. toggleCheckedBtn(scrollWrappedButton, mode === ScrollMode.WRAPPED);
  11628. const forceScrollModePage = this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11629. scrollPageButton.disabled = forceScrollModePage;
  11630. scrollVerticalButton.disabled = forceScrollModePage;
  11631. scrollHorizontalButton.disabled = forceScrollModePage;
  11632. scrollWrappedButton.disabled = forceScrollModePage;
  11633. const isHorizontal = mode === ScrollMode.HORIZONTAL;
  11634. spreadNoneButton.disabled = isHorizontal;
  11635. spreadOddButton.disabled = isHorizontal;
  11636. spreadEvenButton.disabled = isHorizontal;
  11637. }
  11638. #spreadModeChanged({
  11639. mode
  11640. }) {
  11641. const {
  11642. spreadNoneButton,
  11643. spreadOddButton,
  11644. spreadEvenButton
  11645. } = this.#opts;
  11646. toggleCheckedBtn(spreadNoneButton, mode === SpreadMode.NONE);
  11647. toggleCheckedBtn(spreadOddButton, mode === SpreadMode.ODD);
  11648. toggleCheckedBtn(spreadEvenButton, mode === SpreadMode.EVEN);
  11649. }
  11650. open() {
  11651. if (this.opened) {
  11652. return;
  11653. }
  11654. this.opened = true;
  11655. const {
  11656. toggleButton,
  11657. toolbar
  11658. } = this.#opts;
  11659. toggleExpandedBtn(toggleButton, true, toolbar);
  11660. }
  11661. close() {
  11662. if (!this.opened) {
  11663. return;
  11664. }
  11665. this.opened = false;
  11666. const {
  11667. toggleButton,
  11668. toolbar
  11669. } = this.#opts;
  11670. toggleExpandedBtn(toggleButton, false, toolbar);
  11671. }
  11672. toggle() {
  11673. if (this.opened) {
  11674. this.close();
  11675. } else {
  11676. this.open();
  11677. }
  11678. }
  11679. }
  11680. ;// CONCATENATED MODULE: ./web/toolbar.js
  11681. class Toolbar {
  11682. #opts;
  11683. constructor(options, eventBus, toolbarDensity = 0) {
  11684. this.#opts = options;
  11685. this.eventBus = eventBus;
  11686. const buttons = [{
  11687. element: options.previous,
  11688. eventName: "previouspage"
  11689. }, {
  11690. element: options.next,
  11691. eventName: "nextpage"
  11692. }, {
  11693. element: options.zoomIn,
  11694. eventName: "zoomin"
  11695. }, {
  11696. element: options.zoomOut,
  11697. eventName: "zoomout"
  11698. }, {
  11699. element: options.print,
  11700. eventName: "print"
  11701. }, {
  11702. element: options.download,
  11703. eventName: "download"
  11704. }, {
  11705. element: options.editorFreeTextButton,
  11706. eventName: "switchannotationeditormode",
  11707. eventDetails: {
  11708. get mode() {
  11709. const {
  11710. classList
  11711. } = options.editorFreeTextButton;
  11712. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.FREETEXT;
  11713. }
  11714. }
  11715. }, {
  11716. element: options.editorHighlightButton,
  11717. eventName: "switchannotationeditormode",
  11718. eventDetails: {
  11719. get mode() {
  11720. const {
  11721. classList
  11722. } = options.editorHighlightButton;
  11723. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.HIGHLIGHT;
  11724. }
  11725. }
  11726. }, {
  11727. element: options.editorInkButton,
  11728. eventName: "switchannotationeditormode",
  11729. eventDetails: {
  11730. get mode() {
  11731. const {
  11732. classList
  11733. } = options.editorInkButton;
  11734. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.INK;
  11735. }
  11736. }
  11737. }, {
  11738. element: options.editorStampButton,
  11739. eventName: "switchannotationeditormode",
  11740. eventDetails: {
  11741. get mode() {
  11742. const {
  11743. classList
  11744. } = options.editorStampButton;
  11745. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.STAMP;
  11746. }
  11747. }
  11748. }];
  11749. this.#bindListeners(buttons);
  11750. if (options.editorHighlightColorPicker) {
  11751. eventBus._on("annotationeditoruimanager", ({
  11752. uiManager
  11753. }) => {
  11754. this.#setAnnotationEditorUIManager(uiManager, options.editorHighlightColorPicker);
  11755. }, {
  11756. once: true
  11757. });
  11758. }
  11759. eventBus._on("showannotationeditorui", ({
  11760. mode
  11761. }) => {
  11762. switch (mode) {
  11763. case AnnotationEditorType.HIGHLIGHT:
  11764. options.editorHighlightButton.click();
  11765. break;
  11766. }
  11767. });
  11768. eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));
  11769. this.#updateToolbarDensity({
  11770. value: toolbarDensity
  11771. });
  11772. this.reset();
  11773. }
  11774. #updateToolbarDensity() {}
  11775. #setAnnotationEditorUIManager(uiManager, parentContainer) {
  11776. const colorPicker = new ColorPicker({
  11777. uiManager
  11778. });
  11779. uiManager.setMainHighlightColorPicker(colorPicker);
  11780. parentContainer.append(colorPicker.renderMainDropdown());
  11781. }
  11782. setPageNumber(pageNumber, pageLabel) {
  11783. this.pageNumber = pageNumber;
  11784. this.pageLabel = pageLabel;
  11785. this.#updateUIState(false);
  11786. }
  11787. setPagesCount(pagesCount, hasPageLabels) {
  11788. this.pagesCount = pagesCount;
  11789. this.hasPageLabels = hasPageLabels;
  11790. this.#updateUIState(true);
  11791. }
  11792. setPageScale(pageScaleValue, pageScale) {
  11793. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11794. this.pageScale = pageScale;
  11795. this.#updateUIState(false);
  11796. }
  11797. reset() {
  11798. this.pageNumber = 0;
  11799. this.pageLabel = null;
  11800. this.hasPageLabels = false;
  11801. this.pagesCount = 0;
  11802. this.pageScaleValue = DEFAULT_SCALE_VALUE;
  11803. this.pageScale = DEFAULT_SCALE;
  11804. this.#updateUIState(true);
  11805. this.updateLoadingIndicatorState();
  11806. this.#editorModeChanged({
  11807. mode: AnnotationEditorType.DISABLE
  11808. });
  11809. }
  11810. #bindListeners(buttons) {
  11811. const {
  11812. eventBus
  11813. } = this;
  11814. const {
  11815. pageNumber,
  11816. scaleSelect
  11817. } = this.#opts;
  11818. const self = this;
  11819. for (const {
  11820. element,
  11821. eventName,
  11822. eventDetails
  11823. } of buttons) {
  11824. element.addEventListener("click", evt => {
  11825. if (eventName !== null) {
  11826. eventBus.dispatch(eventName, {
  11827. source: this,
  11828. ...eventDetails,
  11829. isFromKeyboard: evt.detail === 0
  11830. });
  11831. }
  11832. });
  11833. }
  11834. pageNumber.addEventListener("click", function () {
  11835. this.select();
  11836. });
  11837. pageNumber.addEventListener("change", function () {
  11838. eventBus.dispatch("pagenumberchanged", {
  11839. source: self,
  11840. value: this.value
  11841. });
  11842. });
  11843. scaleSelect.addEventListener("change", function () {
  11844. if (this.value === "custom") {
  11845. return;
  11846. }
  11847. eventBus.dispatch("scalechanged", {
  11848. source: self,
  11849. value: this.value
  11850. });
  11851. });
  11852. scaleSelect.addEventListener("click", function ({
  11853. target
  11854. }) {
  11855. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11856. this.blur();
  11857. }
  11858. });
  11859. scaleSelect.oncontextmenu = noContextMenu;
  11860. eventBus._on("annotationeditormodechanged", this.#editorModeChanged.bind(this));
  11861. }
  11862. #editorModeChanged({
  11863. mode
  11864. }) {
  11865. const {
  11866. editorFreeTextButton,
  11867. editorFreeTextParamsToolbar,
  11868. editorHighlightButton,
  11869. editorHighlightParamsToolbar,
  11870. editorInkButton,
  11871. editorInkParamsToolbar,
  11872. editorStampButton,
  11873. editorStampParamsToolbar
  11874. } = this.#opts;
  11875. toggleCheckedBtn(editorFreeTextButton, mode === AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  11876. toggleCheckedBtn(editorHighlightButton, mode === AnnotationEditorType.HIGHLIGHT, editorHighlightParamsToolbar);
  11877. toggleCheckedBtn(editorInkButton, mode === AnnotationEditorType.INK, editorInkParamsToolbar);
  11878. toggleCheckedBtn(editorStampButton, mode === AnnotationEditorType.STAMP, editorStampParamsToolbar);
  11879. const isDisable = mode === AnnotationEditorType.DISABLE;
  11880. editorFreeTextButton.disabled = isDisable;
  11881. editorHighlightButton.disabled = isDisable;
  11882. editorInkButton.disabled = isDisable;
  11883. editorStampButton.disabled = isDisable;
  11884. }
  11885. #updateUIState(resetNumPages = false) {
  11886. const {
  11887. pageNumber,
  11888. pagesCount,
  11889. pageScaleValue,
  11890. pageScale
  11891. } = this;
  11892. const opts = this.#opts;
  11893. if (resetNumPages) {
  11894. if (this.hasPageLabels) {
  11895. opts.pageNumber.type = "text";
  11896. opts.numPages.setAttribute("data-l10n-id", "pdfjs-page-of-pages");
  11897. } else {
  11898. opts.pageNumber.type = "number";
  11899. opts.numPages.setAttribute("data-l10n-id", "pdfjs-of-pages");
  11900. opts.numPages.setAttribute("data-l10n-args", JSON.stringify({
  11901. pagesCount
  11902. }));
  11903. }
  11904. opts.pageNumber.max = pagesCount;
  11905. }
  11906. if (this.hasPageLabels) {
  11907. opts.pageNumber.value = this.pageLabel;
  11908. opts.numPages.setAttribute("data-l10n-args", JSON.stringify({
  11909. pageNumber,
  11910. pagesCount
  11911. }));
  11912. } else {
  11913. opts.pageNumber.value = pageNumber;
  11914. }
  11915. opts.previous.disabled = pageNumber <= 1;
  11916. opts.next.disabled = pageNumber >= pagesCount;
  11917. opts.zoomOut.disabled = pageScale <= MIN_SCALE;
  11918. opts.zoomIn.disabled = pageScale >= MAX_SCALE;
  11919. let predefinedValueFound = false;
  11920. for (const option of opts.scaleSelect.options) {
  11921. if (option.value !== pageScaleValue) {
  11922. option.selected = false;
  11923. continue;
  11924. }
  11925. option.selected = true;
  11926. predefinedValueFound = true;
  11927. }
  11928. if (!predefinedValueFound) {
  11929. opts.customScaleOption.selected = true;
  11930. opts.customScaleOption.setAttribute("data-l10n-args", JSON.stringify({
  11931. scale: Math.round(pageScale * 10000) / 100
  11932. }));
  11933. }
  11934. }
  11935. updateLoadingIndicatorState(loading = false) {
  11936. const {
  11937. pageNumber
  11938. } = this.#opts;
  11939. pageNumber.classList.toggle("loading", loading);
  11940. }
  11941. }
  11942. ;// CONCATENATED MODULE: ./web/view_history.js
  11943. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11944. class ViewHistory {
  11945. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11946. this.fingerprint = fingerprint;
  11947. this.cacheSize = cacheSize;
  11948. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11949. const database = JSON.parse(databaseStr || "{}");
  11950. let index = -1;
  11951. if (!Array.isArray(database.files)) {
  11952. database.files = [];
  11953. } else {
  11954. while (database.files.length >= this.cacheSize) {
  11955. database.files.shift();
  11956. }
  11957. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11958. const branch = database.files[i];
  11959. if (branch.fingerprint === this.fingerprint) {
  11960. index = i;
  11961. break;
  11962. }
  11963. }
  11964. }
  11965. if (index === -1) {
  11966. index = database.files.push({
  11967. fingerprint: this.fingerprint
  11968. }) - 1;
  11969. }
  11970. this.file = database.files[index];
  11971. this.database = database;
  11972. });
  11973. }
  11974. async _writeToStorage() {
  11975. const databaseStr = JSON.stringify(this.database);
  11976. localStorage.setItem("pdfjs.history", databaseStr);
  11977. }
  11978. async _readFromStorage() {
  11979. return localStorage.getItem("pdfjs.history");
  11980. }
  11981. async set(name, val) {
  11982. await this._initializedPromise;
  11983. this.file[name] = val;
  11984. return this._writeToStorage();
  11985. }
  11986. async setMultiple(properties) {
  11987. await this._initializedPromise;
  11988. for (const name in properties) {
  11989. this.file[name] = properties[name];
  11990. }
  11991. return this._writeToStorage();
  11992. }
  11993. async get(name, defaultValue) {
  11994. await this._initializedPromise;
  11995. const val = this.file[name];
  11996. return val !== undefined ? val : defaultValue;
  11997. }
  11998. async getMultiple(properties) {
  11999. await this._initializedPromise;
  12000. const values = Object.create(null);
  12001. for (const name in properties) {
  12002. const val = this.file[name];
  12003. values[name] = val !== undefined ? val : properties[name];
  12004. }
  12005. return values;
  12006. }
  12007. }
  12008. ;// CONCATENATED MODULE: ./web/app.js
  12009. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  12010. const ViewOnLoad = {
  12011. UNKNOWN: -1,
  12012. PREVIOUS: 0,
  12013. INITIAL: 1
  12014. };
  12015. const PDFViewerApplication = {
  12016. initialBookmark: document.location.hash.substring(1),
  12017. _initializedCapability: {
  12018. ...Promise.withResolvers(),
  12019. settled: false
  12020. },
  12021. appConfig: null,
  12022. pdfDocument: null,
  12023. pdfLoadingTask: null,
  12024. printService: null,
  12025. pdfViewer: null,
  12026. pdfThumbnailViewer: null,
  12027. pdfRenderingQueue: null,
  12028. pdfPresentationMode: null,
  12029. pdfDocumentProperties: null,
  12030. pdfLinkService: null,
  12031. pdfHistory: null,
  12032. pdfSidebar: null,
  12033. pdfOutlineViewer: null,
  12034. pdfAttachmentViewer: null,
  12035. pdfLayerViewer: null,
  12036. pdfCursorTools: null,
  12037. pdfScriptingManager: null,
  12038. store: null,
  12039. downloadManager: null,
  12040. overlayManager: null,
  12041. preferences: new Preferences(),
  12042. toolbar: null,
  12043. secondaryToolbar: null,
  12044. eventBus: null,
  12045. l10n: null,
  12046. annotationEditorParams: null,
  12047. isInitialViewSet: false,
  12048. isViewerEmbedded: window.parent !== window,
  12049. url: "",
  12050. baseUrl: "",
  12051. mlManager: null,
  12052. _downloadUrl: "",
  12053. _eventBusAbortController: null,
  12054. _windowAbortController: null,
  12055. _globalAbortController: new AbortController(),
  12056. documentInfo: null,
  12057. metadata: null,
  12058. _contentDispositionFilename: null,
  12059. _contentLength: null,
  12060. _saveInProgress: false,
  12061. _wheelUnusedTicks: 0,
  12062. _wheelUnusedFactor: 1,
  12063. _touchUnusedTicks: 0,
  12064. _touchUnusedFactor: 1,
  12065. _PDFBug: null,
  12066. _hasAnnotationEditors: false,
  12067. _title: document.title,
  12068. _printAnnotationStoragePromise: null,
  12069. _touchInfo: null,
  12070. _isCtrlKeyDown: false,
  12071. _caretBrowsing: null,
  12072. _isScrolling: false,
  12073. async initialize(appConfig) {
  12074. this.appConfig = appConfig;
  12075. try {
  12076. await this.preferences.initializedPromise;
  12077. } catch (ex) {
  12078. console.error(`initialize: "${ex.message}".`);
  12079. }
  12080. if (AppOptions.get("pdfBugEnabled")) {
  12081. await this._parseHashParams();
  12082. }
  12083. let mode;
  12084. switch (AppOptions.get("viewerCssTheme")) {
  12085. case 1:
  12086. mode = "is-light";
  12087. break;
  12088. case 2:
  12089. mode = "is-dark";
  12090. break;
  12091. }
  12092. if (mode) {
  12093. document.documentElement.classList.add(mode);
  12094. }
  12095. this.l10n = await this.externalServices.createL10n();
  12096. document.getElementsByTagName("html")[0].dir = this.l10n.getDirection();
  12097. this.l10n.translate(appConfig.appContainer || document.documentElement);
  12098. if (this.isViewerEmbedded && AppOptions.get("externalLinkTarget") === LinkTarget.NONE) {
  12099. AppOptions.set("externalLinkTarget", LinkTarget.TOP);
  12100. }
  12101. await this._initializeViewerComponents();
  12102. this.bindEvents();
  12103. this.bindWindowEvents();
  12104. this._initializedCapability.settled = true;
  12105. this._initializedCapability.resolve();
  12106. },
  12107. async _parseHashParams() {
  12108. const hash = document.location.hash.substring(1);
  12109. if (!hash) {
  12110. return;
  12111. }
  12112. const {
  12113. mainContainer,
  12114. viewerContainer
  12115. } = this.appConfig,
  12116. params = parseQueryString(hash);
  12117. const loadPDFBug = async () => {
  12118. if (this._PDFBug) {
  12119. return;
  12120. }
  12121. const {
  12122. PDFBug
  12123. } = await import( /*webpackIgnore: true*/AppOptions.get("debuggerSrc"));
  12124. this._PDFBug = PDFBug;
  12125. };
  12126. if (params.get("disableworker") === "true") {
  12127. try {
  12128. GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
  12129. await import( /*webpackIgnore: true*/PDFWorker.workerSrc);
  12130. } catch (ex) {
  12131. console.error(`_parseHashParams: "${ex.message}".`);
  12132. }
  12133. }
  12134. if (params.has("disablerange")) {
  12135. AppOptions.set("disableRange", params.get("disablerange") === "true");
  12136. }
  12137. if (params.has("disablestream")) {
  12138. AppOptions.set("disableStream", params.get("disablestream") === "true");
  12139. }
  12140. if (params.has("disableautofetch")) {
  12141. AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  12142. }
  12143. if (params.has("disablefontface")) {
  12144. AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  12145. }
  12146. if (params.has("disablehistory")) {
  12147. AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  12148. }
  12149. if (params.has("verbosity")) {
  12150. AppOptions.set("verbosity", params.get("verbosity") | 0);
  12151. }
  12152. if (params.has("textlayer")) {
  12153. switch (params.get("textlayer")) {
  12154. case "off":
  12155. AppOptions.set("textLayerMode", TextLayerMode.DISABLE);
  12156. break;
  12157. case "visible":
  12158. case "shadow":
  12159. case "hover":
  12160. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  12161. try {
  12162. await loadPDFBug();
  12163. this._PDFBug.loadCSS();
  12164. } catch (ex) {
  12165. console.error(`_parseHashParams: "${ex.message}".`);
  12166. }
  12167. break;
  12168. }
  12169. }
  12170. if (params.has("pdfbug")) {
  12171. AppOptions.setAll({
  12172. pdfBug: true,
  12173. fontExtraProperties: true
  12174. });
  12175. const enabled = params.get("pdfbug").split(",");
  12176. try {
  12177. await loadPDFBug();
  12178. this._PDFBug.init(mainContainer, enabled);
  12179. } catch (ex) {
  12180. console.error(`_parseHashParams: "${ex.message}".`);
  12181. }
  12182. }
  12183. if (params.has("locale")) {
  12184. AppOptions.set("localeProperties", {
  12185. lang: params.get("locale")
  12186. });
  12187. }
  12188. },
  12189. async _initializeViewerComponents() {
  12190. const {
  12191. appConfig,
  12192. externalServices,
  12193. l10n
  12194. } = this;
  12195. let eventBus;
  12196. eventBus = new EventBus();
  12197. this.eventBus = eventBus;
  12198. this.overlayManager = new OverlayManager();
  12199. const pdfRenderingQueue = new PDFRenderingQueue();
  12200. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  12201. this.pdfRenderingQueue = pdfRenderingQueue;
  12202. const pdfLinkService = new PDFLinkService({
  12203. eventBus,
  12204. externalLinkTarget: AppOptions.get("externalLinkTarget"),
  12205. externalLinkRel: AppOptions.get("externalLinkRel"),
  12206. ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom")
  12207. });
  12208. this.pdfLinkService = pdfLinkService;
  12209. const downloadManager = this.downloadManager = new DownloadManager();
  12210. const findController = new PDFFindController({
  12211. linkService: pdfLinkService,
  12212. eventBus,
  12213. updateMatchesCountOnProgress: true
  12214. });
  12215. this.findController = findController;
  12216. const pdfScriptingManager = new PDFScriptingManager({
  12217. eventBus,
  12218. externalServices,
  12219. docProperties: this._scriptingDocProperties.bind(this)
  12220. });
  12221. this.pdfScriptingManager = pdfScriptingManager;
  12222. const container = appConfig.mainContainer,
  12223. viewer = appConfig.viewerContainer;
  12224. const annotationEditorMode = AppOptions.get("annotationEditorMode");
  12225. const pageColors = AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  12226. background: AppOptions.get("pageColorsBackground"),
  12227. foreground: AppOptions.get("pageColorsForeground")
  12228. } : null;
  12229. const altTextManager = appConfig.altTextDialog ? new AltTextManager(appConfig.altTextDialog, container, this.overlayManager, eventBus) : null;
  12230. const enableHWA = AppOptions.get("enableHWA");
  12231. const pdfViewer = new PDFViewer({
  12232. container,
  12233. viewer,
  12234. eventBus,
  12235. renderingQueue: pdfRenderingQueue,
  12236. linkService: pdfLinkService,
  12237. downloadManager,
  12238. altTextManager,
  12239. findController,
  12240. scriptingManager: AppOptions.get("enableScripting") && pdfScriptingManager,
  12241. l10n,
  12242. textLayerMode: AppOptions.get("textLayerMode"),
  12243. annotationMode: AppOptions.get("annotationMode"),
  12244. annotationEditorMode,
  12245. annotationEditorHighlightColors: AppOptions.get("highlightEditorColors"),
  12246. enableHighlightFloatingButton: AppOptions.get("enableHighlightFloatingButton"),
  12247. enableUpdatedAddImage: AppOptions.get("enableUpdatedAddImage"),
  12248. imageResourcesPath: AppOptions.get("imageResourcesPath"),
  12249. enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
  12250. maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
  12251. enablePermissions: AppOptions.get("enablePermissions"),
  12252. pageColors,
  12253. mlManager: this.mlManager,
  12254. abortSignal: this._globalAbortController.signal,
  12255. enableHWA
  12256. });
  12257. this.pdfViewer = pdfViewer;
  12258. pdfRenderingQueue.setViewer(pdfViewer);
  12259. pdfLinkService.setViewer(pdfViewer);
  12260. pdfScriptingManager.setViewer(pdfViewer);
  12261. if (appConfig.sidebar?.thumbnailView) {
  12262. this.pdfThumbnailViewer = new PDFThumbnailViewer({
  12263. container: appConfig.sidebar.thumbnailView,
  12264. eventBus,
  12265. renderingQueue: pdfRenderingQueue,
  12266. linkService: pdfLinkService,
  12267. pageColors,
  12268. abortSignal: this._globalAbortController.signal,
  12269. enableHWA
  12270. });
  12271. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  12272. }
  12273. if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) {
  12274. this.pdfHistory = new PDFHistory({
  12275. linkService: pdfLinkService,
  12276. eventBus
  12277. });
  12278. pdfLinkService.setHistory(this.pdfHistory);
  12279. }
  12280. if (!this.supportsIntegratedFind && appConfig.findBar) {
  12281. this.findBar = new PDFFindBar(appConfig.findBar, eventBus);
  12282. }
  12283. if (appConfig.annotationEditorParams) {
  12284. if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
  12285. const editorHighlightButton = appConfig.toolbar?.editorHighlightButton;
  12286. if (editorHighlightButton && AppOptions.get("enableHighlightEditor")) {
  12287. editorHighlightButton.hidden = false;
  12288. }
  12289. this.annotationEditorParams = new AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  12290. } else {
  12291. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  12292. document.getElementById(id)?.classList.add("hidden");
  12293. }
  12294. }
  12295. }
  12296. if (appConfig.documentProperties) {
  12297. this.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, l10n, () => this._docFilename);
  12298. }
  12299. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  12300. this.pdfCursorTools = new PDFCursorTools({
  12301. container,
  12302. eventBus,
  12303. cursorToolOnLoad: AppOptions.get("cursorToolOnLoad")
  12304. });
  12305. }
  12306. if (appConfig.toolbar) {
  12307. this.toolbar = new Toolbar(appConfig.toolbar, eventBus, AppOptions.get("toolbarDensity"));
  12308. }
  12309. if (appConfig.secondaryToolbar) {
  12310. this.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, eventBus);
  12311. }
  12312. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  12313. this.pdfPresentationMode = new PDFPresentationMode({
  12314. container,
  12315. pdfViewer,
  12316. eventBus
  12317. });
  12318. }
  12319. if (appConfig.passwordOverlay) {
  12320. this.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.isViewerEmbedded);
  12321. }
  12322. if (appConfig.sidebar?.outlineView) {
  12323. this.pdfOutlineViewer = new PDFOutlineViewer({
  12324. container: appConfig.sidebar.outlineView,
  12325. eventBus,
  12326. l10n,
  12327. linkService: pdfLinkService,
  12328. downloadManager
  12329. });
  12330. }
  12331. if (appConfig.sidebar?.attachmentsView) {
  12332. this.pdfAttachmentViewer = new PDFAttachmentViewer({
  12333. container: appConfig.sidebar.attachmentsView,
  12334. eventBus,
  12335. l10n,
  12336. downloadManager
  12337. });
  12338. }
  12339. if (appConfig.sidebar?.layersView) {
  12340. this.pdfLayerViewer = new PDFLayerViewer({
  12341. container: appConfig.sidebar.layersView,
  12342. eventBus,
  12343. l10n
  12344. });
  12345. }
  12346. if (appConfig.sidebar) {
  12347. this.pdfSidebar = new PDFSidebar({
  12348. elements: appConfig.sidebar,
  12349. eventBus,
  12350. l10n
  12351. });
  12352. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  12353. this.pdfSidebar.onUpdateThumbnails = () => {
  12354. for (const pageView of pdfViewer.getCachedPageViews()) {
  12355. if (pageView.renderingState === RenderingStates.FINISHED) {
  12356. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  12357. }
  12358. }
  12359. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  12360. };
  12361. }
  12362. },
  12363. async run(config) {
  12364. await this.initialize(config);
  12365. const {
  12366. appConfig,
  12367. eventBus
  12368. } = this;
  12369. let file;
  12370. const queryString = document.location.search.substring(1);
  12371. const params = parseQueryString(queryString);
  12372. file = params.get("file") ?? AppOptions.get("defaultUrl");
  12373. validateFileURL(file);
  12374. const fileInput = this._openFileInput = document.createElement("input");
  12375. fileInput.id = "fileInput";
  12376. fileInput.hidden = true;
  12377. fileInput.type = "file";
  12378. fileInput.value = null;
  12379. document.body.append(fileInput);
  12380. fileInput.addEventListener("change", function (evt) {
  12381. const {
  12382. files
  12383. } = evt.target;
  12384. if (!files || files.length === 0) {
  12385. return;
  12386. }
  12387. eventBus.dispatch("fileinputchange", {
  12388. source: this,
  12389. fileInput: evt.target
  12390. });
  12391. });
  12392. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  12393. for (const item of evt.dataTransfer.items) {
  12394. if (item.type === "application/pdf") {
  12395. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  12396. evt.preventDefault();
  12397. evt.stopPropagation();
  12398. return;
  12399. }
  12400. }
  12401. });
  12402. appConfig.mainContainer.addEventListener("drop", function (evt) {
  12403. if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
  12404. return;
  12405. }
  12406. evt.preventDefault();
  12407. evt.stopPropagation();
  12408. eventBus.dispatch("fileinputchange", {
  12409. source: this,
  12410. fileInput: evt.dataTransfer
  12411. });
  12412. });
  12413. if (!AppOptions.get("supportsDocumentFonts")) {
  12414. AppOptions.set("disableFontFace", true);
  12415. this.l10n.get("pdfjs-web-fonts-disabled").then(msg => {
  12416. console.warn(msg);
  12417. });
  12418. }
  12419. if (!this.supportsPrinting) {
  12420. appConfig.toolbar?.print?.classList.add("hidden");
  12421. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  12422. }
  12423. if (!this.supportsFullscreen) {
  12424. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  12425. }
  12426. if (this.supportsIntegratedFind) {
  12427. appConfig.toolbar?.viewFind?.classList.add("hidden");
  12428. }
  12429. if (file) {
  12430. this.open({
  12431. url: file
  12432. });
  12433. } else {
  12434. this._hideViewBookmark();
  12435. }
  12436. },
  12437. get externalServices() {
  12438. return shadow(this, "externalServices", new ExternalServices());
  12439. },
  12440. get initialized() {
  12441. return this._initializedCapability.settled;
  12442. },
  12443. get initializedPromise() {
  12444. return this._initializedCapability.promise;
  12445. },
  12446. updateZoom(steps, scaleFactor, origin) {
  12447. if (this.pdfViewer.isInPresentationMode) {
  12448. return;
  12449. }
  12450. this.pdfViewer.updateScale({
  12451. drawingDelay: AppOptions.get("defaultZoomDelay"),
  12452. steps,
  12453. scaleFactor,
  12454. origin
  12455. });
  12456. },
  12457. zoomIn() {
  12458. this.updateZoom(1);
  12459. },
  12460. zoomOut() {
  12461. this.updateZoom(-1);
  12462. },
  12463. zoomReset() {
  12464. if (this.pdfViewer.isInPresentationMode) {
  12465. return;
  12466. }
  12467. this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  12468. },
  12469. get pagesCount() {
  12470. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  12471. },
  12472. get page() {
  12473. return this.pdfViewer.currentPageNumber;
  12474. },
  12475. set page(val) {
  12476. this.pdfViewer.currentPageNumber = val;
  12477. },
  12478. get supportsPrinting() {
  12479. return PDFPrintServiceFactory.supportsPrinting;
  12480. },
  12481. get supportsFullscreen() {
  12482. return shadow(this, "supportsFullscreen", document.fullscreenEnabled);
  12483. },
  12484. get supportsPinchToZoom() {
  12485. return shadow(this, "supportsPinchToZoom", AppOptions.get("supportsPinchToZoom"));
  12486. },
  12487. get supportsIntegratedFind() {
  12488. return shadow(this, "supportsIntegratedFind", AppOptions.get("supportsIntegratedFind"));
  12489. },
  12490. get loadingBar() {
  12491. const barElement = document.getElementById("loadingBar");
  12492. const bar = barElement ? new ProgressBar(barElement) : null;
  12493. return shadow(this, "loadingBar", bar);
  12494. },
  12495. get supportsMouseWheelZoomCtrlKey() {
  12496. return shadow(this, "supportsMouseWheelZoomCtrlKey", AppOptions.get("supportsMouseWheelZoomCtrlKey"));
  12497. },
  12498. get supportsMouseWheelZoomMetaKey() {
  12499. return shadow(this, "supportsMouseWheelZoomMetaKey", AppOptions.get("supportsMouseWheelZoomMetaKey"));
  12500. },
  12501. get supportsCaretBrowsingMode() {
  12502. return AppOptions.get("supportsCaretBrowsingMode");
  12503. },
  12504. moveCaret(isUp, select) {
  12505. this._caretBrowsing ||= new CaretBrowsingMode(this.appConfig.mainContainer, this.appConfig.viewerContainer, this.appConfig.toolbar?.container);
  12506. this._caretBrowsing.moveCaret(isUp, select);
  12507. },
  12508. setTitleUsingUrl(url = "", downloadUrl = null) {
  12509. this.url = url;
  12510. this.baseUrl = url.split("#", 1)[0];
  12511. if (downloadUrl) {
  12512. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#", 1)[0];
  12513. }
  12514. if (isDataScheme(url)) {
  12515. this._hideViewBookmark();
  12516. }
  12517. let title = pdfjs_getPdfFilenameFromUrl(url, "");
  12518. if (!title) {
  12519. try {
  12520. title = decodeURIComponent(getFilenameFromUrl(url));
  12521. } catch {}
  12522. }
  12523. this.setTitle(title || url);
  12524. },
  12525. setTitle(title = this._title) {
  12526. this._title = title;
  12527. if (this.isViewerEmbedded) {
  12528. return;
  12529. }
  12530. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  12531. document.title = `${editorIndicator ? "* " : ""}${title}`;
  12532. },
  12533. get _docFilename() {
  12534. return this._contentDispositionFilename || pdfjs_getPdfFilenameFromUrl(this.url);
  12535. },
  12536. _hideViewBookmark() {
  12537. const {
  12538. secondaryToolbar
  12539. } = this.appConfig;
  12540. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  12541. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  12542. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  12543. }
  12544. },
  12545. async close() {
  12546. this._unblockDocumentLoadEvent();
  12547. this._hideViewBookmark();
  12548. if (!this.pdfLoadingTask) {
  12549. return;
  12550. }
  12551. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  12552. try {
  12553. await this.save();
  12554. } catch {}
  12555. }
  12556. const promises = [];
  12557. promises.push(this.pdfLoadingTask.destroy());
  12558. this.pdfLoadingTask = null;
  12559. if (this.pdfDocument) {
  12560. this.pdfDocument = null;
  12561. this.pdfThumbnailViewer?.setDocument(null);
  12562. this.pdfViewer.setDocument(null);
  12563. this.pdfLinkService.setDocument(null);
  12564. this.pdfDocumentProperties?.setDocument(null);
  12565. }
  12566. this.pdfLinkService.externalLinkEnabled = true;
  12567. this.store = null;
  12568. this.isInitialViewSet = false;
  12569. this.url = "";
  12570. this.baseUrl = "";
  12571. this._downloadUrl = "";
  12572. this.documentInfo = null;
  12573. this.metadata = null;
  12574. this._contentDispositionFilename = null;
  12575. this._contentLength = null;
  12576. this._saveInProgress = false;
  12577. this._hasAnnotationEditors = false;
  12578. promises.push(this.pdfScriptingManager.destroyPromise, this.passwordPrompt.close());
  12579. this.setTitle();
  12580. this.pdfSidebar?.reset();
  12581. this.pdfOutlineViewer?.reset();
  12582. this.pdfAttachmentViewer?.reset();
  12583. this.pdfLayerViewer?.reset();
  12584. this.pdfHistory?.reset();
  12585. this.findBar?.reset();
  12586. this.toolbar?.reset();
  12587. this.secondaryToolbar?.reset();
  12588. this._PDFBug?.cleanup();
  12589. await Promise.all(promises);
  12590. },
  12591. async open(args) {
  12592. if (this.pdfLoadingTask) {
  12593. await this.close();
  12594. }
  12595. const workerParams = AppOptions.getAll(OptionKind.WORKER);
  12596. Object.assign(GlobalWorkerOptions, workerParams);
  12597. if (args.url) {
  12598. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  12599. }
  12600. const apiParams = AppOptions.getAll(OptionKind.API);
  12601. const loadingTask = getDocument({
  12602. ...apiParams,
  12603. ...args
  12604. });
  12605. this.pdfLoadingTask = loadingTask;
  12606. loadingTask.onPassword = (updateCallback, reason) => {
  12607. if (this.isViewerEmbedded) {
  12608. this._unblockDocumentLoadEvent();
  12609. }
  12610. this.pdfLinkService.externalLinkEnabled = false;
  12611. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  12612. this.passwordPrompt.open();
  12613. };
  12614. loadingTask.onProgress = ({
  12615. loaded,
  12616. total
  12617. }) => {
  12618. this.progress(loaded / total);
  12619. };
  12620. return loadingTask.promise.then(pdfDocument => {
  12621. this.load(pdfDocument);
  12622. }, reason => {
  12623. if (loadingTask !== this.pdfLoadingTask) {
  12624. return undefined;
  12625. }
  12626. let key = "pdfjs-loading-error";
  12627. if (reason instanceof InvalidPDFException) {
  12628. key = "pdfjs-invalid-file-error";
  12629. } else if (reason instanceof MissingPDFException) {
  12630. key = "pdfjs-missing-file-error";
  12631. } else if (reason instanceof UnexpectedResponseException) {
  12632. key = "pdfjs-unexpected-response-error";
  12633. }
  12634. return this._documentError(key, {
  12635. message: reason.message
  12636. }).then(() => {
  12637. throw reason;
  12638. });
  12639. });
  12640. },
  12641. async download(options = {}) {
  12642. let data;
  12643. try {
  12644. data = await this.pdfDocument.getData();
  12645. } catch {}
  12646. this.downloadManager.download(data, this._downloadUrl, this._docFilename, options);
  12647. },
  12648. async save(options = {}) {
  12649. if (this._saveInProgress) {
  12650. return;
  12651. }
  12652. this._saveInProgress = true;
  12653. await this.pdfScriptingManager.dispatchWillSave();
  12654. try {
  12655. const data = await this.pdfDocument.saveDocument();
  12656. this.downloadManager.download(data, this._downloadUrl, this._docFilename, options);
  12657. } catch (reason) {
  12658. console.error(`Error when saving the document: ${reason.message}`);
  12659. await this.download(options);
  12660. } finally {
  12661. await this.pdfScriptingManager.dispatchDidSave();
  12662. this._saveInProgress = false;
  12663. }
  12664. if (this._hasAnnotationEditors) {
  12665. this.externalServices.reportTelemetry({
  12666. type: "editing",
  12667. data: {
  12668. type: "save",
  12669. stats: this.pdfDocument?.annotationStorage.editorStats
  12670. }
  12671. });
  12672. }
  12673. },
  12674. async downloadOrSave(options = {}) {
  12675. const {
  12676. classList
  12677. } = this.appConfig.appContainer;
  12678. classList.add("wait");
  12679. await (this.pdfDocument?.annotationStorage.size > 0 ? this.save(options) : this.download(options));
  12680. classList.remove("wait");
  12681. },
  12682. async _documentError(key, moreInfo = null) {
  12683. this._unblockDocumentLoadEvent();
  12684. const message = await this._otherError(key || "pdfjs-loading-error", moreInfo);
  12685. this.eventBus.dispatch("documenterror", {
  12686. source: this,
  12687. message,
  12688. reason: moreInfo?.message ?? null
  12689. });
  12690. },
  12691. async _otherError(key, moreInfo = null) {
  12692. const message = await this.l10n.get(key);
  12693. const moreInfoText = [`PDF.js v${version || "?"} (build: ${build || "?"})`];
  12694. if (moreInfo) {
  12695. moreInfoText.push(`Message: ${moreInfo.message}`);
  12696. if (moreInfo.stack) {
  12697. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  12698. } else {
  12699. if (moreInfo.filename) {
  12700. moreInfoText.push(`File: ${moreInfo.filename}`);
  12701. }
  12702. if (moreInfo.lineNumber) {
  12703. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  12704. }
  12705. }
  12706. }
  12707. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  12708. return message;
  12709. },
  12710. progress(level) {
  12711. const percent = Math.round(level * 100);
  12712. if (!this.loadingBar || percent <= this.loadingBar.percent) {
  12713. return;
  12714. }
  12715. this.loadingBar.percent = percent;
  12716. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? AppOptions.get("disableAutoFetch")) {
  12717. this.loadingBar.setDisableAutoFetch();
  12718. }
  12719. },
  12720. load(pdfDocument) {
  12721. this.pdfDocument = pdfDocument;
  12722. pdfDocument.getDownloadInfo().then(({
  12723. length
  12724. }) => {
  12725. this._contentLength = length;
  12726. this.loadingBar?.hide();
  12727. firstPagePromise.then(() => {
  12728. this.eventBus.dispatch("documentloaded", {
  12729. source: this
  12730. });
  12731. });
  12732. });
  12733. const pageLayoutPromise = pdfDocument.getPageLayout().catch(() => {});
  12734. const pageModePromise = pdfDocument.getPageMode().catch(() => {});
  12735. const openActionPromise = pdfDocument.getOpenAction().catch(() => {});
  12736. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  12737. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  12738. this.pdfLinkService.setDocument(pdfDocument);
  12739. this.pdfDocumentProperties?.setDocument(pdfDocument);
  12740. const pdfViewer = this.pdfViewer;
  12741. pdfViewer.setDocument(pdfDocument);
  12742. const {
  12743. firstPagePromise,
  12744. onePageRendered,
  12745. pagesPromise
  12746. } = pdfViewer;
  12747. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  12748. const storedPromise = (this.store = new ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  12749. page: null,
  12750. zoom: DEFAULT_SCALE_VALUE,
  12751. scrollLeft: "0",
  12752. scrollTop: "0",
  12753. rotation: null,
  12754. sidebarView: SidebarView.UNKNOWN,
  12755. scrollMode: ScrollMode.UNKNOWN,
  12756. spreadMode: SpreadMode.UNKNOWN
  12757. }).catch(() => {});
  12758. firstPagePromise.then(pdfPage => {
  12759. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  12760. this._initializeAnnotationStorageCallbacks(pdfDocument);
  12761. Promise.all([animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  12762. const viewOnLoad = AppOptions.get("viewOnLoad");
  12763. this._initializePdfHistory({
  12764. fingerprint: pdfDocument.fingerprints[0],
  12765. viewOnLoad,
  12766. initialDest: openAction?.dest
  12767. });
  12768. const initialBookmark = this.initialBookmark;
  12769. const zoom = AppOptions.get("defaultZoomValue");
  12770. let hash = zoom ? `zoom=${zoom}` : null;
  12771. let rotation = null;
  12772. let sidebarView = AppOptions.get("sidebarViewOnLoad");
  12773. let scrollMode = AppOptions.get("scrollModeOnLoad");
  12774. let spreadMode = AppOptions.get("spreadModeOnLoad");
  12775. if (stored?.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  12776. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  12777. rotation = parseInt(stored.rotation, 10);
  12778. if (sidebarView === SidebarView.UNKNOWN) {
  12779. sidebarView = stored.sidebarView | 0;
  12780. }
  12781. if (scrollMode === ScrollMode.UNKNOWN) {
  12782. scrollMode = stored.scrollMode | 0;
  12783. }
  12784. if (spreadMode === SpreadMode.UNKNOWN) {
  12785. spreadMode = stored.spreadMode | 0;
  12786. }
  12787. }
  12788. if (pageMode && sidebarView === SidebarView.UNKNOWN) {
  12789. sidebarView = apiPageModeToSidebarView(pageMode);
  12790. }
  12791. if (pageLayout && scrollMode === ScrollMode.UNKNOWN && spreadMode === SpreadMode.UNKNOWN) {
  12792. const modes = apiPageLayoutToViewerModes(pageLayout);
  12793. spreadMode = modes.spreadMode;
  12794. }
  12795. this.setInitialView(hash, {
  12796. rotation,
  12797. sidebarView,
  12798. scrollMode,
  12799. spreadMode
  12800. });
  12801. this.eventBus.dispatch("documentinit", {
  12802. source: this
  12803. });
  12804. if (!this.isViewerEmbedded) {
  12805. pdfViewer.focus();
  12806. }
  12807. await Promise.race([pagesPromise, new Promise(resolve => {
  12808. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  12809. })]);
  12810. if (!initialBookmark && !hash) {
  12811. return;
  12812. }
  12813. if (pdfViewer.hasEqualPageSizes) {
  12814. return;
  12815. }
  12816. this.initialBookmark = initialBookmark;
  12817. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  12818. this.setInitialView(hash);
  12819. }).catch(() => {
  12820. this.setInitialView();
  12821. }).then(function () {
  12822. pdfViewer.update();
  12823. });
  12824. });
  12825. pagesPromise.then(() => {
  12826. this._unblockDocumentLoadEvent();
  12827. this._initializeAutoPrint(pdfDocument, openActionPromise);
  12828. }, reason => {
  12829. this._documentError("pdfjs-loading-error", {
  12830. message: reason.message
  12831. });
  12832. });
  12833. onePageRendered.then(data => {
  12834. this.externalServices.reportTelemetry({
  12835. type: "pageInfo",
  12836. timestamp: data.timestamp
  12837. });
  12838. if (this.pdfOutlineViewer) {
  12839. pdfDocument.getOutline().then(outline => {
  12840. if (pdfDocument !== this.pdfDocument) {
  12841. return;
  12842. }
  12843. this.pdfOutlineViewer.render({
  12844. outline,
  12845. pdfDocument
  12846. });
  12847. });
  12848. }
  12849. if (this.pdfAttachmentViewer) {
  12850. pdfDocument.getAttachments().then(attachments => {
  12851. if (pdfDocument !== this.pdfDocument) {
  12852. return;
  12853. }
  12854. this.pdfAttachmentViewer.render({
  12855. attachments
  12856. });
  12857. });
  12858. }
  12859. if (this.pdfLayerViewer) {
  12860. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  12861. if (pdfDocument !== this.pdfDocument) {
  12862. return;
  12863. }
  12864. this.pdfLayerViewer.render({
  12865. optionalContentConfig,
  12866. pdfDocument
  12867. });
  12868. });
  12869. }
  12870. });
  12871. this._initializePageLabels(pdfDocument);
  12872. this._initializeMetadata(pdfDocument);
  12873. },
  12874. async _scriptingDocProperties(pdfDocument) {
  12875. if (!this.documentInfo) {
  12876. await new Promise(resolve => {
  12877. this.eventBus._on("metadataloaded", resolve, {
  12878. once: true
  12879. });
  12880. });
  12881. if (pdfDocument !== this.pdfDocument) {
  12882. return null;
  12883. }
  12884. }
  12885. if (!this._contentLength) {
  12886. await new Promise(resolve => {
  12887. this.eventBus._on("documentloaded", resolve, {
  12888. once: true
  12889. });
  12890. });
  12891. if (pdfDocument !== this.pdfDocument) {
  12892. return null;
  12893. }
  12894. }
  12895. return {
  12896. ...this.documentInfo,
  12897. baseURL: this.baseUrl,
  12898. filesize: this._contentLength,
  12899. filename: this._docFilename,
  12900. metadata: this.metadata?.getRaw(),
  12901. authors: this.metadata?.get("dc:creator"),
  12902. numPages: this.pagesCount,
  12903. URL: this.url
  12904. };
  12905. },
  12906. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  12907. const [openAction, jsActions] = await Promise.all([openActionPromise, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions()]);
  12908. if (pdfDocument !== this.pdfDocument) {
  12909. return;
  12910. }
  12911. let triggerAutoPrint = openAction?.action === "Print";
  12912. if (jsActions) {
  12913. console.warn("Warning: JavaScript support is not enabled");
  12914. for (const name in jsActions) {
  12915. if (triggerAutoPrint) {
  12916. break;
  12917. }
  12918. switch (name) {
  12919. case "WillClose":
  12920. case "WillSave":
  12921. case "DidSave":
  12922. case "WillPrint":
  12923. case "DidPrint":
  12924. continue;
  12925. }
  12926. triggerAutoPrint = jsActions[name].some(js => AutoPrintRegExp.test(js));
  12927. }
  12928. }
  12929. if (triggerAutoPrint) {
  12930. this.triggerPrinting();
  12931. }
  12932. },
  12933. async _initializeMetadata(pdfDocument) {
  12934. const {
  12935. info,
  12936. metadata,
  12937. contentDispositionFilename,
  12938. contentLength
  12939. } = await pdfDocument.getMetadata();
  12940. if (pdfDocument !== this.pdfDocument) {
  12941. return;
  12942. }
  12943. this.documentInfo = info;
  12944. this.metadata = metadata;
  12945. this._contentDispositionFilename ??= contentDispositionFilename;
  12946. this._contentLength ??= contentLength;
  12947. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${version || "?"} [${build || "?"}])`);
  12948. let pdfTitle = info.Title;
  12949. const metadataTitle = metadata?.get("dc:title");
  12950. if (metadataTitle) {
  12951. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  12952. pdfTitle = metadataTitle;
  12953. }
  12954. }
  12955. if (pdfTitle) {
  12956. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  12957. } else if (this._contentDispositionFilename) {
  12958. this.setTitle(this._contentDispositionFilename);
  12959. }
  12960. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  12961. if (pdfDocument.loadingParams.enableXfa) {
  12962. console.warn("Warning: XFA Foreground documents are not supported");
  12963. } else {
  12964. console.warn("Warning: XFA support is not enabled");
  12965. }
  12966. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  12967. console.warn("Warning: Interactive form support is not enabled");
  12968. }
  12969. if (info.IsSignaturesPresent) {
  12970. console.warn("Warning: Digital signatures validation is not supported");
  12971. }
  12972. this.eventBus.dispatch("metadataloaded", {
  12973. source: this
  12974. });
  12975. },
  12976. async _initializePageLabels(pdfDocument) {
  12977. const labels = await pdfDocument.getPageLabels();
  12978. if (pdfDocument !== this.pdfDocument) {
  12979. return;
  12980. }
  12981. if (!labels || AppOptions.get("disablePageLabels")) {
  12982. return;
  12983. }
  12984. const numLabels = labels.length;
  12985. let standardLabels = 0,
  12986. emptyLabels = 0;
  12987. for (let i = 0; i < numLabels; i++) {
  12988. const label = labels[i];
  12989. if (label === (i + 1).toString()) {
  12990. standardLabels++;
  12991. } else if (label === "") {
  12992. emptyLabels++;
  12993. } else {
  12994. break;
  12995. }
  12996. }
  12997. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  12998. return;
  12999. }
  13000. const {
  13001. pdfViewer,
  13002. pdfThumbnailViewer,
  13003. toolbar
  13004. } = this;
  13005. pdfViewer.setPageLabels(labels);
  13006. pdfThumbnailViewer?.setPageLabels(labels);
  13007. toolbar?.setPagesCount(numLabels, true);
  13008. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  13009. },
  13010. _initializePdfHistory({
  13011. fingerprint,
  13012. viewOnLoad,
  13013. initialDest = null
  13014. }) {
  13015. if (!this.pdfHistory) {
  13016. return;
  13017. }
  13018. this.pdfHistory.initialize({
  13019. fingerprint,
  13020. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  13021. updateUrl: AppOptions.get("historyUpdateUrl")
  13022. });
  13023. if (this.pdfHistory.initialBookmark) {
  13024. this.initialBookmark = this.pdfHistory.initialBookmark;
  13025. this.initialRotation = this.pdfHistory.initialRotation;
  13026. }
  13027. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  13028. this.initialBookmark = JSON.stringify(initialDest);
  13029. this.pdfHistory.push({
  13030. explicitDest: initialDest,
  13031. pageNumber: null
  13032. });
  13033. }
  13034. },
  13035. _initializeAnnotationStorageCallbacks(pdfDocument) {
  13036. if (pdfDocument !== this.pdfDocument) {
  13037. return;
  13038. }
  13039. const {
  13040. annotationStorage
  13041. } = pdfDocument;
  13042. annotationStorage.onSetModified = () => {
  13043. window.addEventListener("beforeunload", beforeUnload);
  13044. this._annotationStorageModified = true;
  13045. };
  13046. annotationStorage.onResetModified = () => {
  13047. window.removeEventListener("beforeunload", beforeUnload);
  13048. delete this._annotationStorageModified;
  13049. };
  13050. annotationStorage.onAnnotationEditor = typeStr => {
  13051. this._hasAnnotationEditors = !!typeStr;
  13052. this.setTitle();
  13053. };
  13054. },
  13055. setInitialView(storedHash, {
  13056. rotation,
  13057. sidebarView,
  13058. scrollMode,
  13059. spreadMode
  13060. } = {}) {
  13061. const setRotation = angle => {
  13062. if (isValidRotation(angle)) {
  13063. this.pdfViewer.pagesRotation = angle;
  13064. }
  13065. };
  13066. const setViewerModes = (scroll, spread) => {
  13067. if (isValidScrollMode(scroll)) {
  13068. this.pdfViewer.scrollMode = scroll;
  13069. }
  13070. if (isValidSpreadMode(spread)) {
  13071. this.pdfViewer.spreadMode = spread;
  13072. }
  13073. };
  13074. this.isInitialViewSet = true;
  13075. this.pdfSidebar?.setInitialView(sidebarView);
  13076. setViewerModes(scrollMode, spreadMode);
  13077. if (this.initialBookmark) {
  13078. setRotation(this.initialRotation);
  13079. delete this.initialRotation;
  13080. this.pdfLinkService.setHash(this.initialBookmark);
  13081. this.initialBookmark = null;
  13082. } else if (storedHash) {
  13083. setRotation(rotation);
  13084. this.pdfLinkService.setHash(storedHash);
  13085. }
  13086. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  13087. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  13088. if (!this.pdfViewer.currentScaleValue) {
  13089. this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  13090. }
  13091. },
  13092. _cleanup() {
  13093. if (!this.pdfDocument) {
  13094. return;
  13095. }
  13096. this.pdfViewer.cleanup();
  13097. this.pdfThumbnailViewer?.cleanup();
  13098. this.pdfDocument.cleanup(AppOptions.get("fontExtraProperties"));
  13099. },
  13100. forceRendering() {
  13101. this.pdfRenderingQueue.printing = !!this.printService;
  13102. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === SidebarView.THUMBS;
  13103. this.pdfRenderingQueue.renderHighestPriority();
  13104. },
  13105. beforePrint() {
  13106. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => this.pdfDocument?.annotationStorage.print);
  13107. if (this.printService) {
  13108. return;
  13109. }
  13110. if (!this.supportsPrinting) {
  13111. this._otherError("pdfjs-printing-not-supported");
  13112. return;
  13113. }
  13114. if (!this.pdfViewer.pageViewsReady) {
  13115. this.l10n.get("pdfjs-printing-not-ready").then(msg => {
  13116. window.alert(msg);
  13117. });
  13118. return;
  13119. }
  13120. this.printService = PDFPrintServiceFactory.createPrintService({
  13121. pdfDocument: this.pdfDocument,
  13122. pagesOverview: this.pdfViewer.getPagesOverview(),
  13123. printContainer: this.appConfig.printContainer,
  13124. printResolution: AppOptions.get("printResolution"),
  13125. printAnnotationStoragePromise: this._printAnnotationStoragePromise
  13126. });
  13127. this.forceRendering();
  13128. this.setTitle();
  13129. this.printService.layout();
  13130. if (this._hasAnnotationEditors) {
  13131. this.externalServices.reportTelemetry({
  13132. type: "editing",
  13133. data: {
  13134. type: "print",
  13135. stats: this.pdfDocument?.annotationStorage.editorStats
  13136. }
  13137. });
  13138. }
  13139. },
  13140. afterPrint() {
  13141. if (this._printAnnotationStoragePromise) {
  13142. this._printAnnotationStoragePromise.then(() => {
  13143. this.pdfScriptingManager.dispatchDidPrint();
  13144. });
  13145. this._printAnnotationStoragePromise = null;
  13146. }
  13147. if (this.printService) {
  13148. this.printService.destroy();
  13149. this.printService = null;
  13150. this.pdfDocument?.annotationStorage.resetModified();
  13151. }
  13152. this.forceRendering();
  13153. this.setTitle();
  13154. },
  13155. rotatePages(delta) {
  13156. this.pdfViewer.pagesRotation += delta;
  13157. },
  13158. requestPresentationMode() {
  13159. this.pdfPresentationMode?.request();
  13160. },
  13161. triggerPrinting() {
  13162. if (!this.supportsPrinting) {
  13163. return;
  13164. }
  13165. window.print();
  13166. },
  13167. bindEvents() {
  13168. if (this._eventBusAbortController) {
  13169. return;
  13170. }
  13171. this._eventBusAbortController = new AbortController();
  13172. const {
  13173. eventBus,
  13174. _eventBusAbortController: {
  13175. signal
  13176. }
  13177. } = this;
  13178. eventBus._on("resize", webViewerResize, {
  13179. signal
  13180. });
  13181. eventBus._on("hashchange", webViewerHashchange, {
  13182. signal
  13183. });
  13184. eventBus._on("beforeprint", this.beforePrint.bind(this), {
  13185. signal
  13186. });
  13187. eventBus._on("afterprint", this.afterPrint.bind(this), {
  13188. signal
  13189. });
  13190. eventBus._on("pagerender", webViewerPageRender, {
  13191. signal
  13192. });
  13193. eventBus._on("pagerendered", webViewerPageRendered, {
  13194. signal
  13195. });
  13196. eventBus._on("updateviewarea", webViewerUpdateViewarea, {
  13197. signal
  13198. });
  13199. eventBus._on("pagechanging", webViewerPageChanging, {
  13200. signal
  13201. });
  13202. eventBus._on("scalechanging", webViewerScaleChanging, {
  13203. signal
  13204. });
  13205. eventBus._on("rotationchanging", webViewerRotationChanging, {
  13206. signal
  13207. });
  13208. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged, {
  13209. signal
  13210. });
  13211. eventBus._on("pagemode", webViewerPageMode, {
  13212. signal
  13213. });
  13214. eventBus._on("namedaction", webViewerNamedAction, {
  13215. signal
  13216. });
  13217. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged, {
  13218. signal
  13219. });
  13220. eventBus._on("presentationmode", webViewerPresentationMode, {
  13221. signal
  13222. });
  13223. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode, {
  13224. signal
  13225. });
  13226. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams, {
  13227. signal
  13228. });
  13229. eventBus._on("print", webViewerPrint, {
  13230. signal
  13231. });
  13232. eventBus._on("download", webViewerDownload, {
  13233. signal
  13234. });
  13235. eventBus._on("firstpage", webViewerFirstPage, {
  13236. signal
  13237. });
  13238. eventBus._on("lastpage", webViewerLastPage, {
  13239. signal
  13240. });
  13241. eventBus._on("nextpage", webViewerNextPage, {
  13242. signal
  13243. });
  13244. eventBus._on("previouspage", webViewerPreviousPage, {
  13245. signal
  13246. });
  13247. eventBus._on("zoomin", webViewerZoomIn, {
  13248. signal
  13249. });
  13250. eventBus._on("zoomout", webViewerZoomOut, {
  13251. signal
  13252. });
  13253. eventBus._on("zoomreset", webViewerZoomReset, {
  13254. signal
  13255. });
  13256. eventBus._on("pagenumberchanged", webViewerPageNumberChanged, {
  13257. signal
  13258. });
  13259. eventBus._on("scalechanged", webViewerScaleChanged, {
  13260. signal
  13261. });
  13262. eventBus._on("rotatecw", webViewerRotateCw, {
  13263. signal
  13264. });
  13265. eventBus._on("rotateccw", webViewerRotateCcw, {
  13266. signal
  13267. });
  13268. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig, {
  13269. signal
  13270. });
  13271. eventBus._on("switchscrollmode", webViewerSwitchScrollMode, {
  13272. signal
  13273. });
  13274. eventBus._on("scrollmodechanged", webViewerScrollModeChanged, {
  13275. signal
  13276. });
  13277. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode, {
  13278. signal
  13279. });
  13280. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged, {
  13281. signal
  13282. });
  13283. eventBus._on("documentproperties", webViewerDocumentProperties, {
  13284. signal
  13285. });
  13286. eventBus._on("findfromurlhash", webViewerFindFromUrlHash, {
  13287. signal
  13288. });
  13289. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount, {
  13290. signal
  13291. });
  13292. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState, {
  13293. signal
  13294. });
  13295. eventBus._on("fileinputchange", webViewerFileInputChange, {
  13296. signal
  13297. });
  13298. eventBus._on("openfile", webViewerOpenFile, {
  13299. signal
  13300. });
  13301. },
  13302. bindWindowEvents() {
  13303. if (this._windowAbortController) {
  13304. return;
  13305. }
  13306. this._windowAbortController = new AbortController();
  13307. const {
  13308. eventBus,
  13309. appConfig: {
  13310. mainContainer
  13311. },
  13312. _windowAbortController: {
  13313. signal
  13314. }
  13315. } = this;
  13316. function addWindowResolutionChange(evt = null) {
  13317. if (evt) {
  13318. webViewerResolutionChange(evt);
  13319. }
  13320. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  13321. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  13322. once: true,
  13323. signal
  13324. });
  13325. }
  13326. addWindowResolutionChange();
  13327. window.addEventListener("wheel", webViewerWheel, {
  13328. passive: false,
  13329. signal
  13330. });
  13331. window.addEventListener("touchstart", webViewerTouchStart, {
  13332. passive: false,
  13333. signal
  13334. });
  13335. window.addEventListener("touchmove", webViewerTouchMove, {
  13336. passive: false,
  13337. signal
  13338. });
  13339. window.addEventListener("touchend", webViewerTouchEnd, {
  13340. passive: false,
  13341. signal
  13342. });
  13343. window.addEventListener("click", webViewerClick, {
  13344. signal
  13345. });
  13346. window.addEventListener("keydown", webViewerKeyDown, {
  13347. signal
  13348. });
  13349. window.addEventListener("keyup", webViewerKeyUp, {
  13350. signal
  13351. });
  13352. window.addEventListener("resize", () => {
  13353. eventBus.dispatch("resize", {
  13354. source: window
  13355. });
  13356. }, {
  13357. signal
  13358. });
  13359. window.addEventListener("hashchange", () => {
  13360. eventBus.dispatch("hashchange", {
  13361. source: window,
  13362. hash: document.location.hash.substring(1)
  13363. });
  13364. }, {
  13365. signal
  13366. });
  13367. window.addEventListener("beforeprint", () => {
  13368. eventBus.dispatch("beforeprint", {
  13369. source: window
  13370. });
  13371. }, {
  13372. signal
  13373. });
  13374. window.addEventListener("afterprint", () => {
  13375. eventBus.dispatch("afterprint", {
  13376. source: window
  13377. });
  13378. }, {
  13379. signal
  13380. });
  13381. window.addEventListener("updatefromsandbox", event => {
  13382. eventBus.dispatch("updatefromsandbox", {
  13383. source: window,
  13384. detail: event.detail
  13385. });
  13386. }, {
  13387. signal
  13388. });
  13389. if (!("onscrollend" in document.documentElement)) {
  13390. return;
  13391. }
  13392. ({
  13393. scrollTop: this._lastScrollTop,
  13394. scrollLeft: this._lastScrollLeft
  13395. } = mainContainer);
  13396. const scrollend = () => {
  13397. ({
  13398. scrollTop: this._lastScrollTop,
  13399. scrollLeft: this._lastScrollLeft
  13400. } = mainContainer);
  13401. this._isScrolling = false;
  13402. mainContainer.addEventListener("scroll", scroll, {
  13403. passive: true,
  13404. signal
  13405. });
  13406. mainContainer.removeEventListener("scrollend", scrollend);
  13407. mainContainer.removeEventListener("blur", scrollend);
  13408. };
  13409. const scroll = () => {
  13410. if (this._isCtrlKeyDown) {
  13411. return;
  13412. }
  13413. if (this._lastScrollTop === mainContainer.scrollTop && this._lastScrollLeft === mainContainer.scrollLeft) {
  13414. return;
  13415. }
  13416. mainContainer.removeEventListener("scroll", scroll, {
  13417. passive: true
  13418. });
  13419. this._isScrolling = true;
  13420. mainContainer.addEventListener("scrollend", scrollend, {
  13421. signal
  13422. });
  13423. mainContainer.addEventListener("blur", scrollend, {
  13424. signal
  13425. });
  13426. };
  13427. mainContainer.addEventListener("scroll", scroll, {
  13428. passive: true,
  13429. signal
  13430. });
  13431. },
  13432. unbindEvents() {
  13433. this._eventBusAbortController?.abort();
  13434. this._eventBusAbortController = null;
  13435. },
  13436. unbindWindowEvents() {
  13437. this._windowAbortController?.abort();
  13438. this._windowAbortController = null;
  13439. },
  13440. async testingClose() {
  13441. this.unbindEvents();
  13442. this.unbindWindowEvents();
  13443. this._globalAbortController?.abort();
  13444. this._globalAbortController = null;
  13445. this.findBar?.close();
  13446. await Promise.all([this.l10n?.destroy(), this.close()]);
  13447. },
  13448. _accumulateTicks(ticks, prop) {
  13449. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  13450. this[prop] = 0;
  13451. }
  13452. this[prop] += ticks;
  13453. const wholeTicks = Math.trunc(this[prop]);
  13454. this[prop] -= wholeTicks;
  13455. return wholeTicks;
  13456. },
  13457. _accumulateFactor(previousScale, factor, prop) {
  13458. if (factor === 1) {
  13459. return 1;
  13460. }
  13461. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  13462. this[prop] = 1;
  13463. }
  13464. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  13465. this[prop] = factor / newFactor;
  13466. return newFactor;
  13467. },
  13468. _unblockDocumentLoadEvent() {
  13469. document.blockUnblockOnload?.(false);
  13470. this._unblockDocumentLoadEvent = () => {};
  13471. },
  13472. get scriptingReady() {
  13473. return this.pdfScriptingManager.ready;
  13474. }
  13475. };
  13476. initCom(PDFViewerApplication);
  13477. {
  13478. PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
  13479. }
  13480. {
  13481. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  13482. var validateFileURL = function (file) {
  13483. if (!file) {
  13484. return;
  13485. }
  13486. try {
  13487. const viewerOrigin = new URL(window.location.href).origin || "null";
  13488. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  13489. return;
  13490. }
  13491. const fileOrigin = new URL(file, window.location.href).origin;
  13492. if (fileOrigin !== viewerOrigin) {
  13493. throw new Error("file origin does not match viewer's");
  13494. }
  13495. } catch (ex) {
  13496. PDFViewerApplication._documentError("pdfjs-loading-error", {
  13497. message: ex.message
  13498. });
  13499. throw ex;
  13500. }
  13501. };
  13502. }
  13503. function webViewerPageRender({
  13504. pageNumber
  13505. }) {
  13506. if (pageNumber === PDFViewerApplication.page) {
  13507. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  13508. }
  13509. }
  13510. function webViewerPageRendered({
  13511. pageNumber,
  13512. error
  13513. }) {
  13514. if (pageNumber === PDFViewerApplication.page) {
  13515. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  13516. }
  13517. if (PDFViewerApplication.pdfSidebar?.visibleView === SidebarView.THUMBS) {
  13518. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  13519. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  13520. if (pageView) {
  13521. thumbnailView?.setImage(pageView);
  13522. }
  13523. }
  13524. if (error) {
  13525. PDFViewerApplication._otherError("pdfjs-rendering-error", error);
  13526. }
  13527. }
  13528. function webViewerPageMode({
  13529. mode
  13530. }) {
  13531. let view;
  13532. switch (mode) {
  13533. case "thumbs":
  13534. view = SidebarView.THUMBS;
  13535. break;
  13536. case "bookmarks":
  13537. case "outline":
  13538. view = SidebarView.OUTLINE;
  13539. break;
  13540. case "attachments":
  13541. view = SidebarView.ATTACHMENTS;
  13542. break;
  13543. case "layers":
  13544. view = SidebarView.LAYERS;
  13545. break;
  13546. case "none":
  13547. view = SidebarView.NONE;
  13548. break;
  13549. default:
  13550. console.error('Invalid "pagemode" hash parameter: ' + mode);
  13551. return;
  13552. }
  13553. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  13554. }
  13555. function webViewerNamedAction(evt) {
  13556. switch (evt.action) {
  13557. case "GoToPage":
  13558. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  13559. break;
  13560. case "Find":
  13561. if (!PDFViewerApplication.supportsIntegratedFind) {
  13562. PDFViewerApplication.findBar?.toggle();
  13563. }
  13564. break;
  13565. case "Print":
  13566. PDFViewerApplication.triggerPrinting();
  13567. break;
  13568. case "SaveAs":
  13569. PDFViewerApplication.downloadOrSave();
  13570. break;
  13571. }
  13572. }
  13573. function webViewerPresentationModeChanged(evt) {
  13574. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  13575. }
  13576. function webViewerSidebarViewChanged({
  13577. view
  13578. }) {
  13579. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === SidebarView.THUMBS;
  13580. if (PDFViewerApplication.isInitialViewSet) {
  13581. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  13582. }
  13583. }
  13584. function webViewerUpdateViewarea({
  13585. location
  13586. }) {
  13587. if (PDFViewerApplication.isInitialViewSet) {
  13588. PDFViewerApplication.store?.setMultiple({
  13589. page: location.pageNumber,
  13590. zoom: location.scale,
  13591. scrollLeft: location.left,
  13592. scrollTop: location.top,
  13593. rotation: location.rotation
  13594. }).catch(() => {});
  13595. }
  13596. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  13597. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  13598. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  13599. }
  13600. }
  13601. function webViewerScrollModeChanged(evt) {
  13602. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  13603. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  13604. }
  13605. }
  13606. function webViewerSpreadModeChanged(evt) {
  13607. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  13608. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  13609. }
  13610. }
  13611. function webViewerResize() {
  13612. const {
  13613. pdfDocument,
  13614. pdfViewer,
  13615. pdfRenderingQueue
  13616. } = PDFViewerApplication;
  13617. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  13618. return;
  13619. }
  13620. if (!pdfDocument) {
  13621. return;
  13622. }
  13623. const currentScaleValue = pdfViewer.currentScaleValue;
  13624. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  13625. pdfViewer.currentScaleValue = currentScaleValue;
  13626. }
  13627. pdfViewer.update();
  13628. }
  13629. function webViewerHashchange(evt) {
  13630. const hash = evt.hash;
  13631. if (!hash) {
  13632. return;
  13633. }
  13634. if (!PDFViewerApplication.isInitialViewSet) {
  13635. PDFViewerApplication.initialBookmark = hash;
  13636. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  13637. PDFViewerApplication.pdfLinkService.setHash(hash);
  13638. }
  13639. }
  13640. {
  13641. var webViewerFileInputChange = function (evt) {
  13642. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  13643. return;
  13644. }
  13645. const file = evt.fileInput.files[0];
  13646. PDFViewerApplication.open({
  13647. url: URL.createObjectURL(file),
  13648. originalUrl: file.name
  13649. });
  13650. };
  13651. var webViewerOpenFile = function (evt) {
  13652. PDFViewerApplication._openFileInput?.click();
  13653. };
  13654. }
  13655. function webViewerPresentationMode() {
  13656. PDFViewerApplication.requestPresentationMode();
  13657. }
  13658. function webViewerSwitchAnnotationEditorMode(evt) {
  13659. PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
  13660. }
  13661. function webViewerSwitchAnnotationEditorParams(evt) {
  13662. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  13663. }
  13664. function webViewerPrint() {
  13665. PDFViewerApplication.triggerPrinting();
  13666. }
  13667. function webViewerDownload() {
  13668. PDFViewerApplication.downloadOrSave();
  13669. }
  13670. function webViewerFirstPage() {
  13671. PDFViewerApplication.page = 1;
  13672. }
  13673. function webViewerLastPage() {
  13674. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  13675. }
  13676. function webViewerNextPage() {
  13677. PDFViewerApplication.pdfViewer.nextPage();
  13678. }
  13679. function webViewerPreviousPage() {
  13680. PDFViewerApplication.pdfViewer.previousPage();
  13681. }
  13682. function webViewerZoomIn() {
  13683. PDFViewerApplication.zoomIn();
  13684. }
  13685. function webViewerZoomOut() {
  13686. PDFViewerApplication.zoomOut();
  13687. }
  13688. function webViewerZoomReset() {
  13689. PDFViewerApplication.zoomReset();
  13690. }
  13691. function webViewerPageNumberChanged(evt) {
  13692. const pdfViewer = PDFViewerApplication.pdfViewer;
  13693. if (evt.value !== "") {
  13694. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  13695. }
  13696. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  13697. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  13698. }
  13699. }
  13700. function webViewerScaleChanged(evt) {
  13701. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  13702. }
  13703. function webViewerRotateCw() {
  13704. PDFViewerApplication.rotatePages(90);
  13705. }
  13706. function webViewerRotateCcw() {
  13707. PDFViewerApplication.rotatePages(-90);
  13708. }
  13709. function webViewerOptionalContentConfig(evt) {
  13710. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  13711. }
  13712. function webViewerSwitchScrollMode(evt) {
  13713. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  13714. }
  13715. function webViewerSwitchSpreadMode(evt) {
  13716. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  13717. }
  13718. function webViewerDocumentProperties() {
  13719. PDFViewerApplication.pdfDocumentProperties?.open();
  13720. }
  13721. function webViewerFindFromUrlHash(evt) {
  13722. PDFViewerApplication.eventBus.dispatch("find", {
  13723. source: evt.source,
  13724. type: "",
  13725. query: evt.query,
  13726. caseSensitive: false,
  13727. entireWord: false,
  13728. highlightAll: true,
  13729. findPrevious: false,
  13730. matchDiacritics: true
  13731. });
  13732. }
  13733. function webViewerUpdateFindMatchesCount({
  13734. matchesCount
  13735. }) {
  13736. if (PDFViewerApplication.supportsIntegratedFind) {
  13737. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  13738. } else {
  13739. PDFViewerApplication.findBar?.updateResultsCount(matchesCount);
  13740. }
  13741. }
  13742. function webViewerUpdateFindControlState({
  13743. state,
  13744. previous,
  13745. entireWord,
  13746. matchesCount,
  13747. rawQuery
  13748. }) {
  13749. if (PDFViewerApplication.supportsIntegratedFind) {
  13750. PDFViewerApplication.externalServices.updateFindControlState({
  13751. result: state,
  13752. findPrevious: previous,
  13753. entireWord,
  13754. matchesCount,
  13755. rawQuery
  13756. });
  13757. } else {
  13758. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  13759. }
  13760. }
  13761. function webViewerScaleChanging(evt) {
  13762. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  13763. PDFViewerApplication.pdfViewer.update();
  13764. }
  13765. function webViewerRotationChanging(evt) {
  13766. if (PDFViewerApplication.pdfThumbnailViewer) {
  13767. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  13768. }
  13769. PDFViewerApplication.forceRendering();
  13770. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  13771. }
  13772. function webViewerPageChanging({
  13773. pageNumber,
  13774. pageLabel
  13775. }) {
  13776. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  13777. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  13778. if (PDFViewerApplication.pdfSidebar?.visibleView === SidebarView.THUMBS) {
  13779. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  13780. }
  13781. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  13782. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === RenderingStates.RUNNING);
  13783. }
  13784. function webViewerResolutionChange(evt) {
  13785. PDFViewerApplication.pdfViewer.refresh();
  13786. }
  13787. function webViewerWheel(evt) {
  13788. const {
  13789. pdfViewer,
  13790. supportsMouseWheelZoomCtrlKey,
  13791. supportsMouseWheelZoomMetaKey,
  13792. supportsPinchToZoom
  13793. } = PDFViewerApplication;
  13794. if (pdfViewer.isInPresentationMode) {
  13795. return;
  13796. }
  13797. const deltaMode = evt.deltaMode;
  13798. let scaleFactor = Math.exp(-evt.deltaY / 100);
  13799. const isBuiltInMac = false;
  13800. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  13801. const origin = [evt.clientX, evt.clientY];
  13802. if (isPinchToZoom || evt.ctrlKey && supportsMouseWheelZoomCtrlKey || evt.metaKey && supportsMouseWheelZoomMetaKey) {
  13803. evt.preventDefault();
  13804. if (PDFViewerApplication._isScrolling || document.visibilityState === "hidden" || PDFViewerApplication.overlayManager.active) {
  13805. return;
  13806. }
  13807. if (isPinchToZoom && supportsPinchToZoom) {
  13808. scaleFactor = PDFViewerApplication._accumulateFactor(pdfViewer.currentScale, scaleFactor, "_wheelUnusedFactor");
  13809. PDFViewerApplication.updateZoom(null, scaleFactor, origin);
  13810. } else {
  13811. const delta = normalizeWheelEventDirection(evt);
  13812. let ticks = 0;
  13813. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  13814. if (Math.abs(delta) >= 1) {
  13815. ticks = Math.sign(delta);
  13816. } else {
  13817. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  13818. }
  13819. } else {
  13820. const PIXELS_PER_LINE_SCALE = 30;
  13821. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  13822. }
  13823. PDFViewerApplication.updateZoom(ticks, null, origin);
  13824. }
  13825. }
  13826. }
  13827. function webViewerTouchStart(evt) {
  13828. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  13829. return;
  13830. }
  13831. evt.preventDefault();
  13832. if (evt.touches.length !== 2 || PDFViewerApplication.overlayManager.active) {
  13833. PDFViewerApplication._touchInfo = null;
  13834. return;
  13835. }
  13836. let [touch0, touch1] = evt.touches;
  13837. if (touch0.identifier > touch1.identifier) {
  13838. [touch0, touch1] = [touch1, touch0];
  13839. }
  13840. PDFViewerApplication._touchInfo = {
  13841. touch0X: touch0.pageX,
  13842. touch0Y: touch0.pageY,
  13843. touch1X: touch1.pageX,
  13844. touch1Y: touch1.pageY
  13845. };
  13846. }
  13847. function webViewerTouchMove(evt) {
  13848. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  13849. return;
  13850. }
  13851. const {
  13852. pdfViewer,
  13853. _touchInfo,
  13854. supportsPinchToZoom
  13855. } = PDFViewerApplication;
  13856. let [touch0, touch1] = evt.touches;
  13857. if (touch0.identifier > touch1.identifier) {
  13858. [touch0, touch1] = [touch1, touch0];
  13859. }
  13860. const {
  13861. pageX: page0X,
  13862. pageY: page0Y
  13863. } = touch0;
  13864. const {
  13865. pageX: page1X,
  13866. pageY: page1Y
  13867. } = touch1;
  13868. const {
  13869. touch0X: pTouch0X,
  13870. touch0Y: pTouch0Y,
  13871. touch1X: pTouch1X,
  13872. touch1Y: pTouch1Y
  13873. } = _touchInfo;
  13874. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  13875. return;
  13876. }
  13877. _touchInfo.touch0X = page0X;
  13878. _touchInfo.touch0Y = page0Y;
  13879. _touchInfo.touch1X = page1X;
  13880. _touchInfo.touch1Y = page1Y;
  13881. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  13882. const v1X = pTouch1X - page0X;
  13883. const v1Y = pTouch1Y - page0Y;
  13884. const v2X = page1X - page0X;
  13885. const v2Y = page1Y - page0Y;
  13886. const det = v1X * v2Y - v1Y * v2X;
  13887. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  13888. return;
  13889. }
  13890. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  13891. const v1X = pTouch0X - page1X;
  13892. const v1Y = pTouch0Y - page1Y;
  13893. const v2X = page0X - page1X;
  13894. const v2Y = page0Y - page1Y;
  13895. const det = v1X * v2Y - v1Y * v2X;
  13896. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  13897. return;
  13898. }
  13899. } else {
  13900. const diff0X = page0X - pTouch0X;
  13901. const diff1X = page1X - pTouch1X;
  13902. const diff0Y = page0Y - pTouch0Y;
  13903. const diff1Y = page1Y - pTouch1Y;
  13904. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  13905. if (dotProduct >= 0) {
  13906. return;
  13907. }
  13908. }
  13909. evt.preventDefault();
  13910. const origin = [(page0X + page1X) / 2, (page0Y + page1Y) / 2];
  13911. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  13912. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  13913. if (supportsPinchToZoom) {
  13914. const newScaleFactor = PDFViewerApplication._accumulateFactor(pdfViewer.currentScale, distance / pDistance, "_touchUnusedFactor");
  13915. PDFViewerApplication.updateZoom(null, newScaleFactor, origin);
  13916. } else {
  13917. const PIXELS_PER_LINE_SCALE = 30;
  13918. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  13919. PDFViewerApplication.updateZoom(ticks, null, origin);
  13920. }
  13921. }
  13922. function webViewerTouchEnd(evt) {
  13923. if (!PDFViewerApplication._touchInfo) {
  13924. return;
  13925. }
  13926. evt.preventDefault();
  13927. PDFViewerApplication._touchInfo = null;
  13928. PDFViewerApplication._touchUnusedTicks = 0;
  13929. PDFViewerApplication._touchUnusedFactor = 1;
  13930. }
  13931. function webViewerClick(evt) {
  13932. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  13933. return;
  13934. }
  13935. const appConfig = PDFViewerApplication.appConfig;
  13936. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  13937. PDFViewerApplication.secondaryToolbar.close();
  13938. }
  13939. }
  13940. function webViewerKeyUp(evt) {
  13941. if (evt.key === "Control") {
  13942. PDFViewerApplication._isCtrlKeyDown = false;
  13943. }
  13944. }
  13945. function webViewerKeyDown(evt) {
  13946. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  13947. if (PDFViewerApplication.overlayManager.active) {
  13948. return;
  13949. }
  13950. const {
  13951. eventBus,
  13952. pdfViewer
  13953. } = PDFViewerApplication;
  13954. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  13955. let handled = false,
  13956. ensureViewerFocused = false;
  13957. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  13958. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  13959. switch (evt.keyCode) {
  13960. case 70:
  13961. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  13962. PDFViewerApplication.findBar?.open();
  13963. handled = true;
  13964. }
  13965. break;
  13966. case 71:
  13967. if (!PDFViewerApplication.supportsIntegratedFind) {
  13968. const {
  13969. state
  13970. } = PDFViewerApplication.findController;
  13971. if (state) {
  13972. const newState = {
  13973. source: window,
  13974. type: "again",
  13975. findPrevious: cmd === 5 || cmd === 12
  13976. };
  13977. eventBus.dispatch("find", {
  13978. ...state,
  13979. ...newState
  13980. });
  13981. }
  13982. handled = true;
  13983. }
  13984. break;
  13985. case 61:
  13986. case 107:
  13987. case 187:
  13988. case 171:
  13989. PDFViewerApplication.zoomIn();
  13990. handled = true;
  13991. break;
  13992. case 173:
  13993. case 109:
  13994. case 189:
  13995. PDFViewerApplication.zoomOut();
  13996. handled = true;
  13997. break;
  13998. case 48:
  13999. case 96:
  14000. if (!isViewerInPresentationMode) {
  14001. setTimeout(function () {
  14002. PDFViewerApplication.zoomReset();
  14003. });
  14004. handled = false;
  14005. }
  14006. break;
  14007. case 38:
  14008. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  14009. PDFViewerApplication.page = 1;
  14010. handled = true;
  14011. ensureViewerFocused = true;
  14012. }
  14013. break;
  14014. case 40:
  14015. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  14016. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  14017. handled = true;
  14018. ensureViewerFocused = true;
  14019. }
  14020. break;
  14021. }
  14022. }
  14023. if (cmd === 1 || cmd === 8) {
  14024. switch (evt.keyCode) {
  14025. case 83:
  14026. eventBus.dispatch("download", {
  14027. source: window
  14028. });
  14029. handled = true;
  14030. break;
  14031. case 79:
  14032. {
  14033. eventBus.dispatch("openfile", {
  14034. source: window
  14035. });
  14036. handled = true;
  14037. }
  14038. break;
  14039. }
  14040. }
  14041. if (cmd === 3 || cmd === 10) {
  14042. switch (evt.keyCode) {
  14043. case 80:
  14044. PDFViewerApplication.requestPresentationMode();
  14045. handled = true;
  14046. PDFViewerApplication.externalServices.reportTelemetry({
  14047. type: "buttons",
  14048. data: {
  14049. id: "presentationModeKeyboard"
  14050. }
  14051. });
  14052. break;
  14053. case 71:
  14054. if (PDFViewerApplication.appConfig.toolbar) {
  14055. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  14056. handled = true;
  14057. }
  14058. break;
  14059. }
  14060. }
  14061. if (handled) {
  14062. if (ensureViewerFocused && !isViewerInPresentationMode) {
  14063. pdfViewer.focus();
  14064. }
  14065. evt.preventDefault();
  14066. return;
  14067. }
  14068. const curElement = getActiveOrFocusedElement();
  14069. const curElementTagName = curElement?.tagName.toUpperCase();
  14070. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElementTagName === "BUTTON" && (evt.keyCode === 13 || evt.keyCode === 32) || curElement?.isContentEditable) {
  14071. if (evt.keyCode !== 27) {
  14072. return;
  14073. }
  14074. }
  14075. if (cmd === 0) {
  14076. let turnPage = 0,
  14077. turnOnlyIfPageFit = false;
  14078. switch (evt.keyCode) {
  14079. case 38:
  14080. if (PDFViewerApplication.supportsCaretBrowsingMode) {
  14081. PDFViewerApplication.moveCaret(true, false);
  14082. handled = true;
  14083. break;
  14084. }
  14085. case 33:
  14086. if (pdfViewer.isVerticalScrollbarEnabled) {
  14087. turnOnlyIfPageFit = true;
  14088. }
  14089. turnPage = -1;
  14090. break;
  14091. case 8:
  14092. if (!isViewerInPresentationMode) {
  14093. turnOnlyIfPageFit = true;
  14094. }
  14095. turnPage = -1;
  14096. break;
  14097. case 37:
  14098. if (PDFViewerApplication.supportsCaretBrowsingMode) {
  14099. return;
  14100. }
  14101. if (pdfViewer.isHorizontalScrollbarEnabled) {
  14102. turnOnlyIfPageFit = true;
  14103. }
  14104. case 75:
  14105. case 80:
  14106. turnPage = -1;
  14107. break;
  14108. case 27:
  14109. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  14110. PDFViewerApplication.secondaryToolbar.close();
  14111. handled = true;
  14112. }
  14113. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  14114. PDFViewerApplication.findBar.close();
  14115. handled = true;
  14116. }
  14117. break;
  14118. case 40:
  14119. if (PDFViewerApplication.supportsCaretBrowsingMode) {
  14120. PDFViewerApplication.moveCaret(false, false);
  14121. handled = true;
  14122. break;
  14123. }
  14124. case 34:
  14125. if (pdfViewer.isVerticalScrollbarEnabled) {
  14126. turnOnlyIfPageFit = true;
  14127. }
  14128. turnPage = 1;
  14129. break;
  14130. case 13:
  14131. case 32:
  14132. if (!isViewerInPresentationMode) {
  14133. turnOnlyIfPageFit = true;
  14134. }
  14135. turnPage = 1;
  14136. break;
  14137. case 39:
  14138. if (PDFViewerApplication.supportsCaretBrowsingMode) {
  14139. return;
  14140. }
  14141. if (pdfViewer.isHorizontalScrollbarEnabled) {
  14142. turnOnlyIfPageFit = true;
  14143. }
  14144. case 74:
  14145. case 78:
  14146. turnPage = 1;
  14147. break;
  14148. case 36:
  14149. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  14150. PDFViewerApplication.page = 1;
  14151. handled = true;
  14152. ensureViewerFocused = true;
  14153. }
  14154. break;
  14155. case 35:
  14156. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  14157. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  14158. handled = true;
  14159. ensureViewerFocused = true;
  14160. }
  14161. break;
  14162. case 83:
  14163. PDFViewerApplication.pdfCursorTools?.switchTool(CursorTool.SELECT);
  14164. break;
  14165. case 72:
  14166. PDFViewerApplication.pdfCursorTools?.switchTool(CursorTool.HAND);
  14167. break;
  14168. case 82:
  14169. PDFViewerApplication.rotatePages(90);
  14170. break;
  14171. case 115:
  14172. PDFViewerApplication.pdfSidebar?.toggle();
  14173. break;
  14174. }
  14175. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  14176. if (turnPage > 0) {
  14177. pdfViewer.nextPage();
  14178. } else {
  14179. pdfViewer.previousPage();
  14180. }
  14181. handled = true;
  14182. }
  14183. }
  14184. if (cmd === 4) {
  14185. switch (evt.keyCode) {
  14186. case 13:
  14187. case 32:
  14188. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  14189. break;
  14190. }
  14191. pdfViewer.previousPage();
  14192. handled = true;
  14193. break;
  14194. case 38:
  14195. PDFViewerApplication.moveCaret(true, true);
  14196. handled = true;
  14197. break;
  14198. case 40:
  14199. PDFViewerApplication.moveCaret(false, true);
  14200. handled = true;
  14201. break;
  14202. case 82:
  14203. PDFViewerApplication.rotatePages(-90);
  14204. break;
  14205. }
  14206. }
  14207. if (!handled && !isViewerInPresentationMode) {
  14208. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  14209. ensureViewerFocused = true;
  14210. }
  14211. }
  14212. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  14213. pdfViewer.focus();
  14214. }
  14215. if (handled) {
  14216. evt.preventDefault();
  14217. }
  14218. }
  14219. function beforeUnload(evt) {
  14220. evt.preventDefault();
  14221. evt.returnValue = "";
  14222. return false;
  14223. }
  14224. function webViewerAnnotationEditorStatesChanged(data) {
  14225. PDFViewerApplication.externalServices.updateEditorStates(data);
  14226. }
  14227. function webViewerReportTelemetry({
  14228. details
  14229. }) {
  14230. PDFViewerApplication.externalServices.reportTelemetry(details);
  14231. }
  14232. function webViewerSetPreference({
  14233. name,
  14234. value
  14235. }) {
  14236. PDFViewerApplication.preferences.set(name, value);
  14237. }
  14238. ;// CONCATENATED MODULE: ./web/viewer.js
  14239. const pdfjsVersion = "4.5.136";
  14240. const pdfjsBuild = "3a21f03b0";
  14241. const AppConstants = {
  14242. LinkTarget: LinkTarget,
  14243. RenderingStates: RenderingStates,
  14244. ScrollMode: ScrollMode,
  14245. SpreadMode: SpreadMode
  14246. };
  14247. window.PDFViewerApplication = PDFViewerApplication;
  14248. window.PDFViewerApplicationConstants = AppConstants;
  14249. window.PDFViewerApplicationOptions = AppOptions;
  14250. function getViewerConfiguration() {
  14251. return {
  14252. appContainer: document.body,
  14253. mainContainer: document.getElementById("viewerContainer"),
  14254. viewerContainer: document.getElementById("viewer"),
  14255. toolbar: {
  14256. container: document.getElementById("toolbarViewer"),
  14257. numPages: document.getElementById("numPages"),
  14258. pageNumber: document.getElementById("pageNumber"),
  14259. scaleSelect: document.getElementById("scaleSelect"),
  14260. customScaleOption: document.getElementById("customScaleOption"),
  14261. previous: document.getElementById("previous"),
  14262. next: document.getElementById("next"),
  14263. zoomIn: document.getElementById("zoomIn"),
  14264. zoomOut: document.getElementById("zoomOut"),
  14265. viewFind: document.getElementById("viewFind"),
  14266. print: document.getElementById("print"),
  14267. editorFreeTextButton: document.getElementById("editorFreeText"),
  14268. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  14269. editorHighlightButton: document.getElementById("editorHighlight"),
  14270. editorHighlightParamsToolbar: document.getElementById("editorHighlightParamsToolbar"),
  14271. editorHighlightColorPicker: document.getElementById("editorHighlightColorPicker"),
  14272. editorInkButton: document.getElementById("editorInk"),
  14273. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  14274. editorStampButton: document.getElementById("editorStamp"),
  14275. editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"),
  14276. download: document.getElementById("download")
  14277. },
  14278. secondaryToolbar: {
  14279. toolbar: document.getElementById("secondaryToolbar"),
  14280. toggleButton: document.getElementById("secondaryToolbarToggle"),
  14281. presentationModeButton: document.getElementById("presentationMode"),
  14282. openFileButton: document.getElementById("secondaryOpenFile"),
  14283. printButton: document.getElementById("secondaryPrint"),
  14284. downloadButton: document.getElementById("secondaryDownload"),
  14285. viewBookmarkButton: document.getElementById("viewBookmark"),
  14286. firstPageButton: document.getElementById("firstPage"),
  14287. lastPageButton: document.getElementById("lastPage"),
  14288. pageRotateCwButton: document.getElementById("pageRotateCw"),
  14289. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  14290. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  14291. cursorHandToolButton: document.getElementById("cursorHandTool"),
  14292. scrollPageButton: document.getElementById("scrollPage"),
  14293. scrollVerticalButton: document.getElementById("scrollVertical"),
  14294. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  14295. scrollWrappedButton: document.getElementById("scrollWrapped"),
  14296. spreadNoneButton: document.getElementById("spreadNone"),
  14297. spreadOddButton: document.getElementById("spreadOdd"),
  14298. spreadEvenButton: document.getElementById("spreadEven"),
  14299. documentPropertiesButton: document.getElementById("documentProperties")
  14300. },
  14301. sidebar: {
  14302. outerContainer: document.getElementById("outerContainer"),
  14303. sidebarContainer: document.getElementById("sidebarContainer"),
  14304. toggleButton: document.getElementById("sidebarToggle"),
  14305. resizer: document.getElementById("sidebarResizer"),
  14306. thumbnailButton: document.getElementById("viewThumbnail"),
  14307. outlineButton: document.getElementById("viewOutline"),
  14308. attachmentsButton: document.getElementById("viewAttachments"),
  14309. layersButton: document.getElementById("viewLayers"),
  14310. thumbnailView: document.getElementById("thumbnailView"),
  14311. outlineView: document.getElementById("outlineView"),
  14312. attachmentsView: document.getElementById("attachmentsView"),
  14313. layersView: document.getElementById("layersView"),
  14314. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  14315. },
  14316. findBar: {
  14317. bar: document.getElementById("findbar"),
  14318. toggleButton: document.getElementById("viewFind"),
  14319. findField: document.getElementById("findInput"),
  14320. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  14321. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  14322. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  14323. entireWordCheckbox: document.getElementById("findEntireWord"),
  14324. findMsg: document.getElementById("findMsg"),
  14325. findResultsCount: document.getElementById("findResultsCount"),
  14326. findPreviousButton: document.getElementById("findPrevious"),
  14327. findNextButton: document.getElementById("findNext")
  14328. },
  14329. passwordOverlay: {
  14330. dialog: document.getElementById("passwordDialog"),
  14331. label: document.getElementById("passwordText"),
  14332. input: document.getElementById("password"),
  14333. submitButton: document.getElementById("passwordSubmit"),
  14334. cancelButton: document.getElementById("passwordCancel")
  14335. },
  14336. documentProperties: {
  14337. dialog: document.getElementById("documentPropertiesDialog"),
  14338. closeButton: document.getElementById("documentPropertiesClose"),
  14339. fields: {
  14340. fileName: document.getElementById("fileNameField"),
  14341. fileSize: document.getElementById("fileSizeField"),
  14342. title: document.getElementById("titleField"),
  14343. author: document.getElementById("authorField"),
  14344. subject: document.getElementById("subjectField"),
  14345. keywords: document.getElementById("keywordsField"),
  14346. creationDate: document.getElementById("creationDateField"),
  14347. modificationDate: document.getElementById("modificationDateField"),
  14348. creator: document.getElementById("creatorField"),
  14349. producer: document.getElementById("producerField"),
  14350. version: document.getElementById("versionField"),
  14351. pageCount: document.getElementById("pageCountField"),
  14352. pageSize: document.getElementById("pageSizeField"),
  14353. linearized: document.getElementById("linearizedField")
  14354. }
  14355. },
  14356. altTextDialog: {
  14357. dialog: document.getElementById("altTextDialog"),
  14358. optionDescription: document.getElementById("descriptionButton"),
  14359. optionDecorative: document.getElementById("decorativeButton"),
  14360. textarea: document.getElementById("descriptionTextarea"),
  14361. cancelButton: document.getElementById("altTextCancel"),
  14362. saveButton: document.getElementById("altTextSave")
  14363. },
  14364. annotationEditorParams: {
  14365. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  14366. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  14367. editorInkColor: document.getElementById("editorInkColor"),
  14368. editorInkThickness: document.getElementById("editorInkThickness"),
  14369. editorInkOpacity: document.getElementById("editorInkOpacity"),
  14370. editorStampAddImage: document.getElementById("editorStampAddImage"),
  14371. editorFreeHighlightThickness: document.getElementById("editorFreeHighlightThickness"),
  14372. editorHighlightShowAll: document.getElementById("editorHighlightShowAll")
  14373. },
  14374. printContainer: document.getElementById("printContainer")
  14375. };
  14376. }
  14377. function webViewerLoad() {
  14378. const config = getViewerConfiguration();
  14379. const event = new CustomEvent("webviewerloaded", {
  14380. bubbles: true,
  14381. cancelable: true,
  14382. detail: {
  14383. source: window
  14384. }
  14385. });
  14386. try {
  14387. parent.document.dispatchEvent(event);
  14388. } catch (ex) {
  14389. console.error(`webviewerloaded: ${ex}`);
  14390. document.dispatchEvent(event);
  14391. }
  14392. PDFViewerApplication.run(config);
  14393. }
  14394. document.blockUnblockOnload?.(true);
  14395. if (document.readyState === "interactive" || document.readyState === "complete") {
  14396. webViewerLoad();
  14397. } else {
  14398. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  14399. }
  14400. var __webpack_exports__PDFViewerApplication = __webpack_exports__.PDFViewerApplication;
  14401. var __webpack_exports__PDFViewerApplicationConstants = __webpack_exports__.PDFViewerApplicationConstants;
  14402. var __webpack_exports__PDFViewerApplicationOptions = __webpack_exports__.PDFViewerApplicationOptions;
  14403. export { __webpack_exports__PDFViewerApplication as PDFViewerApplication, __webpack_exports__PDFViewerApplicationConstants as PDFViewerApplicationConstants, __webpack_exports__PDFViewerApplicationOptions as PDFViewerApplicationOptions };
  14404. //# sourceMappingURL=viewer.mjs.map