@embedpdf/plugin-link 3.0.0-next.14 → 3.0.0-next.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_contract = require("../contract-DXB_v4as.cjs");
3
+ //#region src/host-contract.ts
4
+ /** @embedpdf/plugin-link/contract/host: the host lens, the public capability plus what a framework binding supplies. */
5
+ const LinkToken = (0, require("@embedpdf/core").createHostToken)(require_contract.LinkToken);
6
+ //#endregion
7
+ exports.LinkToken = LinkToken;
8
+ exports.resolveLinkTarget = require_contract.resolveLinkTarget;
9
+
10
+ //# sourceMappingURL=host.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.cjs","names":["PublicLinkToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** @embedpdf/plugin-link/contract/host: the host lens, the public capability plus what a framework binding supplies. */\nimport { createHostToken, type Unsubscribe } from '@embedpdf/core';\n\nimport type { LinkCapability } from './contract';\nimport { LinkToken as PublicLinkToken } from './token';\n\nexport * from './contract';\n\n/**\n * Opens a website for `activate()`, in the user's gesture. Returns whether it\n * opened: false for an address it won't open (a `javascript:` or `file:`\n * URI), which activation then reports.\n */\nexport type UriOpener = (uri: string) => boolean;\n\nexport interface LinkHostCapability extends LinkCapability {\n /** Does the active tool navigate links (the layer paints anchors only then)? */\n isNavigationEngaged(): boolean;\n /**\n * Register the framework's website opener. The plugin never touches the\n * DOM: without an opener, a website link activates as `{ outcome: 'uri' }`\n * for the caller to open. The latest registration wins until it is removed.\n */\n registerUriOpener(opener: UriOpener): Unsubscribe;\n}\n\nexport const LinkToken = createHostToken<LinkHostCapability>(PublicLinkToken);\n"],"mappings":";;;;AA0BA,MAAa,aAAA,2BAAA,CAAA,CAAA,gBAAA,CAAgDA,iBAAAA,SAAe"}
@@ -0,0 +1,3 @@
1
+ import { a as LinkCapability, c as PageDestination, i as LinkActivation, l as PdfLinkTarget, n as LinkActivateContext, o as LinkLoadedEvent, r as LinkActivatedEvent, s as LinkResolution, t as Link, u as resolveLinkTarget } from "../contract-B4x0DFCT.cjs";
2
+ import { n as LinkToken, r as UriOpener, t as LinkHostCapability } from "../host-contract-c0QOjhO6.cjs";
3
+ export { Link, LinkActivateContext, LinkActivatedEvent, LinkActivation, LinkCapability, LinkHostCapability, LinkLoadedEvent, LinkResolution, LinkToken, type PageDestination, type PdfLinkTarget, UriOpener, resolveLinkTarget };
@@ -0,0 +1,3 @@
1
+ import { a as LinkCapability, c as PageDestination, i as LinkActivation, l as PdfLinkTarget, n as LinkActivateContext, o as LinkLoadedEvent, r as LinkActivatedEvent, s as LinkResolution, t as Link, u as resolveLinkTarget } from "../contract-DyTXDEwb.js";
2
+ import { n as LinkToken, r as UriOpener, t as LinkHostCapability } from "../host-contract-DNwp7dlr.js";
3
+ export { Link, LinkActivateContext, LinkActivatedEvent, LinkActivation, LinkCapability, LinkHostCapability, LinkLoadedEvent, LinkResolution, LinkToken, type PageDestination, type PdfLinkTarget, UriOpener, resolveLinkTarget };
@@ -0,0 +1,9 @@
1
+ import { n as LinkToken$1, t as resolveLinkTarget } from "../contract-CJ9mhj7i.js";
2
+ import { createHostToken } from "@embedpdf/core";
3
+ //#region src/host-contract.ts
4
+ /** @embedpdf/plugin-link/contract/host: the host lens, the public capability plus what a framework binding supplies. */
5
+ const LinkToken = createHostToken(LinkToken$1);
6
+ //#endregion
7
+ export { LinkToken, resolveLinkTarget };
8
+
9
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","names":["PublicLinkToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** @embedpdf/plugin-link/contract/host: the host lens, the public capability plus what a framework binding supplies. */\nimport { createHostToken, type Unsubscribe } from '@embedpdf/core';\n\nimport type { LinkCapability } from './contract';\nimport { LinkToken as PublicLinkToken } from './token';\n\nexport * from './contract';\n\n/**\n * Opens a website for `activate()`, in the user's gesture. Returns whether it\n * opened: false for an address it won't open (a `javascript:` or `file:`\n * URI), which activation then reports.\n */\nexport type UriOpener = (uri: string) => boolean;\n\nexport interface LinkHostCapability extends LinkCapability {\n /** Does the active tool navigate links (the layer paints anchors only then)? */\n isNavigationEngaged(): boolean;\n /**\n * Register the framework's website opener. The plugin never touches the\n * DOM: without an opener, a website link activates as `{ outcome: 'uri' }`\n * for the caller to open. The latest registration wins until it is removed.\n */\n registerUriOpener(opener: UriOpener): Unsubscribe;\n}\n\nexport const LinkToken = createHostToken<LinkHostCapability>(PublicLinkToken);\n"],"mappings":";;;;AA0BA,MAAa,YAAY,gBAAoCA,WAAe"}
@@ -0,0 +1,143 @@
1
+ import { EventHook, OperationOptions, PageRef, ResourceStatus } from "@embedpdf/core";
2
+ import { Point } from "@embedpdf/core-geometry";
3
+ import { AnnotationRef, PageDestination, PdfActionTree, PdfLinkTarget } from "@embedpdf/engine-core/runtime";
4
+ import { ActionDispatchResult } from "@embedpdf/plugin-actions/contract";
5
+ import { LinkNavItem } from "@embedpdf/plugin-annotation/contract";
6
+ import { StageCapability } from "@embedpdf/plugin-stage/contract";
7
+ //#region src/token.d.ts
8
+ declare const LinkToken: import("@embedpdf/core").CapabilityToken<LinkCapability>;
9
+ //#endregion
10
+ //#region src/contract.d.ts
11
+ /**
12
+ * A clickable link area: page-space `bounds`, its target, and its annotation
13
+ * (when it is one). The target and `/A` tree are as the annotation holds
14
+ * them, their destinations in page space.
15
+ */
16
+ type Link = LinkNavItem;
17
+ /**
18
+ * What activation did: `revealed` (the view went to a page), `uri` (a website
19
+ * opened), `dispatched` (the actions plugin runs the link's action), or
20
+ * `reported` (a link it won't follow). `destination`, `named` and a `uri`
21
+ * with no framework to open it are handed to the caller to perform.
22
+ */
23
+ type LinkActivation = {
24
+ outcome: 'revealed';
25
+ } | {
26
+ outcome: 'destination';
27
+ destination: PageDestination;
28
+ } | {
29
+ outcome: 'uri';
30
+ uri: string;
31
+ } | {
32
+ outcome: 'named';
33
+ name: string;
34
+ } | {
35
+ outcome: 'reported';
36
+ target: PdfLinkTarget;
37
+ } | {
38
+ outcome: 'dispatched';
39
+ dispatch: Promise<ActionDispatchResult>;
40
+ } | {
41
+ outcome: 'none';
42
+ };
43
+ /**
44
+ * What activating a target would do, with no side effect. A `goto` to a page
45
+ * of this document is its destination, ready for `stage.goToDestination`;
46
+ * one to a page the document doesn't have is reported.
47
+ */
48
+ type LinkResolution = {
49
+ kind: 'destination';
50
+ destination: PageDestination;
51
+ } | {
52
+ kind: 'uri';
53
+ uri: string;
54
+ } | {
55
+ kind: 'named';
56
+ name: string;
57
+ } | {
58
+ kind: 'reported';
59
+ target: PdfLinkTarget;
60
+ };
61
+ /**
62
+ * What activating a target would do, by the rule every link and outline item
63
+ * follows: a `goto` to a page `hasPage` knows is its destination, one to a
64
+ * page the document doesn't have is reported; a website and a named verb are
65
+ * handed on; anything else is reported.
66
+ */
67
+ declare function resolveLinkTarget(target: PdfLinkTarget, hasPage: (page: PageRef) => boolean): LinkResolution;
68
+ interface LinkActivateContext {
69
+ /** The link's `/A` tree when it has one; the actions plugin runs it instead of the target. */
70
+ activate?: PdfActionTree;
71
+ ref?: AnnotationRef;
72
+ page?: PageRef;
73
+ /**
74
+ * The view the link was followed in: a page destination moves this Stage.
75
+ * Defaults to the main view.
76
+ */
77
+ stage?: StageCapability;
78
+ }
79
+ /** A link target was activated through this capability. */
80
+ interface LinkActivatedEvent {
81
+ readonly target: PdfLinkTarget;
82
+ readonly activation: LinkActivation;
83
+ }
84
+ /** A page's links were read from the engine. */
85
+ interface LinkLoadedEvent {
86
+ readonly page: PageRef;
87
+ }
88
+ interface LinkCapability {
89
+ /**
90
+ * Clickable areas on a page (its ref or its index), page space.
91
+ * Reference-stable per page while unchanged; empty for a page that isn't in
92
+ * the document.
93
+ */
94
+ listLinks(page: PageRef | number): readonly Link[];
95
+ /** One link by its stable id, or null. */
96
+ getLink(page: PageRef | number, linkId: string): Link | null;
97
+ /** The topmost (smallest) link under a page point, or null. */
98
+ getLinkAt(page: PageRef | number, point: Point): Link | null;
99
+ /**
100
+ * Every link in the document; loads pages as needed. Rejects when a page's
101
+ * read fails, and `operation-cancelled` when `signal` fires.
102
+ */
103
+ listAllLinks(options?: OperationOptions): Promise<readonly Link[]>;
104
+ /**
105
+ * Load a page's links. Resolves at once when the annotation plugin owns
106
+ * them; rejects when the read fails, which `getStatus(page)` then reports,
107
+ * `not-found` for a page that isn't in the document, and
108
+ * `operation-cancelled` when `signal` fires.
109
+ */
110
+ ensureLoaded(page: PageRef | number, options?: OperationOptions): Promise<void>;
111
+ /** The page's links were read and are current. Always true with the annotation plugin. */
112
+ isLoaded(page: PageRef | number): boolean;
113
+ /** Load state of a page's links: `idle`, `loading`, `ready`, `error` or `forbidden`. */
114
+ getStatus(page: PageRef | number): ResourceStatus;
115
+ /** What activation would do, with no side effect. */
116
+ resolve(target: PdfLinkTarget): LinkResolution;
117
+ /**
118
+ * Follow a link, or a link's target, as a click does, and return what
119
+ * happened at once (the user's gesture is still on the stack, so a website
120
+ * can open in a new tab). A `goto` moves the Stage, by its `scrollBehavior`
121
+ * setting; a website opens through the framework (an `http`, `https`,
122
+ * `mailto` or `tel` address only); a link with an `/A` tree dispatches
123
+ * through the actions plugin. Fires `onActivated`.
124
+ */
125
+ activate(target: PdfLinkTarget | Link, context?: LinkActivateContext): LinkActivation;
126
+ /**
127
+ * Hit test, then activate. Null when no link is there; throws `not-found`
128
+ * for a page that isn't in the document.
129
+ */
130
+ activateAt(page: PageRef | number, point: Point, context?: LinkActivateContext): LinkActivation | null;
131
+ /** A human label for tooltips. */
132
+ getLabel(link: Link | PdfLinkTarget): string;
133
+ /** After the built-in handling of any activation. */
134
+ readonly onActivated: EventHook<LinkActivatedEvent>;
135
+ /**
136
+ * A page's links were read, first or again after an annotation change on
137
+ * it. Never fires for a failed read, nor while the annotation plugin owns the links.
138
+ */
139
+ readonly onLoaded: EventHook<LinkLoadedEvent>;
140
+ }
141
+ //#endregion
142
+ export { LinkCapability as a, PageDestination as c, LinkToken as d, LinkActivation as i, PdfLinkTarget as l, LinkActivateContext as n, LinkLoadedEvent as o, LinkActivatedEvent as r, LinkResolution as s, Link as t, resolveLinkTarget as u };
143
+ //# sourceMappingURL=contract-B4x0DFCT.d.cts.map
@@ -0,0 +1,46 @@
1
+ import { createCapabilityToken } from "@embedpdf/core";
2
+ //#region src/token.ts
3
+ /** The package token, created once here: `contract.ts` re-exports it and
4
+ * `host-contract.ts` widens it to the host capability. */
5
+ const LinkToken = createCapabilityToken("link", {
6
+ hint: `add linkPlugin() from '@embedpdf/plugin-link' to your plugins list`,
7
+ promises: {
8
+ listAllLinks: true,
9
+ ensureLoaded: true
10
+ }
11
+ });
12
+ //#endregion
13
+ //#region src/contract.ts
14
+ /**
15
+ * What activating a target would do, by the rule every link and outline item
16
+ * follows: a `goto` to a page `hasPage` knows is its destination, one to a
17
+ * page the document doesn't have is reported; a website and a named verb are
18
+ * handed on; anything else is reported.
19
+ */
20
+ function resolveLinkTarget(target, hasPage) {
21
+ switch (target.kind) {
22
+ case "goto": return hasPage(target.destination.page) ? {
23
+ kind: "destination",
24
+ destination: target.destination
25
+ } : {
26
+ kind: "reported",
27
+ target
28
+ };
29
+ case "uri": return {
30
+ kind: "uri",
31
+ uri: target.uri
32
+ };
33
+ case "named": return {
34
+ kind: "named",
35
+ name: target.name
36
+ };
37
+ default: return {
38
+ kind: "reported",
39
+ target
40
+ };
41
+ }
42
+ }
43
+ //#endregion
44
+ export { LinkToken as n, resolveLinkTarget as t };
45
+
46
+ //# sourceMappingURL=contract-CJ9mhj7i.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-CJ9mhj7i.js","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here: `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { LinkCapability } from './contract';\n\nexport const LinkToken = createCapabilityToken<LinkCapability>('link', {\n hint: `add linkPlugin() from '@embedpdf/plugin-link' to your plugins list`,\n // Without a document, an adapter's stand-in rejects these with `not-ready`, as the\n // capability would; the type asks for every member that returns a promise.\n promises: {\n listAllLinks: true,\n ensureLoaded: true,\n },\n});\n","/** @embedpdf/plugin-link/contract: the public link vocabulary. */\nimport type { EventHook, OperationOptions, PageRef, ResourceStatus } from '@embedpdf/core';\nimport type { Point } from '@embedpdf/core-geometry';\nimport type {\n AnnotationRef,\n PageDestination,\n PdfActionTree,\n PdfLinkTarget,\n} from '@embedpdf/engine-core/runtime';\nimport type { ActionDispatchResult } from '@embedpdf/plugin-actions/contract';\nimport type { LinkNavItem } from '@embedpdf/plugin-annotation/contract';\nimport type { StageCapability } from '@embedpdf/plugin-stage/contract';\n\nexport { LinkToken } from './token';\n\n/**\n * A clickable link area: page-space `bounds`, its target, and its annotation\n * (when it is one). The target and `/A` tree are as the annotation holds\n * them, their destinations in page space.\n */\nexport type Link = LinkNavItem;\nexport type { PageDestination, PdfLinkTarget };\n\n/**\n * What activation did: `revealed` (the view went to a page), `uri` (a website\n * opened), `dispatched` (the actions plugin runs the link's action), or\n * `reported` (a link it won't follow). `destination`, `named` and a `uri`\n * with no framework to open it are handed to the caller to perform.\n */\nexport type LinkActivation =\n | { outcome: 'revealed' }\n | { outcome: 'destination'; destination: PageDestination }\n | { outcome: 'uri'; uri: string }\n | { outcome: 'named'; name: string }\n | { outcome: 'reported'; target: PdfLinkTarget }\n | { outcome: 'dispatched'; dispatch: Promise<ActionDispatchResult> }\n | { outcome: 'none' };\n\n/**\n * What activating a target would do, with no side effect. A `goto` to a page\n * of this document is its destination, ready for `stage.goToDestination`;\n * one to a page the document doesn't have is reported.\n */\nexport type LinkResolution =\n | { kind: 'destination'; destination: PageDestination }\n | { kind: 'uri'; uri: string }\n | { kind: 'named'; name: string }\n | { kind: 'reported'; target: PdfLinkTarget };\n\n/**\n * What activating a target would do, by the rule every link and outline item\n * follows: a `goto` to a page `hasPage` knows is its destination, one to a\n * page the document doesn't have is reported; a website and a named verb are\n * handed on; anything else is reported.\n */\nexport function resolveLinkTarget(\n target: PdfLinkTarget,\n hasPage: (page: PageRef) => boolean,\n): LinkResolution {\n switch (target.kind) {\n case 'goto':\n return hasPage(target.destination.page)\n ? { kind: 'destination', destination: target.destination }\n : { kind: 'reported', target };\n case 'uri':\n return { kind: 'uri', uri: target.uri };\n case 'named':\n return { kind: 'named', name: target.name };\n default:\n return { kind: 'reported', target };\n }\n}\n\nexport interface LinkActivateContext {\n /** The link's `/A` tree when it has one; the actions plugin runs it instead of the target. */\n activate?: PdfActionTree;\n ref?: AnnotationRef;\n page?: PageRef;\n /**\n * The view the link was followed in: a page destination moves this Stage.\n * Defaults to the main view.\n */\n stage?: StageCapability;\n}\n\n/** A link target was activated through this capability. */\nexport interface LinkActivatedEvent {\n readonly target: PdfLinkTarget;\n readonly activation: LinkActivation;\n}\n/** A page's links were read from the engine. */\nexport interface LinkLoadedEvent {\n readonly page: PageRef;\n}\n\nexport interface LinkCapability {\n /**\n * Clickable areas on a page (its ref or its index), page space.\n * Reference-stable per page while unchanged; empty for a page that isn't in\n * the document.\n */\n listLinks(page: PageRef | number): readonly Link[];\n /** One link by its stable id, or null. */\n getLink(page: PageRef | number, linkId: string): Link | null;\n /** The topmost (smallest) link under a page point, or null. */\n getLinkAt(page: PageRef | number, point: Point): Link | null;\n /**\n * Every link in the document; loads pages as needed. Rejects when a page's\n * read fails, and `operation-cancelled` when `signal` fires.\n */\n listAllLinks(options?: OperationOptions): Promise<readonly Link[]>;\n /**\n * Load a page's links. Resolves at once when the annotation plugin owns\n * them; rejects when the read fails, which `getStatus(page)` then reports,\n * `not-found` for a page that isn't in the document, and\n * `operation-cancelled` when `signal` fires.\n */\n ensureLoaded(page: PageRef | number, options?: OperationOptions): Promise<void>;\n /** The page's links were read and are current. Always true with the annotation plugin. */\n isLoaded(page: PageRef | number): boolean;\n /** Load state of a page's links: `idle`, `loading`, `ready`, `error` or `forbidden`. */\n getStatus(page: PageRef | number): ResourceStatus;\n /** What activation would do, with no side effect. */\n resolve(target: PdfLinkTarget): LinkResolution;\n /**\n * Follow a link, or a link's target, as a click does, and return what\n * happened at once (the user's gesture is still on the stack, so a website\n * can open in a new tab). A `goto` moves the Stage, by its `scrollBehavior`\n * setting; a website opens through the framework (an `http`, `https`,\n * `mailto` or `tel` address only); a link with an `/A` tree dispatches\n * through the actions plugin. Fires `onActivated`.\n */\n activate(target: PdfLinkTarget | Link, context?: LinkActivateContext): LinkActivation;\n /**\n * Hit test, then activate. Null when no link is there; throws `not-found`\n * for a page that isn't in the document.\n */\n activateAt(\n page: PageRef | number,\n point: Point,\n context?: LinkActivateContext,\n ): LinkActivation | null;\n /** A human label for tooltips. */\n getLabel(link: Link | PdfLinkTarget): string;\n /** After the built-in handling of any activation. */\n readonly onActivated: EventHook<LinkActivatedEvent>;\n /**\n * A page's links were read, first or again after an annotation change on\n * it. Never fires for a failed read, nor while the annotation plugin owns the links.\n */\n readonly onLoaded: EventHook<LinkLoadedEvent>;\n}\n"],"mappings":";;;;AAMA,MAAa,YAAY,sBAAsC,QAAQ;CACrE,MAAM;CAGN,UAAU;EACR,cAAc;EACd,cAAc;CAChB;AACF,CAAC;;;;;;;;;ACyCD,SAAgB,kBACd,QACA,SACgB;CAChB,QAAQ,OAAO,MAAf;EACE,KAAK,QACH,OAAO,QAAQ,OAAO,YAAY,IAAI,IAClC;GAAE,MAAM;GAAe,aAAa,OAAO;EAAY,IACvD;GAAE,MAAM;GAAY;EAAO;EACjC,KAAK,OACH,OAAO;GAAE,MAAM;GAAO,KAAK,OAAO;EAAI;EACxC,KAAK,SACH,OAAO;GAAE,MAAM;GAAS,MAAM,OAAO;EAAK;EAC5C,SACE,OAAO;GAAE,MAAM;GAAY;EAAO;CACtC;AACF"}
@@ -0,0 +1,56 @@
1
+ //#region src/token.ts
2
+ /** The package token, created once here: `contract.ts` re-exports it and
3
+ * `host-contract.ts` widens it to the host capability. */
4
+ const LinkToken = (0, require("@embedpdf/core").createCapabilityToken)("link", {
5
+ hint: `add linkPlugin() from '@embedpdf/plugin-link' to your plugins list`,
6
+ promises: {
7
+ listAllLinks: true,
8
+ ensureLoaded: true
9
+ }
10
+ });
11
+ //#endregion
12
+ //#region src/contract.ts
13
+ /**
14
+ * What activating a target would do, by the rule every link and outline item
15
+ * follows: a `goto` to a page `hasPage` knows is its destination, one to a
16
+ * page the document doesn't have is reported; a website and a named verb are
17
+ * handed on; anything else is reported.
18
+ */
19
+ function resolveLinkTarget(target, hasPage) {
20
+ switch (target.kind) {
21
+ case "goto": return hasPage(target.destination.page) ? {
22
+ kind: "destination",
23
+ destination: target.destination
24
+ } : {
25
+ kind: "reported",
26
+ target
27
+ };
28
+ case "uri": return {
29
+ kind: "uri",
30
+ uri: target.uri
31
+ };
32
+ case "named": return {
33
+ kind: "named",
34
+ name: target.name
35
+ };
36
+ default: return {
37
+ kind: "reported",
38
+ target
39
+ };
40
+ }
41
+ }
42
+ //#endregion
43
+ Object.defineProperty(exports, "LinkToken", {
44
+ enumerable: true,
45
+ get: function() {
46
+ return LinkToken;
47
+ }
48
+ });
49
+ Object.defineProperty(exports, "resolveLinkTarget", {
50
+ enumerable: true,
51
+ get: function() {
52
+ return resolveLinkTarget;
53
+ }
54
+ });
55
+
56
+ //# sourceMappingURL=contract-DXB_v4as.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-DXB_v4as.cjs","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here: `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { LinkCapability } from './contract';\n\nexport const LinkToken = createCapabilityToken<LinkCapability>('link', {\n hint: `add linkPlugin() from '@embedpdf/plugin-link' to your plugins list`,\n // Without a document, an adapter's stand-in rejects these with `not-ready`, as the\n // capability would; the type asks for every member that returns a promise.\n promises: {\n listAllLinks: true,\n ensureLoaded: true,\n },\n});\n","/** @embedpdf/plugin-link/contract: the public link vocabulary. */\nimport type { EventHook, OperationOptions, PageRef, ResourceStatus } from '@embedpdf/core';\nimport type { Point } from '@embedpdf/core-geometry';\nimport type {\n AnnotationRef,\n PageDestination,\n PdfActionTree,\n PdfLinkTarget,\n} from '@embedpdf/engine-core/runtime';\nimport type { ActionDispatchResult } from '@embedpdf/plugin-actions/contract';\nimport type { LinkNavItem } from '@embedpdf/plugin-annotation/contract';\nimport type { StageCapability } from '@embedpdf/plugin-stage/contract';\n\nexport { LinkToken } from './token';\n\n/**\n * A clickable link area: page-space `bounds`, its target, and its annotation\n * (when it is one). The target and `/A` tree are as the annotation holds\n * them, their destinations in page space.\n */\nexport type Link = LinkNavItem;\nexport type { PageDestination, PdfLinkTarget };\n\n/**\n * What activation did: `revealed` (the view went to a page), `uri` (a website\n * opened), `dispatched` (the actions plugin runs the link's action), or\n * `reported` (a link it won't follow). `destination`, `named` and a `uri`\n * with no framework to open it are handed to the caller to perform.\n */\nexport type LinkActivation =\n | { outcome: 'revealed' }\n | { outcome: 'destination'; destination: PageDestination }\n | { outcome: 'uri'; uri: string }\n | { outcome: 'named'; name: string }\n | { outcome: 'reported'; target: PdfLinkTarget }\n | { outcome: 'dispatched'; dispatch: Promise<ActionDispatchResult> }\n | { outcome: 'none' };\n\n/**\n * What activating a target would do, with no side effect. A `goto` to a page\n * of this document is its destination, ready for `stage.goToDestination`;\n * one to a page the document doesn't have is reported.\n */\nexport type LinkResolution =\n | { kind: 'destination'; destination: PageDestination }\n | { kind: 'uri'; uri: string }\n | { kind: 'named'; name: string }\n | { kind: 'reported'; target: PdfLinkTarget };\n\n/**\n * What activating a target would do, by the rule every link and outline item\n * follows: a `goto` to a page `hasPage` knows is its destination, one to a\n * page the document doesn't have is reported; a website and a named verb are\n * handed on; anything else is reported.\n */\nexport function resolveLinkTarget(\n target: PdfLinkTarget,\n hasPage: (page: PageRef) => boolean,\n): LinkResolution {\n switch (target.kind) {\n case 'goto':\n return hasPage(target.destination.page)\n ? { kind: 'destination', destination: target.destination }\n : { kind: 'reported', target };\n case 'uri':\n return { kind: 'uri', uri: target.uri };\n case 'named':\n return { kind: 'named', name: target.name };\n default:\n return { kind: 'reported', target };\n }\n}\n\nexport interface LinkActivateContext {\n /** The link's `/A` tree when it has one; the actions plugin runs it instead of the target. */\n activate?: PdfActionTree;\n ref?: AnnotationRef;\n page?: PageRef;\n /**\n * The view the link was followed in: a page destination moves this Stage.\n * Defaults to the main view.\n */\n stage?: StageCapability;\n}\n\n/** A link target was activated through this capability. */\nexport interface LinkActivatedEvent {\n readonly target: PdfLinkTarget;\n readonly activation: LinkActivation;\n}\n/** A page's links were read from the engine. */\nexport interface LinkLoadedEvent {\n readonly page: PageRef;\n}\n\nexport interface LinkCapability {\n /**\n * Clickable areas on a page (its ref or its index), page space.\n * Reference-stable per page while unchanged; empty for a page that isn't in\n * the document.\n */\n listLinks(page: PageRef | number): readonly Link[];\n /** One link by its stable id, or null. */\n getLink(page: PageRef | number, linkId: string): Link | null;\n /** The topmost (smallest) link under a page point, or null. */\n getLinkAt(page: PageRef | number, point: Point): Link | null;\n /**\n * Every link in the document; loads pages as needed. Rejects when a page's\n * read fails, and `operation-cancelled` when `signal` fires.\n */\n listAllLinks(options?: OperationOptions): Promise<readonly Link[]>;\n /**\n * Load a page's links. Resolves at once when the annotation plugin owns\n * them; rejects when the read fails, which `getStatus(page)` then reports,\n * `not-found` for a page that isn't in the document, and\n * `operation-cancelled` when `signal` fires.\n */\n ensureLoaded(page: PageRef | number, options?: OperationOptions): Promise<void>;\n /** The page's links were read and are current. Always true with the annotation plugin. */\n isLoaded(page: PageRef | number): boolean;\n /** Load state of a page's links: `idle`, `loading`, `ready`, `error` or `forbidden`. */\n getStatus(page: PageRef | number): ResourceStatus;\n /** What activation would do, with no side effect. */\n resolve(target: PdfLinkTarget): LinkResolution;\n /**\n * Follow a link, or a link's target, as a click does, and return what\n * happened at once (the user's gesture is still on the stack, so a website\n * can open in a new tab). A `goto` moves the Stage, by its `scrollBehavior`\n * setting; a website opens through the framework (an `http`, `https`,\n * `mailto` or `tel` address only); a link with an `/A` tree dispatches\n * through the actions plugin. Fires `onActivated`.\n */\n activate(target: PdfLinkTarget | Link, context?: LinkActivateContext): LinkActivation;\n /**\n * Hit test, then activate. Null when no link is there; throws `not-found`\n * for a page that isn't in the document.\n */\n activateAt(\n page: PageRef | number,\n point: Point,\n context?: LinkActivateContext,\n ): LinkActivation | null;\n /** A human label for tooltips. */\n getLabel(link: Link | PdfLinkTarget): string;\n /** After the built-in handling of any activation. */\n readonly onActivated: EventHook<LinkActivatedEvent>;\n /**\n * A page's links were read, first or again after an annotation change on\n * it. Never fires for a failed read, nor while the annotation plugin owns the links.\n */\n readonly onLoaded: EventHook<LinkLoadedEvent>;\n}\n"],"mappings":";;;AAMA,MAAa,aAAA,2BAAA,CAAA,CAAA,sBAAA,CAAkD,QAAQ;CACrE,MAAM;CAGN,UAAU;EACR,cAAc;EACd,cAAc;CAChB;AACF,CAAC;;;;;;;;;ACyCD,SAAgB,kBACd,QACA,SACgB;CAChB,QAAQ,OAAO,MAAf;EACE,KAAK,QACH,OAAO,QAAQ,OAAO,YAAY,IAAI,IAClC;GAAE,MAAM;GAAe,aAAa,OAAO;EAAY,IACvD;GAAE,MAAM;GAAY;EAAO;EACjC,KAAK,OACH,OAAO;GAAE,MAAM;GAAO,KAAK,OAAO;EAAI;EACxC,KAAK,SACH,OAAO;GAAE,MAAM;GAAS,MAAM,OAAO;EAAK;EAC5C,SACE,OAAO;GAAE,MAAM;GAAY;EAAO;CACtC;AACF"}
@@ -0,0 +1,143 @@
1
+ import { EventHook, OperationOptions, PageRef, ResourceStatus } from "@embedpdf/core";
2
+ import { ActionDispatchResult } from "@embedpdf/plugin-actions/contract";
3
+ import { LinkNavItem } from "@embedpdf/plugin-annotation/contract";
4
+ import { StageCapability } from "@embedpdf/plugin-stage/contract";
5
+ import { AnnotationRef, PageDestination, PdfActionTree, PdfLinkTarget } from "@embedpdf/engine-core/runtime";
6
+ import { Point } from "@embedpdf/core-geometry";
7
+ //#region src/token.d.ts
8
+ declare const LinkToken: import("@embedpdf/core").CapabilityToken<LinkCapability>;
9
+ //#endregion
10
+ //#region src/contract.d.ts
11
+ /**
12
+ * A clickable link area: page-space `bounds`, its target, and its annotation
13
+ * (when it is one). The target and `/A` tree are as the annotation holds
14
+ * them, their destinations in page space.
15
+ */
16
+ type Link = LinkNavItem;
17
+ /**
18
+ * What activation did: `revealed` (the view went to a page), `uri` (a website
19
+ * opened), `dispatched` (the actions plugin runs the link's action), or
20
+ * `reported` (a link it won't follow). `destination`, `named` and a `uri`
21
+ * with no framework to open it are handed to the caller to perform.
22
+ */
23
+ type LinkActivation = {
24
+ outcome: 'revealed';
25
+ } | {
26
+ outcome: 'destination';
27
+ destination: PageDestination;
28
+ } | {
29
+ outcome: 'uri';
30
+ uri: string;
31
+ } | {
32
+ outcome: 'named';
33
+ name: string;
34
+ } | {
35
+ outcome: 'reported';
36
+ target: PdfLinkTarget;
37
+ } | {
38
+ outcome: 'dispatched';
39
+ dispatch: Promise<ActionDispatchResult>;
40
+ } | {
41
+ outcome: 'none';
42
+ };
43
+ /**
44
+ * What activating a target would do, with no side effect. A `goto` to a page
45
+ * of this document is its destination, ready for `stage.goToDestination`;
46
+ * one to a page the document doesn't have is reported.
47
+ */
48
+ type LinkResolution = {
49
+ kind: 'destination';
50
+ destination: PageDestination;
51
+ } | {
52
+ kind: 'uri';
53
+ uri: string;
54
+ } | {
55
+ kind: 'named';
56
+ name: string;
57
+ } | {
58
+ kind: 'reported';
59
+ target: PdfLinkTarget;
60
+ };
61
+ /**
62
+ * What activating a target would do, by the rule every link and outline item
63
+ * follows: a `goto` to a page `hasPage` knows is its destination, one to a
64
+ * page the document doesn't have is reported; a website and a named verb are
65
+ * handed on; anything else is reported.
66
+ */
67
+ declare function resolveLinkTarget(target: PdfLinkTarget, hasPage: (page: PageRef) => boolean): LinkResolution;
68
+ interface LinkActivateContext {
69
+ /** The link's `/A` tree when it has one; the actions plugin runs it instead of the target. */
70
+ activate?: PdfActionTree;
71
+ ref?: AnnotationRef;
72
+ page?: PageRef;
73
+ /**
74
+ * The view the link was followed in: a page destination moves this Stage.
75
+ * Defaults to the main view.
76
+ */
77
+ stage?: StageCapability;
78
+ }
79
+ /** A link target was activated through this capability. */
80
+ interface LinkActivatedEvent {
81
+ readonly target: PdfLinkTarget;
82
+ readonly activation: LinkActivation;
83
+ }
84
+ /** A page's links were read from the engine. */
85
+ interface LinkLoadedEvent {
86
+ readonly page: PageRef;
87
+ }
88
+ interface LinkCapability {
89
+ /**
90
+ * Clickable areas on a page (its ref or its index), page space.
91
+ * Reference-stable per page while unchanged; empty for a page that isn't in
92
+ * the document.
93
+ */
94
+ listLinks(page: PageRef | number): readonly Link[];
95
+ /** One link by its stable id, or null. */
96
+ getLink(page: PageRef | number, linkId: string): Link | null;
97
+ /** The topmost (smallest) link under a page point, or null. */
98
+ getLinkAt(page: PageRef | number, point: Point): Link | null;
99
+ /**
100
+ * Every link in the document; loads pages as needed. Rejects when a page's
101
+ * read fails, and `operation-cancelled` when `signal` fires.
102
+ */
103
+ listAllLinks(options?: OperationOptions): Promise<readonly Link[]>;
104
+ /**
105
+ * Load a page's links. Resolves at once when the annotation plugin owns
106
+ * them; rejects when the read fails, which `getStatus(page)` then reports,
107
+ * `not-found` for a page that isn't in the document, and
108
+ * `operation-cancelled` when `signal` fires.
109
+ */
110
+ ensureLoaded(page: PageRef | number, options?: OperationOptions): Promise<void>;
111
+ /** The page's links were read and are current. Always true with the annotation plugin. */
112
+ isLoaded(page: PageRef | number): boolean;
113
+ /** Load state of a page's links: `idle`, `loading`, `ready`, `error` or `forbidden`. */
114
+ getStatus(page: PageRef | number): ResourceStatus;
115
+ /** What activation would do, with no side effect. */
116
+ resolve(target: PdfLinkTarget): LinkResolution;
117
+ /**
118
+ * Follow a link, or a link's target, as a click does, and return what
119
+ * happened at once (the user's gesture is still on the stack, so a website
120
+ * can open in a new tab). A `goto` moves the Stage, by its `scrollBehavior`
121
+ * setting; a website opens through the framework (an `http`, `https`,
122
+ * `mailto` or `tel` address only); a link with an `/A` tree dispatches
123
+ * through the actions plugin. Fires `onActivated`.
124
+ */
125
+ activate(target: PdfLinkTarget | Link, context?: LinkActivateContext): LinkActivation;
126
+ /**
127
+ * Hit test, then activate. Null when no link is there; throws `not-found`
128
+ * for a page that isn't in the document.
129
+ */
130
+ activateAt(page: PageRef | number, point: Point, context?: LinkActivateContext): LinkActivation | null;
131
+ /** A human label for tooltips. */
132
+ getLabel(link: Link | PdfLinkTarget): string;
133
+ /** After the built-in handling of any activation. */
134
+ readonly onActivated: EventHook<LinkActivatedEvent>;
135
+ /**
136
+ * A page's links were read, first or again after an annotation change on
137
+ * it. Never fires for a failed read, nor while the annotation plugin owns the links.
138
+ */
139
+ readonly onLoaded: EventHook<LinkLoadedEvent>;
140
+ }
141
+ //#endregion
142
+ export { LinkCapability as a, PageDestination as c, LinkToken as d, LinkActivation as i, PdfLinkTarget as l, LinkActivateContext as n, LinkLoadedEvent as o, LinkActivatedEvent as r, LinkResolution as s, Link as t, resolveLinkTarget as u };
143
+ //# sourceMappingURL=contract-DyTXDEwb.d.ts.map
package/dist/contract.cjs CHANGED
@@ -1,3 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-DGKEPl11.cjs");
2
+ const require_contract = require("./contract-DXB_v4as.cjs");
3
3
  exports.LinkToken = require_contract.LinkToken;
4
+ exports.resolveLinkTarget = require_contract.resolveLinkTarget;
@@ -1,2 +1,2 @@
1
- import { a as LinkCapability, c as LinkState, d as PdfLinkTarget, i as LinkActivation, l as LinkToken, n as LinkActivateContext, o as LinkNavItem, r as LinkActivateEvent, s as LinkPluginConfig, u as PdfDestination } from "./contract-DO3vDsAV.cjs";
2
- export { type LinkActivateContext, type LinkActivateEvent, type LinkActivation, type LinkCapability, type LinkNavItem, type LinkPluginConfig, type LinkState, LinkToken, type PdfDestination, type PdfLinkTarget };
1
+ import { a as LinkCapability, c as PageDestination, d as LinkToken, i as LinkActivation, l as PdfLinkTarget, n as LinkActivateContext, o as LinkLoadedEvent, r as LinkActivatedEvent, s as LinkResolution, t as Link, u as resolveLinkTarget } from "./contract-B4x0DFCT.cjs";
2
+ export { Link, LinkActivateContext, LinkActivatedEvent, LinkActivation, LinkCapability, LinkLoadedEvent, LinkResolution, LinkToken, type PageDestination, type PdfLinkTarget, resolveLinkTarget };
@@ -1,2 +1,2 @@
1
- import { a as LinkCapability, c as LinkState, d as PdfLinkTarget, i as LinkActivation, l as LinkToken, n as LinkActivateContext, o as LinkNavItem, r as LinkActivateEvent, s as LinkPluginConfig, u as PdfDestination } from "./contract-B8bEMeH8.js";
2
- export { type LinkActivateContext, type LinkActivateEvent, type LinkActivation, type LinkCapability, type LinkNavItem, type LinkPluginConfig, type LinkState, LinkToken, type PdfDestination, type PdfLinkTarget };
1
+ import { a as LinkCapability, c as PageDestination, d as LinkToken, i as LinkActivation, l as PdfLinkTarget, n as LinkActivateContext, o as LinkLoadedEvent, r as LinkActivatedEvent, s as LinkResolution, t as Link, u as resolveLinkTarget } from "./contract-DyTXDEwb.js";
2
+ export { Link, LinkActivateContext, LinkActivatedEvent, LinkActivation, LinkCapability, LinkLoadedEvent, LinkResolution, LinkToken, type PageDestination, type PdfLinkTarget, resolveLinkTarget };
package/dist/contract.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as LinkToken } from "./contract-HRggERzU.js";
2
- export { LinkToken };
1
+ import { n as LinkToken, t as resolveLinkTarget } from "./contract-CJ9mhj7i.js";
2
+ export { LinkToken, resolveLinkTarget };
@@ -0,0 +1,23 @@
1
+ import { a as LinkCapability } from "./contract-DyTXDEwb.js";
2
+ import { Unsubscribe } from "@embedpdf/core";
3
+ //#region src/host-contract.d.ts
4
+ /**
5
+ * Opens a website for `activate()`, in the user's gesture. Returns whether it
6
+ * opened: false for an address it won't open (a `javascript:` or `file:`
7
+ * URI), which activation then reports.
8
+ */
9
+ type UriOpener = (uri: string) => boolean;
10
+ interface LinkHostCapability extends LinkCapability {
11
+ /** Does the active tool navigate links (the layer paints anchors only then)? */
12
+ isNavigationEngaged(): boolean;
13
+ /**
14
+ * Register the framework's website opener. The plugin never touches the
15
+ * DOM: without an opener, a website link activates as `{ outcome: 'uri' }`
16
+ * for the caller to open. The latest registration wins until it is removed.
17
+ */
18
+ registerUriOpener(opener: UriOpener): Unsubscribe;
19
+ }
20
+ declare const LinkToken: import("@embedpdf/core").CapabilityToken<LinkHostCapability>;
21
+ //#endregion
22
+ export { LinkToken as n, UriOpener as r, LinkHostCapability as t };
23
+ //# sourceMappingURL=host-contract-DNwp7dlr.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { a as LinkCapability } from "./contract-B4x0DFCT.cjs";
2
+ import { Unsubscribe } from "@embedpdf/core";
3
+ //#region src/host-contract.d.ts
4
+ /**
5
+ * Opens a website for `activate()`, in the user's gesture. Returns whether it
6
+ * opened: false for an address it won't open (a `javascript:` or `file:`
7
+ * URI), which activation then reports.
8
+ */
9
+ type UriOpener = (uri: string) => boolean;
10
+ interface LinkHostCapability extends LinkCapability {
11
+ /** Does the active tool navigate links (the layer paints anchors only then)? */
12
+ isNavigationEngaged(): boolean;
13
+ /**
14
+ * Register the framework's website opener. The plugin never touches the
15
+ * DOM: without an opener, a website link activates as `{ outcome: 'uri' }`
16
+ * for the caller to open. The latest registration wins until it is removed.
17
+ */
18
+ registerUriOpener(opener: UriOpener): Unsubscribe;
19
+ }
20
+ declare const LinkToken: import("@embedpdf/core").CapabilityToken<LinkHostCapability>;
21
+ //#endregion
22
+ export { LinkToken as n, UriOpener as r, LinkHostCapability as t };
23
+ //# sourceMappingURL=host-contract-c0QOjhO6.d.cts.map