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-document-resource

PDF Document Resource

retab-ui/pdf-document-resource
FreeUtility

Load and cache PDF.js documents and pages without viewer chrome.

Install it

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

Source

registry/new-york-v4/lib/pdf-document-resource.tsui.retab.com/r/pdf-document-resource.json · first 6 KB
1import {
2 isResourceError,
3 isViewerFormatError,
4 ViewerFormatError,
5 type ViewerFormatErrorMapperOptions,
6} from "@/lib/viewer-errors";
7import type {
8 PdfDocumentProxy,
9 PdfjsModule,
10 PdfPageProxy,
11} from "@/lib/pdf-document-types";
12import type {
13 ViewerContentBytes,
14 ViewerContentDirectUrl,
15 ViewerContentIdentity,
16} from "@/lib/viewer-resource";
17
18const PDF_CACHE_MAX = 6;
19
20type PdfDocumentContent = ViewerContentIdentity &
21 ViewerContentDirectUrl &
22 ViewerContentBytes;
23
24type DocumentCacheEntry = {
25 loadKey: string;
26 promise: Promise<PdfDocumentProxy>;
27 consumers: number;
28 lastUsedAt: number;
29 retainRejected: boolean;
30 status: "pending" | "resolved" | "rejected";
31 document?: PdfDocumentProxy;
32 error?: unknown;
33};
34
35type PageCacheEntry = {
36 promise: Promise<PdfPageProxy>;
37 retainRejected: boolean;
38 status: "pending" | "resolved" | "rejected";
39 page?: PdfPageProxy;
40 error?: unknown;
41};
42
43type PdfResourceOptions = {
44 retainRejected?: boolean;
45};
46
47let pdfjsPromise: Promise<PdfjsModule> | null = null;
48const documentCache = new Map<string, DocumentCacheEntry>();
49const pageCache = new WeakMap<PdfDocumentProxy, Map<number, PageCacheEntry>>();
50const detachedDocumentEntries = new Set<DocumentCacheEntry>();
51let pruneTimer = 0;
52
53function loadPdfjs(): Promise<PdfjsModule> {
54 if (!pdfjsPromise) {
55 pdfjsPromise = import("pdfjs-dist/legacy/build/pdf.mjs").then((pdfjs) => {
56 const pdfjsModule = pdfjs as unknown as PdfjsModule;
57 if (!pdfjsModule.GlobalWorkerOptions.workerSrc) {
58 pdfjsModule.GlobalWorkerOptions.workerSrc = new URL(
59 "pdfjs-dist/legacy/build/pdf.worker.min.mjs",
60 import.meta.url,
61 ).toString();
62 }
63 return pdfjsModule;
64 });
65 }
66 return pdfjsPromise;
67}
68
69function scheduleDocumentPrune() {
70 if (typeof window === "undefined" || pruneTimer) return;
71 pruneTimer = window.setTimeout(() => {
72 pruneTimer = 0;
73 pruneDocumentCache();
74 }, 0);
75}
76
77function pruneDocumentCache() {
78 while (documentCache.size > PDF_CACHE_MAX) {
79 let evictKey: string | null = null;
80 let evictEntry: DocumentCacheEntry | null = null;
81 for (const [key, documentEntry] of documentCache) {
82 if (documentEntry.consumers > 0 || documentEntry.status === "pending") {
83 continue;
84 }
85 if (!evictEntry || documentEntry.lastUsedAt < evictEntry.lastUsedAt) {
86 evictKey = key;
87 evictEntry = documentEntry;
88 }
89 }
90 if (!evictKey || !evictEntry) return;
91// … truncated

What it pulls in

npm packages

  • pdfjs-dist@5.4.296

Files it writes

  • registry/new-york-v4/lib/pdf-document-types.ts
  • registry/new-york-v4/lib/pdf-document-resource.ts
  • registry/new-york-v4/lib/viewer-errors.ts
  • registry/new-york-v4/lib/viewer-resource.ts
  • registry/new-york-v4/lib/viewer-download-actions.ts
  • registry/new-york-v4/lib/viewer-source.ts

Facts

Registry
retab-ui
Type
registry:lib
Access
Free
Files written
6
Licence
NOASSERTION
In the index
at or before 2026-08-11
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
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
Segment Interactionsegment-interactionretab-uiUtilitiesFreeno deps
Segments modelsegmentsretab-uiUtilitiesFreeno deps
Utilsutilsretab-uiUtilitiesFree2 deps
XLSX SheetJS flattenerxlsx-sheetjs-flattenerretab-uiUtilitiesFree1 dep

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

KitGrade

SaaS starter kits, scored from measured facts

kitgrade.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex