# EdgePDF Viewer

A high-performance and efficient JavaScript library for viewing and interacting with large PDF documents in the browser. EdgePDF delivers smooth navigation, interactive annotations, and marker management for documents of any size. Available as vanilla JavaScript or React components.

## Features

- ⚡ **High Performance**: Smooth viewing and navigation even for very large PDF files (100+ MB)
- 📍 **Interactive Markers**: Place, drag, edit, and manage markers with custom annotations
- 🔍 **Zoom & Pan**: Intuitive navigation with smooth zoom controls and pan gestures
- 🔄 **Data Persistence**: Import and export marker data as JSON for session management
- ⚛️ **React Ready**: Full React support with hooks and components
- 📱 **Multi-Device**: Works seamlessly on desktop, tablet, and mobile devices
- 🎯 **Type Safe**: Fully typed TypeScript API for enhanced developer experience
- 🎨 **Customizable**: Flexible styling and theming options

## Packages

This monorepo contains the following packages:

- **@edgepdf/types** - Shared TypeScript type definitions
- **@edgepdf/utils** - Shared utility functions
- **@edgepdf/viewer-js** - Core viewer library (pure JavaScript)
- **@edgepdf/viewer-react** - React wrapper and components
- **@edgepdf/testing-utils** - Testing utilities and mocks

## Getting Started

### Installation

```bash
# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test
```

### Development

```bash
# Run linting
pnpm lint

# Run type checking
pnpm typecheck

# Run affected tests
pnpm nx affected -t test
```

### Demo Application

#### Vanilla JavaScript Demo

```bash
cd apps/viewer-vanilla
# Serve with any static file server
python3 -m http.server 8000
```

Open [http://localhost:8000](http://localhost:8000)

## Project Structure

```
EdgePDF/
├── packages/
│   ├── types/          # Shared TypeScript types
│   ├── utils/          # Shared utilities
│   ├── viewer-js/      # Core viewer library
│   ├── viewer-react/   # React wrapper
│   └── testing-utils/  # Test utilities
├── apps/
│   └── viewer-vanilla/ # Vanilla JS demo app
└── .github/
    └── workflows/     # CI/CD workflows
```

## Local Development

Local development is enabled via SST sandbox cloud environments.

To create a new sandbox environment for your setup, create `.env` file from `.env.example` and add required values.

i.e

```txt
// .env file
SST_STAGE=rpatel
```

Next, you can run

```sh

# Start all runnable services in dev mode
pnpm dev

pnpm nx run infra-sst:dev

```

## Local Package Testing (Verdaccio)

Use this workflow to test local changes to `@edgepdf/*` packages in an external consuming project before publishing to npm.

### 1. Point `.npmrc` at local registry

In the root `.npmrc`, swap the scoped registry line:

```ini
# Comment out production registry:
# @edgepdf:registry=https://registry.npmjs.org/

# Uncomment local registry:
@edgepdf:registry=http://localhost:4873
```

### 2. Start Verdaccio

```bash
pnpm nx run local-registry
# Registry available at http://localhost:4873
```

### 3. Build & publish packages to local registry

```bash
# Bump versions (patch) before each publish iteration
cd packages/viewer-js && pnpm version patch && cd ../..
cd packages/viewer-react && pnpm version patch && cd ../..

# Build
pnpm nx build viewer-js viewer-react

# Publish
pnpm publish --filter @edgepdf/viewer-js --no-git-checks --force
pnpm publish --filter @edgepdf/viewer-react --no-git-checks --force
```

### 4. Configure the consuming project

In the root `.npmrc` of the consuming repo:

```ini
@edgepdf:registry=http://localhost:4873
```

Then install:

```bash
pnpm add @edgepdf/viewer-react@<version>
# Check published version with:
# npm view @edgepdf/viewer-react --registry=http://localhost:4873
```

### 5. Restore production registry when done

Revert root `.npmrc` back to:

```ini
@edgepdf:registry=https://registry.npmjs.org/
```

---

## Development Principles

This project follows strict development principles outlined in [AGENTS.md](./AGENTS.md):

- **Type Safety**: TypeScript strict mode mandatory
- **Testing**: 80%+ coverage required
- **Code Quality**: ESLint + Prettier enforced
- **Atomic Commits**: One logical change per commit
- **Module Boundaries**: Enforced via ESLint rules

## Contributing

Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

## License

This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.

## Documentation

- [Product Requirements Document](./PRD.md)
- [Technical Implementation Plan](./techanical_plan.md)
- [Development Principles](./AGENTS.md)
