cmaps
3 years ago
images
3 years ago
locale
3 years ago
ep-scripts.js
2 years ago
viewer.css
2 years ago
viewer.html
2 years ago
viewer.js
2 years ago
viewer.js
13972 lines
| 1 | /** |
| 2 | * @licstart The following is the entire license notice for the |
| 3 | * JavaScript code in this page |
| 4 | * |
| 5 | * Copyright 2023 Mozilla Foundation |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * @licend The above is the entire license notice for the |
| 20 | * JavaScript code in this page |
| 21 | */ |
| 22 | |
| 23 | /******/ (() => { // webpackBootstrap |
| 24 | /******/ "use strict"; |
| 25 | /******/ var __webpack_modules__ = ([ |
| 26 | /* 0 */, |
| 27 | /* 1 */ |
| 28 | /***/ ((__unused_webpack_module, exports) => { |
| 29 | |
| 30 | |
| 31 | |
| 32 | Object.defineProperty(exports, "__esModule", ({ |
| 33 | value: true |
| 34 | })); |
| 35 | exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0; |
| 36 | exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes; |
| 37 | exports.apiPageModeToSidebarView = apiPageModeToSidebarView; |
| 38 | exports.approximateFraction = approximateFraction; |
| 39 | exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements; |
| 40 | exports.binarySearchFirstItem = binarySearchFirstItem; |
| 41 | exports.docStyle = void 0; |
| 42 | exports.getActiveOrFocusedElement = getActiveOrFocusedElement; |
| 43 | exports.getPageSizeInches = getPageSizeInches; |
| 44 | exports.getVisibleElements = getVisibleElements; |
| 45 | exports.isPortraitOrientation = isPortraitOrientation; |
| 46 | exports.isValidRotation = isValidRotation; |
| 47 | exports.isValidScrollMode = isValidScrollMode; |
| 48 | exports.isValidSpreadMode = isValidSpreadMode; |
| 49 | exports.noContextMenuHandler = noContextMenuHandler; |
| 50 | exports.normalizeWheelEventDelta = normalizeWheelEventDelta; |
| 51 | exports.normalizeWheelEventDirection = normalizeWheelEventDirection; |
| 52 | exports.parseQueryString = parseQueryString; |
| 53 | exports.removeNullCharacters = removeNullCharacters; |
| 54 | exports.roundToDivide = roundToDivide; |
| 55 | exports.scrollIntoView = scrollIntoView; |
| 56 | exports.watchScroll = watchScroll; |
| 57 | const DEFAULT_SCALE_VALUE = "auto"; |
| 58 | exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE; |
| 59 | const DEFAULT_SCALE = 1.0; |
| 60 | exports.DEFAULT_SCALE = DEFAULT_SCALE; |
| 61 | const DEFAULT_SCALE_DELTA = 1.1; |
| 62 | exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA; |
| 63 | const MIN_SCALE = 0.1; |
| 64 | exports.MIN_SCALE = MIN_SCALE; |
| 65 | const MAX_SCALE = 10.0; |
| 66 | exports.MAX_SCALE = MAX_SCALE; |
| 67 | const UNKNOWN_SCALE = 0; |
| 68 | exports.UNKNOWN_SCALE = UNKNOWN_SCALE; |
| 69 | const MAX_AUTO_SCALE = 1.25; |
| 70 | exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE; |
| 71 | const SCROLLBAR_PADDING = 40; |
| 72 | exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING; |
| 73 | const VERTICAL_PADDING = 5; |
| 74 | exports.VERTICAL_PADDING = VERTICAL_PADDING; |
| 75 | const RenderingStates = { |
| 76 | INITIAL: 0, |
| 77 | RUNNING: 1, |
| 78 | PAUSED: 2, |
| 79 | FINISHED: 3 |
| 80 | }; |
| 81 | exports.RenderingStates = RenderingStates; |
| 82 | const PresentationModeState = { |
| 83 | UNKNOWN: 0, |
| 84 | NORMAL: 1, |
| 85 | CHANGING: 2, |
| 86 | FULLSCREEN: 3 |
| 87 | }; |
| 88 | exports.PresentationModeState = PresentationModeState; |
| 89 | const SidebarView = { |
| 90 | UNKNOWN: -1, |
| 91 | NONE: 0, |
| 92 | THUMBS: 1, |
| 93 | OUTLINE: 2, |
| 94 | ATTACHMENTS: 3, |
| 95 | LAYERS: 4 |
| 96 | }; |
| 97 | exports.SidebarView = SidebarView; |
| 98 | const RendererType = { |
| 99 | CANVAS: "canvas", |
| 100 | SVG: "svg" |
| 101 | }; |
| 102 | exports.RendererType = RendererType; |
| 103 | const TextLayerMode = { |
| 104 | DISABLE: 0, |
| 105 | ENABLE: 1 |
| 106 | }; |
| 107 | exports.TextLayerMode = TextLayerMode; |
| 108 | const ScrollMode = { |
| 109 | UNKNOWN: -1, |
| 110 | VERTICAL: 0, |
| 111 | HORIZONTAL: 1, |
| 112 | WRAPPED: 2, |
| 113 | PAGE: 3 |
| 114 | }; |
| 115 | exports.ScrollMode = ScrollMode; |
| 116 | const SpreadMode = { |
| 117 | UNKNOWN: -1, |
| 118 | NONE: 0, |
| 119 | ODD: 1, |
| 120 | EVEN: 2 |
| 121 | }; |
| 122 | exports.SpreadMode = SpreadMode; |
| 123 | const AutoPrintRegExp = /\bprint\s*\(/; |
| 124 | exports.AutoPrintRegExp = AutoPrintRegExp; |
| 125 | class OutputScale { |
| 126 | constructor() { |
| 127 | const pixelRatio = window.devicePixelRatio || 1; |
| 128 | this.sx = pixelRatio; |
| 129 | this.sy = pixelRatio; |
| 130 | } |
| 131 | get scaled() { |
| 132 | return this.sx !== 1 || this.sy !== 1; |
| 133 | } |
| 134 | } |
| 135 | exports.OutputScale = OutputScale; |
| 136 | function scrollIntoView(element, spot, scrollMatches = false) { |
| 137 | let parent = element.offsetParent; |
| 138 | if (!parent) { |
| 139 | console.error("offsetParent is not set -- cannot scroll"); |
| 140 | return; |
| 141 | } |
| 142 | let offsetY = element.offsetTop + element.clientTop; |
| 143 | let offsetX = element.offsetLeft + element.clientLeft; |
| 144 | while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) { |
| 145 | offsetY += parent.offsetTop; |
| 146 | offsetX += parent.offsetLeft; |
| 147 | parent = parent.offsetParent; |
| 148 | if (!parent) { |
| 149 | return; |
| 150 | } |
| 151 | } |
| 152 | if (spot) { |
| 153 | if (spot.top !== undefined) { |
| 154 | offsetY += spot.top; |
| 155 | } |
| 156 | if (spot.left !== undefined) { |
| 157 | offsetX += spot.left; |
| 158 | parent.scrollLeft = offsetX; |
| 159 | } |
| 160 | } |
| 161 | parent.scrollTop = offsetY; |
| 162 | } |
| 163 | function watchScroll(viewAreaElement, callback) { |
| 164 | const debounceScroll = function (evt) { |
| 165 | if (rAF) { |
| 166 | return; |
| 167 | } |
| 168 | rAF = window.requestAnimationFrame(function viewAreaElementScrolled() { |
| 169 | rAF = null; |
| 170 | const currentX = viewAreaElement.scrollLeft; |
| 171 | const lastX = state.lastX; |
| 172 | if (currentX !== lastX) { |
| 173 | state.right = currentX > lastX; |
| 174 | } |
| 175 | state.lastX = currentX; |
| 176 | const currentY = viewAreaElement.scrollTop; |
| 177 | const lastY = state.lastY; |
| 178 | if (currentY !== lastY) { |
| 179 | state.down = currentY > lastY; |
| 180 | } |
| 181 | state.lastY = currentY; |
| 182 | callback(state); |
| 183 | }); |
| 184 | }; |
| 185 | const state = { |
| 186 | right: true, |
| 187 | down: true, |
| 188 | lastX: viewAreaElement.scrollLeft, |
| 189 | lastY: viewAreaElement.scrollTop, |
| 190 | _eventHandler: debounceScroll |
| 191 | }; |
| 192 | let rAF = null; |
| 193 | viewAreaElement.addEventListener("scroll", debounceScroll, true); |
| 194 | return state; |
| 195 | } |
| 196 | function parseQueryString(query) { |
| 197 | const params = new Map(); |
| 198 | for (const [key, value] of new URLSearchParams(query)) { |
| 199 | params.set(key.toLowerCase(), value); |
| 200 | } |
| 201 | return params; |
| 202 | } |
| 203 | const NullCharactersRegExp = /\x00/g; |
| 204 | const InvisibleCharactersRegExp = /[\x01-\x1F]/g; |
| 205 | function removeNullCharacters(str, replaceInvisible = false) { |
| 206 | if (typeof str !== "string") { |
| 207 | console.error(`The argument must be a string.`); |
| 208 | return str; |
| 209 | } |
| 210 | if (replaceInvisible) { |
| 211 | str = str.replace(InvisibleCharactersRegExp, " "); |
| 212 | } |
| 213 | return str.replace(NullCharactersRegExp, ""); |
| 214 | } |
| 215 | function binarySearchFirstItem(items, condition, start = 0) { |
| 216 | let minIndex = start; |
| 217 | let maxIndex = items.length - 1; |
| 218 | if (maxIndex < 0 || !condition(items[maxIndex])) { |
| 219 | return items.length; |
| 220 | } |
| 221 | if (condition(items[minIndex])) { |
| 222 | return minIndex; |
| 223 | } |
| 224 | while (minIndex < maxIndex) { |
| 225 | const currentIndex = minIndex + maxIndex >> 1; |
| 226 | const currentItem = items[currentIndex]; |
| 227 | if (condition(currentItem)) { |
| 228 | maxIndex = currentIndex; |
| 229 | } else { |
| 230 | minIndex = currentIndex + 1; |
| 231 | } |
| 232 | } |
| 233 | return minIndex; |
| 234 | } |
| 235 | function approximateFraction(x) { |
| 236 | if (Math.floor(x) === x) { |
| 237 | return [x, 1]; |
| 238 | } |
| 239 | const xinv = 1 / x; |
| 240 | const limit = 8; |
| 241 | if (xinv > limit) { |
| 242 | return [1, limit]; |
| 243 | } else if (Math.floor(xinv) === xinv) { |
| 244 | return [1, xinv]; |
| 245 | } |
| 246 | const x_ = x > 1 ? xinv : x; |
| 247 | let a = 0, |
| 248 | b = 1, |
| 249 | c = 1, |
| 250 | d = 1; |
| 251 | while (true) { |
| 252 | const p = a + c, |
| 253 | q = b + d; |
| 254 | if (q > limit) { |
| 255 | break; |
| 256 | } |
| 257 | if (x_ <= p / q) { |
| 258 | c = p; |
| 259 | d = q; |
| 260 | } else { |
| 261 | a = p; |
| 262 | b = q; |
| 263 | } |
| 264 | } |
| 265 | let result; |
| 266 | if (x_ - a / b < c / d - x_) { |
| 267 | result = x_ === x ? [a, b] : [b, a]; |
| 268 | } else { |
| 269 | result = x_ === x ? [c, d] : [d, c]; |
| 270 | } |
| 271 | return result; |
| 272 | } |
| 273 | function roundToDivide(x, div) { |
| 274 | const r = x % div; |
| 275 | return r === 0 ? x : Math.round(x - r + div); |
| 276 | } |
| 277 | function getPageSizeInches({ |
| 278 | view, |
| 279 | userUnit, |
| 280 | rotate |
| 281 | }) { |
| 282 | const [x1, y1, x2, y2] = view; |
| 283 | const changeOrientation = rotate % 180 !== 0; |
| 284 | const width = (x2 - x1) / 72 * userUnit; |
| 285 | const height = (y2 - y1) / 72 * userUnit; |
| 286 | return { |
| 287 | width: changeOrientation ? height : width, |
| 288 | height: changeOrientation ? width : height |
| 289 | }; |
| 290 | } |
| 291 | function backtrackBeforeAllVisibleElements(index, views, top) { |
| 292 | if (index < 2) { |
| 293 | return index; |
| 294 | } |
| 295 | let elt = views[index].div; |
| 296 | let pageTop = elt.offsetTop + elt.clientTop; |
| 297 | if (pageTop >= top) { |
| 298 | elt = views[index - 1].div; |
| 299 | pageTop = elt.offsetTop + elt.clientTop; |
| 300 | } |
| 301 | for (let i = index - 2; i >= 0; --i) { |
| 302 | elt = views[i].div; |
| 303 | if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) { |
| 304 | break; |
| 305 | } |
| 306 | index = i; |
| 307 | } |
| 308 | return index; |
| 309 | } |
| 310 | function getVisibleElements({ |
| 311 | scrollEl, |
| 312 | views, |
| 313 | sortByVisibility = false, |
| 314 | horizontal = false, |
| 315 | rtl = false |
| 316 | }) { |
| 317 | const top = scrollEl.scrollTop, |
| 318 | bottom = top + scrollEl.clientHeight; |
| 319 | const left = scrollEl.scrollLeft, |
| 320 | right = left + scrollEl.clientWidth; |
| 321 | function isElementBottomAfterViewTop(view) { |
| 322 | const element = view.div; |
| 323 | const elementBottom = element.offsetTop + element.clientTop + element.clientHeight; |
| 324 | return elementBottom > top; |
| 325 | } |
| 326 | function isElementNextAfterViewHorizontally(view) { |
| 327 | const element = view.div; |
| 328 | const elementLeft = element.offsetLeft + element.clientLeft; |
| 329 | const elementRight = elementLeft + element.clientWidth; |
| 330 | return rtl ? elementLeft < right : elementRight > left; |
| 331 | } |
| 332 | const visible = [], |
| 333 | ids = new Set(), |
| 334 | numViews = views.length; |
| 335 | let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop); |
| 336 | if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) { |
| 337 | firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top); |
| 338 | } |
| 339 | let lastEdge = horizontal ? right : -1; |
| 340 | for (let i = firstVisibleElementInd; i < numViews; i++) { |
| 341 | const view = views[i], |
| 342 | element = view.div; |
| 343 | const currentWidth = element.offsetLeft + element.clientLeft; |
| 344 | const currentHeight = element.offsetTop + element.clientTop; |
| 345 | const viewWidth = element.clientWidth, |
| 346 | viewHeight = element.clientHeight; |
| 347 | const viewRight = currentWidth + viewWidth; |
| 348 | const viewBottom = currentHeight + viewHeight; |
| 349 | if (lastEdge === -1) { |
| 350 | if (viewBottom >= bottom) { |
| 351 | lastEdge = viewBottom; |
| 352 | } |
| 353 | } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) { |
| 354 | break; |
| 355 | } |
| 356 | if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) { |
| 357 | continue; |
| 358 | } |
| 359 | const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom); |
| 360 | const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right); |
| 361 | const fractionHeight = (viewHeight - hiddenHeight) / viewHeight, |
| 362 | fractionWidth = (viewWidth - hiddenWidth) / viewWidth; |
| 363 | const percent = fractionHeight * fractionWidth * 100 | 0; |
| 364 | visible.push({ |
| 365 | id: view.id, |
| 366 | x: currentWidth, |
| 367 | y: currentHeight, |
| 368 | view, |
| 369 | percent, |
| 370 | widthPercent: fractionWidth * 100 | 0 |
| 371 | }); |
| 372 | ids.add(view.id); |
| 373 | } |
| 374 | const first = visible[0], |
| 375 | last = visible.at(-1); |
| 376 | if (sortByVisibility) { |
| 377 | visible.sort(function (a, b) { |
| 378 | const pc = a.percent - b.percent; |
| 379 | if (Math.abs(pc) > 0.001) { |
| 380 | return -pc; |
| 381 | } |
| 382 | return a.id - b.id; |
| 383 | }); |
| 384 | } |
| 385 | return { |
| 386 | first, |
| 387 | last, |
| 388 | views: visible, |
| 389 | ids |
| 390 | }; |
| 391 | } |
| 392 | function noContextMenuHandler(evt) { |
| 393 | evt.preventDefault(); |
| 394 | } |
| 395 | function normalizeWheelEventDirection(evt) { |
| 396 | let delta = Math.hypot(evt.deltaX, evt.deltaY); |
| 397 | const angle = Math.atan2(evt.deltaY, evt.deltaX); |
| 398 | if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) { |
| 399 | delta = -delta; |
| 400 | } |
| 401 | return delta; |
| 402 | } |
| 403 | function normalizeWheelEventDelta(evt) { |
| 404 | const deltaMode = evt.deltaMode; |
| 405 | let delta = normalizeWheelEventDirection(evt); |
| 406 | const MOUSE_PIXELS_PER_LINE = 30; |
| 407 | const MOUSE_LINES_PER_PAGE = 30; |
| 408 | if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) { |
| 409 | delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE; |
| 410 | } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) { |
| 411 | delta /= MOUSE_LINES_PER_PAGE; |
| 412 | } |
| 413 | return delta; |
| 414 | } |
| 415 | function isValidRotation(angle) { |
| 416 | return Number.isInteger(angle) && angle % 90 === 0; |
| 417 | } |
| 418 | function isValidScrollMode(mode) { |
| 419 | return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN; |
| 420 | } |
| 421 | function isValidSpreadMode(mode) { |
| 422 | return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN; |
| 423 | } |
| 424 | function isPortraitOrientation(size) { |
| 425 | return size.width <= size.height; |
| 426 | } |
| 427 | const animationStarted = new Promise(function (resolve) { |
| 428 | window.requestAnimationFrame(resolve); |
| 429 | }); |
| 430 | exports.animationStarted = animationStarted; |
| 431 | const docStyle = document.documentElement.style; |
| 432 | exports.docStyle = docStyle; |
| 433 | function clamp(v, min, max) { |
| 434 | return Math.min(Math.max(v, min), max); |
| 435 | } |
| 436 | class ProgressBar { |
| 437 | #classList = null; |
| 438 | #disableAutoFetchTimeout = null; |
| 439 | #percent = 0; |
| 440 | #style = null; |
| 441 | #visible = true; |
| 442 | constructor(bar) { |
| 443 | this.#classList = bar.classList; |
| 444 | this.#style = bar.style; |
| 445 | } |
| 446 | get percent() { |
| 447 | return this.#percent; |
| 448 | } |
| 449 | set percent(val) { |
| 450 | this.#percent = clamp(val, 0, 100); |
| 451 | if (isNaN(val)) { |
| 452 | this.#classList.add("indeterminate"); |
| 453 | return; |
| 454 | } |
| 455 | this.#classList.remove("indeterminate"); |
| 456 | this.#style.setProperty("--progressBar-percent", `${this.#percent}%`); |
| 457 | } |
| 458 | setWidth(viewer) { |
| 459 | if (!viewer) { |
| 460 | return; |
| 461 | } |
| 462 | const container = viewer.parentNode; |
| 463 | const scrollbarWidth = container.offsetWidth - viewer.offsetWidth; |
| 464 | if (scrollbarWidth > 0) { |
| 465 | this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`); |
| 466 | } |
| 467 | } |
| 468 | setDisableAutoFetch(delay = 5000) { |
| 469 | if (isNaN(this.#percent)) { |
| 470 | return; |
| 471 | } |
| 472 | if (this.#disableAutoFetchTimeout) { |
| 473 | clearTimeout(this.#disableAutoFetchTimeout); |
| 474 | } |
| 475 | this.show(); |
| 476 | this.#disableAutoFetchTimeout = setTimeout(() => { |
| 477 | this.#disableAutoFetchTimeout = null; |
| 478 | this.hide(); |
| 479 | }, delay); |
| 480 | } |
| 481 | hide() { |
| 482 | if (!this.#visible) { |
| 483 | return; |
| 484 | } |
| 485 | this.#visible = false; |
| 486 | this.#classList.add("hidden"); |
| 487 | } |
| 488 | show() { |
| 489 | if (this.#visible) { |
| 490 | return; |
| 491 | } |
| 492 | this.#visible = true; |
| 493 | this.#classList.remove("hidden"); |
| 494 | } |
| 495 | } |
| 496 | exports.ProgressBar = ProgressBar; |
| 497 | function getActiveOrFocusedElement() { |
| 498 | let curRoot = document; |
| 499 | let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus"); |
| 500 | while (curActiveOrFocused?.shadowRoot) { |
| 501 | curRoot = curActiveOrFocused.shadowRoot; |
| 502 | curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus"); |
| 503 | } |
| 504 | return curActiveOrFocused; |
| 505 | } |
| 506 | function apiPageLayoutToViewerModes(layout) { |
| 507 | let scrollMode = ScrollMode.VERTICAL, |
| 508 | spreadMode = SpreadMode.NONE; |
| 509 | switch (layout) { |
| 510 | case "SinglePage": |
| 511 | scrollMode = ScrollMode.PAGE; |
| 512 | break; |
| 513 | case "OneColumn": |
| 514 | break; |
| 515 | case "TwoPageLeft": |
| 516 | scrollMode = ScrollMode.PAGE; |
| 517 | case "TwoColumnLeft": |
| 518 | spreadMode = SpreadMode.ODD; |
| 519 | break; |
| 520 | case "TwoPageRight": |
| 521 | scrollMode = ScrollMode.PAGE; |
| 522 | case "TwoColumnRight": |
| 523 | spreadMode = SpreadMode.EVEN; |
| 524 | break; |
| 525 | } |
| 526 | return { |
| 527 | scrollMode, |
| 528 | spreadMode |
| 529 | }; |
| 530 | } |
| 531 | function apiPageModeToSidebarView(mode) { |
| 532 | switch (mode) { |
| 533 | case "UseNone": |
| 534 | return SidebarView.NONE; |
| 535 | case "UseThumbs": |
| 536 | return SidebarView.THUMBS; |
| 537 | case "UseOutlines": |
| 538 | return SidebarView.OUTLINE; |
| 539 | case "UseAttachments": |
| 540 | return SidebarView.ATTACHMENTS; |
| 541 | case "UseOC": |
| 542 | return SidebarView.LAYERS; |
| 543 | } |
| 544 | return SidebarView.NONE; |
| 545 | } |
| 546 | |
| 547 | /***/ }), |
| 548 | /* 2 */ |
| 549 | /***/ ((__unused_webpack_module, exports) => { |
| 550 | |
| 551 | |
| 552 | |
| 553 | Object.defineProperty(exports, "__esModule", ({ |
| 554 | value: true |
| 555 | })); |
| 556 | exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0; |
| 557 | const compatibilityParams = Object.create(null); |
| 558 | exports.compatibilityParams = compatibilityParams; |
| 559 | { |
| 560 | const userAgent = navigator.userAgent || ""; |
| 561 | const platform = navigator.platform || ""; |
| 562 | const maxTouchPoints = navigator.maxTouchPoints || 1; |
| 563 | const isAndroid = /Android/.test(userAgent); |
| 564 | const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1; |
| 565 | (function checkCanvasSizeLimitation() { |
| 566 | if (isIOS || isAndroid) { |
| 567 | compatibilityParams.maxCanvasPixels = 5242880; |
| 568 | } |
| 569 | })(); |
| 570 | } |
| 571 | const OptionKind = { |
| 572 | VIEWER: 0x02, |
| 573 | API: 0x04, |
| 574 | WORKER: 0x08, |
| 575 | PREFERENCE: 0x80 |
| 576 | }; |
| 577 | exports.OptionKind = OptionKind; |
| 578 | const defaultOptions = { |
| 579 | annotationEditorMode: { |
| 580 | value: 0, |
| 581 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 582 | }, |
| 583 | annotationMode: { |
| 584 | value: 2, |
| 585 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 586 | }, |
| 587 | cursorToolOnLoad: { |
| 588 | value: 0, |
| 589 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 590 | }, |
| 591 | defaultZoomDelay: { |
| 592 | value: 400, |
| 593 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 594 | }, |
| 595 | defaultZoomValue: { |
| 596 | value: "", |
| 597 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 598 | }, |
| 599 | disableHistory: { |
| 600 | value: false, |
| 601 | kind: OptionKind.VIEWER |
| 602 | }, |
| 603 | disablePageLabels: { |
| 604 | value: false, |
| 605 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 606 | }, |
| 607 | enablePermissions: { |
| 608 | value: false, |
| 609 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 610 | }, |
| 611 | enablePrintAutoRotate: { |
| 612 | value: true, |
| 613 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 614 | }, |
| 615 | enableScripting: { |
| 616 | value: true, |
| 617 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 618 | }, |
| 619 | externalLinkRel: { |
| 620 | value: "noopener noreferrer nofollow", |
| 621 | kind: OptionKind.VIEWER |
| 622 | }, |
| 623 | externalLinkTarget: { |
| 624 | value: 0, |
| 625 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 626 | }, |
| 627 | historyUpdateUrl: { |
| 628 | value: false, |
| 629 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 630 | }, |
| 631 | ignoreDestinationZoom: { |
| 632 | value: false, |
| 633 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 634 | }, |
| 635 | imageResourcesPath: { |
| 636 | value: "./images/", |
| 637 | kind: OptionKind.VIEWER |
| 638 | }, |
| 639 | maxCanvasPixels: { |
| 640 | value: 16777216, |
| 641 | kind: OptionKind.VIEWER |
| 642 | }, |
| 643 | forcePageColors: { |
| 644 | value: false, |
| 645 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 646 | }, |
| 647 | pageColorsBackground: { |
| 648 | value: "Canvas", |
| 649 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 650 | }, |
| 651 | pageColorsForeground: { |
| 652 | value: "CanvasText", |
| 653 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 654 | }, |
| 655 | pdfBugEnabled: { |
| 656 | value: false, |
| 657 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 658 | }, |
| 659 | printResolution: { |
| 660 | value: 150, |
| 661 | kind: OptionKind.VIEWER |
| 662 | }, |
| 663 | sidebarViewOnLoad: { |
| 664 | value: -1, |
| 665 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 666 | }, |
| 667 | scrollModeOnLoad: { |
| 668 | value: -1, |
| 669 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 670 | }, |
| 671 | spreadModeOnLoad: { |
| 672 | value: -1, |
| 673 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 674 | }, |
| 675 | textLayerMode: { |
| 676 | value: 1, |
| 677 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 678 | }, |
| 679 | useOnlyCssZoom: { |
| 680 | value: false, |
| 681 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 682 | }, |
| 683 | viewerCssTheme: { |
| 684 | value: 0, |
| 685 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 686 | }, |
| 687 | viewOnLoad: { |
| 688 | value: 0, |
| 689 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 690 | }, |
| 691 | cMapPacked: { |
| 692 | value: true, |
| 693 | kind: OptionKind.API |
| 694 | }, |
| 695 | cMapUrl: { |
| 696 | value: "../web/cmaps/", |
| 697 | kind: OptionKind.API |
| 698 | }, |
| 699 | disableAutoFetch: { |
| 700 | value: false, |
| 701 | kind: OptionKind.API + OptionKind.PREFERENCE |
| 702 | }, |
| 703 | disableFontFace: { |
| 704 | value: false, |
| 705 | kind: OptionKind.API + OptionKind.PREFERENCE |
| 706 | }, |
| 707 | disableRange: { |
| 708 | value: false, |
| 709 | kind: OptionKind.API + OptionKind.PREFERENCE |
| 710 | }, |
| 711 | disableStream: { |
| 712 | value: false, |
| 713 | kind: OptionKind.API + OptionKind.PREFERENCE |
| 714 | }, |
| 715 | docBaseUrl: { |
| 716 | value: "", |
| 717 | kind: OptionKind.API |
| 718 | }, |
| 719 | enableXfa: { |
| 720 | value: true, |
| 721 | kind: OptionKind.API + OptionKind.PREFERENCE |
| 722 | }, |
| 723 | fontExtraProperties: { |
| 724 | value: false, |
| 725 | kind: OptionKind.API |
| 726 | }, |
| 727 | isEvalSupported: { |
| 728 | value: true, |
| 729 | kind: OptionKind.API |
| 730 | }, |
| 731 | isOffscreenCanvasSupported: { |
| 732 | value: true, |
| 733 | kind: OptionKind.API |
| 734 | }, |
| 735 | maxImageSize: { |
| 736 | value: -1, |
| 737 | kind: OptionKind.API |
| 738 | }, |
| 739 | pdfBug: { |
| 740 | value: false, |
| 741 | kind: OptionKind.API |
| 742 | }, |
| 743 | standardFontDataUrl: { |
| 744 | value: "../web/standard_fonts/", |
| 745 | kind: OptionKind.API |
| 746 | }, |
| 747 | verbosity: { |
| 748 | value: 1, |
| 749 | kind: OptionKind.API |
| 750 | }, |
| 751 | workerPort: { |
| 752 | value: null, |
| 753 | kind: OptionKind.WORKER |
| 754 | }, |
| 755 | workerSrc: { |
| 756 | value: "../build/pdf.worker.js", |
| 757 | kind: OptionKind.WORKER |
| 758 | } |
| 759 | }; |
| 760 | { |
| 761 | defaultOptions.defaultUrl = { |
| 762 | value: "compressed.tracemonkey-pldi-09.pdf", |
| 763 | kind: OptionKind.VIEWER |
| 764 | }; |
| 765 | defaultOptions.disablePreferences = { |
| 766 | value: false, |
| 767 | kind: OptionKind.VIEWER |
| 768 | }; |
| 769 | defaultOptions.locale = { |
| 770 | value: navigator.language || "en-US", |
| 771 | kind: OptionKind.VIEWER |
| 772 | }; |
| 773 | defaultOptions.renderer = { |
| 774 | value: "canvas", |
| 775 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 776 | }; |
| 777 | defaultOptions.sandboxBundleSrc = { |
| 778 | value: "../build/pdf.sandbox.js", |
| 779 | kind: OptionKind.VIEWER |
| 780 | }; |
| 781 | } |
| 782 | const userOptions = Object.create(null); |
| 783 | class AppOptions { |
| 784 | constructor() { |
| 785 | throw new Error("Cannot initialize AppOptions."); |
| 786 | } |
| 787 | static get(name) { |
| 788 | const userOption = userOptions[name]; |
| 789 | if (userOption !== undefined) { |
| 790 | return userOption; |
| 791 | } |
| 792 | const defaultOption = defaultOptions[name]; |
| 793 | if (defaultOption !== undefined) { |
| 794 | return compatibilityParams[name] ?? defaultOption.value; |
| 795 | } |
| 796 | return undefined; |
| 797 | } |
| 798 | static getAll(kind = null) { |
| 799 | const options = Object.create(null); |
| 800 | for (const name in defaultOptions) { |
| 801 | const defaultOption = defaultOptions[name]; |
| 802 | if (kind) { |
| 803 | if ((kind & defaultOption.kind) === 0) { |
| 804 | continue; |
| 805 | } |
| 806 | if (kind === OptionKind.PREFERENCE) { |
| 807 | const value = defaultOption.value, |
| 808 | valueType = typeof value; |
| 809 | if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) { |
| 810 | options[name] = value; |
| 811 | continue; |
| 812 | } |
| 813 | throw new Error(`Invalid type for preference: ${name}`); |
| 814 | } |
| 815 | } |
| 816 | const userOption = userOptions[name]; |
| 817 | options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value; |
| 818 | } |
| 819 | return options; |
| 820 | } |
| 821 | static set(name, value) { |
| 822 | userOptions[name] = value; |
| 823 | } |
| 824 | static setAll(options) { |
| 825 | for (const name in options) { |
| 826 | userOptions[name] = options[name]; |
| 827 | } |
| 828 | } |
| 829 | static remove(name) { |
| 830 | delete userOptions[name]; |
| 831 | } |
| 832 | static _hasUserOptions() { |
| 833 | return Object.keys(userOptions).length > 0; |
| 834 | } |
| 835 | } |
| 836 | exports.AppOptions = AppOptions; |
| 837 | |
| 838 | /***/ }), |
| 839 | /* 3 */ |
| 840 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 841 | |
| 842 | |
| 843 | |
| 844 | Object.defineProperty(exports, "__esModule", ({ |
| 845 | value: true |
| 846 | })); |
| 847 | exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0; |
| 848 | var _ui_utils = __webpack_require__(1); |
| 849 | const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; |
| 850 | const LinkTarget = { |
| 851 | NONE: 0, |
| 852 | SELF: 1, |
| 853 | BLANK: 2, |
| 854 | PARENT: 3, |
| 855 | TOP: 4 |
| 856 | }; |
| 857 | exports.LinkTarget = LinkTarget; |
| 858 | function addLinkAttributes(link, { |
| 859 | url, |
| 860 | target, |
| 861 | rel, |
| 862 | enabled = true |
| 863 | } = {}) { |
| 864 | if (!url || typeof url !== "string") { |
| 865 | throw new Error('A valid "url" parameter must provided.'); |
| 866 | } |
| 867 | const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url); |
| 868 | if (enabled) { |
| 869 | link.href = link.title = urlNullRemoved; |
| 870 | } else { |
| 871 | link.href = ""; |
| 872 | link.title = `Disabled: ${urlNullRemoved}`; |
| 873 | link.onclick = () => { |
| 874 | return false; |
| 875 | }; |
| 876 | } |
| 877 | let targetStr = ""; |
| 878 | switch (target) { |
| 879 | case LinkTarget.NONE: |
| 880 | break; |
| 881 | case LinkTarget.SELF: |
| 882 | targetStr = "_self"; |
| 883 | break; |
| 884 | case LinkTarget.BLANK: |
| 885 | targetStr = "_blank"; |
| 886 | break; |
| 887 | case LinkTarget.PARENT: |
| 888 | targetStr = "_parent"; |
| 889 | break; |
| 890 | case LinkTarget.TOP: |
| 891 | targetStr = "_top"; |
| 892 | break; |
| 893 | } |
| 894 | link.target = targetStr; |
| 895 | link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; |
| 896 | } |
| 897 | class PDFLinkService { |
| 898 | #pagesRefCache = new Map(); |
| 899 | constructor({ |
| 900 | eventBus, |
| 901 | externalLinkTarget = null, |
| 902 | externalLinkRel = null, |
| 903 | ignoreDestinationZoom = false |
| 904 | } = {}) { |
| 905 | this.eventBus = eventBus; |
| 906 | this.externalLinkTarget = externalLinkTarget; |
| 907 | this.externalLinkRel = externalLinkRel; |
| 908 | this.externalLinkEnabled = true; |
| 909 | this._ignoreDestinationZoom = ignoreDestinationZoom; |
| 910 | this.baseUrl = null; |
| 911 | this.pdfDocument = null; |
| 912 | this.pdfViewer = null; |
| 913 | this.pdfHistory = null; |
| 914 | } |
| 915 | setDocument(pdfDocument, baseUrl = null) { |
| 916 | this.baseUrl = baseUrl; |
| 917 | this.pdfDocument = pdfDocument; |
| 918 | this.#pagesRefCache.clear(); |
| 919 | } |
| 920 | setViewer(pdfViewer) { |
| 921 | this.pdfViewer = pdfViewer; |
| 922 | } |
| 923 | setHistory(pdfHistory) { |
| 924 | this.pdfHistory = pdfHistory; |
| 925 | } |
| 926 | get pagesCount() { |
| 927 | return this.pdfDocument ? this.pdfDocument.numPages : 0; |
| 928 | } |
| 929 | get page() { |
| 930 | return this.pdfViewer.currentPageNumber; |
| 931 | } |
| 932 | set page(value) { |
| 933 | this.pdfViewer.currentPageNumber = value; |
| 934 | } |
| 935 | get rotation() { |
| 936 | return this.pdfViewer.pagesRotation; |
| 937 | } |
| 938 | set rotation(value) { |
| 939 | this.pdfViewer.pagesRotation = value; |
| 940 | } |
| 941 | get isInPresentationMode() { |
| 942 | return this.pdfViewer.isInPresentationMode; |
| 943 | } |
| 944 | #goToDestinationHelper(rawDest, namedDest = null, explicitDest) { |
| 945 | const destRef = explicitDest[0]; |
| 946 | let pageNumber; |
| 947 | if (typeof destRef === "object" && destRef !== null) { |
| 948 | pageNumber = this._cachedPageNumber(destRef); |
| 949 | if (!pageNumber) { |
| 950 | this.pdfDocument.getPageIndex(destRef).then(pageIndex => { |
| 951 | this.cachePageRef(pageIndex + 1, destRef); |
| 952 | this.#goToDestinationHelper(rawDest, namedDest, explicitDest); |
| 953 | }).catch(() => { |
| 954 | console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`); |
| 955 | }); |
| 956 | return; |
| 957 | } |
| 958 | } else if (Number.isInteger(destRef)) { |
| 959 | pageNumber = destRef + 1; |
| 960 | } else { |
| 961 | console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`); |
| 962 | return; |
| 963 | } |
| 964 | if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { |
| 965 | console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`); |
| 966 | return; |
| 967 | } |
| 968 | if (this.pdfHistory) { |
| 969 | this.pdfHistory.pushCurrentPosition(); |
| 970 | this.pdfHistory.push({ |
| 971 | namedDest, |
| 972 | explicitDest, |
| 973 | pageNumber |
| 974 | }); |
| 975 | } |
| 976 | this.pdfViewer.scrollPageIntoView({ |
| 977 | pageNumber, |
| 978 | destArray: explicitDest, |
| 979 | ignoreDestinationZoom: this._ignoreDestinationZoom |
| 980 | }); |
| 981 | } |
| 982 | async goToDestination(dest) { |
| 983 | if (!this.pdfDocument) { |
| 984 | return; |
| 985 | } |
| 986 | let namedDest, explicitDest; |
| 987 | if (typeof dest === "string") { |
| 988 | namedDest = dest; |
| 989 | explicitDest = await this.pdfDocument.getDestination(dest); |
| 990 | } else { |
| 991 | namedDest = null; |
| 992 | explicitDest = await dest; |
| 993 | } |
| 994 | if (!Array.isArray(explicitDest)) { |
| 995 | console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`); |
| 996 | return; |
| 997 | } |
| 998 | this.#goToDestinationHelper(dest, namedDest, explicitDest); |
| 999 | } |
| 1000 | goToPage(val) { |
| 1001 | if (!this.pdfDocument) { |
| 1002 | return; |
| 1003 | } |
| 1004 | const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0; |
| 1005 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) { |
| 1006 | console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`); |
| 1007 | return; |
| 1008 | } |
| 1009 | if (this.pdfHistory) { |
| 1010 | this.pdfHistory.pushCurrentPosition(); |
| 1011 | this.pdfHistory.pushPage(pageNumber); |
| 1012 | } |
| 1013 | this.pdfViewer.scrollPageIntoView({ |
| 1014 | pageNumber |
| 1015 | }); |
| 1016 | } |
| 1017 | addLinkAttributes(link, url, newWindow = false) { |
| 1018 | addLinkAttributes(link, { |
| 1019 | url, |
| 1020 | target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget, |
| 1021 | rel: this.externalLinkRel, |
| 1022 | enabled: this.externalLinkEnabled |
| 1023 | }); |
| 1024 | } |
| 1025 | getDestinationHash(dest) { |
| 1026 | if (typeof dest === "string") { |
| 1027 | if (dest.length > 0) { |
| 1028 | return this.getAnchorUrl("#" + escape(dest)); |
| 1029 | } |
| 1030 | } else if (Array.isArray(dest)) { |
| 1031 | const str = JSON.stringify(dest); |
| 1032 | if (str.length > 0) { |
| 1033 | return this.getAnchorUrl("#" + escape(str)); |
| 1034 | } |
| 1035 | } |
| 1036 | return this.getAnchorUrl(""); |
| 1037 | } |
| 1038 | getAnchorUrl(anchor) { |
| 1039 | return (this.baseUrl || "") + anchor; |
| 1040 | } |
| 1041 | setHash(hash) { |
| 1042 | if (!this.pdfDocument) { |
| 1043 | return; |
| 1044 | } |
| 1045 | let pageNumber, dest; |
| 1046 | if (hash.includes("=")) { |
| 1047 | const params = (0, _ui_utils.parseQueryString)(hash); |
| 1048 | if (params.has("search")) { |
| 1049 | this.eventBus.dispatch("findfromurlhash", { |
| 1050 | source: this, |
| 1051 | query: params.get("search").replace(/"/g, ""), |
| 1052 | phraseSearch: params.get("phrase") === "true" |
| 1053 | }); |
| 1054 | } |
| 1055 | if (params.has("page")) { |
| 1056 | pageNumber = params.get("page") | 0 || 1; |
| 1057 | } |
| 1058 | if (params.has("zoom")) { |
| 1059 | const zoomArgs = params.get("zoom").split(","); |
| 1060 | const zoomArg = zoomArgs[0]; |
| 1061 | const zoomArgNumber = parseFloat(zoomArg); |
| 1062 | if (!zoomArg.includes("Fit")) { |
| 1063 | dest = [null, { |
| 1064 | name: "XYZ" |
| 1065 | }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg]; |
| 1066 | } else { |
| 1067 | if (zoomArg === "Fit" || zoomArg === "FitB") { |
| 1068 | dest = [null, { |
| 1069 | name: zoomArg |
| 1070 | }]; |
| 1071 | } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") { |
| 1072 | dest = [null, { |
| 1073 | name: zoomArg |
| 1074 | }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null]; |
| 1075 | } else if (zoomArg === "FitR") { |
| 1076 | if (zoomArgs.length !== 5) { |
| 1077 | console.error('PDFLinkService.setHash: Not enough parameters for "FitR".'); |
| 1078 | } else { |
| 1079 | dest = [null, { |
| 1080 | name: zoomArg |
| 1081 | }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0]; |
| 1082 | } |
| 1083 | } else { |
| 1084 | console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`); |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | if (dest) { |
| 1089 | this.pdfViewer.scrollPageIntoView({ |
| 1090 | pageNumber: pageNumber || this.page, |
| 1091 | destArray: dest, |
| 1092 | allowNegativeOffset: true |
| 1093 | }); |
| 1094 | } else if (pageNumber) { |
| 1095 | this.page = pageNumber; |
| 1096 | } |
| 1097 | if (params.has("pagemode")) { |
| 1098 | this.eventBus.dispatch("pagemode", { |
| 1099 | source: this, |
| 1100 | mode: params.get("pagemode") |
| 1101 | }); |
| 1102 | } |
| 1103 | if (params.has("nameddest")) { |
| 1104 | this.goToDestination(params.get("nameddest")); |
| 1105 | } |
| 1106 | } else { |
| 1107 | dest = unescape(hash); |
| 1108 | try { |
| 1109 | dest = JSON.parse(dest); |
| 1110 | if (!Array.isArray(dest)) { |
| 1111 | dest = dest.toString(); |
| 1112 | } |
| 1113 | } catch (ex) {} |
| 1114 | if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) { |
| 1115 | this.goToDestination(dest); |
| 1116 | return; |
| 1117 | } |
| 1118 | console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`); |
| 1119 | } |
| 1120 | } |
| 1121 | executeNamedAction(action) { |
| 1122 | switch (action) { |
| 1123 | case "GoBack": |
| 1124 | this.pdfHistory?.back(); |
| 1125 | break; |
| 1126 | case "GoForward": |
| 1127 | this.pdfHistory?.forward(); |
| 1128 | break; |
| 1129 | case "NextPage": |
| 1130 | this.pdfViewer.nextPage(); |
| 1131 | break; |
| 1132 | case "PrevPage": |
| 1133 | this.pdfViewer.previousPage(); |
| 1134 | break; |
| 1135 | case "LastPage": |
| 1136 | this.page = this.pagesCount; |
| 1137 | break; |
| 1138 | case "FirstPage": |
| 1139 | this.page = 1; |
| 1140 | break; |
| 1141 | default: |
| 1142 | break; |
| 1143 | } |
| 1144 | this.eventBus.dispatch("namedaction", { |
| 1145 | source: this, |
| 1146 | action |
| 1147 | }); |
| 1148 | } |
| 1149 | async executeSetOCGState(action) { |
| 1150 | const pdfDocument = this.pdfDocument; |
| 1151 | const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; |
| 1152 | if (pdfDocument !== this.pdfDocument) { |
| 1153 | return; |
| 1154 | } |
| 1155 | let operator; |
| 1156 | for (const elem of action.state) { |
| 1157 | switch (elem) { |
| 1158 | case "ON": |
| 1159 | case "OFF": |
| 1160 | case "Toggle": |
| 1161 | operator = elem; |
| 1162 | continue; |
| 1163 | } |
| 1164 | switch (operator) { |
| 1165 | case "ON": |
| 1166 | optionalContentConfig.setVisibility(elem, true); |
| 1167 | break; |
| 1168 | case "OFF": |
| 1169 | optionalContentConfig.setVisibility(elem, false); |
| 1170 | break; |
| 1171 | case "Toggle": |
| 1172 | const group = optionalContentConfig.getGroup(elem); |
| 1173 | if (group) { |
| 1174 | optionalContentConfig.setVisibility(elem, !group.visible); |
| 1175 | } |
| 1176 | break; |
| 1177 | } |
| 1178 | } |
| 1179 | this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig); |
| 1180 | } |
| 1181 | cachePageRef(pageNum, pageRef) { |
| 1182 | if (!pageRef) { |
| 1183 | return; |
| 1184 | } |
| 1185 | const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; |
| 1186 | this.#pagesRefCache.set(refStr, pageNum); |
| 1187 | } |
| 1188 | _cachedPageNumber(pageRef) { |
| 1189 | if (!pageRef) { |
| 1190 | return null; |
| 1191 | } |
| 1192 | const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; |
| 1193 | return this.#pagesRefCache.get(refStr) || null; |
| 1194 | } |
| 1195 | isPageVisible(pageNumber) { |
| 1196 | return this.pdfViewer.isPageVisible(pageNumber); |
| 1197 | } |
| 1198 | isPageCached(pageNumber) { |
| 1199 | return this.pdfViewer.isPageCached(pageNumber); |
| 1200 | } |
| 1201 | static #isValidExplicitDestination(dest) { |
| 1202 | if (!Array.isArray(dest)) { |
| 1203 | return false; |
| 1204 | } |
| 1205 | const destLength = dest.length; |
| 1206 | if (destLength < 2) { |
| 1207 | return false; |
| 1208 | } |
| 1209 | const page = dest[0]; |
| 1210 | if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) { |
| 1211 | return false; |
| 1212 | } |
| 1213 | const zoom = dest[1]; |
| 1214 | if (!(typeof zoom === "object" && typeof zoom.name === "string")) { |
| 1215 | return false; |
| 1216 | } |
| 1217 | let allowNull = true; |
| 1218 | switch (zoom.name) { |
| 1219 | case "XYZ": |
| 1220 | if (destLength !== 5) { |
| 1221 | return false; |
| 1222 | } |
| 1223 | break; |
| 1224 | case "Fit": |
| 1225 | case "FitB": |
| 1226 | return destLength === 2; |
| 1227 | case "FitH": |
| 1228 | case "FitBH": |
| 1229 | case "FitV": |
| 1230 | case "FitBV": |
| 1231 | if (destLength !== 3) { |
| 1232 | return false; |
| 1233 | } |
| 1234 | break; |
| 1235 | case "FitR": |
| 1236 | if (destLength !== 6) { |
| 1237 | return false; |
| 1238 | } |
| 1239 | allowNull = false; |
| 1240 | break; |
| 1241 | default: |
| 1242 | return false; |
| 1243 | } |
| 1244 | for (let i = 2; i < destLength; i++) { |
| 1245 | const param = dest[i]; |
| 1246 | if (!(typeof param === "number" || allowNull && param === null)) { |
| 1247 | return false; |
| 1248 | } |
| 1249 | } |
| 1250 | return true; |
| 1251 | } |
| 1252 | } |
| 1253 | exports.PDFLinkService = PDFLinkService; |
| 1254 | class SimpleLinkService { |
| 1255 | constructor() { |
| 1256 | this.externalLinkEnabled = true; |
| 1257 | } |
| 1258 | get pagesCount() { |
| 1259 | return 0; |
| 1260 | } |
| 1261 | get page() { |
| 1262 | return 0; |
| 1263 | } |
| 1264 | set page(value) {} |
| 1265 | get rotation() { |
| 1266 | return 0; |
| 1267 | } |
| 1268 | set rotation(value) {} |
| 1269 | get isInPresentationMode() { |
| 1270 | return false; |
| 1271 | } |
| 1272 | async goToDestination(dest) {} |
| 1273 | goToPage(val) {} |
| 1274 | addLinkAttributes(link, url, newWindow = false) { |
| 1275 | addLinkAttributes(link, { |
| 1276 | url, |
| 1277 | enabled: this.externalLinkEnabled |
| 1278 | }); |
| 1279 | } |
| 1280 | getDestinationHash(dest) { |
| 1281 | return "#"; |
| 1282 | } |
| 1283 | getAnchorUrl(hash) { |
| 1284 | return "#"; |
| 1285 | } |
| 1286 | setHash(hash) {} |
| 1287 | executeNamedAction(action) {} |
| 1288 | executeSetOCGState(action) {} |
| 1289 | cachePageRef(pageNum, pageRef) {} |
| 1290 | isPageVisible(pageNumber) { |
| 1291 | return true; |
| 1292 | } |
| 1293 | isPageCached(pageNumber) { |
| 1294 | return true; |
| 1295 | } |
| 1296 | } |
| 1297 | exports.SimpleLinkService = SimpleLinkService; |
| 1298 | |
| 1299 | /***/ }), |
| 1300 | /* 4 */ |
| 1301 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | Object.defineProperty(exports, "__esModule", ({ |
| 1306 | value: true |
| 1307 | })); |
| 1308 | exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0; |
| 1309 | var _ui_utils = __webpack_require__(1); |
| 1310 | var _pdfjsLib = __webpack_require__(5); |
| 1311 | var _app_options = __webpack_require__(2); |
| 1312 | var _event_utils = __webpack_require__(6); |
| 1313 | var _pdf_cursor_tools = __webpack_require__(7); |
| 1314 | var _pdf_link_service = __webpack_require__(3); |
| 1315 | var _annotation_editor_params = __webpack_require__(9); |
| 1316 | var _overlay_manager = __webpack_require__(10); |
| 1317 | var _password_prompt = __webpack_require__(11); |
| 1318 | var _pdf_attachment_viewer = __webpack_require__(12); |
| 1319 | var _pdf_document_properties = __webpack_require__(14); |
| 1320 | var _pdf_find_bar = __webpack_require__(15); |
| 1321 | var _pdf_find_controller = __webpack_require__(16); |
| 1322 | var _pdf_history = __webpack_require__(18); |
| 1323 | var _pdf_layer_viewer = __webpack_require__(19); |
| 1324 | var _pdf_outline_viewer = __webpack_require__(20); |
| 1325 | var _pdf_presentation_mode = __webpack_require__(21); |
| 1326 | var _pdf_rendering_queue = __webpack_require__(22); |
| 1327 | var _pdf_scripting_manager = __webpack_require__(23); |
| 1328 | var _pdf_sidebar = __webpack_require__(24); |
| 1329 | var _pdf_sidebar_resizer = __webpack_require__(25); |
| 1330 | var _pdf_thumbnail_viewer = __webpack_require__(26); |
| 1331 | var _pdf_viewer = __webpack_require__(28); |
| 1332 | var _secondary_toolbar = __webpack_require__(38); |
| 1333 | var _toolbar = __webpack_require__(39); |
| 1334 | var _view_history = __webpack_require__(40); |
| 1335 | const FORCE_PAGES_LOADED_TIMEOUT = 10000; |
| 1336 | const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; |
| 1337 | const ViewOnLoad = { |
| 1338 | UNKNOWN: -1, |
| 1339 | PREVIOUS: 0, |
| 1340 | INITIAL: 1 |
| 1341 | }; |
| 1342 | const ViewerCssTheme = { |
| 1343 | AUTOMATIC: 0, |
| 1344 | LIGHT: 1, |
| 1345 | DARK: 2 |
| 1346 | }; |
| 1347 | class DefaultExternalServices { |
| 1348 | constructor() { |
| 1349 | throw new Error("Cannot initialize DefaultExternalServices."); |
| 1350 | } |
| 1351 | static updateFindControlState(data) {} |
| 1352 | static updateFindMatchesCount(data) {} |
| 1353 | static initPassiveLoading(callbacks) {} |
| 1354 | static reportTelemetry(data) {} |
| 1355 | static createDownloadManager() { |
| 1356 | throw new Error("Not implemented: createDownloadManager"); |
| 1357 | } |
| 1358 | static createPreferences() { |
| 1359 | throw new Error("Not implemented: createPreferences"); |
| 1360 | } |
| 1361 | static createL10n(options) { |
| 1362 | throw new Error("Not implemented: createL10n"); |
| 1363 | } |
| 1364 | static createScripting(options) { |
| 1365 | throw new Error("Not implemented: createScripting"); |
| 1366 | } |
| 1367 | static get supportsPinchToZoom() { |
| 1368 | return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true); |
| 1369 | } |
| 1370 | static get supportsIntegratedFind() { |
| 1371 | return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false); |
| 1372 | } |
| 1373 | static get supportsDocumentFonts() { |
| 1374 | return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true); |
| 1375 | } |
| 1376 | static get supportedMouseWheelZoomModifierKeys() { |
| 1377 | return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", { |
| 1378 | ctrlKey: true, |
| 1379 | metaKey: true |
| 1380 | }); |
| 1381 | } |
| 1382 | static get isInAutomation() { |
| 1383 | return (0, _pdfjsLib.shadow)(this, "isInAutomation", false); |
| 1384 | } |
| 1385 | static updateEditorStates(data) { |
| 1386 | throw new Error("Not implemented: updateEditorStates"); |
| 1387 | } |
| 1388 | } |
| 1389 | exports.DefaultExternalServices = DefaultExternalServices; |
| 1390 | const PDFViewerApplication = { |
| 1391 | initialBookmark: document.location.hash.substring(1), |
| 1392 | _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(), |
| 1393 | appConfig: null, |
| 1394 | pdfDocument: null, |
| 1395 | pdfLoadingTask: null, |
| 1396 | printService: null, |
| 1397 | pdfViewer: null, |
| 1398 | pdfThumbnailViewer: null, |
| 1399 | pdfRenderingQueue: null, |
| 1400 | pdfPresentationMode: null, |
| 1401 | pdfDocumentProperties: null, |
| 1402 | pdfLinkService: null, |
| 1403 | pdfHistory: null, |
| 1404 | pdfSidebar: null, |
| 1405 | pdfSidebarResizer: null, |
| 1406 | pdfOutlineViewer: null, |
| 1407 | pdfAttachmentViewer: null, |
| 1408 | pdfLayerViewer: null, |
| 1409 | pdfCursorTools: null, |
| 1410 | pdfScriptingManager: null, |
| 1411 | store: null, |
| 1412 | downloadManager: null, |
| 1413 | overlayManager: null, |
| 1414 | preferences: null, |
| 1415 | toolbar: null, |
| 1416 | secondaryToolbar: null, |
| 1417 | eventBus: null, |
| 1418 | l10n: null, |
| 1419 | annotationEditorParams: null, |
| 1420 | isInitialViewSet: false, |
| 1421 | downloadComplete: false, |
| 1422 | isViewerEmbedded: window.parent !== window, |
| 1423 | url: "", |
| 1424 | baseUrl: "", |
| 1425 | _downloadUrl: "", |
| 1426 | externalServices: DefaultExternalServices, |
| 1427 | _boundEvents: Object.create(null), |
| 1428 | documentInfo: null, |
| 1429 | metadata: null, |
| 1430 | _contentDispositionFilename: null, |
| 1431 | _contentLength: null, |
| 1432 | _saveInProgress: false, |
| 1433 | _wheelUnusedTicks: 0, |
| 1434 | _wheelUnusedFactor: 1, |
| 1435 | _touchUnusedTicks: 0, |
| 1436 | _touchUnusedFactor: 1, |
| 1437 | _PDFBug: null, |
| 1438 | _hasAnnotationEditors: false, |
| 1439 | _title: document.title, |
| 1440 | _printAnnotationStoragePromise: null, |
| 1441 | _touchInfo: null, |
| 1442 | _isCtrlKeyDown: false, |
| 1443 | async initialize(appConfig) { |
| 1444 | this.preferences = this.externalServices.createPreferences(); |
| 1445 | this.appConfig = appConfig; |
| 1446 | await this._readPreferences(); |
| 1447 | await this._parseHashParameters(); |
| 1448 | this._forceCssTheme(); |
| 1449 | await this._initializeL10n(); |
| 1450 | if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) { |
| 1451 | _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP); |
| 1452 | } |
| 1453 | await this._initializeViewerComponents(); |
| 1454 | this.bindEvents(); |
| 1455 | this.bindWindowEvents(); |
| 1456 | const appContainer = appConfig.appContainer || document.documentElement; |
| 1457 | this.l10n.translate(appContainer).then(() => { |
| 1458 | this.eventBus.dispatch("localized", { |
| 1459 | source: this |
| 1460 | }); |
| 1461 | }); |
| 1462 | this._initializedCapability.resolve(); |
| 1463 | }, |
| 1464 | async _readPreferences() { |
| 1465 | if (_app_options.AppOptions.get("disablePreferences")) { |
| 1466 | return; |
| 1467 | } |
| 1468 | if (_app_options.AppOptions._hasUserOptions()) { |
| 1469 | console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.'); |
| 1470 | } |
| 1471 | try { |
| 1472 | _app_options.AppOptions.setAll(await this.preferences.getAll()); |
| 1473 | } catch (reason) { |
| 1474 | console.error(`_readPreferences: "${reason?.message}".`); |
| 1475 | } |
| 1476 | }, |
| 1477 | async _parseHashParameters() { |
| 1478 | if (!_app_options.AppOptions.get("pdfBugEnabled")) { |
| 1479 | return; |
| 1480 | } |
| 1481 | const hash = document.location.hash.substring(1); |
| 1482 | if (!hash) { |
| 1483 | return; |
| 1484 | } |
| 1485 | const { |
| 1486 | mainContainer, |
| 1487 | viewerContainer |
| 1488 | } = this.appConfig, |
| 1489 | params = (0, _ui_utils.parseQueryString)(hash); |
| 1490 | if (params.get("disableworker") === "true") { |
| 1491 | try { |
| 1492 | await loadFakeWorker(); |
| 1493 | } catch (ex) { |
| 1494 | console.error(`_parseHashParameters: "${ex.message}".`); |
| 1495 | } |
| 1496 | } |
| 1497 | if (params.has("disablerange")) { |
| 1498 | _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true"); |
| 1499 | } |
| 1500 | if (params.has("disablestream")) { |
| 1501 | _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true"); |
| 1502 | } |
| 1503 | if (params.has("disableautofetch")) { |
| 1504 | _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true"); |
| 1505 | } |
| 1506 | if (params.has("disablefontface")) { |
| 1507 | _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true"); |
| 1508 | } |
| 1509 | if (params.has("disablehistory")) { |
| 1510 | _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true"); |
| 1511 | } |
| 1512 | if (params.has("verbosity")) { |
| 1513 | _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0); |
| 1514 | } |
| 1515 | if (params.has("textlayer")) { |
| 1516 | switch (params.get("textlayer")) { |
| 1517 | case "off": |
| 1518 | _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE); |
| 1519 | break; |
| 1520 | case "visible": |
| 1521 | case "shadow": |
| 1522 | case "hover": |
| 1523 | viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`); |
| 1524 | try { |
| 1525 | await loadPDFBug(this); |
| 1526 | this._PDFBug.loadCSS(); |
| 1527 | } catch (ex) { |
| 1528 | console.error(`_parseHashParameters: "${ex.message}".`); |
| 1529 | } |
| 1530 | break; |
| 1531 | } |
| 1532 | } |
| 1533 | if (params.has("pdfbug")) { |
| 1534 | _app_options.AppOptions.set("pdfBug", true); |
| 1535 | _app_options.AppOptions.set("fontExtraProperties", true); |
| 1536 | const enabled = params.get("pdfbug").split(","); |
| 1537 | try { |
| 1538 | await loadPDFBug(this); |
| 1539 | this._PDFBug.init({ |
| 1540 | OPS: _pdfjsLib.OPS |
| 1541 | }, mainContainer, enabled); |
| 1542 | } catch (ex) { |
| 1543 | console.error(`_parseHashParameters: "${ex.message}".`); |
| 1544 | } |
| 1545 | } |
| 1546 | if (params.has("locale")) { |
| 1547 | _app_options.AppOptions.set("locale", params.get("locale")); |
| 1548 | } |
| 1549 | }, |
| 1550 | async _initializeL10n() { |
| 1551 | this.l10n = this.externalServices.createL10n({ |
| 1552 | locale: _app_options.AppOptions.get("locale") |
| 1553 | }); |
| 1554 | const dir = await this.l10n.getDirection(); |
| 1555 | document.getElementsByTagName("html")[0].dir = dir; |
| 1556 | }, |
| 1557 | _forceCssTheme() { |
| 1558 | const cssTheme = _app_options.AppOptions.get("viewerCssTheme"); |
| 1559 | if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) { |
| 1560 | return; |
| 1561 | } |
| 1562 | try { |
| 1563 | const styleSheet = document.styleSheets[0]; |
| 1564 | const cssRules = styleSheet?.cssRules || []; |
| 1565 | for (let i = 0, ii = cssRules.length; i < ii; i++) { |
| 1566 | const rule = cssRules[i]; |
| 1567 | if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") { |
| 1568 | if (cssTheme === ViewerCssTheme.LIGHT) { |
| 1569 | styleSheet.deleteRule(i); |
| 1570 | return; |
| 1571 | } |
| 1572 | const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText); |
| 1573 | if (darkRules?.[1]) { |
| 1574 | styleSheet.deleteRule(i); |
| 1575 | styleSheet.insertRule(darkRules[1], i); |
| 1576 | } |
| 1577 | return; |
| 1578 | } |
| 1579 | } |
| 1580 | } catch (reason) { |
| 1581 | console.error(`_forceCssTheme: "${reason?.message}".`); |
| 1582 | } |
| 1583 | }, |
| 1584 | async _initializeViewerComponents() { |
| 1585 | const { |
| 1586 | appConfig, |
| 1587 | externalServices |
| 1588 | } = this; |
| 1589 | const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus(); |
| 1590 | this.eventBus = eventBus; |
| 1591 | this.overlayManager = new _overlay_manager.OverlayManager(); |
| 1592 | const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue(); |
| 1593 | pdfRenderingQueue.onIdle = this._cleanup.bind(this); |
| 1594 | this.pdfRenderingQueue = pdfRenderingQueue; |
| 1595 | const pdfLinkService = new _pdf_link_service.PDFLinkService({ |
| 1596 | eventBus, |
| 1597 | externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"), |
| 1598 | externalLinkRel: _app_options.AppOptions.get("externalLinkRel"), |
| 1599 | ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom") |
| 1600 | }); |
| 1601 | this.pdfLinkService = pdfLinkService; |
| 1602 | const downloadManager = externalServices.createDownloadManager(); |
| 1603 | this.downloadManager = downloadManager; |
| 1604 | const findController = new _pdf_find_controller.PDFFindController({ |
| 1605 | linkService: pdfLinkService, |
| 1606 | eventBus, |
| 1607 | updateMatchesCountOnProgress: true |
| 1608 | }); |
| 1609 | this.findController = findController; |
| 1610 | const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({ |
| 1611 | eventBus, |
| 1612 | sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"), |
| 1613 | scriptingFactory: externalServices, |
| 1614 | docPropertiesLookup: this._scriptingDocProperties.bind(this) |
| 1615 | }); |
| 1616 | this.pdfScriptingManager = pdfScriptingManager; |
| 1617 | const container = appConfig.mainContainer, |
| 1618 | viewer = appConfig.viewerContainer; |
| 1619 | const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode"); |
| 1620 | const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? { |
| 1621 | background: _app_options.AppOptions.get("pageColorsBackground"), |
| 1622 | foreground: _app_options.AppOptions.get("pageColorsForeground") |
| 1623 | } : null; |
| 1624 | this.pdfViewer = new _pdf_viewer.PDFViewer({ |
| 1625 | container, |
| 1626 | viewer, |
| 1627 | eventBus, |
| 1628 | renderingQueue: pdfRenderingQueue, |
| 1629 | linkService: pdfLinkService, |
| 1630 | downloadManager, |
| 1631 | findController, |
| 1632 | scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager, |
| 1633 | renderer: _app_options.AppOptions.get("renderer"), |
| 1634 | l10n: this.l10n, |
| 1635 | textLayerMode: _app_options.AppOptions.get("textLayerMode"), |
| 1636 | annotationMode: _app_options.AppOptions.get("annotationMode"), |
| 1637 | annotationEditorMode, |
| 1638 | imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"), |
| 1639 | enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"), |
| 1640 | useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"), |
| 1641 | isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"), |
| 1642 | maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"), |
| 1643 | enablePermissions: _app_options.AppOptions.get("enablePermissions"), |
| 1644 | pageColors |
| 1645 | }); |
| 1646 | pdfRenderingQueue.setViewer(this.pdfViewer); |
| 1647 | pdfLinkService.setViewer(this.pdfViewer); |
| 1648 | pdfScriptingManager.setViewer(this.pdfViewer); |
| 1649 | if (appConfig.sidebar?.thumbnailView) { |
| 1650 | this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({ |
| 1651 | container: appConfig.sidebar.thumbnailView, |
| 1652 | eventBus, |
| 1653 | renderingQueue: pdfRenderingQueue, |
| 1654 | linkService: pdfLinkService, |
| 1655 | l10n: this.l10n, |
| 1656 | pageColors |
| 1657 | }); |
| 1658 | pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer); |
| 1659 | } |
| 1660 | if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) { |
| 1661 | this.pdfHistory = new _pdf_history.PDFHistory({ |
| 1662 | linkService: pdfLinkService, |
| 1663 | eventBus |
| 1664 | }); |
| 1665 | pdfLinkService.setHistory(this.pdfHistory); |
| 1666 | } |
| 1667 | if (!this.supportsIntegratedFind && appConfig.findBar) { |
| 1668 | this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n); |
| 1669 | } |
| 1670 | if (appConfig.annotationEditorParams) { |
| 1671 | if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) { |
| 1672 | this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus); |
| 1673 | } else { |
| 1674 | for (const id of ["editorModeButtons", "editorModeSeparator"]) { |
| 1675 | document.getElementById(id)?.classList.add("hidden"); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | if (appConfig.documentProperties) { |
| 1680 | this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => { |
| 1681 | return this._docFilename; |
| 1682 | }); |
| 1683 | } |
| 1684 | this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({ |
| 1685 | container, |
| 1686 | eventBus, |
| 1687 | cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad") |
| 1688 | }); |
| 1689 | if (appConfig.toolbar) { |
| 1690 | this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n); |
| 1691 | } |
| 1692 | if (appConfig.secondaryToolbar) { |
| 1693 | this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices); |
| 1694 | } |
| 1695 | if (this.supportsFullscreen) { |
| 1696 | this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({ |
| 1697 | container, |
| 1698 | pdfViewer: this.pdfViewer, |
| 1699 | eventBus |
| 1700 | }); |
| 1701 | } |
| 1702 | if (appConfig.passwordOverlay) { |
| 1703 | this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded); |
| 1704 | } |
| 1705 | if (appConfig.sidebar?.outlineView) { |
| 1706 | this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({ |
| 1707 | container: appConfig.sidebar.outlineView, |
| 1708 | eventBus, |
| 1709 | linkService: pdfLinkService, |
| 1710 | downloadManager |
| 1711 | }); |
| 1712 | } |
| 1713 | if (appConfig.sidebar?.attachmentsView) { |
| 1714 | this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({ |
| 1715 | container: appConfig.sidebar.attachmentsView, |
| 1716 | eventBus, |
| 1717 | downloadManager |
| 1718 | }); |
| 1719 | } |
| 1720 | if (appConfig.sidebar?.layersView) { |
| 1721 | this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({ |
| 1722 | container: appConfig.sidebar.layersView, |
| 1723 | eventBus, |
| 1724 | l10n: this.l10n |
| 1725 | }); |
| 1726 | } |
| 1727 | if (appConfig.sidebar) { |
| 1728 | this.pdfSidebar = new _pdf_sidebar.PDFSidebar({ |
| 1729 | elements: appConfig.sidebar, |
| 1730 | pdfViewer: this.pdfViewer, |
| 1731 | pdfThumbnailViewer: this.pdfThumbnailViewer, |
| 1732 | eventBus, |
| 1733 | l10n: this.l10n |
| 1734 | }); |
| 1735 | this.pdfSidebar.onToggled = this.forceRendering.bind(this); |
| 1736 | this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n); |
| 1737 | } |
| 1738 | }, |
| 1739 | run(config) { |
| 1740 | this.initialize(config).then(webViewerInitialized); |
| 1741 | }, |
| 1742 | get initialized() { |
| 1743 | return this._initializedCapability.settled; |
| 1744 | }, |
| 1745 | get initializedPromise() { |
| 1746 | return this._initializedCapability.promise; |
| 1747 | }, |
| 1748 | zoomIn(steps, scaleFactor) { |
| 1749 | if (this.pdfViewer.isInPresentationMode) { |
| 1750 | return; |
| 1751 | } |
| 1752 | this.pdfViewer.increaseScale({ |
| 1753 | drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"), |
| 1754 | steps, |
| 1755 | scaleFactor |
| 1756 | }); |
| 1757 | }, |
| 1758 | zoomOut(steps, scaleFactor) { |
| 1759 | if (this.pdfViewer.isInPresentationMode) { |
| 1760 | return; |
| 1761 | } |
| 1762 | this.pdfViewer.decreaseScale({ |
| 1763 | drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"), |
| 1764 | steps, |
| 1765 | scaleFactor |
| 1766 | }); |
| 1767 | }, |
| 1768 | zoomReset() { |
| 1769 | if (this.pdfViewer.isInPresentationMode) { |
| 1770 | return; |
| 1771 | } |
| 1772 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE; |
| 1773 | }, |
| 1774 | get pagesCount() { |
| 1775 | return this.pdfDocument ? this.pdfDocument.numPages : 0; |
| 1776 | }, |
| 1777 | get page() { |
| 1778 | return this.pdfViewer.currentPageNumber; |
| 1779 | }, |
| 1780 | set page(val) { |
| 1781 | this.pdfViewer.currentPageNumber = val; |
| 1782 | }, |
| 1783 | get supportsPrinting() { |
| 1784 | return PDFPrintServiceFactory.instance.supportsPrinting; |
| 1785 | }, |
| 1786 | get supportsFullscreen() { |
| 1787 | return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled); |
| 1788 | }, |
| 1789 | get supportsPinchToZoom() { |
| 1790 | return this.externalServices.supportsPinchToZoom; |
| 1791 | }, |
| 1792 | get supportsIntegratedFind() { |
| 1793 | return this.externalServices.supportsIntegratedFind; |
| 1794 | }, |
| 1795 | get supportsDocumentFonts() { |
| 1796 | return this.externalServices.supportsDocumentFonts; |
| 1797 | }, |
| 1798 | get loadingBar() { |
| 1799 | const barElement = document.getElementById("loadingBar"); |
| 1800 | const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null; |
| 1801 | return (0, _pdfjsLib.shadow)(this, "loadingBar", bar); |
| 1802 | }, |
| 1803 | get supportedMouseWheelZoomModifierKeys() { |
| 1804 | return this.externalServices.supportedMouseWheelZoomModifierKeys; |
| 1805 | }, |
| 1806 | initPassiveLoading() { |
| 1807 | throw new Error("Not implemented: initPassiveLoading"); |
| 1808 | }, |
| 1809 | setTitleUsingUrl(url = "", downloadUrl = null) { |
| 1810 | this.url = url; |
| 1811 | this.baseUrl = url.split("#")[0]; |
| 1812 | if (downloadUrl) { |
| 1813 | this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0]; |
| 1814 | } |
| 1815 | if ((0, _pdfjsLib.isDataScheme)(url)) { |
| 1816 | this._hideViewBookmark(); |
| 1817 | } |
| 1818 | let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, ""); |
| 1819 | if (!title) { |
| 1820 | try { |
| 1821 | title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url; |
| 1822 | } catch (ex) { |
| 1823 | title = url; |
| 1824 | } |
| 1825 | } |
| 1826 | this.setTitle(title); |
| 1827 | }, |
| 1828 | setTitle(title = this._title) { |
| 1829 | this._title = title; |
| 1830 | if (this.isViewerEmbedded) { |
| 1831 | return; |
| 1832 | } |
| 1833 | const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing; |
| 1834 | document.title = `${editorIndicator ? "* " : ""}${title}`; |
| 1835 | }, |
| 1836 | get _docFilename() { |
| 1837 | return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url); |
| 1838 | }, |
| 1839 | _hideViewBookmark() { |
| 1840 | const { |
| 1841 | secondaryToolbar |
| 1842 | } = this.appConfig; |
| 1843 | secondaryToolbar?.viewBookmarkButton.classList.add("hidden"); |
| 1844 | if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) { |
| 1845 | document.getElementById("viewBookmarkSeparator")?.classList.add("hidden"); |
| 1846 | } |
| 1847 | }, |
| 1848 | async close() { |
| 1849 | this._unblockDocumentLoadEvent(); |
| 1850 | this._hideViewBookmark(); |
| 1851 | if (!this.pdfLoadingTask) { |
| 1852 | return; |
| 1853 | } |
| 1854 | if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) { |
| 1855 | try { |
| 1856 | await this.save(); |
| 1857 | } catch (reason) {} |
| 1858 | } |
| 1859 | const promises = []; |
| 1860 | promises.push(this.pdfLoadingTask.destroy()); |
| 1861 | this.pdfLoadingTask = null; |
| 1862 | if (this.pdfDocument) { |
| 1863 | this.pdfDocument = null; |
| 1864 | this.pdfThumbnailViewer?.setDocument(null); |
| 1865 | this.pdfViewer.setDocument(null); |
| 1866 | this.pdfLinkService.setDocument(null); |
| 1867 | this.pdfDocumentProperties?.setDocument(null); |
| 1868 | } |
| 1869 | this.pdfLinkService.externalLinkEnabled = true; |
| 1870 | this.store = null; |
| 1871 | this.isInitialViewSet = false; |
| 1872 | this.downloadComplete = false; |
| 1873 | this.url = ""; |
| 1874 | this.baseUrl = ""; |
| 1875 | this._downloadUrl = ""; |
| 1876 | this.documentInfo = null; |
| 1877 | this.metadata = null; |
| 1878 | this._contentDispositionFilename = null; |
| 1879 | this._contentLength = null; |
| 1880 | this._saveInProgress = false; |
| 1881 | this._hasAnnotationEditors = false; |
| 1882 | promises.push(this.pdfScriptingManager.destroyPromise); |
| 1883 | this.setTitle(); |
| 1884 | this.pdfSidebar?.reset(); |
| 1885 | this.pdfOutlineViewer?.reset(); |
| 1886 | this.pdfAttachmentViewer?.reset(); |
| 1887 | this.pdfLayerViewer?.reset(); |
| 1888 | this.pdfHistory?.reset(); |
| 1889 | this.findBar?.reset(); |
| 1890 | this.toolbar?.reset(); |
| 1891 | this.secondaryToolbar?.reset(); |
| 1892 | this._PDFBug?.cleanup(); |
| 1893 | await Promise.all(promises); |
| 1894 | }, |
| 1895 | async open(args) { |
| 1896 | let deprecatedArgs = false; |
| 1897 | if (typeof args === "string") { |
| 1898 | args = { |
| 1899 | url: args |
| 1900 | }; |
| 1901 | deprecatedArgs = true; |
| 1902 | } else if (args?.byteLength) { |
| 1903 | args = { |
| 1904 | data: args |
| 1905 | }; |
| 1906 | deprecatedArgs = true; |
| 1907 | } |
| 1908 | if (deprecatedArgs) { |
| 1909 | console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead."); |
| 1910 | } |
| 1911 | if (this.pdfLoadingTask) { |
| 1912 | await this.close(); |
| 1913 | } |
| 1914 | const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER); |
| 1915 | for (const key in workerParameters) { |
| 1916 | _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key]; |
| 1917 | } |
| 1918 | const parameters = Object.create(null); |
| 1919 | if (args.url) { |
| 1920 | if (args.originalUrl) { |
| 1921 | this.setTitleUsingUrl(args.originalUrl, args.url); |
| 1922 | delete args.originalUrl; |
| 1923 | } else { |
| 1924 | this.setTitleUsingUrl(args.url, args.url); |
| 1925 | } |
| 1926 | } |
| 1927 | const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API); |
| 1928 | for (const key in apiParameters) { |
| 1929 | let value = apiParameters[key]; |
| 1930 | if (key === "docBaseUrl") {} |
| 1931 | parameters[key] = value; |
| 1932 | } |
| 1933 | for (const key in args) { |
| 1934 | parameters[key] = args[key]; |
| 1935 | } |
| 1936 | const loadingTask = (0, _pdfjsLib.getDocument)(parameters); |
| 1937 | this.pdfLoadingTask = loadingTask; |
| 1938 | loadingTask.onPassword = (updateCallback, reason) => { |
| 1939 | if (this.isViewerEmbedded) { |
| 1940 | this._unblockDocumentLoadEvent(); |
| 1941 | } |
| 1942 | this.pdfLinkService.externalLinkEnabled = false; |
| 1943 | this.passwordPrompt.setUpdateCallback(updateCallback, reason); |
| 1944 | this.passwordPrompt.open(); |
| 1945 | }; |
| 1946 | loadingTask.onProgress = ({ |
| 1947 | loaded, |
| 1948 | total |
| 1949 | }) => { |
| 1950 | this.progress(loaded / total); |
| 1951 | }; |
| 1952 | return loadingTask.promise.then(pdfDocument => { |
| 1953 | this.load(pdfDocument); |
| 1954 | }, reason => { |
| 1955 | if (loadingTask !== this.pdfLoadingTask) { |
| 1956 | return undefined; |
| 1957 | } |
| 1958 | let key = "loading_error"; |
| 1959 | if (reason instanceof _pdfjsLib.InvalidPDFException) { |
| 1960 | key = "invalid_file_error"; |
| 1961 | } else if (reason instanceof _pdfjsLib.MissingPDFException) { |
| 1962 | key = "missing_file_error"; |
| 1963 | } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) { |
| 1964 | key = "unexpected_response_error"; |
| 1965 | } |
| 1966 | return this.l10n.get(key).then(msg => { |
| 1967 | this._documentError(msg, { |
| 1968 | message: reason?.message |
| 1969 | }); |
| 1970 | throw reason; |
| 1971 | }); |
| 1972 | }); |
| 1973 | }, |
| 1974 | _ensureDownloadComplete() { |
| 1975 | if (this.pdfDocument && this.downloadComplete) { |
| 1976 | return; |
| 1977 | } |
| 1978 | throw new Error("PDF document not downloaded."); |
| 1979 | }, |
| 1980 | async download() { |
| 1981 | if (location.hash) { |
| 1982 | let hash = location.hash; |
| 1983 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 1984 | |
| 1985 | if(hashParams.get('key') !== null) { |
| 1986 | hashParams = '#' + atob(hashParams.get('key')); |
| 1987 | hashParams = new URLSearchParams(hashParams.substring(1)); |
| 1988 | } |
| 1989 | |
| 1990 | const element = document.querySelector('#download'); |
| 1991 | if((hashParams.get('download') === 'false' || hashParams.get('download') === '') || element.offsetParent === null){ |
| 1992 | return false; |
| 1993 | } |
| 1994 | } // added by EP developer |
| 1995 | |
| 1996 | const url = this._downloadUrl, |
| 1997 | filename = this._docFilename; |
| 1998 | try { |
| 1999 | this._ensureDownloadComplete(); |
| 2000 | const data = await this.pdfDocument.getData(); |
| 2001 | const blob = new Blob([data], { |
| 2002 | type: "application/pdf" |
| 2003 | }); |
| 2004 | await this.downloadManager.download(blob, url, filename); |
| 2005 | } catch (reason) { |
| 2006 | await this.downloadManager.downloadUrl(url, filename); |
| 2007 | } |
| 2008 | }, |
| 2009 | async save() { |
| 2010 | if (location.hash) { |
| 2011 | let hash = location.hash; |
| 2012 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 2013 | |
| 2014 | if(hashParams.get('key') !== null) { |
| 2015 | hashParams = '#' + atob(hashParams.get('key')); |
| 2016 | hashParams = new URLSearchParams(hashParams.substring(1)); |
| 2017 | } |
| 2018 | else{ |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
| 2022 | const element = document.querySelector('#download'); |
| 2023 | |
| 2024 | if((hashParams.get('download') === 'false' || hashParams.get('download') === '') || element.offsetParent === null){ |
| 2025 | return false; |
| 2026 | } |
| 2027 | }// added by EP developer |
| 2028 | |
| 2029 | if (this._saveInProgress) { |
| 2030 | return; |
| 2031 | } |
| 2032 | this._saveInProgress = true; |
| 2033 | await this.pdfScriptingManager.dispatchWillSave(); |
| 2034 | const url = this._downloadUrl, |
| 2035 | filename = this._docFilename; |
| 2036 | try { |
| 2037 | this._ensureDownloadComplete(); |
| 2038 | const data = await this.pdfDocument.saveDocument(); |
| 2039 | const blob = new Blob([data], { |
| 2040 | type: "application/pdf" |
| 2041 | }); |
| 2042 | await this.downloadManager.download(blob, url, filename); |
| 2043 | } catch (reason) { |
| 2044 | console.error(`Error when saving the document: ${reason.message}`); |
| 2045 | await this.download(); |
| 2046 | } finally { |
| 2047 | await this.pdfScriptingManager.dispatchDidSave(); |
| 2048 | this._saveInProgress = false; |
| 2049 | } |
| 2050 | if (this._hasAnnotationEditors) { |
| 2051 | this.externalServices.reportTelemetry({ |
| 2052 | type: "editing", |
| 2053 | data: { |
| 2054 | type: "save" |
| 2055 | } |
| 2056 | }); |
| 2057 | } |
| 2058 | }, |
| 2059 | downloadOrSave() { |
| 2060 | if (this.pdfDocument?.annotationStorage.size > 0) { |
| 2061 | this.save(); |
| 2062 | } else { |
| 2063 | this.download(); |
| 2064 | } |
| 2065 | }, |
| 2066 | _documentError(message, moreInfo = null) { |
| 2067 | this._unblockDocumentLoadEvent(); |
| 2068 | this._otherError(message, moreInfo); |
| 2069 | this.eventBus.dispatch("documenterror", { |
| 2070 | source: this, |
| 2071 | message, |
| 2072 | reason: moreInfo?.message ?? null |
| 2073 | }); |
| 2074 | }, |
| 2075 | _otherError(message, moreInfo = null) { |
| 2076 | const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`]; |
| 2077 | if (moreInfo) { |
| 2078 | moreInfoText.push(`Message: ${moreInfo.message}`); |
| 2079 | if (moreInfo.stack) { |
| 2080 | moreInfoText.push(`Stack: ${moreInfo.stack}`); |
| 2081 | } else { |
| 2082 | if (moreInfo.filename) { |
| 2083 | moreInfoText.push(`File: ${moreInfo.filename}`); |
| 2084 | } |
| 2085 | if (moreInfo.lineNumber) { |
| 2086 | moreInfoText.push(`Line: ${moreInfo.lineNumber}`); |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | console.error(`${message}\n\n${moreInfoText.join("\n")}`); |
| 2091 | }, |
| 2092 | progress(level) { |
| 2093 | if (!this.loadingBar || this.downloadComplete) { |
| 2094 | return; |
| 2095 | } |
| 2096 | const percent = Math.round(level * 100); |
| 2097 | if (percent <= this.loadingBar.percent) { |
| 2098 | return; |
| 2099 | } |
| 2100 | this.loadingBar.percent = percent; |
| 2101 | if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) { |
| 2102 | this.loadingBar.setDisableAutoFetch(); |
| 2103 | } |
| 2104 | }, |
| 2105 | load(pdfDocument) { |
| 2106 | this.pdfDocument = pdfDocument; |
| 2107 | pdfDocument.getDownloadInfo().then(({ |
| 2108 | length |
| 2109 | }) => { |
| 2110 | this._contentLength = length; |
| 2111 | this.downloadComplete = true; |
| 2112 | this.loadingBar?.hide(); |
| 2113 | firstPagePromise.then(() => { |
| 2114 | this.eventBus.dispatch("documentloaded", { |
| 2115 | source: this |
| 2116 | }); |
| 2117 | }); |
| 2118 | }); |
| 2119 | const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {}); |
| 2120 | const pageModePromise = pdfDocument.getPageMode().catch(function () {}); |
| 2121 | const openActionPromise = pdfDocument.getOpenAction().catch(function () {}); |
| 2122 | this.toolbar?.setPagesCount(pdfDocument.numPages, false); |
| 2123 | this.secondaryToolbar?.setPagesCount(pdfDocument.numPages); |
| 2124 | let baseDocumentUrl; |
| 2125 | baseDocumentUrl = null; |
| 2126 | if (baseDocumentUrl && (0, _pdfjsLib.isDataScheme)(baseDocumentUrl)) { |
| 2127 | baseDocumentUrl = null; |
| 2128 | } |
| 2129 | this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); |
| 2130 | this.pdfDocumentProperties?.setDocument(pdfDocument); |
| 2131 | const pdfViewer = this.pdfViewer; |
| 2132 | pdfViewer.setDocument(pdfDocument); |
| 2133 | const { |
| 2134 | firstPagePromise, |
| 2135 | onePageRendered, |
| 2136 | pagesPromise |
| 2137 | } = pdfViewer; |
| 2138 | this.pdfThumbnailViewer?.setDocument(pdfDocument); |
| 2139 | const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({ |
| 2140 | page: null, |
| 2141 | zoom: _ui_utils.DEFAULT_SCALE_VALUE, |
| 2142 | scrollLeft: "0", |
| 2143 | scrollTop: "0", |
| 2144 | rotation: null, |
| 2145 | sidebarView: _ui_utils.SidebarView.UNKNOWN, |
| 2146 | scrollMode: _ui_utils.ScrollMode.UNKNOWN, |
| 2147 | spreadMode: _ui_utils.SpreadMode.UNKNOWN |
| 2148 | }).catch(() => { |
| 2149 | return Object.create(null); |
| 2150 | }); |
| 2151 | firstPagePromise.then(pdfPage => { |
| 2152 | this.loadingBar?.setWidth(this.appConfig.viewerContainer); |
| 2153 | this._initializeAnnotationStorageCallbacks(pdfDocument); |
| 2154 | Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => { |
| 2155 | const viewOnLoad = _app_options.AppOptions.get("viewOnLoad"); |
| 2156 | this._initializePdfHistory({ |
| 2157 | fingerprint: pdfDocument.fingerprints[0], |
| 2158 | viewOnLoad, |
| 2159 | initialDest: openAction?.dest |
| 2160 | }); |
| 2161 | const initialBookmark = this.initialBookmark; |
| 2162 | const zoom = _app_options.AppOptions.get("defaultZoomValue"); |
| 2163 | let hash = zoom ? `zoom=${zoom}` : null; |
| 2164 | let rotation = null; |
| 2165 | let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad"); |
| 2166 | let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad"); |
| 2167 | let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad"); |
| 2168 | if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) { |
| 2169 | hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`; |
| 2170 | rotation = parseInt(stored.rotation, 10); |
| 2171 | if (sidebarView === _ui_utils.SidebarView.UNKNOWN) { |
| 2172 | sidebarView = stored.sidebarView | 0; |
| 2173 | } |
| 2174 | if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) { |
| 2175 | scrollMode = stored.scrollMode | 0; |
| 2176 | } |
| 2177 | if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) { |
| 2178 | spreadMode = stored.spreadMode | 0; |
| 2179 | } |
| 2180 | } |
| 2181 | if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) { |
| 2182 | sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode); |
| 2183 | } |
| 2184 | if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) { |
| 2185 | const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout); |
| 2186 | spreadMode = modes.spreadMode; |
| 2187 | } |
| 2188 | this.setInitialView(hash, { |
| 2189 | rotation, |
| 2190 | sidebarView, |
| 2191 | scrollMode, |
| 2192 | spreadMode |
| 2193 | }); |
| 2194 | this.eventBus.dispatch("documentinit", { |
| 2195 | source: this |
| 2196 | }); |
| 2197 | if (!this.isViewerEmbedded) { |
| 2198 | pdfViewer.focus(); |
| 2199 | } |
| 2200 | await Promise.race([pagesPromise, new Promise(resolve => { |
| 2201 | setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT); |
| 2202 | })]); |
| 2203 | if (!initialBookmark && !hash) { |
| 2204 | return; |
| 2205 | } |
| 2206 | if (pdfViewer.hasEqualPageSizes) { |
| 2207 | return; |
| 2208 | } |
| 2209 | this.initialBookmark = initialBookmark; |
| 2210 | pdfViewer.currentScaleValue = pdfViewer.currentScaleValue; |
| 2211 | this.setInitialView(hash); |
| 2212 | }).catch(() => { |
| 2213 | this.setInitialView(); |
| 2214 | }).then(function () { |
| 2215 | pdfViewer.update(); |
| 2216 | }); |
| 2217 | }); |
| 2218 | pagesPromise.then(() => { |
| 2219 | this._unblockDocumentLoadEvent(); |
| 2220 | this._initializeAutoPrint(pdfDocument, openActionPromise); |
| 2221 | }, reason => { |
| 2222 | this.l10n.get("loading_error").then(msg => { |
| 2223 | this._documentError(msg, { |
| 2224 | message: reason?.message |
| 2225 | }); |
| 2226 | }); |
| 2227 | }); |
| 2228 | onePageRendered.then(data => { |
| 2229 | this.externalServices.reportTelemetry({ |
| 2230 | type: "pageInfo", |
| 2231 | timestamp: data.timestamp |
| 2232 | }); |
| 2233 | pdfDocument.getOutline().then(outline => { |
| 2234 | if (pdfDocument !== this.pdfDocument) { |
| 2235 | return; |
| 2236 | } |
| 2237 | this.pdfOutlineViewer?.render({ |
| 2238 | outline, |
| 2239 | pdfDocument |
| 2240 | }); |
| 2241 | }); |
| 2242 | pdfDocument.getAttachments().then(attachments => { |
| 2243 | if (pdfDocument !== this.pdfDocument) { |
| 2244 | return; |
| 2245 | } |
| 2246 | this.pdfAttachmentViewer?.render({ |
| 2247 | attachments |
| 2248 | }); |
| 2249 | }); |
| 2250 | pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => { |
| 2251 | if (pdfDocument !== this.pdfDocument) { |
| 2252 | return; |
| 2253 | } |
| 2254 | this.pdfLayerViewer?.render({ |
| 2255 | optionalContentConfig, |
| 2256 | pdfDocument |
| 2257 | }); |
| 2258 | }); |
| 2259 | }); |
| 2260 | this._initializePageLabels(pdfDocument); |
| 2261 | this._initializeMetadata(pdfDocument); |
| 2262 | }, |
| 2263 | async _scriptingDocProperties(pdfDocument) { |
| 2264 | if (!this.documentInfo) { |
| 2265 | await new Promise(resolve => { |
| 2266 | this.eventBus._on("metadataloaded", resolve, { |
| 2267 | once: true |
| 2268 | }); |
| 2269 | }); |
| 2270 | if (pdfDocument !== this.pdfDocument) { |
| 2271 | return null; |
| 2272 | } |
| 2273 | } |
| 2274 | if (!this._contentLength) { |
| 2275 | await new Promise(resolve => { |
| 2276 | this.eventBus._on("documentloaded", resolve, { |
| 2277 | once: true |
| 2278 | }); |
| 2279 | }); |
| 2280 | if (pdfDocument !== this.pdfDocument) { |
| 2281 | return null; |
| 2282 | } |
| 2283 | } |
| 2284 | return { |
| 2285 | ...this.documentInfo, |
| 2286 | baseURL: this.baseUrl, |
| 2287 | filesize: this._contentLength, |
| 2288 | filename: this._docFilename, |
| 2289 | metadata: this.metadata?.getRaw(), |
| 2290 | authors: this.metadata?.get("dc:creator"), |
| 2291 | numPages: this.pagesCount, |
| 2292 | URL: this.url |
| 2293 | }; |
| 2294 | }, |
| 2295 | async _initializeAutoPrint(pdfDocument, openActionPromise) { |
| 2296 | const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]); |
| 2297 | if (pdfDocument !== this.pdfDocument) { |
| 2298 | return; |
| 2299 | } |
| 2300 | let triggerAutoPrint = false; |
| 2301 | if (openAction?.action === "Print") { |
| 2302 | triggerAutoPrint = true; |
| 2303 | } |
| 2304 | if (javaScript) { |
| 2305 | javaScript.some(js => { |
| 2306 | if (!js) { |
| 2307 | return false; |
| 2308 | } |
| 2309 | console.warn("Warning: JavaScript support is not enabled"); |
| 2310 | return true; |
| 2311 | }); |
| 2312 | if (!triggerAutoPrint) { |
| 2313 | for (const js of javaScript) { |
| 2314 | if (js && _ui_utils.AutoPrintRegExp.test(js)) { |
| 2315 | triggerAutoPrint = true; |
| 2316 | break; |
| 2317 | } |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | if (triggerAutoPrint) { |
| 2322 | this.triggerPrinting(); |
| 2323 | } |
| 2324 | }, |
| 2325 | async _initializeMetadata(pdfDocument) { |
| 2326 | const { |
| 2327 | info, |
| 2328 | metadata, |
| 2329 | contentDispositionFilename, |
| 2330 | contentLength |
| 2331 | } = await pdfDocument.getMetadata(); |
| 2332 | if (pdfDocument !== this.pdfDocument) { |
| 2333 | return; |
| 2334 | } |
| 2335 | this.documentInfo = info; |
| 2336 | this.metadata = metadata; |
| 2337 | this._contentDispositionFilename ??= contentDispositionFilename; |
| 2338 | this._contentLength ??= contentLength; |
| 2339 | // console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`); |
| 2340 | let pdfTitle = info.Title; |
| 2341 | const metadataTitle = metadata?.get("dc:title"); |
| 2342 | if (metadataTitle) { |
| 2343 | if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) { |
| 2344 | pdfTitle = metadataTitle; |
| 2345 | } |
| 2346 | } |
| 2347 | if (pdfTitle) { |
| 2348 | this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`); |
| 2349 | } else if (this._contentDispositionFilename) { |
| 2350 | this.setTitle(this._contentDispositionFilename); |
| 2351 | } |
| 2352 | if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) { |
| 2353 | if (pdfDocument.loadingParams.enableXfa) { |
| 2354 | console.warn("Warning: XFA Foreground documents are not supported"); |
| 2355 | } else { |
| 2356 | console.warn("Warning: XFA support is not enabled"); |
| 2357 | } |
| 2358 | } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) { |
| 2359 | console.warn("Warning: Interactive form support is not enabled"); |
| 2360 | } |
| 2361 | if (info.IsSignaturesPresent) { |
| 2362 | console.warn("Warning: Digital signatures validation is not supported"); |
| 2363 | } |
| 2364 | this.eventBus.dispatch("metadataloaded", { |
| 2365 | source: this |
| 2366 | }); |
| 2367 | }, |
| 2368 | async _initializePageLabels(pdfDocument) { |
| 2369 | const labels = await pdfDocument.getPageLabels(); |
| 2370 | if (pdfDocument !== this.pdfDocument) { |
| 2371 | return; |
| 2372 | } |
| 2373 | if (!labels || _app_options.AppOptions.get("disablePageLabels")) { |
| 2374 | return; |
| 2375 | } |
| 2376 | const numLabels = labels.length; |
| 2377 | let standardLabels = 0, |
| 2378 | emptyLabels = 0; |
| 2379 | for (let i = 0; i < numLabels; i++) { |
| 2380 | const label = labels[i]; |
| 2381 | if (label === (i + 1).toString()) { |
| 2382 | standardLabels++; |
| 2383 | } else if (label === "") { |
| 2384 | emptyLabels++; |
| 2385 | } else { |
| 2386 | break; |
| 2387 | } |
| 2388 | } |
| 2389 | if (standardLabels >= numLabels || emptyLabels >= numLabels) { |
| 2390 | return; |
| 2391 | } |
| 2392 | const { |
| 2393 | pdfViewer, |
| 2394 | pdfThumbnailViewer, |
| 2395 | toolbar |
| 2396 | } = this; |
| 2397 | pdfViewer.setPageLabels(labels); |
| 2398 | pdfThumbnailViewer?.setPageLabels(labels); |
| 2399 | toolbar?.setPagesCount(numLabels, true); |
| 2400 | toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); |
| 2401 | }, |
| 2402 | _initializePdfHistory({ |
| 2403 | fingerprint, |
| 2404 | viewOnLoad, |
| 2405 | initialDest = null |
| 2406 | }) { |
| 2407 | if (!this.pdfHistory) { |
| 2408 | return; |
| 2409 | } |
| 2410 | this.pdfHistory.initialize({ |
| 2411 | fingerprint, |
| 2412 | resetHistory: viewOnLoad === ViewOnLoad.INITIAL, |
| 2413 | updateUrl: _app_options.AppOptions.get("historyUpdateUrl") |
| 2414 | }); |
| 2415 | if (this.pdfHistory.initialBookmark) { |
| 2416 | this.initialBookmark = this.pdfHistory.initialBookmark; |
| 2417 | this.initialRotation = this.pdfHistory.initialRotation; |
| 2418 | } |
| 2419 | if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) { |
| 2420 | this.initialBookmark = JSON.stringify(initialDest); |
| 2421 | this.pdfHistory.push({ |
| 2422 | explicitDest: initialDest, |
| 2423 | pageNumber: null |
| 2424 | }); |
| 2425 | } |
| 2426 | }, |
| 2427 | _initializeAnnotationStorageCallbacks(pdfDocument) { |
| 2428 | if (pdfDocument !== this.pdfDocument) { |
| 2429 | return; |
| 2430 | } |
| 2431 | const { |
| 2432 | annotationStorage |
| 2433 | } = pdfDocument; |
| 2434 | annotationStorage.onSetModified = () => { |
| 2435 | window.addEventListener("beforeunload", beforeUnload); |
| 2436 | this._annotationStorageModified = true; |
| 2437 | }; |
| 2438 | annotationStorage.onResetModified = () => { |
| 2439 | window.removeEventListener("beforeunload", beforeUnload); |
| 2440 | delete this._annotationStorageModified; |
| 2441 | }; |
| 2442 | annotationStorage.onAnnotationEditor = typeStr => { |
| 2443 | this._hasAnnotationEditors = !!typeStr; |
| 2444 | this.setTitle(); |
| 2445 | if (typeStr) { |
| 2446 | this.externalServices.reportTelemetry({ |
| 2447 | type: "editing", |
| 2448 | data: { |
| 2449 | type: typeStr |
| 2450 | } |
| 2451 | }); |
| 2452 | } |
| 2453 | }; |
| 2454 | }, |
| 2455 | setInitialView(storedHash, { |
| 2456 | rotation, |
| 2457 | sidebarView, |
| 2458 | scrollMode, |
| 2459 | spreadMode |
| 2460 | } = {}) { |
| 2461 | const setRotation = angle => { |
| 2462 | if ((0, _ui_utils.isValidRotation)(angle)) { |
| 2463 | this.pdfViewer.pagesRotation = angle; |
| 2464 | } |
| 2465 | }; |
| 2466 | const setViewerModes = (scroll, spread) => { |
| 2467 | if ((0, _ui_utils.isValidScrollMode)(scroll)) { |
| 2468 | this.pdfViewer.scrollMode = scroll; |
| 2469 | } |
| 2470 | if ((0, _ui_utils.isValidSpreadMode)(spread)) { |
| 2471 | this.pdfViewer.spreadMode = spread; |
| 2472 | } |
| 2473 | }; |
| 2474 | this.isInitialViewSet = true; |
| 2475 | this.pdfSidebar?.setInitialView(sidebarView); |
| 2476 | setViewerModes(scrollMode, spreadMode); |
| 2477 | if (this.initialBookmark) { |
| 2478 | setRotation(this.initialRotation); |
| 2479 | delete this.initialRotation; |
| 2480 | this.pdfLinkService.setHash(this.initialBookmark); |
| 2481 | this.initialBookmark = null; |
| 2482 | } else if (storedHash) { |
| 2483 | setRotation(rotation); |
| 2484 | this.pdfLinkService.setHash(storedHash); |
| 2485 | } |
| 2486 | this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel); |
| 2487 | this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber); |
| 2488 | if (!this.pdfViewer.currentScaleValue) { |
| 2489 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE; |
| 2490 | } |
| 2491 | }, |
| 2492 | _cleanup() { |
| 2493 | if (!this.pdfDocument) { |
| 2494 | return; |
| 2495 | } |
| 2496 | this.pdfViewer.cleanup(); |
| 2497 | this.pdfThumbnailViewer?.cleanup(); |
| 2498 | this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG); |
| 2499 | }, |
| 2500 | forceRendering() { |
| 2501 | this.pdfRenderingQueue.printing = !!this.printService; |
| 2502 | this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS; |
| 2503 | this.pdfRenderingQueue.renderHighestPriority(); |
| 2504 | }, |
| 2505 | beforePrint() { |
| 2506 | |
| 2507 | if (location.hash) { |
| 2508 | let hash = location.hash; |
| 2509 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 2510 | if(hashParams.get('key') !== null) { |
| 2511 | hashParams = '#' + atob(hashParams.get('key')); |
| 2512 | hashParams = new URLSearchParams(hashParams.substring(1)); |
| 2513 | } |
| 2514 | const element = document.querySelector('#download'); |
| 2515 | |
| 2516 | if((hashParams.get('download') === 'false' || hashParams.get('download') === '') || element.offsetParent === null){ |
| 2517 | return false; |
| 2518 | } |
| 2519 | } // added by EP developer |
| 2520 | |
| 2521 | this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => { |
| 2522 | return this.pdfDocument?.annotationStorage.print; |
| 2523 | }); |
| 2524 | if (this.printService) { |
| 2525 | return; |
| 2526 | } |
| 2527 | if (!this.supportsPrinting) { |
| 2528 | this.l10n.get("printing_not_supported").then(msg => { |
| 2529 | this._otherError(msg); |
| 2530 | }); |
| 2531 | return; |
| 2532 | } |
| 2533 | if (!this.pdfViewer.pageViewsReady) { |
| 2534 | this.l10n.get("printing_not_ready").then(msg => { |
| 2535 | window.alert(msg); |
| 2536 | }); |
| 2537 | return; |
| 2538 | } |
| 2539 | const pagesOverview = this.pdfViewer.getPagesOverview(); |
| 2540 | const printContainer = this.appConfig.printContainer; |
| 2541 | const printResolution = _app_options.AppOptions.get("printResolution"); |
| 2542 | const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise; |
| 2543 | const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n); |
| 2544 | this.printService = printService; |
| 2545 | this.forceRendering(); |
| 2546 | this.setTitle(); |
| 2547 | printService.layout(); |
| 2548 | if (this._hasAnnotationEditors) { |
| 2549 | this.externalServices.reportTelemetry({ |
| 2550 | type: "editing", |
| 2551 | data: { |
| 2552 | type: "print" |
| 2553 | } |
| 2554 | }); |
| 2555 | } |
| 2556 | }, |
| 2557 | afterPrint() { |
| 2558 | |
| 2559 | if (location.hash) { |
| 2560 | let hash = location.hash; |
| 2561 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 2562 | |
| 2563 | if(hashParams.get('key') !== null) { |
| 2564 | hashParams = '#' + atob(hashParams.get('key')); |
| 2565 | hashParams = new URLSearchParams(hashParams.substring(1)); |
| 2566 | } |
| 2567 | |
| 2568 | if(hashParams.get('download') === 'false' || hashParams.get('download') === ''){ |
| 2569 | return false; |
| 2570 | } |
| 2571 | } // added by EP developer |
| 2572 | |
| 2573 | if (this._printAnnotationStoragePromise) { |
| 2574 | this._printAnnotationStoragePromise.then(() => { |
| 2575 | this.pdfScriptingManager.dispatchDidPrint(); |
| 2576 | }); |
| 2577 | this._printAnnotationStoragePromise = null; |
| 2578 | } |
| 2579 | if (this.printService) { |
| 2580 | this.printService.destroy(); |
| 2581 | this.printService = null; |
| 2582 | this.pdfDocument?.annotationStorage.resetModified(); |
| 2583 | } |
| 2584 | this.forceRendering(); |
| 2585 | this.setTitle(); |
| 2586 | }, |
| 2587 | rotatePages(delta) { |
| 2588 | this.pdfViewer.pagesRotation += delta; |
| 2589 | }, |
| 2590 | requestPresentationMode() { |
| 2591 | this.pdfPresentationMode?.request(); |
| 2592 | }, |
| 2593 | triggerPrinting() { |
| 2594 | if (!this.supportsPrinting) { |
| 2595 | return; |
| 2596 | } |
| 2597 | window.print(); |
| 2598 | }, |
| 2599 | bindEvents() { |
| 2600 | const { |
| 2601 | eventBus, |
| 2602 | _boundEvents |
| 2603 | } = this; |
| 2604 | _boundEvents.beforePrint = this.beforePrint.bind(this); |
| 2605 | _boundEvents.afterPrint = this.afterPrint.bind(this); |
| 2606 | eventBus._on("resize", webViewerResize); |
| 2607 | eventBus._on("hashchange", webViewerHashchange); |
| 2608 | eventBus._on("beforeprint", _boundEvents.beforePrint); |
| 2609 | eventBus._on("afterprint", _boundEvents.afterPrint); |
| 2610 | eventBus._on("pagerender", webViewerPageRender); |
| 2611 | eventBus._on("pagerendered", webViewerPageRendered); |
| 2612 | eventBus._on("updateviewarea", webViewerUpdateViewarea); |
| 2613 | eventBus._on("pagechanging", webViewerPageChanging); |
| 2614 | eventBus._on("scalechanging", webViewerScaleChanging); |
| 2615 | eventBus._on("rotationchanging", webViewerRotationChanging); |
| 2616 | eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged); |
| 2617 | eventBus._on("pagemode", webViewerPageMode); |
| 2618 | eventBus._on("namedaction", webViewerNamedAction); |
| 2619 | eventBus._on("presentationmodechanged", webViewerPresentationModeChanged); |
| 2620 | eventBus._on("presentationmode", webViewerPresentationMode); |
| 2621 | eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode); |
| 2622 | eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams); |
| 2623 | eventBus._on("print", webViewerPrint); |
| 2624 | eventBus._on("download", webViewerDownload); |
| 2625 | eventBus._on("firstpage", webViewerFirstPage); |
| 2626 | eventBus._on("lastpage", webViewerLastPage); |
| 2627 | eventBus._on("nextpage", webViewerNextPage); |
| 2628 | eventBus._on("previouspage", webViewerPreviousPage); |
| 2629 | eventBus._on("zoomin", webViewerZoomIn); |
| 2630 | eventBus._on("zoomout", webViewerZoomOut); |
| 2631 | eventBus._on("zoomreset", webViewerZoomReset); |
| 2632 | eventBus._on("pagenumberchanged", webViewerPageNumberChanged); |
| 2633 | eventBus._on("scalechanged", webViewerScaleChanged); |
| 2634 | eventBus._on("rotatecw", webViewerRotateCw); |
| 2635 | eventBus._on("rotateccw", webViewerRotateCcw); |
| 2636 | eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig); |
| 2637 | eventBus._on("switchscrollmode", webViewerSwitchScrollMode); |
| 2638 | eventBus._on("scrollmodechanged", webViewerScrollModeChanged); |
| 2639 | eventBus._on("switchspreadmode", webViewerSwitchSpreadMode); |
| 2640 | eventBus._on("spreadmodechanged", webViewerSpreadModeChanged); |
| 2641 | eventBus._on("documentproperties", webViewerDocumentProperties); |
| 2642 | eventBus._on("findfromurlhash", webViewerFindFromUrlHash); |
| 2643 | eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount); |
| 2644 | eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState); |
| 2645 | if (_app_options.AppOptions.get("pdfBug")) { |
| 2646 | _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug; |
| 2647 | eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug); |
| 2648 | eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug); |
| 2649 | } |
| 2650 | eventBus._on("fileinputchange", webViewerFileInputChange); |
| 2651 | eventBus._on("openfile", webViewerOpenFile); |
| 2652 | }, |
| 2653 | bindWindowEvents() { |
| 2654 | const { |
| 2655 | eventBus, |
| 2656 | _boundEvents |
| 2657 | } = this; |
| 2658 | function addWindowResolutionChange(evt = null) { |
| 2659 | if (evt) { |
| 2660 | webViewerResolutionChange(evt); |
| 2661 | } |
| 2662 | const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`); |
| 2663 | mediaQueryList.addEventListener("change", addWindowResolutionChange, { |
| 2664 | once: true |
| 2665 | }); |
| 2666 | _boundEvents.removeWindowResolutionChange ||= function () { |
| 2667 | mediaQueryList.removeEventListener("change", addWindowResolutionChange); |
| 2668 | _boundEvents.removeWindowResolutionChange = null; |
| 2669 | }; |
| 2670 | } |
| 2671 | addWindowResolutionChange(); |
| 2672 | _boundEvents.windowResize = () => { |
| 2673 | eventBus.dispatch("resize", { |
| 2674 | source: window |
| 2675 | }); |
| 2676 | }; |
| 2677 | _boundEvents.windowHashChange = () => { |
| 2678 | eventBus.dispatch("hashchange", { |
| 2679 | source: window, |
| 2680 | hash: document.location.hash.substring(1) |
| 2681 | }); |
| 2682 | }; |
| 2683 | _boundEvents.windowBeforePrint = () => { |
| 2684 | eventBus.dispatch("beforeprint", { |
| 2685 | source: window |
| 2686 | }); |
| 2687 | }; |
| 2688 | _boundEvents.windowAfterPrint = () => { |
| 2689 | eventBus.dispatch("afterprint", { |
| 2690 | source: window |
| 2691 | }); |
| 2692 | }; |
| 2693 | _boundEvents.windowUpdateFromSandbox = event => { |
| 2694 | eventBus.dispatch("updatefromsandbox", { |
| 2695 | source: window, |
| 2696 | detail: event.detail |
| 2697 | }); |
| 2698 | }; |
| 2699 | window.addEventListener("visibilitychange", webViewerVisibilityChange); |
| 2700 | window.addEventListener("wheel", webViewerWheel, { |
| 2701 | passive: false |
| 2702 | }); |
| 2703 | window.addEventListener("touchstart", webViewerTouchStart, { |
| 2704 | passive: false |
| 2705 | }); |
| 2706 | window.addEventListener("touchmove", webViewerTouchMove, { |
| 2707 | passive: false |
| 2708 | }); |
| 2709 | window.addEventListener("touchend", webViewerTouchEnd, { |
| 2710 | passive: false |
| 2711 | }); |
| 2712 | window.addEventListener("click", webViewerClick); |
| 2713 | window.addEventListener("keydown", webViewerKeyDown); |
| 2714 | window.addEventListener("keyup", webViewerKeyUp); |
| 2715 | window.addEventListener("resize", _boundEvents.windowResize); |
| 2716 | window.addEventListener("hashchange", _boundEvents.windowHashChange); |
| 2717 | window.addEventListener("beforeprint", _boundEvents.windowBeforePrint); |
| 2718 | window.addEventListener("afterprint", _boundEvents.windowAfterPrint); |
| 2719 | window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); |
| 2720 | }, |
| 2721 | unbindEvents() { |
| 2722 | const { |
| 2723 | eventBus, |
| 2724 | _boundEvents |
| 2725 | } = this; |
| 2726 | eventBus._off("resize", webViewerResize); |
| 2727 | eventBus._off("hashchange", webViewerHashchange); |
| 2728 | eventBus._off("beforeprint", _boundEvents.beforePrint); |
| 2729 | eventBus._off("afterprint", _boundEvents.afterPrint); |
| 2730 | eventBus._off("pagerender", webViewerPageRender); |
| 2731 | eventBus._off("pagerendered", webViewerPageRendered); |
| 2732 | eventBus._off("updateviewarea", webViewerUpdateViewarea); |
| 2733 | eventBus._off("pagechanging", webViewerPageChanging); |
| 2734 | eventBus._off("scalechanging", webViewerScaleChanging); |
| 2735 | eventBus._off("rotationchanging", webViewerRotationChanging); |
| 2736 | eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged); |
| 2737 | eventBus._off("pagemode", webViewerPageMode); |
| 2738 | eventBus._off("namedaction", webViewerNamedAction); |
| 2739 | eventBus._off("presentationmodechanged", webViewerPresentationModeChanged); |
| 2740 | eventBus._off("presentationmode", webViewerPresentationMode); |
| 2741 | eventBus._off("print", webViewerPrint); |
| 2742 | eventBus._off("download", webViewerDownload); |
| 2743 | eventBus._off("firstpage", webViewerFirstPage); |
| 2744 | eventBus._off("lastpage", webViewerLastPage); |
| 2745 | eventBus._off("nextpage", webViewerNextPage); |
| 2746 | eventBus._off("previouspage", webViewerPreviousPage); |
| 2747 | eventBus._off("zoomin", webViewerZoomIn); |
| 2748 | eventBus._off("zoomout", webViewerZoomOut); |
| 2749 | eventBus._off("zoomreset", webViewerZoomReset); |
| 2750 | eventBus._off("pagenumberchanged", webViewerPageNumberChanged); |
| 2751 | eventBus._off("scalechanged", webViewerScaleChanged); |
| 2752 | eventBus._off("rotatecw", webViewerRotateCw); |
| 2753 | eventBus._off("rotateccw", webViewerRotateCcw); |
| 2754 | eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig); |
| 2755 | eventBus._off("switchscrollmode", webViewerSwitchScrollMode); |
| 2756 | eventBus._off("scrollmodechanged", webViewerScrollModeChanged); |
| 2757 | eventBus._off("switchspreadmode", webViewerSwitchSpreadMode); |
| 2758 | eventBus._off("spreadmodechanged", webViewerSpreadModeChanged); |
| 2759 | eventBus._off("documentproperties", webViewerDocumentProperties); |
| 2760 | eventBus._off("findfromurlhash", webViewerFindFromUrlHash); |
| 2761 | eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount); |
| 2762 | eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState); |
| 2763 | if (_boundEvents.reportPageStatsPDFBug) { |
| 2764 | eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug); |
| 2765 | eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug); |
| 2766 | _boundEvents.reportPageStatsPDFBug = null; |
| 2767 | } |
| 2768 | eventBus._off("fileinputchange", webViewerFileInputChange); |
| 2769 | eventBus._off("openfile", webViewerOpenFile); |
| 2770 | _boundEvents.beforePrint = null; |
| 2771 | _boundEvents.afterPrint = null; |
| 2772 | }, |
| 2773 | unbindWindowEvents() { |
| 2774 | const { |
| 2775 | _boundEvents |
| 2776 | } = this; |
| 2777 | window.removeEventListener("visibilitychange", webViewerVisibilityChange); |
| 2778 | window.removeEventListener("wheel", webViewerWheel, { |
| 2779 | passive: false |
| 2780 | }); |
| 2781 | window.removeEventListener("touchstart", webViewerTouchStart, { |
| 2782 | passive: false |
| 2783 | }); |
| 2784 | window.removeEventListener("touchmove", webViewerTouchMove, { |
| 2785 | passive: false |
| 2786 | }); |
| 2787 | window.removeEventListener("touchend", webViewerTouchEnd, { |
| 2788 | passive: false |
| 2789 | }); |
| 2790 | window.removeEventListener("click", webViewerClick); |
| 2791 | window.removeEventListener("keydown", webViewerKeyDown); |
| 2792 | window.removeEventListener("keyup", webViewerKeyUp); |
| 2793 | window.removeEventListener("resize", _boundEvents.windowResize); |
| 2794 | window.removeEventListener("hashchange", _boundEvents.windowHashChange); |
| 2795 | window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint); |
| 2796 | window.removeEventListener("afterprint", _boundEvents.windowAfterPrint); |
| 2797 | window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); |
| 2798 | _boundEvents.removeWindowResolutionChange?.(); |
| 2799 | _boundEvents.windowResize = null; |
| 2800 | _boundEvents.windowHashChange = null; |
| 2801 | _boundEvents.windowBeforePrint = null; |
| 2802 | _boundEvents.windowAfterPrint = null; |
| 2803 | _boundEvents.windowUpdateFromSandbox = null; |
| 2804 | }, |
| 2805 | _accumulateTicks(ticks, prop) { |
| 2806 | if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) { |
| 2807 | this[prop] = 0; |
| 2808 | } |
| 2809 | this[prop] += ticks; |
| 2810 | const wholeTicks = Math.trunc(this[prop]); |
| 2811 | this[prop] -= wholeTicks; |
| 2812 | return wholeTicks; |
| 2813 | }, |
| 2814 | _accumulateFactor(previousScale, factor, prop) { |
| 2815 | if (factor === 1) { |
| 2816 | return 1; |
| 2817 | } |
| 2818 | if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) { |
| 2819 | this[prop] = 1; |
| 2820 | } |
| 2821 | const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale); |
| 2822 | this[prop] = factor / newFactor; |
| 2823 | return newFactor; |
| 2824 | }, |
| 2825 | _centerAtPos(previousScale, x, y) { |
| 2826 | const { |
| 2827 | pdfViewer |
| 2828 | } = this; |
| 2829 | const scaleDiff = pdfViewer.currentScale / previousScale - 1; |
| 2830 | if (scaleDiff !== 0) { |
| 2831 | const [top, left] = pdfViewer.containerTopLeft; |
| 2832 | pdfViewer.container.scrollLeft += (x - left) * scaleDiff; |
| 2833 | pdfViewer.container.scrollTop += (y - top) * scaleDiff; |
| 2834 | } |
| 2835 | }, |
| 2836 | _unblockDocumentLoadEvent() { |
| 2837 | document.blockUnblockOnload?.(false); |
| 2838 | this._unblockDocumentLoadEvent = () => {}; |
| 2839 | }, |
| 2840 | get scriptingReady() { |
| 2841 | return this.pdfScriptingManager.ready; |
| 2842 | } |
| 2843 | }; |
| 2844 | exports.PDFViewerApplication = PDFViewerApplication; |
| 2845 | { |
| 2846 | const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"]; |
| 2847 | var validateFileURL = function (file) { |
| 2848 | if (!file) { |
| 2849 | return; |
| 2850 | } |
| 2851 | try { |
| 2852 | const viewerOrigin = new URL(window.location.href).origin || "null"; |
| 2853 | if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) { |
| 2854 | return; |
| 2855 | } |
| 2856 | const fileOrigin = new URL(file, window.location.href).origin; |
| 2857 | if (fileOrigin !== viewerOrigin) { |
| 2858 | throw new Error("file origin does not match viewer's"); |
| 2859 | } |
| 2860 | } catch (ex) { |
| 2861 | PDFViewerApplication.l10n.get("loading_error").then(msg => { |
| 2862 | PDFViewerApplication._documentError(msg, { |
| 2863 | message: ex?.message |
| 2864 | }); |
| 2865 | }); |
| 2866 | throw ex; |
| 2867 | } |
| 2868 | }; |
| 2869 | } |
| 2870 | async function loadFakeWorker() { |
| 2871 | _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc"); |
| 2872 | await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc); |
| 2873 | } |
| 2874 | async function loadPDFBug(self) { |
| 2875 | const { |
| 2876 | debuggerScriptPath |
| 2877 | } = self.appConfig; |
| 2878 | const { |
| 2879 | PDFBug |
| 2880 | } = await import(debuggerScriptPath); |
| 2881 | self._PDFBug = PDFBug; |
| 2882 | } |
| 2883 | function reportPageStatsPDFBug({ |
| 2884 | pageNumber |
| 2885 | }) { |
| 2886 | if (!globalThis.Stats?.enabled) { |
| 2887 | return; |
| 2888 | } |
| 2889 | const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1); |
| 2890 | globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats); |
| 2891 | } |
| 2892 | function webViewerInitialized() { |
| 2893 | const { |
| 2894 | appConfig, |
| 2895 | eventBus |
| 2896 | } = PDFViewerApplication; |
| 2897 | let file; |
| 2898 | const queryString = document.location.search.substring(1); |
| 2899 | const params = (0, _ui_utils.parseQueryString)(queryString); |
| 2900 | file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl"); |
| 2901 | validateFileURL(file); |
| 2902 | const fileInput = appConfig.openFileInput; |
| 2903 | fileInput.value = null; |
| 2904 | fileInput.addEventListener("change", function (evt) { |
| 2905 | const { |
| 2906 | files |
| 2907 | } = evt.target; |
| 2908 | if (!files || files.length === 0) { |
| 2909 | return; |
| 2910 | } |
| 2911 | eventBus.dispatch("fileinputchange", { |
| 2912 | source: this, |
| 2913 | fileInput: evt.target |
| 2914 | }); |
| 2915 | }); |
| 2916 | appConfig.mainContainer.addEventListener("dragover", function (evt) { |
| 2917 | evt.preventDefault(); |
| 2918 | evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move"; |
| 2919 | }); |
| 2920 | appConfig.mainContainer.addEventListener("drop", function (evt) { |
| 2921 | evt.preventDefault(); |
| 2922 | const { |
| 2923 | files |
| 2924 | } = evt.dataTransfer; |
| 2925 | if (!files || files.length === 0) { |
| 2926 | return; |
| 2927 | } |
| 2928 | eventBus.dispatch("fileinputchange", { |
| 2929 | source: this, |
| 2930 | fileInput: evt.dataTransfer |
| 2931 | }); |
| 2932 | }); |
| 2933 | if (!PDFViewerApplication.supportsDocumentFonts) { |
| 2934 | _app_options.AppOptions.set("disableFontFace", true); |
| 2935 | PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => { |
| 2936 | console.warn(msg); |
| 2937 | }); |
| 2938 | } |
| 2939 | if (!PDFViewerApplication.supportsPrinting) { |
| 2940 | appConfig.toolbar?.print.classList.add("hidden"); |
| 2941 | appConfig.secondaryToolbar?.printButton.classList.add("hidden"); |
| 2942 | } |
| 2943 | if (!PDFViewerApplication.supportsFullscreen) { |
| 2944 | appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden"); |
| 2945 | } |
| 2946 | if (PDFViewerApplication.supportsIntegratedFind) { |
| 2947 | appConfig.toolbar?.viewFind.classList.add("hidden"); |
| 2948 | } |
| 2949 | appConfig.mainContainer.addEventListener("transitionend", function (evt) { |
| 2950 | if (evt.target === this) { |
| 2951 | eventBus.dispatch("resize", { |
| 2952 | source: this |
| 2953 | }); |
| 2954 | } |
| 2955 | }, true); |
| 2956 | try { |
| 2957 | if (file) { |
| 2958 | PDFViewerApplication.open({ |
| 2959 | url: file |
| 2960 | }); |
| 2961 | } else { |
| 2962 | PDFViewerApplication._hideViewBookmark(); |
| 2963 | } |
| 2964 | } catch (reason) { |
| 2965 | PDFViewerApplication.l10n.get("loading_error").then(msg => { |
| 2966 | PDFViewerApplication._documentError(msg, reason); |
| 2967 | }); |
| 2968 | } |
| 2969 | } |
| 2970 | function webViewerPageRender({ |
| 2971 | pageNumber |
| 2972 | }) { |
| 2973 | if (pageNumber === PDFViewerApplication.page) { |
| 2974 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true); |
| 2975 | } |
| 2976 | } |
| 2977 | function webViewerPageRendered({ |
| 2978 | pageNumber, |
| 2979 | error |
| 2980 | }) { |
| 2981 | if (pageNumber === PDFViewerApplication.page) { |
| 2982 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false); |
| 2983 | } |
| 2984 | if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) { |
| 2985 | const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1); |
| 2986 | const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1); |
| 2987 | if (pageView && thumbnailView) { |
| 2988 | thumbnailView.setImage(pageView); |
| 2989 | } |
| 2990 | } |
| 2991 | if (error) { |
| 2992 | PDFViewerApplication.l10n.get("rendering_error").then(msg => { |
| 2993 | PDFViewerApplication._otherError(msg, error); |
| 2994 | }); |
| 2995 | } |
| 2996 | } |
| 2997 | function webViewerPageMode({ |
| 2998 | mode |
| 2999 | }) { |
| 3000 | let view; |
| 3001 | switch (mode) { |
| 3002 | case "thumbs": |
| 3003 | view = _ui_utils.SidebarView.THUMBS; |
| 3004 | break; |
| 3005 | case "bookmarks": |
| 3006 | case "outline": |
| 3007 | view = _ui_utils.SidebarView.OUTLINE; |
| 3008 | break; |
| 3009 | case "attachments": |
| 3010 | view = _ui_utils.SidebarView.ATTACHMENTS; |
| 3011 | break; |
| 3012 | case "layers": |
| 3013 | view = _ui_utils.SidebarView.LAYERS; |
| 3014 | break; |
| 3015 | case "none": |
| 3016 | view = _ui_utils.SidebarView.NONE; |
| 3017 | break; |
| 3018 | default: |
| 3019 | console.error('Invalid "pagemode" hash parameter: ' + mode); |
| 3020 | return; |
| 3021 | } |
| 3022 | PDFViewerApplication.pdfSidebar?.switchView(view, true); |
| 3023 | } |
| 3024 | function webViewerNamedAction(evt) { |
| 3025 | switch (evt.action) { |
| 3026 | case "GoToPage": |
| 3027 | PDFViewerApplication.appConfig.toolbar?.pageNumber.select(); |
| 3028 | break; |
| 3029 | case "Find": |
| 3030 | if (!PDFViewerApplication.supportsIntegratedFind) { |
| 3031 | PDFViewerApplication?.findBar.toggle(); |
| 3032 | } |
| 3033 | break; |
| 3034 | case "Print": |
| 3035 | PDFViewerApplication.triggerPrinting(); |
| 3036 | break; |
| 3037 | case "SaveAs": |
| 3038 | PDFViewerApplication.downloadOrSave(); |
| 3039 | break; |
| 3040 | } |
| 3041 | } |
| 3042 | function webViewerPresentationModeChanged(evt) { |
| 3043 | PDFViewerApplication.pdfViewer.presentationModeState = evt.state; |
| 3044 | } |
| 3045 | function webViewerSidebarViewChanged({ |
| 3046 | view |
| 3047 | }) { |
| 3048 | PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS; |
| 3049 | if (PDFViewerApplication.isInitialViewSet) { |
| 3050 | PDFViewerApplication.store?.set("sidebarView", view).catch(() => {}); |
| 3051 | } |
| 3052 | } |
| 3053 | function webViewerUpdateViewarea({ |
| 3054 | location |
| 3055 | }) { |
| 3056 | if (PDFViewerApplication.isInitialViewSet) { |
| 3057 | PDFViewerApplication.store?.setMultiple({ |
| 3058 | page: location.pageNumber, |
| 3059 | zoom: location.scale, |
| 3060 | scrollLeft: location.left, |
| 3061 | scrollTop: location.top, |
| 3062 | rotation: location.rotation |
| 3063 | }).catch(() => {}); |
| 3064 | } |
| 3065 | if (PDFViewerApplication.appConfig.secondaryToolbar) { |
| 3066 | const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams); |
| 3067 | PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href; |
| 3068 | } |
| 3069 | } |
| 3070 | function webViewerScrollModeChanged(evt) { |
| 3071 | if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) { |
| 3072 | PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {}); |
| 3073 | } |
| 3074 | } |
| 3075 | function webViewerSpreadModeChanged(evt) { |
| 3076 | if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) { |
| 3077 | PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {}); |
| 3078 | } |
| 3079 | } |
| 3080 | function webViewerResize() { |
| 3081 | const { |
| 3082 | pdfDocument, |
| 3083 | pdfViewer, |
| 3084 | pdfRenderingQueue |
| 3085 | } = PDFViewerApplication; |
| 3086 | if (pdfRenderingQueue.printing && window.matchMedia("print").matches) { |
| 3087 | return; |
| 3088 | } |
| 3089 | if (!pdfDocument) { |
| 3090 | return; |
| 3091 | } |
| 3092 | const currentScaleValue = pdfViewer.currentScaleValue; |
| 3093 | if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") { |
| 3094 | pdfViewer.currentScaleValue = currentScaleValue; |
| 3095 | } |
| 3096 | pdfViewer.update(); |
| 3097 | } |
| 3098 | function webViewerHashchange(evt) { |
| 3099 | const hash = evt.hash; |
| 3100 | if (!hash) { |
| 3101 | return; |
| 3102 | } |
| 3103 | if (!PDFViewerApplication.isInitialViewSet) { |
| 3104 | PDFViewerApplication.initialBookmark = hash; |
| 3105 | } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) { |
| 3106 | PDFViewerApplication.pdfLinkService.setHash(hash); |
| 3107 | } |
| 3108 | } |
| 3109 | { |
| 3110 | var webViewerFileInputChange = function (evt) { |
| 3111 | if (PDFViewerApplication.pdfViewer?.isInPresentationMode) { |
| 3112 | return; |
| 3113 | } |
| 3114 | const file = evt.fileInput.files[0]; |
| 3115 | PDFViewerApplication.open({ |
| 3116 | url: URL.createObjectURL(file), |
| 3117 | originalUrl: file.name |
| 3118 | }); |
| 3119 | }; |
| 3120 | var webViewerOpenFile = function (evt) { |
| 3121 | const fileInput = PDFViewerApplication.appConfig.openFileInput; |
| 3122 | fileInput.click(); |
| 3123 | }; |
| 3124 | } |
| 3125 | function webViewerPresentationMode() { |
| 3126 | PDFViewerApplication.requestPresentationMode(); |
| 3127 | } |
| 3128 | function webViewerSwitchAnnotationEditorMode(evt) { |
| 3129 | PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode; |
| 3130 | } |
| 3131 | function webViewerSwitchAnnotationEditorParams(evt) { |
| 3132 | PDFViewerApplication.pdfViewer.annotationEditorParams = evt; |
| 3133 | } |
| 3134 | function webViewerPrint() { |
| 3135 | PDFViewerApplication.triggerPrinting(); |
| 3136 | } |
| 3137 | function webViewerDownload() { |
| 3138 | PDFViewerApplication.downloadOrSave(); |
| 3139 | } |
| 3140 | function webViewerFirstPage() { |
| 3141 | if (PDFViewerApplication.pdfDocument) { |
| 3142 | PDFViewerApplication.page = 1; |
| 3143 | } |
| 3144 | } |
| 3145 | function webViewerLastPage() { |
| 3146 | if (PDFViewerApplication.pdfDocument) { |
| 3147 | PDFViewerApplication.page = PDFViewerApplication.pagesCount; |
| 3148 | } |
| 3149 | } |
| 3150 | function webViewerNextPage() { |
| 3151 | PDFViewerApplication.pdfViewer.nextPage(); |
| 3152 | } |
| 3153 | function webViewerPreviousPage() { |
| 3154 | PDFViewerApplication.pdfViewer.previousPage(); |
| 3155 | } |
| 3156 | function webViewerZoomIn() { |
| 3157 | PDFViewerApplication.zoomIn(); |
| 3158 | } |
| 3159 | function webViewerZoomOut() { |
| 3160 | PDFViewerApplication.zoomOut(); |
| 3161 | } |
| 3162 | function webViewerZoomReset() { |
| 3163 | PDFViewerApplication.zoomReset(); |
| 3164 | } |
| 3165 | function webViewerPageNumberChanged(evt) { |
| 3166 | const pdfViewer = PDFViewerApplication.pdfViewer; |
| 3167 | if (evt.value !== "") { |
| 3168 | PDFViewerApplication.pdfLinkService.goToPage(evt.value); |
| 3169 | } |
| 3170 | if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) { |
| 3171 | PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); |
| 3172 | } |
| 3173 | } |
| 3174 | function webViewerScaleChanged(evt) { |
| 3175 | PDFViewerApplication.pdfViewer.currentScaleValue = evt.value; |
| 3176 | } |
| 3177 | function webViewerRotateCw() { |
| 3178 | PDFViewerApplication.rotatePages(90); |
| 3179 | } |
| 3180 | function webViewerRotateCcw() { |
| 3181 | PDFViewerApplication.rotatePages(-90); |
| 3182 | } |
| 3183 | function webViewerOptionalContentConfig(evt) { |
| 3184 | PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise; |
| 3185 | } |
| 3186 | function webViewerSwitchScrollMode(evt) { |
| 3187 | PDFViewerApplication.pdfViewer.scrollMode = evt.mode; |
| 3188 | } |
| 3189 | function webViewerSwitchSpreadMode(evt) { |
| 3190 | PDFViewerApplication.pdfViewer.spreadMode = evt.mode; |
| 3191 | } |
| 3192 | function webViewerDocumentProperties() { |
| 3193 | PDFViewerApplication.pdfDocumentProperties?.open(); |
| 3194 | } |
| 3195 | function webViewerFindFromUrlHash(evt) { |
| 3196 | PDFViewerApplication.eventBus.dispatch("find", { |
| 3197 | source: evt.source, |
| 3198 | type: "", |
| 3199 | query: evt.query, |
| 3200 | phraseSearch: evt.phraseSearch, |
| 3201 | caseSensitive: false, |
| 3202 | entireWord: false, |
| 3203 | highlightAll: true, |
| 3204 | findPrevious: false, |
| 3205 | matchDiacritics: true |
| 3206 | }); |
| 3207 | } |
| 3208 | function webViewerUpdateFindMatchesCount({ |
| 3209 | matchesCount |
| 3210 | }) { |
| 3211 | if (PDFViewerApplication.supportsIntegratedFind) { |
| 3212 | PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount); |
| 3213 | } else { |
| 3214 | PDFViewerApplication.findBar.updateResultsCount(matchesCount); |
| 3215 | } |
| 3216 | } |
| 3217 | function webViewerUpdateFindControlState({ |
| 3218 | state, |
| 3219 | previous, |
| 3220 | matchesCount, |
| 3221 | rawQuery |
| 3222 | }) { |
| 3223 | if (PDFViewerApplication.supportsIntegratedFind) { |
| 3224 | PDFViewerApplication.externalServices.updateFindControlState({ |
| 3225 | result: state, |
| 3226 | findPrevious: previous, |
| 3227 | matchesCount, |
| 3228 | rawQuery |
| 3229 | }); |
| 3230 | } else { |
| 3231 | PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount); |
| 3232 | } |
| 3233 | } |
| 3234 | function webViewerScaleChanging(evt) { |
| 3235 | PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale); |
| 3236 | PDFViewerApplication.pdfViewer.update(); |
| 3237 | } |
| 3238 | function webViewerRotationChanging(evt) { |
| 3239 | if (PDFViewerApplication.pdfThumbnailViewer) { |
| 3240 | PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation; |
| 3241 | } |
| 3242 | PDFViewerApplication.forceRendering(); |
| 3243 | PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber; |
| 3244 | } |
| 3245 | function webViewerPageChanging({ |
| 3246 | pageNumber, |
| 3247 | pageLabel |
| 3248 | }) { |
| 3249 | PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel); |
| 3250 | PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber); |
| 3251 | if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) { |
| 3252 | PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber); |
| 3253 | } |
| 3254 | const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1); |
| 3255 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING); |
| 3256 | } |
| 3257 | function webViewerResolutionChange(evt) { |
| 3258 | PDFViewerApplication.pdfViewer.refresh(); |
| 3259 | } |
| 3260 | function webViewerVisibilityChange(evt) { |
| 3261 | if (document.visibilityState === "visible") { |
| 3262 | setZoomDisabledTimeout(); |
| 3263 | } |
| 3264 | } |
| 3265 | let zoomDisabledTimeout = null; |
| 3266 | function setZoomDisabledTimeout() { |
| 3267 | if (zoomDisabledTimeout) { |
| 3268 | clearTimeout(zoomDisabledTimeout); |
| 3269 | } |
| 3270 | zoomDisabledTimeout = setTimeout(function () { |
| 3271 | zoomDisabledTimeout = null; |
| 3272 | }, WHEEL_ZOOM_DISABLED_TIMEOUT); |
| 3273 | } |
| 3274 | function webViewerWheel(evt) { |
| 3275 | const { |
| 3276 | pdfViewer, |
| 3277 | supportedMouseWheelZoomModifierKeys, |
| 3278 | supportsPinchToZoom |
| 3279 | } = PDFViewerApplication; |
| 3280 | if (pdfViewer.isInPresentationMode) { |
| 3281 | return; |
| 3282 | } |
| 3283 | const deltaMode = evt.deltaMode; |
| 3284 | let scaleFactor = Math.exp(-evt.deltaY / 100); |
| 3285 | const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && Math.abs(scaleFactor - 1) < 0.05 && evt.deltaZ === 0; |
| 3286 | if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) { |
| 3287 | evt.preventDefault(); |
| 3288 | if (zoomDisabledTimeout || document.visibilityState === "hidden") { |
| 3289 | return; |
| 3290 | } |
| 3291 | const previousScale = pdfViewer.currentScale; |
| 3292 | if (isPinchToZoom && supportsPinchToZoom) { |
| 3293 | scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor"); |
| 3294 | if (scaleFactor < 1) { |
| 3295 | PDFViewerApplication.zoomOut(null, scaleFactor); |
| 3296 | } else if (scaleFactor > 1) { |
| 3297 | PDFViewerApplication.zoomIn(null, scaleFactor); |
| 3298 | } else { |
| 3299 | return; |
| 3300 | } |
| 3301 | } else { |
| 3302 | const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt); |
| 3303 | let ticks = 0; |
| 3304 | if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) { |
| 3305 | if (Math.abs(delta) >= 1) { |
| 3306 | ticks = Math.sign(delta); |
| 3307 | } else { |
| 3308 | ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks"); |
| 3309 | } |
| 3310 | } else { |
| 3311 | const PIXELS_PER_LINE_SCALE = 30; |
| 3312 | ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks"); |
| 3313 | } |
| 3314 | if (ticks < 0) { |
| 3315 | PDFViewerApplication.zoomOut(-ticks); |
| 3316 | } else if (ticks > 0) { |
| 3317 | PDFViewerApplication.zoomIn(ticks); |
| 3318 | } else { |
| 3319 | return; |
| 3320 | } |
| 3321 | } |
| 3322 | PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY); |
| 3323 | } else { |
| 3324 | setZoomDisabledTimeout(); |
| 3325 | } |
| 3326 | } |
| 3327 | function webViewerTouchStart(evt) { |
| 3328 | if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) { |
| 3329 | return; |
| 3330 | } |
| 3331 | evt.preventDefault(); |
| 3332 | if (evt.touches.length !== 2) { |
| 3333 | PDFViewerApplication._touchInfo = null; |
| 3334 | return; |
| 3335 | } |
| 3336 | let [touch0, touch1] = evt.touches; |
| 3337 | if (touch0.identifier > touch1.identifier) { |
| 3338 | [touch0, touch1] = [touch1, touch0]; |
| 3339 | } |
| 3340 | PDFViewerApplication._touchInfo = { |
| 3341 | touch0X: touch0.pageX, |
| 3342 | touch0Y: touch0.pageY, |
| 3343 | touch1X: touch1.pageX, |
| 3344 | touch1Y: touch1.pageY |
| 3345 | }; |
| 3346 | } |
| 3347 | function webViewerTouchMove(evt) { |
| 3348 | if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) { |
| 3349 | return; |
| 3350 | } |
| 3351 | const { |
| 3352 | pdfViewer, |
| 3353 | _touchInfo, |
| 3354 | supportsPinchToZoom |
| 3355 | } = PDFViewerApplication; |
| 3356 | let [touch0, touch1] = evt.touches; |
| 3357 | if (touch0.identifier > touch1.identifier) { |
| 3358 | [touch0, touch1] = [touch1, touch0]; |
| 3359 | } |
| 3360 | const { |
| 3361 | pageX: page0X, |
| 3362 | pageY: page0Y |
| 3363 | } = touch0; |
| 3364 | const { |
| 3365 | pageX: page1X, |
| 3366 | pageY: page1Y |
| 3367 | } = touch1; |
| 3368 | const { |
| 3369 | touch0X: pTouch0X, |
| 3370 | touch0Y: pTouch0Y, |
| 3371 | touch1X: pTouch1X, |
| 3372 | touch1Y: pTouch1Y |
| 3373 | } = _touchInfo; |
| 3374 | if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) { |
| 3375 | return; |
| 3376 | } |
| 3377 | _touchInfo.touch0X = page0X; |
| 3378 | _touchInfo.touch0Y = page0Y; |
| 3379 | _touchInfo.touch1X = page1X; |
| 3380 | _touchInfo.touch1Y = page1Y; |
| 3381 | if (pTouch0X === page0X && pTouch0Y === page0Y) { |
| 3382 | const v1X = pTouch1X - page0X; |
| 3383 | const v1Y = pTouch1Y - page0Y; |
| 3384 | const v2X = page1X - page0X; |
| 3385 | const v2Y = page1Y - page0Y; |
| 3386 | const det = v1X * v2Y - v1Y * v2X; |
| 3387 | if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) { |
| 3388 | return; |
| 3389 | } |
| 3390 | } else if (pTouch1X === page1X && pTouch1Y === page1Y) { |
| 3391 | const v1X = pTouch0X - page1X; |
| 3392 | const v1Y = pTouch0Y - page1Y; |
| 3393 | const v2X = page0X - page1X; |
| 3394 | const v2Y = page0Y - page1Y; |
| 3395 | const det = v1X * v2Y - v1Y * v2X; |
| 3396 | if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) { |
| 3397 | return; |
| 3398 | } |
| 3399 | } else { |
| 3400 | const diff0X = page0X - pTouch0X; |
| 3401 | const diff1X = page1X - pTouch1X; |
| 3402 | const diff0Y = page0Y - pTouch0Y; |
| 3403 | const diff1Y = page1Y - pTouch1Y; |
| 3404 | const dotProduct = diff0X * diff1X + diff0Y * diff1Y; |
| 3405 | if (dotProduct >= 0) { |
| 3406 | return; |
| 3407 | } |
| 3408 | } |
| 3409 | evt.preventDefault(); |
| 3410 | const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1; |
| 3411 | const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1; |
| 3412 | const previousScale = pdfViewer.currentScale; |
| 3413 | if (supportsPinchToZoom) { |
| 3414 | const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor"); |
| 3415 | if (newScaleFactor < 1) { |
| 3416 | PDFViewerApplication.zoomOut(null, newScaleFactor); |
| 3417 | } else if (newScaleFactor > 1) { |
| 3418 | PDFViewerApplication.zoomIn(null, newScaleFactor); |
| 3419 | } else { |
| 3420 | return; |
| 3421 | } |
| 3422 | } else { |
| 3423 | const PIXELS_PER_LINE_SCALE = 30; |
| 3424 | const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks"); |
| 3425 | if (ticks < 0) { |
| 3426 | PDFViewerApplication.zoomOut(-ticks); |
| 3427 | } else if (ticks > 0) { |
| 3428 | PDFViewerApplication.zoomIn(ticks); |
| 3429 | } else { |
| 3430 | return; |
| 3431 | } |
| 3432 | } |
| 3433 | PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2); |
| 3434 | } |
| 3435 | function webViewerTouchEnd(evt) { |
| 3436 | if (!PDFViewerApplication._touchInfo) { |
| 3437 | return; |
| 3438 | } |
| 3439 | evt.preventDefault(); |
| 3440 | PDFViewerApplication._touchInfo = null; |
| 3441 | PDFViewerApplication._touchUnusedTicks = 0; |
| 3442 | PDFViewerApplication._touchUnusedFactor = 1; |
| 3443 | } |
| 3444 | function webViewerClick(evt) { |
| 3445 | if (!PDFViewerApplication.secondaryToolbar?.isOpen) { |
| 3446 | return; |
| 3447 | } |
| 3448 | const appConfig = PDFViewerApplication.appConfig; |
| 3449 | if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) { |
| 3450 | PDFViewerApplication.secondaryToolbar.close(); |
| 3451 | } |
| 3452 | } |
| 3453 | function webViewerKeyUp(evt) { |
| 3454 | if (evt.key === "Control") { |
| 3455 | PDFViewerApplication._isCtrlKeyDown = false; |
| 3456 | } |
| 3457 | } |
| 3458 | function webViewerKeyDown(evt) { |
| 3459 | PDFViewerApplication._isCtrlKeyDown = evt.key === "Control"; |
| 3460 | if (PDFViewerApplication.overlayManager.active) { |
| 3461 | return; |
| 3462 | } |
| 3463 | const { |
| 3464 | eventBus, |
| 3465 | pdfViewer |
| 3466 | } = PDFViewerApplication; |
| 3467 | const isViewerInPresentationMode = pdfViewer.isInPresentationMode; |
| 3468 | let handled = false, |
| 3469 | ensureViewerFocused = false; |
| 3470 | const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0); |
| 3471 | if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) { |
| 3472 | switch (evt.keyCode) { |
| 3473 | case 70: |
| 3474 | if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) { |
| 3475 | PDFViewerApplication.findBar?.open(); |
| 3476 | handled = true; |
| 3477 | } |
| 3478 | break; |
| 3479 | case 71: |
| 3480 | if (!PDFViewerApplication.supportsIntegratedFind) { |
| 3481 | const { |
| 3482 | state |
| 3483 | } = PDFViewerApplication.findController; |
| 3484 | if (state) { |
| 3485 | const eventState = Object.assign(Object.create(null), state, { |
| 3486 | source: window, |
| 3487 | type: "again", |
| 3488 | findPrevious: cmd === 5 || cmd === 12 |
| 3489 | }); |
| 3490 | eventBus.dispatch("find", eventState); |
| 3491 | } |
| 3492 | handled = true; |
| 3493 | } |
| 3494 | break; |
| 3495 | case 61: |
| 3496 | case 107: |
| 3497 | case 187: |
| 3498 | case 171: |
| 3499 | if (!isViewerInPresentationMode) { |
| 3500 | PDFViewerApplication.zoomIn(); |
| 3501 | } |
| 3502 | handled = true; |
| 3503 | break; |
| 3504 | case 173: |
| 3505 | case 109: |
| 3506 | case 189: |
| 3507 | if (!isViewerInPresentationMode) { |
| 3508 | PDFViewerApplication.zoomOut(); |
| 3509 | } |
| 3510 | handled = true; |
| 3511 | break; |
| 3512 | case 48: |
| 3513 | case 96: |
| 3514 | if (!isViewerInPresentationMode) { |
| 3515 | setTimeout(function () { |
| 3516 | PDFViewerApplication.zoomReset(); |
| 3517 | }); |
| 3518 | handled = false; |
| 3519 | } |
| 3520 | break; |
| 3521 | case 38: |
| 3522 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) { |
| 3523 | PDFViewerApplication.page = 1; |
| 3524 | handled = true; |
| 3525 | ensureViewerFocused = true; |
| 3526 | } |
| 3527 | break; |
| 3528 | case 40: |
| 3529 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) { |
| 3530 | PDFViewerApplication.page = PDFViewerApplication.pagesCount; |
| 3531 | handled = true; |
| 3532 | ensureViewerFocused = true; |
| 3533 | } |
| 3534 | break; |
| 3535 | } |
| 3536 | } |
| 3537 | if (cmd === 1 || cmd === 8) { |
| 3538 | switch (evt.keyCode) { |
| 3539 | case 83: |
| 3540 | eventBus.dispatch("download", { |
| 3541 | source: window |
| 3542 | }); |
| 3543 | handled = true; |
| 3544 | break; |
| 3545 | case 79: |
| 3546 | { |
| 3547 | eventBus.dispatch("openfile", { |
| 3548 | source: window |
| 3549 | }); |
| 3550 | handled = true; |
| 3551 | } |
| 3552 | break; |
| 3553 | } |
| 3554 | } |
| 3555 | if (cmd === 3 || cmd === 10) { |
| 3556 | switch (evt.keyCode) { |
| 3557 | case 80: |
| 3558 | PDFViewerApplication.requestPresentationMode(); |
| 3559 | handled = true; |
| 3560 | PDFViewerApplication.externalServices.reportTelemetry({ |
| 3561 | type: "buttons", |
| 3562 | data: { |
| 3563 | id: "presentationModeKeyboard" |
| 3564 | } |
| 3565 | }); |
| 3566 | break; |
| 3567 | case 71: |
| 3568 | if (PDFViewerApplication.appConfig.toolbar) { |
| 3569 | PDFViewerApplication.appConfig.toolbar.pageNumber.select(); |
| 3570 | handled = true; |
| 3571 | } |
| 3572 | break; |
| 3573 | } |
| 3574 | } |
| 3575 | if (handled) { |
| 3576 | if (ensureViewerFocused && !isViewerInPresentationMode) { |
| 3577 | pdfViewer.focus(); |
| 3578 | } |
| 3579 | evt.preventDefault(); |
| 3580 | return; |
| 3581 | } |
| 3582 | const curElement = (0, _ui_utils.getActiveOrFocusedElement)(); |
| 3583 | const curElementTagName = curElement?.tagName.toUpperCase(); |
| 3584 | if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) { |
| 3585 | if (evt.keyCode !== 27) { |
| 3586 | return; |
| 3587 | } |
| 3588 | } |
| 3589 | if (cmd === 0) { |
| 3590 | let turnPage = 0, |
| 3591 | turnOnlyIfPageFit = false; |
| 3592 | switch (evt.keyCode) { |
| 3593 | case 38: |
| 3594 | case 33: |
| 3595 | if (pdfViewer.isVerticalScrollbarEnabled) { |
| 3596 | turnOnlyIfPageFit = true; |
| 3597 | } |
| 3598 | turnPage = -1; |
| 3599 | break; |
| 3600 | case 8: |
| 3601 | if (!isViewerInPresentationMode) { |
| 3602 | turnOnlyIfPageFit = true; |
| 3603 | } |
| 3604 | turnPage = -1; |
| 3605 | break; |
| 3606 | case 37: |
| 3607 | if (pdfViewer.isHorizontalScrollbarEnabled) { |
| 3608 | turnOnlyIfPageFit = true; |
| 3609 | } |
| 3610 | case 75: |
| 3611 | case 80: |
| 3612 | turnPage = -1; |
| 3613 | break; |
| 3614 | case 27: |
| 3615 | if (PDFViewerApplication.secondaryToolbar?.isOpen) { |
| 3616 | PDFViewerApplication.secondaryToolbar.close(); |
| 3617 | handled = true; |
| 3618 | } |
| 3619 | if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) { |
| 3620 | PDFViewerApplication.findBar.close(); |
| 3621 | handled = true; |
| 3622 | } |
| 3623 | break; |
| 3624 | case 40: |
| 3625 | case 34: |
| 3626 | if (pdfViewer.isVerticalScrollbarEnabled) { |
| 3627 | turnOnlyIfPageFit = true; |
| 3628 | } |
| 3629 | turnPage = 1; |
| 3630 | break; |
| 3631 | case 13: |
| 3632 | case 32: |
| 3633 | if (!isViewerInPresentationMode) { |
| 3634 | turnOnlyIfPageFit = true; |
| 3635 | } |
| 3636 | turnPage = 1; |
| 3637 | break; |
| 3638 | case 39: |
| 3639 | if (pdfViewer.isHorizontalScrollbarEnabled) { |
| 3640 | turnOnlyIfPageFit = true; |
| 3641 | } |
| 3642 | case 74: |
| 3643 | case 78: |
| 3644 | turnPage = 1; |
| 3645 | break; |
| 3646 | case 36: |
| 3647 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) { |
| 3648 | PDFViewerApplication.page = 1; |
| 3649 | handled = true; |
| 3650 | ensureViewerFocused = true; |
| 3651 | } |
| 3652 | break; |
| 3653 | case 35: |
| 3654 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) { |
| 3655 | PDFViewerApplication.page = PDFViewerApplication.pagesCount; |
| 3656 | handled = true; |
| 3657 | ensureViewerFocused = true; |
| 3658 | } |
| 3659 | break; |
| 3660 | case 83: |
| 3661 | PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.SELECT); |
| 3662 | break; |
| 3663 | case 72: |
| 3664 | PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.HAND); |
| 3665 | break; |
| 3666 | case 82: |
| 3667 | PDFViewerApplication.rotatePages(90); |
| 3668 | break; |
| 3669 | case 115: |
| 3670 | PDFViewerApplication.pdfSidebar?.toggle(); |
| 3671 | break; |
| 3672 | } |
| 3673 | if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) { |
| 3674 | if (turnPage > 0) { |
| 3675 | pdfViewer.nextPage(); |
| 3676 | } else { |
| 3677 | pdfViewer.previousPage(); |
| 3678 | } |
| 3679 | handled = true; |
| 3680 | } |
| 3681 | } |
| 3682 | if (cmd === 4) { |
| 3683 | switch (evt.keyCode) { |
| 3684 | case 13: |
| 3685 | case 32: |
| 3686 | if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") { |
| 3687 | break; |
| 3688 | } |
| 3689 | pdfViewer.previousPage(); |
| 3690 | handled = true; |
| 3691 | break; |
| 3692 | case 82: |
| 3693 | PDFViewerApplication.rotatePages(-90); |
| 3694 | break; |
| 3695 | } |
| 3696 | } |
| 3697 | if (!handled && !isViewerInPresentationMode) { |
| 3698 | if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") { |
| 3699 | ensureViewerFocused = true; |
| 3700 | } |
| 3701 | } |
| 3702 | if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) { |
| 3703 | pdfViewer.focus(); |
| 3704 | } |
| 3705 | if (handled) { |
| 3706 | evt.preventDefault(); |
| 3707 | } |
| 3708 | } |
| 3709 | function beforeUnload(evt) { |
| 3710 | evt.preventDefault(); |
| 3711 | evt.returnValue = ""; |
| 3712 | return false; |
| 3713 | } |
| 3714 | function webViewerAnnotationEditorStatesChanged(data) { |
| 3715 | PDFViewerApplication.externalServices.updateEditorStates(data); |
| 3716 | } |
| 3717 | const PDFPrintServiceFactory = { |
| 3718 | instance: { |
| 3719 | supportsPrinting: false, |
| 3720 | createPrintService() { |
| 3721 | throw new Error("Not implemented: createPrintService"); |
| 3722 | } |
| 3723 | } |
| 3724 | }; |
| 3725 | exports.PDFPrintServiceFactory = PDFPrintServiceFactory; |
| 3726 | |
| 3727 | /***/ }), |
| 3728 | /* 5 */ |
| 3729 | /***/ ((module) => { |
| 3730 | |
| 3731 | |
| 3732 | |
| 3733 | let pdfjsLib; |
| 3734 | if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) { |
| 3735 | pdfjsLib = window["pdfjs-dist/build/pdf"]; |
| 3736 | } else { |
| 3737 | pdfjsLib = require("../build/script.js"); |
| 3738 | } |
| 3739 | module.exports = pdfjsLib; |
| 3740 | |
| 3741 | /***/ }), |
| 3742 | /* 6 */ |
| 3743 | /***/ ((__unused_webpack_module, exports) => { |
| 3744 | |
| 3745 | |
| 3746 | |
| 3747 | Object.defineProperty(exports, "__esModule", ({ |
| 3748 | value: true |
| 3749 | })); |
| 3750 | exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0; |
| 3751 | exports.waitOnEventOrTimeout = waitOnEventOrTimeout; |
| 3752 | const WaitOnType = { |
| 3753 | EVENT: "event", |
| 3754 | TIMEOUT: "timeout" |
| 3755 | }; |
| 3756 | exports.WaitOnType = WaitOnType; |
| 3757 | function waitOnEventOrTimeout({ |
| 3758 | target, |
| 3759 | name, |
| 3760 | delay = 0 |
| 3761 | }) { |
| 3762 | return new Promise(function (resolve, reject) { |
| 3763 | if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) { |
| 3764 | throw new Error("waitOnEventOrTimeout - invalid parameters."); |
| 3765 | } |
| 3766 | function handler(type) { |
| 3767 | if (target instanceof EventBus) { |
| 3768 | target._off(name, eventHandler); |
| 3769 | } else { |
| 3770 | target.removeEventListener(name, eventHandler); |
| 3771 | } |
| 3772 | if (timeout) { |
| 3773 | clearTimeout(timeout); |
| 3774 | } |
| 3775 | resolve(type); |
| 3776 | } |
| 3777 | const eventHandler = handler.bind(null, WaitOnType.EVENT); |
| 3778 | if (target instanceof EventBus) { |
| 3779 | target._on(name, eventHandler); |
| 3780 | } else { |
| 3781 | target.addEventListener(name, eventHandler); |
| 3782 | } |
| 3783 | const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); |
| 3784 | const timeout = setTimeout(timeoutHandler, delay); |
| 3785 | }); |
| 3786 | } |
| 3787 | class EventBus { |
| 3788 | #listeners = Object.create(null); |
| 3789 | on(eventName, listener, options = null) { |
| 3790 | this._on(eventName, listener, { |
| 3791 | external: true, |
| 3792 | once: options?.once |
| 3793 | }); |
| 3794 | } |
| 3795 | off(eventName, listener, options = null) { |
| 3796 | this._off(eventName, listener, { |
| 3797 | external: true, |
| 3798 | once: options?.once |
| 3799 | }); |
| 3800 | } |
| 3801 | dispatch(eventName, data) { |
| 3802 | const eventListeners = this.#listeners[eventName]; |
| 3803 | if (!eventListeners || eventListeners.length === 0) { |
| 3804 | return; |
| 3805 | } |
| 3806 | let externalListeners; |
| 3807 | for (const { |
| 3808 | listener, |
| 3809 | external, |
| 3810 | once |
| 3811 | } of eventListeners.slice(0)) { |
| 3812 | if (once) { |
| 3813 | this._off(eventName, listener); |
| 3814 | } |
| 3815 | if (external) { |
| 3816 | (externalListeners ||= []).push(listener); |
| 3817 | continue; |
| 3818 | } |
| 3819 | listener(data); |
| 3820 | } |
| 3821 | if (externalListeners) { |
| 3822 | for (const listener of externalListeners) { |
| 3823 | listener(data); |
| 3824 | } |
| 3825 | externalListeners = null; |
| 3826 | } |
| 3827 | } |
| 3828 | _on(eventName, listener, options = null) { |
| 3829 | const eventListeners = this.#listeners[eventName] ||= []; |
| 3830 | eventListeners.push({ |
| 3831 | listener, |
| 3832 | external: options?.external === true, |
| 3833 | once: options?.once === true |
| 3834 | }); |
| 3835 | } |
| 3836 | _off(eventName, listener, options = null) { |
| 3837 | const eventListeners = this.#listeners[eventName]; |
| 3838 | if (!eventListeners) { |
| 3839 | return; |
| 3840 | } |
| 3841 | for (let i = 0, ii = eventListeners.length; i < ii; i++) { |
| 3842 | if (eventListeners[i].listener === listener) { |
| 3843 | eventListeners.splice(i, 1); |
| 3844 | return; |
| 3845 | } |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | exports.EventBus = EventBus; |
| 3850 | class AutomationEventBus extends EventBus { |
| 3851 | dispatch(eventName, data) { |
| 3852 | throw new Error("Not implemented: AutomationEventBus.dispatch"); |
| 3853 | } |
| 3854 | } |
| 3855 | exports.AutomationEventBus = AutomationEventBus; |
| 3856 | |
| 3857 | /***/ }), |
| 3858 | /* 7 */ |
| 3859 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 3860 | |
| 3861 | |
| 3862 | |
| 3863 | Object.defineProperty(exports, "__esModule", ({ |
| 3864 | value: true |
| 3865 | })); |
| 3866 | exports.PDFCursorTools = exports.CursorTool = void 0; |
| 3867 | var _pdfjsLib = __webpack_require__(5); |
| 3868 | var _grab_to_pan = __webpack_require__(8); |
| 3869 | var _ui_utils = __webpack_require__(1); |
| 3870 | const CursorTool = { |
| 3871 | SELECT: 0, |
| 3872 | HAND: 1, |
| 3873 | ZOOM: 2 |
| 3874 | }; |
| 3875 | exports.CursorTool = CursorTool; |
| 3876 | class PDFCursorTools { |
| 3877 | constructor({ |
| 3878 | container, |
| 3879 | eventBus, |
| 3880 | cursorToolOnLoad = CursorTool.SELECT |
| 3881 | }) { |
| 3882 | this.container = container; |
| 3883 | this.eventBus = eventBus; |
| 3884 | this.active = CursorTool.SELECT; |
| 3885 | this.previouslyActive = null; |
| 3886 | this.handTool = new _grab_to_pan.GrabToPan({ |
| 3887 | element: this.container |
| 3888 | }); |
| 3889 | this.#addEventListeners(); |
| 3890 | Promise.resolve().then(() => { |
| 3891 | this.switchTool(cursorToolOnLoad); |
| 3892 | }); |
| 3893 | } |
| 3894 | get activeTool() { |
| 3895 | return this.active; |
| 3896 | } |
| 3897 | switchTool(tool) { |
| 3898 | if (this.previouslyActive !== null) { |
| 3899 | return; |
| 3900 | } |
| 3901 | if (tool === this.active) { |
| 3902 | return; |
| 3903 | } |
| 3904 | const disableActiveTool = () => { |
| 3905 | switch (this.active) { |
| 3906 | case CursorTool.SELECT: |
| 3907 | break; |
| 3908 | case CursorTool.HAND: |
| 3909 | this.handTool.deactivate(); |
| 3910 | break; |
| 3911 | case CursorTool.ZOOM: |
| 3912 | } |
| 3913 | }; |
| 3914 | switch (tool) { |
| 3915 | case CursorTool.SELECT: |
| 3916 | disableActiveTool(); |
| 3917 | break; |
| 3918 | case CursorTool.HAND: |
| 3919 | disableActiveTool(); |
| 3920 | this.handTool.activate(); |
| 3921 | break; |
| 3922 | case CursorTool.ZOOM: |
| 3923 | default: |
| 3924 | console.error(`switchTool: "${tool}" is an unsupported value.`); |
| 3925 | return; |
| 3926 | } |
| 3927 | this.active = tool; |
| 3928 | this.#dispatchEvent(); |
| 3929 | } |
| 3930 | #dispatchEvent() { |
| 3931 | this.eventBus.dispatch("cursortoolchanged", { |
| 3932 | source: this, |
| 3933 | tool: this.active |
| 3934 | }); |
| 3935 | } |
| 3936 | #addEventListeners() { |
| 3937 | this.eventBus._on("switchcursortool", evt => { |
| 3938 | this.switchTool(evt.tool); |
| 3939 | }); |
| 3940 | let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE, |
| 3941 | presentationModeState = _ui_utils.PresentationModeState.NORMAL; |
| 3942 | const disableActive = () => { |
| 3943 | const previouslyActive = this.active; |
| 3944 | this.switchTool(CursorTool.SELECT); |
| 3945 | this.previouslyActive ??= previouslyActive; |
| 3946 | }; |
| 3947 | const enableActive = () => { |
| 3948 | const previouslyActive = this.previouslyActive; |
| 3949 | if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) { |
| 3950 | this.previouslyActive = null; |
| 3951 | this.switchTool(previouslyActive); |
| 3952 | } |
| 3953 | }; |
| 3954 | this.eventBus._on("secondarytoolbarreset", evt => { |
| 3955 | if (this.previouslyActive !== null) { |
| 3956 | annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE; |
| 3957 | presentationModeState = _ui_utils.PresentationModeState.NORMAL; |
| 3958 | enableActive(); |
| 3959 | } |
| 3960 | }); |
| 3961 | this.eventBus._on("annotationeditormodechanged", ({ |
| 3962 | mode |
| 3963 | }) => { |
| 3964 | annotationEditorMode = mode; |
| 3965 | if (mode === _pdfjsLib.AnnotationEditorType.NONE) { |
| 3966 | enableActive(); |
| 3967 | } else { |
| 3968 | disableActive(); |
| 3969 | } |
| 3970 | }); |
| 3971 | this.eventBus._on("presentationmodechanged", ({ |
| 3972 | state |
| 3973 | }) => { |
| 3974 | presentationModeState = state; |
| 3975 | if (state === _ui_utils.PresentationModeState.NORMAL) { |
| 3976 | enableActive(); |
| 3977 | } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) { |
| 3978 | disableActive(); |
| 3979 | } |
| 3980 | }); |
| 3981 | } |
| 3982 | } |
| 3983 | exports.PDFCursorTools = PDFCursorTools; |
| 3984 | |
| 3985 | /***/ }), |
| 3986 | /* 8 */ |
| 3987 | /***/ ((__unused_webpack_module, exports) => { |
| 3988 | |
| 3989 | |
| 3990 | |
| 3991 | Object.defineProperty(exports, "__esModule", ({ |
| 3992 | value: true |
| 3993 | })); |
| 3994 | exports.GrabToPan = void 0; |
| 3995 | const CSS_CLASS_GRAB = "grab-to-pan-grab"; |
| 3996 | class GrabToPan { |
| 3997 | constructor(options) { |
| 3998 | this.element = options.element; |
| 3999 | this.document = options.element.ownerDocument; |
| 4000 | if (typeof options.ignoreTarget === "function") { |
| 4001 | this.ignoreTarget = options.ignoreTarget; |
| 4002 | } |
| 4003 | this.onActiveChanged = options.onActiveChanged; |
| 4004 | this.activate = this.activate.bind(this); |
| 4005 | this.deactivate = this.deactivate.bind(this); |
| 4006 | this.toggle = this.toggle.bind(this); |
| 4007 | this._onMouseDown = this.#onMouseDown.bind(this); |
| 4008 | this._onMouseMove = this.#onMouseMove.bind(this); |
| 4009 | this._endPan = this.#endPan.bind(this); |
| 4010 | const overlay = this.overlay = document.createElement("div"); |
| 4011 | overlay.className = "grab-to-pan-grabbing"; |
| 4012 | } |
| 4013 | activate() { |
| 4014 | if (!this.active) { |
| 4015 | this.active = true; |
| 4016 | this.element.addEventListener("mousedown", this._onMouseDown, true); |
| 4017 | this.element.classList.add(CSS_CLASS_GRAB); |
| 4018 | this.onActiveChanged?.(true); |
| 4019 | } |
| 4020 | } |
| 4021 | deactivate() { |
| 4022 | if (this.active) { |
| 4023 | this.active = false; |
| 4024 | this.element.removeEventListener("mousedown", this._onMouseDown, true); |
| 4025 | this._endPan(); |
| 4026 | this.element.classList.remove(CSS_CLASS_GRAB); |
| 4027 | this.onActiveChanged?.(false); |
| 4028 | } |
| 4029 | } |
| 4030 | toggle() { |
| 4031 | if (this.active) { |
| 4032 | this.deactivate(); |
| 4033 | } else { |
| 4034 | this.activate(); |
| 4035 | } |
| 4036 | } |
| 4037 | ignoreTarget(node) { |
| 4038 | return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option"); |
| 4039 | } |
| 4040 | #onMouseDown(event) { |
| 4041 | if (event.button !== 0 || this.ignoreTarget(event.target)) { |
| 4042 | return; |
| 4043 | } |
| 4044 | if (event.originalTarget) { |
| 4045 | try { |
| 4046 | event.originalTarget.tagName; |
| 4047 | } catch (e) { |
| 4048 | return; |
| 4049 | } |
| 4050 | } |
| 4051 | this.scrollLeftStart = this.element.scrollLeft; |
| 4052 | this.scrollTopStart = this.element.scrollTop; |
| 4053 | this.clientXStart = event.clientX; |
| 4054 | this.clientYStart = event.clientY; |
| 4055 | this.document.addEventListener("mousemove", this._onMouseMove, true); |
| 4056 | this.document.addEventListener("mouseup", this._endPan, true); |
| 4057 | this.element.addEventListener("scroll", this._endPan, true); |
| 4058 | event.preventDefault(); |
| 4059 | event.stopPropagation(); |
| 4060 | const focusedElement = document.activeElement; |
| 4061 | if (focusedElement && !focusedElement.contains(event.target)) { |
| 4062 | focusedElement.blur(); |
| 4063 | } |
| 4064 | } |
| 4065 | #onMouseMove(event) { |
| 4066 | this.element.removeEventListener("scroll", this._endPan, true); |
| 4067 | if (!(event.buttons & 1)) { |
| 4068 | this._endPan(); |
| 4069 | return; |
| 4070 | } |
| 4071 | const xDiff = event.clientX - this.clientXStart; |
| 4072 | const yDiff = event.clientY - this.clientYStart; |
| 4073 | const scrollTop = this.scrollTopStart - yDiff; |
| 4074 | const scrollLeft = this.scrollLeftStart - xDiff; |
| 4075 | if (this.element.scrollTo) { |
| 4076 | this.element.scrollTo({ |
| 4077 | top: scrollTop, |
| 4078 | left: scrollLeft, |
| 4079 | behavior: "instant" |
| 4080 | }); |
| 4081 | } else { |
| 4082 | this.element.scrollTop = scrollTop; |
| 4083 | this.element.scrollLeft = scrollLeft; |
| 4084 | } |
| 4085 | if (!this.overlay.parentNode) { |
| 4086 | document.body.append(this.overlay); |
| 4087 | } |
| 4088 | } |
| 4089 | #endPan() { |
| 4090 | this.element.removeEventListener("scroll", this._endPan, true); |
| 4091 | this.document.removeEventListener("mousemove", this._onMouseMove, true); |
| 4092 | this.document.removeEventListener("mouseup", this._endPan, true); |
| 4093 | this.overlay.remove(); |
| 4094 | } |
| 4095 | } |
| 4096 | exports.GrabToPan = GrabToPan; |
| 4097 | |
| 4098 | /***/ }), |
| 4099 | /* 9 */ |
| 4100 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4101 | |
| 4102 | |
| 4103 | |
| 4104 | Object.defineProperty(exports, "__esModule", ({ |
| 4105 | value: true |
| 4106 | })); |
| 4107 | exports.AnnotationEditorParams = void 0; |
| 4108 | var _pdfjsLib = __webpack_require__(5); |
| 4109 | class AnnotationEditorParams { |
| 4110 | constructor(options, eventBus) { |
| 4111 | this.eventBus = eventBus; |
| 4112 | this.#bindListeners(options); |
| 4113 | } |
| 4114 | #bindListeners({ |
| 4115 | editorFreeTextFontSize, |
| 4116 | editorFreeTextColor, |
| 4117 | editorInkColor, |
| 4118 | editorInkThickness, |
| 4119 | editorInkOpacity |
| 4120 | }) { |
| 4121 | editorFreeTextFontSize.addEventListener("input", evt => { |
| 4122 | this.eventBus.dispatch("switchannotationeditorparams", { |
| 4123 | source: this, |
| 4124 | type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE, |
| 4125 | value: editorFreeTextFontSize.valueAsNumber |
| 4126 | }); |
| 4127 | }); |
| 4128 | editorFreeTextColor.addEventListener("input", evt => { |
| 4129 | this.eventBus.dispatch("switchannotationeditorparams", { |
| 4130 | source: this, |
| 4131 | type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR, |
| 4132 | value: editorFreeTextColor.value |
| 4133 | }); |
| 4134 | }); |
| 4135 | editorInkColor.addEventListener("input", evt => { |
| 4136 | this.eventBus.dispatch("switchannotationeditorparams", { |
| 4137 | source: this, |
| 4138 | type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR, |
| 4139 | value: editorInkColor.value |
| 4140 | }); |
| 4141 | }); |
| 4142 | editorInkThickness.addEventListener("input", evt => { |
| 4143 | this.eventBus.dispatch("switchannotationeditorparams", { |
| 4144 | source: this, |
| 4145 | type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS, |
| 4146 | value: editorInkThickness.valueAsNumber |
| 4147 | }); |
| 4148 | }); |
| 4149 | editorInkOpacity.addEventListener("input", evt => { |
| 4150 | this.eventBus.dispatch("switchannotationeditorparams", { |
| 4151 | source: this, |
| 4152 | type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY, |
| 4153 | value: editorInkOpacity.valueAsNumber |
| 4154 | }); |
| 4155 | }); |
| 4156 | this.eventBus._on("annotationeditorparamschanged", evt => { |
| 4157 | for (const [type, value] of evt.details) { |
| 4158 | switch (type) { |
| 4159 | case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE: |
| 4160 | editorFreeTextFontSize.value = value; |
| 4161 | break; |
| 4162 | case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR: |
| 4163 | editorFreeTextColor.value = value; |
| 4164 | break; |
| 4165 | case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR: |
| 4166 | editorInkColor.value = value; |
| 4167 | break; |
| 4168 | case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS: |
| 4169 | editorInkThickness.value = value; |
| 4170 | break; |
| 4171 | case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY: |
| 4172 | editorInkOpacity.value = value; |
| 4173 | break; |
| 4174 | } |
| 4175 | } |
| 4176 | }); |
| 4177 | } |
| 4178 | } |
| 4179 | exports.AnnotationEditorParams = AnnotationEditorParams; |
| 4180 | |
| 4181 | /***/ }), |
| 4182 | /* 10 */ |
| 4183 | /***/ ((__unused_webpack_module, exports) => { |
| 4184 | |
| 4185 | |
| 4186 | |
| 4187 | Object.defineProperty(exports, "__esModule", ({ |
| 4188 | value: true |
| 4189 | })); |
| 4190 | exports.OverlayManager = void 0; |
| 4191 | class OverlayManager { |
| 4192 | #overlays = new WeakMap(); |
| 4193 | #active = null; |
| 4194 | get active() { |
| 4195 | return this.#active; |
| 4196 | } |
| 4197 | async register(dialog, canForceClose = false) { |
| 4198 | if (typeof dialog !== "object") { |
| 4199 | throw new Error("Not enough parameters."); |
| 4200 | } else if (this.#overlays.has(dialog)) { |
| 4201 | throw new Error("The overlay is already registered."); |
| 4202 | } |
| 4203 | this.#overlays.set(dialog, { |
| 4204 | canForceClose |
| 4205 | }); |
| 4206 | dialog.addEventListener("cancel", evt => { |
| 4207 | this.#active = null; |
| 4208 | }); |
| 4209 | } |
| 4210 | async unregister(dialog) { |
| 4211 | if (!this.#overlays.has(dialog)) { |
| 4212 | throw new Error("The overlay does not exist."); |
| 4213 | } else if (this.#active === dialog) { |
| 4214 | throw new Error("The overlay cannot be removed while it is active."); |
| 4215 | } |
| 4216 | this.#overlays.delete(dialog); |
| 4217 | } |
| 4218 | async open(dialog) { |
| 4219 | if (!this.#overlays.has(dialog)) { |
| 4220 | throw new Error("The overlay does not exist."); |
| 4221 | } else if (this.#active) { |
| 4222 | if (this.#active === dialog) { |
| 4223 | throw new Error("The overlay is already active."); |
| 4224 | } else if (this.#overlays.get(dialog).canForceClose) { |
| 4225 | await this.close(); |
| 4226 | } else { |
| 4227 | throw new Error("Another overlay is currently active."); |
| 4228 | } |
| 4229 | } |
| 4230 | this.#active = dialog; |
| 4231 | dialog.showModal(); |
| 4232 | } |
| 4233 | async close(dialog = this.#active) { |
| 4234 | if (!this.#overlays.has(dialog)) { |
| 4235 | throw new Error("The overlay does not exist."); |
| 4236 | } else if (!this.#active) { |
| 4237 | throw new Error("The overlay is currently not active."); |
| 4238 | } else if (this.#active !== dialog) { |
| 4239 | throw new Error("Another overlay is currently active."); |
| 4240 | } |
| 4241 | dialog.close(); |
| 4242 | this.#active = null; |
| 4243 | } |
| 4244 | } |
| 4245 | exports.OverlayManager = OverlayManager; |
| 4246 | |
| 4247 | /***/ }), |
| 4248 | /* 11 */ |
| 4249 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4250 | |
| 4251 | |
| 4252 | |
| 4253 | Object.defineProperty(exports, "__esModule", ({ |
| 4254 | value: true |
| 4255 | })); |
| 4256 | exports.PasswordPrompt = void 0; |
| 4257 | var _pdfjsLib = __webpack_require__(5); |
| 4258 | class PasswordPrompt { |
| 4259 | #activeCapability = null; |
| 4260 | #updateCallback = null; |
| 4261 | #reason = null; |
| 4262 | constructor(options, overlayManager, l10n, isViewerEmbedded = false) { |
| 4263 | this.dialog = options.dialog; |
| 4264 | this.label = options.label; |
| 4265 | this.input = options.input; |
| 4266 | this.submitButton = options.submitButton; |
| 4267 | this.cancelButton = options.cancelButton; |
| 4268 | this.overlayManager = overlayManager; |
| 4269 | this.l10n = l10n; |
| 4270 | this._isViewerEmbedded = isViewerEmbedded; |
| 4271 | this.submitButton.addEventListener("click", this.#verify.bind(this)); |
| 4272 | this.cancelButton.addEventListener("click", this.close.bind(this)); |
| 4273 | this.input.addEventListener("keydown", e => { |
| 4274 | if (e.keyCode === 13) { |
| 4275 | this.#verify(); |
| 4276 | } |
| 4277 | }); |
| 4278 | this.overlayManager.register(this.dialog, true); |
| 4279 | this.dialog.addEventListener("close", this.#cancel.bind(this)); |
| 4280 | } |
| 4281 | async open() { |
| 4282 | if (this.#activeCapability) { |
| 4283 | await this.#activeCapability.promise; |
| 4284 | } |
| 4285 | this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 4286 | try { |
| 4287 | await this.overlayManager.open(this.dialog); |
| 4288 | } catch (ex) { |
| 4289 | this.#activeCapability = null; |
| 4290 | throw ex; |
| 4291 | } |
| 4292 | const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD; |
| 4293 | if (!this._isViewerEmbedded || passwordIncorrect) { |
| 4294 | this.input.focus(); |
| 4295 | } |
| 4296 | this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`); |
| 4297 | } |
| 4298 | async close() { |
| 4299 | if (this.overlayManager.active === this.dialog) { |
| 4300 | this.overlayManager.close(this.dialog); |
| 4301 | } |
| 4302 | } |
| 4303 | #verify() { |
| 4304 | const password = this.input.value; |
| 4305 | if (password?.length > 0) { |
| 4306 | this.#invokeCallback(password); |
| 4307 | } |
| 4308 | } |
| 4309 | #cancel() { |
| 4310 | this.#invokeCallback(new Error("PasswordPrompt cancelled.")); |
| 4311 | this.#activeCapability.resolve(); |
| 4312 | } |
| 4313 | #invokeCallback(password) { |
| 4314 | if (!this.#updateCallback) { |
| 4315 | return; |
| 4316 | } |
| 4317 | this.close(); |
| 4318 | this.input.value = ""; |
| 4319 | this.#updateCallback(password); |
| 4320 | this.#updateCallback = null; |
| 4321 | } |
| 4322 | async setUpdateCallback(updateCallback, reason) { |
| 4323 | if (this.#activeCapability) { |
| 4324 | await this.#activeCapability.promise; |
| 4325 | } |
| 4326 | this.#updateCallback = updateCallback; |
| 4327 | this.#reason = reason; |
| 4328 | } |
| 4329 | } |
| 4330 | exports.PasswordPrompt = PasswordPrompt; |
| 4331 | |
| 4332 | /***/ }), |
| 4333 | /* 12 */ |
| 4334 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4335 | |
| 4336 | |
| 4337 | |
| 4338 | Object.defineProperty(exports, "__esModule", ({ |
| 4339 | value: true |
| 4340 | })); |
| 4341 | exports.PDFAttachmentViewer = void 0; |
| 4342 | var _pdfjsLib = __webpack_require__(5); |
| 4343 | var _base_tree_viewer = __webpack_require__(13); |
| 4344 | var _event_utils = __webpack_require__(6); |
| 4345 | class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer { |
| 4346 | constructor(options) { |
| 4347 | super(options); |
| 4348 | this.downloadManager = options.downloadManager; |
| 4349 | this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this)); |
| 4350 | } |
| 4351 | reset(keepRenderedCapability = false) { |
| 4352 | super.reset(); |
| 4353 | this._attachments = null; |
| 4354 | if (!keepRenderedCapability) { |
| 4355 | this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 4356 | } |
| 4357 | this._pendingDispatchEvent = false; |
| 4358 | } |
| 4359 | async _dispatchEvent(attachmentsCount) { |
| 4360 | this._renderedCapability.resolve(); |
| 4361 | if (attachmentsCount === 0 && !this._pendingDispatchEvent) { |
| 4362 | this._pendingDispatchEvent = true; |
| 4363 | await (0, _event_utils.waitOnEventOrTimeout)({ |
| 4364 | target: this.eventBus, |
| 4365 | name: "annotationlayerrendered", |
| 4366 | delay: 1000 |
| 4367 | }); |
| 4368 | if (!this._pendingDispatchEvent) { |
| 4369 | return; |
| 4370 | } |
| 4371 | } |
| 4372 | this._pendingDispatchEvent = false; |
| 4373 | this.eventBus.dispatch("attachmentsloaded", { |
| 4374 | source: this, |
| 4375 | attachmentsCount |
| 4376 | }); |
| 4377 | } |
| 4378 | _bindLink(element, { |
| 4379 | content, |
| 4380 | filename |
| 4381 | }) { |
| 4382 | element.onclick = () => { |
| 4383 | this.downloadManager.openOrDownloadData(element, content, filename); |
| 4384 | return false; |
| 4385 | }; |
| 4386 | } |
| 4387 | render({ |
| 4388 | attachments, |
| 4389 | keepRenderedCapability = false |
| 4390 | }) { |
| 4391 | if (this._attachments) { |
| 4392 | this.reset(keepRenderedCapability); |
| 4393 | } |
| 4394 | this._attachments = attachments || null; |
| 4395 | if (!attachments) { |
| 4396 | this._dispatchEvent(0); |
| 4397 | return; |
| 4398 | } |
| 4399 | const names = Object.keys(attachments).sort(function (a, b) { |
| 4400 | return a.toLowerCase().localeCompare(b.toLowerCase()); |
| 4401 | }); |
| 4402 | const fragment = document.createDocumentFragment(); |
| 4403 | let attachmentsCount = 0; |
| 4404 | for (const name of names) { |
| 4405 | const item = attachments[name]; |
| 4406 | const content = item.content, |
| 4407 | filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true); |
| 4408 | const div = document.createElement("div"); |
| 4409 | div.className = "treeItem"; |
| 4410 | const element = document.createElement("a"); |
| 4411 | this._bindLink(element, { |
| 4412 | content, |
| 4413 | filename |
| 4414 | }); |
| 4415 | element.textContent = this._normalizeTextContent(filename); |
| 4416 | div.append(element); |
| 4417 | fragment.append(div); |
| 4418 | attachmentsCount++; |
| 4419 | } |
| 4420 | this._finishRendering(fragment, attachmentsCount); |
| 4421 | } |
| 4422 | #appendAttachment({ |
| 4423 | filename, |
| 4424 | content |
| 4425 | }) { |
| 4426 | const renderedPromise = this._renderedCapability.promise; |
| 4427 | renderedPromise.then(() => { |
| 4428 | if (renderedPromise !== this._renderedCapability.promise) { |
| 4429 | return; |
| 4430 | } |
| 4431 | const attachments = this._attachments || Object.create(null); |
| 4432 | for (const name in attachments) { |
| 4433 | if (filename === name) { |
| 4434 | return; |
| 4435 | } |
| 4436 | } |
| 4437 | attachments[filename] = { |
| 4438 | filename, |
| 4439 | content |
| 4440 | }; |
| 4441 | this.render({ |
| 4442 | attachments, |
| 4443 | keepRenderedCapability: true |
| 4444 | }); |
| 4445 | }); |
| 4446 | } |
| 4447 | } |
| 4448 | exports.PDFAttachmentViewer = PDFAttachmentViewer; |
| 4449 | |
| 4450 | /***/ }), |
| 4451 | /* 13 */ |
| 4452 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4453 | |
| 4454 | |
| 4455 | |
| 4456 | Object.defineProperty(exports, "__esModule", ({ |
| 4457 | value: true |
| 4458 | })); |
| 4459 | exports.BaseTreeViewer = void 0; |
| 4460 | var _ui_utils = __webpack_require__(1); |
| 4461 | const TREEITEM_OFFSET_TOP = -100; |
| 4462 | const TREEITEM_SELECTED_CLASS = "selected"; |
| 4463 | class BaseTreeViewer { |
| 4464 | constructor(options) { |
| 4465 | if (this.constructor === BaseTreeViewer) { |
| 4466 | throw new Error("Cannot initialize BaseTreeViewer."); |
| 4467 | } |
| 4468 | this.container = options.container; |
| 4469 | this.eventBus = options.eventBus; |
| 4470 | this.reset(); |
| 4471 | } |
| 4472 | reset() { |
| 4473 | this._pdfDocument = null; |
| 4474 | this._lastToggleIsShow = true; |
| 4475 | this._currentTreeItem = null; |
| 4476 | this.container.textContent = ""; |
| 4477 | this.container.classList.remove("treeWithDeepNesting"); |
| 4478 | } |
| 4479 | _dispatchEvent(count) { |
| 4480 | throw new Error("Not implemented: _dispatchEvent"); |
| 4481 | } |
| 4482 | _bindLink(element, params) { |
| 4483 | throw new Error("Not implemented: _bindLink"); |
| 4484 | } |
| 4485 | _normalizeTextContent(str) { |
| 4486 | return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013"; |
| 4487 | } |
| 4488 | _addToggleButton(div, hidden = false) { |
| 4489 | const toggler = document.createElement("div"); |
| 4490 | toggler.className = "treeItemToggler"; |
| 4491 | if (hidden) { |
| 4492 | toggler.classList.add("treeItemsHidden"); |
| 4493 | } |
| 4494 | toggler.onclick = evt => { |
| 4495 | evt.stopPropagation(); |
| 4496 | toggler.classList.toggle("treeItemsHidden"); |
| 4497 | if (evt.shiftKey) { |
| 4498 | const shouldShowAll = !toggler.classList.contains("treeItemsHidden"); |
| 4499 | this._toggleTreeItem(div, shouldShowAll); |
| 4500 | } |
| 4501 | }; |
| 4502 | div.prepend(toggler); |
| 4503 | } |
| 4504 | _toggleTreeItem(root, show = false) { |
| 4505 | this._lastToggleIsShow = show; |
| 4506 | for (const toggler of root.querySelectorAll(".treeItemToggler")) { |
| 4507 | toggler.classList.toggle("treeItemsHidden", !show); |
| 4508 | } |
| 4509 | } |
| 4510 | _toggleAllTreeItems() { |
| 4511 | this._toggleTreeItem(this.container, !this._lastToggleIsShow); |
| 4512 | } |
| 4513 | _finishRendering(fragment, count, hasAnyNesting = false) { |
| 4514 | if (hasAnyNesting) { |
| 4515 | this.container.classList.add("treeWithDeepNesting"); |
| 4516 | this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden"); |
| 4517 | } |
| 4518 | this.container.append(fragment); |
| 4519 | this._dispatchEvent(count); |
| 4520 | } |
| 4521 | render(params) { |
| 4522 | throw new Error("Not implemented: render"); |
| 4523 | } |
| 4524 | _updateCurrentTreeItem(treeItem = null) { |
| 4525 | if (this._currentTreeItem) { |
| 4526 | this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS); |
| 4527 | this._currentTreeItem = null; |
| 4528 | } |
| 4529 | if (treeItem) { |
| 4530 | treeItem.classList.add(TREEITEM_SELECTED_CLASS); |
| 4531 | this._currentTreeItem = treeItem; |
| 4532 | } |
| 4533 | } |
| 4534 | _scrollToCurrentTreeItem(treeItem) { |
| 4535 | if (!treeItem) { |
| 4536 | return; |
| 4537 | } |
| 4538 | let currentNode = treeItem.parentNode; |
| 4539 | while (currentNode && currentNode !== this.container) { |
| 4540 | if (currentNode.classList.contains("treeItem")) { |
| 4541 | const toggler = currentNode.firstElementChild; |
| 4542 | toggler?.classList.remove("treeItemsHidden"); |
| 4543 | } |
| 4544 | currentNode = currentNode.parentNode; |
| 4545 | } |
| 4546 | this._updateCurrentTreeItem(treeItem); |
| 4547 | this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP); |
| 4548 | } |
| 4549 | } |
| 4550 | exports.BaseTreeViewer = BaseTreeViewer; |
| 4551 | |
| 4552 | /***/ }), |
| 4553 | /* 14 */ |
| 4554 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4555 | |
| 4556 | |
| 4557 | |
| 4558 | Object.defineProperty(exports, "__esModule", ({ |
| 4559 | value: true |
| 4560 | })); |
| 4561 | exports.PDFDocumentProperties = void 0; |
| 4562 | var _pdfjsLib = __webpack_require__(5); |
| 4563 | var _ui_utils = __webpack_require__(1); |
| 4564 | const DEFAULT_FIELD_CONTENT = "-"; |
| 4565 | const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"]; |
| 4566 | const US_PAGE_NAMES = { |
| 4567 | "8.5x11": "Letter", |
| 4568 | "8.5x14": "Legal" |
| 4569 | }; |
| 4570 | const METRIC_PAGE_NAMES = { |
| 4571 | "297x420": "A3", |
| 4572 | "210x297": "A4" |
| 4573 | }; |
| 4574 | function getPageName(size, isPortrait, pageNames) { |
| 4575 | const width = isPortrait ? size.width : size.height; |
| 4576 | const height = isPortrait ? size.height : size.width; |
| 4577 | return pageNames[`${width}x${height}`]; |
| 4578 | } |
| 4579 | class PDFDocumentProperties { |
| 4580 | #fieldData = null; |
| 4581 | constructor({ |
| 4582 | dialog, |
| 4583 | fields, |
| 4584 | closeButton |
| 4585 | }, overlayManager, eventBus, l10n, fileNameLookup) { |
| 4586 | this.dialog = dialog; |
| 4587 | this.fields = fields; |
| 4588 | this.overlayManager = overlayManager; |
| 4589 | this.l10n = l10n; |
| 4590 | this._fileNameLookup = fileNameLookup; |
| 4591 | this.#reset(); |
| 4592 | closeButton.addEventListener("click", this.close.bind(this)); |
| 4593 | this.overlayManager.register(this.dialog); |
| 4594 | eventBus._on("pagechanging", evt => { |
| 4595 | this._currentPageNumber = evt.pageNumber; |
| 4596 | }); |
| 4597 | eventBus._on("rotationchanging", evt => { |
| 4598 | this._pagesRotation = evt.pagesRotation; |
| 4599 | }); |
| 4600 | this._isNonMetricLocale = true; |
| 4601 | l10n.getLanguage().then(locale => { |
| 4602 | this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale); |
| 4603 | }); |
| 4604 | } |
| 4605 | async open() { |
| 4606 | await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]); |
| 4607 | const currentPageNumber = this._currentPageNumber; |
| 4608 | const pagesRotation = this._pagesRotation; |
| 4609 | if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) { |
| 4610 | this.#updateUI(); |
| 4611 | return; |
| 4612 | } |
| 4613 | const { |
| 4614 | info, |
| 4615 | contentLength |
| 4616 | } = await this.pdfDocument.getMetadata(); |
| 4617 | 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 => { |
| 4618 | return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation); |
| 4619 | }), this.#parseLinearization(info.IsLinearized)]); |
| 4620 | this.#fieldData = Object.freeze({ |
| 4621 | fileName, |
| 4622 | fileSize, |
| 4623 | title: info.Title, |
| 4624 | author: info.Author, |
| 4625 | subject: info.Subject, |
| 4626 | keywords: info.Keywords, |
| 4627 | creationDate, |
| 4628 | modificationDate, |
| 4629 | creator: info.Creator, |
| 4630 | producer: info.Producer, |
| 4631 | version: info.PDFFormatVersion, |
| 4632 | pageCount: this.pdfDocument.numPages, |
| 4633 | pageSize, |
| 4634 | linearized: isLinearized, |
| 4635 | _currentPageNumber: currentPageNumber, |
| 4636 | _pagesRotation: pagesRotation |
| 4637 | }); |
| 4638 | this.#updateUI(); |
| 4639 | const { |
| 4640 | length |
| 4641 | } = await this.pdfDocument.getDownloadInfo(); |
| 4642 | if (contentLength === length) { |
| 4643 | return; |
| 4644 | } |
| 4645 | const data = Object.assign(Object.create(null), this.#fieldData); |
| 4646 | data.fileSize = await this.#parseFileSize(length); |
| 4647 | this.#fieldData = Object.freeze(data); |
| 4648 | this.#updateUI(); |
| 4649 | } |
| 4650 | async close() { |
| 4651 | this.overlayManager.close(this.dialog); |
| 4652 | } |
| 4653 | setDocument(pdfDocument) { |
| 4654 | if (this.pdfDocument) { |
| 4655 | this.#reset(); |
| 4656 | this.#updateUI(true); |
| 4657 | } |
| 4658 | if (!pdfDocument) { |
| 4659 | return; |
| 4660 | } |
| 4661 | this.pdfDocument = pdfDocument; |
| 4662 | this._dataAvailableCapability.resolve(); |
| 4663 | } |
| 4664 | #reset() { |
| 4665 | this.pdfDocument = null; |
| 4666 | this.#fieldData = null; |
| 4667 | this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 4668 | this._currentPageNumber = 1; |
| 4669 | this._pagesRotation = 0; |
| 4670 | } |
| 4671 | #updateUI(reset = false) { |
| 4672 | if (reset || !this.#fieldData) { |
| 4673 | for (const id in this.fields) { |
| 4674 | this.fields[id].textContent = DEFAULT_FIELD_CONTENT; |
| 4675 | } |
| 4676 | return; |
| 4677 | } |
| 4678 | if (this.overlayManager.active !== this.dialog) { |
| 4679 | return; |
| 4680 | } |
| 4681 | for (const id in this.fields) { |
| 4682 | const content = this.#fieldData[id]; |
| 4683 | this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT; |
| 4684 | } |
| 4685 | } |
| 4686 | async #parseFileSize(fileSize = 0) { |
| 4687 | const kb = fileSize / 1024, |
| 4688 | mb = kb / 1024; |
| 4689 | if (!kb) { |
| 4690 | return undefined; |
| 4691 | } |
| 4692 | return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, { |
| 4693 | size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(), |
| 4694 | size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(), |
| 4695 | size_b: fileSize.toLocaleString() |
| 4696 | }); |
| 4697 | } |
| 4698 | async #parsePageSize(pageSizeInches, pagesRotation) { |
| 4699 | if (!pageSizeInches) { |
| 4700 | return undefined; |
| 4701 | } |
| 4702 | if (pagesRotation % 180 !== 0) { |
| 4703 | pageSizeInches = { |
| 4704 | width: pageSizeInches.height, |
| 4705 | height: pageSizeInches.width |
| 4706 | }; |
| 4707 | } |
| 4708 | const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches); |
| 4709 | let sizeInches = { |
| 4710 | width: Math.round(pageSizeInches.width * 100) / 100, |
| 4711 | height: Math.round(pageSizeInches.height * 100) / 100 |
| 4712 | }; |
| 4713 | let sizeMillimeters = { |
| 4714 | width: Math.round(pageSizeInches.width * 25.4 * 10) / 10, |
| 4715 | height: Math.round(pageSizeInches.height * 25.4 * 10) / 10 |
| 4716 | }; |
| 4717 | let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES); |
| 4718 | if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) { |
| 4719 | const exactMillimeters = { |
| 4720 | width: pageSizeInches.width * 25.4, |
| 4721 | height: pageSizeInches.height * 25.4 |
| 4722 | }; |
| 4723 | const intMillimeters = { |
| 4724 | width: Math.round(sizeMillimeters.width), |
| 4725 | height: Math.round(sizeMillimeters.height) |
| 4726 | }; |
| 4727 | if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) { |
| 4728 | rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES); |
| 4729 | if (rawName) { |
| 4730 | sizeInches = { |
| 4731 | width: Math.round(intMillimeters.width / 25.4 * 100) / 100, |
| 4732 | height: Math.round(intMillimeters.height / 25.4 * 100) / 100 |
| 4733 | }; |
| 4734 | sizeMillimeters = intMillimeters; |
| 4735 | } |
| 4736 | } |
| 4737 | } |
| 4738 | const [{ |
| 4739 | width, |
| 4740 | height |
| 4741 | }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]); |
| 4742 | return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, { |
| 4743 | width: width.toLocaleString(), |
| 4744 | height: height.toLocaleString(), |
| 4745 | unit, |
| 4746 | name, |
| 4747 | orientation |
| 4748 | }); |
| 4749 | } |
| 4750 | async #parseDate(inputDate) { |
| 4751 | const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate); |
| 4752 | if (!dateObject) { |
| 4753 | return undefined; |
| 4754 | } |
| 4755 | return this.l10n.get("document_properties_date_string", { |
| 4756 | date: dateObject.toLocaleDateString(), |
| 4757 | time: dateObject.toLocaleTimeString() |
| 4758 | }); |
| 4759 | } |
| 4760 | #parseLinearization(isLinearized) { |
| 4761 | return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`); |
| 4762 | } |
| 4763 | } |
| 4764 | exports.PDFDocumentProperties = PDFDocumentProperties; |
| 4765 | |
| 4766 | /***/ }), |
| 4767 | /* 15 */ |
| 4768 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4769 | |
| 4770 | |
| 4771 | |
| 4772 | Object.defineProperty(exports, "__esModule", ({ |
| 4773 | value: true |
| 4774 | })); |
| 4775 | exports.PDFFindBar = void 0; |
| 4776 | var _pdf_find_controller = __webpack_require__(16); |
| 4777 | const MATCHES_COUNT_LIMIT = 1000; |
| 4778 | class PDFFindBar { |
| 4779 | constructor(options, eventBus, l10n) { |
| 4780 | this.opened = false; |
| 4781 | this.bar = options.bar; |
| 4782 | this.toggleButton = options.toggleButton; |
| 4783 | this.findField = options.findField; |
| 4784 | this.highlightAll = options.highlightAllCheckbox; |
| 4785 | this.caseSensitive = options.caseSensitiveCheckbox; |
| 4786 | this.matchDiacritics = options.matchDiacriticsCheckbox; |
| 4787 | this.entireWord = options.entireWordCheckbox; |
| 4788 | this.findMsg = options.findMsg; |
| 4789 | this.findResultsCount = options.findResultsCount; |
| 4790 | this.findPreviousButton = options.findPreviousButton; |
| 4791 | this.findNextButton = options.findNextButton; |
| 4792 | this.eventBus = eventBus; |
| 4793 | this.l10n = l10n; |
| 4794 | this.toggleButton.addEventListener("click", () => { |
| 4795 | this.toggle(); |
| 4796 | }); |
| 4797 | this.findField.addEventListener("input", () => { |
| 4798 | this.dispatchEvent(""); |
| 4799 | }); |
| 4800 | this.bar.addEventListener("keydown", e => { |
| 4801 | switch (e.keyCode) { |
| 4802 | case 13: |
| 4803 | if (e.target === this.findField) { |
| 4804 | this.dispatchEvent("again", e.shiftKey); |
| 4805 | } |
| 4806 | break; |
| 4807 | case 27: |
| 4808 | this.close(); |
| 4809 | break; |
| 4810 | } |
| 4811 | }); |
| 4812 | this.findPreviousButton.addEventListener("click", () => { |
| 4813 | this.dispatchEvent("again", true); |
| 4814 | }); |
| 4815 | this.findNextButton.addEventListener("click", () => { |
| 4816 | this.dispatchEvent("again", false); |
| 4817 | }); |
| 4818 | this.highlightAll.addEventListener("click", () => { |
| 4819 | this.dispatchEvent("highlightallchange"); |
| 4820 | }); |
| 4821 | this.caseSensitive.addEventListener("click", () => { |
| 4822 | this.dispatchEvent("casesensitivitychange"); |
| 4823 | }); |
| 4824 | this.entireWord.addEventListener("click", () => { |
| 4825 | this.dispatchEvent("entirewordchange"); |
| 4826 | }); |
| 4827 | this.matchDiacritics.addEventListener("click", () => { |
| 4828 | this.dispatchEvent("diacriticmatchingchange"); |
| 4829 | }); |
| 4830 | this.eventBus._on("resize", this.#adjustWidth.bind(this)); |
| 4831 | } |
| 4832 | reset() { |
| 4833 | this.updateUIState(); |
| 4834 | } |
| 4835 | dispatchEvent(type, findPrev = false) { |
| 4836 | this.eventBus.dispatch("find", { |
| 4837 | source: this, |
| 4838 | type, |
| 4839 | query: this.findField.value, |
| 4840 | phraseSearch: true, |
| 4841 | caseSensitive: this.caseSensitive.checked, |
| 4842 | entireWord: this.entireWord.checked, |
| 4843 | highlightAll: this.highlightAll.checked, |
| 4844 | findPrevious: findPrev, |
| 4845 | matchDiacritics: this.matchDiacritics.checked |
| 4846 | }); |
| 4847 | } |
| 4848 | updateUIState(state, previous, matchesCount) { |
| 4849 | let findMsg = Promise.resolve(""); |
| 4850 | let status = ""; |
| 4851 | switch (state) { |
| 4852 | case _pdf_find_controller.FindState.FOUND: |
| 4853 | break; |
| 4854 | case _pdf_find_controller.FindState.PENDING: |
| 4855 | status = "pending"; |
| 4856 | break; |
| 4857 | case _pdf_find_controller.FindState.NOT_FOUND: |
| 4858 | findMsg = this.l10n.get("find_not_found"); |
| 4859 | status = "notFound"; |
| 4860 | break; |
| 4861 | case _pdf_find_controller.FindState.WRAPPED: |
| 4862 | findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`); |
| 4863 | break; |
| 4864 | } |
| 4865 | this.findField.setAttribute("data-status", status); |
| 4866 | this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND); |
| 4867 | findMsg.then(msg => { |
| 4868 | this.findMsg.textContent = msg; |
| 4869 | this.#adjustWidth(); |
| 4870 | }); |
| 4871 | this.updateResultsCount(matchesCount); |
| 4872 | } |
| 4873 | updateResultsCount({ |
| 4874 | current = 0, |
| 4875 | total = 0 |
| 4876 | } = {}) { |
| 4877 | const limit = MATCHES_COUNT_LIMIT; |
| 4878 | let matchCountMsg = Promise.resolve(""); |
| 4879 | if (total > 0) { |
| 4880 | if (total > limit) { |
| 4881 | let key = "find_match_count_limit"; |
| 4882 | matchCountMsg = this.l10n.get(key, { |
| 4883 | limit |
| 4884 | }); |
| 4885 | } else { |
| 4886 | let key = "find_match_count"; |
| 4887 | matchCountMsg = this.l10n.get(key, { |
| 4888 | current, |
| 4889 | total |
| 4890 | }); |
| 4891 | } |
| 4892 | } |
| 4893 | matchCountMsg.then(msg => { |
| 4894 | this.findResultsCount.textContent = msg; |
| 4895 | this.#adjustWidth(); |
| 4896 | }); |
| 4897 | } |
| 4898 | open() { |
| 4899 | if (!this.opened) { |
| 4900 | this.opened = true; |
| 4901 | this.toggleButton.classList.add("toggled"); |
| 4902 | this.toggleButton.setAttribute("aria-expanded", "true"); |
| 4903 | this.bar.classList.remove("hidden"); |
| 4904 | } |
| 4905 | this.findField.select(); |
| 4906 | this.findField.focus(); |
| 4907 | this.#adjustWidth(); |
| 4908 | } |
| 4909 | close() { |
| 4910 | if (!this.opened) { |
| 4911 | return; |
| 4912 | } |
| 4913 | this.opened = false; |
| 4914 | this.toggleButton.classList.remove("toggled"); |
| 4915 | this.toggleButton.setAttribute("aria-expanded", "false"); |
| 4916 | this.bar.classList.add("hidden"); |
| 4917 | this.eventBus.dispatch("findbarclose", { |
| 4918 | source: this |
| 4919 | }); |
| 4920 | } |
| 4921 | toggle() { |
| 4922 | if (this.opened) { |
| 4923 | this.close(); |
| 4924 | } else { |
| 4925 | this.open(); |
| 4926 | } |
| 4927 | } |
| 4928 | #adjustWidth() { |
| 4929 | if (!this.opened) { |
| 4930 | return; |
| 4931 | } |
| 4932 | this.bar.classList.remove("wrapContainers"); |
| 4933 | const findbarHeight = this.bar.clientHeight; |
| 4934 | const inputContainerHeight = this.bar.firstElementChild.clientHeight; |
| 4935 | if (findbarHeight > inputContainerHeight) { |
| 4936 | this.bar.classList.add("wrapContainers"); |
| 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | exports.PDFFindBar = PDFFindBar; |
| 4941 | |
| 4942 | /***/ }), |
| 4943 | /* 16 */ |
| 4944 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 4945 | |
| 4946 | |
| 4947 | |
| 4948 | Object.defineProperty(exports, "__esModule", ({ |
| 4949 | value: true |
| 4950 | })); |
| 4951 | exports.PDFFindController = exports.FindState = void 0; |
| 4952 | var _ui_utils = __webpack_require__(1); |
| 4953 | var _pdfjsLib = __webpack_require__(5); |
| 4954 | var _pdf_find_utils = __webpack_require__(17); |
| 4955 | const FindState = { |
| 4956 | FOUND: 0, |
| 4957 | NOT_FOUND: 1, |
| 4958 | WRAPPED: 2, |
| 4959 | PENDING: 3 |
| 4960 | }; |
| 4961 | exports.FindState = FindState; |
| 4962 | const FIND_TIMEOUT = 250; |
| 4963 | const MATCH_SCROLL_OFFSET_TOP = -50; |
| 4964 | const MATCH_SCROLL_OFFSET_LEFT = -400; |
| 4965 | const CHARACTERS_TO_NORMALIZE = { |
| 4966 | "\u2010": "-", |
| 4967 | "\u2018": "'", |
| 4968 | "\u2019": "'", |
| 4969 | "\u201A": "'", |
| 4970 | "\u201B": "'", |
| 4971 | "\u201C": '"', |
| 4972 | "\u201D": '"', |
| 4973 | "\u201E": '"', |
| 4974 | "\u201F": '"', |
| 4975 | "\u00BC": "1/4", |
| 4976 | "\u00BD": "1/2", |
| 4977 | "\u00BE": "3/4" |
| 4978 | }; |
| 4979 | 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]); |
| 4980 | let DIACRITICS_EXCEPTION_STR; |
| 4981 | const DIACRITICS_REG_EXP = /\p{M}+/gu; |
| 4982 | const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu; |
| 4983 | const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u; |
| 4984 | const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u; |
| 4985 | const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g; |
| 4986 | const SYLLABLES_LENGTHS = new Map(); |
| 4987 | const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]"; |
| 4988 | const NFKC_CHARS_TO_NORMALIZE = new Map(); |
| 4989 | let noSyllablesRegExp = null; |
| 4990 | let withSyllablesRegExp = null; |
| 4991 | function normalize(text) { |
| 4992 | const syllablePositions = []; |
| 4993 | let m; |
| 4994 | while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) { |
| 4995 | let { |
| 4996 | index |
| 4997 | } = m; |
| 4998 | for (const char of m[0]) { |
| 4999 | let len = SYLLABLES_LENGTHS.get(char); |
| 5000 | if (!len) { |
| 5001 | len = char.normalize("NFD").length; |
| 5002 | SYLLABLES_LENGTHS.set(char, len); |
| 5003 | } |
| 5004 | syllablePositions.push([len, index++]); |
| 5005 | } |
| 5006 | } |
| 5007 | let normalizationRegex; |
| 5008 | if (syllablePositions.length === 0 && noSyllablesRegExp) { |
| 5009 | normalizationRegex = noSyllablesRegExp; |
| 5010 | } else if (syllablePositions.length > 0 && withSyllablesRegExp) { |
| 5011 | normalizationRegex = withSyllablesRegExp; |
| 5012 | } else { |
| 5013 | const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join(""); |
| 5014 | const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef"; |
| 5015 | const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])"; |
| 5016 | const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`; |
| 5017 | if (syllablePositions.length === 0) { |
| 5018 | normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum"); |
| 5019 | } else { |
| 5020 | normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum"); |
| 5021 | } |
| 5022 | } |
| 5023 | const rawDiacriticsPositions = []; |
| 5024 | while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) { |
| 5025 | rawDiacriticsPositions.push([m[0].length, m.index]); |
| 5026 | } |
| 5027 | let normalized = text.normalize("NFD"); |
| 5028 | const positions = [[0, 0]]; |
| 5029 | let rawDiacriticsIndex = 0; |
| 5030 | let syllableIndex = 0; |
| 5031 | let shift = 0; |
| 5032 | let shiftOrigin = 0; |
| 5033 | let eol = 0; |
| 5034 | let hasDiacritics = false; |
| 5035 | normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => { |
| 5036 | i -= shiftOrigin; |
| 5037 | if (p1) { |
| 5038 | const replacement = CHARACTERS_TO_NORMALIZE[p1]; |
| 5039 | const jj = replacement.length; |
| 5040 | for (let j = 1; j < jj; j++) { |
| 5041 | positions.push([i - shift + j, shift - j]); |
| 5042 | } |
| 5043 | shift -= jj - 1; |
| 5044 | return replacement; |
| 5045 | } |
| 5046 | if (p2) { |
| 5047 | let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2); |
| 5048 | if (!replacement) { |
| 5049 | replacement = p2.normalize("NFKC"); |
| 5050 | NFKC_CHARS_TO_NORMALIZE.set(p2, replacement); |
| 5051 | } |
| 5052 | const jj = replacement.length; |
| 5053 | for (let j = 1; j < jj; j++) { |
| 5054 | positions.push([i - shift + j, shift - j]); |
| 5055 | } |
| 5056 | shift -= jj - 1; |
| 5057 | return replacement; |
| 5058 | } |
| 5059 | if (p3) { |
| 5060 | const hasTrailingDashEOL = p3.endsWith("\n"); |
| 5061 | const len = hasTrailingDashEOL ? p3.length - 2 : p3.length; |
| 5062 | hasDiacritics = true; |
| 5063 | let jj = len; |
| 5064 | if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) { |
| 5065 | jj -= rawDiacriticsPositions[rawDiacriticsIndex][0]; |
| 5066 | ++rawDiacriticsIndex; |
| 5067 | } |
| 5068 | for (let j = 1; j <= jj; j++) { |
| 5069 | positions.push([i - 1 - shift + j, shift - j]); |
| 5070 | } |
| 5071 | shift -= jj; |
| 5072 | shiftOrigin += jj; |
| 5073 | if (hasTrailingDashEOL) { |
| 5074 | i += len - 1; |
| 5075 | positions.push([i - shift + 1, 1 + shift]); |
| 5076 | shift += 1; |
| 5077 | shiftOrigin += 1; |
| 5078 | eol += 1; |
| 5079 | return p3.slice(0, len); |
| 5080 | } |
| 5081 | return p3; |
| 5082 | } |
| 5083 | if (p4) { |
| 5084 | positions.push([i - shift + 1, 1 + shift]); |
| 5085 | shift += 1; |
| 5086 | shiftOrigin += 1; |
| 5087 | eol += 1; |
| 5088 | return p4.charAt(0); |
| 5089 | } |
| 5090 | if (p5) { |
| 5091 | positions.push([i - shift + 1, shift]); |
| 5092 | shiftOrigin += 1; |
| 5093 | eol += 1; |
| 5094 | return p5.charAt(0); |
| 5095 | } |
| 5096 | if (p6) { |
| 5097 | positions.push([i - shift + 1, shift - 1]); |
| 5098 | shift -= 1; |
| 5099 | shiftOrigin += 1; |
| 5100 | eol += 1; |
| 5101 | return " "; |
| 5102 | } |
| 5103 | if (i + eol === syllablePositions[syllableIndex]?.[1]) { |
| 5104 | const newCharLen = syllablePositions[syllableIndex][0] - 1; |
| 5105 | ++syllableIndex; |
| 5106 | for (let j = 1; j <= newCharLen; j++) { |
| 5107 | positions.push([i - (shift - j), shift - j]); |
| 5108 | } |
| 5109 | shift -= newCharLen; |
| 5110 | shiftOrigin += newCharLen; |
| 5111 | } |
| 5112 | return p7; |
| 5113 | }); |
| 5114 | positions.push([normalized.length, shift]); |
| 5115 | return [normalized, positions, hasDiacritics]; |
| 5116 | } |
| 5117 | function getOriginalIndex(diffs, pos, len) { |
| 5118 | if (!diffs) { |
| 5119 | return [pos, len]; |
| 5120 | } |
| 5121 | const start = pos; |
| 5122 | const end = pos + len; |
| 5123 | let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start); |
| 5124 | if (diffs[i][0] > start) { |
| 5125 | --i; |
| 5126 | } |
| 5127 | let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i); |
| 5128 | if (diffs[j][0] > end) { |
| 5129 | --j; |
| 5130 | } |
| 5131 | return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]]; |
| 5132 | } |
| 5133 | class PDFFindController { |
| 5134 | #updateMatchesCountOnProgress = true; |
| 5135 | #visitedPagesCount = 0; |
| 5136 | constructor({ |
| 5137 | linkService, |
| 5138 | eventBus, |
| 5139 | updateMatchesCountOnProgress = true |
| 5140 | }) { |
| 5141 | this._linkService = linkService; |
| 5142 | this._eventBus = eventBus; |
| 5143 | this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress; |
| 5144 | this.#reset(); |
| 5145 | eventBus._on("find", this.#onFind.bind(this)); |
| 5146 | eventBus._on("findbarclose", this.#onFindBarClose.bind(this)); |
| 5147 | } |
| 5148 | get highlightMatches() { |
| 5149 | return this._highlightMatches; |
| 5150 | } |
| 5151 | get pageMatches() { |
| 5152 | return this._pageMatches; |
| 5153 | } |
| 5154 | get pageMatchesLength() { |
| 5155 | return this._pageMatchesLength; |
| 5156 | } |
| 5157 | get selected() { |
| 5158 | return this._selected; |
| 5159 | } |
| 5160 | get state() { |
| 5161 | return this._state; |
| 5162 | } |
| 5163 | setDocument(pdfDocument) { |
| 5164 | if (this._pdfDocument) { |
| 5165 | this.#reset(); |
| 5166 | } |
| 5167 | if (!pdfDocument) { |
| 5168 | return; |
| 5169 | } |
| 5170 | this._pdfDocument = pdfDocument; |
| 5171 | this._firstPageCapability.resolve(); |
| 5172 | } |
| 5173 | #onFind(state) { |
| 5174 | if (!state) { |
| 5175 | return; |
| 5176 | } |
| 5177 | const pdfDocument = this._pdfDocument; |
| 5178 | const { |
| 5179 | type |
| 5180 | } = state; |
| 5181 | if (this._state === null || this.#shouldDirtyMatch(state)) { |
| 5182 | this._dirtyMatch = true; |
| 5183 | } |
| 5184 | this._state = state; |
| 5185 | if (type !== "highlightallchange") { |
| 5186 | this.#updateUIState(FindState.PENDING); |
| 5187 | } |
| 5188 | this._firstPageCapability.promise.then(() => { |
| 5189 | if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { |
| 5190 | return; |
| 5191 | } |
| 5192 | this.#extractText(); |
| 5193 | const findbarClosed = !this._highlightMatches; |
| 5194 | const pendingTimeout = !!this._findTimeout; |
| 5195 | if (this._findTimeout) { |
| 5196 | clearTimeout(this._findTimeout); |
| 5197 | this._findTimeout = null; |
| 5198 | } |
| 5199 | if (!type) { |
| 5200 | this._findTimeout = setTimeout(() => { |
| 5201 | this.#nextMatch(); |
| 5202 | this._findTimeout = null; |
| 5203 | }, FIND_TIMEOUT); |
| 5204 | } else if (this._dirtyMatch) { |
| 5205 | this.#nextMatch(); |
| 5206 | } else if (type === "again") { |
| 5207 | this.#nextMatch(); |
| 5208 | if (findbarClosed && this._state.highlightAll) { |
| 5209 | this.#updateAllPages(); |
| 5210 | } |
| 5211 | } else if (type === "highlightallchange") { |
| 5212 | if (pendingTimeout) { |
| 5213 | this.#nextMatch(); |
| 5214 | } else { |
| 5215 | this._highlightMatches = true; |
| 5216 | } |
| 5217 | this.#updateAllPages(); |
| 5218 | } else { |
| 5219 | this.#nextMatch(); |
| 5220 | } |
| 5221 | }); |
| 5222 | } |
| 5223 | scrollMatchIntoView({ |
| 5224 | element = null, |
| 5225 | selectedLeft = 0, |
| 5226 | pageIndex = -1, |
| 5227 | matchIndex = -1 |
| 5228 | }) { |
| 5229 | if (!this._scrollMatches || !element) { |
| 5230 | return; |
| 5231 | } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) { |
| 5232 | return; |
| 5233 | } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) { |
| 5234 | return; |
| 5235 | } |
| 5236 | this._scrollMatches = false; |
| 5237 | const spot = { |
| 5238 | top: MATCH_SCROLL_OFFSET_TOP, |
| 5239 | left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT |
| 5240 | }; |
| 5241 | (0, _ui_utils.scrollIntoView)(element, spot, true); |
| 5242 | } |
| 5243 | #reset() { |
| 5244 | this._highlightMatches = false; |
| 5245 | this._scrollMatches = false; |
| 5246 | this._pdfDocument = null; |
| 5247 | this._pageMatches = []; |
| 5248 | this._pageMatchesLength = []; |
| 5249 | this.#visitedPagesCount = 0; |
| 5250 | this._state = null; |
| 5251 | this._selected = { |
| 5252 | pageIdx: -1, |
| 5253 | matchIdx: -1 |
| 5254 | }; |
| 5255 | this._offset = { |
| 5256 | pageIdx: null, |
| 5257 | matchIdx: null, |
| 5258 | wrapped: false |
| 5259 | }; |
| 5260 | this._extractTextPromises = []; |
| 5261 | this._pageContents = []; |
| 5262 | this._pageDiffs = []; |
| 5263 | this._hasDiacritics = []; |
| 5264 | this._matchesCountTotal = 0; |
| 5265 | this._pagesToSearch = null; |
| 5266 | this._pendingFindMatches = new Set(); |
| 5267 | this._resumePageIdx = null; |
| 5268 | this._dirtyMatch = false; |
| 5269 | clearTimeout(this._findTimeout); |
| 5270 | this._findTimeout = null; |
| 5271 | this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 5272 | } |
| 5273 | get #query() { |
| 5274 | if (this._state.query !== this._rawQuery) { |
| 5275 | this._rawQuery = this._state.query; |
| 5276 | [this._normalizedQuery] = normalize(this._state.query); |
| 5277 | } |
| 5278 | return this._normalizedQuery; |
| 5279 | } |
| 5280 | #shouldDirtyMatch(state) { |
| 5281 | if (state.query !== this._state.query) { |
| 5282 | return true; |
| 5283 | } |
| 5284 | switch (state.type) { |
| 5285 | case "again": |
| 5286 | const pageNumber = this._selected.pageIdx + 1; |
| 5287 | const linkService = this._linkService; |
| 5288 | if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) { |
| 5289 | return true; |
| 5290 | } |
| 5291 | return false; |
| 5292 | case "highlightallchange": |
| 5293 | return false; |
| 5294 | } |
| 5295 | return true; |
| 5296 | } |
| 5297 | #isEntireWord(content, startIdx, length) { |
| 5298 | let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP); |
| 5299 | if (match) { |
| 5300 | const first = content.charCodeAt(startIdx); |
| 5301 | const limit = match[1].charCodeAt(0); |
| 5302 | if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) { |
| 5303 | return false; |
| 5304 | } |
| 5305 | } |
| 5306 | match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP); |
| 5307 | if (match) { |
| 5308 | const last = content.charCodeAt(startIdx + length - 1); |
| 5309 | const limit = match[1].charCodeAt(0); |
| 5310 | if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) { |
| 5311 | return false; |
| 5312 | } |
| 5313 | } |
| 5314 | return true; |
| 5315 | } |
| 5316 | #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) { |
| 5317 | const matches = this._pageMatches[pageIndex] = []; |
| 5318 | const matchesLength = this._pageMatchesLength[pageIndex] = []; |
| 5319 | if (!query) { |
| 5320 | return; |
| 5321 | } |
| 5322 | const diffs = this._pageDiffs[pageIndex]; |
| 5323 | let match; |
| 5324 | while ((match = query.exec(pageContent)) !== null) { |
| 5325 | if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) { |
| 5326 | continue; |
| 5327 | } |
| 5328 | const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length); |
| 5329 | if (matchLen) { |
| 5330 | matches.push(matchPos); |
| 5331 | matchesLength.push(matchLen); |
| 5332 | } |
| 5333 | } |
| 5334 | } |
| 5335 | #convertToRegExpString(query, hasDiacritics) { |
| 5336 | const { |
| 5337 | matchDiacritics |
| 5338 | } = this._state; |
| 5339 | let isUnicode = false; |
| 5340 | query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => { |
| 5341 | if (p1) { |
| 5342 | return `[ ]*\\${p1}[ ]*`; |
| 5343 | } |
| 5344 | if (p2) { |
| 5345 | return `[ ]*${p2}[ ]*`; |
| 5346 | } |
| 5347 | if (p3) { |
| 5348 | return "[ ]+"; |
| 5349 | } |
| 5350 | if (matchDiacritics) { |
| 5351 | return p4 || p5; |
| 5352 | } |
| 5353 | if (p4) { |
| 5354 | return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : ""; |
| 5355 | } |
| 5356 | if (hasDiacritics) { |
| 5357 | isUnicode = true; |
| 5358 | return `${p5}\\p{M}*`; |
| 5359 | } |
| 5360 | return p5; |
| 5361 | }); |
| 5362 | const trailingSpaces = "[ ]*"; |
| 5363 | if (query.endsWith(trailingSpaces)) { |
| 5364 | query = query.slice(0, query.length - trailingSpaces.length); |
| 5365 | } |
| 5366 | if (matchDiacritics) { |
| 5367 | if (hasDiacritics) { |
| 5368 | DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION); |
| 5369 | isUnicode = true; |
| 5370 | query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`; |
| 5371 | } |
| 5372 | } |
| 5373 | return [isUnicode, query]; |
| 5374 | } |
| 5375 | #calculateMatch(pageIndex) { |
| 5376 | let query = this.#query; |
| 5377 | if (!query) { |
| 5378 | return; |
| 5379 | } |
| 5380 | const { |
| 5381 | caseSensitive, |
| 5382 | entireWord, |
| 5383 | phraseSearch |
| 5384 | } = this._state; |
| 5385 | const pageContent = this._pageContents[pageIndex]; |
| 5386 | const hasDiacritics = this._hasDiacritics[pageIndex]; |
| 5387 | let isUnicode = false; |
| 5388 | if (phraseSearch) { |
| 5389 | [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics); |
| 5390 | } else { |
| 5391 | const match = query.match(/\S+/g); |
| 5392 | if (match) { |
| 5393 | query = match.sort().reverse().map(q => { |
| 5394 | const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics); |
| 5395 | isUnicode ||= isUnicodePart; |
| 5396 | return `(${queryPart})`; |
| 5397 | }).join("|"); |
| 5398 | } |
| 5399 | } |
| 5400 | const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`; |
| 5401 | query = query ? new RegExp(query, flags) : null; |
| 5402 | this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent); |
| 5403 | if (this._state.highlightAll) { |
| 5404 | this.#updatePage(pageIndex); |
| 5405 | } |
| 5406 | if (this._resumePageIdx === pageIndex) { |
| 5407 | this._resumePageIdx = null; |
| 5408 | this.#nextPageMatch(); |
| 5409 | } |
| 5410 | const pageMatchesCount = this._pageMatches[pageIndex].length; |
| 5411 | this._matchesCountTotal += pageMatchesCount; |
| 5412 | if (this.#updateMatchesCountOnProgress) { |
| 5413 | if (pageMatchesCount > 0) { |
| 5414 | this.#updateUIResultsCount(); |
| 5415 | } |
| 5416 | } else if (++this.#visitedPagesCount === this._linkService.pagesCount) { |
| 5417 | this.#updateUIResultsCount(); |
| 5418 | } |
| 5419 | } |
| 5420 | #extractText() { |
| 5421 | if (this._extractTextPromises.length > 0) { |
| 5422 | return; |
| 5423 | } |
| 5424 | let promise = Promise.resolve(); |
| 5425 | for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) { |
| 5426 | const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 5427 | this._extractTextPromises[i] = extractTextCapability.promise; |
| 5428 | promise = promise.then(() => { |
| 5429 | return this._pdfDocument.getPage(i + 1).then(pdfPage => { |
| 5430 | return pdfPage.getTextContent(); |
| 5431 | }).then(textContent => { |
| 5432 | const strBuf = []; |
| 5433 | for (const textItem of textContent.items) { |
| 5434 | strBuf.push(textItem.str); |
| 5435 | if (textItem.hasEOL) { |
| 5436 | strBuf.push("\n"); |
| 5437 | } |
| 5438 | } |
| 5439 | [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join("")); |
| 5440 | extractTextCapability.resolve(); |
| 5441 | }, reason => { |
| 5442 | console.error(`Unable to get text content for page ${i + 1}`, reason); |
| 5443 | this._pageContents[i] = ""; |
| 5444 | this._pageDiffs[i] = null; |
| 5445 | this._hasDiacritics[i] = false; |
| 5446 | extractTextCapability.resolve(); |
| 5447 | }); |
| 5448 | }); |
| 5449 | } |
| 5450 | } |
| 5451 | #updatePage(index) { |
| 5452 | if (this._scrollMatches && this._selected.pageIdx === index) { |
| 5453 | this._linkService.page = index + 1; |
| 5454 | } |
| 5455 | this._eventBus.dispatch("updatetextlayermatches", { |
| 5456 | source: this, |
| 5457 | pageIndex: index |
| 5458 | }); |
| 5459 | } |
| 5460 | #updateAllPages() { |
| 5461 | this._eventBus.dispatch("updatetextlayermatches", { |
| 5462 | source: this, |
| 5463 | pageIndex: -1 |
| 5464 | }); |
| 5465 | } |
| 5466 | #nextMatch() { |
| 5467 | const previous = this._state.findPrevious; |
| 5468 | const currentPageIndex = this._linkService.page - 1; |
| 5469 | const numPages = this._linkService.pagesCount; |
| 5470 | this._highlightMatches = true; |
| 5471 | if (this._dirtyMatch) { |
| 5472 | this._dirtyMatch = false; |
| 5473 | this._selected.pageIdx = this._selected.matchIdx = -1; |
| 5474 | this._offset.pageIdx = currentPageIndex; |
| 5475 | this._offset.matchIdx = null; |
| 5476 | this._offset.wrapped = false; |
| 5477 | this._resumePageIdx = null; |
| 5478 | this._pageMatches.length = 0; |
| 5479 | this._pageMatchesLength.length = 0; |
| 5480 | this.#visitedPagesCount = 0; |
| 5481 | this._matchesCountTotal = 0; |
| 5482 | this.#updateAllPages(); |
| 5483 | for (let i = 0; i < numPages; i++) { |
| 5484 | if (this._pendingFindMatches.has(i)) { |
| 5485 | continue; |
| 5486 | } |
| 5487 | this._pendingFindMatches.add(i); |
| 5488 | this._extractTextPromises[i].then(() => { |
| 5489 | this._pendingFindMatches.delete(i); |
| 5490 | this.#calculateMatch(i); |
| 5491 | }); |
| 5492 | } |
| 5493 | } |
| 5494 | if (!this.#query) { |
| 5495 | this.#updateUIState(FindState.FOUND); |
| 5496 | return; |
| 5497 | } |
| 5498 | if (this._resumePageIdx) { |
| 5499 | return; |
| 5500 | } |
| 5501 | const offset = this._offset; |
| 5502 | this._pagesToSearch = numPages; |
| 5503 | if (offset.matchIdx !== null) { |
| 5504 | const numPageMatches = this._pageMatches[offset.pageIdx].length; |
| 5505 | if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) { |
| 5506 | offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1; |
| 5507 | this.#updateMatch(true); |
| 5508 | return; |
| 5509 | } |
| 5510 | this.#advanceOffsetPage(previous); |
| 5511 | } |
| 5512 | this.#nextPageMatch(); |
| 5513 | } |
| 5514 | #matchesReady(matches) { |
| 5515 | const offset = this._offset; |
| 5516 | const numMatches = matches.length; |
| 5517 | const previous = this._state.findPrevious; |
| 5518 | if (numMatches) { |
| 5519 | offset.matchIdx = previous ? numMatches - 1 : 0; |
| 5520 | this.#updateMatch(true); |
| 5521 | return true; |
| 5522 | } |
| 5523 | this.#advanceOffsetPage(previous); |
| 5524 | if (offset.wrapped) { |
| 5525 | offset.matchIdx = null; |
| 5526 | if (this._pagesToSearch < 0) { |
| 5527 | this.#updateMatch(false); |
| 5528 | return true; |
| 5529 | } |
| 5530 | } |
| 5531 | return false; |
| 5532 | } |
| 5533 | #nextPageMatch() { |
| 5534 | if (this._resumePageIdx !== null) { |
| 5535 | console.error("There can only be one pending page."); |
| 5536 | } |
| 5537 | let matches = null; |
| 5538 | do { |
| 5539 | const pageIdx = this._offset.pageIdx; |
| 5540 | matches = this._pageMatches[pageIdx]; |
| 5541 | if (!matches) { |
| 5542 | this._resumePageIdx = pageIdx; |
| 5543 | break; |
| 5544 | } |
| 5545 | } while (!this.#matchesReady(matches)); |
| 5546 | } |
| 5547 | #advanceOffsetPage(previous) { |
| 5548 | const offset = this._offset; |
| 5549 | const numPages = this._linkService.pagesCount; |
| 5550 | offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1; |
| 5551 | offset.matchIdx = null; |
| 5552 | this._pagesToSearch--; |
| 5553 | if (offset.pageIdx >= numPages || offset.pageIdx < 0) { |
| 5554 | offset.pageIdx = previous ? numPages - 1 : 0; |
| 5555 | offset.wrapped = true; |
| 5556 | } |
| 5557 | } |
| 5558 | #updateMatch(found = false) { |
| 5559 | let state = FindState.NOT_FOUND; |
| 5560 | const wrapped = this._offset.wrapped; |
| 5561 | this._offset.wrapped = false; |
| 5562 | if (found) { |
| 5563 | const previousPage = this._selected.pageIdx; |
| 5564 | this._selected.pageIdx = this._offset.pageIdx; |
| 5565 | this._selected.matchIdx = this._offset.matchIdx; |
| 5566 | state = wrapped ? FindState.WRAPPED : FindState.FOUND; |
| 5567 | if (previousPage !== -1 && previousPage !== this._selected.pageIdx) { |
| 5568 | this.#updatePage(previousPage); |
| 5569 | } |
| 5570 | } |
| 5571 | this.#updateUIState(state, this._state.findPrevious); |
| 5572 | if (this._selected.pageIdx !== -1) { |
| 5573 | this._scrollMatches = true; |
| 5574 | this.#updatePage(this._selected.pageIdx); |
| 5575 | } |
| 5576 | } |
| 5577 | #onFindBarClose(evt) { |
| 5578 | const pdfDocument = this._pdfDocument; |
| 5579 | this._firstPageCapability.promise.then(() => { |
| 5580 | if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { |
| 5581 | return; |
| 5582 | } |
| 5583 | if (this._findTimeout) { |
| 5584 | clearTimeout(this._findTimeout); |
| 5585 | this._findTimeout = null; |
| 5586 | } |
| 5587 | if (this._resumePageIdx) { |
| 5588 | this._resumePageIdx = null; |
| 5589 | this._dirtyMatch = true; |
| 5590 | } |
| 5591 | this.#updateUIState(FindState.FOUND); |
| 5592 | this._highlightMatches = false; |
| 5593 | this.#updateAllPages(); |
| 5594 | }); |
| 5595 | } |
| 5596 | #requestMatchesCount() { |
| 5597 | const { |
| 5598 | pageIdx, |
| 5599 | matchIdx |
| 5600 | } = this._selected; |
| 5601 | let current = 0, |
| 5602 | total = this._matchesCountTotal; |
| 5603 | if (matchIdx !== -1) { |
| 5604 | for (let i = 0; i < pageIdx; i++) { |
| 5605 | current += this._pageMatches[i]?.length || 0; |
| 5606 | } |
| 5607 | current += matchIdx + 1; |
| 5608 | } |
| 5609 | if (current < 1 || current > total) { |
| 5610 | current = total = 0; |
| 5611 | } |
| 5612 | return { |
| 5613 | current, |
| 5614 | total |
| 5615 | }; |
| 5616 | } |
| 5617 | #updateUIResultsCount() { |
| 5618 | this._eventBus.dispatch("updatefindmatchescount", { |
| 5619 | source: this, |
| 5620 | matchesCount: this.#requestMatchesCount() |
| 5621 | }); |
| 5622 | } |
| 5623 | #updateUIState(state, previous = false) { |
| 5624 | if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) { |
| 5625 | return; |
| 5626 | } |
| 5627 | this._eventBus.dispatch("updatefindcontrolstate", { |
| 5628 | source: this, |
| 5629 | state, |
| 5630 | previous, |
| 5631 | matchesCount: this.#requestMatchesCount(), |
| 5632 | rawQuery: this._state?.query ?? null |
| 5633 | }); |
| 5634 | } |
| 5635 | } |
| 5636 | exports.PDFFindController = PDFFindController; |
| 5637 | |
| 5638 | /***/ }), |
| 5639 | /* 17 */ |
| 5640 | /***/ ((__unused_webpack_module, exports) => { |
| 5641 | |
| 5642 | |
| 5643 | |
| 5644 | Object.defineProperty(exports, "__esModule", ({ |
| 5645 | value: true |
| 5646 | })); |
| 5647 | exports.CharacterType = void 0; |
| 5648 | exports.getCharacterType = getCharacterType; |
| 5649 | const CharacterType = { |
| 5650 | SPACE: 0, |
| 5651 | ALPHA_LETTER: 1, |
| 5652 | PUNCT: 2, |
| 5653 | HAN_LETTER: 3, |
| 5654 | KATAKANA_LETTER: 4, |
| 5655 | HIRAGANA_LETTER: 5, |
| 5656 | HALFWIDTH_KATAKANA_LETTER: 6, |
| 5657 | THAI_LETTER: 7 |
| 5658 | }; |
| 5659 | exports.CharacterType = CharacterType; |
| 5660 | function isAlphabeticalScript(charCode) { |
| 5661 | return charCode < 0x2e80; |
| 5662 | } |
| 5663 | function isAscii(charCode) { |
| 5664 | return (charCode & 0xff80) === 0; |
| 5665 | } |
| 5666 | function isAsciiAlpha(charCode) { |
| 5667 | return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a; |
| 5668 | } |
| 5669 | function isAsciiDigit(charCode) { |
| 5670 | return charCode >= 0x30 && charCode <= 0x39; |
| 5671 | } |
| 5672 | function isAsciiSpace(charCode) { |
| 5673 | return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a; |
| 5674 | } |
| 5675 | function isHan(charCode) { |
| 5676 | return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff; |
| 5677 | } |
| 5678 | function isKatakana(charCode) { |
| 5679 | return charCode >= 0x30a0 && charCode <= 0x30ff; |
| 5680 | } |
| 5681 | function isHiragana(charCode) { |
| 5682 | return charCode >= 0x3040 && charCode <= 0x309f; |
| 5683 | } |
| 5684 | function isHalfwidthKatakana(charCode) { |
| 5685 | return charCode >= 0xff60 && charCode <= 0xff9f; |
| 5686 | } |
| 5687 | function isThai(charCode) { |
| 5688 | return (charCode & 0xff80) === 0x0e00; |
| 5689 | } |
| 5690 | function getCharacterType(charCode) { |
| 5691 | if (isAlphabeticalScript(charCode)) { |
| 5692 | if (isAscii(charCode)) { |
| 5693 | if (isAsciiSpace(charCode)) { |
| 5694 | return CharacterType.SPACE; |
| 5695 | } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) { |
| 5696 | return CharacterType.ALPHA_LETTER; |
| 5697 | } |
| 5698 | return CharacterType.PUNCT; |
| 5699 | } else if (isThai(charCode)) { |
| 5700 | return CharacterType.THAI_LETTER; |
| 5701 | } else if (charCode === 0xa0) { |
| 5702 | return CharacterType.SPACE; |
| 5703 | } |
| 5704 | return CharacterType.ALPHA_LETTER; |
| 5705 | } |
| 5706 | if (isHan(charCode)) { |
| 5707 | return CharacterType.HAN_LETTER; |
| 5708 | } else if (isKatakana(charCode)) { |
| 5709 | return CharacterType.KATAKANA_LETTER; |
| 5710 | } else if (isHiragana(charCode)) { |
| 5711 | return CharacterType.HIRAGANA_LETTER; |
| 5712 | } else if (isHalfwidthKatakana(charCode)) { |
| 5713 | return CharacterType.HALFWIDTH_KATAKANA_LETTER; |
| 5714 | } |
| 5715 | return CharacterType.ALPHA_LETTER; |
| 5716 | } |
| 5717 | |
| 5718 | /***/ }), |
| 5719 | /* 18 */ |
| 5720 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 5721 | |
| 5722 | |
| 5723 | |
| 5724 | Object.defineProperty(exports, "__esModule", ({ |
| 5725 | value: true |
| 5726 | })); |
| 5727 | exports.PDFHistory = void 0; |
| 5728 | exports.isDestArraysEqual = isDestArraysEqual; |
| 5729 | exports.isDestHashesEqual = isDestHashesEqual; |
| 5730 | var _ui_utils = __webpack_require__(1); |
| 5731 | var _event_utils = __webpack_require__(6); |
| 5732 | const HASH_CHANGE_TIMEOUT = 1000; |
| 5733 | const POSITION_UPDATED_THRESHOLD = 50; |
| 5734 | const UPDATE_VIEWAREA_TIMEOUT = 1000; |
| 5735 | function getCurrentHash() { |
| 5736 | return document.location.hash; |
| 5737 | } |
| 5738 | class PDFHistory { |
| 5739 | constructor({ |
| 5740 | linkService, |
| 5741 | eventBus |
| 5742 | }) { |
| 5743 | this.linkService = linkService; |
| 5744 | this.eventBus = eventBus; |
| 5745 | this._initialized = false; |
| 5746 | this._fingerprint = ""; |
| 5747 | this.reset(); |
| 5748 | this._boundEvents = null; |
| 5749 | this.eventBus._on("pagesinit", () => { |
| 5750 | this._isPagesLoaded = false; |
| 5751 | this.eventBus._on("pagesloaded", evt => { |
| 5752 | this._isPagesLoaded = !!evt.pagesCount; |
| 5753 | }, { |
| 5754 | once: true |
| 5755 | }); |
| 5756 | }); |
| 5757 | } |
| 5758 | initialize({ |
| 5759 | fingerprint, |
| 5760 | resetHistory = false, |
| 5761 | updateUrl = false |
| 5762 | }) { |
| 5763 | if (!fingerprint || typeof fingerprint !== "string") { |
| 5764 | console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.'); |
| 5765 | return; |
| 5766 | } |
| 5767 | if (this._initialized) { |
| 5768 | this.reset(); |
| 5769 | } |
| 5770 | const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint; |
| 5771 | this._fingerprint = fingerprint; |
| 5772 | this._updateUrl = updateUrl === true; |
| 5773 | this._initialized = true; |
| 5774 | this._bindEvents(); |
| 5775 | const state = window.history.state; |
| 5776 | this._popStateInProgress = false; |
| 5777 | this._blockHashChange = 0; |
| 5778 | this._currentHash = getCurrentHash(); |
| 5779 | this._numPositionUpdates = 0; |
| 5780 | this._uid = this._maxUid = 0; |
| 5781 | this._destination = null; |
| 5782 | this._position = null; |
| 5783 | if (!this._isValidState(state, true) || resetHistory) { |
| 5784 | const { |
| 5785 | hash, |
| 5786 | page, |
| 5787 | rotation |
| 5788 | } = this._parseCurrentHash(true); |
| 5789 | if (!hash || reInitialized || resetHistory) { |
| 5790 | this._pushOrReplaceState(null, true); |
| 5791 | return; |
| 5792 | } |
| 5793 | this._pushOrReplaceState({ |
| 5794 | hash, |
| 5795 | page, |
| 5796 | rotation |
| 5797 | }, true); |
| 5798 | return; |
| 5799 | } |
| 5800 | const destination = state.destination; |
| 5801 | this._updateInternalState(destination, state.uid, true); |
| 5802 | if (destination.rotation !== undefined) { |
| 5803 | this._initialRotation = destination.rotation; |
| 5804 | } |
| 5805 | if (destination.dest) { |
| 5806 | this._initialBookmark = JSON.stringify(destination.dest); |
| 5807 | this._destination.page = null; |
| 5808 | } else if (destination.hash) { |
| 5809 | this._initialBookmark = destination.hash; |
| 5810 | } else if (destination.page) { |
| 5811 | this._initialBookmark = `page=${destination.page}`; |
| 5812 | } |
| 5813 | } |
| 5814 | reset() { |
| 5815 | if (this._initialized) { |
| 5816 | this._pageHide(); |
| 5817 | this._initialized = false; |
| 5818 | this._unbindEvents(); |
| 5819 | } |
| 5820 | if (this._updateViewareaTimeout) { |
| 5821 | clearTimeout(this._updateViewareaTimeout); |
| 5822 | this._updateViewareaTimeout = null; |
| 5823 | } |
| 5824 | this._initialBookmark = null; |
| 5825 | this._initialRotation = null; |
| 5826 | } |
| 5827 | push({ |
| 5828 | namedDest = null, |
| 5829 | explicitDest, |
| 5830 | pageNumber |
| 5831 | }) { |
| 5832 | if (!this._initialized) { |
| 5833 | return; |
| 5834 | } |
| 5835 | if (namedDest && typeof namedDest !== "string") { |
| 5836 | console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`); |
| 5837 | return; |
| 5838 | } else if (!Array.isArray(explicitDest)) { |
| 5839 | console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`); |
| 5840 | return; |
| 5841 | } else if (!this._isValidPage(pageNumber)) { |
| 5842 | if (pageNumber !== null || this._destination) { |
| 5843 | console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`); |
| 5844 | return; |
| 5845 | } |
| 5846 | } |
| 5847 | const hash = namedDest || JSON.stringify(explicitDest); |
| 5848 | if (!hash) { |
| 5849 | return; |
| 5850 | } |
| 5851 | let forceReplace = false; |
| 5852 | if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) { |
| 5853 | if (this._destination.page) { |
| 5854 | return; |
| 5855 | } |
| 5856 | forceReplace = true; |
| 5857 | } |
| 5858 | if (this._popStateInProgress && !forceReplace) { |
| 5859 | return; |
| 5860 | } |
| 5861 | this._pushOrReplaceState({ |
| 5862 | dest: explicitDest, |
| 5863 | hash, |
| 5864 | page: pageNumber, |
| 5865 | rotation: this.linkService.rotation |
| 5866 | }, forceReplace); |
| 5867 | if (!this._popStateInProgress) { |
| 5868 | this._popStateInProgress = true; |
| 5869 | Promise.resolve().then(() => { |
| 5870 | this._popStateInProgress = false; |
| 5871 | }); |
| 5872 | } |
| 5873 | } |
| 5874 | pushPage(pageNumber) { |
| 5875 | if (!this._initialized) { |
| 5876 | return; |
| 5877 | } |
| 5878 | if (!this._isValidPage(pageNumber)) { |
| 5879 | console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`); |
| 5880 | return; |
| 5881 | } |
| 5882 | if (this._destination?.page === pageNumber) { |
| 5883 | return; |
| 5884 | } |
| 5885 | if (this._popStateInProgress) { |
| 5886 | return; |
| 5887 | } |
| 5888 | this._pushOrReplaceState({ |
| 5889 | dest: null, |
| 5890 | hash: `page=${pageNumber}`, |
| 5891 | page: pageNumber, |
| 5892 | rotation: this.linkService.rotation |
| 5893 | }); |
| 5894 | if (!this._popStateInProgress) { |
| 5895 | this._popStateInProgress = true; |
| 5896 | Promise.resolve().then(() => { |
| 5897 | this._popStateInProgress = false; |
| 5898 | }); |
| 5899 | } |
| 5900 | } |
| 5901 | pushCurrentPosition() { |
| 5902 | if (!this._initialized || this._popStateInProgress) { |
| 5903 | return; |
| 5904 | } |
| 5905 | this._tryPushCurrentPosition(); |
| 5906 | } |
| 5907 | back() { |
| 5908 | if (!this._initialized || this._popStateInProgress) { |
| 5909 | return; |
| 5910 | } |
| 5911 | const state = window.history.state; |
| 5912 | if (this._isValidState(state) && state.uid > 0) { |
| 5913 | window.history.back(); |
| 5914 | } |
| 5915 | } |
| 5916 | forward() { |
| 5917 | if (!this._initialized || this._popStateInProgress) { |
| 5918 | return; |
| 5919 | } |
| 5920 | const state = window.history.state; |
| 5921 | if (this._isValidState(state) && state.uid < this._maxUid) { |
| 5922 | window.history.forward(); |
| 5923 | } |
| 5924 | } |
| 5925 | get popStateInProgress() { |
| 5926 | return this._initialized && (this._popStateInProgress || this._blockHashChange > 0); |
| 5927 | } |
| 5928 | get initialBookmark() { |
| 5929 | return this._initialized ? this._initialBookmark : null; |
| 5930 | } |
| 5931 | get initialRotation() { |
| 5932 | return this._initialized ? this._initialRotation : null; |
| 5933 | } |
| 5934 | _pushOrReplaceState(destination, forceReplace = false) { |
| 5935 | const shouldReplace = forceReplace || !this._destination; |
| 5936 | const newState = { |
| 5937 | fingerprint: this._fingerprint, |
| 5938 | uid: shouldReplace ? this._uid : this._uid + 1, |
| 5939 | destination |
| 5940 | }; |
| 5941 | this._updateInternalState(destination, newState.uid); |
| 5942 | let newUrl; |
| 5943 | if (this._updateUrl && destination?.hash) { |
| 5944 | const baseUrl = document.location.href.split("#")[0]; |
| 5945 | if (!baseUrl.startsWith("file://")) { |
| 5946 | newUrl = `${baseUrl}#${destination.hash}`; |
| 5947 | } |
| 5948 | } |
| 5949 | if (shouldReplace) { |
| 5950 | window.history.replaceState(newState, "", newUrl); |
| 5951 | } else { |
| 5952 | window.history.pushState(newState, "", newUrl); |
| 5953 | } |
| 5954 | } |
| 5955 | _tryPushCurrentPosition(temporary = false) { |
| 5956 | if (!this._position) { |
| 5957 | return; |
| 5958 | } |
| 5959 | let position = this._position; |
| 5960 | if (temporary) { |
| 5961 | position = Object.assign(Object.create(null), this._position); |
| 5962 | position.temporary = true; |
| 5963 | } |
| 5964 | if (!this._destination) { |
| 5965 | this._pushOrReplaceState(position); |
| 5966 | return; |
| 5967 | } |
| 5968 | if (this._destination.temporary) { |
| 5969 | this._pushOrReplaceState(position, true); |
| 5970 | return; |
| 5971 | } |
| 5972 | if (this._destination.hash === position.hash) { |
| 5973 | return; |
| 5974 | } |
| 5975 | if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) { |
| 5976 | return; |
| 5977 | } |
| 5978 | let forceReplace = false; |
| 5979 | if (this._destination.page >= position.first && this._destination.page <= position.page) { |
| 5980 | if (this._destination.dest !== undefined || !this._destination.first) { |
| 5981 | return; |
| 5982 | } |
| 5983 | forceReplace = true; |
| 5984 | } |
| 5985 | this._pushOrReplaceState(position, forceReplace); |
| 5986 | } |
| 5987 | _isValidPage(val) { |
| 5988 | return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount; |
| 5989 | } |
| 5990 | _isValidState(state, checkReload = false) { |
| 5991 | if (!state) { |
| 5992 | return false; |
| 5993 | } |
| 5994 | if (state.fingerprint !== this._fingerprint) { |
| 5995 | if (checkReload) { |
| 5996 | if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) { |
| 5997 | return false; |
| 5998 | } |
| 5999 | const [perfEntry] = performance.getEntriesByType("navigation"); |
| 6000 | if (perfEntry?.type !== "reload") { |
| 6001 | return false; |
| 6002 | } |
| 6003 | } else { |
| 6004 | return false; |
| 6005 | } |
| 6006 | } |
| 6007 | if (!Number.isInteger(state.uid) || state.uid < 0) { |
| 6008 | return false; |
| 6009 | } |
| 6010 | if (state.destination === null || typeof state.destination !== "object") { |
| 6011 | return false; |
| 6012 | } |
| 6013 | return true; |
| 6014 | } |
| 6015 | _updateInternalState(destination, uid, removeTemporary = false) { |
| 6016 | if (this._updateViewareaTimeout) { |
| 6017 | clearTimeout(this._updateViewareaTimeout); |
| 6018 | this._updateViewareaTimeout = null; |
| 6019 | } |
| 6020 | if (removeTemporary && destination?.temporary) { |
| 6021 | delete destination.temporary; |
| 6022 | } |
| 6023 | this._destination = destination; |
| 6024 | this._uid = uid; |
| 6025 | this._maxUid = Math.max(this._maxUid, uid); |
| 6026 | this._numPositionUpdates = 0; |
| 6027 | } |
| 6028 | _parseCurrentHash(checkNameddest = false) { |
| 6029 | const hash = unescape(getCurrentHash()).substring(1); |
| 6030 | const params = (0, _ui_utils.parseQueryString)(hash); |
| 6031 | const nameddest = params.get("nameddest") || ""; |
| 6032 | let page = params.get("page") | 0; |
| 6033 | if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) { |
| 6034 | page = null; |
| 6035 | } |
| 6036 | return { |
| 6037 | hash, |
| 6038 | page, |
| 6039 | rotation: this.linkService.rotation |
| 6040 | }; |
| 6041 | } |
| 6042 | _updateViewarea({ |
| 6043 | location |
| 6044 | }) { |
| 6045 | if (this._updateViewareaTimeout) { |
| 6046 | clearTimeout(this._updateViewareaTimeout); |
| 6047 | this._updateViewareaTimeout = null; |
| 6048 | } |
| 6049 | this._position = { |
| 6050 | hash: location.pdfOpenParams.substring(1), |
| 6051 | page: this.linkService.page, |
| 6052 | first: location.pageNumber, |
| 6053 | rotation: location.rotation |
| 6054 | }; |
| 6055 | if (this._popStateInProgress) { |
| 6056 | return; |
| 6057 | } |
| 6058 | if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) { |
| 6059 | this._numPositionUpdates++; |
| 6060 | } |
| 6061 | if (UPDATE_VIEWAREA_TIMEOUT > 0) { |
| 6062 | this._updateViewareaTimeout = setTimeout(() => { |
| 6063 | if (!this._popStateInProgress) { |
| 6064 | this._tryPushCurrentPosition(true); |
| 6065 | } |
| 6066 | this._updateViewareaTimeout = null; |
| 6067 | }, UPDATE_VIEWAREA_TIMEOUT); |
| 6068 | } |
| 6069 | } |
| 6070 | _popState({ |
| 6071 | state |
| 6072 | }) { |
| 6073 | const newHash = getCurrentHash(), |
| 6074 | hashChanged = this._currentHash !== newHash; |
| 6075 | this._currentHash = newHash; |
| 6076 | if (!state) { |
| 6077 | this._uid++; |
| 6078 | const { |
| 6079 | hash, |
| 6080 | page, |
| 6081 | rotation |
| 6082 | } = this._parseCurrentHash(); |
| 6083 | this._pushOrReplaceState({ |
| 6084 | hash, |
| 6085 | page, |
| 6086 | rotation |
| 6087 | }, true); |
| 6088 | return; |
| 6089 | } |
| 6090 | if (!this._isValidState(state)) { |
| 6091 | return; |
| 6092 | } |
| 6093 | this._popStateInProgress = true; |
| 6094 | if (hashChanged) { |
| 6095 | this._blockHashChange++; |
| 6096 | (0, _event_utils.waitOnEventOrTimeout)({ |
| 6097 | target: window, |
| 6098 | name: "hashchange", |
| 6099 | delay: HASH_CHANGE_TIMEOUT |
| 6100 | }).then(() => { |
| 6101 | this._blockHashChange--; |
| 6102 | }); |
| 6103 | } |
| 6104 | const destination = state.destination; |
| 6105 | this._updateInternalState(destination, state.uid, true); |
| 6106 | if ((0, _ui_utils.isValidRotation)(destination.rotation)) { |
| 6107 | this.linkService.rotation = destination.rotation; |
| 6108 | } |
| 6109 | if (destination.dest) { |
| 6110 | this.linkService.goToDestination(destination.dest); |
| 6111 | } else if (destination.hash) { |
| 6112 | this.linkService.setHash(destination.hash); |
| 6113 | } else if (destination.page) { |
| 6114 | this.linkService.page = destination.page; |
| 6115 | } |
| 6116 | Promise.resolve().then(() => { |
| 6117 | this._popStateInProgress = false; |
| 6118 | }); |
| 6119 | } |
| 6120 | _pageHide() { |
| 6121 | if (!this._destination || this._destination.temporary) { |
| 6122 | this._tryPushCurrentPosition(); |
| 6123 | } |
| 6124 | } |
| 6125 | _bindEvents() { |
| 6126 | if (this._boundEvents) { |
| 6127 | return; |
| 6128 | } |
| 6129 | this._boundEvents = { |
| 6130 | updateViewarea: this._updateViewarea.bind(this), |
| 6131 | popState: this._popState.bind(this), |
| 6132 | pageHide: this._pageHide.bind(this) |
| 6133 | }; |
| 6134 | this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea); |
| 6135 | window.addEventListener("popstate", this._boundEvents.popState); |
| 6136 | window.addEventListener("pagehide", this._boundEvents.pageHide); |
| 6137 | } |
| 6138 | _unbindEvents() { |
| 6139 | if (!this._boundEvents) { |
| 6140 | return; |
| 6141 | } |
| 6142 | this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea); |
| 6143 | window.removeEventListener("popstate", this._boundEvents.popState); |
| 6144 | window.removeEventListener("pagehide", this._boundEvents.pageHide); |
| 6145 | this._boundEvents = null; |
| 6146 | } |
| 6147 | } |
| 6148 | exports.PDFHistory = PDFHistory; |
| 6149 | function isDestHashesEqual(destHash, pushHash) { |
| 6150 | if (typeof destHash !== "string" || typeof pushHash !== "string") { |
| 6151 | return false; |
| 6152 | } |
| 6153 | if (destHash === pushHash) { |
| 6154 | return true; |
| 6155 | } |
| 6156 | const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest"); |
| 6157 | if (nameddest === pushHash) { |
| 6158 | return true; |
| 6159 | } |
| 6160 | return false; |
| 6161 | } |
| 6162 | function isDestArraysEqual(firstDest, secondDest) { |
| 6163 | function isEntryEqual(first, second) { |
| 6164 | if (typeof first !== typeof second) { |
| 6165 | return false; |
| 6166 | } |
| 6167 | if (Array.isArray(first) || Array.isArray(second)) { |
| 6168 | return false; |
| 6169 | } |
| 6170 | if (first !== null && typeof first === "object" && second !== null) { |
| 6171 | if (Object.keys(first).length !== Object.keys(second).length) { |
| 6172 | return false; |
| 6173 | } |
| 6174 | for (const key in first) { |
| 6175 | if (!isEntryEqual(first[key], second[key])) { |
| 6176 | return false; |
| 6177 | } |
| 6178 | } |
| 6179 | return true; |
| 6180 | } |
| 6181 | return first === second || Number.isNaN(first) && Number.isNaN(second); |
| 6182 | } |
| 6183 | if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) { |
| 6184 | return false; |
| 6185 | } |
| 6186 | if (firstDest.length !== secondDest.length) { |
| 6187 | return false; |
| 6188 | } |
| 6189 | for (let i = 0, ii = firstDest.length; i < ii; i++) { |
| 6190 | if (!isEntryEqual(firstDest[i], secondDest[i])) { |
| 6191 | return false; |
| 6192 | } |
| 6193 | } |
| 6194 | return true; |
| 6195 | } |
| 6196 | |
| 6197 | /***/ }), |
| 6198 | /* 19 */ |
| 6199 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 6200 | |
| 6201 | |
| 6202 | |
| 6203 | Object.defineProperty(exports, "__esModule", ({ |
| 6204 | value: true |
| 6205 | })); |
| 6206 | exports.PDFLayerViewer = void 0; |
| 6207 | var _base_tree_viewer = __webpack_require__(13); |
| 6208 | class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer { |
| 6209 | constructor(options) { |
| 6210 | super(options); |
| 6211 | this.l10n = options.l10n; |
| 6212 | this.eventBus._on("optionalcontentconfigchanged", evt => { |
| 6213 | this.#updateLayers(evt.promise); |
| 6214 | }); |
| 6215 | this.eventBus._on("resetlayers", () => { |
| 6216 | this.#updateLayers(); |
| 6217 | }); |
| 6218 | this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this)); |
| 6219 | } |
| 6220 | reset() { |
| 6221 | super.reset(); |
| 6222 | this._optionalContentConfig = null; |
| 6223 | this._optionalContentHash = null; |
| 6224 | } |
| 6225 | _dispatchEvent(layersCount) { |
| 6226 | this.eventBus.dispatch("layersloaded", { |
| 6227 | source: this, |
| 6228 | layersCount |
| 6229 | }); |
| 6230 | } |
| 6231 | _bindLink(element, { |
| 6232 | groupId, |
| 6233 | input |
| 6234 | }) { |
| 6235 | const setVisibility = () => { |
| 6236 | this._optionalContentConfig.setVisibility(groupId, input.checked); |
| 6237 | this._optionalContentHash = this._optionalContentConfig.getHash(); |
| 6238 | this.eventBus.dispatch("optionalcontentconfig", { |
| 6239 | source: this, |
| 6240 | promise: Promise.resolve(this._optionalContentConfig) |
| 6241 | }); |
| 6242 | }; |
| 6243 | element.onclick = evt => { |
| 6244 | if (evt.target === input) { |
| 6245 | setVisibility(); |
| 6246 | return true; |
| 6247 | } else if (evt.target !== element) { |
| 6248 | return true; |
| 6249 | } |
| 6250 | input.checked = !input.checked; |
| 6251 | setVisibility(); |
| 6252 | return false; |
| 6253 | }; |
| 6254 | } |
| 6255 | async _setNestedName(element, { |
| 6256 | name = null |
| 6257 | }) { |
| 6258 | if (typeof name === "string") { |
| 6259 | element.textContent = this._normalizeTextContent(name); |
| 6260 | return; |
| 6261 | } |
| 6262 | element.textContent = await this.l10n.get("additional_layers"); |
| 6263 | element.style.fontStyle = "italic"; |
| 6264 | } |
| 6265 | _addToggleButton(div, { |
| 6266 | name = null |
| 6267 | }) { |
| 6268 | super._addToggleButton(div, name === null); |
| 6269 | } |
| 6270 | _toggleAllTreeItems() { |
| 6271 | if (!this._optionalContentConfig) { |
| 6272 | return; |
| 6273 | } |
| 6274 | super._toggleAllTreeItems(); |
| 6275 | } |
| 6276 | render({ |
| 6277 | optionalContentConfig, |
| 6278 | pdfDocument |
| 6279 | }) { |
| 6280 | if (this._optionalContentConfig) { |
| 6281 | this.reset(); |
| 6282 | } |
| 6283 | this._optionalContentConfig = optionalContentConfig || null; |
| 6284 | this._pdfDocument = pdfDocument || null; |
| 6285 | const groups = optionalContentConfig?.getOrder(); |
| 6286 | if (!groups) { |
| 6287 | this._dispatchEvent(0); |
| 6288 | return; |
| 6289 | } |
| 6290 | this._optionalContentHash = optionalContentConfig.getHash(); |
| 6291 | const fragment = document.createDocumentFragment(), |
| 6292 | queue = [{ |
| 6293 | parent: fragment, |
| 6294 | groups |
| 6295 | }]; |
| 6296 | let layersCount = 0, |
| 6297 | hasAnyNesting = false; |
| 6298 | while (queue.length > 0) { |
| 6299 | const levelData = queue.shift(); |
| 6300 | for (const groupId of levelData.groups) { |
| 6301 | const div = document.createElement("div"); |
| 6302 | div.className = "treeItem"; |
| 6303 | const element = document.createElement("a"); |
| 6304 | div.append(element); |
| 6305 | if (typeof groupId === "object") { |
| 6306 | hasAnyNesting = true; |
| 6307 | this._addToggleButton(div, groupId); |
| 6308 | this._setNestedName(element, groupId); |
| 6309 | const itemsDiv = document.createElement("div"); |
| 6310 | itemsDiv.className = "treeItems"; |
| 6311 | div.append(itemsDiv); |
| 6312 | queue.push({ |
| 6313 | parent: itemsDiv, |
| 6314 | groups: groupId.order |
| 6315 | }); |
| 6316 | } else { |
| 6317 | const group = optionalContentConfig.getGroup(groupId); |
| 6318 | const input = document.createElement("input"); |
| 6319 | this._bindLink(element, { |
| 6320 | groupId, |
| 6321 | input |
| 6322 | }); |
| 6323 | input.type = "checkbox"; |
| 6324 | input.checked = group.visible; |
| 6325 | const label = document.createElement("label"); |
| 6326 | label.textContent = this._normalizeTextContent(group.name); |
| 6327 | label.append(input); |
| 6328 | element.append(label); |
| 6329 | layersCount++; |
| 6330 | } |
| 6331 | levelData.parent.append(div); |
| 6332 | } |
| 6333 | } |
| 6334 | this._finishRendering(fragment, layersCount, hasAnyNesting); |
| 6335 | } |
| 6336 | async #updateLayers(promise = null) { |
| 6337 | if (!this._optionalContentConfig) { |
| 6338 | return; |
| 6339 | } |
| 6340 | const pdfDocument = this._pdfDocument; |
| 6341 | const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig()); |
| 6342 | if (pdfDocument !== this._pdfDocument) { |
| 6343 | return; |
| 6344 | } |
| 6345 | if (promise) { |
| 6346 | if (optionalContentConfig.getHash() === this._optionalContentHash) { |
| 6347 | return; |
| 6348 | } |
| 6349 | } else { |
| 6350 | this.eventBus.dispatch("optionalcontentconfig", { |
| 6351 | source: this, |
| 6352 | promise: Promise.resolve(optionalContentConfig) |
| 6353 | }); |
| 6354 | } |
| 6355 | this.render({ |
| 6356 | optionalContentConfig, |
| 6357 | pdfDocument: this._pdfDocument |
| 6358 | }); |
| 6359 | } |
| 6360 | } |
| 6361 | exports.PDFLayerViewer = PDFLayerViewer; |
| 6362 | |
| 6363 | /***/ }), |
| 6364 | /* 20 */ |
| 6365 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 6366 | |
| 6367 | |
| 6368 | |
| 6369 | Object.defineProperty(exports, "__esModule", ({ |
| 6370 | value: true |
| 6371 | })); |
| 6372 | exports.PDFOutlineViewer = void 0; |
| 6373 | var _base_tree_viewer = __webpack_require__(13); |
| 6374 | var _pdfjsLib = __webpack_require__(5); |
| 6375 | var _ui_utils = __webpack_require__(1); |
| 6376 | class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer { |
| 6377 | constructor(options) { |
| 6378 | super(options); |
| 6379 | this.linkService = options.linkService; |
| 6380 | this.downloadManager = options.downloadManager; |
| 6381 | this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this)); |
| 6382 | this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this)); |
| 6383 | this.eventBus._on("pagechanging", evt => { |
| 6384 | this._currentPageNumber = evt.pageNumber; |
| 6385 | }); |
| 6386 | this.eventBus._on("pagesloaded", evt => { |
| 6387 | this._isPagesLoaded = !!evt.pagesCount; |
| 6388 | if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) { |
| 6389 | this._currentOutlineItemCapability.resolve(this._isPagesLoaded); |
| 6390 | } |
| 6391 | }); |
| 6392 | this.eventBus._on("sidebarviewchanged", evt => { |
| 6393 | this._sidebarView = evt.view; |
| 6394 | }); |
| 6395 | } |
| 6396 | reset() { |
| 6397 | super.reset(); |
| 6398 | this._outline = null; |
| 6399 | this._pageNumberToDestHashCapability = null; |
| 6400 | this._currentPageNumber = 1; |
| 6401 | this._isPagesLoaded = null; |
| 6402 | if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) { |
| 6403 | this._currentOutlineItemCapability.resolve(false); |
| 6404 | } |
| 6405 | this._currentOutlineItemCapability = null; |
| 6406 | } |
| 6407 | _dispatchEvent(outlineCount) { |
| 6408 | this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 6409 | if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) { |
| 6410 | this._currentOutlineItemCapability.resolve(false); |
| 6411 | } else if (this._isPagesLoaded !== null) { |
| 6412 | this._currentOutlineItemCapability.resolve(this._isPagesLoaded); |
| 6413 | } |
| 6414 | this.eventBus.dispatch("outlineloaded", { |
| 6415 | source: this, |
| 6416 | outlineCount, |
| 6417 | currentOutlineItemPromise: this._currentOutlineItemCapability.promise |
| 6418 | }); |
| 6419 | } |
| 6420 | _bindLink(element, { |
| 6421 | url, |
| 6422 | newWindow, |
| 6423 | action, |
| 6424 | attachment, |
| 6425 | dest, |
| 6426 | setOCGState |
| 6427 | }) { |
| 6428 | const { |
| 6429 | linkService |
| 6430 | } = this; |
| 6431 | if (url) { |
| 6432 | linkService.addLinkAttributes(element, url, newWindow); |
| 6433 | return; |
| 6434 | } |
| 6435 | if (action) { |
| 6436 | element.href = linkService.getAnchorUrl(""); |
| 6437 | element.onclick = () => { |
| 6438 | linkService.executeNamedAction(action); |
| 6439 | return false; |
| 6440 | }; |
| 6441 | return; |
| 6442 | } |
| 6443 | if (attachment) { |
| 6444 | element.href = linkService.getAnchorUrl(""); |
| 6445 | element.onclick = () => { |
| 6446 | this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename); |
| 6447 | return false; |
| 6448 | }; |
| 6449 | return; |
| 6450 | } |
| 6451 | if (setOCGState) { |
| 6452 | element.href = linkService.getAnchorUrl(""); |
| 6453 | element.onclick = () => { |
| 6454 | linkService.executeSetOCGState(setOCGState); |
| 6455 | return false; |
| 6456 | }; |
| 6457 | return; |
| 6458 | } |
| 6459 | element.href = linkService.getDestinationHash(dest); |
| 6460 | element.onclick = evt => { |
| 6461 | this._updateCurrentTreeItem(evt.target.parentNode); |
| 6462 | if (dest) { |
| 6463 | linkService.goToDestination(dest); |
| 6464 | } |
| 6465 | return false; |
| 6466 | }; |
| 6467 | } |
| 6468 | _setStyles(element, { |
| 6469 | bold, |
| 6470 | italic |
| 6471 | }) { |
| 6472 | if (bold) { |
| 6473 | element.style.fontWeight = "bold"; |
| 6474 | } |
| 6475 | if (italic) { |
| 6476 | element.style.fontStyle = "italic"; |
| 6477 | } |
| 6478 | } |
| 6479 | _addToggleButton(div, { |
| 6480 | count, |
| 6481 | items |
| 6482 | }) { |
| 6483 | let hidden = false; |
| 6484 | if (count < 0) { |
| 6485 | let totalCount = items.length; |
| 6486 | if (totalCount > 0) { |
| 6487 | const queue = [...items]; |
| 6488 | while (queue.length > 0) { |
| 6489 | const { |
| 6490 | count: nestedCount, |
| 6491 | items: nestedItems |
| 6492 | } = queue.shift(); |
| 6493 | if (nestedCount > 0 && nestedItems.length > 0) { |
| 6494 | totalCount += nestedItems.length; |
| 6495 | queue.push(...nestedItems); |
| 6496 | } |
| 6497 | } |
| 6498 | } |
| 6499 | if (Math.abs(count) === totalCount) { |
| 6500 | hidden = true; |
| 6501 | } |
| 6502 | } |
| 6503 | super._addToggleButton(div, hidden); |
| 6504 | } |
| 6505 | _toggleAllTreeItems() { |
| 6506 | if (!this._outline) { |
| 6507 | return; |
| 6508 | } |
| 6509 | super._toggleAllTreeItems(); |
| 6510 | } |
| 6511 | render({ |
| 6512 | outline, |
| 6513 | pdfDocument |
| 6514 | }) { |
| 6515 | if (this._outline) { |
| 6516 | this.reset(); |
| 6517 | } |
| 6518 | this._outline = outline || null; |
| 6519 | this._pdfDocument = pdfDocument || null; |
| 6520 | if (!outline) { |
| 6521 | this._dispatchEvent(0); |
| 6522 | return; |
| 6523 | } |
| 6524 | const fragment = document.createDocumentFragment(); |
| 6525 | const queue = [{ |
| 6526 | parent: fragment, |
| 6527 | items: outline |
| 6528 | }]; |
| 6529 | let outlineCount = 0, |
| 6530 | hasAnyNesting = false; |
| 6531 | while (queue.length > 0) { |
| 6532 | const levelData = queue.shift(); |
| 6533 | for (const item of levelData.items) { |
| 6534 | const div = document.createElement("div"); |
| 6535 | div.className = "treeItem"; |
| 6536 | const element = document.createElement("a"); |
| 6537 | this._bindLink(element, item); |
| 6538 | this._setStyles(element, item); |
| 6539 | element.textContent = this._normalizeTextContent(item.title); |
| 6540 | div.append(element); |
| 6541 | if (item.items.length > 0) { |
| 6542 | hasAnyNesting = true; |
| 6543 | this._addToggleButton(div, item); |
| 6544 | const itemsDiv = document.createElement("div"); |
| 6545 | itemsDiv.className = "treeItems"; |
| 6546 | div.append(itemsDiv); |
| 6547 | queue.push({ |
| 6548 | parent: itemsDiv, |
| 6549 | items: item.items |
| 6550 | }); |
| 6551 | } |
| 6552 | levelData.parent.append(div); |
| 6553 | outlineCount++; |
| 6554 | } |
| 6555 | } |
| 6556 | this._finishRendering(fragment, outlineCount, hasAnyNesting); |
| 6557 | } |
| 6558 | async _currentOutlineItem() { |
| 6559 | if (!this._isPagesLoaded) { |
| 6560 | throw new Error("_currentOutlineItem: All pages have not been loaded."); |
| 6561 | } |
| 6562 | if (!this._outline || !this._pdfDocument) { |
| 6563 | return; |
| 6564 | } |
| 6565 | const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument); |
| 6566 | if (!pageNumberToDestHash) { |
| 6567 | return; |
| 6568 | } |
| 6569 | this._updateCurrentTreeItem(null); |
| 6570 | if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) { |
| 6571 | return; |
| 6572 | } |
| 6573 | for (let i = this._currentPageNumber; i > 0; i--) { |
| 6574 | const destHash = pageNumberToDestHash.get(i); |
| 6575 | if (!destHash) { |
| 6576 | continue; |
| 6577 | } |
| 6578 | const linkElement = this.container.querySelector(`a[href="${destHash}"]`); |
| 6579 | if (!linkElement) { |
| 6580 | continue; |
| 6581 | } |
| 6582 | this._scrollToCurrentTreeItem(linkElement.parentNode); |
| 6583 | break; |
| 6584 | } |
| 6585 | } |
| 6586 | async _getPageNumberToDestHash(pdfDocument) { |
| 6587 | if (this._pageNumberToDestHashCapability) { |
| 6588 | return this._pageNumberToDestHashCapability.promise; |
| 6589 | } |
| 6590 | this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 6591 | const pageNumberToDestHash = new Map(), |
| 6592 | pageNumberNesting = new Map(); |
| 6593 | const queue = [{ |
| 6594 | nesting: 0, |
| 6595 | items: this._outline |
| 6596 | }]; |
| 6597 | while (queue.length > 0) { |
| 6598 | const levelData = queue.shift(), |
| 6599 | currentNesting = levelData.nesting; |
| 6600 | for (const { |
| 6601 | dest, |
| 6602 | items |
| 6603 | } of levelData.items) { |
| 6604 | let explicitDest, pageNumber; |
| 6605 | if (typeof dest === "string") { |
| 6606 | explicitDest = await pdfDocument.getDestination(dest); |
| 6607 | if (pdfDocument !== this._pdfDocument) { |
| 6608 | return null; |
| 6609 | } |
| 6610 | } else { |
| 6611 | explicitDest = dest; |
| 6612 | } |
| 6613 | if (Array.isArray(explicitDest)) { |
| 6614 | const [destRef] = explicitDest; |
| 6615 | if (typeof destRef === "object" && destRef !== null) { |
| 6616 | pageNumber = this.linkService._cachedPageNumber(destRef); |
| 6617 | if (!pageNumber) { |
| 6618 | try { |
| 6619 | pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1; |
| 6620 | if (pdfDocument !== this._pdfDocument) { |
| 6621 | return null; |
| 6622 | } |
| 6623 | this.linkService.cachePageRef(pageNumber, destRef); |
| 6624 | } catch (ex) {} |
| 6625 | } |
| 6626 | } else if (Number.isInteger(destRef)) { |
| 6627 | pageNumber = destRef + 1; |
| 6628 | } |
| 6629 | if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) { |
| 6630 | const destHash = this.linkService.getDestinationHash(dest); |
| 6631 | pageNumberToDestHash.set(pageNumber, destHash); |
| 6632 | pageNumberNesting.set(pageNumber, currentNesting); |
| 6633 | } |
| 6634 | } |
| 6635 | if (items.length > 0) { |
| 6636 | queue.push({ |
| 6637 | nesting: currentNesting + 1, |
| 6638 | items |
| 6639 | }); |
| 6640 | } |
| 6641 | } |
| 6642 | } |
| 6643 | this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null); |
| 6644 | return this._pageNumberToDestHashCapability.promise; |
| 6645 | } |
| 6646 | } |
| 6647 | exports.PDFOutlineViewer = PDFOutlineViewer; |
| 6648 | |
| 6649 | /***/ }), |
| 6650 | /* 21 */ |
| 6651 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 6652 | |
| 6653 | |
| 6654 | |
| 6655 | Object.defineProperty(exports, "__esModule", ({ |
| 6656 | value: true |
| 6657 | })); |
| 6658 | exports.PDFPresentationMode = void 0; |
| 6659 | var _ui_utils = __webpack_require__(1); |
| 6660 | var _pdfjsLib = __webpack_require__(5); |
| 6661 | const DELAY_BEFORE_HIDING_CONTROLS = 3000; |
| 6662 | const ACTIVE_SELECTOR = "pdfPresentationMode"; |
| 6663 | const CONTROLS_SELECTOR = "pdfPresentationModeControls"; |
| 6664 | const MOUSE_SCROLL_COOLDOWN_TIME = 50; |
| 6665 | const PAGE_SWITCH_THRESHOLD = 0.1; |
| 6666 | const SWIPE_MIN_DISTANCE_THRESHOLD = 50; |
| 6667 | const SWIPE_ANGLE_THRESHOLD = Math.PI / 6; |
| 6668 | class PDFPresentationMode { |
| 6669 | #state = _ui_utils.PresentationModeState.UNKNOWN; |
| 6670 | #args = null; |
| 6671 | constructor({ |
| 6672 | container, |
| 6673 | pdfViewer, |
| 6674 | eventBus |
| 6675 | }) { |
| 6676 | this.container = container; |
| 6677 | this.pdfViewer = pdfViewer; |
| 6678 | this.eventBus = eventBus; |
| 6679 | this.contextMenuOpen = false; |
| 6680 | this.mouseScrollTimeStamp = 0; |
| 6681 | this.mouseScrollDelta = 0; |
| 6682 | this.touchSwipeState = null; |
| 6683 | } |
| 6684 | async request() { |
| 6685 | const { |
| 6686 | container, |
| 6687 | pdfViewer |
| 6688 | } = this; |
| 6689 | if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) { |
| 6690 | return false; |
| 6691 | } |
| 6692 | this.#addFullscreenChangeListeners(); |
| 6693 | this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING); |
| 6694 | const promise = container.requestFullscreen(); |
| 6695 | this.#args = { |
| 6696 | pageNumber: pdfViewer.currentPageNumber, |
| 6697 | scaleValue: pdfViewer.currentScaleValue, |
| 6698 | scrollMode: pdfViewer.scrollMode, |
| 6699 | spreadMode: null, |
| 6700 | annotationEditorMode: null |
| 6701 | }; |
| 6702 | if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) { |
| 6703 | console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes."); |
| 6704 | this.#args.spreadMode = pdfViewer.spreadMode; |
| 6705 | } |
| 6706 | if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) { |
| 6707 | this.#args.annotationEditorMode = pdfViewer.annotationEditorMode; |
| 6708 | } |
| 6709 | try { |
| 6710 | await promise; |
| 6711 | pdfViewer.focus(); |
| 6712 | return true; |
| 6713 | } catch (reason) { |
| 6714 | this.#removeFullscreenChangeListeners(); |
| 6715 | this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL); |
| 6716 | } |
| 6717 | return false; |
| 6718 | } |
| 6719 | get active() { |
| 6720 | return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN; |
| 6721 | } |
| 6722 | #mouseWheel(evt) { |
| 6723 | if (!this.active) { |
| 6724 | return; |
| 6725 | } |
| 6726 | evt.preventDefault(); |
| 6727 | const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt); |
| 6728 | const currentTime = Date.now(); |
| 6729 | const storedTime = this.mouseScrollTimeStamp; |
| 6730 | if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) { |
| 6731 | return; |
| 6732 | } |
| 6733 | if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) { |
| 6734 | this.#resetMouseScrollState(); |
| 6735 | } |
| 6736 | this.mouseScrollDelta += delta; |
| 6737 | if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) { |
| 6738 | const totalDelta = this.mouseScrollDelta; |
| 6739 | this.#resetMouseScrollState(); |
| 6740 | const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage(); |
| 6741 | if (success) { |
| 6742 | this.mouseScrollTimeStamp = currentTime; |
| 6743 | } |
| 6744 | } |
| 6745 | } |
| 6746 | #notifyStateChange(state) { |
| 6747 | this.#state = state; |
| 6748 | this.eventBus.dispatch("presentationmodechanged", { |
| 6749 | source: this, |
| 6750 | state |
| 6751 | }); |
| 6752 | } |
| 6753 | #enter() { |
| 6754 | this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN); |
| 6755 | this.container.classList.add(ACTIVE_SELECTOR); |
| 6756 | setTimeout(() => { |
| 6757 | this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE; |
| 6758 | if (this.#args.spreadMode !== null) { |
| 6759 | this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE; |
| 6760 | } |
| 6761 | this.pdfViewer.currentPageNumber = this.#args.pageNumber; |
| 6762 | this.pdfViewer.currentScaleValue = "page-fit"; |
| 6763 | if (this.#args.annotationEditorMode !== null) { |
| 6764 | this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE; |
| 6765 | } |
| 6766 | }, 0); |
| 6767 | this.#addWindowListeners(); |
| 6768 | this.#showControls(); |
| 6769 | this.contextMenuOpen = false; |
| 6770 | window.getSelection().removeAllRanges(); |
| 6771 | } |
| 6772 | #exit() { |
| 6773 | const pageNumber = this.pdfViewer.currentPageNumber; |
| 6774 | this.container.classList.remove(ACTIVE_SELECTOR); |
| 6775 | setTimeout(() => { |
| 6776 | this.#removeFullscreenChangeListeners(); |
| 6777 | this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL); |
| 6778 | this.pdfViewer.scrollMode = this.#args.scrollMode; |
| 6779 | if (this.#args.spreadMode !== null) { |
| 6780 | this.pdfViewer.spreadMode = this.#args.spreadMode; |
| 6781 | } |
| 6782 | this.pdfViewer.currentScaleValue = this.#args.scaleValue; |
| 6783 | this.pdfViewer.currentPageNumber = pageNumber; |
| 6784 | if (this.#args.annotationEditorMode !== null) { |
| 6785 | this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode; |
| 6786 | } |
| 6787 | this.#args = null; |
| 6788 | }, 0); |
| 6789 | this.#removeWindowListeners(); |
| 6790 | this.#hideControls(); |
| 6791 | this.#resetMouseScrollState(); |
| 6792 | this.contextMenuOpen = false; |
| 6793 | } |
| 6794 | #mouseDown(evt) { |
| 6795 | if (this.contextMenuOpen) { |
| 6796 | this.contextMenuOpen = false; |
| 6797 | evt.preventDefault(); |
| 6798 | return; |
| 6799 | } |
| 6800 | if (evt.button !== 0) { |
| 6801 | return; |
| 6802 | } |
| 6803 | if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) { |
| 6804 | return; |
| 6805 | } |
| 6806 | evt.preventDefault(); |
| 6807 | if (evt.shiftKey) { |
| 6808 | this.pdfViewer.previousPage(); |
| 6809 | } else { |
| 6810 | this.pdfViewer.nextPage(); |
| 6811 | } |
| 6812 | } |
| 6813 | #contextMenu() { |
| 6814 | this.contextMenuOpen = true; |
| 6815 | } |
| 6816 | #showControls() { |
| 6817 | if (this.controlsTimeout) { |
| 6818 | clearTimeout(this.controlsTimeout); |
| 6819 | } else { |
| 6820 | this.container.classList.add(CONTROLS_SELECTOR); |
| 6821 | } |
| 6822 | this.controlsTimeout = setTimeout(() => { |
| 6823 | this.container.classList.remove(CONTROLS_SELECTOR); |
| 6824 | delete this.controlsTimeout; |
| 6825 | }, DELAY_BEFORE_HIDING_CONTROLS); |
| 6826 | } |
| 6827 | #hideControls() { |
| 6828 | if (!this.controlsTimeout) { |
| 6829 | return; |
| 6830 | } |
| 6831 | clearTimeout(this.controlsTimeout); |
| 6832 | this.container.classList.remove(CONTROLS_SELECTOR); |
| 6833 | delete this.controlsTimeout; |
| 6834 | } |
| 6835 | #resetMouseScrollState() { |
| 6836 | this.mouseScrollTimeStamp = 0; |
| 6837 | this.mouseScrollDelta = 0; |
| 6838 | } |
| 6839 | #touchSwipe(evt) { |
| 6840 | if (!this.active) { |
| 6841 | return; |
| 6842 | } |
| 6843 | if (evt.touches.length > 1) { |
| 6844 | this.touchSwipeState = null; |
| 6845 | return; |
| 6846 | } |
| 6847 | switch (evt.type) { |
| 6848 | case "touchstart": |
| 6849 | this.touchSwipeState = { |
| 6850 | startX: evt.touches[0].pageX, |
| 6851 | startY: evt.touches[0].pageY, |
| 6852 | endX: evt.touches[0].pageX, |
| 6853 | endY: evt.touches[0].pageY |
| 6854 | }; |
| 6855 | break; |
| 6856 | case "touchmove": |
| 6857 | if (this.touchSwipeState === null) { |
| 6858 | return; |
| 6859 | } |
| 6860 | this.touchSwipeState.endX = evt.touches[0].pageX; |
| 6861 | this.touchSwipeState.endY = evt.touches[0].pageY; |
| 6862 | evt.preventDefault(); |
| 6863 | break; |
| 6864 | case "touchend": |
| 6865 | if (this.touchSwipeState === null) { |
| 6866 | return; |
| 6867 | } |
| 6868 | let delta = 0; |
| 6869 | const dx = this.touchSwipeState.endX - this.touchSwipeState.startX; |
| 6870 | const dy = this.touchSwipeState.endY - this.touchSwipeState.startY; |
| 6871 | const absAngle = Math.abs(Math.atan2(dy, dx)); |
| 6872 | if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) { |
| 6873 | delta = dx; |
| 6874 | } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) { |
| 6875 | delta = dy; |
| 6876 | } |
| 6877 | if (delta > 0) { |
| 6878 | this.pdfViewer.previousPage(); |
| 6879 | } else if (delta < 0) { |
| 6880 | this.pdfViewer.nextPage(); |
| 6881 | } |
| 6882 | break; |
| 6883 | } |
| 6884 | } |
| 6885 | #addWindowListeners() { |
| 6886 | this.showControlsBind = this.#showControls.bind(this); |
| 6887 | this.mouseDownBind = this.#mouseDown.bind(this); |
| 6888 | this.mouseWheelBind = this.#mouseWheel.bind(this); |
| 6889 | this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this); |
| 6890 | this.contextMenuBind = this.#contextMenu.bind(this); |
| 6891 | this.touchSwipeBind = this.#touchSwipe.bind(this); |
| 6892 | window.addEventListener("mousemove", this.showControlsBind); |
| 6893 | window.addEventListener("mousedown", this.mouseDownBind); |
| 6894 | window.addEventListener("wheel", this.mouseWheelBind, { |
| 6895 | passive: false |
| 6896 | }); |
| 6897 | window.addEventListener("keydown", this.resetMouseScrollStateBind); |
| 6898 | window.addEventListener("contextmenu", this.contextMenuBind); |
| 6899 | window.addEventListener("touchstart", this.touchSwipeBind); |
| 6900 | window.addEventListener("touchmove", this.touchSwipeBind); |
| 6901 | window.addEventListener("touchend", this.touchSwipeBind); |
| 6902 | } |
| 6903 | #removeWindowListeners() { |
| 6904 | window.removeEventListener("mousemove", this.showControlsBind); |
| 6905 | window.removeEventListener("mousedown", this.mouseDownBind); |
| 6906 | window.removeEventListener("wheel", this.mouseWheelBind, { |
| 6907 | passive: false |
| 6908 | }); |
| 6909 | window.removeEventListener("keydown", this.resetMouseScrollStateBind); |
| 6910 | window.removeEventListener("contextmenu", this.contextMenuBind); |
| 6911 | window.removeEventListener("touchstart", this.touchSwipeBind); |
| 6912 | window.removeEventListener("touchmove", this.touchSwipeBind); |
| 6913 | window.removeEventListener("touchend", this.touchSwipeBind); |
| 6914 | delete this.showControlsBind; |
| 6915 | delete this.mouseDownBind; |
| 6916 | delete this.mouseWheelBind; |
| 6917 | delete this.resetMouseScrollStateBind; |
| 6918 | delete this.contextMenuBind; |
| 6919 | delete this.touchSwipeBind; |
| 6920 | } |
| 6921 | #fullscreenChange() { |
| 6922 | if (document.fullscreenElement) { |
| 6923 | this.#enter(); |
| 6924 | } else { |
| 6925 | this.#exit(); |
| 6926 | } |
| 6927 | } |
| 6928 | #addFullscreenChangeListeners() { |
| 6929 | this.fullscreenChangeBind = this.#fullscreenChange.bind(this); |
| 6930 | window.addEventListener("fullscreenchange", this.fullscreenChangeBind); |
| 6931 | } |
| 6932 | #removeFullscreenChangeListeners() { |
| 6933 | window.removeEventListener("fullscreenchange", this.fullscreenChangeBind); |
| 6934 | delete this.fullscreenChangeBind; |
| 6935 | } |
| 6936 | } |
| 6937 | exports.PDFPresentationMode = PDFPresentationMode; |
| 6938 | |
| 6939 | /***/ }), |
| 6940 | /* 22 */ |
| 6941 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 6942 | |
| 6943 | |
| 6944 | |
| 6945 | Object.defineProperty(exports, "__esModule", ({ |
| 6946 | value: true |
| 6947 | })); |
| 6948 | exports.PDFRenderingQueue = void 0; |
| 6949 | var _pdfjsLib = __webpack_require__(5); |
| 6950 | var _ui_utils = __webpack_require__(1); |
| 6951 | const CLEANUP_TIMEOUT = 30000; |
| 6952 | class PDFRenderingQueue { |
| 6953 | constructor() { |
| 6954 | this.pdfViewer = null; |
| 6955 | this.pdfThumbnailViewer = null; |
| 6956 | this.onIdle = null; |
| 6957 | this.highestPriorityPage = null; |
| 6958 | this.idleTimeout = null; |
| 6959 | this.printing = false; |
| 6960 | this.isThumbnailViewEnabled = false; |
| 6961 | } |
| 6962 | setViewer(pdfViewer) { |
| 6963 | this.pdfViewer = pdfViewer; |
| 6964 | } |
| 6965 | setThumbnailViewer(pdfThumbnailViewer) { |
| 6966 | this.pdfThumbnailViewer = pdfThumbnailViewer; |
| 6967 | } |
| 6968 | isHighestPriority(view) { |
| 6969 | return this.highestPriorityPage === view.renderingId; |
| 6970 | } |
| 6971 | hasViewer() { |
| 6972 | return !!this.pdfViewer; |
| 6973 | } |
| 6974 | renderHighestPriority(currentlyVisiblePages) { |
| 6975 | if (this.idleTimeout) { |
| 6976 | clearTimeout(this.idleTimeout); |
| 6977 | this.idleTimeout = null; |
| 6978 | } |
| 6979 | if (this.pdfViewer.forceRendering(currentlyVisiblePages)) { |
| 6980 | return; |
| 6981 | } |
| 6982 | if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) { |
| 6983 | return; |
| 6984 | } |
| 6985 | if (this.printing) { |
| 6986 | return; |
| 6987 | } |
| 6988 | if (this.onIdle) { |
| 6989 | this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT); |
| 6990 | } |
| 6991 | } |
| 6992 | getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) { |
| 6993 | const visibleViews = visible.views, |
| 6994 | numVisible = visibleViews.length; |
| 6995 | if (numVisible === 0) { |
| 6996 | return null; |
| 6997 | } |
| 6998 | for (let i = 0; i < numVisible; i++) { |
| 6999 | const view = visibleViews[i].view; |
| 7000 | if (!this.isViewFinished(view)) { |
| 7001 | return view; |
| 7002 | } |
| 7003 | } |
| 7004 | const firstId = visible.first.id, |
| 7005 | lastId = visible.last.id; |
| 7006 | if (lastId - firstId + 1 > numVisible) { |
| 7007 | const visibleIds = visible.ids; |
| 7008 | for (let i = 1, ii = lastId - firstId; i < ii; i++) { |
| 7009 | const holeId = scrolledDown ? firstId + i : lastId - i; |
| 7010 | if (visibleIds.has(holeId)) { |
| 7011 | continue; |
| 7012 | } |
| 7013 | const holeView = views[holeId - 1]; |
| 7014 | if (!this.isViewFinished(holeView)) { |
| 7015 | return holeView; |
| 7016 | } |
| 7017 | } |
| 7018 | } |
| 7019 | let preRenderIndex = scrolledDown ? lastId : firstId - 2; |
| 7020 | let preRenderView = views[preRenderIndex]; |
| 7021 | if (preRenderView && !this.isViewFinished(preRenderView)) { |
| 7022 | return preRenderView; |
| 7023 | } |
| 7024 | if (preRenderExtra) { |
| 7025 | preRenderIndex += scrolledDown ? 1 : -1; |
| 7026 | preRenderView = views[preRenderIndex]; |
| 7027 | if (preRenderView && !this.isViewFinished(preRenderView)) { |
| 7028 | return preRenderView; |
| 7029 | } |
| 7030 | } |
| 7031 | return null; |
| 7032 | } |
| 7033 | isViewFinished(view) { |
| 7034 | return view.renderingState === _ui_utils.RenderingStates.FINISHED; |
| 7035 | } |
| 7036 | renderView(view) { |
| 7037 | switch (view.renderingState) { |
| 7038 | case _ui_utils.RenderingStates.FINISHED: |
| 7039 | return false; |
| 7040 | case _ui_utils.RenderingStates.PAUSED: |
| 7041 | this.highestPriorityPage = view.renderingId; |
| 7042 | view.resume(); |
| 7043 | break; |
| 7044 | case _ui_utils.RenderingStates.RUNNING: |
| 7045 | this.highestPriorityPage = view.renderingId; |
| 7046 | break; |
| 7047 | case _ui_utils.RenderingStates.INITIAL: |
| 7048 | this.highestPriorityPage = view.renderingId; |
| 7049 | view.draw().finally(() => { |
| 7050 | this.renderHighestPriority(); |
| 7051 | }).catch(reason => { |
| 7052 | if (reason instanceof _pdfjsLib.RenderingCancelledException) { |
| 7053 | return; |
| 7054 | } |
| 7055 | console.error(`renderView: "${reason}"`); |
| 7056 | }); |
| 7057 | break; |
| 7058 | } |
| 7059 | return true; |
| 7060 | } |
| 7061 | } |
| 7062 | exports.PDFRenderingQueue = PDFRenderingQueue; |
| 7063 | |
| 7064 | /***/ }), |
| 7065 | /* 23 */ |
| 7066 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 7067 | |
| 7068 | |
| 7069 | |
| 7070 | Object.defineProperty(exports, "__esModule", ({ |
| 7071 | value: true |
| 7072 | })); |
| 7073 | exports.PDFScriptingManager = void 0; |
| 7074 | var _ui_utils = __webpack_require__(1); |
| 7075 | var _pdfjsLib = __webpack_require__(5); |
| 7076 | class PDFScriptingManager { |
| 7077 | constructor({ |
| 7078 | eventBus, |
| 7079 | sandboxBundleSrc = null, |
| 7080 | scriptingFactory = null, |
| 7081 | docPropertiesLookup = null |
| 7082 | }) { |
| 7083 | this._pdfDocument = null; |
| 7084 | this._pdfViewer = null; |
| 7085 | this._closeCapability = null; |
| 7086 | this._destroyCapability = null; |
| 7087 | this._scripting = null; |
| 7088 | this._ready = false; |
| 7089 | this._eventBus = eventBus; |
| 7090 | this._sandboxBundleSrc = sandboxBundleSrc; |
| 7091 | this._scriptingFactory = scriptingFactory; |
| 7092 | this._docPropertiesLookup = docPropertiesLookup; |
| 7093 | } |
| 7094 | setViewer(pdfViewer) { |
| 7095 | this._pdfViewer = pdfViewer; |
| 7096 | } |
| 7097 | async setDocument(pdfDocument) { |
| 7098 | if (this._pdfDocument) { |
| 7099 | await this._destroyScripting(); |
| 7100 | } |
| 7101 | this._pdfDocument = pdfDocument; |
| 7102 | if (!pdfDocument) { |
| 7103 | return; |
| 7104 | } |
| 7105 | const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]); |
| 7106 | if (!objects && !docActions) { |
| 7107 | await this._destroyScripting(); |
| 7108 | return; |
| 7109 | } |
| 7110 | if (pdfDocument !== this._pdfDocument) { |
| 7111 | return; |
| 7112 | } |
| 7113 | try { |
| 7114 | this._scripting = this._createScripting(); |
| 7115 | } catch (error) { |
| 7116 | console.error(`PDFScriptingManager.setDocument: "${error?.message}".`); |
| 7117 | await this._destroyScripting(); |
| 7118 | return; |
| 7119 | } |
| 7120 | this._internalEvents.set("updatefromsandbox", event => { |
| 7121 | if (event?.source !== window) { |
| 7122 | return; |
| 7123 | } |
| 7124 | this._updateFromSandbox(event.detail); |
| 7125 | }); |
| 7126 | this._internalEvents.set("dispatcheventinsandbox", event => { |
| 7127 | this._scripting?.dispatchEventInSandbox(event.detail); |
| 7128 | }); |
| 7129 | this._internalEvents.set("pagechanging", ({ |
| 7130 | pageNumber, |
| 7131 | previous |
| 7132 | }) => { |
| 7133 | if (pageNumber === previous) { |
| 7134 | return; |
| 7135 | } |
| 7136 | this._dispatchPageClose(previous); |
| 7137 | this._dispatchPageOpen(pageNumber); |
| 7138 | }); |
| 7139 | this._internalEvents.set("pagerendered", ({ |
| 7140 | pageNumber |
| 7141 | }) => { |
| 7142 | if (!this._pageOpenPending.has(pageNumber)) { |
| 7143 | return; |
| 7144 | } |
| 7145 | if (pageNumber !== this._pdfViewer.currentPageNumber) { |
| 7146 | return; |
| 7147 | } |
| 7148 | this._dispatchPageOpen(pageNumber); |
| 7149 | }); |
| 7150 | this._internalEvents.set("pagesdestroy", async event => { |
| 7151 | await this._dispatchPageClose(this._pdfViewer.currentPageNumber); |
| 7152 | await this._scripting?.dispatchEventInSandbox({ |
| 7153 | id: "doc", |
| 7154 | name: "WillClose" |
| 7155 | }); |
| 7156 | this._closeCapability?.resolve(); |
| 7157 | }); |
| 7158 | for (const [name, listener] of this._internalEvents) { |
| 7159 | this._eventBus._on(name, listener); |
| 7160 | } |
| 7161 | try { |
| 7162 | const docProperties = await this._getDocProperties(); |
| 7163 | if (pdfDocument !== this._pdfDocument) { |
| 7164 | return; |
| 7165 | } |
| 7166 | await this._scripting.createSandbox({ |
| 7167 | objects, |
| 7168 | calculationOrder, |
| 7169 | appInfo: { |
| 7170 | platform: navigator.platform, |
| 7171 | language: navigator.language |
| 7172 | }, |
| 7173 | docInfo: { |
| 7174 | ...docProperties, |
| 7175 | actions: docActions |
| 7176 | } |
| 7177 | }); |
| 7178 | this._eventBus.dispatch("sandboxcreated", { |
| 7179 | source: this |
| 7180 | }); |
| 7181 | } catch (error) { |
| 7182 | console.error(`PDFScriptingManager.setDocument: "${error?.message}".`); |
| 7183 | await this._destroyScripting(); |
| 7184 | return; |
| 7185 | } |
| 7186 | await this._scripting?.dispatchEventInSandbox({ |
| 7187 | id: "doc", |
| 7188 | name: "Open" |
| 7189 | }); |
| 7190 | await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true); |
| 7191 | Promise.resolve().then(() => { |
| 7192 | if (pdfDocument === this._pdfDocument) { |
| 7193 | this._ready = true; |
| 7194 | } |
| 7195 | }); |
| 7196 | } |
| 7197 | async dispatchWillSave(detail) { |
| 7198 | return this._scripting?.dispatchEventInSandbox({ |
| 7199 | id: "doc", |
| 7200 | name: "WillSave" |
| 7201 | }); |
| 7202 | } |
| 7203 | async dispatchDidSave(detail) { |
| 7204 | return this._scripting?.dispatchEventInSandbox({ |
| 7205 | id: "doc", |
| 7206 | name: "DidSave" |
| 7207 | }); |
| 7208 | } |
| 7209 | async dispatchWillPrint(detail) { |
| 7210 | return this._scripting?.dispatchEventInSandbox({ |
| 7211 | id: "doc", |
| 7212 | name: "WillPrint" |
| 7213 | }); |
| 7214 | } |
| 7215 | async dispatchDidPrint(detail) { |
| 7216 | return this._scripting?.dispatchEventInSandbox({ |
| 7217 | id: "doc", |
| 7218 | name: "DidPrint" |
| 7219 | }); |
| 7220 | } |
| 7221 | get destroyPromise() { |
| 7222 | return this._destroyCapability?.promise || null; |
| 7223 | } |
| 7224 | get ready() { |
| 7225 | return this._ready; |
| 7226 | } |
| 7227 | get _internalEvents() { |
| 7228 | return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map()); |
| 7229 | } |
| 7230 | get _pageOpenPending() { |
| 7231 | return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set()); |
| 7232 | } |
| 7233 | get _visitedPages() { |
| 7234 | return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map()); |
| 7235 | } |
| 7236 | async _updateFromSandbox(detail) { |
| 7237 | const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode; |
| 7238 | const { |
| 7239 | id, |
| 7240 | siblings, |
| 7241 | command, |
| 7242 | value |
| 7243 | } = detail; |
| 7244 | if (!id) { |
| 7245 | switch (command) { |
| 7246 | case "clear": |
| 7247 | console.clear(); |
| 7248 | break; |
| 7249 | case "error": |
| 7250 | console.error(value); |
| 7251 | break; |
| 7252 | case "layout": |
| 7253 | { |
| 7254 | if (isInPresentationMode) { |
| 7255 | return; |
| 7256 | } |
| 7257 | const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value); |
| 7258 | this._pdfViewer.spreadMode = modes.spreadMode; |
| 7259 | break; |
| 7260 | } |
| 7261 | case "page-num": |
| 7262 | this._pdfViewer.currentPageNumber = value + 1; |
| 7263 | break; |
| 7264 | case "print": |
| 7265 | await this._pdfViewer.pagesPromise; |
| 7266 | this._eventBus.dispatch("print", { |
| 7267 | source: this |
| 7268 | }); |
| 7269 | break; |
| 7270 | case "println": |
| 7271 | console.log(value); |
| 7272 | break; |
| 7273 | case "zoom": |
| 7274 | if (isInPresentationMode) { |
| 7275 | return; |
| 7276 | } |
| 7277 | this._pdfViewer.currentScaleValue = value; |
| 7278 | break; |
| 7279 | case "SaveAs": |
| 7280 | this._eventBus.dispatch("download", { |
| 7281 | source: this |
| 7282 | }); |
| 7283 | break; |
| 7284 | case "FirstPage": |
| 7285 | this._pdfViewer.currentPageNumber = 1; |
| 7286 | break; |
| 7287 | case "LastPage": |
| 7288 | this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount; |
| 7289 | break; |
| 7290 | case "NextPage": |
| 7291 | this._pdfViewer.nextPage(); |
| 7292 | break; |
| 7293 | case "PrevPage": |
| 7294 | this._pdfViewer.previousPage(); |
| 7295 | break; |
| 7296 | case "ZoomViewIn": |
| 7297 | if (isInPresentationMode) { |
| 7298 | return; |
| 7299 | } |
| 7300 | this._pdfViewer.increaseScale(); |
| 7301 | break; |
| 7302 | case "ZoomViewOut": |
| 7303 | if (isInPresentationMode) { |
| 7304 | return; |
| 7305 | } |
| 7306 | this._pdfViewer.decreaseScale(); |
| 7307 | break; |
| 7308 | } |
| 7309 | return; |
| 7310 | } |
| 7311 | if (isInPresentationMode) { |
| 7312 | if (detail.focus) { |
| 7313 | return; |
| 7314 | } |
| 7315 | } |
| 7316 | delete detail.id; |
| 7317 | delete detail.siblings; |
| 7318 | const ids = siblings ? [id, ...siblings] : [id]; |
| 7319 | for (const elementId of ids) { |
| 7320 | const element = document.querySelector(`[data-element-id="${elementId}"]`); |
| 7321 | if (element) { |
| 7322 | element.dispatchEvent(new CustomEvent("updatefromsandbox", { |
| 7323 | detail |
| 7324 | })); |
| 7325 | } else { |
| 7326 | this._pdfDocument?.annotationStorage.setValue(elementId, detail); |
| 7327 | } |
| 7328 | } |
| 7329 | } |
| 7330 | async _dispatchPageOpen(pageNumber, initialize = false) { |
| 7331 | const pdfDocument = this._pdfDocument, |
| 7332 | visitedPages = this._visitedPages; |
| 7333 | if (initialize) { |
| 7334 | this._closeCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 7335 | } |
| 7336 | if (!this._closeCapability) { |
| 7337 | return; |
| 7338 | } |
| 7339 | const pageView = this._pdfViewer.getPageView(pageNumber - 1); |
| 7340 | if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 7341 | this._pageOpenPending.add(pageNumber); |
| 7342 | return; |
| 7343 | } |
| 7344 | this._pageOpenPending.delete(pageNumber); |
| 7345 | const actionsPromise = (async () => { |
| 7346 | const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null); |
| 7347 | if (pdfDocument !== this._pdfDocument) { |
| 7348 | return; |
| 7349 | } |
| 7350 | await this._scripting?.dispatchEventInSandbox({ |
| 7351 | id: "page", |
| 7352 | name: "PageOpen", |
| 7353 | pageNumber, |
| 7354 | actions |
| 7355 | }); |
| 7356 | })(); |
| 7357 | visitedPages.set(pageNumber, actionsPromise); |
| 7358 | } |
| 7359 | async _dispatchPageClose(pageNumber) { |
| 7360 | const pdfDocument = this._pdfDocument, |
| 7361 | visitedPages = this._visitedPages; |
| 7362 | if (!this._closeCapability) { |
| 7363 | return; |
| 7364 | } |
| 7365 | if (this._pageOpenPending.has(pageNumber)) { |
| 7366 | return; |
| 7367 | } |
| 7368 | const actionsPromise = visitedPages.get(pageNumber); |
| 7369 | if (!actionsPromise) { |
| 7370 | return; |
| 7371 | } |
| 7372 | visitedPages.set(pageNumber, null); |
| 7373 | await actionsPromise; |
| 7374 | if (pdfDocument !== this._pdfDocument) { |
| 7375 | return; |
| 7376 | } |
| 7377 | await this._scripting?.dispatchEventInSandbox({ |
| 7378 | id: "page", |
| 7379 | name: "PageClose", |
| 7380 | pageNumber |
| 7381 | }); |
| 7382 | } |
| 7383 | async _getDocProperties() { |
| 7384 | if (this._docPropertiesLookup) { |
| 7385 | return this._docPropertiesLookup(this._pdfDocument); |
| 7386 | } |
| 7387 | throw new Error("_getDocProperties: Unable to lookup properties."); |
| 7388 | } |
| 7389 | _createScripting() { |
| 7390 | this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 7391 | if (this._scripting) { |
| 7392 | throw new Error("_createScripting: Scripting already exists."); |
| 7393 | } |
| 7394 | if (this._scriptingFactory) { |
| 7395 | return this._scriptingFactory.createScripting({ |
| 7396 | sandboxBundleSrc: this._sandboxBundleSrc |
| 7397 | }); |
| 7398 | } |
| 7399 | throw new Error("_createScripting: Cannot create scripting."); |
| 7400 | } |
| 7401 | async _destroyScripting() { |
| 7402 | if (!this._scripting) { |
| 7403 | this._pdfDocument = null; |
| 7404 | this._destroyCapability?.resolve(); |
| 7405 | return; |
| 7406 | } |
| 7407 | if (this._closeCapability) { |
| 7408 | await Promise.race([this._closeCapability.promise, new Promise(resolve => { |
| 7409 | setTimeout(resolve, 1000); |
| 7410 | })]).catch(reason => {}); |
| 7411 | this._closeCapability = null; |
| 7412 | } |
| 7413 | this._pdfDocument = null; |
| 7414 | try { |
| 7415 | await this._scripting.destroySandbox(); |
| 7416 | } catch (ex) {} |
| 7417 | for (const [name, listener] of this._internalEvents) { |
| 7418 | this._eventBus._off(name, listener); |
| 7419 | } |
| 7420 | this._internalEvents.clear(); |
| 7421 | this._pageOpenPending.clear(); |
| 7422 | this._visitedPages.clear(); |
| 7423 | this._scripting = null; |
| 7424 | this._ready = false; |
| 7425 | this._destroyCapability?.resolve(); |
| 7426 | } |
| 7427 | } |
| 7428 | exports.PDFScriptingManager = PDFScriptingManager; |
| 7429 | |
| 7430 | /***/ }), |
| 7431 | /* 24 */ |
| 7432 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 7433 | |
| 7434 | |
| 7435 | |
| 7436 | Object.defineProperty(exports, "__esModule", ({ |
| 7437 | value: true |
| 7438 | })); |
| 7439 | exports.PDFSidebar = void 0; |
| 7440 | var _ui_utils = __webpack_require__(1); |
| 7441 | const UI_NOTIFICATION_CLASS = "pdfSidebarNotification"; |
| 7442 | class PDFSidebar { |
| 7443 | constructor({ |
| 7444 | elements, |
| 7445 | pdfViewer, |
| 7446 | pdfThumbnailViewer, |
| 7447 | eventBus, |
| 7448 | l10n |
| 7449 | }) { |
| 7450 | this.isOpen = false; |
| 7451 | this.active = _ui_utils.SidebarView.THUMBS; |
| 7452 | this.isInitialViewSet = false; |
| 7453 | this.isInitialEventDispatched = false; |
| 7454 | this.onToggled = null; |
| 7455 | this.pdfViewer = pdfViewer; |
| 7456 | this.pdfThumbnailViewer = pdfThumbnailViewer; |
| 7457 | this.outerContainer = elements.outerContainer; |
| 7458 | this.sidebarContainer = elements.sidebarContainer; |
| 7459 | this.toggleButton = elements.toggleButton; |
| 7460 | this.thumbnailButton = elements.thumbnailButton; |
| 7461 | this.outlineButton = elements.outlineButton; |
| 7462 | this.attachmentsButton = elements.attachmentsButton; |
| 7463 | this.layersButton = elements.layersButton; |
| 7464 | this.thumbnailView = elements.thumbnailView; |
| 7465 | this.outlineView = elements.outlineView; |
| 7466 | this.attachmentsView = elements.attachmentsView; |
| 7467 | this.layersView = elements.layersView; |
| 7468 | this._outlineOptionsContainer = elements.outlineOptionsContainer; |
| 7469 | this._currentOutlineItemButton = elements.currentOutlineItemButton; |
| 7470 | this.eventBus = eventBus; |
| 7471 | this.l10n = l10n; |
| 7472 | this.#addEventListeners(); |
| 7473 | } |
| 7474 | reset() { |
| 7475 | this.isInitialViewSet = false; |
| 7476 | this.isInitialEventDispatched = false; |
| 7477 | this.#hideUINotification(true); |
| 7478 | this.switchView(_ui_utils.SidebarView.THUMBS); |
| 7479 | this.outlineButton.disabled = false; |
| 7480 | this.attachmentsButton.disabled = false; |
| 7481 | this.layersButton.disabled = false; |
| 7482 | this._currentOutlineItemButton.disabled = true; |
| 7483 | } |
| 7484 | get visibleView() { |
| 7485 | return this.isOpen ? this.active : _ui_utils.SidebarView.NONE; |
| 7486 | } |
| 7487 | setInitialView(view = _ui_utils.SidebarView.NONE) { |
| 7488 | if (this.isInitialViewSet) { |
| 7489 | return; |
| 7490 | } |
| 7491 | this.isInitialViewSet = true; |
| 7492 | if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) { |
| 7493 | this.#dispatchEvent(); |
| 7494 | return; |
| 7495 | } |
| 7496 | this.switchView(view, true); |
| 7497 | if (!this.isInitialEventDispatched) { |
| 7498 | this.#dispatchEvent(); |
| 7499 | } |
| 7500 | } |
| 7501 | switchView(view, forceOpen = false) { |
| 7502 | const isViewChanged = view !== this.active; |
| 7503 | let shouldForceRendering = false; |
| 7504 | switch (view) { |
| 7505 | case _ui_utils.SidebarView.NONE: |
| 7506 | if (this.isOpen) { |
| 7507 | this.close(); |
| 7508 | } |
| 7509 | return; |
| 7510 | case _ui_utils.SidebarView.THUMBS: |
| 7511 | if (this.isOpen && isViewChanged) { |
| 7512 | shouldForceRendering = true; |
| 7513 | } |
| 7514 | break; |
| 7515 | case _ui_utils.SidebarView.OUTLINE: |
| 7516 | if (this.outlineButton.disabled) { |
| 7517 | return; |
| 7518 | } |
| 7519 | break; |
| 7520 | case _ui_utils.SidebarView.ATTACHMENTS: |
| 7521 | if (this.attachmentsButton.disabled) { |
| 7522 | return; |
| 7523 | } |
| 7524 | break; |
| 7525 | case _ui_utils.SidebarView.LAYERS: |
| 7526 | if (this.layersButton.disabled) { |
| 7527 | return; |
| 7528 | } |
| 7529 | break; |
| 7530 | default: |
| 7531 | console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`); |
| 7532 | return; |
| 7533 | } |
| 7534 | this.active = view; |
| 7535 | const isThumbs = view === _ui_utils.SidebarView.THUMBS, |
| 7536 | isOutline = view === _ui_utils.SidebarView.OUTLINE, |
| 7537 | isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS, |
| 7538 | isLayers = view === _ui_utils.SidebarView.LAYERS; |
| 7539 | this.thumbnailButton.classList.toggle("toggled", isThumbs); |
| 7540 | this.outlineButton.classList.toggle("toggled", isOutline); |
| 7541 | this.attachmentsButton.classList.toggle("toggled", isAttachments); |
| 7542 | this.layersButton.classList.toggle("toggled", isLayers); |
| 7543 | this.thumbnailButton.setAttribute("aria-checked", isThumbs); |
| 7544 | this.outlineButton.setAttribute("aria-checked", isOutline); |
| 7545 | this.attachmentsButton.setAttribute("aria-checked", isAttachments); |
| 7546 | this.layersButton.setAttribute("aria-checked", isLayers); |
| 7547 | this.thumbnailView.classList.toggle("hidden", !isThumbs); |
| 7548 | this.outlineView.classList.toggle("hidden", !isOutline); |
| 7549 | this.attachmentsView.classList.toggle("hidden", !isAttachments); |
| 7550 | this.layersView.classList.toggle("hidden", !isLayers); |
| 7551 | this._outlineOptionsContainer.classList.toggle("hidden", !isOutline); |
| 7552 | if (forceOpen && !this.isOpen) { |
| 7553 | this.open(); |
| 7554 | return; |
| 7555 | } |
| 7556 | if (shouldForceRendering) { |
| 7557 | this.#updateThumbnailViewer(); |
| 7558 | this.#forceRendering(); |
| 7559 | } |
| 7560 | if (isViewChanged) { |
| 7561 | this.#dispatchEvent(); |
| 7562 | } |
| 7563 | } |
| 7564 | open() { |
| 7565 | if (this.isOpen) { |
| 7566 | return; |
| 7567 | } |
| 7568 | this.isOpen = true; |
| 7569 | this.toggleButton.classList.add("toggled"); |
| 7570 | this.toggleButton.setAttribute("aria-expanded", "true"); |
| 7571 | this.outerContainer.classList.add("sidebarMoving", "sidebarOpen"); |
| 7572 | if (this.active === _ui_utils.SidebarView.THUMBS) { |
| 7573 | this.#updateThumbnailViewer(); |
| 7574 | } |
| 7575 | this.#forceRendering(); |
| 7576 | this.#dispatchEvent(); |
| 7577 | this.#hideUINotification(); |
| 7578 | } |
| 7579 | close() { |
| 7580 | if (!this.isOpen) { |
| 7581 | return; |
| 7582 | } |
| 7583 | this.isOpen = false; |
| 7584 | this.toggleButton.classList.remove("toggled"); |
| 7585 | this.toggleButton.setAttribute("aria-expanded", "false"); |
| 7586 | this.outerContainer.classList.add("sidebarMoving"); |
| 7587 | this.outerContainer.classList.remove("sidebarOpen"); |
| 7588 | this.#forceRendering(); |
| 7589 | this.#dispatchEvent(); |
| 7590 | } |
| 7591 | toggle() { |
| 7592 | if (this.isOpen) { |
| 7593 | this.close(); |
| 7594 | } else { |
| 7595 | this.open(); |
| 7596 | } |
| 7597 | } |
| 7598 | #dispatchEvent() { |
| 7599 | if (this.isInitialViewSet && !this.isInitialEventDispatched) { |
| 7600 | this.isInitialEventDispatched = true; |
| 7601 | } |
| 7602 | this.eventBus.dispatch("sidebarviewchanged", { |
| 7603 | source: this, |
| 7604 | view: this.visibleView |
| 7605 | }); |
| 7606 | } |
| 7607 | #forceRendering() { |
| 7608 | if (this.onToggled) { |
| 7609 | this.onToggled(); |
| 7610 | } else { |
| 7611 | this.pdfViewer.forceRendering(); |
| 7612 | this.pdfThumbnailViewer.forceRendering(); |
| 7613 | } |
| 7614 | } |
| 7615 | #updateThumbnailViewer() { |
| 7616 | const { |
| 7617 | pdfViewer, |
| 7618 | pdfThumbnailViewer |
| 7619 | } = this; |
| 7620 | const pagesCount = pdfViewer.pagesCount; |
| 7621 | for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) { |
| 7622 | const pageView = pdfViewer.getPageView(pageIndex); |
| 7623 | if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) { |
| 7624 | const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex); |
| 7625 | thumbnailView.setImage(pageView); |
| 7626 | } |
| 7627 | } |
| 7628 | pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber); |
| 7629 | } |
| 7630 | #showUINotification() { |
| 7631 | this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2"); |
| 7632 | this.l10n.translate(this.toggleButton); |
| 7633 | if (!this.isOpen) { |
| 7634 | this.toggleButton.classList.add(UI_NOTIFICATION_CLASS); |
| 7635 | } |
| 7636 | } |
| 7637 | #hideUINotification(reset = false) { |
| 7638 | if (this.isOpen || reset) { |
| 7639 | this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS); |
| 7640 | } |
| 7641 | if (reset) { |
| 7642 | this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar"); |
| 7643 | this.l10n.translate(this.toggleButton); |
| 7644 | } |
| 7645 | } |
| 7646 | #addEventListeners() { |
| 7647 | this.sidebarContainer.addEventListener("transitionend", evt => { |
| 7648 | if (evt.target === this.sidebarContainer) { |
| 7649 | this.outerContainer.classList.remove("sidebarMoving"); |
| 7650 | } |
| 7651 | }); |
| 7652 | this.toggleButton.addEventListener("click", () => { |
| 7653 | this.toggle(); |
| 7654 | }); |
| 7655 | this.thumbnailButton.addEventListener("click", () => { |
| 7656 | this.switchView(_ui_utils.SidebarView.THUMBS); |
| 7657 | }); |
| 7658 | this.outlineButton.addEventListener("click", () => { |
| 7659 | this.switchView(_ui_utils.SidebarView.OUTLINE); |
| 7660 | }); |
| 7661 | this.outlineButton.addEventListener("dblclick", () => { |
| 7662 | this.eventBus.dispatch("toggleoutlinetree", { |
| 7663 | source: this |
| 7664 | }); |
| 7665 | }); |
| 7666 | this.attachmentsButton.addEventListener("click", () => { |
| 7667 | this.switchView(_ui_utils.SidebarView.ATTACHMENTS); |
| 7668 | }); |
| 7669 | this.layersButton.addEventListener("click", () => { |
| 7670 | this.switchView(_ui_utils.SidebarView.LAYERS); |
| 7671 | }); |
| 7672 | this.layersButton.addEventListener("dblclick", () => { |
| 7673 | this.eventBus.dispatch("resetlayers", { |
| 7674 | source: this |
| 7675 | }); |
| 7676 | }); |
| 7677 | this._currentOutlineItemButton.addEventListener("click", () => { |
| 7678 | this.eventBus.dispatch("currentoutlineitem", { |
| 7679 | source: this |
| 7680 | }); |
| 7681 | }); |
| 7682 | const onTreeLoaded = (count, button, view) => { |
| 7683 | button.disabled = !count; |
| 7684 | if (count) { |
| 7685 | this.#showUINotification(); |
| 7686 | } else if (this.active === view) { |
| 7687 | this.switchView(_ui_utils.SidebarView.THUMBS); |
| 7688 | } |
| 7689 | }; |
| 7690 | this.eventBus._on("outlineloaded", evt => { |
| 7691 | onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE); |
| 7692 | evt.currentOutlineItemPromise.then(enabled => { |
| 7693 | if (!this.isInitialViewSet) { |
| 7694 | return; |
| 7695 | } |
| 7696 | this._currentOutlineItemButton.disabled = !enabled; |
| 7697 | }); |
| 7698 | }); |
| 7699 | this.eventBus._on("attachmentsloaded", evt => { |
| 7700 | onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS); |
| 7701 | }); |
| 7702 | this.eventBus._on("layersloaded", evt => { |
| 7703 | onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS); |
| 7704 | }); |
| 7705 | this.eventBus._on("presentationmodechanged", evt => { |
| 7706 | if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) { |
| 7707 | this.#updateThumbnailViewer(); |
| 7708 | } |
| 7709 | }); |
| 7710 | } |
| 7711 | } |
| 7712 | exports.PDFSidebar = PDFSidebar; |
| 7713 | |
| 7714 | /***/ }), |
| 7715 | /* 25 */ |
| 7716 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 7717 | |
| 7718 | |
| 7719 | |
| 7720 | Object.defineProperty(exports, "__esModule", ({ |
| 7721 | value: true |
| 7722 | })); |
| 7723 | exports.PDFSidebarResizer = void 0; |
| 7724 | var _ui_utils = __webpack_require__(1); |
| 7725 | const SIDEBAR_WIDTH_VAR = "--sidebar-width"; |
| 7726 | const SIDEBAR_MIN_WIDTH = 200; |
| 7727 | const SIDEBAR_RESIZING_CLASS = "sidebarResizing"; |
| 7728 | class PDFSidebarResizer { |
| 7729 | constructor(options, eventBus, l10n) { |
| 7730 | this.isRTL = false; |
| 7731 | this.sidebarOpen = false; |
| 7732 | this._width = null; |
| 7733 | this._outerContainerWidth = null; |
| 7734 | this._boundEvents = Object.create(null); |
| 7735 | this.outerContainer = options.outerContainer; |
| 7736 | this.resizer = options.resizer; |
| 7737 | this.eventBus = eventBus; |
| 7738 | l10n.getDirection().then(dir => { |
| 7739 | this.isRTL = dir === "rtl"; |
| 7740 | }); |
| 7741 | this._addEventListeners(); |
| 7742 | } |
| 7743 | get outerContainerWidth() { |
| 7744 | return this._outerContainerWidth ||= this.outerContainer.clientWidth; |
| 7745 | } |
| 7746 | _updateWidth(width = 0) { |
| 7747 | const maxWidth = Math.floor(this.outerContainerWidth / 2); |
| 7748 | if (width > maxWidth) { |
| 7749 | width = maxWidth; |
| 7750 | } |
| 7751 | if (width < SIDEBAR_MIN_WIDTH) { |
| 7752 | width = SIDEBAR_MIN_WIDTH; |
| 7753 | } |
| 7754 | if (width === this._width) { |
| 7755 | return false; |
| 7756 | } |
| 7757 | this._width = width; |
| 7758 | _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`); |
| 7759 | return true; |
| 7760 | } |
| 7761 | _mouseMove(evt) { |
| 7762 | let width = evt.clientX; |
| 7763 | if (this.isRTL) { |
| 7764 | width = this.outerContainerWidth - width; |
| 7765 | } |
| 7766 | this._updateWidth(width); |
| 7767 | } |
| 7768 | _mouseUp(evt) { |
| 7769 | this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS); |
| 7770 | this.eventBus.dispatch("resize", { |
| 7771 | source: this |
| 7772 | }); |
| 7773 | const _boundEvents = this._boundEvents; |
| 7774 | window.removeEventListener("mousemove", _boundEvents.mouseMove); |
| 7775 | window.removeEventListener("mouseup", _boundEvents.mouseUp); |
| 7776 | } |
| 7777 | _addEventListeners() { |
| 7778 | const _boundEvents = this._boundEvents; |
| 7779 | _boundEvents.mouseMove = this._mouseMove.bind(this); |
| 7780 | _boundEvents.mouseUp = this._mouseUp.bind(this); |
| 7781 | this.resizer.addEventListener("mousedown", evt => { |
| 7782 | if (evt.button !== 0) { |
| 7783 | return; |
| 7784 | } |
| 7785 | this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS); |
| 7786 | window.addEventListener("mousemove", _boundEvents.mouseMove); |
| 7787 | window.addEventListener("mouseup", _boundEvents.mouseUp); |
| 7788 | }); |
| 7789 | this.eventBus._on("sidebarviewchanged", evt => { |
| 7790 | this.sidebarOpen = !!evt?.view; |
| 7791 | }); |
| 7792 | this.eventBus._on("resize", evt => { |
| 7793 | if (evt?.source !== window) { |
| 7794 | return; |
| 7795 | } |
| 7796 | this._outerContainerWidth = null; |
| 7797 | if (!this._width) { |
| 7798 | return; |
| 7799 | } |
| 7800 | if (!this.sidebarOpen) { |
| 7801 | this._updateWidth(this._width); |
| 7802 | return; |
| 7803 | } |
| 7804 | this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS); |
| 7805 | const updated = this._updateWidth(this._width); |
| 7806 | Promise.resolve().then(() => { |
| 7807 | this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS); |
| 7808 | if (updated) { |
| 7809 | this.eventBus.dispatch("resize", { |
| 7810 | source: this |
| 7811 | }); |
| 7812 | } |
| 7813 | }); |
| 7814 | }); |
| 7815 | } |
| 7816 | } |
| 7817 | exports.PDFSidebarResizer = PDFSidebarResizer; |
| 7818 | |
| 7819 | /***/ }), |
| 7820 | /* 26 */ |
| 7821 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 7822 | |
| 7823 | |
| 7824 | |
| 7825 | Object.defineProperty(exports, "__esModule", ({ |
| 7826 | value: true |
| 7827 | })); |
| 7828 | exports.PDFThumbnailViewer = void 0; |
| 7829 | var _ui_utils = __webpack_require__(1); |
| 7830 | var _pdf_thumbnail_view = __webpack_require__(27); |
| 7831 | const THUMBNAIL_SCROLL_MARGIN = -19; |
| 7832 | const THUMBNAIL_SELECTED_CLASS = "selected"; |
| 7833 | class PDFThumbnailViewer { |
| 7834 | constructor({ |
| 7835 | container, |
| 7836 | eventBus, |
| 7837 | linkService, |
| 7838 | renderingQueue, |
| 7839 | l10n, |
| 7840 | pageColors |
| 7841 | }) { |
| 7842 | this.container = container; |
| 7843 | this.linkService = linkService; |
| 7844 | this.renderingQueue = renderingQueue; |
| 7845 | this.l10n = l10n; |
| 7846 | this.pageColors = pageColors || null; |
| 7847 | if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) { |
| 7848 | if (this.pageColors.background || this.pageColors.foreground) { |
| 7849 | console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."); |
| 7850 | } |
| 7851 | this.pageColors = null; |
| 7852 | } |
| 7853 | this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this)); |
| 7854 | this._resetView(); |
| 7855 | } |
| 7856 | _scrollUpdated() { |
| 7857 | this.renderingQueue.renderHighestPriority(); |
| 7858 | } |
| 7859 | getThumbnail(index) { |
| 7860 | return this._thumbnails[index]; |
| 7861 | } |
| 7862 | _getVisibleThumbs() { |
| 7863 | return (0, _ui_utils.getVisibleElements)({ |
| 7864 | scrollEl: this.container, |
| 7865 | views: this._thumbnails |
| 7866 | }); |
| 7867 | } |
| 7868 | scrollThumbnailIntoView(pageNumber) { |
| 7869 | if (!this.pdfDocument) { |
| 7870 | return; |
| 7871 | } |
| 7872 | const thumbnailView = this._thumbnails[pageNumber - 1]; |
| 7873 | if (!thumbnailView) { |
| 7874 | console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.'); |
| 7875 | return; |
| 7876 | } |
| 7877 | if (pageNumber !== this._currentPageNumber) { |
| 7878 | const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1]; |
| 7879 | prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS); |
| 7880 | thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS); |
| 7881 | } |
| 7882 | const { |
| 7883 | first, |
| 7884 | last, |
| 7885 | views |
| 7886 | } = this._getVisibleThumbs(); |
| 7887 | if (views.length > 0) { |
| 7888 | let shouldScroll = false; |
| 7889 | if (pageNumber <= first.id || pageNumber >= last.id) { |
| 7890 | shouldScroll = true; |
| 7891 | } else { |
| 7892 | for (const { |
| 7893 | id, |
| 7894 | percent |
| 7895 | } of views) { |
| 7896 | if (id !== pageNumber) { |
| 7897 | continue; |
| 7898 | } |
| 7899 | shouldScroll = percent < 100; |
| 7900 | break; |
| 7901 | } |
| 7902 | } |
| 7903 | if (shouldScroll) { |
| 7904 | (0, _ui_utils.scrollIntoView)(thumbnailView.div, { |
| 7905 | top: THUMBNAIL_SCROLL_MARGIN |
| 7906 | }); |
| 7907 | } |
| 7908 | } |
| 7909 | this._currentPageNumber = pageNumber; |
| 7910 | } |
| 7911 | get pagesRotation() { |
| 7912 | return this._pagesRotation; |
| 7913 | } |
| 7914 | set pagesRotation(rotation) { |
| 7915 | if (!(0, _ui_utils.isValidRotation)(rotation)) { |
| 7916 | throw new Error("Invalid thumbnails rotation angle."); |
| 7917 | } |
| 7918 | if (!this.pdfDocument) { |
| 7919 | return; |
| 7920 | } |
| 7921 | if (this._pagesRotation === rotation) { |
| 7922 | return; |
| 7923 | } |
| 7924 | this._pagesRotation = rotation; |
| 7925 | const updateArgs = { |
| 7926 | rotation |
| 7927 | }; |
| 7928 | for (const thumbnail of this._thumbnails) { |
| 7929 | thumbnail.update(updateArgs); |
| 7930 | } |
| 7931 | } |
| 7932 | cleanup() { |
| 7933 | for (const thumbnail of this._thumbnails) { |
| 7934 | if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 7935 | thumbnail.reset(); |
| 7936 | } |
| 7937 | } |
| 7938 | _pdf_thumbnail_view.TempImageFactory.destroyCanvas(); |
| 7939 | } |
| 7940 | _resetView() { |
| 7941 | this._thumbnails = []; |
| 7942 | this._currentPageNumber = 1; |
| 7943 | this._pageLabels = null; |
| 7944 | this._pagesRotation = 0; |
| 7945 | this.container.textContent = ""; |
| 7946 | } |
| 7947 | setDocument(pdfDocument) { |
| 7948 | if (this.pdfDocument) { |
| 7949 | this._cancelRendering(); |
| 7950 | this._resetView(); |
| 7951 | } |
| 7952 | this.pdfDocument = pdfDocument; |
| 7953 | if (!pdfDocument) { |
| 7954 | return; |
| 7955 | } |
| 7956 | const firstPagePromise = pdfDocument.getPage(1); |
| 7957 | const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig(); |
| 7958 | firstPagePromise.then(firstPdfPage => { |
| 7959 | const pagesCount = pdfDocument.numPages; |
| 7960 | const viewport = firstPdfPage.getViewport({ |
| 7961 | scale: 1 |
| 7962 | }); |
| 7963 | for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
| 7964 | const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({ |
| 7965 | container: this.container, |
| 7966 | id: pageNum, |
| 7967 | defaultViewport: viewport.clone(), |
| 7968 | optionalContentConfigPromise, |
| 7969 | linkService: this.linkService, |
| 7970 | renderingQueue: this.renderingQueue, |
| 7971 | l10n: this.l10n, |
| 7972 | pageColors: this.pageColors |
| 7973 | }); |
| 7974 | this._thumbnails.push(thumbnail); |
| 7975 | } |
| 7976 | this._thumbnails[0]?.setPdfPage(firstPdfPage); |
| 7977 | const thumbnailView = this._thumbnails[this._currentPageNumber - 1]; |
| 7978 | thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS); |
| 7979 | }).catch(reason => { |
| 7980 | console.error("Unable to initialize thumbnail viewer", reason); |
| 7981 | }); |
| 7982 | } |
| 7983 | _cancelRendering() { |
| 7984 | for (const thumbnail of this._thumbnails) { |
| 7985 | thumbnail.cancelRendering(); |
| 7986 | } |
| 7987 | } |
| 7988 | setPageLabels(labels) { |
| 7989 | if (!this.pdfDocument) { |
| 7990 | return; |
| 7991 | } |
| 7992 | if (!labels) { |
| 7993 | this._pageLabels = null; |
| 7994 | } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) { |
| 7995 | this._pageLabels = null; |
| 7996 | console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels."); |
| 7997 | } else { |
| 7998 | this._pageLabels = labels; |
| 7999 | } |
| 8000 | for (let i = 0, ii = this._thumbnails.length; i < ii; i++) { |
| 8001 | this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null); |
| 8002 | } |
| 8003 | } |
| 8004 | async #ensurePdfPageLoaded(thumbView) { |
| 8005 | if (thumbView.pdfPage) { |
| 8006 | return thumbView.pdfPage; |
| 8007 | } |
| 8008 | try { |
| 8009 | const pdfPage = await this.pdfDocument.getPage(thumbView.id); |
| 8010 | if (!thumbView.pdfPage) { |
| 8011 | thumbView.setPdfPage(pdfPage); |
| 8012 | } |
| 8013 | return pdfPage; |
| 8014 | } catch (reason) { |
| 8015 | console.error("Unable to get page for thumb view", reason); |
| 8016 | return null; |
| 8017 | } |
| 8018 | } |
| 8019 | #getScrollAhead(visible) { |
| 8020 | if (visible.first?.id === 1) { |
| 8021 | return true; |
| 8022 | } else if (visible.last?.id === this._thumbnails.length) { |
| 8023 | return false; |
| 8024 | } |
| 8025 | return this.scroll.down; |
| 8026 | } |
| 8027 | forceRendering() { |
| 8028 | const visibleThumbs = this._getVisibleThumbs(); |
| 8029 | const scrollAhead = this.#getScrollAhead(visibleThumbs); |
| 8030 | const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead); |
| 8031 | if (thumbView) { |
| 8032 | this.#ensurePdfPageLoaded(thumbView).then(() => { |
| 8033 | this.renderingQueue.renderView(thumbView); |
| 8034 | }); |
| 8035 | return true; |
| 8036 | } |
| 8037 | return false; |
| 8038 | } |
| 8039 | } |
| 8040 | exports.PDFThumbnailViewer = PDFThumbnailViewer; |
| 8041 | |
| 8042 | /***/ }), |
| 8043 | /* 27 */ |
| 8044 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 8045 | |
| 8046 | |
| 8047 | |
| 8048 | Object.defineProperty(exports, "__esModule", ({ |
| 8049 | value: true |
| 8050 | })); |
| 8051 | exports.TempImageFactory = exports.PDFThumbnailView = void 0; |
| 8052 | var _ui_utils = __webpack_require__(1); |
| 8053 | var _pdfjsLib = __webpack_require__(5); |
| 8054 | const DRAW_UPSCALE_FACTOR = 2; |
| 8055 | const MAX_NUM_SCALING_STEPS = 3; |
| 8056 | const THUMBNAIL_CANVAS_BORDER_WIDTH = 1; |
| 8057 | const THUMBNAIL_WIDTH = 98; |
| 8058 | class TempImageFactory { |
| 8059 | static #tempCanvas = null; |
| 8060 | static getCanvas(width, height) { |
| 8061 | const tempCanvas = this.#tempCanvas ||= document.createElement("canvas"); |
| 8062 | tempCanvas.width = width; |
| 8063 | tempCanvas.height = height; |
| 8064 | const ctx = tempCanvas.getContext("2d", { |
| 8065 | alpha: false |
| 8066 | }); |
| 8067 | ctx.save(); |
| 8068 | ctx.fillStyle = "rgb(255, 255, 255)"; |
| 8069 | ctx.fillRect(0, 0, width, height); |
| 8070 | ctx.restore(); |
| 8071 | return [tempCanvas, tempCanvas.getContext("2d")]; |
| 8072 | } |
| 8073 | static destroyCanvas() { |
| 8074 | const tempCanvas = this.#tempCanvas; |
| 8075 | if (tempCanvas) { |
| 8076 | tempCanvas.width = 0; |
| 8077 | tempCanvas.height = 0; |
| 8078 | } |
| 8079 | this.#tempCanvas = null; |
| 8080 | } |
| 8081 | } |
| 8082 | exports.TempImageFactory = TempImageFactory; |
| 8083 | class PDFThumbnailView { |
| 8084 | constructor({ |
| 8085 | container, |
| 8086 | id, |
| 8087 | defaultViewport, |
| 8088 | optionalContentConfigPromise, |
| 8089 | linkService, |
| 8090 | renderingQueue, |
| 8091 | l10n, |
| 8092 | pageColors |
| 8093 | }) { |
| 8094 | this.id = id; |
| 8095 | this.renderingId = "thumbnail" + id; |
| 8096 | this.pageLabel = null; |
| 8097 | this.pdfPage = null; |
| 8098 | this.rotation = 0; |
| 8099 | this.viewport = defaultViewport; |
| 8100 | this.pdfPageRotate = defaultViewport.rotation; |
| 8101 | this._optionalContentConfigPromise = optionalContentConfigPromise || null; |
| 8102 | this.pageColors = pageColors || null; |
| 8103 | this.linkService = linkService; |
| 8104 | this.renderingQueue = renderingQueue; |
| 8105 | this.renderTask = null; |
| 8106 | this.renderingState = _ui_utils.RenderingStates.INITIAL; |
| 8107 | this.resume = null; |
| 8108 | const pageWidth = this.viewport.width, |
| 8109 | pageHeight = this.viewport.height, |
| 8110 | pageRatio = pageWidth / pageHeight; |
| 8111 | this.canvasWidth = THUMBNAIL_WIDTH; |
| 8112 | this.canvasHeight = this.canvasWidth / pageRatio | 0; |
| 8113 | this.scale = this.canvasWidth / pageWidth; |
| 8114 | this.l10n = l10n; |
| 8115 | const anchor = document.createElement("a"); |
| 8116 | anchor.href = linkService.getAnchorUrl("#page=" + id); |
| 8117 | this._thumbPageTitle.then(msg => { |
| 8118 | anchor.title = msg; |
| 8119 | }); |
| 8120 | anchor.onclick = function () { |
| 8121 | linkService.goToPage(id); |
| 8122 | return false; |
| 8123 | }; |
| 8124 | this.anchor = anchor; |
| 8125 | const div = document.createElement("div"); |
| 8126 | div.className = "thumbnail"; |
| 8127 | div.setAttribute("data-page-number", this.id); |
| 8128 | this.div = div; |
| 8129 | const ring = document.createElement("div"); |
| 8130 | ring.className = "thumbnailSelectionRing"; |
| 8131 | const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH; |
| 8132 | ring.style.width = this.canvasWidth + borderAdjustment + "px"; |
| 8133 | ring.style.height = this.canvasHeight + borderAdjustment + "px"; |
| 8134 | this.ring = ring; |
| 8135 | div.append(ring); |
| 8136 | anchor.append(div); |
| 8137 | container.append(anchor); |
| 8138 | } |
| 8139 | setPdfPage(pdfPage) { |
| 8140 | this.pdfPage = pdfPage; |
| 8141 | this.pdfPageRotate = pdfPage.rotate; |
| 8142 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 8143 | this.viewport = pdfPage.getViewport({ |
| 8144 | scale: 1, |
| 8145 | rotation: totalRotation |
| 8146 | }); |
| 8147 | this.reset(); |
| 8148 | } |
| 8149 | reset() { |
| 8150 | this.cancelRendering(); |
| 8151 | this.renderingState = _ui_utils.RenderingStates.INITIAL; |
| 8152 | const pageWidth = this.viewport.width, |
| 8153 | pageHeight = this.viewport.height, |
| 8154 | pageRatio = pageWidth / pageHeight; |
| 8155 | this.canvasHeight = this.canvasWidth / pageRatio | 0; |
| 8156 | this.scale = this.canvasWidth / pageWidth; |
| 8157 | this.div.removeAttribute("data-loaded"); |
| 8158 | const ring = this.ring; |
| 8159 | ring.textContent = ""; |
| 8160 | const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH; |
| 8161 | ring.style.width = this.canvasWidth + borderAdjustment + "px"; |
| 8162 | ring.style.height = this.canvasHeight + borderAdjustment + "px"; |
| 8163 | if (this.canvas) { |
| 8164 | this.canvas.width = 0; |
| 8165 | this.canvas.height = 0; |
| 8166 | delete this.canvas; |
| 8167 | } |
| 8168 | if (this.image) { |
| 8169 | this.image.removeAttribute("src"); |
| 8170 | delete this.image; |
| 8171 | } |
| 8172 | } |
| 8173 | update({ |
| 8174 | rotation = null |
| 8175 | }) { |
| 8176 | if (typeof rotation === "number") { |
| 8177 | this.rotation = rotation; |
| 8178 | } |
| 8179 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 8180 | this.viewport = this.viewport.clone({ |
| 8181 | scale: 1, |
| 8182 | rotation: totalRotation |
| 8183 | }); |
| 8184 | this.reset(); |
| 8185 | } |
| 8186 | cancelRendering() { |
| 8187 | if (this.renderTask) { |
| 8188 | this.renderTask.cancel(); |
| 8189 | this.renderTask = null; |
| 8190 | } |
| 8191 | this.resume = null; |
| 8192 | } |
| 8193 | _getPageDrawContext(upscaleFactor = 1) { |
| 8194 | const canvas = document.createElement("canvas"); |
| 8195 | const ctx = canvas.getContext("2d", { |
| 8196 | alpha: false |
| 8197 | }); |
| 8198 | const outputScale = new _ui_utils.OutputScale(); |
| 8199 | canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0; |
| 8200 | canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0; |
| 8201 | const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null; |
| 8202 | return { |
| 8203 | ctx, |
| 8204 | canvas, |
| 8205 | transform |
| 8206 | }; |
| 8207 | } |
| 8208 | _convertCanvasToImage(canvas) { |
| 8209 | if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 8210 | throw new Error("_convertCanvasToImage: Rendering has not finished."); |
| 8211 | } |
| 8212 | const reducedCanvas = this._reduceImage(canvas); |
| 8213 | const image = document.createElement("img"); |
| 8214 | image.className = "thumbnailImage"; |
| 8215 | this._thumbPageCanvas.then(msg => { |
| 8216 | image.setAttribute("aria-label", msg); |
| 8217 | }); |
| 8218 | image.style.width = this.canvasWidth + "px"; |
| 8219 | image.style.height = this.canvasHeight + "px"; |
| 8220 | image.src = reducedCanvas.toDataURL(); |
| 8221 | this.image = image; |
| 8222 | this.div.setAttribute("data-loaded", true); |
| 8223 | this.ring.append(image); |
| 8224 | reducedCanvas.width = 0; |
| 8225 | reducedCanvas.height = 0; |
| 8226 | } |
| 8227 | draw() { |
| 8228 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) { |
| 8229 | console.error("Must be in new state before drawing"); |
| 8230 | return Promise.resolve(); |
| 8231 | } |
| 8232 | const { |
| 8233 | pdfPage |
| 8234 | } = this; |
| 8235 | if (!pdfPage) { |
| 8236 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 8237 | return Promise.reject(new Error("pdfPage is not loaded")); |
| 8238 | } |
| 8239 | this.renderingState = _ui_utils.RenderingStates.RUNNING; |
| 8240 | const finishRenderTask = async (error = null) => { |
| 8241 | if (renderTask === this.renderTask) { |
| 8242 | this.renderTask = null; |
| 8243 | } |
| 8244 | if (error instanceof _pdfjsLib.RenderingCancelledException) { |
| 8245 | return; |
| 8246 | } |
| 8247 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 8248 | this._convertCanvasToImage(canvas); |
| 8249 | if (error) { |
| 8250 | throw error; |
| 8251 | } |
| 8252 | }; |
| 8253 | const { |
| 8254 | ctx, |
| 8255 | canvas, |
| 8256 | transform |
| 8257 | } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR); |
| 8258 | const drawViewport = this.viewport.clone({ |
| 8259 | scale: DRAW_UPSCALE_FACTOR * this.scale |
| 8260 | }); |
| 8261 | const renderContinueCallback = cont => { |
| 8262 | if (!this.renderingQueue.isHighestPriority(this)) { |
| 8263 | this.renderingState = _ui_utils.RenderingStates.PAUSED; |
| 8264 | this.resume = () => { |
| 8265 | this.renderingState = _ui_utils.RenderingStates.RUNNING; |
| 8266 | cont(); |
| 8267 | }; |
| 8268 | return; |
| 8269 | } |
| 8270 | cont(); |
| 8271 | }; |
| 8272 | const renderContext = { |
| 8273 | canvasContext: ctx, |
| 8274 | transform, |
| 8275 | viewport: drawViewport, |
| 8276 | optionalContentConfigPromise: this._optionalContentConfigPromise, |
| 8277 | pageColors: this.pageColors |
| 8278 | }; |
| 8279 | const renderTask = this.renderTask = pdfPage.render(renderContext); |
| 8280 | renderTask.onContinue = renderContinueCallback; |
| 8281 | const resultPromise = renderTask.promise.then(function () { |
| 8282 | return finishRenderTask(null); |
| 8283 | }, function (error) { |
| 8284 | return finishRenderTask(error); |
| 8285 | }); |
| 8286 | resultPromise.finally(() => { |
| 8287 | canvas.width = 0; |
| 8288 | canvas.height = 0; |
| 8289 | const pageCached = this.linkService.isPageCached(this.id); |
| 8290 | if (!pageCached) { |
| 8291 | this.pdfPage?.cleanup(); |
| 8292 | } |
| 8293 | }); |
| 8294 | return resultPromise; |
| 8295 | } |
| 8296 | setImage(pageView) { |
| 8297 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) { |
| 8298 | return; |
| 8299 | } |
| 8300 | const { |
| 8301 | thumbnailCanvas: canvas, |
| 8302 | pdfPage, |
| 8303 | scale |
| 8304 | } = pageView; |
| 8305 | if (!canvas) { |
| 8306 | return; |
| 8307 | } |
| 8308 | if (!this.pdfPage) { |
| 8309 | this.setPdfPage(pdfPage); |
| 8310 | } |
| 8311 | if (scale < this.scale) { |
| 8312 | return; |
| 8313 | } |
| 8314 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 8315 | this._convertCanvasToImage(canvas); |
| 8316 | } |
| 8317 | _reduceImage(img) { |
| 8318 | const { |
| 8319 | ctx, |
| 8320 | canvas |
| 8321 | } = this._getPageDrawContext(); |
| 8322 | if (img.width <= 2 * canvas.width) { |
| 8323 | ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height); |
| 8324 | return canvas; |
| 8325 | } |
| 8326 | let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS; |
| 8327 | let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS; |
| 8328 | const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight); |
| 8329 | while (reducedWidth > img.width || reducedHeight > img.height) { |
| 8330 | reducedWidth >>= 1; |
| 8331 | reducedHeight >>= 1; |
| 8332 | } |
| 8333 | reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight); |
| 8334 | while (reducedWidth > 2 * canvas.width) { |
| 8335 | reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1); |
| 8336 | reducedWidth >>= 1; |
| 8337 | reducedHeight >>= 1; |
| 8338 | } |
| 8339 | ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height); |
| 8340 | return canvas; |
| 8341 | } |
| 8342 | get _thumbPageTitle() { |
| 8343 | return this.l10n.get("thumb_page_title", { |
| 8344 | page: this.pageLabel ?? this.id |
| 8345 | }); |
| 8346 | } |
| 8347 | get _thumbPageCanvas() { |
| 8348 | return this.l10n.get("thumb_page_canvas", { |
| 8349 | page: this.pageLabel ?? this.id |
| 8350 | }); |
| 8351 | } |
| 8352 | setPageLabel(label) { |
| 8353 | this.pageLabel = typeof label === "string" ? label : null; |
| 8354 | this._thumbPageTitle.then(msg => { |
| 8355 | this.anchor.title = msg; |
| 8356 | }); |
| 8357 | if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 8358 | return; |
| 8359 | } |
| 8360 | this._thumbPageCanvas.then(msg => { |
| 8361 | this.image?.setAttribute("aria-label", msg); |
| 8362 | }); |
| 8363 | } |
| 8364 | } |
| 8365 | exports.PDFThumbnailView = PDFThumbnailView; |
| 8366 | |
| 8367 | /***/ }), |
| 8368 | /* 28 */ |
| 8369 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 8370 | |
| 8371 | |
| 8372 | |
| 8373 | Object.defineProperty(exports, "__esModule", ({ |
| 8374 | value: true |
| 8375 | })); |
| 8376 | exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0; |
| 8377 | var _pdfjsLib = __webpack_require__(5); |
| 8378 | var _ui_utils = __webpack_require__(1); |
| 8379 | var _l10n_utils = __webpack_require__(29); |
| 8380 | var _pdf_page_view = __webpack_require__(30); |
| 8381 | var _pdf_rendering_queue = __webpack_require__(22); |
| 8382 | var _pdf_link_service = __webpack_require__(3); |
| 8383 | const DEFAULT_CACHE_SIZE = 10; |
| 8384 | const ENABLE_PERMISSIONS_CLASS = "enablePermissions"; |
| 8385 | const PagesCountLimit = { |
| 8386 | FORCE_SCROLL_MODE_PAGE: 15000, |
| 8387 | FORCE_LAZY_PAGE_INIT: 7500, |
| 8388 | PAUSE_EAGER_PAGE_INIT: 250 |
| 8389 | }; |
| 8390 | exports.PagesCountLimit = PagesCountLimit; |
| 8391 | function isValidAnnotationEditorMode(mode) { |
| 8392 | return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE; |
| 8393 | } |
| 8394 | class PDFPageViewBuffer { |
| 8395 | #buf = new Set(); |
| 8396 | #size = 0; |
| 8397 | constructor(size) { |
| 8398 | this.#size = size; |
| 8399 | } |
| 8400 | push(view) { |
| 8401 | const buf = this.#buf; |
| 8402 | if (buf.has(view)) { |
| 8403 | buf.delete(view); |
| 8404 | } |
| 8405 | buf.add(view); |
| 8406 | if (buf.size > this.#size) { |
| 8407 | this.#destroyFirstView(); |
| 8408 | } |
| 8409 | } |
| 8410 | resize(newSize, idsToKeep = null) { |
| 8411 | this.#size = newSize; |
| 8412 | const buf = this.#buf; |
| 8413 | if (idsToKeep) { |
| 8414 | const ii = buf.size; |
| 8415 | let i = 1; |
| 8416 | for (const view of buf) { |
| 8417 | if (idsToKeep.has(view.id)) { |
| 8418 | buf.delete(view); |
| 8419 | buf.add(view); |
| 8420 | } |
| 8421 | if (++i > ii) { |
| 8422 | break; |
| 8423 | } |
| 8424 | } |
| 8425 | } |
| 8426 | while (buf.size > this.#size) { |
| 8427 | this.#destroyFirstView(); |
| 8428 | } |
| 8429 | } |
| 8430 | has(view) { |
| 8431 | return this.#buf.has(view); |
| 8432 | } |
| 8433 | [Symbol.iterator]() { |
| 8434 | return this.#buf.keys(); |
| 8435 | } |
| 8436 | #destroyFirstView() { |
| 8437 | const firstView = this.#buf.keys().next().value; |
| 8438 | firstView?.destroy(); |
| 8439 | this.#buf.delete(firstView); |
| 8440 | } |
| 8441 | } |
| 8442 | exports.PDFPageViewBuffer = PDFPageViewBuffer; |
| 8443 | class PDFViewer { |
| 8444 | #buffer = null; |
| 8445 | #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE; |
| 8446 | #annotationEditorUIManager = null; |
| 8447 | #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS; |
| 8448 | #containerTopLeft = null; |
| 8449 | #enablePermissions = false; |
| 8450 | #previousContainerHeight = 0; |
| 8451 | #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this)); |
| 8452 | #scrollModePageState = null; |
| 8453 | #onVisibilityChange = null; |
| 8454 | #scaleTimeoutId = null; |
| 8455 | constructor(options) { |
| 8456 | const viewerVersion = '3.3.122'; |
| 8457 | if (_pdfjsLib.version !== viewerVersion) { |
| 8458 | throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`); |
| 8459 | } |
| 8460 | this.container = options.container; |
| 8461 | this.viewer = options.viewer || options.container.firstElementChild; |
| 8462 | if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") { |
| 8463 | throw new Error("Invalid `container` and/or `viewer` option."); |
| 8464 | } |
| 8465 | if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") { |
| 8466 | throw new Error("The `container` must be absolutely positioned."); |
| 8467 | } |
| 8468 | this.#resizeObserver.observe(this.container); |
| 8469 | this.eventBus = options.eventBus; |
| 8470 | this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService(); |
| 8471 | this.downloadManager = options.downloadManager || null; |
| 8472 | this.findController = options.findController || null; |
| 8473 | this._scriptingManager = options.scriptingManager || null; |
| 8474 | this.removePageBorders = options.removePageBorders || false; |
| 8475 | this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE; |
| 8476 | this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS; |
| 8477 | this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE; |
| 8478 | this.imageResourcesPath = options.imageResourcesPath || ""; |
| 8479 | this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; |
| 8480 | this.renderer = options.renderer || _ui_utils.RendererType.CANVAS; |
| 8481 | this.useOnlyCssZoom = options.useOnlyCssZoom || false; |
| 8482 | this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true; |
| 8483 | this.maxCanvasPixels = options.maxCanvasPixels; |
| 8484 | this.l10n = options.l10n || _l10n_utils.NullL10n; |
| 8485 | this.#enablePermissions = options.enablePermissions || false; |
| 8486 | this.pageColors = options.pageColors || null; |
| 8487 | if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) { |
| 8488 | if (this.pageColors.background || this.pageColors.foreground) { |
| 8489 | console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."); |
| 8490 | } |
| 8491 | this.pageColors = null; |
| 8492 | } |
| 8493 | this.defaultRenderingQueue = !options.renderingQueue; |
| 8494 | if (this.defaultRenderingQueue) { |
| 8495 | this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue(); |
| 8496 | this.renderingQueue.setViewer(this); |
| 8497 | } else { |
| 8498 | this.renderingQueue = options.renderingQueue; |
| 8499 | } |
| 8500 | this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this)); |
| 8501 | this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN; |
| 8502 | this._onBeforeDraw = this._onAfterDraw = null; |
| 8503 | this._resetView(); |
| 8504 | if (this.removePageBorders) { |
| 8505 | this.viewer.classList.add("removePageBorders"); |
| 8506 | } |
| 8507 | this.#updateContainerHeightCss(); |
| 8508 | } |
| 8509 | get pagesCount() { |
| 8510 | return this._pages.length; |
| 8511 | } |
| 8512 | getPageView(index) { |
| 8513 | return this._pages[index]; |
| 8514 | } |
| 8515 | get pageViewsReady() { |
| 8516 | if (!this._pagesCapability.settled) { |
| 8517 | return false; |
| 8518 | } |
| 8519 | return this._pages.every(function (pageView) { |
| 8520 | return pageView?.pdfPage; |
| 8521 | }); |
| 8522 | } |
| 8523 | get renderForms() { |
| 8524 | return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS; |
| 8525 | } |
| 8526 | get enableScripting() { |
| 8527 | return !!this._scriptingManager; |
| 8528 | } |
| 8529 | get currentPageNumber() { |
| 8530 | return this._currentPageNumber; |
| 8531 | } |
| 8532 | set currentPageNumber(val) { |
| 8533 | if (!Number.isInteger(val)) { |
| 8534 | throw new Error("Invalid page number."); |
| 8535 | } |
| 8536 | if (!this.pdfDocument) { |
| 8537 | return; |
| 8538 | } |
| 8539 | if (!this._setCurrentPageNumber(val, true)) { |
| 8540 | console.error(`currentPageNumber: "${val}" is not a valid page.`); |
| 8541 | } |
| 8542 | } |
| 8543 | _setCurrentPageNumber(val, resetCurrentPageView = false) { |
| 8544 | if (this._currentPageNumber === val) { |
| 8545 | if (resetCurrentPageView) { |
| 8546 | this.#resetCurrentPageView(); |
| 8547 | } |
| 8548 | return true; |
| 8549 | } |
| 8550 | if (!(0 < val && val <= this.pagesCount)) { |
| 8551 | return false; |
| 8552 | } |
| 8553 | const previous = this._currentPageNumber; |
| 8554 | this._currentPageNumber = val; |
| 8555 | this.eventBus.dispatch("pagechanging", { |
| 8556 | source: this, |
| 8557 | pageNumber: val, |
| 8558 | pageLabel: this._pageLabels?.[val - 1] ?? null, |
| 8559 | previous |
| 8560 | }); |
| 8561 | if (resetCurrentPageView) { |
| 8562 | this.#resetCurrentPageView(); |
| 8563 | } |
| 8564 | return true; |
| 8565 | } |
| 8566 | get currentPageLabel() { |
| 8567 | return this._pageLabels?.[this._currentPageNumber - 1] ?? null; |
| 8568 | } |
| 8569 | set currentPageLabel(val) { |
| 8570 | if (!this.pdfDocument) { |
| 8571 | return; |
| 8572 | } |
| 8573 | let page = val | 0; |
| 8574 | if (this._pageLabels) { |
| 8575 | const i = this._pageLabels.indexOf(val); |
| 8576 | if (i >= 0) { |
| 8577 | page = i + 1; |
| 8578 | } |
| 8579 | } |
| 8580 | if (!this._setCurrentPageNumber(page, true)) { |
| 8581 | console.error(`currentPageLabel: "${val}" is not a valid page.`); |
| 8582 | } |
| 8583 | } |
| 8584 | get currentScale() { |
| 8585 | return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE; |
| 8586 | } |
| 8587 | set currentScale(val) { |
| 8588 | if (isNaN(val)) { |
| 8589 | throw new Error("Invalid numeric scale."); |
| 8590 | } |
| 8591 | if (!this.pdfDocument) { |
| 8592 | return; |
| 8593 | } |
| 8594 | this._setScale(val, { |
| 8595 | noScroll: false |
| 8596 | }); |
| 8597 | } |
| 8598 | get currentScaleValue() { |
| 8599 | return this._currentScaleValue; |
| 8600 | } |
| 8601 | set currentScaleValue(val) { |
| 8602 | if (!this.pdfDocument) { |
| 8603 | return; |
| 8604 | } |
| 8605 | this._setScale(val, { |
| 8606 | noScroll: false |
| 8607 | }); |
| 8608 | } |
| 8609 | get pagesRotation() { |
| 8610 | return this._pagesRotation; |
| 8611 | } |
| 8612 | set pagesRotation(rotation) { |
| 8613 | if (!(0, _ui_utils.isValidRotation)(rotation)) { |
| 8614 | throw new Error("Invalid pages rotation angle."); |
| 8615 | } |
| 8616 | if (!this.pdfDocument) { |
| 8617 | return; |
| 8618 | } |
| 8619 | rotation %= 360; |
| 8620 | if (rotation < 0) { |
| 8621 | rotation += 360; |
| 8622 | } |
| 8623 | if (this._pagesRotation === rotation) { |
| 8624 | return; |
| 8625 | } |
| 8626 | this._pagesRotation = rotation; |
| 8627 | const pageNumber = this._currentPageNumber; |
| 8628 | this.refresh(true, { |
| 8629 | rotation |
| 8630 | }); |
| 8631 | if (this._currentScaleValue) { |
| 8632 | this._setScale(this._currentScaleValue, { |
| 8633 | noScroll: true |
| 8634 | }); |
| 8635 | } |
| 8636 | this.eventBus.dispatch("rotationchanging", { |
| 8637 | source: this, |
| 8638 | pagesRotation: rotation, |
| 8639 | pageNumber |
| 8640 | }); |
| 8641 | if (this.defaultRenderingQueue) { |
| 8642 | this.update(); |
| 8643 | } |
| 8644 | } |
| 8645 | get firstPagePromise() { |
| 8646 | return this.pdfDocument ? this._firstPageCapability.promise : null; |
| 8647 | } |
| 8648 | get onePageRendered() { |
| 8649 | return this.pdfDocument ? this._onePageRenderedCapability.promise : null; |
| 8650 | } |
| 8651 | get pagesPromise() { |
| 8652 | return this.pdfDocument ? this._pagesCapability.promise : null; |
| 8653 | } |
| 8654 | #layerProperties() { |
| 8655 | const self = this; |
| 8656 | return { |
| 8657 | get annotationEditorUIManager() { |
| 8658 | return self.#annotationEditorUIManager; |
| 8659 | }, |
| 8660 | get annotationStorage() { |
| 8661 | return self.pdfDocument?.annotationStorage; |
| 8662 | }, |
| 8663 | get downloadManager() { |
| 8664 | return self.downloadManager; |
| 8665 | }, |
| 8666 | get enableScripting() { |
| 8667 | return !!self._scriptingManager; |
| 8668 | }, |
| 8669 | get fieldObjectsPromise() { |
| 8670 | return self.pdfDocument?.getFieldObjects(); |
| 8671 | }, |
| 8672 | get findController() { |
| 8673 | return self.findController; |
| 8674 | }, |
| 8675 | get hasJSActionsPromise() { |
| 8676 | return self.pdfDocument?.hasJSActions(); |
| 8677 | }, |
| 8678 | get linkService() { |
| 8679 | return self.linkService; |
| 8680 | } |
| 8681 | }; |
| 8682 | } |
| 8683 | #initializePermissions(permissions) { |
| 8684 | const params = { |
| 8685 | annotationEditorMode: this.#annotationEditorMode, |
| 8686 | annotationMode: this.#annotationMode, |
| 8687 | textLayerMode: this.textLayerMode |
| 8688 | }; |
| 8689 | if (!permissions) { |
| 8690 | return params; |
| 8691 | } |
| 8692 | if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) { |
| 8693 | this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS); |
| 8694 | } |
| 8695 | if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) { |
| 8696 | params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE; |
| 8697 | } |
| 8698 | if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) { |
| 8699 | params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE; |
| 8700 | } |
| 8701 | return params; |
| 8702 | } |
| 8703 | #onePageRenderedOrForceFetch() { |
| 8704 | if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) { |
| 8705 | return Promise.resolve(); |
| 8706 | } |
| 8707 | const visibilityChangePromise = new Promise(resolve => { |
| 8708 | this.#onVisibilityChange = () => { |
| 8709 | if (document.visibilityState !== "hidden") { |
| 8710 | return; |
| 8711 | } |
| 8712 | resolve(); |
| 8713 | document.removeEventListener("visibilitychange", this.#onVisibilityChange); |
| 8714 | this.#onVisibilityChange = null; |
| 8715 | }; |
| 8716 | document.addEventListener("visibilitychange", this.#onVisibilityChange); |
| 8717 | }); |
| 8718 | return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]); |
| 8719 | } |
| 8720 | setDocument(pdfDocument) { |
| 8721 | if (this.pdfDocument) { |
| 8722 | this.eventBus.dispatch("pagesdestroy", { |
| 8723 | source: this |
| 8724 | }); |
| 8725 | this._cancelRendering(); |
| 8726 | this._resetView(); |
| 8727 | this.findController?.setDocument(null); |
| 8728 | this._scriptingManager?.setDocument(null); |
| 8729 | if (this.#annotationEditorUIManager) { |
| 8730 | this.#annotationEditorUIManager.destroy(); |
| 8731 | this.#annotationEditorUIManager = null; |
| 8732 | } |
| 8733 | } |
| 8734 | this.pdfDocument = pdfDocument; |
| 8735 | if (!pdfDocument) { |
| 8736 | return; |
| 8737 | } |
| 8738 | const pagesCount = pdfDocument.numPages; |
| 8739 | const firstPagePromise = pdfDocument.getPage(1); |
| 8740 | const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig(); |
| 8741 | const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve(); |
| 8742 | if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) { |
| 8743 | console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document."); |
| 8744 | const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE; |
| 8745 | this.eventBus.dispatch("scrollmodechanged", { |
| 8746 | source: this, |
| 8747 | mode |
| 8748 | }); |
| 8749 | } |
| 8750 | this._pagesCapability.promise.then(() => { |
| 8751 | this.eventBus.dispatch("pagesloaded", { |
| 8752 | source: this, |
| 8753 | pagesCount |
| 8754 | }); |
| 8755 | }, () => {}); |
| 8756 | this._onBeforeDraw = evt => { |
| 8757 | const pageView = this._pages[evt.pageNumber - 1]; |
| 8758 | if (!pageView) { |
| 8759 | return; |
| 8760 | } |
| 8761 | this.#buffer.push(pageView); |
| 8762 | }; |
| 8763 | this.eventBus._on("pagerender", this._onBeforeDraw); |
| 8764 | this._onAfterDraw = evt => { |
| 8765 | if (evt.cssTransform || this._onePageRenderedCapability.settled) { |
| 8766 | return; |
| 8767 | } |
| 8768 | this._onePageRenderedCapability.resolve({ |
| 8769 | timestamp: evt.timestamp |
| 8770 | }); |
| 8771 | this.eventBus._off("pagerendered", this._onAfterDraw); |
| 8772 | this._onAfterDraw = null; |
| 8773 | if (this.#onVisibilityChange) { |
| 8774 | document.removeEventListener("visibilitychange", this.#onVisibilityChange); |
| 8775 | this.#onVisibilityChange = null; |
| 8776 | } |
| 8777 | }; |
| 8778 | this.eventBus._on("pagerendered", this._onAfterDraw); |
| 8779 | Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => { |
| 8780 | if (pdfDocument !== this.pdfDocument) { |
| 8781 | return; |
| 8782 | } |
| 8783 | this._firstPageCapability.resolve(firstPdfPage); |
| 8784 | this._optionalContentConfigPromise = optionalContentConfigPromise; |
| 8785 | const { |
| 8786 | annotationEditorMode, |
| 8787 | annotationMode, |
| 8788 | textLayerMode |
| 8789 | } = this.#initializePermissions(permissions); |
| 8790 | if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) { |
| 8791 | const mode = annotationEditorMode; |
| 8792 | if (pdfDocument.isPureXfa) { |
| 8793 | console.warn("Warning: XFA-editing is not implemented."); |
| 8794 | } else if (isValidAnnotationEditorMode(mode)) { |
| 8795 | this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage); |
| 8796 | if (mode !== _pdfjsLib.AnnotationEditorType.NONE) { |
| 8797 | this.#annotationEditorUIManager.updateMode(mode); |
| 8798 | } |
| 8799 | } else { |
| 8800 | console.error(`Invalid AnnotationEditor mode: ${mode}`); |
| 8801 | } |
| 8802 | } |
| 8803 | const layerProperties = this.#layerProperties.bind(this); |
| 8804 | const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer; |
| 8805 | const scale = this.currentScale; |
| 8806 | const viewport = firstPdfPage.getViewport({ |
| 8807 | scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS |
| 8808 | }); |
| 8809 | this.viewer.style.setProperty("--scale-factor", viewport.scale); |
| 8810 | for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
| 8811 | const pageView = new _pdf_page_view.PDFPageView({ |
| 8812 | container: viewerElement, |
| 8813 | eventBus: this.eventBus, |
| 8814 | id: pageNum, |
| 8815 | scale, |
| 8816 | defaultViewport: viewport.clone(), |
| 8817 | optionalContentConfigPromise, |
| 8818 | renderingQueue: this.renderingQueue, |
| 8819 | textLayerMode, |
| 8820 | annotationMode, |
| 8821 | imageResourcesPath: this.imageResourcesPath, |
| 8822 | renderer: this.renderer, |
| 8823 | useOnlyCssZoom: this.useOnlyCssZoom, |
| 8824 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported, |
| 8825 | maxCanvasPixels: this.maxCanvasPixels, |
| 8826 | pageColors: this.pageColors, |
| 8827 | l10n: this.l10n, |
| 8828 | layerProperties |
| 8829 | }); |
| 8830 | this._pages.push(pageView); |
| 8831 | } |
| 8832 | const firstPageView = this._pages[0]; |
| 8833 | if (firstPageView) { |
| 8834 | firstPageView.setPdfPage(firstPdfPage); |
| 8835 | this.linkService.cachePageRef(1, firstPdfPage.ref); |
| 8836 | } |
| 8837 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) { |
| 8838 | this.#ensurePageViewVisible(); |
| 8839 | } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) { |
| 8840 | this._updateSpreadMode(); |
| 8841 | } |
| 8842 | this.#onePageRenderedOrForceFetch().then(async () => { |
| 8843 | this.findController?.setDocument(pdfDocument); |
| 8844 | this._scriptingManager?.setDocument(pdfDocument); |
| 8845 | if (this.#annotationEditorUIManager) { |
| 8846 | this.eventBus.dispatch("annotationeditormodechanged", { |
| 8847 | source: this, |
| 8848 | mode: this.#annotationEditorMode |
| 8849 | }); |
| 8850 | } |
| 8851 | if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) { |
| 8852 | this._pagesCapability.resolve(); |
| 8853 | return; |
| 8854 | } |
| 8855 | let getPagesLeft = pagesCount - 1; |
| 8856 | if (getPagesLeft <= 0) { |
| 8857 | this._pagesCapability.resolve(); |
| 8858 | return; |
| 8859 | } |
| 8860 | for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) { |
| 8861 | const promise = pdfDocument.getPage(pageNum).then(pdfPage => { |
| 8862 | const pageView = this._pages[pageNum - 1]; |
| 8863 | if (!pageView.pdfPage) { |
| 8864 | pageView.setPdfPage(pdfPage); |
| 8865 | } |
| 8866 | this.linkService.cachePageRef(pageNum, pdfPage.ref); |
| 8867 | if (--getPagesLeft === 0) { |
| 8868 | this._pagesCapability.resolve(); |
| 8869 | } |
| 8870 | }, reason => { |
| 8871 | console.error(`Unable to get page ${pageNum} to initialize viewer`, reason); |
| 8872 | if (--getPagesLeft === 0) { |
| 8873 | this._pagesCapability.resolve(); |
| 8874 | } |
| 8875 | }); |
| 8876 | if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) { |
| 8877 | await promise; |
| 8878 | } |
| 8879 | } |
| 8880 | }); |
| 8881 | this.eventBus.dispatch("pagesinit", { |
| 8882 | source: this |
| 8883 | }); |
| 8884 | pdfDocument.getMetadata().then(({ |
| 8885 | info |
| 8886 | }) => { |
| 8887 | if (pdfDocument !== this.pdfDocument) { |
| 8888 | return; |
| 8889 | } |
| 8890 | if (info.Language) { |
| 8891 | this.viewer.lang = info.Language; |
| 8892 | } |
| 8893 | }); |
| 8894 | if (this.defaultRenderingQueue) { |
| 8895 | this.update(); |
| 8896 | } |
| 8897 | }).catch(reason => { |
| 8898 | console.error("Unable to initialize viewer", reason); |
| 8899 | this._pagesCapability.reject(reason); |
| 8900 | }); |
| 8901 | } |
| 8902 | setPageLabels(labels) { |
| 8903 | if (!this.pdfDocument) { |
| 8904 | return; |
| 8905 | } |
| 8906 | if (!labels) { |
| 8907 | this._pageLabels = null; |
| 8908 | } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) { |
| 8909 | this._pageLabels = null; |
| 8910 | console.error(`setPageLabels: Invalid page labels.`); |
| 8911 | } else { |
| 8912 | this._pageLabels = labels; |
| 8913 | } |
| 8914 | for (let i = 0, ii = this._pages.length; i < ii; i++) { |
| 8915 | this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null); |
| 8916 | } |
| 8917 | } |
| 8918 | _resetView() { |
| 8919 | this._pages = []; |
| 8920 | this._currentPageNumber = 1; |
| 8921 | this._currentScale = _ui_utils.UNKNOWN_SCALE; |
| 8922 | this._currentScaleValue = null; |
| 8923 | this._pageLabels = null; |
| 8924 | this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE); |
| 8925 | this._location = null; |
| 8926 | this._pagesRotation = 0; |
| 8927 | this._optionalContentConfigPromise = null; |
| 8928 | this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 8929 | this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 8930 | this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 8931 | this._scrollMode = _ui_utils.ScrollMode.VERTICAL; |
| 8932 | this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN; |
| 8933 | this._spreadMode = _ui_utils.SpreadMode.NONE; |
| 8934 | this.#scrollModePageState = { |
| 8935 | previousPageNumber: 1, |
| 8936 | scrollDown: true, |
| 8937 | pages: [] |
| 8938 | }; |
| 8939 | if (this._onBeforeDraw) { |
| 8940 | this.eventBus._off("pagerender", this._onBeforeDraw); |
| 8941 | this._onBeforeDraw = null; |
| 8942 | } |
| 8943 | if (this._onAfterDraw) { |
| 8944 | this.eventBus._off("pagerendered", this._onAfterDraw); |
| 8945 | this._onAfterDraw = null; |
| 8946 | } |
| 8947 | if (this.#onVisibilityChange) { |
| 8948 | document.removeEventListener("visibilitychange", this.#onVisibilityChange); |
| 8949 | this.#onVisibilityChange = null; |
| 8950 | } |
| 8951 | this.viewer.textContent = ""; |
| 8952 | this._updateScrollMode(); |
| 8953 | this.viewer.removeAttribute("lang"); |
| 8954 | this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS); |
| 8955 | } |
| 8956 | #ensurePageViewVisible() { |
| 8957 | if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) { |
| 8958 | throw new Error("#ensurePageViewVisible: Invalid scrollMode value."); |
| 8959 | } |
| 8960 | const pageNumber = this._currentPageNumber, |
| 8961 | state = this.#scrollModePageState, |
| 8962 | viewer = this.viewer; |
| 8963 | viewer.textContent = ""; |
| 8964 | state.pages.length = 0; |
| 8965 | if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) { |
| 8966 | const pageView = this._pages[pageNumber - 1]; |
| 8967 | viewer.append(pageView.div); |
| 8968 | state.pages.push(pageView); |
| 8969 | } else { |
| 8970 | const pageIndexSet = new Set(), |
| 8971 | parity = this._spreadMode - 1; |
| 8972 | if (parity === -1) { |
| 8973 | pageIndexSet.add(pageNumber - 1); |
| 8974 | } else if (pageNumber % 2 !== parity) { |
| 8975 | pageIndexSet.add(pageNumber - 1); |
| 8976 | pageIndexSet.add(pageNumber); |
| 8977 | } else { |
| 8978 | pageIndexSet.add(pageNumber - 2); |
| 8979 | pageIndexSet.add(pageNumber - 1); |
| 8980 | } |
| 8981 | const spread = document.createElement("div"); |
| 8982 | spread.className = "spread"; |
| 8983 | if (this.isInPresentationMode) { |
| 8984 | const dummyPage = document.createElement("div"); |
| 8985 | dummyPage.className = "dummyPage"; |
| 8986 | spread.append(dummyPage); |
| 8987 | } |
| 8988 | for (const i of pageIndexSet) { |
| 8989 | const pageView = this._pages[i]; |
| 8990 | if (!pageView) { |
| 8991 | continue; |
| 8992 | } |
| 8993 | spread.append(pageView.div); |
| 8994 | state.pages.push(pageView); |
| 8995 | } |
| 8996 | viewer.append(spread); |
| 8997 | } |
| 8998 | state.scrollDown = pageNumber >= state.previousPageNumber; |
| 8999 | state.previousPageNumber = pageNumber; |
| 9000 | } |
| 9001 | _scrollUpdate() { |
| 9002 | if (this.pagesCount === 0) { |
| 9003 | return; |
| 9004 | } |
| 9005 | this.update(); |
| 9006 | } |
| 9007 | #scrollIntoView(pageView, pageSpot = null) { |
| 9008 | const { |
| 9009 | div, |
| 9010 | id |
| 9011 | } = pageView; |
| 9012 | if (this._currentPageNumber !== id) { |
| 9013 | this._setCurrentPageNumber(id); |
| 9014 | } |
| 9015 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) { |
| 9016 | this.#ensurePageViewVisible(); |
| 9017 | this.update(); |
| 9018 | } |
| 9019 | if (!pageSpot && !this.isInPresentationMode) { |
| 9020 | const left = div.offsetLeft + div.clientLeft, |
| 9021 | right = left + div.clientWidth; |
| 9022 | const { |
| 9023 | scrollLeft, |
| 9024 | clientWidth |
| 9025 | } = this.container; |
| 9026 | if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) { |
| 9027 | pageSpot = { |
| 9028 | left: 0, |
| 9029 | top: 0 |
| 9030 | }; |
| 9031 | } |
| 9032 | } |
| 9033 | (0, _ui_utils.scrollIntoView)(div, pageSpot); |
| 9034 | if (!this._currentScaleValue && this._location) { |
| 9035 | this._location = null; |
| 9036 | } |
| 9037 | } |
| 9038 | #isSameScale(newScale) { |
| 9039 | return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15; |
| 9040 | } |
| 9041 | _setScaleUpdatePages(newScale, newValue, { |
| 9042 | noScroll = false, |
| 9043 | preset = false, |
| 9044 | drawingDelay = -1 |
| 9045 | }) { |
| 9046 | this._currentScaleValue = newValue.toString(); |
| 9047 | if (this.#isSameScale(newScale)) { |
| 9048 | if (preset) { |
| 9049 | this.eventBus.dispatch("scalechanging", { |
| 9050 | source: this, |
| 9051 | scale: newScale, |
| 9052 | presetValue: newValue |
| 9053 | }); |
| 9054 | } |
| 9055 | return; |
| 9056 | } |
| 9057 | this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS); |
| 9058 | const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000; |
| 9059 | this.refresh(true, { |
| 9060 | scale: newScale, |
| 9061 | drawingDelay: postponeDrawing ? drawingDelay : -1 |
| 9062 | }); |
| 9063 | if (postponeDrawing) { |
| 9064 | this.#scaleTimeoutId = setTimeout(() => { |
| 9065 | this.#scaleTimeoutId = null; |
| 9066 | this.refresh(); |
| 9067 | }, drawingDelay); |
| 9068 | } |
| 9069 | this._currentScale = newScale; |
| 9070 | if (!noScroll) { |
| 9071 | let page = this._currentPageNumber, |
| 9072 | dest; |
| 9073 | if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) { |
| 9074 | page = this._location.pageNumber; |
| 9075 | dest = [null, { |
| 9076 | name: "XYZ" |
| 9077 | }, this._location.left, this._location.top, null]; |
| 9078 | } |
| 9079 | this.scrollPageIntoView({ |
| 9080 | pageNumber: page, |
| 9081 | destArray: dest, |
| 9082 | allowNegativeOffset: true |
| 9083 | }); |
| 9084 | } |
| 9085 | this.eventBus.dispatch("scalechanging", { |
| 9086 | source: this, |
| 9087 | scale: newScale, |
| 9088 | presetValue: preset ? newValue : undefined |
| 9089 | }); |
| 9090 | if (this.defaultRenderingQueue) { |
| 9091 | this.update(); |
| 9092 | } |
| 9093 | } |
| 9094 | get _pageWidthScaleFactor() { |
| 9095 | if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) { |
| 9096 | return 2; |
| 9097 | } |
| 9098 | return 1; |
| 9099 | } |
| 9100 | _setScale(value, options) { |
| 9101 | let scale = parseFloat(value); |
| 9102 | if (scale > 0) { |
| 9103 | options.preset = false; |
| 9104 | this._setScaleUpdatePages(scale, value, options); |
| 9105 | } else { |
| 9106 | const currentPage = this._pages[this._currentPageNumber - 1]; |
| 9107 | if (!currentPage) { |
| 9108 | return; |
| 9109 | } |
| 9110 | let hPadding = _ui_utils.SCROLLBAR_PADDING, |
| 9111 | vPadding = _ui_utils.VERTICAL_PADDING; |
| 9112 | if (this.isInPresentationMode) { |
| 9113 | hPadding = vPadding = 4; |
| 9114 | if (this._spreadMode !== _ui_utils.SpreadMode.NONE) { |
| 9115 | hPadding *= 2; |
| 9116 | } |
| 9117 | } else if (this.removePageBorders) { |
| 9118 | hPadding = vPadding = 0; |
| 9119 | } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) { |
| 9120 | [hPadding, vPadding] = [vPadding, hPadding]; |
| 9121 | } |
| 9122 | const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor; |
| 9123 | const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale; |
| 9124 | switch (value) { |
| 9125 | case "page-actual": |
| 9126 | scale = 1; |
| 9127 | break; |
| 9128 | case "page-width": |
| 9129 | scale = pageWidthScale; |
| 9130 | break; |
| 9131 | case "page-height": |
| 9132 | scale = pageHeightScale; |
| 9133 | break; |
| 9134 | case "page-fit": |
| 9135 | scale = Math.min(pageWidthScale, pageHeightScale); |
| 9136 | break; |
| 9137 | case "auto": |
| 9138 | const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale); |
| 9139 | scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale); |
| 9140 | break; |
| 9141 | default: |
| 9142 | console.error(`_setScale: "${value}" is an unknown zoom value.`); |
| 9143 | return; |
| 9144 | } |
| 9145 | options.preset = true; |
| 9146 | this._setScaleUpdatePages(scale, value, options); |
| 9147 | } |
| 9148 | } |
| 9149 | #resetCurrentPageView() { |
| 9150 | const pageView = this._pages[this._currentPageNumber - 1]; |
| 9151 | if (this.isInPresentationMode) { |
| 9152 | this._setScale(this._currentScaleValue, { |
| 9153 | noScroll: true |
| 9154 | }); |
| 9155 | } |
| 9156 | this.#scrollIntoView(pageView); |
| 9157 | } |
| 9158 | pageLabelToPageNumber(label) { |
| 9159 | if (!this._pageLabels) { |
| 9160 | return null; |
| 9161 | } |
| 9162 | const i = this._pageLabels.indexOf(label); |
| 9163 | if (i < 0) { |
| 9164 | return null; |
| 9165 | } |
| 9166 | return i + 1; |
| 9167 | } |
| 9168 | scrollPageIntoView({ |
| 9169 | pageNumber, |
| 9170 | destArray = null, |
| 9171 | allowNegativeOffset = false, |
| 9172 | ignoreDestinationZoom = false |
| 9173 | }) { |
| 9174 | if (!this.pdfDocument) { |
| 9175 | return; |
| 9176 | } |
| 9177 | const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1]; |
| 9178 | if (!pageView) { |
| 9179 | console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`); |
| 9180 | return; |
| 9181 | } |
| 9182 | if (this.isInPresentationMode || !destArray) { |
| 9183 | this._setCurrentPageNumber(pageNumber, true); |
| 9184 | return; |
| 9185 | } |
| 9186 | let x = 0, |
| 9187 | y = 0; |
| 9188 | let width = 0, |
| 9189 | height = 0, |
| 9190 | widthScale, |
| 9191 | heightScale; |
| 9192 | const changeOrientation = pageView.rotation % 180 !== 0; |
| 9193 | const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS; |
| 9194 | const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS; |
| 9195 | let scale = 0; |
| 9196 | switch (destArray[1].name) { |
| 9197 | case "XYZ": |
| 9198 | x = destArray[2]; |
| 9199 | y = destArray[3]; |
| 9200 | scale = destArray[4]; |
| 9201 | x = x !== null ? x : 0; |
| 9202 | y = y !== null ? y : pageHeight; |
| 9203 | break; |
| 9204 | case "Fit": |
| 9205 | case "FitB": |
| 9206 | scale = "page-fit"; |
| 9207 | break; |
| 9208 | case "FitH": |
| 9209 | case "FitBH": |
| 9210 | y = destArray[2]; |
| 9211 | scale = "page-width"; |
| 9212 | if (y === null && this._location) { |
| 9213 | x = this._location.left; |
| 9214 | y = this._location.top; |
| 9215 | } else if (typeof y !== "number" || y < 0) { |
| 9216 | y = pageHeight; |
| 9217 | } |
| 9218 | break; |
| 9219 | case "FitV": |
| 9220 | case "FitBV": |
| 9221 | x = destArray[2]; |
| 9222 | width = pageWidth; |
| 9223 | height = pageHeight; |
| 9224 | scale = "page-height"; |
| 9225 | break; |
| 9226 | case "FitR": |
| 9227 | x = destArray[2]; |
| 9228 | y = destArray[3]; |
| 9229 | width = destArray[4] - x; |
| 9230 | height = destArray[5] - y; |
| 9231 | const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING; |
| 9232 | const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING; |
| 9233 | widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS; |
| 9234 | heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS; |
| 9235 | scale = Math.min(Math.abs(widthScale), Math.abs(heightScale)); |
| 9236 | break; |
| 9237 | default: |
| 9238 | console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`); |
| 9239 | return; |
| 9240 | } |
| 9241 | if (!ignoreDestinationZoom) { |
| 9242 | if (scale && scale !== this._currentScale) { |
| 9243 | this.currentScaleValue = scale; |
| 9244 | } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) { |
| 9245 | this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE; |
| 9246 | } |
| 9247 | } |
| 9248 | if (scale === "page-fit" && !destArray[4]) { |
| 9249 | this.#scrollIntoView(pageView); |
| 9250 | return; |
| 9251 | } |
| 9252 | const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)]; |
| 9253 | let left = Math.min(boundingRect[0][0], boundingRect[1][0]); |
| 9254 | let top = Math.min(boundingRect[0][1], boundingRect[1][1]); |
| 9255 | if (!allowNegativeOffset) { |
| 9256 | left = Math.max(left, 0); |
| 9257 | top = Math.max(top, 0); |
| 9258 | } |
| 9259 | this.#scrollIntoView(pageView, { |
| 9260 | left, |
| 9261 | top |
| 9262 | }); |
| 9263 | } |
| 9264 | _updateLocation(firstPage) { |
| 9265 | const currentScale = this._currentScale; |
| 9266 | const currentScaleValue = this._currentScaleValue; |
| 9267 | const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue; |
| 9268 | const pageNumber = firstPage.id; |
| 9269 | const currentPageView = this._pages[pageNumber - 1]; |
| 9270 | const container = this.container; |
| 9271 | const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y); |
| 9272 | const intLeft = Math.round(topLeft[0]); |
| 9273 | const intTop = Math.round(topLeft[1]); |
| 9274 | let pdfOpenParams = `#page=${pageNumber}`; |
| 9275 | if (!this.isInPresentationMode) { |
| 9276 | pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`; |
| 9277 | } |
| 9278 | this._location = { |
| 9279 | pageNumber, |
| 9280 | scale: normalizedScaleValue, |
| 9281 | top: intTop, |
| 9282 | left: intLeft, |
| 9283 | rotation: this._pagesRotation, |
| 9284 | pdfOpenParams |
| 9285 | }; |
| 9286 | } |
| 9287 | update() { |
| 9288 | const visible = this._getVisiblePages(); |
| 9289 | const visiblePages = visible.views, |
| 9290 | numVisiblePages = visiblePages.length; |
| 9291 | if (numVisiblePages === 0) { |
| 9292 | return; |
| 9293 | } |
| 9294 | const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1); |
| 9295 | this.#buffer.resize(newCacheSize, visible.ids); |
| 9296 | this.renderingQueue.renderHighestPriority(visible); |
| 9297 | const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL); |
| 9298 | const currentId = this._currentPageNumber; |
| 9299 | let stillFullyVisible = false; |
| 9300 | for (const page of visiblePages) { |
| 9301 | if (page.percent < 100) { |
| 9302 | break; |
| 9303 | } |
| 9304 | if (page.id === currentId && isSimpleLayout) { |
| 9305 | stillFullyVisible = true; |
| 9306 | break; |
| 9307 | } |
| 9308 | } |
| 9309 | this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id); |
| 9310 | this._updateLocation(visible.first); |
| 9311 | this.eventBus.dispatch("updateviewarea", { |
| 9312 | source: this, |
| 9313 | location: this._location |
| 9314 | }); |
| 9315 | } |
| 9316 | containsElement(element) { |
| 9317 | return this.container.contains(element); |
| 9318 | } |
| 9319 | focus() { |
| 9320 | this.container.focus(); |
| 9321 | } |
| 9322 | get _isContainerRtl() { |
| 9323 | return getComputedStyle(this.container).direction === "rtl"; |
| 9324 | } |
| 9325 | get isInPresentationMode() { |
| 9326 | return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN; |
| 9327 | } |
| 9328 | get isChangingPresentationMode() { |
| 9329 | return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING; |
| 9330 | } |
| 9331 | get isHorizontalScrollbarEnabled() { |
| 9332 | return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth; |
| 9333 | } |
| 9334 | get isVerticalScrollbarEnabled() { |
| 9335 | return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight; |
| 9336 | } |
| 9337 | _getVisiblePages() { |
| 9338 | const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages, |
| 9339 | horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL, |
| 9340 | rtl = horizontal && this._isContainerRtl; |
| 9341 | return (0, _ui_utils.getVisibleElements)({ |
| 9342 | scrollEl: this.container, |
| 9343 | views, |
| 9344 | sortByVisibility: true, |
| 9345 | horizontal, |
| 9346 | rtl |
| 9347 | }); |
| 9348 | } |
| 9349 | isPageVisible(pageNumber) { |
| 9350 | if (!this.pdfDocument) { |
| 9351 | return false; |
| 9352 | } |
| 9353 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) { |
| 9354 | console.error(`isPageVisible: "${pageNumber}" is not a valid page.`); |
| 9355 | return false; |
| 9356 | } |
| 9357 | return this._getVisiblePages().ids.has(pageNumber); |
| 9358 | } |
| 9359 | isPageCached(pageNumber) { |
| 9360 | if (!this.pdfDocument) { |
| 9361 | return false; |
| 9362 | } |
| 9363 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) { |
| 9364 | console.error(`isPageCached: "${pageNumber}" is not a valid page.`); |
| 9365 | return false; |
| 9366 | } |
| 9367 | const pageView = this._pages[pageNumber - 1]; |
| 9368 | return this.#buffer.has(pageView); |
| 9369 | } |
| 9370 | cleanup() { |
| 9371 | for (const pageView of this._pages) { |
| 9372 | if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 9373 | pageView.reset(); |
| 9374 | } |
| 9375 | } |
| 9376 | } |
| 9377 | _cancelRendering() { |
| 9378 | for (const pageView of this._pages) { |
| 9379 | pageView.cancelRendering(); |
| 9380 | } |
| 9381 | } |
| 9382 | async #ensurePdfPageLoaded(pageView) { |
| 9383 | if (pageView.pdfPage) { |
| 9384 | return pageView.pdfPage; |
| 9385 | } |
| 9386 | try { |
| 9387 | const pdfPage = await this.pdfDocument.getPage(pageView.id); |
| 9388 | if (!pageView.pdfPage) { |
| 9389 | pageView.setPdfPage(pdfPage); |
| 9390 | } |
| 9391 | if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) { |
| 9392 | this.linkService.cachePageRef(pageView.id, pdfPage.ref); |
| 9393 | } |
| 9394 | return pdfPage; |
| 9395 | } catch (reason) { |
| 9396 | console.error("Unable to get page for page view", reason); |
| 9397 | return null; |
| 9398 | } |
| 9399 | } |
| 9400 | #getScrollAhead(visible) { |
| 9401 | if (visible.first?.id === 1) { |
| 9402 | return true; |
| 9403 | } else if (visible.last?.id === this.pagesCount) { |
| 9404 | return false; |
| 9405 | } |
| 9406 | switch (this._scrollMode) { |
| 9407 | case _ui_utils.ScrollMode.PAGE: |
| 9408 | return this.#scrollModePageState.scrollDown; |
| 9409 | case _ui_utils.ScrollMode.HORIZONTAL: |
| 9410 | return this.scroll.right; |
| 9411 | } |
| 9412 | return this.scroll.down; |
| 9413 | } |
| 9414 | forceRendering(currentlyVisiblePages) { |
| 9415 | const visiblePages = currentlyVisiblePages || this._getVisiblePages(); |
| 9416 | const scrollAhead = this.#getScrollAhead(visiblePages); |
| 9417 | const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL; |
| 9418 | const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra); |
| 9419 | if (pageView) { |
| 9420 | this.#ensurePdfPageLoaded(pageView).then(() => { |
| 9421 | this.renderingQueue.renderView(pageView); |
| 9422 | }); |
| 9423 | return true; |
| 9424 | } |
| 9425 | return false; |
| 9426 | } |
| 9427 | get hasEqualPageSizes() { |
| 9428 | const firstPageView = this._pages[0]; |
| 9429 | for (let i = 1, ii = this._pages.length; i < ii; ++i) { |
| 9430 | const pageView = this._pages[i]; |
| 9431 | if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) { |
| 9432 | return false; |
| 9433 | } |
| 9434 | } |
| 9435 | return true; |
| 9436 | } |
| 9437 | getPagesOverview() { |
| 9438 | return this._pages.map(pageView => { |
| 9439 | const viewport = pageView.pdfPage.getViewport({ |
| 9440 | scale: 1 |
| 9441 | }); |
| 9442 | if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) { |
| 9443 | return { |
| 9444 | width: viewport.width, |
| 9445 | height: viewport.height, |
| 9446 | rotation: viewport.rotation |
| 9447 | }; |
| 9448 | } |
| 9449 | return { |
| 9450 | width: viewport.height, |
| 9451 | height: viewport.width, |
| 9452 | rotation: (viewport.rotation - 90) % 360 |
| 9453 | }; |
| 9454 | }); |
| 9455 | } |
| 9456 | get optionalContentConfigPromise() { |
| 9457 | if (!this.pdfDocument) { |
| 9458 | return Promise.resolve(null); |
| 9459 | } |
| 9460 | if (!this._optionalContentConfigPromise) { |
| 9461 | console.error("optionalContentConfigPromise: Not initialized yet."); |
| 9462 | return this.pdfDocument.getOptionalContentConfig(); |
| 9463 | } |
| 9464 | return this._optionalContentConfigPromise; |
| 9465 | } |
| 9466 | set optionalContentConfigPromise(promise) { |
| 9467 | if (!(promise instanceof Promise)) { |
| 9468 | throw new Error(`Invalid optionalContentConfigPromise: ${promise}`); |
| 9469 | } |
| 9470 | if (!this.pdfDocument) { |
| 9471 | return; |
| 9472 | } |
| 9473 | if (!this._optionalContentConfigPromise) { |
| 9474 | return; |
| 9475 | } |
| 9476 | this._optionalContentConfigPromise = promise; |
| 9477 | this.refresh(false, { |
| 9478 | optionalContentConfigPromise: promise |
| 9479 | }); |
| 9480 | this.eventBus.dispatch("optionalcontentconfigchanged", { |
| 9481 | source: this, |
| 9482 | promise |
| 9483 | }); |
| 9484 | } |
| 9485 | get scrollMode() { |
| 9486 | return this._scrollMode; |
| 9487 | } |
| 9488 | set scrollMode(mode) { |
| 9489 | if (this._scrollMode === mode) { |
| 9490 | return; |
| 9491 | } |
| 9492 | if (!(0, _ui_utils.isValidScrollMode)(mode)) { |
| 9493 | throw new Error(`Invalid scroll mode: ${mode}`); |
| 9494 | } |
| 9495 | if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) { |
| 9496 | return; |
| 9497 | } |
| 9498 | this._previousScrollMode = this._scrollMode; |
| 9499 | this._scrollMode = mode; |
| 9500 | this.eventBus.dispatch("scrollmodechanged", { |
| 9501 | source: this, |
| 9502 | mode |
| 9503 | }); |
| 9504 | this._updateScrollMode(this._currentPageNumber); |
| 9505 | } |
| 9506 | _updateScrollMode(pageNumber = null) { |
| 9507 | const scrollMode = this._scrollMode, |
| 9508 | viewer = this.viewer; |
| 9509 | viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL); |
| 9510 | viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED); |
| 9511 | if (!this.pdfDocument || !pageNumber) { |
| 9512 | return; |
| 9513 | } |
| 9514 | if (scrollMode === _ui_utils.ScrollMode.PAGE) { |
| 9515 | this.#ensurePageViewVisible(); |
| 9516 | } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) { |
| 9517 | this._updateSpreadMode(); |
| 9518 | } |
| 9519 | if (this._currentScaleValue && isNaN(this._currentScaleValue)) { |
| 9520 | this._setScale(this._currentScaleValue, { |
| 9521 | noScroll: true |
| 9522 | }); |
| 9523 | } |
| 9524 | this._setCurrentPageNumber(pageNumber, true); |
| 9525 | this.update(); |
| 9526 | } |
| 9527 | get spreadMode() { |
| 9528 | return this._spreadMode; |
| 9529 | } |
| 9530 | set spreadMode(mode) { |
| 9531 | if (this._spreadMode === mode) { |
| 9532 | return; |
| 9533 | } |
| 9534 | if (!(0, _ui_utils.isValidSpreadMode)(mode)) { |
| 9535 | throw new Error(`Invalid spread mode: ${mode}`); |
| 9536 | } |
| 9537 | this._spreadMode = mode; |
| 9538 | this.eventBus.dispatch("spreadmodechanged", { |
| 9539 | source: this, |
| 9540 | mode |
| 9541 | }); |
| 9542 | this._updateSpreadMode(this._currentPageNumber); |
| 9543 | } |
| 9544 | _updateSpreadMode(pageNumber = null) { |
| 9545 | if (!this.pdfDocument) { |
| 9546 | return; |
| 9547 | } |
| 9548 | const viewer = this.viewer, |
| 9549 | pages = this._pages; |
| 9550 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) { |
| 9551 | this.#ensurePageViewVisible(); |
| 9552 | } else { |
| 9553 | viewer.textContent = ""; |
| 9554 | if (this._spreadMode === _ui_utils.SpreadMode.NONE) { |
| 9555 | for (const pageView of this._pages) { |
| 9556 | viewer.append(pageView.div); |
| 9557 | } |
| 9558 | } else { |
| 9559 | const parity = this._spreadMode - 1; |
| 9560 | let spread = null; |
| 9561 | for (let i = 0, ii = pages.length; i < ii; ++i) { |
| 9562 | if (spread === null) { |
| 9563 | spread = document.createElement("div"); |
| 9564 | spread.className = "spread"; |
| 9565 | viewer.append(spread); |
| 9566 | } else if (i % 2 === parity) { |
| 9567 | spread = spread.cloneNode(false); |
| 9568 | viewer.append(spread); |
| 9569 | } |
| 9570 | spread.append(pages[i].div); |
| 9571 | } |
| 9572 | } |
| 9573 | } |
| 9574 | if (!pageNumber) { |
| 9575 | return; |
| 9576 | } |
| 9577 | if (this._currentScaleValue && isNaN(this._currentScaleValue)) { |
| 9578 | this._setScale(this._currentScaleValue, { |
| 9579 | noScroll: true |
| 9580 | }); |
| 9581 | } |
| 9582 | this._setCurrentPageNumber(pageNumber, true); |
| 9583 | this.update(); |
| 9584 | } |
| 9585 | _getPageAdvance(currentPageNumber, previous = false) { |
| 9586 | switch (this._scrollMode) { |
| 9587 | case _ui_utils.ScrollMode.WRAPPED: |
| 9588 | { |
| 9589 | const { |
| 9590 | views |
| 9591 | } = this._getVisiblePages(), |
| 9592 | pageLayout = new Map(); |
| 9593 | for (const { |
| 9594 | id, |
| 9595 | y, |
| 9596 | percent, |
| 9597 | widthPercent |
| 9598 | } of views) { |
| 9599 | if (percent === 0 || widthPercent < 100) { |
| 9600 | continue; |
| 9601 | } |
| 9602 | let yArray = pageLayout.get(y); |
| 9603 | if (!yArray) { |
| 9604 | pageLayout.set(y, yArray ||= []); |
| 9605 | } |
| 9606 | yArray.push(id); |
| 9607 | } |
| 9608 | for (const yArray of pageLayout.values()) { |
| 9609 | const currentIndex = yArray.indexOf(currentPageNumber); |
| 9610 | if (currentIndex === -1) { |
| 9611 | continue; |
| 9612 | } |
| 9613 | const numPages = yArray.length; |
| 9614 | if (numPages === 1) { |
| 9615 | break; |
| 9616 | } |
| 9617 | if (previous) { |
| 9618 | for (let i = currentIndex - 1, ii = 0; i >= ii; i--) { |
| 9619 | const currentId = yArray[i], |
| 9620 | expectedId = yArray[i + 1] - 1; |
| 9621 | if (currentId < expectedId) { |
| 9622 | return currentPageNumber - expectedId; |
| 9623 | } |
| 9624 | } |
| 9625 | } else { |
| 9626 | for (let i = currentIndex + 1, ii = numPages; i < ii; i++) { |
| 9627 | const currentId = yArray[i], |
| 9628 | expectedId = yArray[i - 1] + 1; |
| 9629 | if (currentId > expectedId) { |
| 9630 | return expectedId - currentPageNumber; |
| 9631 | } |
| 9632 | } |
| 9633 | } |
| 9634 | if (previous) { |
| 9635 | const firstId = yArray[0]; |
| 9636 | if (firstId < currentPageNumber) { |
| 9637 | return currentPageNumber - firstId + 1; |
| 9638 | } |
| 9639 | } else { |
| 9640 | const lastId = yArray[numPages - 1]; |
| 9641 | if (lastId > currentPageNumber) { |
| 9642 | return lastId - currentPageNumber + 1; |
| 9643 | } |
| 9644 | } |
| 9645 | break; |
| 9646 | } |
| 9647 | break; |
| 9648 | } |
| 9649 | case _ui_utils.ScrollMode.HORIZONTAL: |
| 9650 | { |
| 9651 | break; |
| 9652 | } |
| 9653 | case _ui_utils.ScrollMode.PAGE: |
| 9654 | case _ui_utils.ScrollMode.VERTICAL: |
| 9655 | { |
| 9656 | if (this._spreadMode === _ui_utils.SpreadMode.NONE) { |
| 9657 | break; |
| 9658 | } |
| 9659 | const parity = this._spreadMode - 1; |
| 9660 | if (previous && currentPageNumber % 2 !== parity) { |
| 9661 | break; |
| 9662 | } else if (!previous && currentPageNumber % 2 === parity) { |
| 9663 | break; |
| 9664 | } |
| 9665 | const { |
| 9666 | views |
| 9667 | } = this._getVisiblePages(), |
| 9668 | expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1; |
| 9669 | for (const { |
| 9670 | id, |
| 9671 | percent, |
| 9672 | widthPercent |
| 9673 | } of views) { |
| 9674 | if (id !== expectedId) { |
| 9675 | continue; |
| 9676 | } |
| 9677 | if (percent > 0 && widthPercent === 100) { |
| 9678 | return 2; |
| 9679 | } |
| 9680 | break; |
| 9681 | } |
| 9682 | break; |
| 9683 | } |
| 9684 | } |
| 9685 | return 1; |
| 9686 | } |
| 9687 | nextPage() { |
| 9688 | const currentPageNumber = this._currentPageNumber, |
| 9689 | pagesCount = this.pagesCount; |
| 9690 | if (currentPageNumber >= pagesCount) { |
| 9691 | return false; |
| 9692 | } |
| 9693 | const advance = this._getPageAdvance(currentPageNumber, false) || 1; |
| 9694 | this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount); |
| 9695 | return true; |
| 9696 | } |
| 9697 | previousPage() { |
| 9698 | const currentPageNumber = this._currentPageNumber; |
| 9699 | if (currentPageNumber <= 1) { |
| 9700 | return false; |
| 9701 | } |
| 9702 | const advance = this._getPageAdvance(currentPageNumber, true) || 1; |
| 9703 | this.currentPageNumber = Math.max(currentPageNumber - advance, 1); |
| 9704 | return true; |
| 9705 | } |
| 9706 | increaseScale(options = null) { |
| 9707 | if (typeof options === "number") { |
| 9708 | console.error("The `increaseScale` method-signature was updated, please use an object instead."); |
| 9709 | options = { |
| 9710 | steps: options |
| 9711 | }; |
| 9712 | } |
| 9713 | if (!this.pdfDocument) { |
| 9714 | return; |
| 9715 | } |
| 9716 | options ||= Object.create(null); |
| 9717 | let newScale = this._currentScale; |
| 9718 | if (options.scaleFactor > 1) { |
| 9719 | newScale = Math.min(_ui_utils.MAX_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100); |
| 9720 | } else { |
| 9721 | let steps = options.steps ?? 1; |
| 9722 | do { |
| 9723 | newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2); |
| 9724 | newScale = Math.ceil(newScale * 10) / 10; |
| 9725 | newScale = Math.min(_ui_utils.MAX_SCALE, newScale); |
| 9726 | } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE); |
| 9727 | } |
| 9728 | options.noScroll = false; |
| 9729 | this._setScale(newScale, options); |
| 9730 | } |
| 9731 | decreaseScale(options = null) { |
| 9732 | if (typeof options === "number") { |
| 9733 | console.error("The `decreaseScale` method-signature was updated, please use an object instead."); |
| 9734 | options = { |
| 9735 | steps: options |
| 9736 | }; |
| 9737 | } |
| 9738 | if (!this.pdfDocument) { |
| 9739 | return; |
| 9740 | } |
| 9741 | options ||= Object.create(null); |
| 9742 | let newScale = this._currentScale; |
| 9743 | if (options.scaleFactor > 0 && options.scaleFactor < 1) { |
| 9744 | newScale = Math.max(_ui_utils.MIN_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100); |
| 9745 | } else { |
| 9746 | let steps = options.steps ?? 1; |
| 9747 | do { |
| 9748 | newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2); |
| 9749 | newScale = Math.floor(newScale * 10) / 10; |
| 9750 | newScale = Math.max(_ui_utils.MIN_SCALE, newScale); |
| 9751 | } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE); |
| 9752 | } |
| 9753 | options.noScroll = false; |
| 9754 | this._setScale(newScale, options); |
| 9755 | } |
| 9756 | #updateContainerHeightCss(height = this.container.clientHeight) { |
| 9757 | if (height !== this.#previousContainerHeight) { |
| 9758 | this.#previousContainerHeight = height; |
| 9759 | _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`); |
| 9760 | } |
| 9761 | } |
| 9762 | #resizeObserverCallback(entries) { |
| 9763 | for (const entry of entries) { |
| 9764 | if (entry.target === this.container) { |
| 9765 | this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize)); |
| 9766 | this.#containerTopLeft = null; |
| 9767 | break; |
| 9768 | } |
| 9769 | } |
| 9770 | } |
| 9771 | get containerTopLeft() { |
| 9772 | return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft]; |
| 9773 | } |
| 9774 | get annotationEditorMode() { |
| 9775 | return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE; |
| 9776 | } |
| 9777 | set annotationEditorMode(mode) { |
| 9778 | if (!this.#annotationEditorUIManager) { |
| 9779 | throw new Error(`The AnnotationEditor is not enabled.`); |
| 9780 | } |
| 9781 | if (this.#annotationEditorMode === mode) { |
| 9782 | return; |
| 9783 | } |
| 9784 | if (!isValidAnnotationEditorMode(mode)) { |
| 9785 | throw new Error(`Invalid AnnotationEditor mode: ${mode}`); |
| 9786 | } |
| 9787 | if (!this.pdfDocument) { |
| 9788 | return; |
| 9789 | } |
| 9790 | this.#annotationEditorMode = mode; |
| 9791 | this.eventBus.dispatch("annotationeditormodechanged", { |
| 9792 | source: this, |
| 9793 | mode |
| 9794 | }); |
| 9795 | this.#annotationEditorUIManager.updateMode(mode); |
| 9796 | } |
| 9797 | set annotationEditorParams({ |
| 9798 | type, |
| 9799 | value |
| 9800 | }) { |
| 9801 | if (!this.#annotationEditorUIManager) { |
| 9802 | throw new Error(`The AnnotationEditor is not enabled.`); |
| 9803 | } |
| 9804 | this.#annotationEditorUIManager.updateParams(type, value); |
| 9805 | } |
| 9806 | refresh(noUpdate = false, updateArgs = Object.create(null)) { |
| 9807 | if (!this.pdfDocument) { |
| 9808 | return; |
| 9809 | } |
| 9810 | for (const pageView of this._pages) { |
| 9811 | pageView.update(updateArgs); |
| 9812 | } |
| 9813 | if (this.#scaleTimeoutId !== null) { |
| 9814 | clearTimeout(this.#scaleTimeoutId); |
| 9815 | this.#scaleTimeoutId = null; |
| 9816 | } |
| 9817 | if (!noUpdate) { |
| 9818 | this.update(); |
| 9819 | } |
| 9820 | } |
| 9821 | } |
| 9822 | exports.PDFViewer = PDFViewer; |
| 9823 | |
| 9824 | /***/ }), |
| 9825 | /* 29 */ |
| 9826 | /***/ ((__unused_webpack_module, exports) => { |
| 9827 | |
| 9828 | |
| 9829 | |
| 9830 | Object.defineProperty(exports, "__esModule", ({ |
| 9831 | value: true |
| 9832 | })); |
| 9833 | exports.NullL10n = void 0; |
| 9834 | exports.fixupLangCode = fixupLangCode; |
| 9835 | exports.getL10nFallback = getL10nFallback; |
| 9836 | const DEFAULT_L10N_STRINGS = { |
| 9837 | of_pages: "of {{pagesCount}}", |
| 9838 | page_of_pages: "({{pageNumber}} of {{pagesCount}})", |
| 9839 | document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)", |
| 9840 | document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)", |
| 9841 | document_properties_date_string: "{{date}}, {{time}}", |
| 9842 | document_properties_page_size_unit_inches: "in", |
| 9843 | document_properties_page_size_unit_millimeters: "mm", |
| 9844 | document_properties_page_size_orientation_portrait: "portrait", |
| 9845 | document_properties_page_size_orientation_landscape: "landscape", |
| 9846 | document_properties_page_size_name_a3: "A3", |
| 9847 | document_properties_page_size_name_a4: "A4", |
| 9848 | document_properties_page_size_name_letter: "Letter", |
| 9849 | document_properties_page_size_name_legal: "Legal", |
| 9850 | document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})", |
| 9851 | document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})", |
| 9852 | document_properties_linearized_yes: "Yes", |
| 9853 | document_properties_linearized_no: "No", |
| 9854 | additional_layers: "Additional Layers", |
| 9855 | page_landmark: "Page {{page}}", |
| 9856 | thumb_page_title: "Page {{page}}", |
| 9857 | thumb_page_canvas: "Thumbnail of Page {{page}}", |
| 9858 | find_reached_top: "Reached top of document, continued from bottom", |
| 9859 | find_reached_bottom: "Reached end of document, continued from top", |
| 9860 | "find_match_count[one]": "{{current}} of {{total}} match", |
| 9861 | "find_match_count[other]": "{{current}} of {{total}} matches", |
| 9862 | "find_match_count_limit[one]": "More than {{limit}} match", |
| 9863 | "find_match_count_limit[other]": "More than {{limit}} matches", |
| 9864 | find_not_found: "Phrase not found", |
| 9865 | page_scale_width: "Page Width", |
| 9866 | page_scale_fit: "Page Fit", |
| 9867 | page_scale_auto: "Automatic Zoom", |
| 9868 | page_scale_actual: "Actual Size", |
| 9869 | page_scale_percent: "{{scale}}%", |
| 9870 | loading: "Loading…", |
| 9871 | loading_error: "An error occurred while loading the PDF.", |
| 9872 | invalid_file_error: "Invalid or corrupted PDF file.", |
| 9873 | missing_file_error: "Missing PDF file.", |
| 9874 | unexpected_response_error: "Unexpected server response.", |
| 9875 | rendering_error: "An error occurred while rendering the page.", |
| 9876 | printing_not_supported: "Warning: Printing is not fully supported by this browser.", |
| 9877 | printing_not_ready: "Warning: The PDF is not fully loaded for printing.", |
| 9878 | web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.", |
| 9879 | free_text2_default_content: "Start typing…", |
| 9880 | editor_free_text2_aria_label: "Text Editor", |
| 9881 | editor_ink2_aria_label: "Draw Editor", |
| 9882 | editor_ink_canvas_aria_label: "User-created image" |
| 9883 | }; |
| 9884 | { |
| 9885 | DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%"; |
| 9886 | } |
| 9887 | function getL10nFallback(key, args) { |
| 9888 | switch (key) { |
| 9889 | case "find_match_count": |
| 9890 | key = `find_match_count[${args.total === 1 ? "one" : "other"}]`; |
| 9891 | break; |
| 9892 | case "find_match_count_limit": |
| 9893 | key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`; |
| 9894 | break; |
| 9895 | } |
| 9896 | return DEFAULT_L10N_STRINGS[key] || ""; |
| 9897 | } |
| 9898 | const PARTIAL_LANG_CODES = { |
| 9899 | en: "en-US", |
| 9900 | es: "es-ES", |
| 9901 | fy: "fy-NL", |
| 9902 | ga: "ga-IE", |
| 9903 | gu: "gu-IN", |
| 9904 | hi: "hi-IN", |
| 9905 | hy: "hy-AM", |
| 9906 | nb: "nb-NO", |
| 9907 | ne: "ne-NP", |
| 9908 | nn: "nn-NO", |
| 9909 | pa: "pa-IN", |
| 9910 | pt: "pt-PT", |
| 9911 | sv: "sv-SE", |
| 9912 | zh: "zh-CN" |
| 9913 | }; |
| 9914 | function fixupLangCode(langCode) { |
| 9915 | return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode; |
| 9916 | } |
| 9917 | function formatL10nValue(text, args) { |
| 9918 | if (!args) { |
| 9919 | return text; |
| 9920 | } |
| 9921 | return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => { |
| 9922 | return name in args ? args[name] : "{{" + name + "}}"; |
| 9923 | }); |
| 9924 | } |
| 9925 | const NullL10n = { |
| 9926 | async getLanguage() { |
| 9927 | return "en-us"; |
| 9928 | }, |
| 9929 | async getDirection() { |
| 9930 | return "ltr"; |
| 9931 | }, |
| 9932 | async get(key, args = null, fallback = getL10nFallback(key, args)) { |
| 9933 | return formatL10nValue(fallback, args); |
| 9934 | }, |
| 9935 | async translate(element) {} |
| 9936 | }; |
| 9937 | exports.NullL10n = NullL10n; |
| 9938 | |
| 9939 | /***/ }), |
| 9940 | /* 30 */ |
| 9941 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 9942 | |
| 9943 | |
| 9944 | |
| 9945 | Object.defineProperty(exports, "__esModule", ({ |
| 9946 | value: true |
| 9947 | })); |
| 9948 | exports.PDFPageView = void 0; |
| 9949 | var _pdfjsLib = __webpack_require__(5); |
| 9950 | var _ui_utils = __webpack_require__(1); |
| 9951 | var _annotation_editor_layer_builder = __webpack_require__(31); |
| 9952 | var _annotation_layer_builder = __webpack_require__(32); |
| 9953 | var _app_options = __webpack_require__(2); |
| 9954 | var _l10n_utils = __webpack_require__(29); |
| 9955 | var _struct_tree_layer_builder = __webpack_require__(33); |
| 9956 | var _text_accessibility = __webpack_require__(34); |
| 9957 | var _text_highlighter = __webpack_require__(35); |
| 9958 | var _text_layer_builder = __webpack_require__(36); |
| 9959 | var _xfa_layer_builder = __webpack_require__(37); |
| 9960 | const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216; |
| 9961 | const DEFAULT_LAYER_PROPERTIES = () => { |
| 9962 | return null; |
| 9963 | }; |
| 9964 | class PDFPageView { |
| 9965 | #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS; |
| 9966 | #layerProperties = null; |
| 9967 | #previousRotation = null; |
| 9968 | #renderingState = _ui_utils.RenderingStates.INITIAL; |
| 9969 | #useThumbnailCanvas = { |
| 9970 | initialOptionalContent: true, |
| 9971 | regularAnnotations: true |
| 9972 | }; |
| 9973 | constructor(options) { |
| 9974 | const container = options.container; |
| 9975 | const defaultViewport = options.defaultViewport; |
| 9976 | this.id = options.id; |
| 9977 | this.renderingId = "page" + this.id; |
| 9978 | this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES; |
| 9979 | this.pdfPage = null; |
| 9980 | this.pageLabel = null; |
| 9981 | this.rotation = 0; |
| 9982 | this.scale = options.scale || _ui_utils.DEFAULT_SCALE; |
| 9983 | this.viewport = defaultViewport; |
| 9984 | this.pdfPageRotate = defaultViewport.rotation; |
| 9985 | this._optionalContentConfigPromise = options.optionalContentConfigPromise || null; |
| 9986 | this.hasRestrictedScaling = false; |
| 9987 | this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE; |
| 9988 | this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS; |
| 9989 | this.imageResourcesPath = options.imageResourcesPath || ""; |
| 9990 | this.useOnlyCssZoom = options.useOnlyCssZoom || false; |
| 9991 | this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true; |
| 9992 | this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; |
| 9993 | this.pageColors = options.pageColors || null; |
| 9994 | this.eventBus = options.eventBus; |
| 9995 | this.renderingQueue = options.renderingQueue; |
| 9996 | this.renderer = options.renderer || _ui_utils.RendererType.CANVAS; |
| 9997 | this.l10n = options.l10n || _l10n_utils.NullL10n; |
| 9998 | this.paintTask = null; |
| 9999 | this.paintedViewportMap = new WeakMap(); |
| 10000 | this.resume = null; |
| 10001 | this._renderError = null; |
| 10002 | this._isStandalone = !this.renderingQueue?.hasViewer(); |
| 10003 | this._annotationCanvasMap = null; |
| 10004 | this.annotationLayer = null; |
| 10005 | this.annotationEditorLayer = null; |
| 10006 | this.textLayer = null; |
| 10007 | this.zoomLayer = null; |
| 10008 | this.xfaLayer = null; |
| 10009 | this.structTreeLayer = null; |
| 10010 | const div = document.createElement("div"); |
| 10011 | div.className = "page"; |
| 10012 | div.setAttribute("data-page-number", this.id); |
| 10013 | div.setAttribute("role", "region"); |
| 10014 | this.l10n.get("page_landmark", { |
| 10015 | page: this.id |
| 10016 | }).then(msg => { |
| 10017 | div.setAttribute("aria-label", msg); |
| 10018 | }); |
| 10019 | this.div = div; |
| 10020 | this.#setDimensions(); |
| 10021 | container?.append(div); |
| 10022 | if (this._isStandalone) { |
| 10023 | container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS); |
| 10024 | const { |
| 10025 | optionalContentConfigPromise |
| 10026 | } = options; |
| 10027 | if (optionalContentConfigPromise) { |
| 10028 | optionalContentConfigPromise.then(optionalContentConfig => { |
| 10029 | if (optionalContentConfigPromise !== this._optionalContentConfigPromise) { |
| 10030 | return; |
| 10031 | } |
| 10032 | this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility; |
| 10033 | }); |
| 10034 | } |
| 10035 | } |
| 10036 | } |
| 10037 | get renderingState() { |
| 10038 | return this.#renderingState; |
| 10039 | } |
| 10040 | set renderingState(state) { |
| 10041 | this.#renderingState = state; |
| 10042 | switch (state) { |
| 10043 | case _ui_utils.RenderingStates.INITIAL: |
| 10044 | case _ui_utils.RenderingStates.PAUSED: |
| 10045 | this.loadingIconDiv?.classList.add("notVisible"); |
| 10046 | break; |
| 10047 | case _ui_utils.RenderingStates.RUNNING: |
| 10048 | this.loadingIconDiv?.classList.remove("notVisible"); |
| 10049 | break; |
| 10050 | case _ui_utils.RenderingStates.FINISHED: |
| 10051 | if (this.loadingIconDiv) { |
| 10052 | this.loadingIconDiv.remove(); |
| 10053 | delete this.loadingIconDiv; |
| 10054 | } |
| 10055 | break; |
| 10056 | } |
| 10057 | } |
| 10058 | #setDimensions() { |
| 10059 | const { |
| 10060 | viewport |
| 10061 | } = this; |
| 10062 | if (this.pdfPage) { |
| 10063 | if (this.#previousRotation === viewport.rotation) { |
| 10064 | return; |
| 10065 | } |
| 10066 | this.#previousRotation = viewport.rotation; |
| 10067 | } |
| 10068 | (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false); |
| 10069 | } |
| 10070 | setPdfPage(pdfPage) { |
| 10071 | this.pdfPage = pdfPage; |
| 10072 | this.pdfPageRotate = pdfPage.rotate; |
| 10073 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 10074 | this.viewport = pdfPage.getViewport({ |
| 10075 | scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS, |
| 10076 | rotation: totalRotation |
| 10077 | }); |
| 10078 | this.#setDimensions(); |
| 10079 | this.reset(); |
| 10080 | } |
| 10081 | destroy() { |
| 10082 | this.reset(); |
| 10083 | this.pdfPage?.cleanup(); |
| 10084 | } |
| 10085 | get _textHighlighter() { |
| 10086 | return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({ |
| 10087 | pageIndex: this.id - 1, |
| 10088 | eventBus: this.eventBus, |
| 10089 | findController: this.#layerProperties().findController |
| 10090 | })); |
| 10091 | } |
| 10092 | async #renderAnnotationLayer() { |
| 10093 | let error = null; |
| 10094 | try { |
| 10095 | await this.annotationLayer.render(this.viewport, "display"); |
| 10096 | } catch (ex) { |
| 10097 | console.error(`#renderAnnotationLayer: "${ex}".`); |
| 10098 | error = ex; |
| 10099 | } finally { |
| 10100 | this.eventBus.dispatch("annotationlayerrendered", { |
| 10101 | source: this, |
| 10102 | pageNumber: this.id, |
| 10103 | error |
| 10104 | }); |
| 10105 | } |
| 10106 | } |
| 10107 | async #renderAnnotationEditorLayer() { |
| 10108 | let error = null; |
| 10109 | try { |
| 10110 | await this.annotationEditorLayer.render(this.viewport, "display"); |
| 10111 | } catch (ex) { |
| 10112 | console.error(`#renderAnnotationEditorLayer: "${ex}".`); |
| 10113 | error = ex; |
| 10114 | } finally { |
| 10115 | this.eventBus.dispatch("annotationeditorlayerrendered", { |
| 10116 | source: this, |
| 10117 | pageNumber: this.id, |
| 10118 | error |
| 10119 | }); |
| 10120 | } |
| 10121 | } |
| 10122 | async #renderXfaLayer() { |
| 10123 | let error = null; |
| 10124 | try { |
| 10125 | const result = await this.xfaLayer.render(this.viewport, "display"); |
| 10126 | if (result?.textDivs && this._textHighlighter) { |
| 10127 | this.#buildXfaTextContentItems(result.textDivs); |
| 10128 | } |
| 10129 | } catch (ex) { |
| 10130 | console.error(`#renderXfaLayer: "${ex}".`); |
| 10131 | error = ex; |
| 10132 | } finally { |
| 10133 | this.eventBus.dispatch("xfalayerrendered", { |
| 10134 | source: this, |
| 10135 | pageNumber: this.id, |
| 10136 | error |
| 10137 | }); |
| 10138 | } |
| 10139 | } |
| 10140 | async #renderTextLayer() { |
| 10141 | const { |
| 10142 | pdfPage, |
| 10143 | textLayer, |
| 10144 | viewport |
| 10145 | } = this; |
| 10146 | if (!textLayer) { |
| 10147 | return; |
| 10148 | } |
| 10149 | let error = null; |
| 10150 | try { |
| 10151 | if (!textLayer.renderingDone) { |
| 10152 | const readableStream = pdfPage.streamTextContent({ |
| 10153 | includeMarkedContent: true |
| 10154 | }); |
| 10155 | textLayer.setTextContentSource(readableStream); |
| 10156 | } |
| 10157 | await textLayer.render(viewport); |
| 10158 | } catch (ex) { |
| 10159 | if (ex instanceof _pdfjsLib.AbortException) { |
| 10160 | return; |
| 10161 | } |
| 10162 | console.error(`#renderTextLayer: "${ex}".`); |
| 10163 | error = ex; |
| 10164 | } |
| 10165 | this.eventBus.dispatch("textlayerrendered", { |
| 10166 | source: this, |
| 10167 | pageNumber: this.id, |
| 10168 | numTextDivs: textLayer.numTextDivs, |
| 10169 | error |
| 10170 | }); |
| 10171 | this.#renderStructTreeLayer(); |
| 10172 | } |
| 10173 | async #renderStructTreeLayer() { |
| 10174 | if (!this.textLayer) { |
| 10175 | return; |
| 10176 | } |
| 10177 | this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder(); |
| 10178 | const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null); |
| 10179 | const treeDom = this.structTreeLayer?.render(tree); |
| 10180 | if (treeDom) { |
| 10181 | this.canvas?.append(treeDom); |
| 10182 | } |
| 10183 | } |
| 10184 | async #buildXfaTextContentItems(textDivs) { |
| 10185 | const text = await this.pdfPage.getTextContent(); |
| 10186 | const items = []; |
| 10187 | for (const item of text.items) { |
| 10188 | items.push(item.str); |
| 10189 | } |
| 10190 | this._textHighlighter.setTextMapping(textDivs, items); |
| 10191 | this._textHighlighter.enable(); |
| 10192 | } |
| 10193 | _resetZoomLayer(removeFromDOM = false) { |
| 10194 | if (!this.zoomLayer) { |
| 10195 | return; |
| 10196 | } |
| 10197 | const zoomLayerCanvas = this.zoomLayer.firstChild; |
| 10198 | this.paintedViewportMap.delete(zoomLayerCanvas); |
| 10199 | zoomLayerCanvas.width = 0; |
| 10200 | zoomLayerCanvas.height = 0; |
| 10201 | if (removeFromDOM) { |
| 10202 | this.zoomLayer.remove(); |
| 10203 | } |
| 10204 | this.zoomLayer = null; |
| 10205 | } |
| 10206 | reset({ |
| 10207 | keepZoomLayer = false, |
| 10208 | keepAnnotationLayer = false, |
| 10209 | keepAnnotationEditorLayer = false, |
| 10210 | keepXfaLayer = false, |
| 10211 | keepTextLayer = false |
| 10212 | } = {}) { |
| 10213 | this.cancelRendering({ |
| 10214 | keepAnnotationLayer, |
| 10215 | keepAnnotationEditorLayer, |
| 10216 | keepXfaLayer, |
| 10217 | keepTextLayer |
| 10218 | }); |
| 10219 | this.renderingState = _ui_utils.RenderingStates.INITIAL; |
| 10220 | const div = this.div; |
| 10221 | const childNodes = div.childNodes, |
| 10222 | zoomLayerNode = keepZoomLayer && this.zoomLayer || null, |
| 10223 | annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null, |
| 10224 | annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null, |
| 10225 | xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null, |
| 10226 | textLayerNode = keepTextLayer && this.textLayer?.div || null; |
| 10227 | for (let i = childNodes.length - 1; i >= 0; i--) { |
| 10228 | const node = childNodes[i]; |
| 10229 | switch (node) { |
| 10230 | case zoomLayerNode: |
| 10231 | case annotationLayerNode: |
| 10232 | case annotationEditorLayerNode: |
| 10233 | case xfaLayerNode: |
| 10234 | case textLayerNode: |
| 10235 | case this.loadingIconDiv: |
| 10236 | continue; |
| 10237 | } |
| 10238 | node.remove(); |
| 10239 | } |
| 10240 | div.removeAttribute("data-loaded"); |
| 10241 | if (annotationLayerNode) { |
| 10242 | this.annotationLayer.hide(); |
| 10243 | } |
| 10244 | if (annotationEditorLayerNode) { |
| 10245 | this.annotationEditorLayer.hide(); |
| 10246 | } |
| 10247 | if (xfaLayerNode) { |
| 10248 | this.xfaLayer.hide(); |
| 10249 | } |
| 10250 | if (textLayerNode) { |
| 10251 | this.textLayer.hide(); |
| 10252 | } |
| 10253 | if (!zoomLayerNode) { |
| 10254 | if (this.canvas) { |
| 10255 | this.paintedViewportMap.delete(this.canvas); |
| 10256 | this.canvas.width = 0; |
| 10257 | this.canvas.height = 0; |
| 10258 | delete this.canvas; |
| 10259 | } |
| 10260 | this._resetZoomLayer(); |
| 10261 | } |
| 10262 | if (this.svg) { |
| 10263 | this.paintedViewportMap.delete(this.svg); |
| 10264 | delete this.svg; |
| 10265 | } |
| 10266 | if (!this.loadingIconDiv) { |
| 10267 | this.loadingIconDiv = document.createElement("div"); |
| 10268 | this.loadingIconDiv.className = "loadingIcon notVisible"; |
| 10269 | this.loadingIconDiv.setAttribute("role", "img"); |
| 10270 | this.l10n.get("loading").then(msg => { |
| 10271 | this.loadingIconDiv?.setAttribute("aria-label", msg); |
| 10272 | }); |
| 10273 | div.append(this.loadingIconDiv); |
| 10274 | } |
| 10275 | } |
| 10276 | update({ |
| 10277 | scale = 0, |
| 10278 | rotation = null, |
| 10279 | optionalContentConfigPromise = null, |
| 10280 | drawingDelay = -1 |
| 10281 | }) { |
| 10282 | this.scale = scale || this.scale; |
| 10283 | if (typeof rotation === "number") { |
| 10284 | this.rotation = rotation; |
| 10285 | } |
| 10286 | if (optionalContentConfigPromise instanceof Promise) { |
| 10287 | this._optionalContentConfigPromise = optionalContentConfigPromise; |
| 10288 | optionalContentConfigPromise.then(optionalContentConfig => { |
| 10289 | if (optionalContentConfigPromise !== this._optionalContentConfigPromise) { |
| 10290 | return; |
| 10291 | } |
| 10292 | this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility; |
| 10293 | }); |
| 10294 | } |
| 10295 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 10296 | this.viewport = this.viewport.clone({ |
| 10297 | scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS, |
| 10298 | rotation: totalRotation |
| 10299 | }); |
| 10300 | this.#setDimensions(); |
| 10301 | if (this._isStandalone) { |
| 10302 | this.div.parentNode?.style.setProperty("--scale-factor", this.viewport.scale); |
| 10303 | } |
| 10304 | if (this.svg) { |
| 10305 | this.cssTransform({ |
| 10306 | target: this.svg, |
| 10307 | redrawAnnotationLayer: true, |
| 10308 | redrawAnnotationEditorLayer: true, |
| 10309 | redrawXfaLayer: true, |
| 10310 | redrawTextLayer: true |
| 10311 | }); |
| 10312 | this.eventBus.dispatch("pagerendered", { |
| 10313 | source: this, |
| 10314 | pageNumber: this.id, |
| 10315 | cssTransform: true, |
| 10316 | timestamp: performance.now(), |
| 10317 | error: this._renderError |
| 10318 | }); |
| 10319 | return; |
| 10320 | } |
| 10321 | let isScalingRestricted = false; |
| 10322 | if (this.canvas && this.maxCanvasPixels > 0) { |
| 10323 | const outputScale = this.outputScale; |
| 10324 | if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) { |
| 10325 | isScalingRestricted = true; |
| 10326 | } |
| 10327 | } |
| 10328 | const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000; |
| 10329 | if (this.canvas) { |
| 10330 | if (postponeDrawing || this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) { |
| 10331 | if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) { |
| 10332 | this.cancelRendering({ |
| 10333 | keepZoomLayer: true, |
| 10334 | keepAnnotationLayer: true, |
| 10335 | keepAnnotationEditorLayer: true, |
| 10336 | keepXfaLayer: true, |
| 10337 | keepTextLayer: true, |
| 10338 | cancelExtraDelay: drawingDelay |
| 10339 | }); |
| 10340 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 10341 | } |
| 10342 | this.cssTransform({ |
| 10343 | target: this.canvas, |
| 10344 | redrawAnnotationLayer: true, |
| 10345 | redrawAnnotationEditorLayer: true, |
| 10346 | redrawXfaLayer: true, |
| 10347 | redrawTextLayer: !postponeDrawing, |
| 10348 | hideTextLayer: postponeDrawing |
| 10349 | }); |
| 10350 | this.eventBus.dispatch("pagerendered", { |
| 10351 | source: this, |
| 10352 | pageNumber: this.id, |
| 10353 | cssTransform: true, |
| 10354 | timestamp: performance.now(), |
| 10355 | error: this._renderError |
| 10356 | }); |
| 10357 | return; |
| 10358 | } |
| 10359 | if (!this.zoomLayer && !this.canvas.hidden) { |
| 10360 | this.zoomLayer = this.canvas.parentNode; |
| 10361 | this.zoomLayer.style.position = "absolute"; |
| 10362 | } |
| 10363 | } |
| 10364 | if (this.zoomLayer) { |
| 10365 | this.cssTransform({ |
| 10366 | target: this.zoomLayer.firstChild |
| 10367 | }); |
| 10368 | } |
| 10369 | this.reset({ |
| 10370 | keepZoomLayer: true, |
| 10371 | keepAnnotationLayer: true, |
| 10372 | keepAnnotationEditorLayer: true, |
| 10373 | keepXfaLayer: true, |
| 10374 | keepTextLayer: true |
| 10375 | }); |
| 10376 | } |
| 10377 | cancelRendering({ |
| 10378 | keepAnnotationLayer = false, |
| 10379 | keepAnnotationEditorLayer = false, |
| 10380 | keepXfaLayer = false, |
| 10381 | keepTextLayer = false, |
| 10382 | cancelExtraDelay = 0 |
| 10383 | } = {}) { |
| 10384 | if (this.paintTask) { |
| 10385 | this.paintTask.cancel(cancelExtraDelay); |
| 10386 | this.paintTask = null; |
| 10387 | } |
| 10388 | this.resume = null; |
| 10389 | if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) { |
| 10390 | this.textLayer.cancel(); |
| 10391 | this.textLayer = null; |
| 10392 | } |
| 10393 | if (this.structTreeLayer && !this.textLayer) { |
| 10394 | this.structTreeLayer = null; |
| 10395 | } |
| 10396 | if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) { |
| 10397 | this.annotationLayer.cancel(); |
| 10398 | this.annotationLayer = null; |
| 10399 | this._annotationCanvasMap = null; |
| 10400 | } |
| 10401 | if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) { |
| 10402 | this.annotationEditorLayer.cancel(); |
| 10403 | this.annotationEditorLayer = null; |
| 10404 | } |
| 10405 | if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) { |
| 10406 | this.xfaLayer.cancel(); |
| 10407 | this.xfaLayer = null; |
| 10408 | this._textHighlighter?.disable(); |
| 10409 | } |
| 10410 | } |
| 10411 | cssTransform({ |
| 10412 | target, |
| 10413 | redrawAnnotationLayer = false, |
| 10414 | redrawAnnotationEditorLayer = false, |
| 10415 | redrawXfaLayer = false, |
| 10416 | redrawTextLayer = false, |
| 10417 | hideTextLayer = false |
| 10418 | }) { |
| 10419 | if (target instanceof HTMLCanvasElement) { |
| 10420 | if (!target.hasAttribute("zooming")) { |
| 10421 | target.setAttribute("zooming", true); |
| 10422 | const { |
| 10423 | style |
| 10424 | } = target; |
| 10425 | style.width = style.height = ""; |
| 10426 | } |
| 10427 | } else { |
| 10428 | const div = this.div; |
| 10429 | const { |
| 10430 | width, |
| 10431 | height |
| 10432 | } = this.viewport; |
| 10433 | target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px"; |
| 10434 | target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px"; |
| 10435 | } |
| 10436 | const originalViewport = this.paintedViewportMap.get(target); |
| 10437 | if (this.viewport !== originalViewport) { |
| 10438 | const relativeRotation = this.viewport.rotation - originalViewport.rotation; |
| 10439 | const absRotation = Math.abs(relativeRotation); |
| 10440 | let scaleX = 1, |
| 10441 | scaleY = 1; |
| 10442 | if (absRotation === 90 || absRotation === 270) { |
| 10443 | const { |
| 10444 | width, |
| 10445 | height |
| 10446 | } = this.viewport; |
| 10447 | scaleX = height / width; |
| 10448 | scaleY = width / height; |
| 10449 | } |
| 10450 | if (absRotation !== 0) { |
| 10451 | target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`; |
| 10452 | } |
| 10453 | } |
| 10454 | if (redrawAnnotationLayer && this.annotationLayer) { |
| 10455 | this.#renderAnnotationLayer(); |
| 10456 | } |
| 10457 | if (redrawAnnotationEditorLayer && this.annotationEditorLayer) { |
| 10458 | this.#renderAnnotationEditorLayer(); |
| 10459 | } |
| 10460 | if (redrawXfaLayer && this.xfaLayer) { |
| 10461 | this.#renderXfaLayer(); |
| 10462 | } |
| 10463 | if (this.textLayer) { |
| 10464 | if (hideTextLayer) { |
| 10465 | this.textLayer.hide(); |
| 10466 | } else if (redrawTextLayer) { |
| 10467 | this.#renderTextLayer(); |
| 10468 | } |
| 10469 | } |
| 10470 | } |
| 10471 | get width() { |
| 10472 | return this.viewport.width; |
| 10473 | } |
| 10474 | get height() { |
| 10475 | return this.viewport.height; |
| 10476 | } |
| 10477 | getPagePoint(x, y) { |
| 10478 | return this.viewport.convertToPdfPoint(x, y); |
| 10479 | } |
| 10480 | draw() { |
| 10481 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) { |
| 10482 | console.error("Must be in new state before drawing"); |
| 10483 | this.reset(); |
| 10484 | } |
| 10485 | const { |
| 10486 | div, |
| 10487 | pdfPage |
| 10488 | } = this; |
| 10489 | if (!pdfPage) { |
| 10490 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 10491 | return Promise.reject(new Error("pdfPage is not loaded")); |
| 10492 | } |
| 10493 | this.renderingState = _ui_utils.RenderingStates.RUNNING; |
| 10494 | const canvasWrapper = document.createElement("div"); |
| 10495 | canvasWrapper.classList.add("canvasWrapper"); |
| 10496 | div.append(canvasWrapper); |
| 10497 | if (!this.textLayer && this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) { |
| 10498 | this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager(); |
| 10499 | this.textLayer = new _text_layer_builder.TextLayerBuilder({ |
| 10500 | highlighter: this._textHighlighter, |
| 10501 | accessibilityManager: this._accessibilityManager, |
| 10502 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported |
| 10503 | }); |
| 10504 | div.append(this.textLayer.div); |
| 10505 | } |
| 10506 | if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) { |
| 10507 | const { |
| 10508 | annotationStorage, |
| 10509 | downloadManager, |
| 10510 | enableScripting, |
| 10511 | fieldObjectsPromise, |
| 10512 | hasJSActionsPromise, |
| 10513 | linkService |
| 10514 | } = this.#layerProperties(); |
| 10515 | this._annotationCanvasMap ||= new Map(); |
| 10516 | this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({ |
| 10517 | pageDiv: div, |
| 10518 | pdfPage, |
| 10519 | annotationStorage, |
| 10520 | imageResourcesPath: this.imageResourcesPath, |
| 10521 | renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS, |
| 10522 | linkService, |
| 10523 | downloadManager, |
| 10524 | l10n: this.l10n, |
| 10525 | enableScripting, |
| 10526 | hasJSActionsPromise, |
| 10527 | fieldObjectsPromise, |
| 10528 | annotationCanvasMap: this._annotationCanvasMap, |
| 10529 | accessibilityManager: this._accessibilityManager |
| 10530 | }); |
| 10531 | } |
| 10532 | if (this.xfaLayer?.div) { |
| 10533 | div.append(this.xfaLayer.div); |
| 10534 | } |
| 10535 | let renderContinueCallback = null; |
| 10536 | if (this.renderingQueue) { |
| 10537 | renderContinueCallback = cont => { |
| 10538 | if (!this.renderingQueue.isHighestPriority(this)) { |
| 10539 | this.renderingState = _ui_utils.RenderingStates.PAUSED; |
| 10540 | this.resume = () => { |
| 10541 | this.renderingState = _ui_utils.RenderingStates.RUNNING; |
| 10542 | cont(); |
| 10543 | }; |
| 10544 | return; |
| 10545 | } |
| 10546 | cont(); |
| 10547 | }; |
| 10548 | } |
| 10549 | const finishPaintTask = async (error = null) => { |
| 10550 | if (paintTask === this.paintTask) { |
| 10551 | this.paintTask = null; |
| 10552 | } |
| 10553 | if (error instanceof _pdfjsLib.RenderingCancelledException) { |
| 10554 | this._renderError = null; |
| 10555 | return; |
| 10556 | } |
| 10557 | this._renderError = error; |
| 10558 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 10559 | this._resetZoomLayer(true); |
| 10560 | this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots; |
| 10561 | this.eventBus.dispatch("pagerendered", { |
| 10562 | source: this, |
| 10563 | pageNumber: this.id, |
| 10564 | cssTransform: false, |
| 10565 | timestamp: performance.now(), |
| 10566 | error: this._renderError |
| 10567 | }); |
| 10568 | if (error) { |
| 10569 | throw error; |
| 10570 | } |
| 10571 | }; |
| 10572 | const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper); |
| 10573 | paintTask.onRenderContinue = renderContinueCallback; |
| 10574 | this.paintTask = paintTask; |
| 10575 | const resultPromise = paintTask.promise.then(() => { |
| 10576 | return finishPaintTask(null).then(async () => { |
| 10577 | this.#renderTextLayer(); |
| 10578 | if (this.annotationLayer) { |
| 10579 | await this.#renderAnnotationLayer(); |
| 10580 | } |
| 10581 | if (!this.annotationEditorLayer) { |
| 10582 | const { |
| 10583 | annotationEditorUIManager |
| 10584 | } = this.#layerProperties(); |
| 10585 | if (!annotationEditorUIManager) { |
| 10586 | return; |
| 10587 | } |
| 10588 | this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({ |
| 10589 | uiManager: annotationEditorUIManager, |
| 10590 | pageDiv: div, |
| 10591 | pdfPage, |
| 10592 | l10n: this.l10n, |
| 10593 | accessibilityManager: this._accessibilityManager |
| 10594 | }); |
| 10595 | } |
| 10596 | this.#renderAnnotationEditorLayer(); |
| 10597 | }); |
| 10598 | }, function (reason) { |
| 10599 | return finishPaintTask(reason); |
| 10600 | }); |
| 10601 | if (pdfPage.isPureXfa) { |
| 10602 | if (!this.xfaLayer) { |
| 10603 | const { |
| 10604 | annotationStorage, |
| 10605 | linkService |
| 10606 | } = this.#layerProperties(); |
| 10607 | this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({ |
| 10608 | pageDiv: div, |
| 10609 | pdfPage, |
| 10610 | annotationStorage, |
| 10611 | linkService |
| 10612 | }); |
| 10613 | } |
| 10614 | this.#renderXfaLayer(); |
| 10615 | } |
| 10616 | div.setAttribute("data-loaded", true); |
| 10617 | this.eventBus.dispatch("pagerender", { |
| 10618 | source: this, |
| 10619 | pageNumber: this.id |
| 10620 | }); |
| 10621 | return resultPromise; |
| 10622 | } |
| 10623 | paintOnCanvas(canvasWrapper) { |
| 10624 | const renderCapability = (0, _pdfjsLib.createPromiseCapability)(); |
| 10625 | const result = { |
| 10626 | promise: renderCapability.promise, |
| 10627 | onRenderContinue(cont) { |
| 10628 | cont(); |
| 10629 | }, |
| 10630 | cancel(extraDelay = 0) { |
| 10631 | renderTask.cancel(extraDelay); |
| 10632 | }, |
| 10633 | get separateAnnots() { |
| 10634 | return renderTask.separateAnnots; |
| 10635 | } |
| 10636 | }; |
| 10637 | const viewport = this.viewport; |
| 10638 | const { |
| 10639 | width, |
| 10640 | height |
| 10641 | } = viewport; |
| 10642 | const canvas = document.createElement("canvas"); |
| 10643 | canvas.setAttribute("role", "presentation"); |
| 10644 | canvas.hidden = true; |
| 10645 | let isCanvasHidden = true; |
| 10646 | const showCanvas = function () { |
| 10647 | if (isCanvasHidden) { |
| 10648 | canvas.hidden = false; |
| 10649 | isCanvasHidden = false; |
| 10650 | } |
| 10651 | }; |
| 10652 | canvasWrapper.append(canvas); |
| 10653 | this.canvas = canvas; |
| 10654 | const ctx = canvas.getContext("2d", { |
| 10655 | alpha: false |
| 10656 | }); |
| 10657 | const outputScale = this.outputScale = new _ui_utils.OutputScale(); |
| 10658 | if (this.useOnlyCssZoom) { |
| 10659 | const actualSizeViewport = viewport.clone({ |
| 10660 | scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS |
| 10661 | }); |
| 10662 | outputScale.sx *= actualSizeViewport.width / width; |
| 10663 | outputScale.sy *= actualSizeViewport.height / height; |
| 10664 | } |
| 10665 | if (this.maxCanvasPixels > 0) { |
| 10666 | const pixelsInViewport = width * height; |
| 10667 | const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport); |
| 10668 | if (outputScale.sx > maxScale || outputScale.sy > maxScale) { |
| 10669 | outputScale.sx = maxScale; |
| 10670 | outputScale.sy = maxScale; |
| 10671 | this.hasRestrictedScaling = true; |
| 10672 | } else { |
| 10673 | this.hasRestrictedScaling = false; |
| 10674 | } |
| 10675 | } |
| 10676 | const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx); |
| 10677 | const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy); |
| 10678 | canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]); |
| 10679 | canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]); |
| 10680 | const { |
| 10681 | style |
| 10682 | } = canvas; |
| 10683 | style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px"; |
| 10684 | style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px"; |
| 10685 | this.paintedViewportMap.set(canvas, viewport); |
| 10686 | const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null; |
| 10687 | const renderContext = { |
| 10688 | canvasContext: ctx, |
| 10689 | transform, |
| 10690 | viewport, |
| 10691 | annotationMode: this.#annotationMode, |
| 10692 | optionalContentConfigPromise: this._optionalContentConfigPromise, |
| 10693 | annotationCanvasMap: this._annotationCanvasMap, |
| 10694 | pageColors: this.pageColors |
| 10695 | }; |
| 10696 | const renderTask = this.pdfPage.render(renderContext); |
| 10697 | renderTask.onContinue = function (cont) { |
| 10698 | showCanvas(); |
| 10699 | if (result.onRenderContinue) { |
| 10700 | result.onRenderContinue(cont); |
| 10701 | } else { |
| 10702 | cont(); |
| 10703 | } |
| 10704 | }; |
| 10705 | renderTask.promise.then(function () { |
| 10706 | showCanvas(); |
| 10707 | renderCapability.resolve(); |
| 10708 | }, function (error) { |
| 10709 | if (!(error instanceof _pdfjsLib.RenderingCancelledException)) { |
| 10710 | showCanvas(); |
| 10711 | } |
| 10712 | renderCapability.reject(error); |
| 10713 | }); |
| 10714 | return result; |
| 10715 | } |
| 10716 | paintOnSvg(wrapper) { |
| 10717 | let cancelled = false; |
| 10718 | const ensureNotCancelled = () => { |
| 10719 | if (cancelled) { |
| 10720 | throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg"); |
| 10721 | } |
| 10722 | }; |
| 10723 | const pdfPage = this.pdfPage; |
| 10724 | const actualSizeViewport = this.viewport.clone({ |
| 10725 | scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS |
| 10726 | }); |
| 10727 | const promise = pdfPage.getOperatorList({ |
| 10728 | annotationMode: this.#annotationMode |
| 10729 | }).then(opList => { |
| 10730 | ensureNotCancelled(); |
| 10731 | const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs); |
| 10732 | return svgGfx.getSVG(opList, actualSizeViewport).then(svg => { |
| 10733 | ensureNotCancelled(); |
| 10734 | this.svg = svg; |
| 10735 | this.paintedViewportMap.set(svg, actualSizeViewport); |
| 10736 | svg.style.width = wrapper.style.width; |
| 10737 | svg.style.height = wrapper.style.height; |
| 10738 | this.renderingState = _ui_utils.RenderingStates.FINISHED; |
| 10739 | wrapper.append(svg); |
| 10740 | }); |
| 10741 | }); |
| 10742 | return { |
| 10743 | promise, |
| 10744 | onRenderContinue(cont) { |
| 10745 | cont(); |
| 10746 | }, |
| 10747 | cancel() { |
| 10748 | cancelled = true; |
| 10749 | }, |
| 10750 | get separateAnnots() { |
| 10751 | return false; |
| 10752 | } |
| 10753 | }; |
| 10754 | } |
| 10755 | setPageLabel(label) { |
| 10756 | this.pageLabel = typeof label === "string" ? label : null; |
| 10757 | if (this.pageLabel !== null) { |
| 10758 | this.div.setAttribute("data-page-label", this.pageLabel); |
| 10759 | } else { |
| 10760 | this.div.removeAttribute("data-page-label"); |
| 10761 | } |
| 10762 | } |
| 10763 | get thumbnailCanvas() { |
| 10764 | const { |
| 10765 | initialOptionalContent, |
| 10766 | regularAnnotations |
| 10767 | } = this.#useThumbnailCanvas; |
| 10768 | return initialOptionalContent && regularAnnotations ? this.canvas : null; |
| 10769 | } |
| 10770 | } |
| 10771 | exports.PDFPageView = PDFPageView; |
| 10772 | |
| 10773 | /***/ }), |
| 10774 | /* 31 */ |
| 10775 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 10776 | |
| 10777 | |
| 10778 | |
| 10779 | Object.defineProperty(exports, "__esModule", ({ |
| 10780 | value: true |
| 10781 | })); |
| 10782 | exports.AnnotationEditorLayerBuilder = void 0; |
| 10783 | var _pdfjsLib = __webpack_require__(5); |
| 10784 | var _l10n_utils = __webpack_require__(29); |
| 10785 | class AnnotationEditorLayerBuilder { |
| 10786 | #uiManager; |
| 10787 | constructor(options) { |
| 10788 | this.pageDiv = options.pageDiv; |
| 10789 | this.pdfPage = options.pdfPage; |
| 10790 | this.accessibilityManager = options.accessibilityManager; |
| 10791 | this.l10n = options.l10n || _l10n_utils.NullL10n; |
| 10792 | this.annotationEditorLayer = null; |
| 10793 | this.div = null; |
| 10794 | this._cancelled = false; |
| 10795 | this.#uiManager = options.uiManager; |
| 10796 | } |
| 10797 | async render(viewport, intent = "display") { |
| 10798 | if (intent !== "display") { |
| 10799 | return; |
| 10800 | } |
| 10801 | if (this._cancelled) { |
| 10802 | return; |
| 10803 | } |
| 10804 | const clonedViewport = viewport.clone({ |
| 10805 | dontFlip: true |
| 10806 | }); |
| 10807 | if (this.div) { |
| 10808 | this.annotationEditorLayer.update({ |
| 10809 | viewport: clonedViewport |
| 10810 | }); |
| 10811 | this.show(); |
| 10812 | return; |
| 10813 | } |
| 10814 | const div = this.div = document.createElement("div"); |
| 10815 | div.className = "annotationEditorLayer"; |
| 10816 | div.tabIndex = 0; |
| 10817 | this.pageDiv.append(div); |
| 10818 | this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({ |
| 10819 | uiManager: this.#uiManager, |
| 10820 | div, |
| 10821 | accessibilityManager: this.accessibilityManager, |
| 10822 | pageIndex: this.pdfPage.pageNumber - 1, |
| 10823 | l10n: this.l10n, |
| 10824 | viewport: clonedViewport |
| 10825 | }); |
| 10826 | const parameters = { |
| 10827 | viewport: clonedViewport, |
| 10828 | div, |
| 10829 | annotations: null, |
| 10830 | intent |
| 10831 | }; |
| 10832 | this.annotationEditorLayer.render(parameters); |
| 10833 | } |
| 10834 | cancel() { |
| 10835 | this._cancelled = true; |
| 10836 | if (!this.div) { |
| 10837 | return; |
| 10838 | } |
| 10839 | this.pageDiv = null; |
| 10840 | this.annotationEditorLayer.destroy(); |
| 10841 | this.div.remove(); |
| 10842 | } |
| 10843 | hide() { |
| 10844 | if (!this.div) { |
| 10845 | return; |
| 10846 | } |
| 10847 | this.div.hidden = true; |
| 10848 | } |
| 10849 | show() { |
| 10850 | if (!this.div) { |
| 10851 | return; |
| 10852 | } |
| 10853 | this.div.hidden = false; |
| 10854 | } |
| 10855 | } |
| 10856 | exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder; |
| 10857 | |
| 10858 | /***/ }), |
| 10859 | /* 32 */ |
| 10860 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 10861 | |
| 10862 | |
| 10863 | |
| 10864 | Object.defineProperty(exports, "__esModule", ({ |
| 10865 | value: true |
| 10866 | })); |
| 10867 | exports.AnnotationLayerBuilder = void 0; |
| 10868 | var _pdfjsLib = __webpack_require__(5); |
| 10869 | var _l10n_utils = __webpack_require__(29); |
| 10870 | var _ui_utils = __webpack_require__(1); |
| 10871 | class AnnotationLayerBuilder { |
| 10872 | #numAnnotations = 0; |
| 10873 | #onPresentationModeChanged = null; |
| 10874 | constructor({ |
| 10875 | pageDiv, |
| 10876 | pdfPage, |
| 10877 | linkService, |
| 10878 | downloadManager, |
| 10879 | annotationStorage = null, |
| 10880 | imageResourcesPath = "", |
| 10881 | renderForms = true, |
| 10882 | l10n = _l10n_utils.NullL10n, |
| 10883 | enableScripting = false, |
| 10884 | hasJSActionsPromise = null, |
| 10885 | fieldObjectsPromise = null, |
| 10886 | annotationCanvasMap = null, |
| 10887 | accessibilityManager = null |
| 10888 | }) { |
| 10889 | this.pageDiv = pageDiv; |
| 10890 | this.pdfPage = pdfPage; |
| 10891 | this.linkService = linkService; |
| 10892 | this.downloadManager = downloadManager; |
| 10893 | this.imageResourcesPath = imageResourcesPath; |
| 10894 | this.renderForms = renderForms; |
| 10895 | this.l10n = l10n; |
| 10896 | this.annotationStorage = annotationStorage; |
| 10897 | this.enableScripting = enableScripting; |
| 10898 | this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false); |
| 10899 | this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null); |
| 10900 | this._annotationCanvasMap = annotationCanvasMap; |
| 10901 | this._accessibilityManager = accessibilityManager; |
| 10902 | this.div = null; |
| 10903 | this._cancelled = false; |
| 10904 | this._eventBus = linkService.eventBus; |
| 10905 | } |
| 10906 | async render(viewport, intent = "display") { |
| 10907 | if (this.div) { |
| 10908 | if (this._cancelled || this.#numAnnotations === 0) { |
| 10909 | return; |
| 10910 | } |
| 10911 | _pdfjsLib.AnnotationLayer.update({ |
| 10912 | viewport: viewport.clone({ |
| 10913 | dontFlip: true |
| 10914 | }), |
| 10915 | div: this.div, |
| 10916 | annotationCanvasMap: this._annotationCanvasMap |
| 10917 | }); |
| 10918 | return; |
| 10919 | } |
| 10920 | const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({ |
| 10921 | intent |
| 10922 | }), this._hasJSActionsPromise, this._fieldObjectsPromise]); |
| 10923 | if (this._cancelled) { |
| 10924 | return; |
| 10925 | } |
| 10926 | this.#numAnnotations = annotations.length; |
| 10927 | this.div = document.createElement("div"); |
| 10928 | this.div.className = "annotationLayer"; |
| 10929 | this.pageDiv.append(this.div); |
| 10930 | if (this.#numAnnotations === 0) { |
| 10931 | this.hide(); |
| 10932 | return; |
| 10933 | } |
| 10934 | _pdfjsLib.AnnotationLayer.render({ |
| 10935 | viewport: viewport.clone({ |
| 10936 | dontFlip: true |
| 10937 | }), |
| 10938 | div: this.div, |
| 10939 | annotations, |
| 10940 | page: this.pdfPage, |
| 10941 | imageResourcesPath: this.imageResourcesPath, |
| 10942 | renderForms: this.renderForms, |
| 10943 | linkService: this.linkService, |
| 10944 | downloadManager: this.downloadManager, |
| 10945 | annotationStorage: this.annotationStorage, |
| 10946 | enableScripting: this.enableScripting, |
| 10947 | hasJSActions, |
| 10948 | fieldObjects, |
| 10949 | annotationCanvasMap: this._annotationCanvasMap, |
| 10950 | accessibilityManager: this._accessibilityManager |
| 10951 | }); |
| 10952 | this.l10n.translate(this.div); |
| 10953 | if (this.linkService.isInPresentationMode) { |
| 10954 | this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN); |
| 10955 | } |
| 10956 | if (!this.#onPresentationModeChanged) { |
| 10957 | this.#onPresentationModeChanged = evt => { |
| 10958 | this.#updatePresentationModeState(evt.state); |
| 10959 | }; |
| 10960 | this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged); |
| 10961 | } |
| 10962 | } |
| 10963 | cancel() { |
| 10964 | this._cancelled = true; |
| 10965 | if (this.#onPresentationModeChanged) { |
| 10966 | this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged); |
| 10967 | this.#onPresentationModeChanged = null; |
| 10968 | } |
| 10969 | } |
| 10970 | hide() { |
| 10971 | if (!this.div) { |
| 10972 | return; |
| 10973 | } |
| 10974 | this.div.hidden = true; |
| 10975 | } |
| 10976 | #updatePresentationModeState(state) { |
| 10977 | if (!this.div) { |
| 10978 | return; |
| 10979 | } |
| 10980 | let disableFormElements = false; |
| 10981 | switch (state) { |
| 10982 | case _ui_utils.PresentationModeState.FULLSCREEN: |
| 10983 | disableFormElements = true; |
| 10984 | break; |
| 10985 | case _ui_utils.PresentationModeState.NORMAL: |
| 10986 | break; |
| 10987 | default: |
| 10988 | return; |
| 10989 | } |
| 10990 | for (const section of this.div.childNodes) { |
| 10991 | if (section.hasAttribute("data-internal-link")) { |
| 10992 | continue; |
| 10993 | } |
| 10994 | section.inert = disableFormElements; |
| 10995 | } |
| 10996 | } |
| 10997 | } |
| 10998 | exports.AnnotationLayerBuilder = AnnotationLayerBuilder; |
| 10999 | |
| 11000 | /***/ }), |
| 11001 | /* 33 */ |
| 11002 | /***/ ((__unused_webpack_module, exports) => { |
| 11003 | |
| 11004 | |
| 11005 | |
| 11006 | Object.defineProperty(exports, "__esModule", ({ |
| 11007 | value: true |
| 11008 | })); |
| 11009 | exports.StructTreeLayerBuilder = void 0; |
| 11010 | const PDF_ROLE_TO_HTML_ROLE = { |
| 11011 | Document: null, |
| 11012 | DocumentFragment: null, |
| 11013 | Part: "group", |
| 11014 | Sect: "group", |
| 11015 | Div: "group", |
| 11016 | Aside: "note", |
| 11017 | NonStruct: "none", |
| 11018 | P: null, |
| 11019 | H: "heading", |
| 11020 | Title: null, |
| 11021 | FENote: "note", |
| 11022 | Sub: "group", |
| 11023 | Lbl: null, |
| 11024 | Span: null, |
| 11025 | Em: null, |
| 11026 | Strong: null, |
| 11027 | Link: "link", |
| 11028 | Annot: "note", |
| 11029 | Form: "form", |
| 11030 | Ruby: null, |
| 11031 | RB: null, |
| 11032 | RT: null, |
| 11033 | RP: null, |
| 11034 | Warichu: null, |
| 11035 | WT: null, |
| 11036 | WP: null, |
| 11037 | L: "list", |
| 11038 | LI: "listitem", |
| 11039 | LBody: null, |
| 11040 | Table: "table", |
| 11041 | TR: "row", |
| 11042 | TH: "columnheader", |
| 11043 | TD: "cell", |
| 11044 | THead: "columnheader", |
| 11045 | TBody: null, |
| 11046 | TFoot: null, |
| 11047 | Caption: null, |
| 11048 | Figure: "figure", |
| 11049 | Formula: null, |
| 11050 | Artifact: null |
| 11051 | }; |
| 11052 | const HEADING_PATTERN = /^H(\d+)$/; |
| 11053 | class StructTreeLayerBuilder { |
| 11054 | #treeDom = undefined; |
| 11055 | get renderingDone() { |
| 11056 | return this.#treeDom !== undefined; |
| 11057 | } |
| 11058 | render(structTree) { |
| 11059 | if (this.#treeDom !== undefined) { |
| 11060 | return this.#treeDom; |
| 11061 | } |
| 11062 | const treeDom = this.#walk(structTree); |
| 11063 | treeDom?.classList.add("structTree"); |
| 11064 | return this.#treeDom = treeDom; |
| 11065 | } |
| 11066 | #setAttributes(structElement, htmlElement) { |
| 11067 | if (structElement.alt !== undefined) { |
| 11068 | htmlElement.setAttribute("aria-label", structElement.alt); |
| 11069 | } |
| 11070 | if (structElement.id !== undefined) { |
| 11071 | htmlElement.setAttribute("aria-owns", structElement.id); |
| 11072 | } |
| 11073 | if (structElement.lang !== undefined) { |
| 11074 | htmlElement.setAttribute("lang", structElement.lang); |
| 11075 | } |
| 11076 | } |
| 11077 | #walk(node) { |
| 11078 | if (!node) { |
| 11079 | return null; |
| 11080 | } |
| 11081 | const element = document.createElement("span"); |
| 11082 | if ("role" in node) { |
| 11083 | const { |
| 11084 | role |
| 11085 | } = node; |
| 11086 | const match = role.match(HEADING_PATTERN); |
| 11087 | if (match) { |
| 11088 | element.setAttribute("role", "heading"); |
| 11089 | element.setAttribute("aria-level", match[1]); |
| 11090 | } else if (PDF_ROLE_TO_HTML_ROLE[role]) { |
| 11091 | element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]); |
| 11092 | } |
| 11093 | } |
| 11094 | this.#setAttributes(node, element); |
| 11095 | if (node.children) { |
| 11096 | if (node.children.length === 1 && "id" in node.children[0]) { |
| 11097 | this.#setAttributes(node.children[0], element); |
| 11098 | } else { |
| 11099 | for (const kid of node.children) { |
| 11100 | element.append(this.#walk(kid)); |
| 11101 | } |
| 11102 | } |
| 11103 | } |
| 11104 | return element; |
| 11105 | } |
| 11106 | } |
| 11107 | exports.StructTreeLayerBuilder = StructTreeLayerBuilder; |
| 11108 | |
| 11109 | /***/ }), |
| 11110 | /* 34 */ |
| 11111 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 11112 | |
| 11113 | |
| 11114 | |
| 11115 | Object.defineProperty(exports, "__esModule", ({ |
| 11116 | value: true |
| 11117 | })); |
| 11118 | exports.TextAccessibilityManager = void 0; |
| 11119 | var _ui_utils = __webpack_require__(1); |
| 11120 | class TextAccessibilityManager { |
| 11121 | #enabled = false; |
| 11122 | #textChildren = null; |
| 11123 | #textNodes = new Map(); |
| 11124 | #waitingElements = new Map(); |
| 11125 | setTextMapping(textDivs) { |
| 11126 | this.#textChildren = textDivs; |
| 11127 | } |
| 11128 | static #compareElementPositions(e1, e2) { |
| 11129 | const rect1 = e1.getBoundingClientRect(); |
| 11130 | const rect2 = e2.getBoundingClientRect(); |
| 11131 | if (rect1.width === 0 && rect1.height === 0) { |
| 11132 | return +1; |
| 11133 | } |
| 11134 | if (rect2.width === 0 && rect2.height === 0) { |
| 11135 | return -1; |
| 11136 | } |
| 11137 | const top1 = rect1.y; |
| 11138 | const bot1 = rect1.y + rect1.height; |
| 11139 | const mid1 = rect1.y + rect1.height / 2; |
| 11140 | const top2 = rect2.y; |
| 11141 | const bot2 = rect2.y + rect2.height; |
| 11142 | const mid2 = rect2.y + rect2.height / 2; |
| 11143 | if (mid1 <= top2 && mid2 >= bot1) { |
| 11144 | return -1; |
| 11145 | } |
| 11146 | if (mid2 <= top1 && mid1 >= bot2) { |
| 11147 | return +1; |
| 11148 | } |
| 11149 | const centerX1 = rect1.x + rect1.width / 2; |
| 11150 | const centerX2 = rect2.x + rect2.width / 2; |
| 11151 | return centerX1 - centerX2; |
| 11152 | } |
| 11153 | enable() { |
| 11154 | if (this.#enabled) { |
| 11155 | throw new Error("TextAccessibilityManager is already enabled."); |
| 11156 | } |
| 11157 | if (!this.#textChildren) { |
| 11158 | throw new Error("Text divs and strings have not been set."); |
| 11159 | } |
| 11160 | this.#enabled = true; |
| 11161 | this.#textChildren = this.#textChildren.slice(); |
| 11162 | this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions); |
| 11163 | if (this.#textNodes.size > 0) { |
| 11164 | const textChildren = this.#textChildren; |
| 11165 | for (const [id, nodeIndex] of this.#textNodes) { |
| 11166 | const element = document.getElementById(id); |
| 11167 | if (!element) { |
| 11168 | this.#textNodes.delete(id); |
| 11169 | continue; |
| 11170 | } |
| 11171 | this.#addIdToAriaOwns(id, textChildren[nodeIndex]); |
| 11172 | } |
| 11173 | } |
| 11174 | for (const [element, isRemovable] of this.#waitingElements) { |
| 11175 | this.addPointerInTextLayer(element, isRemovable); |
| 11176 | } |
| 11177 | this.#waitingElements.clear(); |
| 11178 | } |
| 11179 | disable() { |
| 11180 | if (!this.#enabled) { |
| 11181 | return; |
| 11182 | } |
| 11183 | this.#waitingElements.clear(); |
| 11184 | this.#textChildren = null; |
| 11185 | this.#enabled = false; |
| 11186 | } |
| 11187 | removePointerInTextLayer(element) { |
| 11188 | if (!this.#enabled) { |
| 11189 | this.#waitingElements.delete(element); |
| 11190 | return; |
| 11191 | } |
| 11192 | const children = this.#textChildren; |
| 11193 | if (!children || children.length === 0) { |
| 11194 | return; |
| 11195 | } |
| 11196 | const { |
| 11197 | id |
| 11198 | } = element; |
| 11199 | const nodeIndex = this.#textNodes.get(id); |
| 11200 | if (nodeIndex === undefined) { |
| 11201 | return; |
| 11202 | } |
| 11203 | const node = children[nodeIndex]; |
| 11204 | this.#textNodes.delete(id); |
| 11205 | let owns = node.getAttribute("aria-owns"); |
| 11206 | if (owns?.includes(id)) { |
| 11207 | owns = owns.split(" ").filter(x => x !== id).join(" "); |
| 11208 | if (owns) { |
| 11209 | node.setAttribute("aria-owns", owns); |
| 11210 | } else { |
| 11211 | node.removeAttribute("aria-owns"); |
| 11212 | node.setAttribute("role", "presentation"); |
| 11213 | } |
| 11214 | } |
| 11215 | } |
| 11216 | #addIdToAriaOwns(id, node) { |
| 11217 | const owns = node.getAttribute("aria-owns"); |
| 11218 | if (!owns?.includes(id)) { |
| 11219 | node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id); |
| 11220 | } |
| 11221 | node.removeAttribute("role"); |
| 11222 | } |
| 11223 | addPointerInTextLayer(element, isRemovable) { |
| 11224 | const { |
| 11225 | id |
| 11226 | } = element; |
| 11227 | if (!id) { |
| 11228 | return; |
| 11229 | } |
| 11230 | if (!this.#enabled) { |
| 11231 | this.#waitingElements.set(element, isRemovable); |
| 11232 | return; |
| 11233 | } |
| 11234 | if (isRemovable) { |
| 11235 | this.removePointerInTextLayer(element); |
| 11236 | } |
| 11237 | const children = this.#textChildren; |
| 11238 | if (!children || children.length === 0) { |
| 11239 | return; |
| 11240 | } |
| 11241 | const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0); |
| 11242 | const nodeIndex = Math.max(0, index - 1); |
| 11243 | this.#addIdToAriaOwns(id, children[nodeIndex]); |
| 11244 | this.#textNodes.set(id, nodeIndex); |
| 11245 | } |
| 11246 | moveElementInDOM(container, element, contentElement, isRemovable) { |
| 11247 | this.addPointerInTextLayer(contentElement, isRemovable); |
| 11248 | if (!container.hasChildNodes()) { |
| 11249 | container.append(element); |
| 11250 | return; |
| 11251 | } |
| 11252 | const children = Array.from(container.childNodes).filter(node => node !== element); |
| 11253 | if (children.length === 0) { |
| 11254 | return; |
| 11255 | } |
| 11256 | const elementToCompare = contentElement || element; |
| 11257 | const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0); |
| 11258 | if (index === 0) { |
| 11259 | children[0].before(element); |
| 11260 | } else { |
| 11261 | children[index - 1].after(element); |
| 11262 | } |
| 11263 | } |
| 11264 | } |
| 11265 | exports.TextAccessibilityManager = TextAccessibilityManager; |
| 11266 | |
| 11267 | /***/ }), |
| 11268 | /* 35 */ |
| 11269 | /***/ ((__unused_webpack_module, exports) => { |
| 11270 | |
| 11271 | |
| 11272 | |
| 11273 | Object.defineProperty(exports, "__esModule", ({ |
| 11274 | value: true |
| 11275 | })); |
| 11276 | exports.TextHighlighter = void 0; |
| 11277 | class TextHighlighter { |
| 11278 | constructor({ |
| 11279 | findController, |
| 11280 | eventBus, |
| 11281 | pageIndex |
| 11282 | }) { |
| 11283 | this.findController = findController; |
| 11284 | this.matches = []; |
| 11285 | this.eventBus = eventBus; |
| 11286 | this.pageIdx = pageIndex; |
| 11287 | this._onUpdateTextLayerMatches = null; |
| 11288 | this.textDivs = null; |
| 11289 | this.textContentItemsStr = null; |
| 11290 | this.enabled = false; |
| 11291 | } |
| 11292 | setTextMapping(divs, texts) { |
| 11293 | this.textDivs = divs; |
| 11294 | this.textContentItemsStr = texts; |
| 11295 | } |
| 11296 | enable() { |
| 11297 | if (!this.textDivs || !this.textContentItemsStr) { |
| 11298 | throw new Error("Text divs and strings have not been set."); |
| 11299 | } |
| 11300 | if (this.enabled) { |
| 11301 | throw new Error("TextHighlighter is already enabled."); |
| 11302 | } |
| 11303 | this.enabled = true; |
| 11304 | if (!this._onUpdateTextLayerMatches) { |
| 11305 | this._onUpdateTextLayerMatches = evt => { |
| 11306 | if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) { |
| 11307 | this._updateMatches(); |
| 11308 | } |
| 11309 | }; |
| 11310 | this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches); |
| 11311 | } |
| 11312 | this._updateMatches(); |
| 11313 | } |
| 11314 | disable() { |
| 11315 | if (!this.enabled) { |
| 11316 | return; |
| 11317 | } |
| 11318 | this.enabled = false; |
| 11319 | if (this._onUpdateTextLayerMatches) { |
| 11320 | this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches); |
| 11321 | this._onUpdateTextLayerMatches = null; |
| 11322 | } |
| 11323 | this._updateMatches(true); |
| 11324 | } |
| 11325 | _convertMatches(matches, matchesLength) { |
| 11326 | if (!matches) { |
| 11327 | return []; |
| 11328 | } |
| 11329 | const { |
| 11330 | textContentItemsStr |
| 11331 | } = this; |
| 11332 | let i = 0, |
| 11333 | iIndex = 0; |
| 11334 | const end = textContentItemsStr.length - 1; |
| 11335 | const result = []; |
| 11336 | for (let m = 0, mm = matches.length; m < mm; m++) { |
| 11337 | let matchIdx = matches[m]; |
| 11338 | while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) { |
| 11339 | iIndex += textContentItemsStr[i].length; |
| 11340 | i++; |
| 11341 | } |
| 11342 | if (i === textContentItemsStr.length) { |
| 11343 | console.error("Could not find a matching mapping"); |
| 11344 | } |
| 11345 | const match = { |
| 11346 | begin: { |
| 11347 | divIdx: i, |
| 11348 | offset: matchIdx - iIndex |
| 11349 | } |
| 11350 | }; |
| 11351 | matchIdx += matchesLength[m]; |
| 11352 | while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) { |
| 11353 | iIndex += textContentItemsStr[i].length; |
| 11354 | i++; |
| 11355 | } |
| 11356 | match.end = { |
| 11357 | divIdx: i, |
| 11358 | offset: matchIdx - iIndex |
| 11359 | }; |
| 11360 | result.push(match); |
| 11361 | } |
| 11362 | return result; |
| 11363 | } |
| 11364 | _renderMatches(matches) { |
| 11365 | if (matches.length === 0) { |
| 11366 | return; |
| 11367 | } |
| 11368 | const { |
| 11369 | findController, |
| 11370 | pageIdx |
| 11371 | } = this; |
| 11372 | const { |
| 11373 | textContentItemsStr, |
| 11374 | textDivs |
| 11375 | } = this; |
| 11376 | const isSelectedPage = pageIdx === findController.selected.pageIdx; |
| 11377 | const selectedMatchIdx = findController.selected.matchIdx; |
| 11378 | const highlightAll = findController.state.highlightAll; |
| 11379 | let prevEnd = null; |
| 11380 | const infinity = { |
| 11381 | divIdx: -1, |
| 11382 | offset: undefined |
| 11383 | }; |
| 11384 | function beginText(begin, className) { |
| 11385 | const divIdx = begin.divIdx; |
| 11386 | textDivs[divIdx].textContent = ""; |
| 11387 | return appendTextToDiv(divIdx, 0, begin.offset, className); |
| 11388 | } |
| 11389 | function appendTextToDiv(divIdx, fromOffset, toOffset, className) { |
| 11390 | let div = textDivs[divIdx]; |
| 11391 | if (div.nodeType === Node.TEXT_NODE) { |
| 11392 | const span = document.createElement("span"); |
| 11393 | div.before(span); |
| 11394 | span.append(div); |
| 11395 | textDivs[divIdx] = span; |
| 11396 | div = span; |
| 11397 | } |
| 11398 | const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset); |
| 11399 | const node = document.createTextNode(content); |
| 11400 | if (className) { |
| 11401 | const span = document.createElement("span"); |
| 11402 | span.className = `${className} appended`; |
| 11403 | span.append(node); |
| 11404 | div.append(span); |
| 11405 | return className.includes("selected") ? span.offsetLeft : 0; |
| 11406 | } |
| 11407 | div.append(node); |
| 11408 | return 0; |
| 11409 | } |
| 11410 | let i0 = selectedMatchIdx, |
| 11411 | i1 = i0 + 1; |
| 11412 | if (highlightAll) { |
| 11413 | i0 = 0; |
| 11414 | i1 = matches.length; |
| 11415 | } else if (!isSelectedPage) { |
| 11416 | return; |
| 11417 | } |
| 11418 | for (let i = i0; i < i1; i++) { |
| 11419 | const match = matches[i]; |
| 11420 | const begin = match.begin; |
| 11421 | const end = match.end; |
| 11422 | const isSelected = isSelectedPage && i === selectedMatchIdx; |
| 11423 | const highlightSuffix = isSelected ? " selected" : ""; |
| 11424 | let selectedLeft = 0; |
| 11425 | if (!prevEnd || begin.divIdx !== prevEnd.divIdx) { |
| 11426 | if (prevEnd !== null) { |
| 11427 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); |
| 11428 | } |
| 11429 | beginText(begin); |
| 11430 | } else { |
| 11431 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset); |
| 11432 | } |
| 11433 | if (begin.divIdx === end.divIdx) { |
| 11434 | selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix); |
| 11435 | } else { |
| 11436 | selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix); |
| 11437 | for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) { |
| 11438 | textDivs[n0].className = "highlight middle" + highlightSuffix; |
| 11439 | } |
| 11440 | beginText(end, "highlight end" + highlightSuffix); |
| 11441 | } |
| 11442 | prevEnd = end; |
| 11443 | if (isSelected) { |
| 11444 | findController.scrollMatchIntoView({ |
| 11445 | element: textDivs[begin.divIdx], |
| 11446 | selectedLeft, |
| 11447 | pageIndex: pageIdx, |
| 11448 | matchIndex: selectedMatchIdx |
| 11449 | }); |
| 11450 | } |
| 11451 | } |
| 11452 | if (prevEnd) { |
| 11453 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); |
| 11454 | } |
| 11455 | } |
| 11456 | _updateMatches(reset = false) { |
| 11457 | if (!this.enabled && !reset) { |
| 11458 | return; |
| 11459 | } |
| 11460 | const { |
| 11461 | findController, |
| 11462 | matches, |
| 11463 | pageIdx |
| 11464 | } = this; |
| 11465 | const { |
| 11466 | textContentItemsStr, |
| 11467 | textDivs |
| 11468 | } = this; |
| 11469 | let clearedUntilDivIdx = -1; |
| 11470 | for (const match of matches) { |
| 11471 | const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); |
| 11472 | for (let n = begin, end = match.end.divIdx; n <= end; n++) { |
| 11473 | const div = textDivs[n]; |
| 11474 | div.textContent = textContentItemsStr[n]; |
| 11475 | div.className = ""; |
| 11476 | } |
| 11477 | clearedUntilDivIdx = match.end.divIdx + 1; |
| 11478 | } |
| 11479 | if (!findController?.highlightMatches || reset) { |
| 11480 | return; |
| 11481 | } |
| 11482 | const pageMatches = findController.pageMatches[pageIdx] || null; |
| 11483 | const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null; |
| 11484 | this.matches = this._convertMatches(pageMatches, pageMatchesLength); |
| 11485 | this._renderMatches(this.matches); |
| 11486 | } |
| 11487 | } |
| 11488 | exports.TextHighlighter = TextHighlighter; |
| 11489 | |
| 11490 | /***/ }), |
| 11491 | /* 36 */ |
| 11492 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 11493 | |
| 11494 | |
| 11495 | |
| 11496 | Object.defineProperty(exports, "__esModule", ({ |
| 11497 | value: true |
| 11498 | })); |
| 11499 | exports.TextLayerBuilder = void 0; |
| 11500 | var _pdfjsLib = __webpack_require__(5); |
| 11501 | class TextLayerBuilder { |
| 11502 | #rotation = 0; |
| 11503 | #scale = 0; |
| 11504 | #textContentSource = null; |
| 11505 | constructor({ |
| 11506 | highlighter = null, |
| 11507 | accessibilityManager = null, |
| 11508 | isOffscreenCanvasSupported = true |
| 11509 | }) { |
| 11510 | this.textContentItemsStr = []; |
| 11511 | this.renderingDone = false; |
| 11512 | this.textDivs = []; |
| 11513 | this.textDivProperties = new WeakMap(); |
| 11514 | this.textLayerRenderTask = null; |
| 11515 | this.highlighter = highlighter; |
| 11516 | this.accessibilityManager = accessibilityManager; |
| 11517 | this.isOffscreenCanvasSupported = isOffscreenCanvasSupported; |
| 11518 | this.div = document.createElement("div"); |
| 11519 | this.div.className = "textLayer"; |
| 11520 | this.hide(); |
| 11521 | } |
| 11522 | #finishRendering() { |
| 11523 | this.renderingDone = true; |
| 11524 | const endOfContent = document.createElement("div"); |
| 11525 | endOfContent.className = "endOfContent"; |
| 11526 | this.div.append(endOfContent); |
| 11527 | this.#bindMouse(); |
| 11528 | } |
| 11529 | get numTextDivs() { |
| 11530 | return this.textDivs.length; |
| 11531 | } |
| 11532 | async render(viewport) { |
| 11533 | if (!this.#textContentSource) { |
| 11534 | throw new Error('No "textContentSource" parameter specified.'); |
| 11535 | } |
| 11536 | const scale = viewport.scale * (globalThis.devicePixelRatio || 1); |
| 11537 | const { |
| 11538 | rotation |
| 11539 | } = viewport; |
| 11540 | if (this.renderingDone) { |
| 11541 | const mustRotate = rotation !== this.#rotation; |
| 11542 | const mustRescale = scale !== this.#scale; |
| 11543 | if (mustRotate || mustRescale) { |
| 11544 | this.hide(); |
| 11545 | (0, _pdfjsLib.updateTextLayer)({ |
| 11546 | container: this.div, |
| 11547 | viewport, |
| 11548 | textDivs: this.textDivs, |
| 11549 | textDivProperties: this.textDivProperties, |
| 11550 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported, |
| 11551 | mustRescale, |
| 11552 | mustRotate |
| 11553 | }); |
| 11554 | this.#scale = scale; |
| 11555 | this.#rotation = rotation; |
| 11556 | } |
| 11557 | this.show(); |
| 11558 | return; |
| 11559 | } |
| 11560 | this.cancel(); |
| 11561 | this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr); |
| 11562 | this.accessibilityManager?.setTextMapping(this.textDivs); |
| 11563 | this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({ |
| 11564 | textContentSource: this.#textContentSource, |
| 11565 | container: this.div, |
| 11566 | viewport, |
| 11567 | textDivs: this.textDivs, |
| 11568 | textDivProperties: this.textDivProperties, |
| 11569 | textContentItemsStr: this.textContentItemsStr, |
| 11570 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported |
| 11571 | }); |
| 11572 | await this.textLayerRenderTask.promise; |
| 11573 | this.#finishRendering(); |
| 11574 | this.#scale = scale; |
| 11575 | this.#rotation = rotation; |
| 11576 | this.show(); |
| 11577 | this.accessibilityManager?.enable(); |
| 11578 | } |
| 11579 | hide() { |
| 11580 | if (!this.div.hidden) { |
| 11581 | this.highlighter?.disable(); |
| 11582 | this.div.hidden = true; |
| 11583 | } |
| 11584 | } |
| 11585 | show() { |
| 11586 | if (this.div.hidden && this.renderingDone) { |
| 11587 | this.div.hidden = false; |
| 11588 | this.highlighter?.enable(); |
| 11589 | } |
| 11590 | } |
| 11591 | cancel() { |
| 11592 | if (this.textLayerRenderTask) { |
| 11593 | this.textLayerRenderTask.cancel(); |
| 11594 | this.textLayerRenderTask = null; |
| 11595 | } |
| 11596 | this.highlighter?.disable(); |
| 11597 | this.accessibilityManager?.disable(); |
| 11598 | this.textContentItemsStr.length = 0; |
| 11599 | this.textDivs.length = 0; |
| 11600 | this.textDivProperties = new WeakMap(); |
| 11601 | } |
| 11602 | setTextContentSource(source) { |
| 11603 | this.cancel(); |
| 11604 | this.#textContentSource = source; |
| 11605 | } |
| 11606 | #bindMouse() { |
| 11607 | const { |
| 11608 | div |
| 11609 | } = this; |
| 11610 | div.addEventListener("mousedown", evt => { |
| 11611 | const end = div.querySelector(".endOfContent"); |
| 11612 | if (!end) { |
| 11613 | return; |
| 11614 | } |
| 11615 | let adjustTop = evt.target !== div; |
| 11616 | adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none"; |
| 11617 | if (adjustTop) { |
| 11618 | const divBounds = div.getBoundingClientRect(); |
| 11619 | const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height); |
| 11620 | end.style.top = (r * 100).toFixed(2) + "%"; |
| 11621 | } |
| 11622 | end.classList.add("active"); |
| 11623 | }); |
| 11624 | div.addEventListener("mouseup", () => { |
| 11625 | const end = div.querySelector(".endOfContent"); |
| 11626 | if (!end) { |
| 11627 | return; |
| 11628 | } |
| 11629 | end.style.top = ""; |
| 11630 | end.classList.remove("active"); |
| 11631 | }); |
| 11632 | } |
| 11633 | } |
| 11634 | exports.TextLayerBuilder = TextLayerBuilder; |
| 11635 | |
| 11636 | /***/ }), |
| 11637 | /* 37 */ |
| 11638 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 11639 | |
| 11640 | |
| 11641 | |
| 11642 | Object.defineProperty(exports, "__esModule", ({ |
| 11643 | value: true |
| 11644 | })); |
| 11645 | exports.XfaLayerBuilder = void 0; |
| 11646 | var _pdfjsLib = __webpack_require__(5); |
| 11647 | class XfaLayerBuilder { |
| 11648 | constructor({ |
| 11649 | pageDiv, |
| 11650 | pdfPage, |
| 11651 | annotationStorage = null, |
| 11652 | linkService, |
| 11653 | xfaHtml = null |
| 11654 | }) { |
| 11655 | this.pageDiv = pageDiv; |
| 11656 | this.pdfPage = pdfPage; |
| 11657 | this.annotationStorage = annotationStorage; |
| 11658 | this.linkService = linkService; |
| 11659 | this.xfaHtml = xfaHtml; |
| 11660 | this.div = null; |
| 11661 | this._cancelled = false; |
| 11662 | } |
| 11663 | async render(viewport, intent = "display") { |
| 11664 | if (intent === "print") { |
| 11665 | const parameters = { |
| 11666 | viewport: viewport.clone({ |
| 11667 | dontFlip: true |
| 11668 | }), |
| 11669 | div: this.div, |
| 11670 | xfaHtml: this.xfaHtml, |
| 11671 | annotationStorage: this.annotationStorage, |
| 11672 | linkService: this.linkService, |
| 11673 | intent |
| 11674 | }; |
| 11675 | const div = document.createElement("div"); |
| 11676 | this.pageDiv.append(div); |
| 11677 | parameters.div = div; |
| 11678 | return _pdfjsLib.XfaLayer.render(parameters); |
| 11679 | } |
| 11680 | const xfaHtml = await this.pdfPage.getXfa(); |
| 11681 | if (this._cancelled || !xfaHtml) { |
| 11682 | return { |
| 11683 | textDivs: [] |
| 11684 | }; |
| 11685 | } |
| 11686 | const parameters = { |
| 11687 | viewport: viewport.clone({ |
| 11688 | dontFlip: true |
| 11689 | }), |
| 11690 | div: this.div, |
| 11691 | xfaHtml, |
| 11692 | annotationStorage: this.annotationStorage, |
| 11693 | linkService: this.linkService, |
| 11694 | intent |
| 11695 | }; |
| 11696 | if (this.div) { |
| 11697 | return _pdfjsLib.XfaLayer.update(parameters); |
| 11698 | } |
| 11699 | this.div = document.createElement("div"); |
| 11700 | this.pageDiv.append(this.div); |
| 11701 | parameters.div = this.div; |
| 11702 | return _pdfjsLib.XfaLayer.render(parameters); |
| 11703 | } |
| 11704 | cancel() { |
| 11705 | this._cancelled = true; |
| 11706 | } |
| 11707 | hide() { |
| 11708 | if (!this.div) { |
| 11709 | return; |
| 11710 | } |
| 11711 | this.div.hidden = true; |
| 11712 | } |
| 11713 | } |
| 11714 | exports.XfaLayerBuilder = XfaLayerBuilder; |
| 11715 | |
| 11716 | /***/ }), |
| 11717 | /* 38 */ |
| 11718 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 11719 | |
| 11720 | |
| 11721 | |
| 11722 | Object.defineProperty(exports, "__esModule", ({ |
| 11723 | value: true |
| 11724 | })); |
| 11725 | exports.SecondaryToolbar = void 0; |
| 11726 | var _ui_utils = __webpack_require__(1); |
| 11727 | var _pdf_cursor_tools = __webpack_require__(7); |
| 11728 | var _pdf_viewer = __webpack_require__(28); |
| 11729 | class SecondaryToolbar { |
| 11730 | constructor(options, eventBus, externalServices) { |
| 11731 | this.toolbar = options.toolbar; |
| 11732 | this.toggleButton = options.toggleButton; |
| 11733 | this.buttons = [{ |
| 11734 | element: options.presentationModeButton, |
| 11735 | eventName: "presentationmode", |
| 11736 | close: true |
| 11737 | }, { |
| 11738 | element: options.printButton, |
| 11739 | eventName: "print", |
| 11740 | close: true |
| 11741 | }, { |
| 11742 | element: options.downloadButton, |
| 11743 | eventName: "download", |
| 11744 | close: true |
| 11745 | }, { |
| 11746 | element: options.viewBookmarkButton, |
| 11747 | eventName: null, |
| 11748 | close: true |
| 11749 | }, { |
| 11750 | element: options.firstPageButton, |
| 11751 | eventName: "firstpage", |
| 11752 | close: true |
| 11753 | }, { |
| 11754 | element: options.lastPageButton, |
| 11755 | eventName: "lastpage", |
| 11756 | close: true |
| 11757 | }, { |
| 11758 | element: options.pageRotateCwButton, |
| 11759 | eventName: "rotatecw", |
| 11760 | close: false |
| 11761 | }, { |
| 11762 | element: options.pageRotateCcwButton, |
| 11763 | eventName: "rotateccw", |
| 11764 | close: false |
| 11765 | }, { |
| 11766 | element: options.cursorSelectToolButton, |
| 11767 | eventName: "switchcursortool", |
| 11768 | eventDetails: { |
| 11769 | tool: _pdf_cursor_tools.CursorTool.SELECT |
| 11770 | }, |
| 11771 | close: true |
| 11772 | }, { |
| 11773 | element: options.cursorHandToolButton, |
| 11774 | eventName: "switchcursortool", |
| 11775 | eventDetails: { |
| 11776 | tool: _pdf_cursor_tools.CursorTool.HAND |
| 11777 | }, |
| 11778 | close: true |
| 11779 | }, { |
| 11780 | element: options.scrollPageButton, |
| 11781 | eventName: "switchscrollmode", |
| 11782 | eventDetails: { |
| 11783 | mode: _ui_utils.ScrollMode.PAGE |
| 11784 | }, |
| 11785 | close: true |
| 11786 | }, { |
| 11787 | element: options.scrollVerticalButton, |
| 11788 | eventName: "switchscrollmode", |
| 11789 | eventDetails: { |
| 11790 | mode: _ui_utils.ScrollMode.VERTICAL |
| 11791 | }, |
| 11792 | close: true |
| 11793 | }, { |
| 11794 | element: options.scrollHorizontalButton, |
| 11795 | eventName: "switchscrollmode", |
| 11796 | eventDetails: { |
| 11797 | mode: _ui_utils.ScrollMode.HORIZONTAL |
| 11798 | }, |
| 11799 | close: true |
| 11800 | }, { |
| 11801 | element: options.scrollWrappedButton, |
| 11802 | eventName: "switchscrollmode", |
| 11803 | eventDetails: { |
| 11804 | mode: _ui_utils.ScrollMode.WRAPPED |
| 11805 | }, |
| 11806 | close: true |
| 11807 | }, { |
| 11808 | element: options.spreadNoneButton, |
| 11809 | eventName: "switchspreadmode", |
| 11810 | eventDetails: { |
| 11811 | mode: _ui_utils.SpreadMode.NONE |
| 11812 | }, |
| 11813 | close: true |
| 11814 | }, { |
| 11815 | element: options.spreadOddButton, |
| 11816 | eventName: "switchspreadmode", |
| 11817 | eventDetails: { |
| 11818 | mode: _ui_utils.SpreadMode.ODD |
| 11819 | }, |
| 11820 | close: true |
| 11821 | }, { |
| 11822 | element: options.spreadEvenButton, |
| 11823 | eventName: "switchspreadmode", |
| 11824 | eventDetails: { |
| 11825 | mode: _ui_utils.SpreadMode.EVEN |
| 11826 | }, |
| 11827 | close: true |
| 11828 | }, { |
| 11829 | element: options.documentPropertiesButton, |
| 11830 | eventName: "documentproperties", |
| 11831 | close: true |
| 11832 | }]; |
| 11833 | this.buttons.push({ |
| 11834 | element: options.openFileButton, |
| 11835 | eventName: "openfile", |
| 11836 | close: true |
| 11837 | }); |
| 11838 | this.items = { |
| 11839 | firstPage: options.firstPageButton, |
| 11840 | lastPage: options.lastPageButton, |
| 11841 | pageRotateCw: options.pageRotateCwButton, |
| 11842 | pageRotateCcw: options.pageRotateCcwButton |
| 11843 | }; |
| 11844 | this.eventBus = eventBus; |
| 11845 | this.externalServices = externalServices; |
| 11846 | this.opened = false; |
| 11847 | this.#bindClickListeners(); |
| 11848 | this.#bindCursorToolsListener(options); |
| 11849 | this.#bindScrollModeListener(options); |
| 11850 | this.#bindSpreadModeListener(options); |
| 11851 | this.reset(); |
| 11852 | } |
| 11853 | get isOpen() { |
| 11854 | return this.opened; |
| 11855 | } |
| 11856 | setPageNumber(pageNumber) { |
| 11857 | this.pageNumber = pageNumber; |
| 11858 | this.#updateUIState(); |
| 11859 | } |
| 11860 | setPagesCount(pagesCount) { |
| 11861 | this.pagesCount = pagesCount; |
| 11862 | this.#updateUIState(); |
| 11863 | } |
| 11864 | reset() { |
| 11865 | this.pageNumber = 0; |
| 11866 | this.pagesCount = 0; |
| 11867 | this.#updateUIState(); |
| 11868 | this.eventBus.dispatch("secondarytoolbarreset", { |
| 11869 | source: this |
| 11870 | }); |
| 11871 | } |
| 11872 | #updateUIState() { |
| 11873 | this.items.firstPage.disabled = this.pageNumber <= 1; |
| 11874 | this.items.lastPage.disabled = this.pageNumber >= this.pagesCount; |
| 11875 | this.items.pageRotateCw.disabled = this.pagesCount === 0; |
| 11876 | this.items.pageRotateCcw.disabled = this.pagesCount === 0; |
| 11877 | } |
| 11878 | #bindClickListeners() { |
| 11879 | this.toggleButton.addEventListener("click", this.toggle.bind(this)); |
| 11880 | for (const { |
| 11881 | element, |
| 11882 | eventName, |
| 11883 | close, |
| 11884 | eventDetails |
| 11885 | } of this.buttons) { |
| 11886 | element.addEventListener("click", evt => { |
| 11887 | if (eventName !== null) { |
| 11888 | const details = { |
| 11889 | source: this |
| 11890 | }; |
| 11891 | for (const property in eventDetails) { |
| 11892 | details[property] = eventDetails[property]; |
| 11893 | } |
| 11894 | this.eventBus.dispatch(eventName, details); |
| 11895 | } |
| 11896 | if (close) { |
| 11897 | this.close(); |
| 11898 | } |
| 11899 | this.externalServices.reportTelemetry({ |
| 11900 | type: "buttons", |
| 11901 | data: { |
| 11902 | id: element.id |
| 11903 | } |
| 11904 | }); |
| 11905 | }); |
| 11906 | } |
| 11907 | } |
| 11908 | #bindCursorToolsListener({ |
| 11909 | cursorSelectToolButton, |
| 11910 | cursorHandToolButton |
| 11911 | }) { |
| 11912 | this.eventBus._on("cursortoolchanged", function ({ |
| 11913 | tool |
| 11914 | }) { |
| 11915 | const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT, |
| 11916 | isHand = tool === _pdf_cursor_tools.CursorTool.HAND; |
| 11917 | cursorSelectToolButton.classList.toggle("toggled", isSelect); |
| 11918 | cursorHandToolButton.classList.toggle("toggled", isHand); |
| 11919 | cursorSelectToolButton.setAttribute("aria-checked", isSelect); |
| 11920 | cursorHandToolButton.setAttribute("aria-checked", isHand); |
| 11921 | }); |
| 11922 | } |
| 11923 | #bindScrollModeListener({ |
| 11924 | scrollPageButton, |
| 11925 | scrollVerticalButton, |
| 11926 | scrollHorizontalButton, |
| 11927 | scrollWrappedButton, |
| 11928 | spreadNoneButton, |
| 11929 | spreadOddButton, |
| 11930 | spreadEvenButton |
| 11931 | }) { |
| 11932 | const scrollModeChanged = ({ |
| 11933 | mode |
| 11934 | }) => { |
| 11935 | const isPage = mode === _ui_utils.ScrollMode.PAGE, |
| 11936 | isVertical = mode === _ui_utils.ScrollMode.VERTICAL, |
| 11937 | isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL, |
| 11938 | isWrapped = mode === _ui_utils.ScrollMode.WRAPPED; |
| 11939 | scrollPageButton.classList.toggle("toggled", isPage); |
| 11940 | scrollVerticalButton.classList.toggle("toggled", isVertical); |
| 11941 | scrollHorizontalButton.classList.toggle("toggled", isHorizontal); |
| 11942 | scrollWrappedButton.classList.toggle("toggled", isWrapped); |
| 11943 | scrollPageButton.setAttribute("aria-checked", isPage); |
| 11944 | scrollVerticalButton.setAttribute("aria-checked", isVertical); |
| 11945 | scrollHorizontalButton.setAttribute("aria-checked", isHorizontal); |
| 11946 | scrollWrappedButton.setAttribute("aria-checked", isWrapped); |
| 11947 | const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE; |
| 11948 | scrollPageButton.disabled = forceScrollModePage; |
| 11949 | scrollVerticalButton.disabled = forceScrollModePage; |
| 11950 | scrollHorizontalButton.disabled = forceScrollModePage; |
| 11951 | scrollWrappedButton.disabled = forceScrollModePage; |
| 11952 | spreadNoneButton.disabled = isHorizontal; |
| 11953 | spreadOddButton.disabled = isHorizontal; |
| 11954 | spreadEvenButton.disabled = isHorizontal; |
| 11955 | }; |
| 11956 | this.eventBus._on("scrollmodechanged", scrollModeChanged); |
| 11957 | this.eventBus._on("secondarytoolbarreset", evt => { |
| 11958 | if (evt.source === this) { |
| 11959 | scrollModeChanged({ |
| 11960 | mode: _ui_utils.ScrollMode.VERTICAL |
| 11961 | }); |
| 11962 | } |
| 11963 | }); |
| 11964 | } |
| 11965 | #bindSpreadModeListener({ |
| 11966 | spreadNoneButton, |
| 11967 | spreadOddButton, |
| 11968 | spreadEvenButton |
| 11969 | }) { |
| 11970 | function spreadModeChanged({ |
| 11971 | mode |
| 11972 | }) { |
| 11973 | const isNone = mode === _ui_utils.SpreadMode.NONE, |
| 11974 | isOdd = mode === _ui_utils.SpreadMode.ODD, |
| 11975 | isEven = mode === _ui_utils.SpreadMode.EVEN; |
| 11976 | spreadNoneButton.classList.toggle("toggled", isNone); |
| 11977 | spreadOddButton.classList.toggle("toggled", isOdd); |
| 11978 | spreadEvenButton.classList.toggle("toggled", isEven); |
| 11979 | spreadNoneButton.setAttribute("aria-checked", isNone); |
| 11980 | spreadOddButton.setAttribute("aria-checked", isOdd); |
| 11981 | spreadEvenButton.setAttribute("aria-checked", isEven); |
| 11982 | } |
| 11983 | this.eventBus._on("spreadmodechanged", spreadModeChanged); |
| 11984 | this.eventBus._on("secondarytoolbarreset", evt => { |
| 11985 | if (evt.source === this) { |
| 11986 | spreadModeChanged({ |
| 11987 | mode: _ui_utils.SpreadMode.NONE |
| 11988 | }); |
| 11989 | } |
| 11990 | }); |
| 11991 | } |
| 11992 | open() { |
| 11993 | if (this.opened) { |
| 11994 | return; |
| 11995 | } |
| 11996 | this.opened = true; |
| 11997 | this.toggleButton.classList.add("toggled"); |
| 11998 | this.toggleButton.setAttribute("aria-expanded", "true"); |
| 11999 | this.toolbar.classList.remove("hidden"); |
| 12000 | } |
| 12001 | close() { |
| 12002 | if (!this.opened) { |
| 12003 | return; |
| 12004 | } |
| 12005 | this.opened = false; |
| 12006 | this.toolbar.classList.add("hidden"); |
| 12007 | this.toggleButton.classList.remove("toggled"); |
| 12008 | this.toggleButton.setAttribute("aria-expanded", "false"); |
| 12009 | } |
| 12010 | toggle() { |
| 12011 | if (this.opened) { |
| 12012 | this.close(); |
| 12013 | } else { |
| 12014 | this.open(); |
| 12015 | } |
| 12016 | } |
| 12017 | } |
| 12018 | exports.SecondaryToolbar = SecondaryToolbar; |
| 12019 | |
| 12020 | /***/ }), |
| 12021 | /* 39 */ |
| 12022 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 12023 | |
| 12024 | |
| 12025 | |
| 12026 | Object.defineProperty(exports, "__esModule", ({ |
| 12027 | value: true |
| 12028 | })); |
| 12029 | exports.Toolbar = void 0; |
| 12030 | var _ui_utils = __webpack_require__(1); |
| 12031 | var _pdfjsLib = __webpack_require__(5); |
| 12032 | const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading"; |
| 12033 | class Toolbar { |
| 12034 | #wasLocalized = false; |
| 12035 | constructor(options, eventBus, l10n) { |
| 12036 | this.toolbar = options.container; |
| 12037 | this.eventBus = eventBus; |
| 12038 | this.l10n = l10n; |
| 12039 | this.buttons = [{ |
| 12040 | element: options.previous, |
| 12041 | eventName: "previouspage" |
| 12042 | }, { |
| 12043 | element: options.next, |
| 12044 | eventName: "nextpage" |
| 12045 | }, { |
| 12046 | element: options.zoomIn, |
| 12047 | eventName: "zoomin" |
| 12048 | }, { |
| 12049 | element: options.zoomOut, |
| 12050 | eventName: "zoomout" |
| 12051 | }, { |
| 12052 | element: options.print, |
| 12053 | eventName: "print" |
| 12054 | }, { |
| 12055 | element: options.download, |
| 12056 | eventName: "download" |
| 12057 | }, { |
| 12058 | element: options.editorFreeTextButton, |
| 12059 | eventName: "switchannotationeditormode", |
| 12060 | eventDetails: { |
| 12061 | get mode() { |
| 12062 | const { |
| 12063 | classList |
| 12064 | } = options.editorFreeTextButton; |
| 12065 | return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT; |
| 12066 | } |
| 12067 | } |
| 12068 | }, { |
| 12069 | element: options.editorInkButton, |
| 12070 | eventName: "switchannotationeditormode", |
| 12071 | eventDetails: { |
| 12072 | get mode() { |
| 12073 | const { |
| 12074 | classList |
| 12075 | } = options.editorInkButton; |
| 12076 | return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK; |
| 12077 | } |
| 12078 | } |
| 12079 | }]; |
| 12080 | this.buttons.push({ |
| 12081 | element: options.openFile, |
| 12082 | eventName: "openfile" |
| 12083 | }); |
| 12084 | this.items = { |
| 12085 | numPages: options.numPages, |
| 12086 | pageNumber: options.pageNumber, |
| 12087 | scaleSelect: options.scaleSelect, |
| 12088 | customScaleOption: options.customScaleOption, |
| 12089 | previous: options.previous, |
| 12090 | next: options.next, |
| 12091 | zoomIn: options.zoomIn, |
| 12092 | zoomOut: options.zoomOut |
| 12093 | }; |
| 12094 | this.#bindListeners(options); |
| 12095 | this.reset(); |
| 12096 | } |
| 12097 | setPageNumber(pageNumber, pageLabel) { |
| 12098 | this.pageNumber = pageNumber; |
| 12099 | this.pageLabel = pageLabel; |
| 12100 | this.#updateUIState(false); |
| 12101 | } |
| 12102 | setPagesCount(pagesCount, hasPageLabels) { |
| 12103 | this.pagesCount = pagesCount; |
| 12104 | this.hasPageLabels = hasPageLabels; |
| 12105 | this.#updateUIState(true); |
| 12106 | } |
| 12107 | setPageScale(pageScaleValue, pageScale) { |
| 12108 | this.pageScaleValue = (pageScaleValue || pageScale).toString(); |
| 12109 | this.pageScale = pageScale; |
| 12110 | this.#updateUIState(false); |
| 12111 | } |
| 12112 | reset() { |
| 12113 | this.pageNumber = 0; |
| 12114 | this.pageLabel = null; |
| 12115 | this.hasPageLabels = false; |
| 12116 | this.pagesCount = 0; |
| 12117 | this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE; |
| 12118 | this.pageScale = _ui_utils.DEFAULT_SCALE; |
| 12119 | this.#updateUIState(true); |
| 12120 | this.updateLoadingIndicatorState(); |
| 12121 | this.eventBus.dispatch("toolbarreset", { |
| 12122 | source: this |
| 12123 | }); |
| 12124 | } |
| 12125 | #bindListeners(options) { |
| 12126 | const { |
| 12127 | pageNumber, |
| 12128 | scaleSelect |
| 12129 | } = this.items; |
| 12130 | const self = this; |
| 12131 | for (const { |
| 12132 | element, |
| 12133 | eventName, |
| 12134 | eventDetails |
| 12135 | } of this.buttons) { |
| 12136 | element.addEventListener("click", evt => { |
| 12137 | if (eventName !== null) { |
| 12138 | const details = { |
| 12139 | source: this |
| 12140 | }; |
| 12141 | if (eventDetails) { |
| 12142 | for (const property in eventDetails) { |
| 12143 | details[property] = eventDetails[property]; |
| 12144 | } |
| 12145 | } |
| 12146 | this.eventBus.dispatch(eventName, details); |
| 12147 | } |
| 12148 | }); |
| 12149 | } |
| 12150 | pageNumber.addEventListener("click", function () { |
| 12151 | this.select(); |
| 12152 | }); |
| 12153 | pageNumber.addEventListener("change", function () { |
| 12154 | self.eventBus.dispatch("pagenumberchanged", { |
| 12155 | source: self, |
| 12156 | value: this.value |
| 12157 | }); |
| 12158 | }); |
| 12159 | scaleSelect.addEventListener("change", function () { |
| 12160 | if (this.value === "custom") { |
| 12161 | return; |
| 12162 | } |
| 12163 | self.eventBus.dispatch("scalechanged", { |
| 12164 | source: self, |
| 12165 | value: this.value |
| 12166 | }); |
| 12167 | }); |
| 12168 | scaleSelect.addEventListener("click", function (evt) { |
| 12169 | const target = evt.target; |
| 12170 | if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") { |
| 12171 | this.blur(); |
| 12172 | } |
| 12173 | }); |
| 12174 | scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler; |
| 12175 | this.eventBus._on("localized", () => { |
| 12176 | this.#wasLocalized = true; |
| 12177 | this.#adjustScaleWidth(); |
| 12178 | this.#updateUIState(true); |
| 12179 | }); |
| 12180 | this.#bindEditorToolsListener(options); |
| 12181 | } |
| 12182 | #bindEditorToolsListener({ |
| 12183 | editorFreeTextButton, |
| 12184 | editorFreeTextParamsToolbar, |
| 12185 | editorInkButton, |
| 12186 | editorInkParamsToolbar |
| 12187 | }) { |
| 12188 | const editorModeChanged = (evt, disableButtons = false) => { |
| 12189 | const editorButtons = [{ |
| 12190 | mode: _pdfjsLib.AnnotationEditorType.FREETEXT, |
| 12191 | button: editorFreeTextButton, |
| 12192 | toolbar: editorFreeTextParamsToolbar |
| 12193 | }, { |
| 12194 | mode: _pdfjsLib.AnnotationEditorType.INK, |
| 12195 | button: editorInkButton, |
| 12196 | toolbar: editorInkParamsToolbar |
| 12197 | }]; |
| 12198 | for (const { |
| 12199 | mode, |
| 12200 | button, |
| 12201 | toolbar |
| 12202 | } of editorButtons) { |
| 12203 | const checked = mode === evt.mode; |
| 12204 | button.classList.toggle("toggled", checked); |
| 12205 | button.setAttribute("aria-checked", checked); |
| 12206 | button.disabled = disableButtons; |
| 12207 | toolbar?.classList.toggle("hidden", !checked); |
| 12208 | } |
| 12209 | }; |
| 12210 | this.eventBus._on("annotationeditormodechanged", editorModeChanged); |
| 12211 | this.eventBus._on("toolbarreset", evt => { |
| 12212 | if (evt.source === this) { |
| 12213 | editorModeChanged({ |
| 12214 | mode: _pdfjsLib.AnnotationEditorType.NONE |
| 12215 | }, true); |
| 12216 | } |
| 12217 | }); |
| 12218 | } |
| 12219 | #updateUIState(resetNumPages = false) { |
| 12220 | if (!this.#wasLocalized) { |
| 12221 | return; |
| 12222 | } |
| 12223 | const { |
| 12224 | pageNumber, |
| 12225 | pagesCount, |
| 12226 | pageScaleValue, |
| 12227 | pageScale, |
| 12228 | items |
| 12229 | } = this; |
| 12230 | if (resetNumPages) { |
| 12231 | if (this.hasPageLabels) { |
| 12232 | items.pageNumber.type = "text"; |
| 12233 | } else { |
| 12234 | items.pageNumber.type = "number"; |
| 12235 | this.l10n.get("of_pages", { |
| 12236 | pagesCount |
| 12237 | }).then(msg => { |
| 12238 | items.numPages.textContent = msg; |
| 12239 | }); |
| 12240 | } |
| 12241 | items.pageNumber.max = pagesCount; |
| 12242 | } |
| 12243 | if (this.hasPageLabels) { |
| 12244 | items.pageNumber.value = this.pageLabel; |
| 12245 | this.l10n.get("page_of_pages", { |
| 12246 | pageNumber, |
| 12247 | pagesCount |
| 12248 | }).then(msg => { |
| 12249 | items.numPages.textContent = msg; |
| 12250 | }); |
| 12251 | } else { |
| 12252 | items.pageNumber.value = pageNumber; |
| 12253 | } |
| 12254 | items.previous.disabled = pageNumber <= 1; |
| 12255 | items.next.disabled = pageNumber >= pagesCount; |
| 12256 | items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE; |
| 12257 | items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE; |
| 12258 | this.l10n.get("page_scale_percent", { |
| 12259 | scale: Math.round(pageScale * 10000) / 100 |
| 12260 | }).then(msg => { |
| 12261 | let predefinedValueFound = false; |
| 12262 | for (const option of items.scaleSelect.options) { |
| 12263 | if (option.value !== pageScaleValue) { |
| 12264 | option.selected = false; |
| 12265 | continue; |
| 12266 | } |
| 12267 | option.selected = true; |
| 12268 | predefinedValueFound = true; |
| 12269 | } |
| 12270 | if (!predefinedValueFound) { |
| 12271 | items.customScaleOption.textContent = msg; |
| 12272 | items.customScaleOption.selected = true; |
| 12273 | } |
| 12274 | }); |
| 12275 | } |
| 12276 | updateLoadingIndicatorState(loading = false) { |
| 12277 | const { |
| 12278 | pageNumber |
| 12279 | } = this.items; |
| 12280 | pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading); |
| 12281 | } |
| 12282 | async #adjustScaleWidth() { |
| 12283 | const { |
| 12284 | items, |
| 12285 | l10n |
| 12286 | } = this; |
| 12287 | const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]); |
| 12288 | await _ui_utils.animationStarted; |
| 12289 | const style = getComputedStyle(items.scaleSelect); |
| 12290 | const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width")); |
| 12291 | const canvas = document.createElement("canvas"); |
| 12292 | const ctx = canvas.getContext("2d", { |
| 12293 | alpha: false |
| 12294 | }); |
| 12295 | ctx.font = `${style.fontSize} ${style.fontFamily}`; |
| 12296 | let maxWidth = 0; |
| 12297 | for (const predefinedValue of await predefinedValuesPromise) { |
| 12298 | const { |
| 12299 | width |
| 12300 | } = ctx.measureText(predefinedValue); |
| 12301 | if (width > maxWidth) { |
| 12302 | maxWidth = width; |
| 12303 | } |
| 12304 | } |
| 12305 | maxWidth += 0.3 * scaleSelectWidth; |
| 12306 | if (maxWidth > scaleSelectWidth) { |
| 12307 | _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`); |
| 12308 | } |
| 12309 | canvas.width = 0; |
| 12310 | canvas.height = 0; |
| 12311 | } |
| 12312 | } |
| 12313 | exports.Toolbar = Toolbar; |
| 12314 | |
| 12315 | /***/ }), |
| 12316 | /* 40 */ |
| 12317 | /***/ ((__unused_webpack_module, exports) => { |
| 12318 | |
| 12319 | |
| 12320 | |
| 12321 | Object.defineProperty(exports, "__esModule", ({ |
| 12322 | value: true |
| 12323 | })); |
| 12324 | exports.ViewHistory = void 0; |
| 12325 | const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20; |
| 12326 | class ViewHistory { |
| 12327 | constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) { |
| 12328 | this.fingerprint = fingerprint; |
| 12329 | this.cacheSize = cacheSize; |
| 12330 | this._initializedPromise = this._readFromStorage().then(databaseStr => { |
| 12331 | const database = JSON.parse(databaseStr || "{}"); |
| 12332 | let index = -1; |
| 12333 | if (!Array.isArray(database.files)) { |
| 12334 | database.files = []; |
| 12335 | } else { |
| 12336 | while (database.files.length >= this.cacheSize) { |
| 12337 | database.files.shift(); |
| 12338 | } |
| 12339 | for (let i = 0, ii = database.files.length; i < ii; i++) { |
| 12340 | const branch = database.files[i]; |
| 12341 | if (branch.fingerprint === this.fingerprint) { |
| 12342 | index = i; |
| 12343 | break; |
| 12344 | } |
| 12345 | } |
| 12346 | } |
| 12347 | if (index === -1) { |
| 12348 | index = database.files.push({ |
| 12349 | fingerprint: this.fingerprint |
| 12350 | }) - 1; |
| 12351 | } |
| 12352 | this.file = database.files[index]; |
| 12353 | this.database = database; |
| 12354 | }); |
| 12355 | } |
| 12356 | async _writeToStorage() { |
| 12357 | const databaseStr = JSON.stringify(this.database); |
| 12358 | localStorage.setItem("pdfjs.history", databaseStr); |
| 12359 | } |
| 12360 | async _readFromStorage() { |
| 12361 | return localStorage.getItem("pdfjs.history"); |
| 12362 | } |
| 12363 | async set(name, val) { |
| 12364 | await this._initializedPromise; |
| 12365 | this.file[name] = val; |
| 12366 | return this._writeToStorage(); |
| 12367 | } |
| 12368 | async setMultiple(properties) { |
| 12369 | await this._initializedPromise; |
| 12370 | for (const name in properties) { |
| 12371 | this.file[name] = properties[name]; |
| 12372 | } |
| 12373 | return this._writeToStorage(); |
| 12374 | } |
| 12375 | async get(name, defaultValue) { |
| 12376 | await this._initializedPromise; |
| 12377 | const val = this.file[name]; |
| 12378 | return val !== undefined ? val : defaultValue; |
| 12379 | } |
| 12380 | async getMultiple(properties) { |
| 12381 | await this._initializedPromise; |
| 12382 | const values = Object.create(null); |
| 12383 | for (const name in properties) { |
| 12384 | const val = this.file[name]; |
| 12385 | values[name] = val !== undefined ? val : properties[name]; |
| 12386 | } |
| 12387 | return values; |
| 12388 | } |
| 12389 | } |
| 12390 | exports.ViewHistory = ViewHistory; |
| 12391 | |
| 12392 | /***/ }), |
| 12393 | /* 41 */ |
| 12394 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 12395 | |
| 12396 | |
| 12397 | |
| 12398 | Object.defineProperty(exports, "__esModule", ({ |
| 12399 | value: true |
| 12400 | })); |
| 12401 | exports.GenericCom = void 0; |
| 12402 | var _app = __webpack_require__(4); |
| 12403 | var _preferences = __webpack_require__(42); |
| 12404 | var _download_manager = __webpack_require__(43); |
| 12405 | var _genericl10n = __webpack_require__(44); |
| 12406 | var _generic_scripting = __webpack_require__(46); |
| 12407 | ; |
| 12408 | const GenericCom = {}; |
| 12409 | exports.GenericCom = GenericCom; |
| 12410 | class GenericPreferences extends _preferences.BasePreferences { |
| 12411 | async _writeToStorage(prefObj) { |
| 12412 | localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj)); |
| 12413 | } |
| 12414 | async _readFromStorage(prefObj) { |
| 12415 | return JSON.parse(localStorage.getItem("pdfjs.preferences")); |
| 12416 | } |
| 12417 | } |
| 12418 | class GenericExternalServices extends _app.DefaultExternalServices { |
| 12419 | static createDownloadManager() { |
| 12420 | return new _download_manager.DownloadManager(); |
| 12421 | } |
| 12422 | static createPreferences() { |
| 12423 | return new GenericPreferences(); |
| 12424 | } |
| 12425 | static createL10n({ |
| 12426 | locale = "en-US" |
| 12427 | }) { |
| 12428 | return new _genericl10n.GenericL10n(locale); |
| 12429 | } |
| 12430 | static createScripting({ |
| 12431 | sandboxBundleSrc |
| 12432 | }) { |
| 12433 | return new _generic_scripting.GenericScripting(sandboxBundleSrc); |
| 12434 | } |
| 12435 | } |
| 12436 | _app.PDFViewerApplication.externalServices = GenericExternalServices; |
| 12437 | |
| 12438 | /***/ }), |
| 12439 | /* 42 */ |
| 12440 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 12441 | |
| 12442 | |
| 12443 | |
| 12444 | Object.defineProperty(exports, "__esModule", ({ |
| 12445 | value: true |
| 12446 | })); |
| 12447 | exports.BasePreferences = void 0; |
| 12448 | var _app_options = __webpack_require__(2); |
| 12449 | class BasePreferences { |
| 12450 | #defaults = Object.freeze({ |
| 12451 | "annotationEditorMode": 0, |
| 12452 | "annotationMode": 2, |
| 12453 | "cursorToolOnLoad": 0, |
| 12454 | "defaultZoomDelay": 400, |
| 12455 | "defaultZoomValue": "", |
| 12456 | "disablePageLabels": false, |
| 12457 | "enablePermissions": false, |
| 12458 | "enablePrintAutoRotate": true, |
| 12459 | "enableScripting": true, |
| 12460 | "externalLinkTarget": 0, |
| 12461 | "historyUpdateUrl": false, |
| 12462 | "ignoreDestinationZoom": false, |
| 12463 | "forcePageColors": false, |
| 12464 | "pageColorsBackground": "Canvas", |
| 12465 | "pageColorsForeground": "CanvasText", |
| 12466 | "pdfBugEnabled": false, |
| 12467 | "sidebarViewOnLoad": -1, |
| 12468 | "scrollModeOnLoad": -1, |
| 12469 | "spreadModeOnLoad": -1, |
| 12470 | "textLayerMode": 1, |
| 12471 | "useOnlyCssZoom": false, |
| 12472 | "viewerCssTheme": 0, |
| 12473 | "viewOnLoad": 0, |
| 12474 | "disableAutoFetch": false, |
| 12475 | "disableFontFace": false, |
| 12476 | "disableRange": false, |
| 12477 | "disableStream": false, |
| 12478 | "enableXfa": true, |
| 12479 | "renderer": "canvas" |
| 12480 | }); |
| 12481 | #prefs = Object.create(null); |
| 12482 | #initializedPromise = null; |
| 12483 | constructor() { |
| 12484 | if (this.constructor === BasePreferences) { |
| 12485 | throw new Error("Cannot initialize BasePreferences."); |
| 12486 | } |
| 12487 | this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => { |
| 12488 | for (const name in this.#defaults) { |
| 12489 | const prefValue = prefs?.[name]; |
| 12490 | if (typeof prefValue === typeof this.#defaults[name]) { |
| 12491 | this.#prefs[name] = prefValue; |
| 12492 | } |
| 12493 | } |
| 12494 | }); |
| 12495 | } |
| 12496 | async _writeToStorage(prefObj) { |
| 12497 | throw new Error("Not implemented: _writeToStorage"); |
| 12498 | } |
| 12499 | async _readFromStorage(prefObj) { |
| 12500 | throw new Error("Not implemented: _readFromStorage"); |
| 12501 | } |
| 12502 | async reset() { |
| 12503 | await this.#initializedPromise; |
| 12504 | const prefs = this.#prefs; |
| 12505 | this.#prefs = Object.create(null); |
| 12506 | return this._writeToStorage(this.#defaults).catch(reason => { |
| 12507 | this.#prefs = prefs; |
| 12508 | throw reason; |
| 12509 | }); |
| 12510 | } |
| 12511 | async set(name, value) { |
| 12512 | await this.#initializedPromise; |
| 12513 | const defaultValue = this.#defaults[name], |
| 12514 | prefs = this.#prefs; |
| 12515 | if (defaultValue === undefined) { |
| 12516 | throw new Error(`Set preference: "${name}" is undefined.`); |
| 12517 | } else if (value === undefined) { |
| 12518 | throw new Error("Set preference: no value is specified."); |
| 12519 | } |
| 12520 | const valueType = typeof value, |
| 12521 | defaultType = typeof defaultValue; |
| 12522 | if (valueType !== defaultType) { |
| 12523 | if (valueType === "number" && defaultType === "string") { |
| 12524 | value = value.toString(); |
| 12525 | } else { |
| 12526 | throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`); |
| 12527 | } |
| 12528 | } else { |
| 12529 | if (valueType === "number" && !Number.isInteger(value)) { |
| 12530 | throw new Error(`Set preference: "${value}" must be an integer.`); |
| 12531 | } |
| 12532 | } |
| 12533 | this.#prefs[name] = value; |
| 12534 | return this._writeToStorage(this.#prefs).catch(reason => { |
| 12535 | this.#prefs = prefs; |
| 12536 | throw reason; |
| 12537 | }); |
| 12538 | } |
| 12539 | async get(name) { |
| 12540 | await this.#initializedPromise; |
| 12541 | const defaultValue = this.#defaults[name]; |
| 12542 | if (defaultValue === undefined) { |
| 12543 | throw new Error(`Get preference: "${name}" is undefined.`); |
| 12544 | } |
| 12545 | return this.#prefs[name] ?? defaultValue; |
| 12546 | } |
| 12547 | async getAll() { |
| 12548 | await this.#initializedPromise; |
| 12549 | const obj = Object.create(null); |
| 12550 | for (const name in this.#defaults) { |
| 12551 | obj[name] = this.#prefs[name] ?? this.#defaults[name]; |
| 12552 | } |
| 12553 | return obj; |
| 12554 | } |
| 12555 | } |
| 12556 | exports.BasePreferences = BasePreferences; |
| 12557 | |
| 12558 | /***/ }), |
| 12559 | /* 43 */ |
| 12560 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 12561 | |
| 12562 | |
| 12563 | |
| 12564 | Object.defineProperty(exports, "__esModule", ({ |
| 12565 | value: true |
| 12566 | })); |
| 12567 | exports.DownloadManager = void 0; |
| 12568 | var _pdfjsLib = __webpack_require__(5); |
| 12569 | ; |
| 12570 | function download(blobUrl, filename) { |
| 12571 | const a = document.createElement("a"); |
| 12572 | if (!a.click) { |
| 12573 | throw new Error('DownloadManager: "a.click()" is not supported.'); |
| 12574 | } |
| 12575 | a.href = blobUrl; |
| 12576 | a.target = "_parent"; |
| 12577 | if ("download" in a) { |
| 12578 | a.download = filename; |
| 12579 | } |
| 12580 | (document.body || document.documentElement).append(a); |
| 12581 | a.click(); |
| 12582 | a.remove(); |
| 12583 | } |
| 12584 | class DownloadManager { |
| 12585 | #openBlobUrls = new WeakMap(); |
| 12586 | downloadUrl(url, filename) { |
| 12587 | if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) { |
| 12588 | console.error(`downloadUrl - not a valid URL: ${url}`); |
| 12589 | return; |
| 12590 | } |
| 12591 | download(url + "#pdfjs.action=download", filename); |
| 12592 | } |
| 12593 | downloadData(data, filename, contentType) { |
| 12594 | const blobUrl = URL.createObjectURL(new Blob([data], { |
| 12595 | type: contentType |
| 12596 | })); |
| 12597 | download(blobUrl, filename); |
| 12598 | } |
| 12599 | openOrDownloadData(element, data, filename) { |
| 12600 | const isPdfData = (0, _pdfjsLib.isPdfFile)(filename); |
| 12601 | const contentType = isPdfData ? "application/pdf" : ""; |
| 12602 | if (isPdfData) { |
| 12603 | let blobUrl = this.#openBlobUrls.get(element); |
| 12604 | if (!blobUrl) { |
| 12605 | blobUrl = URL.createObjectURL(new Blob([data], { |
| 12606 | type: contentType |
| 12607 | })); |
| 12608 | this.#openBlobUrls.set(element, blobUrl); |
| 12609 | } |
| 12610 | let viewerUrl; |
| 12611 | viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename); |
| 12612 | try { |
| 12613 | window.open(viewerUrl); |
| 12614 | return true; |
| 12615 | } catch (ex) { |
| 12616 | console.error(`openOrDownloadData: ${ex}`); |
| 12617 | URL.revokeObjectURL(blobUrl); |
| 12618 | this.#openBlobUrls.delete(element); |
| 12619 | } |
| 12620 | } |
| 12621 | this.downloadData(data, filename, contentType); |
| 12622 | return false; |
| 12623 | } |
| 12624 | download(blob, url, filename) { |
| 12625 | const blobUrl = URL.createObjectURL(blob); |
| 12626 | download(blobUrl, filename); |
| 12627 | } |
| 12628 | } |
| 12629 | exports.DownloadManager = DownloadManager; |
| 12630 | |
| 12631 | /***/ }), |
| 12632 | /* 44 */ |
| 12633 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 12634 | |
| 12635 | |
| 12636 | |
| 12637 | Object.defineProperty(exports, "__esModule", ({ |
| 12638 | value: true |
| 12639 | })); |
| 12640 | exports.GenericL10n = void 0; |
| 12641 | __webpack_require__(45); |
| 12642 | var _l10n_utils = __webpack_require__(29); |
| 12643 | const webL10n = document.webL10n; |
| 12644 | class GenericL10n { |
| 12645 | constructor(lang) { |
| 12646 | this._lang = lang; |
| 12647 | this._ready = new Promise((resolve, reject) => { |
| 12648 | webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => { |
| 12649 | resolve(webL10n); |
| 12650 | }); |
| 12651 | }); |
| 12652 | } |
| 12653 | async getLanguage() { |
| 12654 | const l10n = await this._ready; |
| 12655 | return l10n.getLanguage(); |
| 12656 | } |
| 12657 | async getDirection() { |
| 12658 | const l10n = await this._ready; |
| 12659 | return l10n.getDirection(); |
| 12660 | } |
| 12661 | async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) { |
| 12662 | const l10n = await this._ready; |
| 12663 | return l10n.get(key, args, fallback); |
| 12664 | } |
| 12665 | async translate(element) { |
| 12666 | const l10n = await this._ready; |
| 12667 | return l10n.translate(element); |
| 12668 | } |
| 12669 | } |
| 12670 | exports.GenericL10n = GenericL10n; |
| 12671 | |
| 12672 | /***/ }), |
| 12673 | /* 45 */ |
| 12674 | /***/ (() => { |
| 12675 | |
| 12676 | |
| 12677 | |
| 12678 | document.webL10n = function (window, document, undefined) { |
| 12679 | var gL10nData = {}; |
| 12680 | var gTextData = ''; |
| 12681 | var gTextProp = 'textContent'; |
| 12682 | var gLanguage = ''; |
| 12683 | var gMacros = {}; |
| 12684 | var gReadyState = 'loading'; |
| 12685 | var gAsyncResourceLoading = true; |
| 12686 | function getL10nResourceLinks() { |
| 12687 | return document.querySelectorAll('link[type="application/l10n"]'); |
| 12688 | } |
| 12689 | function getL10nDictionary() { |
| 12690 | var script = document.querySelector('script[type="application/l10n"]'); |
| 12691 | return script ? JSON.parse(script.innerHTML) : null; |
| 12692 | } |
| 12693 | function getTranslatableChildren(element) { |
| 12694 | return element ? element.querySelectorAll('*[data-l10n-id]') : []; |
| 12695 | } |
| 12696 | function getL10nAttributes(element) { |
| 12697 | if (!element) return {}; |
| 12698 | var l10nId = element.getAttribute('data-l10n-id'); |
| 12699 | var l10nArgs = element.getAttribute('data-l10n-args'); |
| 12700 | var args = {}; |
| 12701 | if (l10nArgs) { |
| 12702 | try { |
| 12703 | args = JSON.parse(l10nArgs); |
| 12704 | } catch (e) { |
| 12705 | console.warn('could not parse arguments for #' + l10nId); |
| 12706 | } |
| 12707 | } |
| 12708 | return { |
| 12709 | id: l10nId, |
| 12710 | args: args |
| 12711 | }; |
| 12712 | } |
| 12713 | function xhrLoadText(url, onSuccess, onFailure) { |
| 12714 | onSuccess = onSuccess || function _onSuccess(data) {}; |
| 12715 | onFailure = onFailure || function _onFailure() {}; |
| 12716 | var xhr = new XMLHttpRequest(); |
| 12717 | xhr.open('GET', url, gAsyncResourceLoading); |
| 12718 | if (xhr.overrideMimeType) { |
| 12719 | xhr.overrideMimeType('text/plain; charset=utf-8'); |
| 12720 | } |
| 12721 | xhr.onreadystatechange = function () { |
| 12722 | if (xhr.readyState == 4) { |
| 12723 | if (xhr.status == 200 || xhr.status === 0) { |
| 12724 | onSuccess(xhr.responseText); |
| 12725 | } else { |
| 12726 | onFailure(); |
| 12727 | } |
| 12728 | } |
| 12729 | }; |
| 12730 | xhr.onerror = onFailure; |
| 12731 | xhr.ontimeout = onFailure; |
| 12732 | try { |
| 12733 | xhr.send(null); |
| 12734 | } catch (e) { |
| 12735 | onFailure(); |
| 12736 | } |
| 12737 | } |
| 12738 | function parseResource(href, lang, successCallback, failureCallback) { |
| 12739 | var baseURL = href.replace(/[^\/]*$/, '') || './'; |
| 12740 | function evalString(text) { |
| 12741 | if (text.lastIndexOf('\\') < 0) return text; |
| 12742 | return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'"); |
| 12743 | } |
| 12744 | function parseProperties(text, parsedPropertiesCallback) { |
| 12745 | var dictionary = {}; |
| 12746 | var reBlank = /^\s*|\s*$/; |
| 12747 | var reComment = /^\s*#|^\s*$/; |
| 12748 | var reSection = /^\s*\[(.*)\]\s*$/; |
| 12749 | var reImport = /^\s*@import\s+url\((.*)\)\s*$/i; |
| 12750 | var reSplit = /^([^=\s]*)\s*=\s*(.+)$/; |
| 12751 | function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) { |
| 12752 | var entries = rawText.replace(reBlank, '').split(/[\r\n]+/); |
| 12753 | var currentLang = '*'; |
| 12754 | var genericLang = lang.split('-', 1)[0]; |
| 12755 | var skipLang = false; |
| 12756 | var match = ''; |
| 12757 | function nextEntry() { |
| 12758 | while (true) { |
| 12759 | if (!entries.length) { |
| 12760 | parsedRawLinesCallback(); |
| 12761 | return; |
| 12762 | } |
| 12763 | var line = entries.shift(); |
| 12764 | if (reComment.test(line)) continue; |
| 12765 | if (extendedSyntax) { |
| 12766 | match = reSection.exec(line); |
| 12767 | if (match) { |
| 12768 | currentLang = match[1].toLowerCase(); |
| 12769 | skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang; |
| 12770 | continue; |
| 12771 | } else if (skipLang) { |
| 12772 | continue; |
| 12773 | } |
| 12774 | match = reImport.exec(line); |
| 12775 | if (match) { |
| 12776 | loadImport(baseURL + match[1], nextEntry); |
| 12777 | return; |
| 12778 | } |
| 12779 | } |
| 12780 | var tmp = line.match(reSplit); |
| 12781 | if (tmp && tmp.length == 3) { |
| 12782 | dictionary[tmp[1]] = evalString(tmp[2]); |
| 12783 | } |
| 12784 | } |
| 12785 | } |
| 12786 | nextEntry(); |
| 12787 | } |
| 12788 | function loadImport(url, callback) { |
| 12789 | xhrLoadText(url, function (content) { |
| 12790 | parseRawLines(content, false, callback); |
| 12791 | }, function () { |
| 12792 | console.warn(url + ' not found.'); |
| 12793 | callback(); |
| 12794 | }); |
| 12795 | } |
| 12796 | parseRawLines(text, true, function () { |
| 12797 | parsedPropertiesCallback(dictionary); |
| 12798 | }); |
| 12799 | } |
| 12800 | xhrLoadText(href, function (response) { |
| 12801 | gTextData += response; |
| 12802 | parseProperties(response, function (data) { |
| 12803 | for (var key in data) { |
| 12804 | var id, |
| 12805 | prop, |
| 12806 | index = key.lastIndexOf('.'); |
| 12807 | if (index > 0) { |
| 12808 | id = key.substring(0, index); |
| 12809 | prop = key.substring(index + 1); |
| 12810 | } else { |
| 12811 | id = key; |
| 12812 | prop = gTextProp; |
| 12813 | } |
| 12814 | if (!gL10nData[id]) { |
| 12815 | gL10nData[id] = {}; |
| 12816 | } |
| 12817 | gL10nData[id][prop] = data[key]; |
| 12818 | } |
| 12819 | if (successCallback) { |
| 12820 | successCallback(); |
| 12821 | } |
| 12822 | }); |
| 12823 | }, failureCallback); |
| 12824 | } |
| 12825 | function loadLocale(lang, callback) { |
| 12826 | if (lang) { |
| 12827 | lang = lang.toLowerCase(); |
| 12828 | } |
| 12829 | callback = callback || function _callback() {}; |
| 12830 | clear(); |
| 12831 | gLanguage = lang; |
| 12832 | var langLinks = getL10nResourceLinks(); |
| 12833 | var langCount = langLinks.length; |
| 12834 | if (langCount === 0) { |
| 12835 | var dict = getL10nDictionary(); |
| 12836 | if (dict && dict.locales && dict.default_locale) { |
| 12837 | console.log('using the embedded JSON directory, early way out'); |
| 12838 | gL10nData = dict.locales[lang]; |
| 12839 | if (!gL10nData) { |
| 12840 | var defaultLocale = dict.default_locale.toLowerCase(); |
| 12841 | for (var anyCaseLang in dict.locales) { |
| 12842 | anyCaseLang = anyCaseLang.toLowerCase(); |
| 12843 | if (anyCaseLang === lang) { |
| 12844 | gL10nData = dict.locales[lang]; |
| 12845 | break; |
| 12846 | } else if (anyCaseLang === defaultLocale) { |
| 12847 | gL10nData = dict.locales[defaultLocale]; |
| 12848 | } |
| 12849 | } |
| 12850 | } |
| 12851 | callback(); |
| 12852 | } else { |
| 12853 | console.log('no resource to load, early way out'); |
| 12854 | } |
| 12855 | gReadyState = 'complete'; |
| 12856 | return; |
| 12857 | } |
| 12858 | var onResourceLoaded = null; |
| 12859 | var gResourceCount = 0; |
| 12860 | onResourceLoaded = function () { |
| 12861 | gResourceCount++; |
| 12862 | if (gResourceCount >= langCount) { |
| 12863 | callback(); |
| 12864 | gReadyState = 'complete'; |
| 12865 | } |
| 12866 | }; |
| 12867 | function L10nResourceLink(link) { |
| 12868 | var href = link.href; |
| 12869 | this.load = function (lang, callback) { |
| 12870 | parseResource(href, lang, callback, function () { |
| 12871 | console.warn(href + ' not found.'); |
| 12872 | console.warn('"' + lang + '" resource not found'); |
| 12873 | gLanguage = ''; |
| 12874 | callback(); |
| 12875 | }); |
| 12876 | }; |
| 12877 | } |
| 12878 | for (var i = 0; i < langCount; i++) { |
| 12879 | var resource = new L10nResourceLink(langLinks[i]); |
| 12880 | resource.load(lang, onResourceLoaded); |
| 12881 | } |
| 12882 | } |
| 12883 | function clear() { |
| 12884 | gL10nData = {}; |
| 12885 | gTextData = ''; |
| 12886 | gLanguage = ''; |
| 12887 | } |
| 12888 | function getPluralRules(lang) { |
| 12889 | var locales2rules = { |
| 12890 | 'af': 3, |
| 12891 | 'ak': 4, |
| 12892 | 'am': 4, |
| 12893 | 'ar': 1, |
| 12894 | 'asa': 3, |
| 12895 | 'az': 0, |
| 12896 | 'be': 11, |
| 12897 | 'bem': 3, |
| 12898 | 'bez': 3, |
| 12899 | 'bg': 3, |
| 12900 | 'bh': 4, |
| 12901 | 'bm': 0, |
| 12902 | 'bn': 3, |
| 12903 | 'bo': 0, |
| 12904 | 'br': 20, |
| 12905 | 'brx': 3, |
| 12906 | 'bs': 11, |
| 12907 | 'ca': 3, |
| 12908 | 'cgg': 3, |
| 12909 | 'chr': 3, |
| 12910 | 'cs': 12, |
| 12911 | 'cy': 17, |
| 12912 | 'da': 3, |
| 12913 | 'de': 3, |
| 12914 | 'dv': 3, |
| 12915 | 'dz': 0, |
| 12916 | 'ee': 3, |
| 12917 | 'el': 3, |
| 12918 | 'en': 3, |
| 12919 | 'eo': 3, |
| 12920 | 'es': 3, |
| 12921 | 'et': 3, |
| 12922 | 'eu': 3, |
| 12923 | 'fa': 0, |
| 12924 | 'ff': 5, |
| 12925 | 'fi': 3, |
| 12926 | 'fil': 4, |
| 12927 | 'fo': 3, |
| 12928 | 'fr': 5, |
| 12929 | 'fur': 3, |
| 12930 | 'fy': 3, |
| 12931 | 'ga': 8, |
| 12932 | 'gd': 24, |
| 12933 | 'gl': 3, |
| 12934 | 'gsw': 3, |
| 12935 | 'gu': 3, |
| 12936 | 'guw': 4, |
| 12937 | 'gv': 23, |
| 12938 | 'ha': 3, |
| 12939 | 'haw': 3, |
| 12940 | 'he': 2, |
| 12941 | 'hi': 4, |
| 12942 | 'hr': 11, |
| 12943 | 'hu': 0, |
| 12944 | 'id': 0, |
| 12945 | 'ig': 0, |
| 12946 | 'ii': 0, |
| 12947 | 'is': 3, |
| 12948 | 'it': 3, |
| 12949 | 'iu': 7, |
| 12950 | 'ja': 0, |
| 12951 | 'jmc': 3, |
| 12952 | 'jv': 0, |
| 12953 | 'ka': 0, |
| 12954 | 'kab': 5, |
| 12955 | 'kaj': 3, |
| 12956 | 'kcg': 3, |
| 12957 | 'kde': 0, |
| 12958 | 'kea': 0, |
| 12959 | 'kk': 3, |
| 12960 | 'kl': 3, |
| 12961 | 'km': 0, |
| 12962 | 'kn': 0, |
| 12963 | 'ko': 0, |
| 12964 | 'ksb': 3, |
| 12965 | 'ksh': 21, |
| 12966 | 'ku': 3, |
| 12967 | 'kw': 7, |
| 12968 | 'lag': 18, |
| 12969 | 'lb': 3, |
| 12970 | 'lg': 3, |
| 12971 | 'ln': 4, |
| 12972 | 'lo': 0, |
| 12973 | 'lt': 10, |
| 12974 | 'lv': 6, |
| 12975 | 'mas': 3, |
| 12976 | 'mg': 4, |
| 12977 | 'mk': 16, |
| 12978 | 'ml': 3, |
| 12979 | 'mn': 3, |
| 12980 | 'mo': 9, |
| 12981 | 'mr': 3, |
| 12982 | 'ms': 0, |
| 12983 | 'mt': 15, |
| 12984 | 'my': 0, |
| 12985 | 'nah': 3, |
| 12986 | 'naq': 7, |
| 12987 | 'nb': 3, |
| 12988 | 'nd': 3, |
| 12989 | 'ne': 3, |
| 12990 | 'nl': 3, |
| 12991 | 'nn': 3, |
| 12992 | 'no': 3, |
| 12993 | 'nr': 3, |
| 12994 | 'nso': 4, |
| 12995 | 'ny': 3, |
| 12996 | 'nyn': 3, |
| 12997 | 'om': 3, |
| 12998 | 'or': 3, |
| 12999 | 'pa': 3, |
| 13000 | 'pap': 3, |
| 13001 | 'pl': 13, |
| 13002 | 'ps': 3, |
| 13003 | 'pt': 3, |
| 13004 | 'rm': 3, |
| 13005 | 'ro': 9, |
| 13006 | 'rof': 3, |
| 13007 | 'ru': 11, |
| 13008 | 'rwk': 3, |
| 13009 | 'sah': 0, |
| 13010 | 'saq': 3, |
| 13011 | 'se': 7, |
| 13012 | 'seh': 3, |
| 13013 | 'ses': 0, |
| 13014 | 'sg': 0, |
| 13015 | 'sh': 11, |
| 13016 | 'shi': 19, |
| 13017 | 'sk': 12, |
| 13018 | 'sl': 14, |
| 13019 | 'sma': 7, |
| 13020 | 'smi': 7, |
| 13021 | 'smj': 7, |
| 13022 | 'smn': 7, |
| 13023 | 'sms': 7, |
| 13024 | 'sn': 3, |
| 13025 | 'so': 3, |
| 13026 | 'sq': 3, |
| 13027 | 'sr': 11, |
| 13028 | 'ss': 3, |
| 13029 | 'ssy': 3, |
| 13030 | 'st': 3, |
| 13031 | 'sv': 3, |
| 13032 | 'sw': 3, |
| 13033 | 'syr': 3, |
| 13034 | 'ta': 3, |
| 13035 | 'te': 3, |
| 13036 | 'teo': 3, |
| 13037 | 'th': 0, |
| 13038 | 'ti': 4, |
| 13039 | 'tig': 3, |
| 13040 | 'tk': 3, |
| 13041 | 'tl': 4, |
| 13042 | 'tn': 3, |
| 13043 | 'to': 0, |
| 13044 | 'tr': 0, |
| 13045 | 'ts': 3, |
| 13046 | 'tzm': 22, |
| 13047 | 'uk': 11, |
| 13048 | 'ur': 3, |
| 13049 | 've': 3, |
| 13050 | 'vi': 0, |
| 13051 | 'vun': 3, |
| 13052 | 'wa': 4, |
| 13053 | 'wae': 3, |
| 13054 | 'wo': 0, |
| 13055 | 'xh': 3, |
| 13056 | 'xog': 3, |
| 13057 | 'yo': 0, |
| 13058 | 'zh': 0, |
| 13059 | 'zu': 3 |
| 13060 | }; |
| 13061 | function isIn(n, list) { |
| 13062 | return list.indexOf(n) !== -1; |
| 13063 | } |
| 13064 | function isBetween(n, start, end) { |
| 13065 | return start <= n && n <= end; |
| 13066 | } |
| 13067 | var pluralRules = { |
| 13068 | '0': function (n) { |
| 13069 | return 'other'; |
| 13070 | }, |
| 13071 | '1': function (n) { |
| 13072 | if (isBetween(n % 100, 3, 10)) return 'few'; |
| 13073 | if (n === 0) return 'zero'; |
| 13074 | if (isBetween(n % 100, 11, 99)) return 'many'; |
| 13075 | if (n == 2) return 'two'; |
| 13076 | if (n == 1) return 'one'; |
| 13077 | return 'other'; |
| 13078 | }, |
| 13079 | '2': function (n) { |
| 13080 | if (n !== 0 && n % 10 === 0) return 'many'; |
| 13081 | if (n == 2) return 'two'; |
| 13082 | if (n == 1) return 'one'; |
| 13083 | return 'other'; |
| 13084 | }, |
| 13085 | '3': function (n) { |
| 13086 | if (n == 1) return 'one'; |
| 13087 | return 'other'; |
| 13088 | }, |
| 13089 | '4': function (n) { |
| 13090 | if (isBetween(n, 0, 1)) return 'one'; |
| 13091 | return 'other'; |
| 13092 | }, |
| 13093 | '5': function (n) { |
| 13094 | if (isBetween(n, 0, 2) && n != 2) return 'one'; |
| 13095 | return 'other'; |
| 13096 | }, |
| 13097 | '6': function (n) { |
| 13098 | if (n === 0) return 'zero'; |
| 13099 | if (n % 10 == 1 && n % 100 != 11) return 'one'; |
| 13100 | return 'other'; |
| 13101 | }, |
| 13102 | '7': function (n) { |
| 13103 | if (n == 2) return 'two'; |
| 13104 | if (n == 1) return 'one'; |
| 13105 | return 'other'; |
| 13106 | }, |
| 13107 | '8': function (n) { |
| 13108 | if (isBetween(n, 3, 6)) return 'few'; |
| 13109 | if (isBetween(n, 7, 10)) return 'many'; |
| 13110 | if (n == 2) return 'two'; |
| 13111 | if (n == 1) return 'one'; |
| 13112 | return 'other'; |
| 13113 | }, |
| 13114 | '9': function (n) { |
| 13115 | if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few'; |
| 13116 | if (n == 1) return 'one'; |
| 13117 | return 'other'; |
| 13118 | }, |
| 13119 | '10': function (n) { |
| 13120 | if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few'; |
| 13121 | if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one'; |
| 13122 | return 'other'; |
| 13123 | }, |
| 13124 | '11': function (n) { |
| 13125 | if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few'; |
| 13126 | if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many'; |
| 13127 | if (n % 10 == 1 && n % 100 != 11) return 'one'; |
| 13128 | return 'other'; |
| 13129 | }, |
| 13130 | '12': function (n) { |
| 13131 | if (isBetween(n, 2, 4)) return 'few'; |
| 13132 | if (n == 1) return 'one'; |
| 13133 | return 'other'; |
| 13134 | }, |
| 13135 | '13': function (n) { |
| 13136 | if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few'; |
| 13137 | if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many'; |
| 13138 | if (n == 1) return 'one'; |
| 13139 | return 'other'; |
| 13140 | }, |
| 13141 | '14': function (n) { |
| 13142 | if (isBetween(n % 100, 3, 4)) return 'few'; |
| 13143 | if (n % 100 == 2) return 'two'; |
| 13144 | if (n % 100 == 1) return 'one'; |
| 13145 | return 'other'; |
| 13146 | }, |
| 13147 | '15': function (n) { |
| 13148 | if (n === 0 || isBetween(n % 100, 2, 10)) return 'few'; |
| 13149 | if (isBetween(n % 100, 11, 19)) return 'many'; |
| 13150 | if (n == 1) return 'one'; |
| 13151 | return 'other'; |
| 13152 | }, |
| 13153 | '16': function (n) { |
| 13154 | if (n % 10 == 1 && n != 11) return 'one'; |
| 13155 | return 'other'; |
| 13156 | }, |
| 13157 | '17': function (n) { |
| 13158 | if (n == 3) return 'few'; |
| 13159 | if (n === 0) return 'zero'; |
| 13160 | if (n == 6) return 'many'; |
| 13161 | if (n == 2) return 'two'; |
| 13162 | if (n == 1) return 'one'; |
| 13163 | return 'other'; |
| 13164 | }, |
| 13165 | '18': function (n) { |
| 13166 | if (n === 0) return 'zero'; |
| 13167 | if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one'; |
| 13168 | return 'other'; |
| 13169 | }, |
| 13170 | '19': function (n) { |
| 13171 | if (isBetween(n, 2, 10)) return 'few'; |
| 13172 | if (isBetween(n, 0, 1)) return 'one'; |
| 13173 | return 'other'; |
| 13174 | }, |
| 13175 | '20': function (n) { |
| 13176 | if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few'; |
| 13177 | if (n % 1000000 === 0 && n !== 0) return 'many'; |
| 13178 | if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two'; |
| 13179 | if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one'; |
| 13180 | return 'other'; |
| 13181 | }, |
| 13182 | '21': function (n) { |
| 13183 | if (n === 0) return 'zero'; |
| 13184 | if (n == 1) return 'one'; |
| 13185 | return 'other'; |
| 13186 | }, |
| 13187 | '22': function (n) { |
| 13188 | if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one'; |
| 13189 | return 'other'; |
| 13190 | }, |
| 13191 | '23': function (n) { |
| 13192 | if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one'; |
| 13193 | return 'other'; |
| 13194 | }, |
| 13195 | '24': function (n) { |
| 13196 | if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few'; |
| 13197 | if (isIn(n, [2, 12])) return 'two'; |
| 13198 | if (isIn(n, [1, 11])) return 'one'; |
| 13199 | return 'other'; |
| 13200 | } |
| 13201 | }; |
| 13202 | var index = locales2rules[lang.replace(/-.*$/, '')]; |
| 13203 | if (!(index in pluralRules)) { |
| 13204 | console.warn('plural form unknown for [' + lang + ']'); |
| 13205 | return function () { |
| 13206 | return 'other'; |
| 13207 | }; |
| 13208 | } |
| 13209 | return pluralRules[index]; |
| 13210 | } |
| 13211 | gMacros.plural = function (str, param, key, prop) { |
| 13212 | var n = parseFloat(param); |
| 13213 | if (isNaN(n)) return str; |
| 13214 | if (prop != gTextProp) return str; |
| 13215 | if (!gMacros._pluralRules) { |
| 13216 | gMacros._pluralRules = getPluralRules(gLanguage); |
| 13217 | } |
| 13218 | var index = '[' + gMacros._pluralRules(n) + ']'; |
| 13219 | if (n === 0 && key + '[zero]' in gL10nData) { |
| 13220 | str = gL10nData[key + '[zero]'][prop]; |
| 13221 | } else if (n == 1 && key + '[one]' in gL10nData) { |
| 13222 | str = gL10nData[key + '[one]'][prop]; |
| 13223 | } else if (n == 2 && key + '[two]' in gL10nData) { |
| 13224 | str = gL10nData[key + '[two]'][prop]; |
| 13225 | } else if (key + index in gL10nData) { |
| 13226 | str = gL10nData[key + index][prop]; |
| 13227 | } else if (key + '[other]' in gL10nData) { |
| 13228 | str = gL10nData[key + '[other]'][prop]; |
| 13229 | } |
| 13230 | return str; |
| 13231 | }; |
| 13232 | function getL10nData(key, args, fallback) { |
| 13233 | var data = gL10nData[key]; |
| 13234 | if (!data) { |
| 13235 | console.warn('#' + key + ' is undefined.'); |
| 13236 | if (!fallback) { |
| 13237 | return null; |
| 13238 | } |
| 13239 | data = fallback; |
| 13240 | } |
| 13241 | var rv = {}; |
| 13242 | for (var prop in data) { |
| 13243 | var str = data[prop]; |
| 13244 | str = substIndexes(str, args, key, prop); |
| 13245 | str = substArguments(str, args, key); |
| 13246 | rv[prop] = str; |
| 13247 | } |
| 13248 | return rv; |
| 13249 | } |
| 13250 | function substIndexes(str, args, key, prop) { |
| 13251 | var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/; |
| 13252 | var reMatch = reIndex.exec(str); |
| 13253 | if (!reMatch || !reMatch.length) return str; |
| 13254 | var macroName = reMatch[1]; |
| 13255 | var paramName = reMatch[2]; |
| 13256 | var param; |
| 13257 | if (args && paramName in args) { |
| 13258 | param = args[paramName]; |
| 13259 | } else if (paramName in gL10nData) { |
| 13260 | param = gL10nData[paramName]; |
| 13261 | } |
| 13262 | if (macroName in gMacros) { |
| 13263 | var macro = gMacros[macroName]; |
| 13264 | str = macro(str, param, key, prop); |
| 13265 | } |
| 13266 | return str; |
| 13267 | } |
| 13268 | function substArguments(str, args, key) { |
| 13269 | var reArgs = /\{\{\s*(.+?)\s*\}\}/g; |
| 13270 | return str.replace(reArgs, function (matched_text, arg) { |
| 13271 | if (args && arg in args) { |
| 13272 | return args[arg]; |
| 13273 | } |
| 13274 | if (arg in gL10nData) { |
| 13275 | return gL10nData[arg]; |
| 13276 | } |
| 13277 | console.log('argument {{' + arg + '}} for #' + key + ' is undefined.'); |
| 13278 | return matched_text; |
| 13279 | }); |
| 13280 | } |
| 13281 | function translateElement(element) { |
| 13282 | var l10n = getL10nAttributes(element); |
| 13283 | if (!l10n.id) return; |
| 13284 | var data = getL10nData(l10n.id, l10n.args); |
| 13285 | if (!data) { |
| 13286 | console.warn('#' + l10n.id + ' is undefined.'); |
| 13287 | return; |
| 13288 | } |
| 13289 | if (data[gTextProp]) { |
| 13290 | if (getChildElementCount(element) === 0) { |
| 13291 | element[gTextProp] = data[gTextProp]; |
| 13292 | } else { |
| 13293 | var children = element.childNodes; |
| 13294 | var found = false; |
| 13295 | for (var i = 0, l = children.length; i < l; i++) { |
| 13296 | if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) { |
| 13297 | if (found) { |
| 13298 | children[i].nodeValue = ''; |
| 13299 | } else { |
| 13300 | children[i].nodeValue = data[gTextProp]; |
| 13301 | found = true; |
| 13302 | } |
| 13303 | } |
| 13304 | } |
| 13305 | if (!found) { |
| 13306 | var textNode = document.createTextNode(data[gTextProp]); |
| 13307 | element.prepend(textNode); |
| 13308 | } |
| 13309 | } |
| 13310 | delete data[gTextProp]; |
| 13311 | } |
| 13312 | for (var k in data) { |
| 13313 | element[k] = data[k]; |
| 13314 | } |
| 13315 | } |
| 13316 | function getChildElementCount(element) { |
| 13317 | if (element.children) { |
| 13318 | return element.children.length; |
| 13319 | } |
| 13320 | if (typeof element.childElementCount !== 'undefined') { |
| 13321 | return element.childElementCount; |
| 13322 | } |
| 13323 | var count = 0; |
| 13324 | for (var i = 0; i < element.childNodes.length; i++) { |
| 13325 | count += element.nodeType === 1 ? 1 : 0; |
| 13326 | } |
| 13327 | return count; |
| 13328 | } |
| 13329 | function translateFragment(element) { |
| 13330 | element = element || document.documentElement; |
| 13331 | var children = getTranslatableChildren(element); |
| 13332 | var elementCount = children.length; |
| 13333 | for (var i = 0; i < elementCount; i++) { |
| 13334 | translateElement(children[i]); |
| 13335 | } |
| 13336 | translateElement(element); |
| 13337 | } |
| 13338 | return { |
| 13339 | get: function (key, args, fallbackString) { |
| 13340 | var index = key.lastIndexOf('.'); |
| 13341 | var prop = gTextProp; |
| 13342 | if (index > 0) { |
| 13343 | prop = key.substring(index + 1); |
| 13344 | key = key.substring(0, index); |
| 13345 | } |
| 13346 | var fallback; |
| 13347 | if (fallbackString) { |
| 13348 | fallback = {}; |
| 13349 | fallback[prop] = fallbackString; |
| 13350 | } |
| 13351 | var data = getL10nData(key, args, fallback); |
| 13352 | if (data && prop in data) { |
| 13353 | return data[prop]; |
| 13354 | } |
| 13355 | return '{{' + key + '}}'; |
| 13356 | }, |
| 13357 | getData: function () { |
| 13358 | return gL10nData; |
| 13359 | }, |
| 13360 | getText: function () { |
| 13361 | return gTextData; |
| 13362 | }, |
| 13363 | getLanguage: function () { |
| 13364 | return gLanguage; |
| 13365 | }, |
| 13366 | setLanguage: function (lang, callback) { |
| 13367 | loadLocale(lang, function () { |
| 13368 | if (callback) callback(); |
| 13369 | }); |
| 13370 | }, |
| 13371 | getDirection: function () { |
| 13372 | var rtlList = ['ar', 'he', 'fa', 'ps', 'ur']; |
| 13373 | var shortCode = gLanguage.split('-', 1)[0]; |
| 13374 | return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr'; |
| 13375 | }, |
| 13376 | translate: translateFragment, |
| 13377 | getReadyState: function () { |
| 13378 | return gReadyState; |
| 13379 | }, |
| 13380 | ready: function (callback) { |
| 13381 | if (!callback) { |
| 13382 | return; |
| 13383 | } else if (gReadyState == 'complete' || gReadyState == 'interactive') { |
| 13384 | window.setTimeout(function () { |
| 13385 | callback(); |
| 13386 | }); |
| 13387 | } else if (document.addEventListener) { |
| 13388 | document.addEventListener('localized', function once() { |
| 13389 | document.removeEventListener('localized', once); |
| 13390 | callback(); |
| 13391 | }); |
| 13392 | } |
| 13393 | } |
| 13394 | }; |
| 13395 | }(window, document); |
| 13396 | |
| 13397 | /***/ }), |
| 13398 | /* 46 */ |
| 13399 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 13400 | |
| 13401 | |
| 13402 | |
| 13403 | Object.defineProperty(exports, "__esModule", ({ |
| 13404 | value: true |
| 13405 | })); |
| 13406 | exports.GenericScripting = void 0; |
| 13407 | exports.docPropertiesLookup = docPropertiesLookup; |
| 13408 | var _pdfjsLib = __webpack_require__(5); |
| 13409 | async function docPropertiesLookup(pdfDocument) { |
| 13410 | const url = "", |
| 13411 | baseUrl = url.split("#")[0]; |
| 13412 | let { |
| 13413 | info, |
| 13414 | metadata, |
| 13415 | contentDispositionFilename, |
| 13416 | contentLength |
| 13417 | } = await pdfDocument.getMetadata(); |
| 13418 | if (!contentLength) { |
| 13419 | const { |
| 13420 | length |
| 13421 | } = await pdfDocument.getDownloadInfo(); |
| 13422 | contentLength = length; |
| 13423 | } |
| 13424 | return { |
| 13425 | ...info, |
| 13426 | baseURL: baseUrl, |
| 13427 | filesize: contentLength, |
| 13428 | filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url), |
| 13429 | metadata: metadata?.getRaw(), |
| 13430 | authors: metadata?.get("dc:creator"), |
| 13431 | numPages: pdfDocument.numPages, |
| 13432 | URL: url |
| 13433 | }; |
| 13434 | } |
| 13435 | class GenericScripting { |
| 13436 | constructor(sandboxBundleSrc) { |
| 13437 | this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => { |
| 13438 | return window.pdfjsSandbox.QuickJSSandbox(); |
| 13439 | }); |
| 13440 | } |
| 13441 | async createSandbox(data) { |
| 13442 | const sandbox = await this._ready; |
| 13443 | sandbox.create(data); |
| 13444 | } |
| 13445 | async dispatchEventInSandbox(event) { |
| 13446 | const sandbox = await this._ready; |
| 13447 | setTimeout(() => sandbox.dispatchEvent(event), 0); |
| 13448 | } |
| 13449 | async destroySandbox() { |
| 13450 | const sandbox = await this._ready; |
| 13451 | sandbox.nukeSandbox(); |
| 13452 | } |
| 13453 | } |
| 13454 | exports.GenericScripting = GenericScripting; |
| 13455 | |
| 13456 | /***/ }), |
| 13457 | /* 47 */ |
| 13458 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 13459 | |
| 13460 | |
| 13461 | |
| 13462 | Object.defineProperty(exports, "__esModule", ({ |
| 13463 | value: true |
| 13464 | })); |
| 13465 | exports.PDFPrintService = PDFPrintService; |
| 13466 | var _pdfjsLib = __webpack_require__(5); |
| 13467 | var _app = __webpack_require__(4); |
| 13468 | var _print_utils = __webpack_require__(48); |
| 13469 | let activeService = null; |
| 13470 | let dialog = null; |
| 13471 | let overlayManager = null; |
| 13472 | function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) { |
| 13473 | const scratchCanvas = activeService.scratchCanvas; |
| 13474 | const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF; |
| 13475 | scratchCanvas.width = Math.floor(size.width * PRINT_UNITS); |
| 13476 | scratchCanvas.height = Math.floor(size.height * PRINT_UNITS); |
| 13477 | const ctx = scratchCanvas.getContext("2d"); |
| 13478 | ctx.save(); |
| 13479 | ctx.fillStyle = "rgb(255, 255, 255)"; |
| 13480 | ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height); |
| 13481 | ctx.restore(); |
| 13482 | return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) { |
| 13483 | const renderContext = { |
| 13484 | canvasContext: ctx, |
| 13485 | transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0], |
| 13486 | viewport: pdfPage.getViewport({ |
| 13487 | scale: 1, |
| 13488 | rotation: size.rotation |
| 13489 | }), |
| 13490 | intent: "print", |
| 13491 | annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE, |
| 13492 | optionalContentConfigPromise, |
| 13493 | printAnnotationStorage |
| 13494 | }; |
| 13495 | return pdfPage.render(renderContext).promise; |
| 13496 | }); |
| 13497 | } |
| 13498 | function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) { |
| 13499 | this.pdfDocument = pdfDocument; |
| 13500 | this.pagesOverview = pagesOverview; |
| 13501 | this.printContainer = printContainer; |
| 13502 | this._printResolution = printResolution || 150; |
| 13503 | this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig(); |
| 13504 | this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve(); |
| 13505 | this.l10n = l10n; |
| 13506 | this.currentPage = -1; |
| 13507 | this.scratchCanvas = document.createElement("canvas"); |
| 13508 | } |
| 13509 | PDFPrintService.prototype = { |
| 13510 | layout() { |
| 13511 | this.throwIfInactive(); |
| 13512 | const body = document.querySelector("body"); |
| 13513 | body.setAttribute("data-pdfjsprinting", true); |
| 13514 | const hasEqualPageSizes = this.pagesOverview.every(function (size) { |
| 13515 | return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height; |
| 13516 | }, this); |
| 13517 | if (!hasEqualPageSizes) { |
| 13518 | console.warn("Not all pages have the same size. The printed " + "result may be incorrect!"); |
| 13519 | } |
| 13520 | this.pageStyleSheet = document.createElement("style"); |
| 13521 | const pageSize = this.pagesOverview[0]; |
| 13522 | this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}"; |
| 13523 | body.append(this.pageStyleSheet); |
| 13524 | }, |
| 13525 | destroy() { |
| 13526 | if (activeService !== this) { |
| 13527 | return; |
| 13528 | } |
| 13529 | this.printContainer.textContent = ""; |
| 13530 | const body = document.querySelector("body"); |
| 13531 | body.removeAttribute("data-pdfjsprinting"); |
| 13532 | if (this.pageStyleSheet) { |
| 13533 | this.pageStyleSheet.remove(); |
| 13534 | this.pageStyleSheet = null; |
| 13535 | } |
| 13536 | this.scratchCanvas.width = this.scratchCanvas.height = 0; |
| 13537 | this.scratchCanvas = null; |
| 13538 | activeService = null; |
| 13539 | ensureOverlay().then(function () { |
| 13540 | if (overlayManager.active === dialog) { |
| 13541 | overlayManager.close(dialog); |
| 13542 | } |
| 13543 | }); |
| 13544 | }, |
| 13545 | renderPages() { |
| 13546 | if (this.pdfDocument.isPureXfa) { |
| 13547 | (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument); |
| 13548 | return Promise.resolve(); |
| 13549 | } |
| 13550 | const pageCount = this.pagesOverview.length; |
| 13551 | const renderNextPage = (resolve, reject) => { |
| 13552 | this.throwIfInactive(); |
| 13553 | if (++this.currentPage >= pageCount) { |
| 13554 | renderProgress(pageCount, pageCount, this.l10n); |
| 13555 | resolve(); |
| 13556 | return; |
| 13557 | } |
| 13558 | const index = this.currentPage; |
| 13559 | renderProgress(index, pageCount, this.l10n); |
| 13560 | renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () { |
| 13561 | renderNextPage(resolve, reject); |
| 13562 | }, reject); |
| 13563 | }; |
| 13564 | return new Promise(renderNextPage); |
| 13565 | }, |
| 13566 | useRenderedPage() { |
| 13567 | this.throwIfInactive(); |
| 13568 | const img = document.createElement("img"); |
| 13569 | const scratchCanvas = this.scratchCanvas; |
| 13570 | if ("toBlob" in scratchCanvas) { |
| 13571 | scratchCanvas.toBlob(function (blob) { |
| 13572 | img.src = URL.createObjectURL(blob); |
| 13573 | }); |
| 13574 | } else { |
| 13575 | img.src = scratchCanvas.toDataURL(); |
| 13576 | } |
| 13577 | const wrapper = document.createElement("div"); |
| 13578 | wrapper.className = "printedPage"; |
| 13579 | wrapper.append(img); |
| 13580 | this.printContainer.append(wrapper); |
| 13581 | return new Promise(function (resolve, reject) { |
| 13582 | img.onload = resolve; |
| 13583 | img.onerror = reject; |
| 13584 | }); |
| 13585 | }, |
| 13586 | performPrint() { |
| 13587 | |
| 13588 | if (location.hash) { |
| 13589 | let hash = location.hash; |
| 13590 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 13591 | |
| 13592 | if(hashParams.get('key') !== null) { |
| 13593 | hashParams = '#' + atob(hashParams.get('key')); |
| 13594 | hashParams = new URLSearchParams(hashParams.substring(1)); |
| 13595 | } |
| 13596 | const element = document.querySelector('#download'); |
| 13597 | if((hashParams.get('download') === 'false' || hashParams.get('download') === '') || element.offsetParent === null){ |
| 13598 | return false; |
| 13599 | } |
| 13600 | } // added by EP developer |
| 13601 | |
| 13602 | this.throwIfInactive(); |
| 13603 | return new Promise(resolve => { |
| 13604 | setTimeout(() => { |
| 13605 | if (!this.active) { |
| 13606 | resolve(); |
| 13607 | return; |
| 13608 | } |
| 13609 | print.call(window); |
| 13610 | setTimeout(resolve, 20); |
| 13611 | }, 0); |
| 13612 | }); |
| 13613 | }, |
| 13614 | get active() { |
| 13615 | return this === activeService; |
| 13616 | }, |
| 13617 | throwIfInactive() { |
| 13618 | if (!this.active) { |
| 13619 | throw new Error("This print request was cancelled or completed."); |
| 13620 | } |
| 13621 | } |
| 13622 | }; |
| 13623 | const print = window.print; |
| 13624 | window.print = function () { |
| 13625 | if (activeService) { |
| 13626 | console.warn("Ignored window.print() because of a pending print job."); |
| 13627 | return; |
| 13628 | } |
| 13629 | ensureOverlay().then(function () { |
| 13630 | if (activeService) { |
| 13631 | overlayManager.open(dialog); |
| 13632 | } |
| 13633 | }); |
| 13634 | try { |
| 13635 | dispatchEvent("beforeprint"); |
| 13636 | } finally { |
| 13637 | if (!activeService) { |
| 13638 | console.error("Expected print service to be initialized."); |
| 13639 | ensureOverlay().then(function () { |
| 13640 | if (overlayManager.active === dialog) { |
| 13641 | overlayManager.close(dialog); |
| 13642 | } |
| 13643 | }); |
| 13644 | return; |
| 13645 | } |
| 13646 | const activeServiceOnEntry = activeService; |
| 13647 | activeService.renderPages().then(function () { |
| 13648 | return activeServiceOnEntry.performPrint(); |
| 13649 | }).catch(function () {}).then(function () { |
| 13650 | if (activeServiceOnEntry.active) { |
| 13651 | abort(); |
| 13652 | } |
| 13653 | }); |
| 13654 | } |
| 13655 | }; |
| 13656 | function dispatchEvent(eventType) { |
| 13657 | const event = document.createEvent("CustomEvent"); |
| 13658 | event.initCustomEvent(eventType, false, false, "custom"); |
| 13659 | window.dispatchEvent(event); |
| 13660 | } |
| 13661 | function abort() { |
| 13662 | if (activeService) { |
| 13663 | activeService.destroy(); |
| 13664 | dispatchEvent("afterprint"); |
| 13665 | } |
| 13666 | } |
| 13667 | function renderProgress(index, total, l10n) { |
| 13668 | dialog ||= document.getElementById("printServiceDialog"); |
| 13669 | const progress = Math.round(100 * index / total); |
| 13670 | const progressBar = dialog.querySelector("progress"); |
| 13671 | const progressPerc = dialog.querySelector(".relative-progress"); |
| 13672 | progressBar.value = progress; |
| 13673 | l10n.get("print_progress_percent", { |
| 13674 | progress |
| 13675 | }).then(msg => { |
| 13676 | progressPerc.textContent = msg; |
| 13677 | }); |
| 13678 | } |
| 13679 | window.addEventListener("keydown", function (event) { |
| 13680 | if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) { |
| 13681 | window.print(); |
| 13682 | event.preventDefault(); |
| 13683 | event.stopImmediatePropagation(); |
| 13684 | } |
| 13685 | }, true); |
| 13686 | if ("onbeforeprint" in window) { |
| 13687 | const stopPropagationIfNeeded = function (event) { |
| 13688 | if (event.detail !== "custom") { |
| 13689 | event.stopImmediatePropagation(); |
| 13690 | } |
| 13691 | }; |
| 13692 | window.addEventListener("beforeprint", stopPropagationIfNeeded); |
| 13693 | window.addEventListener("afterprint", stopPropagationIfNeeded); |
| 13694 | } |
| 13695 | let overlayPromise; |
| 13696 | function ensureOverlay() { |
| 13697 | if (!overlayPromise) { |
| 13698 | overlayManager = _app.PDFViewerApplication.overlayManager; |
| 13699 | if (!overlayManager) { |
| 13700 | throw new Error("The overlay manager has not yet been initialized."); |
| 13701 | } |
| 13702 | dialog ||= document.getElementById("printServiceDialog"); |
| 13703 | overlayPromise = overlayManager.register(dialog, true); |
| 13704 | document.getElementById("printCancel").onclick = abort; |
| 13705 | dialog.addEventListener("close", abort); |
| 13706 | } |
| 13707 | return overlayPromise; |
| 13708 | } |
| 13709 | _app.PDFPrintServiceFactory.instance = { |
| 13710 | supportsPrinting: true, |
| 13711 | createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) { |
| 13712 | if (activeService) { |
| 13713 | throw new Error("The print service is created and active."); |
| 13714 | } |
| 13715 | activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n); |
| 13716 | return activeService; |
| 13717 | } |
| 13718 | }; |
| 13719 | |
| 13720 | /***/ }), |
| 13721 | /* 48 */ |
| 13722 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 13723 | |
| 13724 | |
| 13725 | |
| 13726 | Object.defineProperty(exports, "__esModule", ({ |
| 13727 | value: true |
| 13728 | })); |
| 13729 | exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting; |
| 13730 | var _pdfjsLib = __webpack_require__(5); |
| 13731 | var _pdf_link_service = __webpack_require__(3); |
| 13732 | var _xfa_layer_builder = __webpack_require__(37); |
| 13733 | function getXfaHtmlForPrinting(printContainer, pdfDocument) { |
| 13734 | const xfaHtml = pdfDocument.allXfaHtml; |
| 13735 | const linkService = new _pdf_link_service.SimpleLinkService(); |
| 13736 | const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100; |
| 13737 | for (const xfaPage of xfaHtml.children) { |
| 13738 | const page = document.createElement("div"); |
| 13739 | page.className = "xfaPrintedPage"; |
| 13740 | printContainer.append(page); |
| 13741 | const builder = new _xfa_layer_builder.XfaLayerBuilder({ |
| 13742 | pageDiv: page, |
| 13743 | pdfPage: null, |
| 13744 | annotationStorage: pdfDocument.annotationStorage, |
| 13745 | linkService, |
| 13746 | xfaHtml: xfaPage |
| 13747 | }); |
| 13748 | const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, { |
| 13749 | scale |
| 13750 | }); |
| 13751 | builder.render(viewport, "print"); |
| 13752 | } |
| 13753 | } |
| 13754 | |
| 13755 | /***/ }) |
| 13756 | /******/ ]); |
| 13757 | /************************************************************************/ |
| 13758 | /******/ // The module cache |
| 13759 | /******/ var __webpack_module_cache__ = {}; |
| 13760 | /******/ |
| 13761 | /******/ // The require function |
| 13762 | /******/ function __webpack_require__(moduleId) { |
| 13763 | /******/ // Check if module is in cache |
| 13764 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 13765 | /******/ if (cachedModule !== undefined) { |
| 13766 | /******/ return cachedModule.exports; |
| 13767 | /******/ } |
| 13768 | /******/ // Create a new module (and put it into the cache) |
| 13769 | /******/ var module = __webpack_module_cache__[moduleId] = { |
| 13770 | /******/ // no module.id needed |
| 13771 | /******/ // no module.loaded needed |
| 13772 | /******/ exports: {} |
| 13773 | /******/ }; |
| 13774 | /******/ |
| 13775 | /******/ // Execute the module function |
| 13776 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 13777 | /******/ |
| 13778 | /******/ // Return the exports of the module |
| 13779 | /******/ return module.exports; |
| 13780 | /******/ } |
| 13781 | /******/ |
| 13782 | /************************************************************************/ |
| 13783 | var __webpack_exports__ = {}; |
| 13784 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
| 13785 | (() => { |
| 13786 | var exports = __webpack_exports__; |
| 13787 | |
| 13788 | |
| 13789 | Object.defineProperty(exports, "__esModule", ({ |
| 13790 | value: true |
| 13791 | })); |
| 13792 | Object.defineProperty(exports, "PDFViewerApplication", ({ |
| 13793 | enumerable: true, |
| 13794 | get: function () { |
| 13795 | return _app.PDFViewerApplication; |
| 13796 | } |
| 13797 | })); |
| 13798 | exports.PDFViewerApplicationConstants = void 0; |
| 13799 | Object.defineProperty(exports, "PDFViewerApplicationOptions", ({ |
| 13800 | enumerable: true, |
| 13801 | get: function () { |
| 13802 | return _app_options.AppOptions; |
| 13803 | } |
| 13804 | })); |
| 13805 | var _ui_utils = __webpack_require__(1); |
| 13806 | var _app_options = __webpack_require__(2); |
| 13807 | var _pdf_link_service = __webpack_require__(3); |
| 13808 | var _app = __webpack_require__(4); |
| 13809 | const pdfjsVersion = '3.3.122'; |
| 13810 | const pdfjsBuild = '562045607'; |
| 13811 | const AppConstants = { |
| 13812 | LinkTarget: _pdf_link_service.LinkTarget, |
| 13813 | RenderingStates: _ui_utils.RenderingStates, |
| 13814 | ScrollMode: _ui_utils.ScrollMode, |
| 13815 | SpreadMode: _ui_utils.SpreadMode |
| 13816 | }; |
| 13817 | exports.PDFViewerApplicationConstants = AppConstants; |
| 13818 | window.PDFViewerApplication = _app.PDFViewerApplication; |
| 13819 | window.PDFViewerApplicationConstants = AppConstants; |
| 13820 | window.PDFViewerApplicationOptions = _app_options.AppOptions; |
| 13821 | ; |
| 13822 | ; |
| 13823 | { |
| 13824 | __webpack_require__(41); |
| 13825 | } |
| 13826 | ; |
| 13827 | { |
| 13828 | __webpack_require__(47); |
| 13829 | } |
| 13830 | function getViewerConfiguration() { |
| 13831 | return { |
| 13832 | appContainer: document.body, |
| 13833 | mainContainer: document.getElementById("viewerContainer"), |
| 13834 | viewerContainer: document.getElementById("viewer"), |
| 13835 | toolbar: { |
| 13836 | container: document.getElementById("toolbarViewer"), |
| 13837 | numPages: document.getElementById("numPages"), |
| 13838 | pageNumber: document.getElementById("pageNumber"), |
| 13839 | scaleSelect: document.getElementById("scaleSelect"), |
| 13840 | customScaleOption: document.getElementById("customScaleOption"), |
| 13841 | previous: document.getElementById("previous"), |
| 13842 | next: document.getElementById("next"), |
| 13843 | zoomIn: document.getElementById("zoomIn"), |
| 13844 | zoomOut: document.getElementById("zoomOut"), |
| 13845 | viewFind: document.getElementById("viewFind"), |
| 13846 | openFile: document.getElementById("openFile"), |
| 13847 | print: document.getElementById("print"), |
| 13848 | editorFreeTextButton: document.getElementById("editorFreeText"), |
| 13849 | editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"), |
| 13850 | editorInkButton: document.getElementById("editorInk"), |
| 13851 | editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"), |
| 13852 | download: document.getElementById("download") |
| 13853 | }, |
| 13854 | secondaryToolbar: { |
| 13855 | toolbar: document.getElementById("secondaryToolbar"), |
| 13856 | toggleButton: document.getElementById("secondaryToolbarToggle"), |
| 13857 | presentationModeButton: document.getElementById("presentationMode"), |
| 13858 | openFileButton: document.getElementById("secondaryOpenFile"), |
| 13859 | printButton: document.getElementById("secondaryPrint"), |
| 13860 | downloadButton: document.getElementById("secondaryDownload"), |
| 13861 | viewBookmarkButton: document.getElementById("viewBookmark"), |
| 13862 | firstPageButton: document.getElementById("firstPage"), |
| 13863 | lastPageButton: document.getElementById("lastPage"), |
| 13864 | pageRotateCwButton: document.getElementById("pageRotateCw"), |
| 13865 | pageRotateCcwButton: document.getElementById("pageRotateCcw"), |
| 13866 | cursorSelectToolButton: document.getElementById("cursorSelectTool"), |
| 13867 | cursorHandToolButton: document.getElementById("cursorHandTool"), |
| 13868 | scrollPageButton: document.getElementById("scrollPage"), |
| 13869 | scrollVerticalButton: document.getElementById("scrollVertical"), |
| 13870 | scrollHorizontalButton: document.getElementById("scrollHorizontal"), |
| 13871 | scrollWrappedButton: document.getElementById("scrollWrapped"), |
| 13872 | spreadNoneButton: document.getElementById("spreadNone"), |
| 13873 | spreadOddButton: document.getElementById("spreadOdd"), |
| 13874 | spreadEvenButton: document.getElementById("spreadEven"), |
| 13875 | documentPropertiesButton: document.getElementById("documentProperties") |
| 13876 | }, |
| 13877 | sidebar: { |
| 13878 | outerContainer: document.getElementById("outerContainer"), |
| 13879 | sidebarContainer: document.getElementById("sidebarContainer"), |
| 13880 | toggleButton: document.getElementById("sidebarToggle"), |
| 13881 | thumbnailButton: document.getElementById("viewThumbnail"), |
| 13882 | outlineButton: document.getElementById("viewOutline"), |
| 13883 | attachmentsButton: document.getElementById("viewAttachments"), |
| 13884 | layersButton: document.getElementById("viewLayers"), |
| 13885 | thumbnailView: document.getElementById("thumbnailView"), |
| 13886 | outlineView: document.getElementById("outlineView"), |
| 13887 | attachmentsView: document.getElementById("attachmentsView"), |
| 13888 | layersView: document.getElementById("layersView"), |
| 13889 | outlineOptionsContainer: document.getElementById("outlineOptionsContainer"), |
| 13890 | currentOutlineItemButton: document.getElementById("currentOutlineItem") |
| 13891 | }, |
| 13892 | sidebarResizer: { |
| 13893 | outerContainer: document.getElementById("outerContainer"), |
| 13894 | resizer: document.getElementById("sidebarResizer") |
| 13895 | }, |
| 13896 | findBar: { |
| 13897 | bar: document.getElementById("findbar"), |
| 13898 | toggleButton: document.getElementById("viewFind"), |
| 13899 | findField: document.getElementById("findInput"), |
| 13900 | highlightAllCheckbox: document.getElementById("findHighlightAll"), |
| 13901 | caseSensitiveCheckbox: document.getElementById("findMatchCase"), |
| 13902 | matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"), |
| 13903 | entireWordCheckbox: document.getElementById("findEntireWord"), |
| 13904 | findMsg: document.getElementById("findMsg"), |
| 13905 | findResultsCount: document.getElementById("findResultsCount"), |
| 13906 | findPreviousButton: document.getElementById("findPrevious"), |
| 13907 | findNextButton: document.getElementById("findNext") |
| 13908 | }, |
| 13909 | passwordOverlay: { |
| 13910 | dialog: document.getElementById("passwordDialog"), |
| 13911 | label: document.getElementById("passwordText"), |
| 13912 | input: document.getElementById("password"), |
| 13913 | submitButton: document.getElementById("passwordSubmit"), |
| 13914 | cancelButton: document.getElementById("passwordCancel") |
| 13915 | }, |
| 13916 | documentProperties: { |
| 13917 | dialog: document.getElementById("documentPropertiesDialog"), |
| 13918 | closeButton: document.getElementById("documentPropertiesClose"), |
| 13919 | fields: { |
| 13920 | fileName: document.getElementById("fileNameField"), |
| 13921 | fileSize: document.getElementById("fileSizeField"), |
| 13922 | title: document.getElementById("titleField"), |
| 13923 | author: document.getElementById("authorField"), |
| 13924 | subject: document.getElementById("subjectField"), |
| 13925 | keywords: document.getElementById("keywordsField"), |
| 13926 | creationDate: document.getElementById("creationDateField"), |
| 13927 | modificationDate: document.getElementById("modificationDateField"), |
| 13928 | creator: document.getElementById("creatorField"), |
| 13929 | producer: document.getElementById("producerField"), |
| 13930 | version: document.getElementById("versionField"), |
| 13931 | pageCount: document.getElementById("pageCountField"), |
| 13932 | pageSize: document.getElementById("pageSizeField"), |
| 13933 | linearized: document.getElementById("linearizedField") |
| 13934 | } |
| 13935 | }, |
| 13936 | annotationEditorParams: { |
| 13937 | editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"), |
| 13938 | editorFreeTextColor: document.getElementById("editorFreeTextColor"), |
| 13939 | editorInkColor: document.getElementById("editorInkColor"), |
| 13940 | editorInkThickness: document.getElementById("editorInkThickness"), |
| 13941 | editorInkOpacity: document.getElementById("editorInkOpacity") |
| 13942 | }, |
| 13943 | printContainer: document.getElementById("printContainer"), |
| 13944 | openFileInput: document.getElementById("fileInput"), |
| 13945 | debuggerScriptPath: "./debugger.js" |
| 13946 | }; |
| 13947 | } |
| 13948 | function webViewerLoad() { |
| 13949 | const config = getViewerConfiguration(); |
| 13950 | const event = document.createEvent("CustomEvent"); |
| 13951 | event.initCustomEvent("webviewerloaded", true, true, { |
| 13952 | source: window |
| 13953 | }); |
| 13954 | try { |
| 13955 | parent.document.dispatchEvent(event); |
| 13956 | } catch (ex) { |
| 13957 | console.error(`webviewerloaded: ${ex}`); |
| 13958 | document.dispatchEvent(event); |
| 13959 | } |
| 13960 | _app.PDFViewerApplication.run(config); |
| 13961 | } |
| 13962 | document.blockUnblockOnload?.(true); |
| 13963 | if (document.readyState === "interactive" || document.readyState === "complete") { |
| 13964 | webViewerLoad(); |
| 13965 | } else { |
| 13966 | document.addEventListener("DOMContentLoaded", webViewerLoad, true); |
| 13967 | } |
| 13968 | })(); |
| 13969 | |
| 13970 | /******/ })() |
| 13971 | ; |
| 13972 | //# sourceMappingURL=viewer.js.map |