BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/retab-ui/pdf-source

PDF source adapter

retab-ui/pdf-source
FreeComponent

Bridges the document-source model to the PDF viewer: pdfAnchorToTarget and renderPdfSourceOverlay for PDF bbox anchors.

Install it

npx shadcn@latest add https://ui.retab.com/r/pdf-source.json

Source

registry/new-york-v4/ui/pdf-source.tsxui.retab.com/r/pdf-source.json
1"use client";
2
3import * as React from "react";
4
5import type {
6 Source,
7 SourceAnchor,
8 SourceLocation,
9} from "@/lib/document-source";
10import {
11 PdfHighlight,
12 type PageOverlayProps,
13 type PdfViewerHandle,
14} from "@/components/ui/pdf-viewer";
15
16export interface SourceTarget {
17 scrollTo?: (source: Source, options: { behavior: ScrollBehavior }) => void;
18}
19
20/**
21 * Turn a source anchor into a PDF target, or `undefined` when the anchor isn't
22 * a page region (a spreadsheet cell, a text span, …). PDF/image bbox anchors are
23 * normalized [0, 1]; the viewer wants percentages, so scale by 100. An image
24 * lands on the single page 1.
25 */
26export function pdfAnchorToTarget(
27 anchor: SourceAnchor,
28): SourceLocation | undefined {
29 if (anchor.kind === "pdf_bbox") {
30 if (!isPositiveInteger(anchor.page) || !isValidNormalizedBox(anchor)) {
31 return undefined;
32 }
33 return {
34 page: anchor.page,
35 area: {
36 left: anchor.left * 100,
37 top: anchor.top * 100,
38 width: anchor.width * 100,
39 height: anchor.height * 100,
40 },
41 };
42 }
43 if (anchor.kind === "image_bbox") {
44 if (anchor.page != null && !isPositiveInteger(anchor.page)) {
45 return undefined;
46 }
47 if (!isValidNormalizedBox(anchor)) return undefined;
48 return {
49 page: 1,
50 area: {
51 left: anchor.left * 100,
52 top: anchor.top * 100,
53 width: anchor.width * 100,
54 height: anchor.height * 100,
55 },
56 };
57 }
58 return undefined;
59}
60
61function isPositiveInteger(value: number): boolean {
62 return Number.isInteger(value) && value >= 1;
63}
64
65function isValidNormalizedBox({
66 left,
67 top,
68 width,
69 height,
70}: {
71 left: number;
72 top: number;
73 width: number;
74 height: number;
75}): boolean {
76 return (
77 Number.isFinite(left) &&
78 Number.isFinite(top) &&
79 Number.isFinite(width) &&
80 Number.isFinite(height) &&
81 left >= 0 &&
82 top >= 0 &&
83 width > 0 &&
84 height > 0 &&
85 left + width <= 1 &&
86 top + height <= 1
87 );
88}
89
90/**
91 * A stable source target over a `PdfViewer` ref. The ref is read lazily, so this
92 * is just the bridge from source anchors to the viewer's imperative handle.
93 */
94export function usePdfSourceTarget(
95 viewerRef: React.RefObject<PdfViewerHandle | null>,
96): SourceTarget {
97 return React.useMemo<SourceTarget>(
98 () => ({
99 scrollTo: (source: Source, options) => {
100 const target = pdfAnchorToTarget(source.anchor);
101 if (target) {
102// … truncated

What it pulls in

Other registry items

  • @retab/pdf-viewer
  • @retab/document-source

Files it writes

  • registry/new-york-v4/ui/pdf-source.tsx

Facts

Registry
retab-ui
Type
registry:ui
Access
Free
Files written
1
Licence
NOASSERTION
First indexed
2026-08-03
Last confirmed
yesterday

Go to the source

ui.retab.com retab-dev/retab-ui on GitHub Raw registry item This item as JSON

More from retab-ui

All 130 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Alertalertretab-uiComponentsFree1 dep
Alert Dialogalert-dialogretab-uiComponentsFree1 dep
Aspect Ratioaspect-ratioretab-uiComponentsFreeno deps
Attachment Sidebarattachment-sidebarretab-uiComponentsFree1 dep
Autocompleteautocompleteretab-uiComponentsFree2 deps
Calendarcalendarretab-uiComponentsFree2 deps
Code Viewercode-viewerretab-uiComponentsFree2 deps · 32 files
Commandcommandretab-uiComponentsFree2 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex