123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- const DEFAULT_SCALE_VALUE = "auto";
- const DEFAULT_SCALE = 1.0;
- const DEFAULT_SCALE_DELTA = 1.1;
- const MIN_SCALE = 0.1;
- const MAX_SCALE = 10.0;
- 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 SidebarView = {
- UNKNOWN: -1,
- NONE: 0,
- THUMBS: 1,
- OUTLINE: 2,
- ATTACHMENTS: 3,
- LAYERS: 4,
- };
- const RendererType =
- typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC")
- ? {
- CANVAS: "canvas",
- SVG: "svg",
- }
- : null;
- const TextLayerMode = {
- DISABLE: 0,
- ENABLE: 1,
- };
- const ScrollMode = {
- UNKNOWN: -1,
- VERTICAL: 0,
- HORIZONTAL: 1,
- WRAPPED: 2,
- PAGE: 3,
- };
- const SpreadMode = {
- UNKNOWN: -1,
- NONE: 0,
- ODD: 1,
- EVEN: 2,
- };
- const AutoPrintRegExp = /\bprint\s*\(/;
- 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 !== undefined) {
- offsetY += spot.top;
- }
- if (spot.left !== undefined) {
- offsetX += spot.left;
- parent.scrollLeft = offsetX;
- }
- }
- parent.scrollTop = offsetY;
- }
- function watchScroll(viewAreaElement, callback) {
- 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, true);
- return state;
- }
- function parseQueryString(query) {
- const params = new Map();
- for (const [key, value] of new URLSearchParams(query)) {
- params.set(key.toLowerCase(), value);
- }
- return params;
- }
- const NullCharactersRegExp = /\x00/g;
- const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
- function removeNullCharacters(str, replaceInvisible = false) {
- if (typeof str !== "string") {
- console.error(`The argument must be a string.`);
- return str;
- }
- if (replaceInvisible) {
- str = str.replace(InvisibleCharactersRegExp, " ");
- }
- return str.replace(NullCharactersRegExp, "");
- }
- 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 roundToDivide(x, div) {
- const r = x % div;
- return r === 0 ? x : Math.round(x - r + div);
- }
- function getPageSizeInches({ view, userUnit, rotate }) {
- const [x1, y1, x2, y2] = view;
-
- const changeOrientation = rotate % 180 !== 0;
- const width = ((x2 - x1) / 72) * userUnit;
- const height = ((y2 - y1) / 72) * userUnit;
- return {
- width: changeOrientation ? height : width,
- height: changeOrientation ? width : height,
- };
- }
- 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 = 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) > 0.001) {
- return -pc;
- }
- return a.id - b.id;
- });
- }
- return { first, last, views: visible, ids };
- }
- function noContextMenuHandler(evt) {
- evt.preventDefault();
- }
- function normalizeWheelEventDirection(evt) {
- let delta = Math.hypot(evt.deltaX, evt.deltaY);
- const angle = Math.atan2(evt.deltaY, evt.deltaX);
- if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
-
- delta = -delta;
- }
- return delta;
- }
- function normalizeWheelEventDelta(evt) {
- let delta = normalizeWheelEventDirection(evt);
- const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
- const MOUSE_DOM_DELTA_LINE_MODE = 1;
- const MOUSE_PIXELS_PER_LINE = 30;
- const MOUSE_LINES_PER_PAGE = 30;
-
- if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
- delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
- } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
- delta /= MOUSE_LINES_PER_PAGE;
- }
- return delta;
- }
- 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;
- }
- const animationStarted = new Promise(function (resolve) {
- if (
- typeof PDFJSDev !== "undefined" &&
- PDFJSDev.test("LIB") &&
- typeof window === "undefined"
- ) {
-
-
- setTimeout(resolve, 20);
- return;
- }
- window.requestAnimationFrame(resolve);
- });
- const docStyle =
- typeof PDFJSDev !== "undefined" &&
- PDFJSDev.test("LIB") &&
- typeof document === "undefined"
- ? null
- : document.documentElement.style;
- function clamp(v, min, max) {
- return Math.min(Math.max(v, min), max);
- }
- class ProgressBar {
- #classList = null;
- #percent = 0;
- #visible = true;
- constructor(bar) {
- this.#classList = bar.classList;
- }
- get percent() {
- return this.#percent;
- }
- set percent(val) {
- this.#percent = clamp(val, 0, 100);
- if (isNaN(val)) {
- this.#classList.add("indeterminate");
- return;
- }
- this.#classList.remove("indeterminate");
- docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
- }
- setWidth(viewer) {
- if (!viewer) {
- return;
- }
- const container = viewer.parentNode;
- const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
- if (scrollbarWidth > 0) {
- docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
- }
- }
- hide() {
- if (!this.#visible) {
- return;
- }
- this.#visible = false;
- this.#classList.add("hidden");
- }
- show() {
- if (this.#visible) {
- return;
- }
- this.#visible = true;
- this.#classList.remove("hidden");
- }
- }
- function getActiveOrFocusedElement() {
- let curRoot = document;
- let curActiveOrFocused =
- curRoot.activeElement || curRoot.querySelector(":focus");
- while (curActiveOrFocused?.shadowRoot) {
- curRoot = curActiveOrFocused.shadowRoot;
- curActiveOrFocused =
- curRoot.activeElement || curRoot.querySelector(":focus");
- }
- return curActiveOrFocused;
- }
- 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 };
- }
- function apiPageModeToSidebarView(mode) {
- switch (mode) {
- case "UseNone":
- return SidebarView.NONE;
- case "UseThumbs":
- return SidebarView.THUMBS;
- case "UseOutlines":
- return SidebarView.OUTLINE;
- case "UseAttachments":
- return SidebarView.ATTACHMENTS;
- case "UseOC":
- return SidebarView.LAYERS;
- }
- return SidebarView.NONE;
- }
- export {
- animationStarted,
- apiPageLayoutToViewerModes,
- apiPageModeToSidebarView,
- approximateFraction,
- AutoPrintRegExp,
- backtrackBeforeAllVisibleElements,
- binarySearchFirstItem,
- DEFAULT_SCALE,
- DEFAULT_SCALE_DELTA,
- DEFAULT_SCALE_VALUE,
- docStyle,
- getActiveOrFocusedElement,
- getPageSizeInches,
- getVisibleElements,
- isPortraitOrientation,
- isValidRotation,
- isValidScrollMode,
- isValidSpreadMode,
- MAX_AUTO_SCALE,
- MAX_SCALE,
- MIN_SCALE,
- noContextMenuHandler,
- normalizeWheelEventDelta,
- normalizeWheelEventDirection,
- OutputScale,
- parseQueryString,
- PresentationModeState,
- ProgressBar,
- removeNullCharacters,
- RendererType,
- RenderingStates,
- roundToDivide,
- SCROLLBAR_PADDING,
- scrollIntoView,
- ScrollMode,
- SidebarView,
- SpreadMode,
- TextLayerMode,
- UNKNOWN_SCALE,
- VERTICAL_PADDING,
- watchScroll,
- };
|