mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Merge pull request #19577 from Snuffleupagus/isValidExplicitDest-reuse
Re-use the `isValidExplicitDest` helper function in the worker/viewer
This commit is contained in:
commit
be6ef64a2c
7 changed files with 90 additions and 119 deletions
|
@ -16,6 +16,7 @@
|
|||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
||||
|
||||
import { isValidExplicitDest } from "pdfjs-lib";
|
||||
import { parseQueryString } from "./ui_utils.js";
|
||||
|
||||
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
||||
|
@ -415,7 +416,7 @@ class PDFLinkService {
|
|||
}
|
||||
} catch {}
|
||||
|
||||
if (typeof dest === "string" || PDFLinkService.#isValidExplicitDest(dest)) {
|
||||
if (typeof dest === "string" || isValidExplicitDest(dest)) {
|
||||
this.goToDestination(dest);
|
||||
return;
|
||||
}
|
||||
|
@ -486,60 +487,6 @@ class PDFLinkService {
|
|||
optionalContentConfig
|
||||
);
|
||||
}
|
||||
|
||||
static #isValidExplicitDest(dest) {
|
||||
if (!Array.isArray(dest) || dest.length < 2) {
|
||||
return false;
|
||||
}
|
||||
const [page, zoom, ...args] = dest;
|
||||
if (
|
||||
!(
|
||||
typeof page === "object" &&
|
||||
Number.isInteger(page?.num) &&
|
||||
Number.isInteger(page?.gen)
|
||||
) &&
|
||||
!Number.isInteger(page)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (!(typeof zoom === "object" && typeof zoom?.name === "string")) {
|
||||
return false;
|
||||
}
|
||||
const argsLen = args.length;
|
||||
let allowNull = true;
|
||||
switch (zoom.name) {
|
||||
case "XYZ":
|
||||
if (argsLen < 2 || argsLen > 3) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "Fit":
|
||||
case "FitB":
|
||||
return argsLen === 0;
|
||||
case "FitH":
|
||||
case "FitBH":
|
||||
case "FitV":
|
||||
case "FitBV":
|
||||
if (argsLen > 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "FitR":
|
||||
if (argsLen !== 4) {
|
||||
return false;
|
||||
}
|
||||
allowNull = false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
for (const arg of args) {
|
||||
if (!(typeof arg === "number" || (allowNull && arg === null))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,7 @@ const {
|
|||
InvalidPDFException,
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
isValidExplicitDest,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
@ -90,6 +91,7 @@ export {
|
|||
InvalidPDFException,
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
isValidExplicitDest,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue