mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[api-minor] Move addLinkAttributes
and LinkTarget
into the viewer
As part of the changes/improvement in PR 14092, we're no longer using the `addLinkAttributes` directly in e.g. the AnnotationLayer-code. Given that the helper function is now *only* used in the viewer, hence it no longer seems necessary to expose it through the official API. *Please note:* It seems somewhat unlikely that third-party users were relying *directly* on the helper function, which is why it's not being exported as part of the viewer components. (If necessary, we can always change this later on.)
This commit is contained in:
parent
290cbc5232
commit
2d2b6463b8
5 changed files with 111 additions and 124 deletions
|
@ -13,24 +13,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
assert,
|
||||
BaseException,
|
||||
isString,
|
||||
removeNullCharacters,
|
||||
shadow,
|
||||
stringToBytes,
|
||||
Util,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import {
|
||||
BaseCanvasFactory,
|
||||
BaseCMapReaderFactory,
|
||||
BaseStandardFontDataFactory,
|
||||
BaseSVGFactory,
|
||||
} from "./base_factory.js";
|
||||
import {
|
||||
BaseException,
|
||||
isString,
|
||||
shadow,
|
||||
stringToBytes,
|
||||
Util,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
|
||||
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
|
||||
const PixelsPerInch = {
|
||||
|
@ -316,70 +313,6 @@ class RenderingCancelledException extends BaseException {
|
|||
}
|
||||
}
|
||||
|
||||
const LinkTarget = {
|
||||
NONE: 0, // Default value.
|
||||
SELF: 1,
|
||||
BLANK: 2,
|
||||
PARENT: 3,
|
||||
TOP: 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef ExternalLinkParameters
|
||||
* @typedef {Object} ExternalLinkParameters
|
||||
* @property {string} url - An absolute URL.
|
||||
* @property {LinkTarget} [target] - The link target. The default value is
|
||||
* `LinkTarget.NONE`.
|
||||
* @property {string} [rel] - The link relationship. The default value is
|
||||
* `DEFAULT_LINK_REL`.
|
||||
* @property {boolean} [enabled] - Whether the link should be enabled. The
|
||||
* default value is true.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds various attributes (href, title, target, rel) to hyperlinks.
|
||||
* @param {HTMLAnchorElement} link - The link element.
|
||||
* @param {ExternalLinkParameters} params
|
||||
*/
|
||||
function addLinkAttributes(link, { url, target, rel, enabled = true } = {}) {
|
||||
assert(
|
||||
url && typeof url === "string",
|
||||
'addLinkAttributes: A valid "url" parameter must provided.'
|
||||
);
|
||||
|
||||
const urlNullRemoved = removeNullCharacters(url);
|
||||
if (enabled) {
|
||||
link.href = link.title = urlNullRemoved;
|
||||
} else {
|
||||
link.href = "";
|
||||
link.title = `Disabled: ${urlNullRemoved}`;
|
||||
link.onclick = () => {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
let targetStr = ""; // LinkTarget.NONE
|
||||
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;
|
||||
}
|
||||
|
||||
function isDataScheme(url) {
|
||||
const ii = url.length;
|
||||
let i = 0;
|
||||
|
@ -632,7 +565,6 @@ function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
|
|||
}
|
||||
|
||||
export {
|
||||
addLinkAttributes,
|
||||
deprecated,
|
||||
DOMCanvasFactory,
|
||||
DOMCMapReaderFactory,
|
||||
|
@ -644,7 +576,6 @@ export {
|
|||
isDataScheme,
|
||||
isPdfFile,
|
||||
isValidFetchUrl,
|
||||
LinkTarget,
|
||||
loadScript,
|
||||
PageViewport,
|
||||
PDFDateString,
|
||||
|
|
69
src/pdf.js
69
src/pdf.js
|
@ -12,7 +12,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable sort-exports/sort-exports */
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./display/api").PDFDocumentLoadingTask} PDFDocumentLoadingTask */
|
||||
|
@ -20,19 +19,6 @@
|
|||
/** @typedef {import("./display/api").PDFPageProxy} PDFPageProxy */
|
||||
/** @typedef {import("./display/api").RenderTask} RenderTask */
|
||||
|
||||
import {
|
||||
addLinkAttributes,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
getXfaPageViewport,
|
||||
isPdfFile,
|
||||
isValidFetchUrl,
|
||||
LinkTarget,
|
||||
loadScript,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
} from "./display/display_utils.js";
|
||||
import {
|
||||
AnnotationMode,
|
||||
CMapCompressionType,
|
||||
|
@ -60,6 +46,17 @@ import {
|
|||
setPDFNetworkStreamFactory,
|
||||
version,
|
||||
} from "./display/api.js";
|
||||
import {
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
getXfaPageViewport,
|
||||
isPdfFile,
|
||||
isValidFetchUrl,
|
||||
loadScript,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
} from "./display/display_utils.js";
|
||||
import { AnnotationLayer } from "./display/annotation_layer.js";
|
||||
import { GlobalWorkerOptions } from "./display/worker_options.js";
|
||||
import { isNodeJS } from "./shared/is_node.js";
|
||||
|
@ -108,49 +105,39 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
|||
}
|
||||
|
||||
export {
|
||||
// From "./display/display_utils.js":
|
||||
addLinkAttributes,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
isPdfFile,
|
||||
LinkTarget,
|
||||
loadScript,
|
||||
PDFDateString,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
getXfaPageViewport,
|
||||
// From "./shared/util.js":
|
||||
AnnotationLayer,
|
||||
AnnotationMode,
|
||||
build,
|
||||
CMapCompressionType,
|
||||
createObjectURL,
|
||||
createPromiseCapability,
|
||||
createValidAbsoluteUrl,
|
||||
getDocument,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
getXfaPageViewport,
|
||||
GlobalWorkerOptions,
|
||||
InvalidPDFException,
|
||||
isPdfFile,
|
||||
loadScript,
|
||||
LoopbackPort,
|
||||
MissingPDFException,
|
||||
OPS,
|
||||
PasswordResponses,
|
||||
PDFDataRangeTransport,
|
||||
PDFDateString,
|
||||
PDFWorker,
|
||||
PermissionFlag,
|
||||
PixelsPerInch,
|
||||
removeNullCharacters,
|
||||
RenderingCancelledException,
|
||||
renderTextLayer,
|
||||
shadow,
|
||||
SVGGraphics,
|
||||
UnexpectedResponseException,
|
||||
UNSUPPORTED_FEATURES,
|
||||
Util,
|
||||
VerbosityLevel,
|
||||
// From "./display/api.js":
|
||||
build,
|
||||
getDocument,
|
||||
LoopbackPort,
|
||||
PDFDataRangeTransport,
|
||||
PDFWorker,
|
||||
version,
|
||||
// From "./display/annotation_layer.js":
|
||||
AnnotationLayer,
|
||||
// From "./display/worker_options.js":
|
||||
GlobalWorkerOptions,
|
||||
// From "./display/text_layer.js":
|
||||
renderTextLayer,
|
||||
// From "./display/svg.js":
|
||||
SVGGraphics,
|
||||
// From "./display/xfa_layer.js":
|
||||
XfaLayer,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue