# @embedpdf/react — ./link Link [TypeAliasDeclaration] (from packages/plugin/link/src/contract.ts): export type Link = LinkNavItem; LinkActivateContext [InterfaceDeclaration] (from packages/plugin/link/src/contract.ts): export interface LinkActivateContext{ readonly activate?: PdfActionTree; readonly ref?: AnnotationRef; readonly page?: PageRef; readonly stage?: StageCapability; } LinkActivatedEvent [InterfaceDeclaration] (from packages/plugin/link/src/contract.ts): export interface LinkActivatedEvent{ readonly target: PdfLinkTarget; readonly activation: LinkActivation; } LinkActivation [TypeAliasDeclaration] (from packages/plugin/link/src/contract.ts): export type LinkActivation = |{ status: 'revealed'} |{ status: 'destination'; destination: PageDestination} |{ status: 'uri'; uri: string} |{ status: 'named'; name: string} |{ status: 'reported'; target: PdfLinkTarget} |{ status: 'dispatched'; dispatch: Promise} |{ status: 'none'} ; LinkCapability [InterfaceDeclaration] (from packages/plugin/link/src/contract.ts): export interface LinkCapability{ listLinks(page: PageRef | number): readonly Link[]; getLink(page: PageRef | number, linkId: string): Link | null; getLinkAt(page: PageRef | number, point: Point): Link | null; readAllLinks(options?: OperationOptions): Promise; ensureLoaded(page: PageRef | number, options?: OperationOptions): Promise; isLoaded(page: PageRef | number): boolean; getStatus(page: PageRef | number): ResourceStatus; resolve(target: PdfLinkTarget): LinkResolution; activate(target: PdfLinkTarget | Link, context?: LinkActivateContext): LinkActivation; activateAt( page: PageRef | number, point: Point, context?: LinkActivateContext, ): LinkActivation | null; getLabel(link: Link | PdfLinkTarget): string; readonly onActivated: EventHook; readonly onLoaded: EventHook; } LinkLayer [FunctionDeclaration]: export function LinkLayer({ renderLink} : LinkLayerProps ={ } ){ const page = usePage(); const link = useCapability(LinkToken); useUriOpener(); const stage = useOptionalCapability(useStageToken()); const actions = useOptionalCapability(ActionsToken); const linkPump = useMemo(() => (actions ? createHoverPump(actions.dispatch) : null), [actions]); const items = useSelector(LinkToken, (link) => link.listLinks(page.ref), shallowArray); const engaged = useSelector(LinkHostToken, (link) => link.isNavigationEngaged()); const editEnabled = useOptionalSelector( InteractionToken, (interaction) => interaction.activeToolEnables('annotation-edit'), false, ); useEffect(() =>{ void link.ensureLoaded(page.ref); } , [link, page.ref]); if (!engaged || !items.length) return null; const visible = navigableLinksOf(items, editEnabled); if (!visible.length) return null; return (
{ visible.map((item) =>{ const{ box, href, label} = linkAnchorOf(item, page.transform, (each) => link.getLabel(each), ); const context = linkActivateContextOf(item, page.ref, stage); const native = ( sendLinkEvent(actions, item, page.ref, 'mouseDown')} href={ href ?? undefined} target="_blank" rel="noopener noreferrer" role="link" tabIndex={ 0} title={ label} aria-label={ label} onClick={ (event) =>{ if (href && isModifiedClick(event)) return; event.preventDefault(); link.activate(item, context); } } onKeyDown={ (event) =>{ if (event.key === 'Enter' || event.key === ' '){ event.preventDefault(); link.activate(item, context); } } } onPointerEnter={ () => hoverLink(linkPump, item, page.ref)} onPointerLeave={ () => linkPump?.hover(null)} onPointerUp={ () => sendLinkEvent(actions, item, page.ref, 'mouseUp')} onFocus={ () => sendLinkEvent(actions, item, page.ref, 'focus')} onBlur={ () => sendLinkEvent(actions, item, page.ref, 'blur')} style={ { position: 'absolute', left: box.left, top: box.top, width: box.width, height: box.height, cursor: 'pointer', pointerEvents: 'auto', } } /> ); const drawn = renderLink?.({ link: item, native} ) ?? native; return { drawn} ; } )}
); } LinkLayerProps [InterfaceDeclaration]: export interface LinkLayerProps{ renderLink?: (props: LinkRenderProps) => React.ReactNode | undefined; } LinkLoadedEvent [InterfaceDeclaration] (from packages/plugin/link/src/contract.ts): export interface LinkLoadedEvent{ readonly page: PageRef; } LinkRenderProps [InterfaceDeclaration]: export interface LinkRenderProps{ link: Link; native: React.ReactNode; } LinkResolution [TypeAliasDeclaration] (from packages/plugin/link/src/contract.ts): export type LinkResolution = |{ kind: 'destination'; destination: PageDestination} |{ kind: 'uri'; uri: string} |{ kind: 'named'; name: string} |{ kind: 'reported'; target: PdfLinkTarget} ; LinkToken [VariableDeclaration] (from packages/plugin/link/src/token.ts): LinkToken = createCapabilityToken('link', { hint: `add linkPlugin() from '@embedpdf/plugin-link' to your plugins list`, promises:{ readAllLinks: true, ensureLoaded: true, } , } ) PageDestination [TypeAliasDeclaration] (from packages/engine/core/src/dto/PdfDestination.ts): export type PageDestination = |{ kind: 'xyz'; page: PageRef; x: number | null; y: number | null; zoom: number | null} |{ kind: 'fit'; page: PageRef} |{ kind: 'fitH'; page: PageRef; y: number | null} |{ kind: 'fitV'; page: PageRef; x: number | null} |{ kind: 'fitR'; page: PageRef; x: number; y: number; width: number; height: number} |{ kind: 'fitB'; page: PageRef} |{ kind: 'fitBH'; page: PageRef; y: number | null} |{ kind: 'fitBV'; page: PageRef; x: number | null} ; PdfLinkTarget [TypeAliasDeclaration] (from packages/engine/core/src/dto/PdfLinkTarget.ts): export type PdfLinkTarget = |{ kind: 'goto'; destination: Destination} |{ kind: 'uri'; uri: string} |{ kind: 'goto-remote'; file: string} |{ kind: 'launch'; path: string} |{ kind: 'javascript'} |{ kind: 'named'; name: string} |{ kind: 'unsupported'} ; linkPlugin [VariableDeclaration] (from packages/plugin/link/src/link.plugin.ts): linkPlugin = () => definePlugin({ id: 'link', token: LinkToken, scope: 'document', requires: [InteractionToken], optional: [StageToken, AnnotationToken, ActionsToken], create: createLinkController, } ) resolveLinkTarget [FunctionDeclaration] (from packages/plugin/link/src/contract.ts): export function resolveLinkTarget( target: PdfLinkTarget, hasPage: (page: PageRef) => boolean, ): LinkResolution{ switch (target.kind){ case 'goto': return hasPage(target.destination.page) ?{ kind: 'destination', destination: target.destination} :{ kind: 'reported', target} ; case 'uri': return{ kind: 'uri', uri: target.uri} ; case 'named': return{ kind: 'named', name: target.name} ; default: return{ kind: 'reported', target} ; } } useLink [FunctionDeclaration]: export function useLink(): LinkCapability{ useUriOpener(); return useCapability(LinkToken); } useLinkEvent [FunctionDeclaration]: export function useLinkEvent( select: (link: LinkCapability) => EventHook, handler: (event: T) => void, ): void{ useCapabilityEvent(LinkToken, select, handler); }