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/image-source

Image source adapter

retab-ui/image-source
FreeComponent

Bridges the document-source model to the image viewer: imageAnchorToTarget, rotateImageArea, and renderImageSourceOverlay for image_bbox anchors.

Install it

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

Source

registry/new-york-v4/ui/image-source.tsxui.retab.com/r/image-source.json
1"use client";
2
3import * as React from "react";
4
5import type { Source, SourceAnchor, SourceArea } from "@/lib/document-source";
6import { normalizeRotation, rotateNormalizedBox } from "@/lib/image-geometry";
7import {
8 type ImageFrameOverlayProps,
9 type ImageViewerHandle,
10} from "@/components/ui/image-viewer-types";
11
12const HIGHLIGHT_CLASS =
13 "pointer-events-none absolute z-10 rounded-[2px] border border-primary/70 bg-primary/12 shadow-[0_4px_16px_rgb(0_0_0_/_8%)]";
14
15export interface SourceTarget {
16 scrollTo?: (source: Source, options: { behavior: ScrollBehavior }) => void;
17}
18
19export interface ImageSourceTarget {
20 frame: number;
21 area: SourceArea;
22}
23
24/** A normalized image/pdf bbox anchor → the frame and percentage box to target. */
25export function imageAnchorToTarget(
26 anchor: SourceAnchor,
27): ImageSourceTarget | undefined {
28 if (anchor.kind === "image_bbox" || anchor.kind === "pdf_bbox") {
29 const frame = imageAnchorFrame(anchor);
30 if (!isValidNormalizedBox(anchor)) return undefined;
31 if (frame === undefined) return undefined;
32 return {
33 frame,
34 area: {
35 left: anchor.left * 100,
36 top: anchor.top * 100,
37 width: anchor.width * 100,
38 height: anchor.height * 100,
39 },
40 };
41 }
42 return undefined;
43}
44
45/**
46 * The 1-based frame a bbox anchor lives on, or undefined if it isn't a raster
47 * bbox. `image_bbox` defaults to frame 1 (single image); a multi-frame TIFF (or
48 * a rasterized slide deck) sets `page` explicitly.
49 */
50function imageAnchorFrame(anchor: SourceAnchor): number | undefined {
51 if (anchor.kind === "image_bbox") {
52 const frame = anchor.page ?? 1;
53 return isPositiveInteger(frame) ? frame : undefined;
54 }
55 if (anchor.kind === "pdf_bbox") {
56 return isPositiveInteger(anchor.page) ? anchor.page : undefined;
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
90export function rotateImageArea(
91 area: SourceArea,
92 rotation: number,
93): SourceArea {
94 const rotated = rotateNormalizedBox(
95 {
96// … truncated

What it pulls in

Other registry items

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

Files it writes

  • registry/new-york-v4/lib/image-geometry.ts
  • registry/new-york-v4/ui/image-source.tsx

Facts

Registry
retab-ui
Type
registry:ui
Access
Free
Files written
2
Licence
NOASSERTION
First indexed
2026-08-04
Last confirmed
today

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