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/segments

Segments model

retab-ui/segments
FreeUtility

Shared model + helpers for page-segmented results (partition/split): Segment type, Tableau palette, color map, page-range and confidence helpers.

Install it

npx shadcn@latest add https://ui.retab.com/r/segments.json

Source

registry/new-york-v4/lib/segments.tsui.retab.com/r/segments.json
1/**
2 * Shared model for page-segmented document results — Retab "partition" (keyed
3 * chunks) and "split" (named subdocuments). Both reduce to the same `Segment[]`:
4 * a label, the pages it owns, a deterministic color, and optional confidence.
5 *
6 * The legend, sidebar, and timeline primitives all consume `Segment[]`, so a
7 * partition and a split render through the exact same components.
8 */
9
10// Tableau 20 — the palette Retab's dashboard uses, so colors match.
11export const SEGMENT_PALETTE = [
12 "#4E79A7",
13 "#A0CBE8",
14 "#F28E2B",
15 "#FFBE7D",
16 "#59A14F",
17 "#8CD17D",
18 "#B6992D",
19 "#F1CE63",
20 "#499894",
21 "#86BCB6",
22 "#E15759",
23 "#FF9D9A",
24 "#79706E",
25 "#BAB0AC",
26 "#D37295",
27 "#FABFD2",
28 "#B07AA1",
29 "#D4A6C8",
30 "#9D7660",
31 "#D7B5A6",
32] as const;
33
34export interface Segment {
35 /** Stable id (label + occurrence, since a split name can repeat). */
36 id: string;
37 /** Display label — the partition key or the subdocument name. */
38 label: string;
39 /** Sorted, de-duplicated 1-based pages owned by this segment. */
40 pages: number[];
41 /** Deterministic color (by label, so the same label is always one color). */
42 color: string;
43 /** Render order. */
44 index: number;
45 /** Optional consensus confidence in [0, 1]. */
46 confidence?: number | null;
47}
48
49export interface SegmentChunk {
50 key?: string;
51 name?: string;
52 pages: number[];
53}
54
55export function segmentDisplayLabel(label: string): string {
56 const trimmed = typeof label === "string" ? label.trim() : "";
57 return trimmed || "unnamed";
58}
59
60export function normalizePageCount(value: number): number {
61 return Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
62}
63
64/** Assign one palette color per distinct display label, ordered by sorted label. */
65export function buildColorMap(labels: string[]): Map<string, string> {
66 const distinct = Array.from(new Set(labels.map(segmentDisplayLabel))).sort(
67 (a, b) => a.localeCompare(b),
68 );
69 const map = new Map<string, string>();
70 distinct.forEach((label, i) => {
71 map.set(label, SEGMENT_PALETTE[i % SEGMENT_PALETTE.length]);
72 });
73 return map;
74}
75
76function normalizePages(pages: number[]): number[] {
77 const rawPages = Array.isArray(pages) ? pages : [];
78 return Array.from(
79 new Set(rawPages.filter((p) => Number.isInteger(p) && p > 0)),
80 ).sort((a, b) => a - b);
81}
82
83export function segmentPageCount(pages: number[]): number {
84 return normalizePages(pages).length;
85}
86
87export function firstSegmentPage(pages: number[]): number | null {
88// … truncated

Files it writes

  • registry/new-york-v4/lib/segments.ts

Facts

Registry
retab-ui
Type
registry:lib
Access
Free
Files written
1
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
CSV parsercsvretab-uiUtilitiesFreeno deps · 4 files
Document source modeldocument-sourceretab-uiUtilitiesFreeno deps
DOCX Document Resourcedocx-document-resourceretab-uiUtilitiesFreeno deps · 5 files
Effect Keyeffect-keyretab-uiUtilitiesFreeno deps
PDF Document Resourcepdf-document-resourceretab-uiUtilitiesFree1 dep · 6 files
Segment Interactionsegment-interactionretab-uiUtilitiesFreeno deps
Utilsutilsretab-uiUtilitiesFree2 deps
XLSX SheetJS flattenerxlsx-sheetjs-flattenerretab-uiUtilitiesFree1 dep
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