{"owner":"mozilla","repo":"pdf.js","hasSkills":true,"hasMcp":false,"mcpConfig":null,"found":["AGENTS.md"],"skills":{"AGENTS.md":"## Overview\n\nPDF.js is a Portable Document Format (PDF) viewer built with JavaScript, HTML5 Canvas, and CSS. It's a Mozilla project that provides a general-purpose, web standards-based platform for parsing and rendering PDFs without requiring native code or plugins.\n\n## Common Commands\n\n### Development Server\n```bash\nnpx gulp server\n```\nThen open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame\n\n### Building\n\nBuild for modern browsers:\n```bash\nnpx gulp generic\n```\n\nThis generates `pdf.js` and `pdf.worker.js` in `build/generic/build/`.\n\nBuild for distribution (creates pdfjs-dist package):\n```bash\nnpx gulp dist\nnpx gulp dist-install    # Build and install locally\n```\n\n### Testing\n\nRun all tests:\n```bash\nnpx gulp test\n```\n\nRun unit tests only:\n```bash\nnpx gulp unittest\n```\n\nRun integration tests (browser-based tests using Puppeteer):\n```bash\nnpx gulp integrationtest\n```\n\nRun font tests:\n```bash\nnpx gulp fonttest\n```\n\nRun a single test file by modifying test/test_manifest.json or using test runner options.\n\n### Linting and Formatting\n\nLint JavaScript:\n```bash\nnpx gulp lint\n```\n\nFormat code (uses Prettier and ESLint):\n```bash\nnpx eslint --fix <file>\n```\n\n### Type Checking\n\nRun TypeScript type checking:\n```bash\nnpx gulp typestest\n```\n\n## Architecture\n\n### High-Level Structure\n\nPDF.js has a multi-layer architecture that separates concerns between PDF parsing, rendering, and UI:\n\n#### 1. Core Layer (`src/core/`)\nThe core layer handles PDF parsing and interpretation. Key responsibilities:\n- **PDF parsing**: Parsing PDF structure, cross-reference tables, streams\n- **Font handling**: CFF, TrueType, Type1 font parsing and conversion (`font.js`, `fonts.js`, `cff_*.js`, `type1_*.js`)\n- **Image decoding**: JPEG, JBIG2, JPX/JPEG2000 decoders\n- **Operators**: Processing PDF drawing operators (`operator_list.js`, `evaluator.js`)\n- **XFA Forms**: XML Forms Architecture support (`src/core/xfa/`)\n- **Color spaces**: ICC profiles, device color spaces (`colorspace.js`, `icc_colorspace.js`)\n- Runs in a Web Worker for performance isolation\n\nEntry point: `src/pdf.worker.js`\n\n#### 2. Display Layer (`src/display/`)\nThe display layer provides the API for rendering PDFs to canvas and managing documents. Key components:\n- **API**: Main public API (`api.js`) - `PDFDocumentProxy`, `PDFPageProxy`, `getDocument()`\n- **Canvas rendering**: Renders PDF operations to HTML5 canvas (`canvas.js`)\n- **Text layer**: Extracts and positions text for selection/search (`text_layer.js`)\n- **Annotation layer**: Renders and handles PDF annotations (`annotation_layer.js`)\n- **Editor layer**: Supports PDF editing (annotations, highlights, stamps) (`editor/`)\n- **Metadata**: Parses XMP metadata (`metadata.js`)\n- **Streams**: Handles PDF data fetching (fetch, network, node) (`fetch_stream.js`, `network.js`, `node_stream.js`)\n\nEntry point: `src/pdf.js`\n\n#### 3. Scripting Layer (`src/scripting_api/`)\nImplements JavaScript execution for interactive PDFs (form calculations, validations, button actions).\n- Sandboxed execution environment\n- Implements Acrobat JavaScript API objects (App, Doc, Field, etc.)\n\nEntry points: `src/pdf.scripting.js`, `src/pdf.sandbox.js`\n\n#### 4. Web Viewer (`web/`)\nThe complete PDF viewer application with UI. Key components:\n- **Main app**: Application orchestration (`app.js`)\n- **Viewer**: Page rendering and layout (`pdf_viewer.js`, `pdf_page_view.js`)\n- **Toolbar**: Zoom, page navigation, print, download controls\n- **Sidebar**: Thumbnails, outlines, attachments (`pdf_sidebar.js`, `pdf_thumbnail_view.js`, `pdf_outline_viewer.js`)\n- **Find controller**: Text search functionality (`pdf_find_controller.js`)\n- **Annotation editors**: UI for creating/editing annotations (`annotation_editor_layer_builder.js`)\n- **Presentation mode**: Full-screen presentation (`pdf_presentation_mode.js`)\n\nEntry point: `web/viewer.html` + `web/viewer.mjs`\n\n#### 5. Shared Utilities (`src/shared/`)\nCommon utilities used across layers:\n- **Message handling**: Worker communication (`message_handler.js`)\n- **Utilities**: Common functions and constants (`util.js`)\n- **Image utilities**: Image processing helpers (`image_utils.js`)\n\n### Worker Communication\n\nPDF.js uses a Web Worker architecture:\n- Main thread (`display` layer) communicates with worker thread (`core` layer) via `MessageHandler`\n- Keeps PDF parsing off the main thread for better performance\n- Messages include: page rendering requests, text content extraction, metadata queries\n\n### Build System\n\n- Uses **Gulp** for build orchestration (`gulpfile.mjs`)\n- **Webpack** bundles modules into browser-compatible formats\n- **Babel** transpiles for browser compatibility (configurable targets in gulpfile)\n- Preprocessor replaces build-time constants (e.g., `typeof PDFJSDev !== \"undefined\"` checks)\n- Multiple build targets: generic, components, minified, legacy (older browser support)\n\n### External Dependencies\n\nLocated in `external/`:\n- **bcmaps**: Binary CMaps for CJK fonts\n- **standard_fonts**: Core 14 PDF fonts metrics\n- **cmapscompress**: Tools for compressing CMaps\n- **openjpeg**: JPEG2000 decoder (WASM)\n- **quickjs**: JavaScript engine for sandboxed execution\n\n### Translations\n\nTranslations in `l10n/` are imported from Mozilla Firefox Nightly. Only the file l10n/en-US/viewer.ftl can be updated.\n\n## Development Notes\n\n### Adding New Features\n\nWhen adding features that span multiple layers:\n1. Start with the `core` layer if parsing/interpretation changes are needed\n2. Update the `display` layer API if new capabilities need exposure\n3. Modify the `web` viewer if UI changes are required\n4. Ensure worker communication handles new message types\n\n### Preprocessor Directives\n\nCode uses preprocessor checks for build-time conditionals:\n```javascript\nif (typeof PDFJSDev !== \"undefined\" && PDFJSDev.test(\"GENERIC\")) {\n  // Generic build-specific code\n}\n```\n\nCommon flags: `GENERIC`, `MOZCENTRAL`, `CHROME`, `MINIFIED`, `TESTING`, `LIB`, `SKIP_BABEL`, `IMAGE_DECODERS`\n\n### Testing\n\n- Unit tests use Jasmine framework (`test/unit/`)\n- Integration tests use Puppeteer for browser automation (`test/integration/`)\n- Test PDFs downloaded from manifest (`test/test_manifest.json`)\n- Reference images for visual regression testing (`test/ref/`)\n\n### Code Style\n\n- Uses ESLint with custom configuration (`eslint.config.mjs`)\n- Prettier for formatting\n- Stylelint for CSS\n- No semicolons required (ASI enabled)\n- Single quotes for strings\n\n### Pull Request Process\n\n- Keep PRs focused on a single issue\n- Provide a test PDF if the issue is PDF-specific\n- Ensure tests pass (`npx gulp test`)\n- Run linting (`npx gulp lint`)\n- Follow existing code patterns\n- Don't modify translations directly (they come from Firefox)\n\n### Performance Considerations\n\n- Core parsing runs in a Web Worker - keep main thread work minimal\n- Canvas rendering can be expensive - use appropriate scale factors\n- Text layer generation is separate from rendering - can be deferred\n- Annotation layer is optional - only enable when needed\n"},"files":{"AGENTS.md":"## Overview\n\nPDF.js is a Portable Document Format (PDF) viewer built with JavaScript, HTML5 Canvas, and CSS. It's a Mozilla project that provides a general-purpose, web standards-based platform for parsing and rendering PDFs without requiring native code or plugins.\n\n## Common Commands\n\n### Development Server\n```bash\nnpx gulp server\n```\nThen open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame\n\n### Building\n\nBuild for modern browsers:\n```bash\nnpx gulp generic\n```\n\nThis generates `pdf.js` and `pdf.worker.js` in `build/generic/build/`.\n\nBuild for distribution (creates pdfjs-dist package):\n```bash\nnpx gulp dist\nnpx gulp dist-install    # Build and install locally\n```\n\n### Testing\n\nRun all tests:\n```bash\nnpx gulp test\n```\n\nRun unit tests only:\n```bash\nnpx gulp unittest\n```\n\nRun integration tests (browser-based tests using Puppeteer):\n```bash\nnpx gulp integrationtest\n```\n\nRun font tests:\n```bash\nnpx gulp fonttest\n```\n\nRun a single test file by modifying test/test_manifest.json or using test runner options.\n\n### Linting and Formatting\n\nLint JavaScript:\n```bash\nnpx gulp lint\n```\n\nFormat code (uses Prettier and ESLint):\n```bash\nnpx eslint --fix <file>\n```\n\n### Type Checking\n\nRun TypeScript type checking:\n```bash\nnpx gulp typestest\n```\n\n## Architecture\n\n### High-Level Structure\n\nPDF.js has a multi-layer architecture that separates concerns between PDF parsing, rendering, and UI:\n\n#### 1. Core Layer (`src/core/`)\nThe core layer handles PDF parsing and interpretation. Key responsibilities:\n- **PDF parsing**: Parsing PDF structure, cross-reference tables, streams\n- **Font handling**: CFF, TrueType, Type1 font parsing and conversion (`font.js`, `fonts.js`, `cff_*.js`, `type1_*.js`)\n- **Image decoding**: JPEG, JBIG2, JPX/JPEG2000 decoders\n- **Operators**: Processing PDF drawing operators (`operator_list.js`, `evaluator.js`)\n- **XFA Forms**: XML Forms Architecture support (`src/core/xfa/`)\n- **Color spaces**: ICC profiles, device color spaces (`colorspace.js`, `icc_colorspace.js`)\n- Runs in a Web Worker for performance isolation\n\nEntry point: `src/pdf.worker.js`\n\n#### 2. Display Layer (`src/display/`)\nThe display layer provides the API for rendering PDFs to canvas and managing documents. Key components:\n- **API**: Main public API (`api.js`) - `PDFDocumentProxy`, `PDFPageProxy`, `getDocument()`\n- **Canvas rendering**: Renders PDF operations to HTML5 canvas (`canvas.js`)\n- **Text layer**: Extracts and positions text for selection/search (`text_layer.js`)\n- **Annotation layer**: Renders and handles PDF annotations (`annotation_layer.js`)\n- **Editor layer**: Supports PDF editing (annotations, highlights, stamps) (`editor/`)\n- **Metadata**: Parses XMP metadata (`metadata.js`)\n- **Streams**: Handles PDF data fetching (fetch, network, node) (`fetch_stream.js`, `network.js`, `node_stream.js`)\n\nEntry point: `src/pdf.js`\n\n#### 3. Scripting Layer (`src/scripting_api/`)\nImplements JavaScript execution for interactive PDFs (form calculations, validations, button actions).\n- Sandboxed execution environment\n- Implements Acrobat JavaScript API objects (App, Doc, Field, etc.)\n\nEntry points: `src/pdf.scripting.js`, `src/pdf.sandbox.js`\n\n#### 4. Web Viewer (`web/`)\nThe complete PDF viewer application with UI. Key components:\n- **Main app**: Application orchestration (`app.js`)\n- **Viewer**: Page rendering and layout (`pdf_viewer.js`, `pdf_page_view.js`)\n- **Toolbar**: Zoom, page navigation, print, download controls\n- **Sidebar**: Thumbnails, outlines, attachments (`pdf_sidebar.js`, `pdf_thumbnail_view.js`, `pdf_outline_viewer.js`)\n- **Find controller**: Text search functionality (`pdf_find_controller.js`)\n- **Annotation editors**: UI for creating/editing annotations (`annotation_editor_layer_builder.js`)\n- **Presentation mode**: Full-screen presentation (`pdf_presentation_mode.js`)\n\nEntry point: `web/viewer.html` + `web/viewer.mjs`\n\n#### 5. Shared Utilities (`src/shared/`)\nCommon utilities used across layers:\n- **Message handling**: Worker communication (`message_handler.js`)\n- **Utilities**: Common functions and constants (`util.js`)\n- **Image utilities**: Image processing helpers (`image_utils.js`)\n\n### Worker Communication\n\nPDF.js uses a Web Worker architecture:\n- Main thread (`display` layer) communicates with worker thread (`core` layer) via `MessageHandler`\n- Keeps PDF parsing off the main thread for better performance\n- Messages include: page rendering requests, text content extraction, metadata queries\n\n### Build System\n\n- Uses **Gulp** for build orchestration (`gulpfile.mjs`)\n- **Webpack** bundles modules into browser-compatible formats\n- **Babel** transpiles for browser compatibility (configurable targets in gulpfile)\n- Preprocessor replaces build-time constants (e.g., `typeof PDFJSDev !== \"undefined\"` checks)\n- Multiple build targets: generic, components, minified, legacy (older browser support)\n\n### External Dependencies\n\nLocated in `external/`:\n- **bcmaps**: Binary CMaps for CJK fonts\n- **standard_fonts**: Core 14 PDF fonts metrics\n- **cmapscompress**: Tools for compressing CMaps\n- **openjpeg**: JPEG2000 decoder (WASM)\n- **quickjs**: JavaScript engine for sandboxed execution\n\n### Translations\n\nTranslations in `l10n/` are imported from Mozilla Firefox Nightly. Only the file l10n/en-US/viewer.ftl can be updated.\n\n## Development Notes\n\n### Adding New Features\n\nWhen adding features that span multiple layers:\n1. Start with the `core` layer if parsing/interpretation changes are needed\n2. Update the `display` layer API if new capabilities need exposure\n3. Modify the `web` viewer if UI changes are required\n4. Ensure worker communication handles new message types\n\n### Preprocessor Directives\n\nCode uses preprocessor checks for build-time conditionals:\n```javascript\nif (typeof PDFJSDev !== \"undefined\" && PDFJSDev.test(\"GENERIC\")) {\n  // Generic build-specific code\n}\n```\n\nCommon flags: `GENERIC`, `MOZCENTRAL`, `CHROME`, `MINIFIED`, `TESTING`, `LIB`, `SKIP_BABEL`, `IMAGE_DECODERS`\n\n### Testing\n\n- Unit tests use Jasmine framework (`test/unit/`)\n- Integration tests use Puppeteer for browser automation (`test/integration/`)\n- Test PDFs downloaded from manifest (`test/test_manifest.json`)\n- Reference images for visual regression testing (`test/ref/`)\n\n### Code Style\n\n- Uses ESLint with custom configuration (`eslint.config.mjs`)\n- Prettier for formatting\n- Stylelint for CSS\n- No semicolons required (ASI enabled)\n- Single quotes for strings\n\n### Pull Request Process\n\n- Keep PRs focused on a single issue\n- Provide a test PDF if the issue is PDF-specific\n- Ensure tests pass (`npx gulp test`)\n- Run linting (`npx gulp lint`)\n- Follow existing code patterns\n- Don't modify translations directly (they come from Firefox)\n\n### Performance Considerations\n\n- Core parsing runs in a Web Worker - keep main thread work minimal\n- Canvas rendering can be expensive - use appropriate scale factors\n- Text layer generation is separate from rendering - can be deferred\n- Annotation layer is optional - only enable when needed\n"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","title":"AGENTS.md","content":"## Overview\n\nPDF.js is a Portable Document Format (PDF) viewer built with JavaScript, HTML5 Canvas, and CSS. It's a Mozilla project that provides a general-purpose, web standards-based platform for parsing and rendering PDFs without requiring native code or plugins.\n\n## Common Commands\n\n### Development Server\n```bash\nnpx gulp server\n```\nThen open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame\n\n### Building\n\nBuild for modern browsers:\n```bash\nnpx gulp generic\n```\n\nThis generates `pdf.js` and `pdf.worker.js` in `build/generic/build/`.\n\nBuild for distribution (creates pdfjs-dist package):\n```bash\nnpx gulp dist\nnpx gulp dist-install    # Build and install locally\n```\n\n### Testing\n\nRun all tests:\n```bash\nnpx gulp test\n```\n\nRun unit tests only:\n```bash\nnpx gulp unittest\n```\n\nRun integration tests (browser-based tests using Puppeteer):\n```bash\nnpx gulp integrationtest\n```\n\nRun font tests:\n```bash\nnpx gulp fonttest\n```\n\nRun a single test file by modifying test/test_manifest.json or using test runner options.\n\n### Linting and Formatting\n\nLint JavaScript:\n```bash\nnpx gulp lint\n```\n\nFormat code (uses Prettier and ESLint):\n```bash\nnpx eslint --fix <file>\n```\n\n### Type Checking\n\nRun TypeScript type checking:\n```bash\nnpx gulp typestest\n```\n\n## Architecture\n\n### High-Level Structure\n\nPDF.js has a multi-layer architecture that separates concerns between PDF parsing, rendering, and UI:\n\n#### 1. Core Layer (`src/core/`)\nThe core layer handles PDF parsing and interpretation. Key responsibilities:\n- **PDF parsing**: Parsing PDF structure, cross-reference tables, streams\n- **Font handling**: CFF, TrueType, Type1 font parsing and conversion (`font.js`, `fonts.js`, `cff_*.js`, `type1_*.js`)\n- **Image decoding**: JPEG, JBIG2, JPX/JPEG2000 decoders\n- **Operators**: Processing PDF drawing operators (`operator_list.js`, `evaluator.js`)\n- **XFA Forms**: XML Forms Architecture support (`src/core/xfa/`)\n- **Color spaces**: ICC profiles, device color spaces (`colorspace.js`, `icc_colorspace.js`)\n- Runs in a Web Worker for performance isolation\n\nEntry point: `src/pdf.worker.js`\n\n#### 2. Display Layer (`src/display/`)\nThe display layer provides the API for rendering PDFs to canvas and managing documents. Key components:\n- **API**: Main public API (`api.js`) - `PDFDocumentProxy`, `PDFPageProxy`, `getDocument()`\n- **Canvas rendering**: Renders PDF operations to HTML5 canvas (`canvas.js`)\n- **Text layer**: Extracts and positions text for selection/search (`text_layer.js`)\n- **Annotation layer**: Renders and handles PDF annotations (`annotation_layer.js`)\n- **Editor layer**: Supports PDF editing (annotations, highlights, stamps) (`editor/`)\n- **Metadata**: Parses XMP metadata (`metadata.js`)\n- **Streams**: Handles PDF data fetching (fetch, network, node) (`fetch_stream.js`, `network.js`, `node_stream.js`)\n\nEntry point: `src/pdf.js`\n\n#### 3. Scripting Layer (`src/scripting_api/`)\nImplements JavaScript execution for interactive PDFs (form calculations, validations, button actions).\n- Sandboxed execution environment\n- Implements Acrobat JavaScript API objects (App, Doc, Field, etc.)\n\nEntry points: `src/pdf.scripting.js`, `src/pdf.sandbox.js`\n\n#### 4. Web Viewer (`web/`)\nThe complete PDF viewer application with UI. Key components:\n- **Main app**: Application orchestration (`app.js`)\n- **Viewer**: Page rendering and layout (`pdf_viewer.js`, `pdf_page_view.js`)\n- **Toolbar**: Zoom, page navigation, print, download controls\n- **Sidebar**: Thumbnails, outlines, attachments (`pdf_sidebar.js`, `pdf_thumbnail_view.js`, `pdf_outline_viewer.js`)\n- **Find controller**: Text search functionality (`pdf_find_controller.js`)\n- **Annotation editors**: UI for creating/editing annotations (`annotation_editor_layer_builder.js`)\n- **Presentation mode**: Full-screen presentation (`pdf_presentation_mode.js`)\n\nEntry point: `web/viewer.html` + `web/viewer.mjs`\n\n#### 5. Shared Utilities (`src/shared/`)\nCommon utilities used across layers:\n- **Message handling**: Worker communication (`message_handler.js`)\n- **Utilities**: Common functions and constants (`util.js`)\n- **Image utilities**: Image processing helpers (`image_utils.js`)\n\n### Worker Communication\n\nPDF.js uses a Web Worker architecture:\n- Main thread (`display` layer) communicates with worker thread (`core` layer) via `MessageHandler`\n- Keeps PDF parsing off the main thread for better performance\n- Messages include: page rendering requests, text content extraction, metadata queries\n\n### Build System\n\n- Uses **Gulp** for build orchestration (`gulpfile.mjs`)\n- **Webpack** bundles modules into browser-compatible formats\n- **Babel** transpiles for browser compatibility (configurable targets in gulpfile)\n- Preprocessor replaces build-time constants (e.g., `typeof PDFJSDev !== \"undefined\"` checks)\n- Multiple build targets: generic, components, minified, legacy (older browser support)\n\n### External Dependencies\n\nLocated in `external/`:\n- **bcmaps**: Binary CMaps for CJK fonts\n- **standard_fonts**: Core 14 PDF fonts metrics\n- **cmapscompress**: Tools for compressing CMaps\n- **openjpeg**: JPEG2000 decoder (WASM)\n- **quickjs**: JavaScript engine for sandboxed execution\n\n### Translations\n\nTranslations in `l10n/` are imported from Mozilla Firefox Nightly. Only the file l10n/en-US/viewer.ftl can be updated.\n\n## Development Notes\n\n### Adding New Features\n\nWhen adding features that span multiple layers:\n1. Start with the `core` layer if parsing/interpretation changes are needed\n2. Update the `display` layer API if new capabilities need exposure\n3. Modify the `web` viewer if UI changes are required\n4. Ensure worker communication handles new message types\n\n### Preprocessor Directives\n\nCode uses preprocessor checks for build-time conditionals:\n```javascript\nif (typeof PDFJSDev !== \"undefined\" && PDFJSDev.test(\"GENERIC\")) {\n  // Generic build-specific code\n}\n```\n\nCommon flags: `GENERIC`, `MOZCENTRAL`, `CHROME`, `MINIFIED`, `TESTING`, `LIB`, `SKIP_BABEL`, `IMAGE_DECODERS`\n\n### Testing\n\n- Unit tests use Jasmine framework (`test/unit/`)\n- Integration tests use Puppeteer for browser automation (`test/integration/`)\n- Test PDFs downloaded from manifest (`test/test_manifest.json`)\n- Reference images for visual regression testing (`test/ref/`)\n\n### Code Style\n\n- Uses ESLint with custom configuration (`eslint.config.mjs`)\n- Prettier for formatting\n- Stylelint for CSS\n- No semicolons required (ASI enabled)\n- Single quotes for strings\n\n### Pull Request Process\n\n- Keep PRs focused on a single issue\n- Provide a test PDF if the issue is PDF-specific\n- Ensure tests pass (`npx gulp test`)\n- Run linting (`npx gulp lint`)\n- Follow existing code patterns\n- Don't modify translations directly (they come from Firefox)\n\n### Performance Considerations\n\n- Core parsing runs in a Web Worker - keep main thread work minimal\n- Canvas rendering can be expensive - use appropriate scale factors\n- Text layer generation is separate from rendering - can be deferred\n- Annotation layer is optional - only enable when needed\n","category":"root","tokens":1769}]}