Convert the isValidExplicitDestination helper to a private static method on PDFLinkService

This patch also changes a previously "private" method, on `PDFLinkService`, to be *properly* private since that's now supported.
This commit is contained in:
Jonas Jenwald 2022-01-03 13:44:08 +01:00
parent 2d2b6463b8
commit fc31e1ba87

View File

@ -175,10 +175,7 @@ class PDFLinkService {
this.pdfViewer.pagesRotation = value;
}
/**
* @private
*/
_goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
#goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
// Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
const destRef = explicitDest[0];
let pageNumber;
@ -193,11 +190,11 @@ class PDFLinkService {
.getPageIndex(destRef)
.then(pageIndex => {
this.cachePageRef(pageIndex + 1, destRef);
this._goToDestinationHelper(rawDest, namedDest, explicitDest);
this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
})
.catch(() => {
console.error(
`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` +
`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` +
`a valid page reference, for dest="${rawDest}".`
);
});
@ -207,14 +204,14 @@ class PDFLinkService {
pageNumber = destRef + 1;
} else {
console.error(
`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` +
`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` +
`a valid destination reference, for dest="${rawDest}".`
);
return;
}
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
console.error(
`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` +
`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` +
`a valid page number, for dest="${rawDest}".`
);
return;
@ -258,7 +255,7 @@ class PDFLinkService {
);
return;
}
this._goToDestinationHelper(dest, namedDest, explicitDest);
this.#goToDestinationHelper(dest, namedDest, explicitDest);
}
/**
@ -405,8 +402,7 @@ class PDFLinkService {
}
} else {
console.error(
`PDFLinkService.setHash: "${zoomArg}" is not ` +
"a valid zoom value."
`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`
);
}
}
@ -444,13 +440,17 @@ class PDFLinkService {
}
} catch (ex) {}
if (typeof dest === "string" || isValidExplicitDestination(dest)) {
if (
typeof dest === "string" ||
PDFLinkService.#isValidExplicitDestination(dest)
) {
this.goToDestination(dest);
return;
}
console.error(
`PDFLinkService.setHash: "${unescape(hash)}" is not ` +
"a valid destination."
`PDFLinkService.setHash: "${unescape(
hash
)}" is not a valid destination.`
);
}
}
@ -509,7 +509,7 @@ class PDFLinkService {
}
/**
* @private
* @ignore
*/
_cachedPageNumber(pageRef) {
if (!pageRef) {
@ -533,9 +533,8 @@ class PDFLinkService {
isPageCached(pageNumber) {
return this.pdfViewer.isPageCached(pageNumber);
}
}
function isValidExplicitDestination(dest) {
static #isValidExplicitDestination(dest) {
if (!Array.isArray(dest)) {
return false;
}
@ -592,6 +591,7 @@ function isValidExplicitDestination(dest) {
}
}
return true;
}
}
/**