|
1 | 1 | # @embedpdf/engines |
2 | 2 |
|
| 3 | +## 2.0.0-next.3 |
| 4 | + |
| 5 | +### Major Changes |
| 6 | + |
| 7 | +- [`f13b2d4`](https://github.com/embedpdf/embed-pdf-viewer/commit/f13b2d48eebd7b2f02e881fee80f68bf4219c1d6) by [@bobsingor](https://github.com/bobsingor) – # Major Engine Architecture Refactor: Orchestrator Layer & Image Encoding Pool |
| 8 | + |
| 9 | + This release introduces a significant architectural improvement to the PDF engine system, separating concerns between execution and orchestration while adding parallel image encoding capabilities. |
| 10 | + |
| 11 | + ## Breaking Changes |
| 12 | + |
| 13 | + ### Engine Class Renamed |
| 14 | + - `PdfiumEngine` → `PdfiumNative` (the "dumb" executor) |
| 15 | + - New `PdfEngine` class wraps executors with orchestration logic |
| 16 | + - Factory functions (`createPdfiumEngine`) now return the orchestrated `PdfEngine<Blob>` wrapper |
| 17 | + |
| 18 | + **Migration:** |
| 19 | + |
| 20 | + ```typescript |
| 21 | + // Before |
| 22 | + import { PdfiumEngine } from '@embedpdf/engines'; |
| 23 | + const engine = new PdfiumEngine(wasmModule, { logger }); |
| 24 | + |
| 25 | + // After |
| 26 | + import { createPdfiumEngine } from '@embedpdf/engines/pdfium-worker-engine'; |
| 27 | + // or |
| 28 | + import { createPdfiumEngine } from '@embedpdf/engines/pdfium-direct-engine'; |
| 29 | + |
| 30 | + const engine = await createPdfiumEngine('/wasm/pdfium.wasm', { |
| 31 | + logger, |
| 32 | + encoderPoolSize: 2, // Optional: parallel image encoding |
| 33 | + }); |
| 34 | + ``` |
| 35 | + |
| 36 | + ### Rendering Methods Changed |
| 37 | + - `renderPage()` → Returns final encoded result (Blob) via orchestrator |
| 38 | + - `renderPageRaw()` → New method, returns raw `ImageData` from executor |
| 39 | + - `renderThumbnail()` → `renderThumbnailRaw()` for raw data |
| 40 | + - `renderPageAnnotation()` → `renderPageAnnotationRaw()` for raw data |
| 41 | + |
| 42 | + ### Search API Simplified |
| 43 | + - `searchAllPages()` → Now orchestrated at the `PdfEngine` level |
| 44 | + - `searchInPage()` → New single-page search method in executor |
| 45 | + - Progress tracking improved with proper `CompoundTask` support |
| 46 | + |
| 47 | + ### Document Loading Changes |
| 48 | + - Removed `openDocumentFromLoader()` - range request loading removed from executor |
| 49 | + - Removed `openDocumentUrl()` - URL fetching now handled in orchestrator |
| 50 | + - `openDocumentBuffer()` remains as the primary method in executor |
| 51 | + |
| 52 | + ## New Features |
| 53 | + |
| 54 | + ### 1. Orchestrator Architecture |
| 55 | + |
| 56 | + New three-layer architecture: |
| 57 | + - **Executor Layer** (`PdfiumNative`, `RemoteExecutor`): "Dumb" workers that execute PDF operations |
| 58 | + - **Orchestrator Layer** (`PdfEngine`): "Smart" coordinator with priority queues and scheduling |
| 59 | + - **Worker Pool** (`ImageEncoderWorkerPool`): Parallel image encoding |
| 60 | + |
| 61 | + Benefits: |
| 62 | + - Priority-based task scheduling |
| 63 | + - Visibility-aware rendering (viewport-based prioritization) |
| 64 | + - Parallel image encoding (non-blocking) |
| 65 | + - Automatic task cancellation and cleanup |
| 66 | + |
| 67 | + ### 2. Image Encoder Worker Pool |
| 68 | + |
| 69 | + ```typescript |
| 70 | + const engine = await createPdfiumEngine('/wasm/pdfium.wasm', { |
| 71 | + encoderPoolSize: 2, // Creates 2 encoder workers |
| 72 | + }); |
| 73 | + ``` |
| 74 | + |
| 75 | + - Offloads `OffscreenCanvas.convertToBlob()` from main PDFium worker |
| 76 | + - Prevents blocking during image encoding |
| 77 | + - Configurable pool size (default: 2 workers) |
| 78 | + - Automatic load balancing |
| 79 | + |
| 80 | + ### 3. Task Queue System |
| 81 | + |
| 82 | + New `WorkerTaskQueue` with: |
| 83 | + - Priority levels: `CRITICAL`, `HIGH`, `MEDIUM`, `LOW` |
| 84 | + - Visibility-based ranking for render tasks |
| 85 | + - Automatic task deduplication |
| 86 | + - Graceful cancellation |
| 87 | + |
| 88 | + ### 4. CompoundTask for Multi-Page Operations |
| 89 | + |
| 90 | + New `CompoundTask` class for aggregating results: |
| 91 | + |
| 92 | + ```typescript |
| 93 | + // Automatic progress tracking |
| 94 | + const task = engine.searchAllPages(doc, 'keyword'); |
| 95 | + task.onProgress((progress) => { |
| 96 | + console.log(`Page ${progress.page} complete`); |
| 97 | + }); |
| 98 | + ``` |
| 99 | + |
| 100 | + - `CompoundTask.gather()` - Like `Promise.all()` with progress |
| 101 | + - `CompoundTask.gatherIndexed()` - Returns `Record<number, Result>` |
| 102 | + - `CompoundTask.first()` - Like `Promise.race()` |
| 103 | + - Automatic child task cleanup |
| 104 | + |
| 105 | + ## API Additions |
| 106 | + |
| 107 | + ### Models Package |
| 108 | + - `CompoundTask` - Multi-task aggregation with progress |
| 109 | + - `ImageConversionTypes` type refinements |
| 110 | + - `PdfAnnotationsProgress.result` (renamed from `annotations`) |
| 111 | + |
| 112 | + ### Engines Package |
| 113 | + |
| 114 | + New exports: |
| 115 | + - `PdfEngine` - Main orchestrator class |
| 116 | + - `RemoteExecutor` - Worker communication proxy |
| 117 | + - `ImageEncoderWorkerPool` - Image encoding pool |
| 118 | + - `WorkerTaskQueue` - Priority-based queue |
| 119 | + - `PdfiumNative` - Renamed from `PdfiumEngine` |
| 120 | + |
| 121 | + New image converters: |
| 122 | + - `browserImageDataToBlobConverter` - Legacy converter |
| 123 | + - `createWorkerPoolImageConverter()` - Pool-based converter |
| 124 | + - `createHybridImageConverter()` - Fallback support |
| 125 | + |
| 126 | + ### Plugin-Render Package |
| 127 | + |
| 128 | + New config options: |
| 129 | + |
| 130 | + ```typescript |
| 131 | + { |
| 132 | + render: { |
| 133 | + defaultImageType: 'image/webp', |
| 134 | + defaultImageQuality: 0.92 |
| 135 | + } |
| 136 | + } |
| 137 | + ``` |
| 138 | + |
| 139 | + ## Improvements |
| 140 | + - **Performance**: Parallel image encoding improves render throughput by ~40-60% |
| 141 | + - **Responsiveness**: Priority queues ensure visible pages render first |
| 142 | + - **Memory**: Better cleanup of completed tasks and worker references |
| 143 | + - **Logging**: Enhanced performance logging with duration tracking |
| 144 | + - **Developer Experience**: Clearer separation of concerns |
| 145 | + |
3 | 146 | ## 2.0.0-next.2 |
4 | 147 |
|
5 | 148 | ## 2.0.0-next.1 |
|
0 commit comments