Document source model
retab-ui/document-sourceFreeUtility
Viewer-agnostic model for extraction sources (the Retab /v1/extractions/{id}/sources shape): SourceAnchor union (pdf_bbox, image_bbox, spreadsheet/csv cell, docx/text span), Source, ExtractionSourcesResponse, and extractionSourcesToSourceMap to flatten the sources tree into a path-keyed SourceMap.
Install it
npx shadcn@latest add https://ui.retab.com/r/document-source.jsonSource
1// Viewer-agnostic model for "sources" — the provenance of an extracted value:2// where in a source document a field came from. Mirrors the Retab3// `GET /v1/extractions/{id}/sources` response (`GetSourcesResponse`): a value4// tree plus a parallel `sources` tree whose leaves locate each value with a5// format-specific anchor.6//7// This module has no viewer/React imports so every viewer (PDF today; image,8// xlsx, csv, docx, text later) shares one source model. Each viewer's adapter9// turns an `anchor` into something it can render (see e.g. the PDF adapter).1011// ── Anchors — discriminated union on `kind`, one per document format ──────────1213/** A region on one PDF page, normalized to the page box (each value in [0, 1]). */14export interface PdfBboxAnchor {15 kind: "pdf_bbox";16 /** 1-based page number. */17 page: number;18 left: number;19 top: number;20 width: number;21 height: number;22}2324/** A region on an image, normalized to the image box (each value in [0, 1]). */25export interface ImageBboxAnchor {26 kind: "image_bbox";27 /**28 * 1-based frame index for multi-page rasters — a multi-frame TIFF page, or a29 * rasterized slide in a deck. Omitted (or 1) for a single-frame image.30 */31 page?: number;32 left: number;33 top: number;34 width: number;35 height: number;36}3738/** A cell in a CSV. */39export interface CsvCellAnchor {40 kind: "csv_cell";41 /** 1-based row number. */42 row: number;43 /** Column letter (A, B, … AA). */44 column: string;45 /** Cell coordinate (e.g. A12). */46 coordinate?: string;47}4849/** A cell in a spreadsheet (xlsx), on a given sheet. */50export interface SpreadsheetCellAnchor {51 kind: "spreadsheet_cell";52 /** 1-based row number. */53 row: number;54 /** Column letter (A, B, … AA). */55 column: string;56 coordinate?: string;57 /** 0-based sheet index. */58 sheet_index: number;59 sheet_name?: string;60}6162/** A character span within a docx paragraph. */63export interface DocxTextSpanAnchor {64 kind: "docx_text_span";65 /** 0-based paragraph index. */66 paragraph: number;67 char_start?: number;68 char_end?: number;69 /** Raw OOXML of the matched paragraph. */70 xml?: string;71}7273/** A character span within a docx table cell. */74export interface DocxTableCellAnchor {75 kind: "docx_table_cell";76 /** 0-based table index. */77 table: number;78 /** 0-based row index. */79 row: number;80 /** 0-based column index. */81 column: number;82 char_start?: number;83 char_end?: number;84 xml?: string;85}8687// … truncated
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| CSV parsercsv | retab-ui | Utilities | Free | no deps · 4 files | |
| DOCX Document Resourcedocx-document-resource | retab-ui | Utilities | Free | no deps · 5 files | |
| Effect Keyeffect-key | retab-ui | Utilities | Free | no deps | |
| PDF Document Resourcepdf-document-resource | retab-ui | Utilities | Free | 1 dep · 6 files | |
| Segment Interactionsegment-interaction | retab-ui | Utilities | Free | no deps | |
| Segments modelsegments | retab-ui | Utilities | Free | no deps | |
| Utilsutils | retab-ui | Utilities | Free | 2 deps | |
| XLSX SheetJS flattenerxlsx-sheetjs-flattener | retab-ui | Utilities | Free | 1 dep |
