UNPKG

react-pdf-highlighter

Version:
1,479 lines 273 kB
var __defProp = Object.defineProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); var __privateWrapper = (obj, member, setter, getter) => ({ set _(value) { __privateSet(obj, member, value, setter); }, get _() { return __privateGet(obj, member, getter); } }); var _classList, _disableAutoFetchTimeout, _percent, _style, _visible, _state, _updateMatchesCountOnProgress, _visitedPagesCount, _PDFFindController_instances, onFind_fn, reset_fn, query_get, shouldDirtyMatch_fn, isEntireWord_fn, calculateRegExpMatch_fn, convertToRegExpString_fn, calculateMatch_fn, extractText_fn, updatePage_fn, updateAllPages_fn, nextMatch_fn, matchesReady_fn, nextPageMatch_fn, advanceOffsetPage_fn, updateMatch_fn, onFindBarClose_fn, requestMatchesCount_fn, updateUIResultsCount_fn, updateUIState_fn, _PDFLinkService_static, isValidExplicitDest_fn, _onAppend, _eventAbortController, _AnnotationLayerBuilder_instances, updatePresentationModeState_fn, _openBlobUrls, _listeners, _dir, _elements, _lang, _l10n, _L10n_static, fixupLangCode_fn, isRTL_fn, _genericl10n_GenericL10n_static, generateBundles_fn, createBundle_fn, getPaths_fn, generateBundlesFallback_fn, createBundleFallback_fn, _eventAbortController2, _PDFHistory_instances, pushOrReplaceState_fn, tryPushCurrentPosition_fn, isValidPage_fn, isValidState_fn, updateInternalState_fn, parseCurrentHash_fn, updateViewarea_fn, popState_fn, pageHide_fn, bindEvents_fn, unbindEvents_fn, _annotationLayer, _drawLayer, _onAppend2, _textLayer, _uiManager, _drawLayer2, _treeDom, _StructTreeLayerBuilder_instances, setAttributes_fn, walk_fn, _enabled, _textChildren, _textNodes, _waitingElements, _TextAccessibilityManager_static, compareElementPositions_fn, _TextAccessibilityManager_instances, addIdToAriaOwns_fn, _eventAbortController3, _enablePermissions, _onAppend3, _renderingDone, _textLayer2, _textLayers, _selectionChangeAbortController, _TextLayerBuilder_instances, bindMouse_fn, _TextLayerBuilder_static, removeGlobalSelectionListener_fn, enableGlobalSelectionListener_fn, _annotationMode, _enableHWA, _hasRestrictedScaling, _layerProperties, _loadingId, _previousRotation, _renderError, _renderingState, _textLayerMode, _useThumbnailCanvas, _viewportMap, _layers, _PDFPageView_instances, addLayer_fn, setDimensions_fn, dispatchLayerRendered_fn, renderAnnotationLayer_fn, renderAnnotationEditorLayer_fn, renderDrawLayer_fn, renderXfaLayer_fn, renderTextLayer_fn, renderStructTreeLayer_fn, buildXfaTextContentItems_fn, finishRenderTask_fn, _closeCapability, _destroyCapability, _docProperties, _eventAbortController4, _eventBus, _externalServices, _pdfDocument, _pdfViewer, _ready, _scripting, _willPrintCapability, _PDFScriptingManager_instances, updateFromSandbox_fn, dispatchPageOpen_fn, dispatchPageClose_fn, initScripting_fn, destroyScripting_fn, _buf, _size, _PDFPageViewBuffer_instances, destroyFirstView_fn, _buffer, _altTextManager, _annotationEditorHighlightColors, _annotationEditorMode, _annotationEditorUIManager, _annotationMode2, _containerTopLeft, _enableHWA2, _enableHighlightFloatingButton, _enablePermissions2, _eventAbortController5, _mlManager, _getAllTextInProgress, _hiddenCopyElement, _interruptCopyCondition, _previousContainerHeight, _resizeObserver, _scrollModePageState, _scaleTimeoutId, _textLayerMode2, _PDFViewer_instances, initializePermissions_fn, onePageRenderedOrForceFetch_fn, copyCallback_fn, ensurePageViewVisible_fn, scrollIntoView_fn, isSameScale_fn, setScaleUpdatePages_fn, pageWidthScaleFactor_get, setScale_fn, resetCurrentPageView_fn, ensurePdfPageLoaded_fn, getScrollAhead_fn, updateContainerHeightCss_fn, resizeObserverCallback_fn; var __webpack_require__ = {}; (() => { __webpack_require__.d = (exports, definition) => { for (var key in definition) { if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); } } }; })(); (() => { __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); })(); var __webpack_exports__ = globalThis.pdfjsViewer = {}; __webpack_require__.d(__webpack_exports__, { AnnotationLayerBuilder: () => ( /* reexport */ AnnotationLayerBuilder ), DownloadManager: () => ( /* reexport */ DownloadManager ), EventBus: () => ( /* reexport */ EventBus ), FindState: () => ( /* reexport */ FindState ), GenericL10n: () => ( /* reexport */ genericl10n_GenericL10n ), LinkTarget: () => ( /* reexport */ LinkTarget ), PDFFindController: () => ( /* reexport */ PDFFindController ), PDFHistory: () => ( /* reexport */ PDFHistory ), PDFLinkService: () => ( /* reexport */ PDFLinkService ), PDFPageView: () => ( /* reexport */ PDFPageView ), PDFScriptingManager: () => ( /* reexport */ PDFScriptingManagerComponents ), PDFSinglePageViewer: () => ( /* reexport */ PDFSinglePageViewer ), PDFViewer: () => ( /* reexport */ PDFViewer ), ProgressBar: () => ( /* reexport */ ProgressBar ), RenderingStates: () => ( /* reexport */ RenderingStates ), ScrollMode: () => ( /* reexport */ ScrollMode ), SimpleLinkService: () => ( /* reexport */ SimpleLinkService ), SpreadMode: () => ( /* reexport */ SpreadMode ), StructTreeLayerBuilder: () => ( /* reexport */ StructTreeLayerBuilder ), TextLayerBuilder: () => ( /* reexport */ TextLayerBuilder ), XfaLayerBuilder: () => ( /* reexport */ XfaLayerBuilder ), parseQueryString: () => ( /* reexport */ parseQueryString ) }); const DEFAULT_SCALE_VALUE = "auto"; const DEFAULT_SCALE = 1; const DEFAULT_SCALE_DELTA = 1.1; const MIN_SCALE = 0.1; const MAX_SCALE = 10; const UNKNOWN_SCALE = 0; const MAX_AUTO_SCALE = 1.25; const SCROLLBAR_PADDING = 40; const VERTICAL_PADDING = 5; const RenderingStates = { INITIAL: 0, RUNNING: 1, PAUSED: 2, FINISHED: 3 }; const PresentationModeState = { UNKNOWN: 0, NORMAL: 1, CHANGING: 2, FULLSCREEN: 3 }; const TextLayerMode = { DISABLE: 0, ENABLE: 1, ENABLE_PERMISSIONS: 2 }; const ScrollMode = { UNKNOWN: -1, VERTICAL: 0, HORIZONTAL: 1, WRAPPED: 2, PAGE: 3 }; const SpreadMode = { UNKNOWN: -1, NONE: 0, ODD: 1, EVEN: 2 }; class OutputScale { constructor() { const pixelRatio = window.devicePixelRatio || 1; this.sx = pixelRatio; this.sy = pixelRatio; } get scaled() { return this.sx !== 1 || this.sy !== 1; } } function scrollIntoView(element, spot, scrollMatches = false) { let parent = element.offsetParent; if (!parent) { console.error("offsetParent is not set -- cannot scroll"); return; } let offsetY = element.offsetTop + element.clientTop; let offsetX = element.offsetLeft + element.clientLeft; while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) { offsetY += parent.offsetTop; offsetX += parent.offsetLeft; parent = parent.offsetParent; if (!parent) { return; } } if (spot) { if (spot.top !== void 0) { offsetY += spot.top; } if (spot.left !== void 0) { offsetX += spot.left; parent.scrollLeft = offsetX; } } parent.scrollTop = offsetY; } function watchScroll(viewAreaElement, callback, abortSignal = void 0) { const debounceScroll = function(evt) { if (rAF) { return; } rAF = window.requestAnimationFrame(function viewAreaElementScrolled() { rAF = null; const currentX = viewAreaElement.scrollLeft; const lastX = state.lastX; if (currentX !== lastX) { state.right = currentX > lastX; } state.lastX = currentX; const currentY = viewAreaElement.scrollTop; const lastY = state.lastY; if (currentY !== lastY) { state.down = currentY > lastY; } state.lastY = currentY; callback(state); }); }; const state = { right: true, down: true, lastX: viewAreaElement.scrollLeft, lastY: viewAreaElement.scrollTop, _eventHandler: debounceScroll }; let rAF = null; viewAreaElement.addEventListener("scroll", debounceScroll, { useCapture: true, signal: abortSignal }); abortSignal == null ? void 0 : abortSignal.addEventListener("abort", () => window.cancelAnimationFrame(rAF), { once: true }); return state; } function parseQueryString(query) { const params = /* @__PURE__ */ new Map(); for (const [key, value] of new URLSearchParams(query)) { params.set(key.toLowerCase(), value); } return params; } const InvisibleCharsRegExp = /[\x00-\x1F]/g; function removeNullCharacters(str, replaceInvisible = false) { if (!InvisibleCharsRegExp.test(str)) { return str; } if (replaceInvisible) { return str.replaceAll(InvisibleCharsRegExp, (m) => m === "\0" ? "" : " "); } return str.replaceAll("\0", ""); } function binarySearchFirstItem(items, condition, start = 0) { let minIndex = start; let maxIndex = items.length - 1; if (maxIndex < 0 || !condition(items[maxIndex])) { return items.length; } if (condition(items[minIndex])) { return minIndex; } while (minIndex < maxIndex) { const currentIndex = minIndex + maxIndex >> 1; const currentItem = items[currentIndex]; if (condition(currentItem)) { maxIndex = currentIndex; } else { minIndex = currentIndex + 1; } } return minIndex; } function approximateFraction(x) { if (Math.floor(x) === x) { return [x, 1]; } const xinv = 1 / x; const limit = 8; if (xinv > limit) { return [1, limit]; } else if (Math.floor(xinv) === xinv) { return [1, xinv]; } const x_ = x > 1 ? xinv : x; let a = 0, b = 1, c = 1, d = 1; while (true) { const p = a + c, q = b + d; if (q > limit) { break; } if (x_ <= p / q) { c = p; d = q; } else { a = p; b = q; } } let result; if (x_ - a / b < c / d - x_) { result = x_ === x ? [a, b] : [b, a]; } else { result = x_ === x ? [c, d] : [d, c]; } return result; } function floorToDivide(x, div) { return x - x % div; } function backtrackBeforeAllVisibleElements(index, views, top) { if (index < 2) { return index; } let elt = views[index].div; let pageTop = elt.offsetTop + elt.clientTop; if (pageTop >= top) { elt = views[index - 1].div; pageTop = elt.offsetTop + elt.clientTop; } for (let i = index - 2; i >= 0; --i) { elt = views[i].div; if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) { break; } index = i; } return index; } function getVisibleElements({ scrollEl, views, sortByVisibility = false, horizontal = false, rtl = false }) { const top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight; const left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth; function isElementBottomAfterViewTop(view) { const element = view.div; const elementBottom = element.offsetTop + element.clientTop + element.clientHeight; return elementBottom > top; } function isElementNextAfterViewHorizontally(view) { const element = view.div; const elementLeft = element.offsetLeft + element.clientLeft; const elementRight = elementLeft + element.clientWidth; return rtl ? elementLeft < right : elementRight > left; } const visible = [], ids = /* @__PURE__ */ new Set(), numViews = views.length; let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop); if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) { firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top); } let lastEdge = horizontal ? right : -1; for (let i = firstVisibleElementInd; i < numViews; i++) { const view = views[i], element = view.div; const currentWidth = element.offsetLeft + element.clientLeft; const currentHeight = element.offsetTop + element.clientTop; const viewWidth = element.clientWidth, viewHeight = element.clientHeight; const viewRight = currentWidth + viewWidth; const viewBottom = currentHeight + viewHeight; if (lastEdge === -1) { if (viewBottom >= bottom) { lastEdge = viewBottom; } } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) { break; } if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) { continue; } const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom); const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right); const fractionHeight = (viewHeight - hiddenHeight) / viewHeight, fractionWidth = (viewWidth - hiddenWidth) / viewWidth; const percent = fractionHeight * fractionWidth * 100 | 0; visible.push({ id: view.id, x: currentWidth, y: currentHeight, view, percent, widthPercent: fractionWidth * 100 | 0 }); ids.add(view.id); } const first = visible[0], last = visible.at(-1); if (sortByVisibility) { visible.sort(function(a, b) { const pc = a.percent - b.percent; if (Math.abs(pc) > 1e-3) { return -pc; } return a.id - b.id; }); } return { first, last, views: visible, ids }; } function isValidRotation(angle) { return Number.isInteger(angle) && angle % 90 === 0; } function isValidScrollMode(mode) { return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN; } function isValidSpreadMode(mode) { return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN; } function isPortraitOrientation(size) { return size.width <= size.height; } new Promise(function(resolve) { window.requestAnimationFrame(resolve); }); const docStyle = document.documentElement.style; function clamp(v, min, max) { return Math.min(Math.max(v, min), max); } class ProgressBar { constructor(bar) { __privateAdd(this, _classList, null); __privateAdd(this, _disableAutoFetchTimeout, null); __privateAdd(this, _percent, 0); __privateAdd(this, _style, null); __privateAdd(this, _visible, true); __privateSet(this, _classList, bar.classList); __privateSet(this, _style, bar.style); } get percent() { return __privateGet(this, _percent); } set percent(val) { __privateSet(this, _percent, clamp(val, 0, 100)); if (isNaN(val)) { __privateGet(this, _classList).add("indeterminate"); return; } __privateGet(this, _classList).remove("indeterminate"); __privateGet(this, _style).setProperty("--progressBar-percent", `${__privateGet(this, _percent)}%`); } setWidth(viewer) { if (!viewer) { return; } const container = viewer.parentNode; const scrollbarWidth = container.offsetWidth - viewer.offsetWidth; if (scrollbarWidth > 0) { __privateGet(this, _style).setProperty("--progressBar-end-offset", `${scrollbarWidth}px`); } } setDisableAutoFetch(delay = 5e3) { if (isNaN(__privateGet(this, _percent))) { return; } if (__privateGet(this, _disableAutoFetchTimeout)) { clearTimeout(__privateGet(this, _disableAutoFetchTimeout)); } this.show(); __privateSet(this, _disableAutoFetchTimeout, setTimeout(() => { __privateSet(this, _disableAutoFetchTimeout, null); this.hide(); }, delay)); } hide() { if (!__privateGet(this, _visible)) { return; } __privateSet(this, _visible, false); __privateGet(this, _classList).add("hidden"); } show() { if (__privateGet(this, _visible)) { return; } __privateSet(this, _visible, true); __privateGet(this, _classList).remove("hidden"); } } _classList = new WeakMap(); _disableAutoFetchTimeout = new WeakMap(); _percent = new WeakMap(); _style = new WeakMap(); _visible = new WeakMap(); function apiPageLayoutToViewerModes(layout) { let scrollMode = ScrollMode.VERTICAL, spreadMode = SpreadMode.NONE; switch (layout) { case "SinglePage": scrollMode = ScrollMode.PAGE; break; case "OneColumn": break; case "TwoPageLeft": scrollMode = ScrollMode.PAGE; case "TwoColumnLeft": spreadMode = SpreadMode.ODD; break; case "TwoPageRight": scrollMode = ScrollMode.PAGE; case "TwoColumnRight": spreadMode = SpreadMode.EVEN; break; } return { scrollMode, spreadMode }; } const CharacterType = { SPACE: 0, ALPHA_LETTER: 1, PUNCT: 2, HAN_LETTER: 3, KATAKANA_LETTER: 4, HIRAGANA_LETTER: 5, HALFWIDTH_KATAKANA_LETTER: 6, THAI_LETTER: 7 }; function isAlphabeticalScript(charCode) { return charCode < 11904; } function isAscii(charCode) { return (charCode & 65408) === 0; } function isAsciiAlpha(charCode) { return charCode >= 97 && charCode <= 122 || charCode >= 65 && charCode <= 90; } function isAsciiDigit(charCode) { return charCode >= 48 && charCode <= 57; } function isAsciiSpace(charCode) { return charCode === 32 || charCode === 9 || charCode === 13 || charCode === 10; } function isHan(charCode) { return charCode >= 13312 && charCode <= 40959 || charCode >= 63744 && charCode <= 64255; } function isKatakana(charCode) { return charCode >= 12448 && charCode <= 12543; } function isHiragana(charCode) { return charCode >= 12352 && charCode <= 12447; } function isHalfwidthKatakana(charCode) { return charCode >= 65376 && charCode <= 65439; } function isThai(charCode) { return (charCode & 65408) === 3584; } function getCharacterType(charCode) { if (isAlphabeticalScript(charCode)) { if (isAscii(charCode)) { if (isAsciiSpace(charCode)) { return CharacterType.SPACE; } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 95) { return CharacterType.ALPHA_LETTER; } return CharacterType.PUNCT; } else if (isThai(charCode)) { return CharacterType.THAI_LETTER; } else if (charCode === 160) { return CharacterType.SPACE; } return CharacterType.ALPHA_LETTER; } if (isHan(charCode)) { return CharacterType.HAN_LETTER; } else if (isKatakana(charCode)) { return CharacterType.KATAKANA_LETTER; } else if (isHiragana(charCode)) { return CharacterType.HIRAGANA_LETTER; } else if (isHalfwidthKatakana(charCode)) { return CharacterType.HALFWIDTH_KATAKANA_LETTER; } return CharacterType.ALPHA_LETTER; } let NormalizeWithNFKC; function getNormalizeWithNFKC() { NormalizeWithNFKC || (NormalizeWithNFKC = ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`); return NormalizeWithNFKC; } const FindState = { FOUND: 0, NOT_FOUND: 1, WRAPPED: 2, PENDING: 3 }; const FIND_TIMEOUT = 250; const MATCH_SCROLL_OFFSET_TOP = -50; const MATCH_SCROLL_OFFSET_LEFT = -400; const CHARACTERS_TO_NORMALIZE = { "‐": "-", "‘": "'", "’": "'", "‚": "'", "‛": "'", "“": '"', "”": '"', "„": '"', "‟": '"', "¼": "1/4", "½": "1/2", "¾": "3/4" }; const DIACRITICS_EXCEPTION = /* @__PURE__ */ new Set([12441, 12442, 2381, 2509, 2637, 2765, 2893, 3021, 3149, 3277, 3387, 3388, 3405, 3530, 3642, 3770, 3972, 4153, 4154, 5908, 5940, 6098, 6752, 6980, 7082, 7083, 7154, 7155, 11647, 43014, 43052, 43204, 43347, 43456, 43766, 44013, 3158, 3953, 3954, 3962, 3963, 3964, 3965, 3968, 3956]); let DIACRITICS_EXCEPTION_STR; const DIACRITICS_REG_EXP = new RegExp("\\p{M}+", "gu"); const SPECIAL_CHARS_REG_EXP = new RegExp("([.*+?^${}()|[\\]\\\\])|(\\p{P})|(\\s+)|(\\p{M})|(\\p{L})", "gu"); const NOT_DIACRITIC_FROM_END_REG_EXP = new RegExp("([^\\p{M}])\\p{M}*$", "u"); const NOT_DIACRITIC_FROM_START_REG_EXP = new RegExp("^\\p{M}*([^\\p{M}])", "u"); const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g; const SYLLABLES_LENGTHS = /* @__PURE__ */ new Map(); const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]"; const NFKC_CHARS_TO_NORMALIZE = /* @__PURE__ */ new Map(); let noSyllablesRegExp = null; let withSyllablesRegExp = null; function normalize(text) { const syllablePositions = []; let m; while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) { let { index } = m; for (const char of m[0]) { let len = SYLLABLES_LENGTHS.get(char); if (!len) { len = char.normalize("NFD").length; SYLLABLES_LENGTHS.set(char, len); } syllablePositions.push([len, index++]); } } let normalizationRegex; if (syllablePositions.length === 0 && noSyllablesRegExp) { normalizationRegex = noSyllablesRegExp; } else if (syllablePositions.length > 0 && withSyllablesRegExp) { normalizationRegex = withSyllablesRegExp; } else { const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join(""); const toNormalizeWithNFKC = getNormalizeWithNFKC(); const CJK = "(?:\\p{Ideographic}|[぀-ヿ])"; const HKDiacritics = "(?:゙|゚)"; const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`; if (syllablePositions.length === 0) { normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum"); } else { normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum"); } } const rawDiacriticsPositions = []; while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) { rawDiacriticsPositions.push([m[0].length, m.index]); } let normalized = text.normalize("NFD"); const positions = [[0, 0]]; let rawDiacriticsIndex = 0; let syllableIndex = 0; let shift = 0; let shiftOrigin = 0; let eol = 0; let hasDiacritics = false; normalized = normalized.replace(normalizationRegex, (match2, p1, p2, p3, p4, p5, p6, p7, p8, i) => { var _a, _b, _c; i -= shiftOrigin; if (p1) { const replacement = CHARACTERS_TO_NORMALIZE[p1]; const jj = replacement.length; for (let j = 1; j < jj; j++) { positions.push([i - shift + j, shift - j]); } shift -= jj - 1; return replacement; } if (p2) { let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2); if (!replacement) { replacement = p2.normalize("NFKC"); NFKC_CHARS_TO_NORMALIZE.set(p2, replacement); } const jj = replacement.length; for (let j = 1; j < jj; j++) { positions.push([i - shift + j, shift - j]); } shift -= jj - 1; return replacement; } if (p3) { hasDiacritics = true; if (i + eol === ((_a = rawDiacriticsPositions[rawDiacriticsIndex]) == null ? void 0 : _a[1])) { ++rawDiacriticsIndex; } else { positions.push([i - 1 - shift + 1, shift - 1]); shift -= 1; shiftOrigin += 1; } positions.push([i - shift + 1, shift]); shiftOrigin += 1; eol += 1; return p3.charAt(0); } if (p4) { const hasTrailingDashEOL = p4.endsWith("\n"); const len = hasTrailingDashEOL ? p4.length - 2 : p4.length; hasDiacritics = true; let jj = len; if (i + eol === ((_b = rawDiacriticsPositions[rawDiacriticsIndex]) == null ? void 0 : _b[1])) { jj -= rawDiacriticsPositions[rawDiacriticsIndex][0]; ++rawDiacriticsIndex; } for (let j = 1; j <= jj; j++) { positions.push([i - 1 - shift + j, shift - j]); } shift -= jj; shiftOrigin += jj; if (hasTrailingDashEOL) { i += len - 1; positions.push([i - shift + 1, 1 + shift]); shift += 1; shiftOrigin += 1; eol += 1; return p4.slice(0, len); } return p4; } if (p5) { const len = p5.length - 2; positions.push([i - shift + len, 1 + shift]); shift += 1; shiftOrigin += 1; eol += 1; return p5.slice(0, -2); } if (p6) { const len = p6.length - 1; positions.push([i - shift + len, shift]); shiftOrigin += 1; eol += 1; return p6.slice(0, -1); } if (p7) { positions.push([i - shift + 1, shift - 1]); shift -= 1; shiftOrigin += 1; eol += 1; return " "; } if (i + eol === ((_c = syllablePositions[syllableIndex]) == null ? void 0 : _c[1])) { const newCharLen = syllablePositions[syllableIndex][0] - 1; ++syllableIndex; for (let j = 1; j <= newCharLen; j++) { positions.push([i - (shift - j), shift - j]); } shift -= newCharLen; shiftOrigin += newCharLen; } return p8; }); positions.push([normalized.length, shift]); return [normalized, positions, hasDiacritics]; } function getOriginalIndex(diffs, pos, len) { if (!diffs) { return [pos, len]; } const start = pos; const end = pos + len - 1; let i = binarySearchFirstItem(diffs, (x) => x[0] >= start); if (diffs[i][0] > start) { --i; } let j = binarySearchFirstItem(diffs, (x) => x[0] >= end, i); if (diffs[j][0] > end) { --j; } const oldStart = start + diffs[i][1]; const oldEnd = end + diffs[j][1]; const oldLen = oldEnd + 1 - oldStart; return [oldStart, oldLen]; } class PDFFindController { constructor({ linkService, eventBus, updateMatchesCountOnProgress = true }) { __privateAdd(this, _PDFFindController_instances); __privateAdd(this, _state, null); __privateAdd(this, _updateMatchesCountOnProgress, true); __privateAdd(this, _visitedPagesCount, 0); this._linkService = linkService; this._eventBus = eventBus; __privateSet(this, _updateMatchesCountOnProgress, updateMatchesCountOnProgress); this.onIsPageVisible = null; __privateMethod(this, _PDFFindController_instances, reset_fn).call(this); eventBus._on("find", __privateMethod(this, _PDFFindController_instances, onFind_fn).bind(this)); eventBus._on("findbarclose", __privateMethod(this, _PDFFindController_instances, onFindBarClose_fn).bind(this)); } get highlightMatches() { return this._highlightMatches; } get pageMatches() { return this._pageMatches; } get pageMatchesLength() { return this._pageMatchesLength; } get selected() { return this._selected; } get state() { return __privateGet(this, _state); } setDocument(pdfDocument) { if (this._pdfDocument) { __privateMethod(this, _PDFFindController_instances, reset_fn).call(this); } if (!pdfDocument) { return; } this._pdfDocument = pdfDocument; this._firstPageCapability.resolve(); } scrollMatchIntoView({ element = null, selectedLeft = 0, pageIndex = -1, matchIndex = -1 }) { if (!this._scrollMatches || !element) { return; } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) { return; } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) { return; } this._scrollMatches = false; const spot = { top: MATCH_SCROLL_OFFSET_TOP, left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT }; scrollIntoView(element, spot, true); } } _state = new WeakMap(); _updateMatchesCountOnProgress = new WeakMap(); _visitedPagesCount = new WeakMap(); _PDFFindController_instances = new WeakSet(); onFind_fn = function(state) { if (!state) { return; } const pdfDocument = this._pdfDocument; const { type } = state; if (__privateGet(this, _state) === null || __privateMethod(this, _PDFFindController_instances, shouldDirtyMatch_fn).call(this, state)) { this._dirtyMatch = true; } __privateSet(this, _state, state); if (type !== "highlightallchange") { __privateMethod(this, _PDFFindController_instances, updateUIState_fn).call(this, FindState.PENDING); } this._firstPageCapability.promise.then(() => { if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { return; } __privateMethod(this, _PDFFindController_instances, extractText_fn).call(this); const findbarClosed = !this._highlightMatches; const pendingTimeout = !!this._findTimeout; if (this._findTimeout) { clearTimeout(this._findTimeout); this._findTimeout = null; } if (!type) { this._findTimeout = setTimeout(() => { __privateMethod(this, _PDFFindController_instances, nextMatch_fn).call(this); this._findTimeout = null; }, FIND_TIMEOUT); } else if (this._dirtyMatch) { __privateMethod(this, _PDFFindController_instances, nextMatch_fn).call(this); } else if (type === "again") { __privateMethod(this, _PDFFindController_instances, nextMatch_fn).call(this); if (findbarClosed && __privateGet(this, _state).highlightAll) { __privateMethod(this, _PDFFindController_instances, updateAllPages_fn).call(this); } } else if (type === "highlightallchange") { if (pendingTimeout) { __privateMethod(this, _PDFFindController_instances, nextMatch_fn).call(this); } else { this._highlightMatches = true; } __privateMethod(this, _PDFFindController_instances, updateAllPages_fn).call(this); } else { __privateMethod(this, _PDFFindController_instances, nextMatch_fn).call(this); } }); }; reset_fn = function() { this._highlightMatches = false; this._scrollMatches = false; this._pdfDocument = null; this._pageMatches = []; this._pageMatchesLength = []; __privateSet(this, _visitedPagesCount, 0); __privateSet(this, _state, null); this._selected = { pageIdx: -1, matchIdx: -1 }; this._offset = { pageIdx: null, matchIdx: null, wrapped: false }; this._extractTextPromises = []; this._pageContents = []; this._pageDiffs = []; this._hasDiacritics = []; this._matchesCountTotal = 0; this._pagesToSearch = null; this._pendingFindMatches = /* @__PURE__ */ new Set(); this._resumePageIdx = null; this._dirtyMatch = false; clearTimeout(this._findTimeout); this._findTimeout = null; this._firstPageCapability = Promise.withResolvers(); }; query_get = function() { const { query } = __privateGet(this, _state); if (typeof query === "string") { if (query !== this._rawQuery) { this._rawQuery = query; [this._normalizedQuery] = normalize(query); } return this._normalizedQuery; } return (query || []).filter((q) => !!q).map((q) => normalize(q)[0]); }; shouldDirtyMatch_fn = function(state) { var _a; const newQuery = state.query, prevQuery = __privateGet(this, _state).query; const newType = typeof newQuery, prevType = typeof prevQuery; if (newType !== prevType) { return true; } if (newType === "string") { if (newQuery !== prevQuery) { return true; } } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) { return true; } switch (state.type) { case "again": const pageNumber = this._selected.pageIdx + 1; const linkService = this._linkService; return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(((_a = this.onIsPageVisible) == null ? void 0 : _a.call(this, pageNumber)) ?? true); case "highlightallchange": return false; } return true; }; isEntireWord_fn = function(content, startIdx, length) { let match2 = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP); if (match2) { const first = content.charCodeAt(startIdx); const limit = match2[1].charCodeAt(0); if (getCharacterType(first) === getCharacterType(limit)) { return false; } } match2 = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP); if (match2) { const last = content.charCodeAt(startIdx + length - 1); const limit = match2[1].charCodeAt(0); if (getCharacterType(last) === getCharacterType(limit)) { return false; } } return true; }; calculateRegExpMatch_fn = function(query, entireWord, pageIndex, pageContent) { const matches = this._pageMatches[pageIndex] = []; const matchesLength = this._pageMatchesLength[pageIndex] = []; if (!query) { return; } const diffs = this._pageDiffs[pageIndex]; let match2; while ((match2 = query.exec(pageContent)) !== null) { if (entireWord && !__privateMethod(this, _PDFFindController_instances, isEntireWord_fn).call(this, pageContent, match2.index, match2[0].length)) { continue; } const [matchPos, matchLen] = getOriginalIndex(diffs, match2.index, match2[0].length); if (matchLen) { matches.push(matchPos); matchesLength.push(matchLen); } } }; convertToRegExpString_fn = function(query, hasDiacritics) { const { matchDiacritics } = __privateGet(this, _state); let isUnicode = false; query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match2, p1, p2, p3, p4, p5) => { if (p1) { return `[ ]*\\${p1}[ ]*`; } if (p2) { return `[ ]*${p2}[ ]*`; } if (p3) { return "[ ]+"; } if (matchDiacritics) { return p4 || p5; } if (p4) { return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : ""; } if (hasDiacritics) { isUnicode = true; return `${p5}\\p{M}*`; } return p5; }); const trailingSpaces = "[ ]*"; if (query.endsWith(trailingSpaces)) { query = query.slice(0, query.length - trailingSpaces.length); } if (matchDiacritics) { if (hasDiacritics) { DIACRITICS_EXCEPTION_STR || (DIACRITICS_EXCEPTION_STR = String.fromCharCode(...DIACRITICS_EXCEPTION)); isUnicode = true; query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`; } } return [isUnicode, query]; }; calculateMatch_fn = function(pageIndex) { let query = __privateGet(this, _PDFFindController_instances, query_get); if (query.length === 0) { return; } const { caseSensitive, entireWord } = __privateGet(this, _state); const pageContent = this._pageContents[pageIndex]; const hasDiacritics = this._hasDiacritics[pageIndex]; let isUnicode = false; if (typeof query === "string") { [isUnicode, query] = __privateMethod(this, _PDFFindController_instances, convertToRegExpString_fn).call(this, query, hasDiacritics); } else { query = query.sort().reverse().map((q) => { const [isUnicodePart, queryPart] = __privateMethod(this, _PDFFindController_instances, convertToRegExpString_fn).call(this, q, hasDiacritics); isUnicode || (isUnicode = isUnicodePart); return `(${queryPart})`; }).join("|"); } const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`; query = query ? new RegExp(query, flags) : null; __privateMethod(this, _PDFFindController_instances, calculateRegExpMatch_fn).call(this, query, entireWord, pageIndex, pageContent); if (__privateGet(this, _state).highlightAll) { __privateMethod(this, _PDFFindController_instances, updatePage_fn).call(this, pageIndex); } if (this._resumePageIdx === pageIndex) { this._resumePageIdx = null; __privateMethod(this, _PDFFindController_instances, nextPageMatch_fn).call(this); } const pageMatchesCount = this._pageMatches[pageIndex].length; this._matchesCountTotal += pageMatchesCount; if (__privateGet(this, _updateMatchesCountOnProgress)) { if (pageMatchesCount > 0) { __privateMethod(this, _PDFFindController_instances, updateUIResultsCount_fn).call(this); } } else if (++__privateWrapper(this, _visitedPagesCount)._ === this._linkService.pagesCount) { __privateMethod(this, _PDFFindController_instances, updateUIResultsCount_fn).call(this); } }; extractText_fn = function() { if (this._extractTextPromises.length > 0) { return; } let deferred = Promise.resolve(); const textOptions = { disableNormalization: true }; for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) { const { promise, resolve } = Promise.withResolvers(); this._extractTextPromises[i] = promise; deferred = deferred.then(() => { return this._pdfDocument.getPage(i + 1).then((pdfPage) => pdfPage.getTextContent(textOptions)).then((textContent) => { const strBuf = []; for (const textItem of textContent.items) { strBuf.push(textItem.str); if (textItem.hasEOL) { strBuf.push("\n"); } } [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join("")); resolve(); }, (reason) => { console.error(`Unable to get text content for page ${i + 1}`, reason); this._pageContents[i] = ""; this._pageDiffs[i] = null; this._hasDiacritics[i] = false; resolve(); }); }); } }; updatePage_fn = function(index) { if (this._scrollMatches && this._selected.pageIdx === index) { this._linkService.page = index + 1; } this._eventBus.dispatch("updatetextlayermatches", { source: this, pageIndex: index }); }; updateAllPages_fn = function() { this._eventBus.dispatch("updatetextlayermatches", { source: this, pageIndex: -1 }); }; nextMatch_fn = function() { const previous = __privateGet(this, _state).findPrevious; const currentPageIndex = this._linkService.page - 1; const numPages = this._linkService.pagesCount; this._highlightMatches = true; if (this._dirtyMatch) { this._dirtyMatch = false; this._selected.pageIdx = this._selected.matchIdx = -1; this._offset.pageIdx = currentPageIndex; this._offset.matchIdx = null; this._offset.wrapped = false; this._resumePageIdx = null; this._pageMatches.length = 0; this._pageMatchesLength.length = 0; __privateSet(this, _visitedPagesCount, 0); this._matchesCountTotal = 0; __privateMethod(this, _PDFFindController_instances, updateAllPages_fn).call(this); for (let i = 0; i < numPages; i++) { if (this._pendingFindMatches.has(i)) { continue; } this._pendingFindMatches.add(i); this._extractTextPromises[i].then(() => { this._pendingFindMatches.delete(i); __privateMethod(this, _PDFFindController_instances, calculateMatch_fn).call(this, i); }); } } const query = __privateGet(this, _PDFFindController_instances, query_get); if (query.length === 0) { __privateMethod(this, _PDFFindController_instances, updateUIState_fn).call(this, FindState.FOUND); return; } if (this._resumePageIdx) { return; } const offset = this._offset; this._pagesToSearch = numPages; if (offset.matchIdx !== null) { const numPageMatches = this._pageMatches[offset.pageIdx].length; if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) { offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1; __privateMethod(this, _PDFFindController_instances, updateMatch_fn).call(this, true); return; } __privateMethod(this, _PDFFindController_instances, advanceOffsetPage_fn).call(this, previous); } __privateMethod(this, _PDFFindController_instances, nextPageMatch_fn).call(this); }; matchesReady_fn = function(matches) { const offset = this._offset; const numMatches = matches.length; const previous = __privateGet(this, _state).findPrevious; if (numMatches) { offset.matchIdx = previous ? numMatches - 1 : 0; __privateMethod(this, _PDFFindController_instances, updateMatch_fn).call(this, true); return true; } __privateMethod(this, _PDFFindController_instances, advanceOffsetPage_fn).call(this, previous); if (offset.wrapped) { offset.matchIdx = null; if (this._pagesToSearch < 0) { __privateMethod(this, _PDFFindController_instances, updateMatch_fn).call(this, false); return true; } } return false; }; nextPageMatch_fn = function() { if (this._resumePageIdx !== null) { console.error("There can only be one pending page."); } let matches = null; do { const pageIdx = this._offset.pageIdx; matches = this._pageMatches[pageIdx]; if (!matches) { this._resumePageIdx = pageIdx; break; } } while (!__privateMethod(this, _PDFFindController_instances, matchesReady_fn).call(this, matches)); }; advanceOffsetPage_fn = function(previous) { const offset = this._offset; const numPages = this._linkService.pagesCount; offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1; offset.matchIdx = null; this._pagesToSearch--; if (offset.pageIdx >= numPages || offset.pageIdx < 0) { offset.pageIdx = previous ? numPages - 1 : 0; offset.wrapped = true; } }; updateMatch_fn = function(found = false) { let state = FindState.NOT_FOUND; const wrapped = this._offset.wrapped; this._offset.wrapped = false; if (found) { const previousPage = this._selected.pageIdx; this._selected.pageIdx = this._offset.pageIdx; this._selected.matchIdx = this._offset.matchIdx; state = wrapped ? FindState.WRAPPED : FindState.FOUND; if (previousPage !== -1 && previousPage !== this._selected.pageIdx) { __privateMethod(this, _PDFFindController_instances, updatePage_fn).call(this, previousPage); } } __privateMethod(this, _PDFFindController_instances, updateUIState_fn).call(this, state, __privateGet(this, _state).findPrevious); if (this._selected.pageIdx !== -1) { this._scrollMatches = true; __privateMethod(this, _PDFFindController_instances, updatePage_fn).call(this, this._selected.pageIdx); } }; onFindBarClose_fn = function(evt) { const pdfDocument = this._pdfDocument; this._firstPageCapability.promise.then(() => { if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { return; } if (this._findTimeout) { clearTimeout(this._findTimeout); this._findTimeout = null; } if (this._resumePageIdx) { this._resumePageIdx = null; this._dirtyMatch = true; } __privateMethod(this, _PDFFindController_instances, updateUIState_fn).call(this, FindState.FOUND); this._highlightMatches = false; __privateMethod(this, _PDFFindController_instances, updateAllPages_fn).call(this); }); }; requestMatchesCount_fn = function() { var _a; const { pageIdx, matchIdx } = this._selected; let current = 0, total = this._matchesCountTotal; if (matchIdx !== -1) { for (let i = 0; i < pageIdx; i++) { current += ((_a = this._pageMatches[i]) == null ? void 0 : _a.length) || 0; } current += matchIdx + 1; } if (current < 1 || current > total) { current = total = 0; } return { current, total }; }; updateUIResultsCount_fn = function() { this._eventBus.dispatch("updatefindmatchescount", { source: this, matchesCount: __privateMethod(this, _PDFFindController_instances, requestMatchesCount_fn).call(this) }); }; updateUIState_fn = function(state, previous = false) { var _a, _b; if (!__privateGet(this, _updateMatchesCountOnProgress) && (__privateGet(this, _visitedPagesCount) !== this._linkService.pagesCount || state === FindState.PENDING)) { return; } this._eventBus.dispatch("updatefindcontrolstate", { source: this, state, previous, entireWord: ((_a = __privateGet(this, _state)) == null ? void 0 : _a.entireWord) ?? null, matchesCount: __privateMethod(this, _PDFFindController_instances, requestMatchesCount_fn).call(this), rawQuery: ((_b = __privateGet(this, _state)) == null ? void 0 : _b.query) ?? null }); }; const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; const LinkTarget = { NONE: 0, SELF: 1, BLANK: 2, PARENT: 3, TOP: 4 }; const _PDFLinkService = class _PDFLinkService { constructor({ eventBus, externalLinkTarget = null, externalLinkRel = null, ignoreDestinationZoom = false } = {}) { __publicField(this, "externalLinkEnabled", true); this.eventBus = eventBus; this.externalLinkTarget = externalLinkTarget; this.externalLinkRel = externalLinkRel; this._ignoreDestinationZoom = ignoreDestinationZoom; this.baseUrl = null; this.pdfDocument = null; this.pdfViewer = null; this.pdfHistory = null; } setDocument(pdfDocument, baseUrl = null) { this.baseUrl = baseUrl; this.pdfDocument = pdfDocument; } setViewer(pdfViewer) { this.pdfViewer = pdfViewer; } setHistory(pdfHistory) { this.pdfHistory = pdfHistory; } get pagesCount() { return this.pdfDocument ? this.pdfDocument.numPages : 0; } get page() { return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1; } set page(value) { if (this.pdfDocument) { this.pdfViewer.currentPageNumber = value; } } get rotation() { return this.pdfDocument ? this.pdfViewer.pagesRotation : 0; } set rotation(value) { if (this.pdfDocument) { this.pdfViewer.pagesRotation = value; } } get isInPresentationMode() { return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false; } async goToDestination(dest) { if (!this.pdfDocument) { return; } let namedDest, explicitDest, pageNumber; if (typeof dest === "string") { namedDest = dest; explicitDest = await this.pdfDocument.getDestination(dest); } else { namedDest = null; explicitDest = await dest; } if (!Array.isArray(explicitDest)) { console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`); return; } const [destRef] = explicitDest; if (destRef && typeof destRef === "object") { pageNumber = this.pdfDocument.cachedPageNumber(destRef); if (!pageNumber) { try { pageNumber = await this.pdfDocument.getPageIndex(destRef) + 1; } catch { console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`); return; } } } else if (Number.isInteger(destRef)) { pageNumber = destRef + 1; } if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`); return; } if (this.pdfHistory) { this.pdfHistory.pushCurrentPosition(); this.pdfHistory.push({ namedDest, explicitDest, pageNumber }); } this.pdfViewer.scrollPageIntoView({ pageNumber, destArray: explicitDest, ignoreDestinationZoom: this._ignoreDestinationZoom }); } goToPage(val) { if (!this.pdfDocument) { return; } const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0; if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) { console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`); return; } if (this.pdfHistory) { this.pdfHistory.pushCurrentPosition(); this.pdfHistory.pushPage(pageNumber); } this.pdfViewer.scrollPageIntoView({ pageNumber }); } addLinkAttributes(link, url, newWindow = false) { if (!url || typeof url !== "string") { throw new Error('A valid "url" parameter must provided.'); } const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, rel = this.externalLinkRel; if (this.externalLinkEnabled) { link.href = link.title = url; } else { link.href = ""; link.title = `Disabled: ${url}`; link.onclick = () => false; } let targetStr = ""; switch (target) { case LinkTarget.NONE: break; case LinkTarget.SELF: targetStr = "_self"; break; case LinkTarget.BLANK: targetStr = "_blank"; break; case LinkTarget.PARENT: targetStr = "_parent"; break; case LinkTarget.TOP: targetStr = "_top"; break; } link.target = targetStr; link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; } getDestinationHash(dest) { if (typeof dest === "string") { if (dest.length > 0) { return this.getAnchorUrl("#" + escape(dest)); } } else if (Array.isArray(dest)) { const str = JSON.stringify(dest); if (str.length > 0) { return this.getAnchorUrl("#" + escape(str)); } } return this.getAnchorUrl(""); } getAnchorUrl(anchor) { return this.baseUrl ? th