|
| 1 | +--- |
| 2 | +'@embedpdf/engines': major |
| 3 | +'@embedpdf/models': major |
| 4 | +'@embedpdf/core': minor |
| 5 | +--- |
| 6 | + |
| 7 | +# Remove `initialize()` - PDFium Now Initializes in Constructor |
| 8 | + |
| 9 | +This release removes the `initialize()` method from all engine classes. PDFium is now automatically initialized in the constructor, simplifying the API and reducing boilerplate. |
| 10 | + |
| 11 | +## Breaking Changes |
| 12 | + |
| 13 | +### `initialize()` Method Removed |
| 14 | + |
| 15 | +The `initialize()` method has been removed from: |
| 16 | + |
| 17 | +- `PdfiumNative` (formerly `PdfiumEngine`) |
| 18 | +- `PdfEngine` orchestrator |
| 19 | +- `RemoteExecutor` |
| 20 | +- `WebWorkerEngine` |
| 21 | +- `IPdfiumExecutor` interface |
| 22 | +- `PdfEngine` interface (in models) |
| 23 | + |
| 24 | +**Migration:** |
| 25 | + |
| 26 | +```typescript |
| 27 | +// Before |
| 28 | +const native = new PdfiumNative(wasmModule, { logger }); |
| 29 | +native.initialize(); |
| 30 | + |
| 31 | +const engine = new PdfEngine(native, { imageConverter, logger }); |
| 32 | +engine.initialize(); |
| 33 | + |
| 34 | +// After - no initialize() needed! |
| 35 | +const native = new PdfiumNative(wasmModule, { logger }); |
| 36 | +const engine = new PdfEngine(native, { imageConverter, logger }); |
| 37 | + |
| 38 | +// Ready to use immediately |
| 39 | +const doc = await engine.openDocumentBuffer(file).toPromise(); |
| 40 | +``` |
| 41 | + |
| 42 | +### Framework Hooks Simplified |
| 43 | + |
| 44 | +The `usePdfiumEngine` hooks (React, Vue, Svelte) no longer require calling `initialize()`: |
| 45 | + |
| 46 | +```typescript |
| 47 | +// Before |
| 48 | +const { engine, isLoading } = usePdfiumEngine(); |
| 49 | +const [initialized, setInitialized] = useState(false); |
| 50 | + |
| 51 | +useEffect(() => { |
| 52 | + if (engine && !initialized) { |
| 53 | + engine.initialize().wait(setInitialized, ignore); |
| 54 | + } |
| 55 | +}, [engine, initialized]); |
| 56 | + |
| 57 | +// After - engine is ready when returned! |
| 58 | +const { engine, isLoading } = usePdfiumEngine(); |
| 59 | + |
| 60 | +if (!isLoading && engine) { |
| 61 | + // Ready to use immediately |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### `PluginRegistry.ensureEngineInitialized()` Removed |
| 66 | + |
| 67 | +The `ensureEngineInitialized()` method and `engineInitialized` property have been removed from `PluginRegistry` since engines are now initialized in their constructors. |
| 68 | + |
| 69 | +## Cross-Platform Image Data |
| 70 | + |
| 71 | +### `ImageData` → `ImageDataLike` |
| 72 | + |
| 73 | +The engine now returns `ImageDataLike` (a plain object with `data`, `width`, `height`) instead of the browser-specific `ImageData` class. This enables Node.js compatibility without polyfills. |
| 74 | + |
| 75 | +**Affected types:** |
| 76 | + |
| 77 | +- `PdfImageObject.imageData` now uses `ImageDataLike` |
| 78 | +- All raw render methods return `ImageDataLike` |
| 79 | + |
| 80 | +### Browser Converter Fallback |
| 81 | + |
| 82 | +`browserImageDataToBlobConverter` now falls back to regular `<canvas>` when `OffscreenCanvas` is not available (older browsers). The hybrid converter (`createHybridImageConverter`) uses: |
| 83 | + |
| 84 | +1. Worker pool with `OffscreenCanvas` (preferred, non-blocking) |
| 85 | +2. Main-thread `<canvas>` fallback (blocking, but works everywhere) |
| 86 | + |
| 87 | +## Benefits |
| 88 | + |
| 89 | +- **Simpler API**: One less step to get started |
| 90 | +- **Less boilerplate**: No more `initialize()` calls in every component |
| 91 | +- **Node.js compatible**: `ImageDataLike` works without browser APIs |
| 92 | +- **Broader browser support**: Canvas fallback for older browsers |
0 commit comments