|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a monorepo for `@mikecousins/react-pdf`, a React component library that provides an easy way to render PDF documents using PDF.js. The repository uses pnpm workspaces with Turborepo for build orchestration. |
| 8 | + |
| 9 | +## Repository Structure |
| 10 | + |
| 11 | +- `packages/react-pdf-js/` - Main React PDF component library |
| 12 | +- `apps/demo/` - Demo application showcasing the component |
| 13 | +- `apps/demo-react-router/` - React Router demo application |
| 14 | +- `apps/docs/` - Documentation site built with Next.js |
| 15 | + |
| 16 | +## Development Commands |
| 17 | + |
| 18 | +### Root Level Commands (use these for most tasks) |
| 19 | +- `pnpm build` - Build all packages and apps via Turborepo |
| 20 | +- `pnpm lint` - Lint all packages and apps via Turborepo |
| 21 | +- `pnpm test` - Run tests for all packages via Turborepo |
| 22 | +- `pnpm format` - Format all code using Prettier |
| 23 | + |
| 24 | +### Package-Specific Commands |
| 25 | +For the main library (`packages/react-pdf-js/`): |
| 26 | +- `pnpm build` - Build using tsup (outputs ESM and CJS formats) |
| 27 | +- `pnpm lint` - Run ESLint |
| 28 | + |
| 29 | +### Package Manager |
| 30 | +This project uses `pnpm` as the package manager (version 10.7.0). Always use `pnpm` instead of npm or yarn. |
| 31 | + |
| 32 | +## Core Architecture |
| 33 | + |
| 34 | +The main library exports a single React hook called `usePdf` that: |
| 35 | + |
| 36 | +1. **PDF Document Loading**: Uses PDF.js `getDocument()` to load PDF files from URLs |
| 37 | +2. **Canvas Rendering**: Renders PDF pages to HTML5 canvas elements with support for: |
| 38 | + - Scaling and rotation |
| 39 | + - High DPI displays (devicePixelRatio handling) |
| 40 | + - Render task cancellation for performance |
| 41 | +3. **Lifecycle Callbacks**: Provides optional callbacks for document/page load and render events |
| 42 | +4. **Configuration**: Supports PDF.js worker configuration, cMap settings, and credential handling |
| 43 | + |
| 44 | +### Key Files |
| 45 | +- `packages/react-pdf-js/src/index.tsx` - Main hook implementation and TypeScript types |
| 46 | +- `packages/react-pdf-js/package.json` - Library configuration with peer dependencies on React 19+ and pdfjs-dist 5+ |
| 47 | + |
| 48 | +## Testing |
| 49 | + |
| 50 | +Tests are located in `packages/react-pdf-js/test/` and use Jest with React Testing Library. The project includes canvas mocking for PDF rendering tests. |
| 51 | + |
| 52 | +## Build Output |
| 53 | + |
| 54 | +The library builds to both ESM and CommonJS formats in the `dist/` directory with full TypeScript declarations. |
0 commit comments