@embedpdf/engines 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/direct-engine-BeZ18SKz.cjs +2 -0
  2. package/dist/direct-engine-BeZ18SKz.cjs.map +1 -0
  3. package/dist/{direct-engine-CHrj3o_a.js → direct-engine-CB3k-o0I.js} +509 -9
  4. package/dist/direct-engine-CB3k-o0I.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +11 -4
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/orchestrator/remote-executor.d.ts +5 -0
  10. package/dist/lib/pdfium/cdn-fonts.d.ts +50 -0
  11. package/dist/lib/pdfium/engine.d.ts +17 -2
  12. package/dist/lib/pdfium/font-fallback.d.ts +207 -0
  13. package/dist/lib/pdfium/index.cjs +1 -1
  14. package/dist/lib/pdfium/index.cjs.map +1 -1
  15. package/dist/lib/pdfium/index.d.ts +2 -0
  16. package/dist/lib/pdfium/index.js +55 -2
  17. package/dist/lib/pdfium/index.js.map +1 -1
  18. package/dist/lib/pdfium/runner.d.ts +5 -1
  19. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  20. package/dist/lib/pdfium/web/direct-engine.d.ts +8 -0
  21. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  22. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  23. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  24. package/dist/lib/pdfium/web/worker-engine.d.ts +8 -0
  25. package/dist/lib/pdfium/web/worker-engine.js +5 -4
  26. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  27. package/dist/preact/index.cjs +1 -1
  28. package/dist/preact/index.cjs.map +1 -1
  29. package/dist/preact/index.js +14 -4
  30. package/dist/preact/index.js.map +1 -1
  31. package/dist/react/index.cjs +1 -1
  32. package/dist/react/index.cjs.map +1 -1
  33. package/dist/react/index.js +14 -4
  34. package/dist/react/index.js.map +1 -1
  35. package/dist/shared-preact/hooks/use-pdfium-engine.d.ts +5 -0
  36. package/dist/shared-react/hooks/use-pdfium-engine.d.ts +5 -0
  37. package/dist/svelte/hooks/use-pdfium-engine.svelte.d.ts +5 -0
  38. package/dist/svelte/index.cjs +1 -1
  39. package/dist/svelte/index.cjs.map +1 -1
  40. package/dist/svelte/index.js +8 -3
  41. package/dist/svelte/index.js.map +1 -1
  42. package/dist/vue/composables/use-pdfium-engine.d.ts +5 -0
  43. package/dist/vue/index.cjs +1 -1
  44. package/dist/vue/index.cjs.map +1 -1
  45. package/dist/vue/index.js +4 -4
  46. package/dist/vue/index.js.map +1 -1
  47. package/package.json +10 -3
  48. package/dist/direct-engine-B7b7cTsH.cjs +0 -2
  49. package/dist/direct-engine-B7b7cTsH.cjs.map +0 -1
  50. package/dist/direct-engine-CHrj3o_a.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"worker-engine.js","sources":["../../../../src/lib/orchestrator/remote-executor.ts","../../../../src/lib/image-encoder/worker-pool.ts"],"sourcesContent":["import {\n BatchProgress,\n Logger,\n NoopLogger,\n PdfDocumentObject,\n PdfPageObject,\n PdfTask,\n PdfErrorReason,\n PdfFile,\n PdfOpenDocumentBufferOptions,\n PdfMetadataObject,\n PdfBookmarksObject,\n PdfBookmarkObject,\n PdfRenderPageOptions,\n PdfRenderThumbnailOptions,\n PdfRenderPageAnnotationOptions,\n PdfAnnotationObject,\n PdfTextRectObject,\n PdfAttachmentObject,\n PdfAddAttachmentParams,\n PdfWidgetAnnoObject,\n FormFieldValue,\n PdfFlattenPageOptions,\n PdfPageFlattenResult,\n PdfRedactTextOptions,\n Rect,\n PageTextSlice,\n PdfGlyphObject,\n PdfPageGeometry,\n PdfPrintOptions,\n PdfSignatureObject,\n AnnotationCreateContext,\n Task,\n TaskError,\n PdfErrorCode,\n SearchResult,\n serializeLogger,\n IPdfiumExecutor,\n ImageDataLike,\n} from '@embedpdf/models';\nimport type { WorkerRequest, WorkerResponse } from './pdfium-native-runner';\n\n/**\n * Options for creating a RemoteExecutor\n */\nexport interface RemoteExecutorOptions {\n /**\n * URL to the pdfium.wasm file (required)\n */\n wasmUrl: string;\n /**\n * Logger instance for debugging\n */\n logger?: Logger;\n}\n\nconst LOG_SOURCE = 'RemoteExecutor';\nconst LOG_CATEGORY = 'Worker';\n\n/**\n * Message types for worker communication\n */\ntype MessageType =\n | 'destroy'\n | 'openDocumentBuffer'\n | 'getMetadata'\n | 'setMetadata'\n | 'getDocPermissions'\n | 'getDocUserPermissions'\n | 'getSignatures'\n | 'getBookmarks'\n | 'setBookmarks'\n | 'deleteBookmarks'\n | 'renderPageRaw'\n | 'renderPageRect'\n | 'renderThumbnailRaw'\n | 'renderPageAnnotationRaw'\n | 'getPageAnnotations'\n | 'getPageAnnotationsRaw'\n | 'createPageAnnotation'\n | 'updatePageAnnotation'\n | 'removePageAnnotation'\n | 'getPageTextRects'\n | 'searchInPage'\n | 'getAnnotationsBatch'\n | 'searchBatch'\n | 'getAttachments'\n | 'addAttachment'\n | 'removeAttachment'\n | 'readAttachmentContent'\n | 'setFormFieldValue'\n | 'flattenPage'\n | 'extractPages'\n | 'extractText'\n | 'redactTextInRects'\n | 'getTextSlices'\n | 'getPageGlyphs'\n | 'getPageGeometry'\n | 'merge'\n | 'mergePages'\n | 'preparePrintDocument'\n | 'saveAsCopy'\n | 'closeDocument'\n | 'closeAllDocuments';\n\n/**\n * RemoteExecutor - Proxy for worker communication\n *\n * This implements IPdfExecutor but forwards all calls to a Web Worker.\n * It handles:\n * - Serialization/deserialization of messages\n * - Promise/Task conversion\n * - Error handling\n * - Progress tracking\n */\nexport class RemoteExecutor implements IPdfiumExecutor {\n private static READY_TASK_ID = '0';\n private pendingRequests = new Map<string, Task<any, any>>();\n private requestCounter = 0;\n private logger: Logger;\n private readyTask: Task<boolean, PdfErrorReason>;\n\n constructor(\n private worker: Worker,\n options: RemoteExecutorOptions,\n ) {\n this.logger = options.logger ?? new NoopLogger();\n this.worker.addEventListener('message', this.handleMessage);\n\n // Create ready task - will be resolved when worker sends 'ready'\n this.readyTask = new Task<boolean, PdfErrorReason>();\n this.pendingRequests.set(RemoteExecutor.READY_TASK_ID, this.readyTask);\n\n // Send initialization message with WASM URL\n this.worker.postMessage({\n id: RemoteExecutor.READY_TASK_ID,\n type: 'wasmInit',\n wasmUrl: options.wasmUrl,\n logger: options.logger ? serializeLogger(options.logger) : undefined,\n });\n\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'RemoteExecutor created');\n }\n\n /**\n * Generate unique request ID\n */\n private generateId(): string {\n return `req-${Date.now()}-${this.requestCounter++}`;\n }\n\n /**\n * Send a message to the worker and return a Task\n * Waits for worker to be ready before sending\n */\n private send<T, P = unknown>(method: MessageType, args: any[]): Task<T, PdfErrorReason, P> {\n const id = this.generateId();\n const task = new Task<T, PdfErrorReason, P>();\n\n const request: WorkerRequest = {\n id,\n type: 'execute',\n method,\n args,\n };\n\n // Wait for worker to be ready before sending\n this.readyTask.wait(\n () => {\n this.pendingRequests.set(id, task);\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Sending ${method} request:`, id);\n this.worker.postMessage(request);\n },\n (error) => {\n this.logger.error(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Worker init failed, rejecting ${method}:`,\n error,\n );\n task.reject({\n code: PdfErrorCode.Initialization,\n message: 'Worker initialization failed',\n });\n },\n );\n\n return task;\n }\n\n /**\n * Handle messages from worker\n */\n private handleMessage = (event: MessageEvent<WorkerResponse>) => {\n const response = event.data;\n\n // Handle ready response - resolve the readyTask\n if (response.type === 'ready') {\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Worker is ready');\n this.readyTask.resolve(true);\n return;\n }\n\n const task = this.pendingRequests.get(response.id);\n\n if (!task) {\n this.logger.warn(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received response for unknown request: ${response.id}`,\n );\n return;\n }\n\n switch (response.type) {\n case 'result':\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Received result for ${response.id}`);\n task.resolve(response.data);\n this.pendingRequests.delete(response.id);\n break;\n\n case 'error':\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received error for ${response.id}:`,\n response.error,\n );\n if (response.error) {\n task.fail(response.error);\n } else {\n task.reject({ code: PdfErrorCode.Unknown, message: 'Unknown error' });\n }\n this.pendingRequests.delete(response.id);\n break;\n\n case 'progress':\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Received progress for ${response.id}`);\n task.progress(response.progress);\n break;\n }\n };\n\n /**\n * Cleanup and terminate worker\n */\n destroy(): void {\n this.worker.removeEventListener('message', this.handleMessage);\n\n // Reject all pending requests (except readyTask)\n this.pendingRequests.forEach((task, id) => {\n if (id !== RemoteExecutor.READY_TASK_ID) {\n task.abort('Worker destroyed');\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Aborted pending request: ${id}`);\n }\n });\n this.pendingRequests.clear();\n\n this.worker.terminate();\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'RemoteExecutor destroyed');\n }\n\n // ========== IPdfExecutor Implementation ==========\n\n openDocumentBuffer(\n file: PdfFile,\n options?: PdfOpenDocumentBufferOptions,\n ): PdfTask<PdfDocumentObject> {\n return this.send<PdfDocumentObject>('openDocumentBuffer', [file, options]);\n }\n\n getMetadata(doc: PdfDocumentObject): PdfTask<PdfMetadataObject> {\n return this.send<PdfMetadataObject>('getMetadata', [doc]);\n }\n\n setMetadata(doc: PdfDocumentObject, metadata: Partial<PdfMetadataObject>): PdfTask<boolean> {\n return this.send<boolean>('setMetadata', [doc, metadata]);\n }\n\n getDocPermissions(doc: PdfDocumentObject): PdfTask<number> {\n return this.send<number>('getDocPermissions', [doc]);\n }\n\n getDocUserPermissions(doc: PdfDocumentObject): PdfTask<number> {\n return this.send<number>('getDocUserPermissions', [doc]);\n }\n\n getSignatures(doc: PdfDocumentObject): PdfTask<PdfSignatureObject[]> {\n return this.send<PdfSignatureObject[]>('getSignatures', [doc]);\n }\n\n getBookmarks(doc: PdfDocumentObject): PdfTask<PdfBookmarksObject> {\n return this.send<PdfBookmarksObject>('getBookmarks', [doc]);\n }\n\n setBookmarks(doc: PdfDocumentObject, bookmarks: PdfBookmarkObject[]): PdfTask<boolean> {\n return this.send<boolean>('setBookmarks', [doc, bookmarks]);\n }\n\n deleteBookmarks(doc: PdfDocumentObject): PdfTask<boolean> {\n return this.send<boolean>('deleteBookmarks', [doc]);\n }\n\n renderPageRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfRenderPageOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageRaw', [doc, page, options]);\n }\n\n renderPageRect(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n rect: Rect,\n options?: PdfRenderPageOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageRect', [doc, page, rect, options]);\n }\n\n renderThumbnailRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfRenderThumbnailOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderThumbnailRaw', [doc, page, options]);\n }\n\n renderPageAnnotationRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n options?: PdfRenderPageAnnotationOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageAnnotationRaw', [doc, page, annotation, options]);\n }\n\n getPageAnnotationsRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n ): PdfTask<PdfAnnotationObject[]> {\n return this.send<PdfAnnotationObject[]>('getPageAnnotationsRaw', [doc, page]);\n }\n\n getPageAnnotations(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfAnnotationObject[]> {\n return this.send<PdfAnnotationObject[]>('getPageAnnotations', [doc, page]);\n }\n\n createPageAnnotation<A extends PdfAnnotationObject>(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: A,\n context?: AnnotationCreateContext<A>,\n ): PdfTask<string> {\n return this.send<string>('createPageAnnotation', [doc, page, annotation, context]);\n }\n\n updatePageAnnotation(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ): PdfTask<boolean> {\n return this.send<boolean>('updatePageAnnotation', [doc, page, annotation]);\n }\n\n removePageAnnotation(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ): PdfTask<boolean> {\n return this.send<boolean>('removePageAnnotation', [doc, page, annotation]);\n }\n\n getPageTextRects(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfTextRectObject[]> {\n return this.send<PdfTextRectObject[]>('getPageTextRects', [doc, page]);\n }\n\n searchInPage(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n keyword: string,\n flags: number,\n ): PdfTask<SearchResult[]> {\n return this.send<SearchResult[]>('searchInPage', [doc, page, keyword, flags]);\n }\n\n getAnnotationsBatch(\n doc: PdfDocumentObject,\n pages: PdfPageObject[],\n ): PdfTask<Record<number, PdfAnnotationObject[]>, BatchProgress<PdfAnnotationObject[]>> {\n return this.send<Record<number, PdfAnnotationObject[]>, BatchProgress<PdfAnnotationObject[]>>(\n 'getAnnotationsBatch',\n [doc, pages],\n );\n }\n\n searchBatch(\n doc: PdfDocumentObject,\n pages: PdfPageObject[],\n keyword: string,\n flags: number,\n ): PdfTask<Record<number, SearchResult[]>, BatchProgress<SearchResult[]>> {\n return this.send<Record<number, SearchResult[]>, BatchProgress<SearchResult[]>>('searchBatch', [\n doc,\n pages,\n keyword,\n flags,\n ]);\n }\n\n getAttachments(doc: PdfDocumentObject): PdfTask<PdfAttachmentObject[]> {\n return this.send<PdfAttachmentObject[]>('getAttachments', [doc]);\n }\n\n addAttachment(doc: PdfDocumentObject, params: PdfAddAttachmentParams): PdfTask<boolean> {\n return this.send<boolean>('addAttachment', [doc, params]);\n }\n\n removeAttachment(doc: PdfDocumentObject, attachment: PdfAttachmentObject): PdfTask<boolean> {\n return this.send<boolean>('removeAttachment', [doc, attachment]);\n }\n\n readAttachmentContent(\n doc: PdfDocumentObject,\n attachment: PdfAttachmentObject,\n ): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('readAttachmentContent', [doc, attachment]);\n }\n\n setFormFieldValue(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfWidgetAnnoObject,\n value: FormFieldValue,\n ): PdfTask<boolean> {\n return this.send<boolean>('setFormFieldValue', [doc, page, annotation, value]);\n }\n\n flattenPage(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfFlattenPageOptions,\n ): PdfTask<PdfPageFlattenResult> {\n return this.send<PdfPageFlattenResult>('flattenPage', [doc, page, options]);\n }\n\n extractPages(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('extractPages', [doc, pageIndexes]);\n }\n\n extractText(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<string> {\n return this.send<string>('extractText', [doc, pageIndexes]);\n }\n\n redactTextInRects(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n rects: Rect[],\n options?: PdfRedactTextOptions,\n ): PdfTask<boolean> {\n return this.send<boolean>('redactTextInRects', [doc, page, rects, options]);\n }\n\n getTextSlices(doc: PdfDocumentObject, slices: PageTextSlice[]): PdfTask<string[]> {\n return this.send<string[]>('getTextSlices', [doc, slices]);\n }\n\n getPageGlyphs(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfGlyphObject[]> {\n return this.send<PdfGlyphObject[]>('getPageGlyphs', [doc, page]);\n }\n\n getPageGeometry(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfPageGeometry> {\n return this.send<PdfPageGeometry>('getPageGeometry', [doc, page]);\n }\n\n merge(files: PdfFile[]): PdfTask<PdfFile> {\n return this.send<PdfFile>('merge', [files]);\n }\n\n mergePages(mergeConfigs: Array<{ docId: string; pageIndices: number[] }>): PdfTask<PdfFile> {\n return this.send<PdfFile>('mergePages', [mergeConfigs]);\n }\n\n preparePrintDocument(doc: PdfDocumentObject, options?: PdfPrintOptions): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('preparePrintDocument', [doc, options]);\n }\n\n saveAsCopy(doc: PdfDocumentObject): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('saveAsCopy', [doc]);\n }\n\n closeDocument(doc: PdfDocumentObject): PdfTask<boolean> {\n return this.send<boolean>('closeDocument', [doc]);\n }\n\n closeAllDocuments(): PdfTask<boolean> {\n return this.send<boolean>('closeAllDocuments', []);\n }\n}\n","import { Logger, NoopLogger } from '@embedpdf/models';\nimport type { EncodeImageRequest, EncodeImageResponse } from './image-encoder-worker';\n\nconst LOG_SOURCE = 'ImageEncoderPool';\nconst LOG_CATEGORY = 'Encoder';\n\ninterface EncodingTask {\n resolve: (blob: Blob) => void;\n reject: (error: Error) => void;\n}\n\n/**\n * Pool of image encoding workers to offload OffscreenCanvas operations\n * from the main PDFium worker thread\n */\nexport class ImageEncoderWorkerPool {\n private workers: Worker[] = [];\n private pendingTasks = new Map<string, EncodingTask>();\n private nextWorkerId = 0;\n private requestCounter = 0;\n private logger: Logger;\n\n /**\n * Create a pool of image encoding workers\n * @param poolSize - Number of workers to create (default: 2)\n * @param workerUrl - URL to the worker script\n * @param logger - Logger instance\n */\n constructor(\n private poolSize: number = 2,\n private workerUrl: string,\n logger?: Logger,\n ) {\n this.logger = logger ?? new NoopLogger();\n this.initialize();\n }\n\n /**\n * Initialize the worker pool\n */\n private initialize() {\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Creating worker pool with ${this.poolSize} workers`,\n );\n\n for (let i = 0; i < this.poolSize; i++) {\n try {\n const worker = new Worker(this.workerUrl, { type: 'module' });\n worker.onmessage = this.handleWorkerMessage.bind(this);\n worker.onerror = this.handleWorkerError.bind(this);\n this.workers.push(worker);\n\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Worker ${i} created successfully`);\n } catch (error) {\n this.logger.error(LOG_SOURCE, LOG_CATEGORY, `Failed to create worker ${i}:`, error);\n }\n }\n }\n\n /**\n * Handle messages from workers\n */\n private handleWorkerMessage(event: MessageEvent<EncodeImageResponse>) {\n const response = event.data;\n const task = this.pendingTasks.get(response.id);\n\n if (!task) {\n this.logger.warn(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received response for unknown task: ${response.id}`,\n );\n return;\n }\n\n this.pendingTasks.delete(response.id);\n\n if (response.type === 'result') {\n task.resolve(response.data as Blob);\n } else {\n const errorData = response.data as { message: string };\n task.reject(new Error(errorData.message));\n }\n }\n\n /**\n * Handle worker errors\n */\n private handleWorkerError(error: ErrorEvent) {\n this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'Worker error:', error.message);\n }\n\n /**\n * Get the next available worker using round-robin\n */\n private getNextWorker(): Worker | null {\n if (this.workers.length === 0) {\n return null;\n }\n\n const worker = this.workers[this.nextWorkerId];\n this.nextWorkerId = (this.nextWorkerId + 1) % this.workers.length;\n return worker;\n }\n\n /**\n * Encode ImageData to Blob using a worker from the pool\n * @param imageData - Raw image data\n * @param imageType - Target image format\n * @param quality - Image quality (0-1) for lossy formats\n * @returns Promise that resolves to encoded Blob\n */\n encode(\n imageData: { data: Uint8ClampedArray; width: number; height: number },\n imageType: 'image/png' | 'image/jpeg' | 'image/webp' = 'image/webp',\n quality?: number,\n ): Promise<Blob> {\n return new Promise((resolve, reject) => {\n const worker = this.getNextWorker();\n\n if (!worker) {\n reject(new Error('No workers available in the pool'));\n return;\n }\n\n const requestId = `encode-${Date.now()}-${this.requestCounter++}`;\n this.pendingTasks.set(requestId, { resolve, reject });\n\n const request: EncodeImageRequest = {\n id: requestId,\n type: 'encode',\n data: {\n imageData: {\n data: imageData.data,\n width: imageData.width,\n height: imageData.height,\n },\n imageType,\n quality,\n },\n };\n\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Sending encoding request ${requestId} (${imageData.width}x${imageData.height})`,\n );\n\n // Transfer the buffer for better performance\n worker.postMessage(request, [imageData.data.buffer]);\n });\n }\n\n /**\n * Destroy all workers in the pool\n */\n destroy() {\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Destroying worker pool');\n\n // Reject all pending tasks\n this.pendingTasks.forEach((task, id) => {\n task.reject(new Error('Worker pool destroyed'));\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Rejected pending task: ${id}`);\n });\n this.pendingTasks.clear();\n\n // Terminate all workers\n this.workers.forEach((worker, index) => {\n worker.terminate();\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Worker ${index} terminated`);\n });\n this.workers = [];\n }\n\n /**\n * Get the number of active workers in the pool\n */\n get activeWorkers(): number {\n return this.workers.length;\n }\n\n /**\n * Get the number of pending encoding tasks\n */\n get pendingTasksCount(): number {\n return this.pendingTasks.size;\n }\n}\n"],"names":["LOG_SOURCE","LOG_CATEGORY"],"mappings":";;;AAwDA,MAAMA,eAAa;AACnB,MAAMC,iBAAe;AA0Dd,MAAM,kBAAN,MAAM,gBAA0C;AAAA,EAOrD,YACU,QACR,SACA;AAFQ,SAAA,SAAA;AANV,SAAQ,sCAAsB,IAAA;AAC9B,SAAQ,iBAAiB;AA2EzB,SAAQ,gBAAgB,CAAC,UAAwC;AAC/D,YAAM,WAAW,MAAM;AAGvB,UAAI,SAAS,SAAS,SAAS;AAC7B,aAAK,OAAO,MAAMD,cAAYC,gBAAc,iBAAiB;AAC7D,aAAK,UAAU,QAAQ,IAAI;AAC3B;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,gBAAgB,IAAI,SAAS,EAAE;AAEjD,UAAI,CAAC,MAAM;AACT,aAAK,OAAO;AAAA,UACVD;AAAAA,UACAC;AAAAA,UACA,0CAA0C,SAAS,EAAE;AAAA,QAAA;AAEvD;AAAA,MACF;AAEA,cAAQ,SAAS,MAAA;AAAA,QACf,KAAK;AACH,eAAK,OAAO,MAAMD,cAAYC,gBAAc,uBAAuB,SA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K,MAAM,CAAC;AAAA,IACrD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU;AACR,SAAK,OAAO,MAAM,YAAY,cAAc,wBAAwB;AAGpE,SAAK,aAAa,QAAQ,CAAC,MAAM,OAAO;AACtC,WAAK,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAC9C,WAAK,OAAO,MAAM,YAAY,cAAc,0BAA0B,EAAE,EAAE;AAAA,IAC5E,CAAC;AACD,SAAK,aAAa,MAAA;AAGlB,SAAK,QAAQ,QAAQ,CAAC,QAAQ,UAAU;AACtC,aAAO,UAAA;AACP,WAAK,OAAO,MAAM,YAAY,cAAc,UAAU,KAAK,aAAa;AAAA,IAC1E,CAAC;AACD,SAAK,UAAU,CAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,gBAAwB;AAC1B,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,oBAA4B;AAC9B,WAAO,KAAK,aAAa;AAAA,EAC3B;AACF;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"worker-engine.js","sources":["../../../../src/lib/orchestrator/remote-executor.ts","../../../../src/lib/image-encoder/worker-pool.ts"],"sourcesContent":["import {\n BatchProgress,\n Logger,\n NoopLogger,\n PdfDocumentObject,\n PdfPageObject,\n PdfTask,\n PdfErrorReason,\n PdfFile,\n PdfOpenDocumentBufferOptions,\n PdfMetadataObject,\n PdfBookmarksObject,\n PdfBookmarkObject,\n PdfRenderPageOptions,\n PdfRenderThumbnailOptions,\n PdfRenderPageAnnotationOptions,\n PdfAnnotationObject,\n PdfTextRectObject,\n PdfAttachmentObject,\n PdfAddAttachmentParams,\n PdfWidgetAnnoObject,\n FormFieldValue,\n PdfFlattenPageOptions,\n PdfPageFlattenResult,\n PdfRedactTextOptions,\n Rect,\n PageTextSlice,\n PdfGlyphObject,\n PdfPageGeometry,\n PdfPrintOptions,\n PdfSignatureObject,\n AnnotationCreateContext,\n Task,\n TaskError,\n PdfErrorCode,\n SearchResult,\n serializeLogger,\n IPdfiumExecutor,\n ImageDataLike,\n} from '@embedpdf/models';\nimport type { WorkerRequest, WorkerResponse } from './pdfium-native-runner';\nimport type { FontFallbackConfig } from '../pdfium/font-fallback';\n\n/**\n * Options for creating a RemoteExecutor\n */\nexport interface RemoteExecutorOptions {\n /**\n * URL to the pdfium.wasm file (required)\n */\n wasmUrl: string;\n /**\n * Logger instance for debugging\n */\n logger?: Logger;\n /**\n * Font fallback configuration for handling missing fonts\n */\n fontFallback?: FontFallbackConfig;\n}\n\nconst LOG_SOURCE = 'RemoteExecutor';\nconst LOG_CATEGORY = 'Worker';\n\n/**\n * Message types for worker communication\n */\ntype MessageType =\n | 'destroy'\n | 'openDocumentBuffer'\n | 'getMetadata'\n | 'setMetadata'\n | 'getDocPermissions'\n | 'getDocUserPermissions'\n | 'getSignatures'\n | 'getBookmarks'\n | 'setBookmarks'\n | 'deleteBookmarks'\n | 'renderPageRaw'\n | 'renderPageRect'\n | 'renderThumbnailRaw'\n | 'renderPageAnnotationRaw'\n | 'getPageAnnotations'\n | 'getPageAnnotationsRaw'\n | 'createPageAnnotation'\n | 'updatePageAnnotation'\n | 'removePageAnnotation'\n | 'getPageTextRects'\n | 'searchInPage'\n | 'getAnnotationsBatch'\n | 'searchBatch'\n | 'getAttachments'\n | 'addAttachment'\n | 'removeAttachment'\n | 'readAttachmentContent'\n | 'setFormFieldValue'\n | 'flattenPage'\n | 'extractPages'\n | 'extractText'\n | 'redactTextInRects'\n | 'getTextSlices'\n | 'getPageGlyphs'\n | 'getPageGeometry'\n | 'merge'\n | 'mergePages'\n | 'preparePrintDocument'\n | 'saveAsCopy'\n | 'closeDocument'\n | 'closeAllDocuments';\n\n/**\n * RemoteExecutor - Proxy for worker communication\n *\n * This implements IPdfExecutor but forwards all calls to a Web Worker.\n * It handles:\n * - Serialization/deserialization of messages\n * - Promise/Task conversion\n * - Error handling\n * - Progress tracking\n */\nexport class RemoteExecutor implements IPdfiumExecutor {\n private static READY_TASK_ID = '0';\n private pendingRequests = new Map<string, Task<any, any>>();\n private requestCounter = 0;\n private logger: Logger;\n private readyTask: Task<boolean, PdfErrorReason>;\n\n constructor(\n private worker: Worker,\n options: RemoteExecutorOptions,\n ) {\n this.logger = options.logger ?? new NoopLogger();\n this.worker.addEventListener('message', this.handleMessage);\n\n // Create ready task - will be resolved when worker sends 'ready'\n this.readyTask = new Task<boolean, PdfErrorReason>();\n this.pendingRequests.set(RemoteExecutor.READY_TASK_ID, this.readyTask);\n\n // Send initialization message with WASM URL and font fallback config\n this.worker.postMessage({\n id: RemoteExecutor.READY_TASK_ID,\n type: 'wasmInit',\n wasmUrl: options.wasmUrl,\n logger: options.logger ? serializeLogger(options.logger) : undefined,\n fontFallback: options.fontFallback,\n });\n\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'RemoteExecutor created');\n }\n\n /**\n * Generate unique request ID\n */\n private generateId(): string {\n return `req-${Date.now()}-${this.requestCounter++}`;\n }\n\n /**\n * Send a message to the worker and return a Task\n * Waits for worker to be ready before sending\n */\n private send<T, P = unknown>(method: MessageType, args: any[]): Task<T, PdfErrorReason, P> {\n const id = this.generateId();\n const task = new Task<T, PdfErrorReason, P>();\n\n const request: WorkerRequest = {\n id,\n type: 'execute',\n method,\n args,\n };\n\n // Wait for worker to be ready before sending\n this.readyTask.wait(\n () => {\n this.pendingRequests.set(id, task);\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Sending ${method} request:`, id);\n this.worker.postMessage(request);\n },\n (error) => {\n this.logger.error(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Worker init failed, rejecting ${method}:`,\n error,\n );\n task.reject({\n code: PdfErrorCode.Initialization,\n message: 'Worker initialization failed',\n });\n },\n );\n\n return task;\n }\n\n /**\n * Handle messages from worker\n */\n private handleMessage = (event: MessageEvent<WorkerResponse>) => {\n const response = event.data;\n\n // Handle ready response - resolve the readyTask\n if (response.type === 'ready') {\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Worker is ready');\n this.readyTask.resolve(true);\n return;\n }\n\n const task = this.pendingRequests.get(response.id);\n\n if (!task) {\n this.logger.warn(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received response for unknown request: ${response.id}`,\n );\n return;\n }\n\n switch (response.type) {\n case 'result':\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Received result for ${response.id}`);\n task.resolve(response.data);\n this.pendingRequests.delete(response.id);\n break;\n\n case 'error':\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received error for ${response.id}:`,\n response.error,\n );\n if (response.error) {\n task.fail(response.error);\n } else {\n task.reject({ code: PdfErrorCode.Unknown, message: 'Unknown error' });\n }\n this.pendingRequests.delete(response.id);\n break;\n\n case 'progress':\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Received progress for ${response.id}`);\n task.progress(response.progress);\n break;\n }\n };\n\n /**\n * Cleanup and terminate worker\n */\n destroy(): void {\n this.worker.removeEventListener('message', this.handleMessage);\n\n // Reject all pending requests (except readyTask)\n this.pendingRequests.forEach((task, id) => {\n if (id !== RemoteExecutor.READY_TASK_ID) {\n task.abort('Worker destroyed');\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Aborted pending request: ${id}`);\n }\n });\n this.pendingRequests.clear();\n\n this.worker.terminate();\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'RemoteExecutor destroyed');\n }\n\n // ========== IPdfExecutor Implementation ==========\n\n openDocumentBuffer(\n file: PdfFile,\n options?: PdfOpenDocumentBufferOptions,\n ): PdfTask<PdfDocumentObject> {\n return this.send<PdfDocumentObject>('openDocumentBuffer', [file, options]);\n }\n\n getMetadata(doc: PdfDocumentObject): PdfTask<PdfMetadataObject> {\n return this.send<PdfMetadataObject>('getMetadata', [doc]);\n }\n\n setMetadata(doc: PdfDocumentObject, metadata: Partial<PdfMetadataObject>): PdfTask<boolean> {\n return this.send<boolean>('setMetadata', [doc, metadata]);\n }\n\n getDocPermissions(doc: PdfDocumentObject): PdfTask<number> {\n return this.send<number>('getDocPermissions', [doc]);\n }\n\n getDocUserPermissions(doc: PdfDocumentObject): PdfTask<number> {\n return this.send<number>('getDocUserPermissions', [doc]);\n }\n\n getSignatures(doc: PdfDocumentObject): PdfTask<PdfSignatureObject[]> {\n return this.send<PdfSignatureObject[]>('getSignatures', [doc]);\n }\n\n getBookmarks(doc: PdfDocumentObject): PdfTask<PdfBookmarksObject> {\n return this.send<PdfBookmarksObject>('getBookmarks', [doc]);\n }\n\n setBookmarks(doc: PdfDocumentObject, bookmarks: PdfBookmarkObject[]): PdfTask<boolean> {\n return this.send<boolean>('setBookmarks', [doc, bookmarks]);\n }\n\n deleteBookmarks(doc: PdfDocumentObject): PdfTask<boolean> {\n return this.send<boolean>('deleteBookmarks', [doc]);\n }\n\n renderPageRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfRenderPageOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageRaw', [doc, page, options]);\n }\n\n renderPageRect(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n rect: Rect,\n options?: PdfRenderPageOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageRect', [doc, page, rect, options]);\n }\n\n renderThumbnailRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfRenderThumbnailOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderThumbnailRaw', [doc, page, options]);\n }\n\n renderPageAnnotationRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n options?: PdfRenderPageAnnotationOptions,\n ): PdfTask<ImageDataLike> {\n return this.send<ImageDataLike>('renderPageAnnotationRaw', [doc, page, annotation, options]);\n }\n\n getPageAnnotationsRaw(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n ): PdfTask<PdfAnnotationObject[]> {\n return this.send<PdfAnnotationObject[]>('getPageAnnotationsRaw', [doc, page]);\n }\n\n getPageAnnotations(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfAnnotationObject[]> {\n return this.send<PdfAnnotationObject[]>('getPageAnnotations', [doc, page]);\n }\n\n createPageAnnotation<A extends PdfAnnotationObject>(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: A,\n context?: AnnotationCreateContext<A>,\n ): PdfTask<string> {\n return this.send<string>('createPageAnnotation', [doc, page, annotation, context]);\n }\n\n updatePageAnnotation(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ): PdfTask<boolean> {\n return this.send<boolean>('updatePageAnnotation', [doc, page, annotation]);\n }\n\n removePageAnnotation(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ): PdfTask<boolean> {\n return this.send<boolean>('removePageAnnotation', [doc, page, annotation]);\n }\n\n getPageTextRects(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfTextRectObject[]> {\n return this.send<PdfTextRectObject[]>('getPageTextRects', [doc, page]);\n }\n\n searchInPage(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n keyword: string,\n flags: number,\n ): PdfTask<SearchResult[]> {\n return this.send<SearchResult[]>('searchInPage', [doc, page, keyword, flags]);\n }\n\n getAnnotationsBatch(\n doc: PdfDocumentObject,\n pages: PdfPageObject[],\n ): PdfTask<Record<number, PdfAnnotationObject[]>, BatchProgress<PdfAnnotationObject[]>> {\n return this.send<Record<number, PdfAnnotationObject[]>, BatchProgress<PdfAnnotationObject[]>>(\n 'getAnnotationsBatch',\n [doc, pages],\n );\n }\n\n searchBatch(\n doc: PdfDocumentObject,\n pages: PdfPageObject[],\n keyword: string,\n flags: number,\n ): PdfTask<Record<number, SearchResult[]>, BatchProgress<SearchResult[]>> {\n return this.send<Record<number, SearchResult[]>, BatchProgress<SearchResult[]>>('searchBatch', [\n doc,\n pages,\n keyword,\n flags,\n ]);\n }\n\n getAttachments(doc: PdfDocumentObject): PdfTask<PdfAttachmentObject[]> {\n return this.send<PdfAttachmentObject[]>('getAttachments', [doc]);\n }\n\n addAttachment(doc: PdfDocumentObject, params: PdfAddAttachmentParams): PdfTask<boolean> {\n return this.send<boolean>('addAttachment', [doc, params]);\n }\n\n removeAttachment(doc: PdfDocumentObject, attachment: PdfAttachmentObject): PdfTask<boolean> {\n return this.send<boolean>('removeAttachment', [doc, attachment]);\n }\n\n readAttachmentContent(\n doc: PdfDocumentObject,\n attachment: PdfAttachmentObject,\n ): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('readAttachmentContent', [doc, attachment]);\n }\n\n setFormFieldValue(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfWidgetAnnoObject,\n value: FormFieldValue,\n ): PdfTask<boolean> {\n return this.send<boolean>('setFormFieldValue', [doc, page, annotation, value]);\n }\n\n flattenPage(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n options?: PdfFlattenPageOptions,\n ): PdfTask<PdfPageFlattenResult> {\n return this.send<PdfPageFlattenResult>('flattenPage', [doc, page, options]);\n }\n\n extractPages(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('extractPages', [doc, pageIndexes]);\n }\n\n extractText(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<string> {\n return this.send<string>('extractText', [doc, pageIndexes]);\n }\n\n redactTextInRects(\n doc: PdfDocumentObject,\n page: PdfPageObject,\n rects: Rect[],\n options?: PdfRedactTextOptions,\n ): PdfTask<boolean> {\n return this.send<boolean>('redactTextInRects', [doc, page, rects, options]);\n }\n\n getTextSlices(doc: PdfDocumentObject, slices: PageTextSlice[]): PdfTask<string[]> {\n return this.send<string[]>('getTextSlices', [doc, slices]);\n }\n\n getPageGlyphs(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfGlyphObject[]> {\n return this.send<PdfGlyphObject[]>('getPageGlyphs', [doc, page]);\n }\n\n getPageGeometry(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfPageGeometry> {\n return this.send<PdfPageGeometry>('getPageGeometry', [doc, page]);\n }\n\n merge(files: PdfFile[]): PdfTask<PdfFile> {\n return this.send<PdfFile>('merge', [files]);\n }\n\n mergePages(mergeConfigs: Array<{ docId: string; pageIndices: number[] }>): PdfTask<PdfFile> {\n return this.send<PdfFile>('mergePages', [mergeConfigs]);\n }\n\n preparePrintDocument(doc: PdfDocumentObject, options?: PdfPrintOptions): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('preparePrintDocument', [doc, options]);\n }\n\n saveAsCopy(doc: PdfDocumentObject): PdfTask<ArrayBuffer> {\n return this.send<ArrayBuffer>('saveAsCopy', [doc]);\n }\n\n closeDocument(doc: PdfDocumentObject): PdfTask<boolean> {\n return this.send<boolean>('closeDocument', [doc]);\n }\n\n closeAllDocuments(): PdfTask<boolean> {\n return this.send<boolean>('closeAllDocuments', []);\n }\n}\n","import { Logger, NoopLogger } from '@embedpdf/models';\nimport type { EncodeImageRequest, EncodeImageResponse } from './image-encoder-worker';\n\nconst LOG_SOURCE = 'ImageEncoderPool';\nconst LOG_CATEGORY = 'Encoder';\n\ninterface EncodingTask {\n resolve: (blob: Blob) => void;\n reject: (error: Error) => void;\n}\n\n/**\n * Pool of image encoding workers to offload OffscreenCanvas operations\n * from the main PDFium worker thread\n */\nexport class ImageEncoderWorkerPool {\n private workers: Worker[] = [];\n private pendingTasks = new Map<string, EncodingTask>();\n private nextWorkerId = 0;\n private requestCounter = 0;\n private logger: Logger;\n\n /**\n * Create a pool of image encoding workers\n * @param poolSize - Number of workers to create (default: 2)\n * @param workerUrl - URL to the worker script\n * @param logger - Logger instance\n */\n constructor(\n private poolSize: number = 2,\n private workerUrl: string,\n logger?: Logger,\n ) {\n this.logger = logger ?? new NoopLogger();\n this.initialize();\n }\n\n /**\n * Initialize the worker pool\n */\n private initialize() {\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Creating worker pool with ${this.poolSize} workers`,\n );\n\n for (let i = 0; i < this.poolSize; i++) {\n try {\n const worker = new Worker(this.workerUrl, { type: 'module' });\n worker.onmessage = this.handleWorkerMessage.bind(this);\n worker.onerror = this.handleWorkerError.bind(this);\n this.workers.push(worker);\n\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Worker ${i} created successfully`);\n } catch (error) {\n this.logger.error(LOG_SOURCE, LOG_CATEGORY, `Failed to create worker ${i}:`, error);\n }\n }\n }\n\n /**\n * Handle messages from workers\n */\n private handleWorkerMessage(event: MessageEvent<EncodeImageResponse>) {\n const response = event.data;\n const task = this.pendingTasks.get(response.id);\n\n if (!task) {\n this.logger.warn(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Received response for unknown task: ${response.id}`,\n );\n return;\n }\n\n this.pendingTasks.delete(response.id);\n\n if (response.type === 'result') {\n task.resolve(response.data as Blob);\n } else {\n const errorData = response.data as { message: string };\n task.reject(new Error(errorData.message));\n }\n }\n\n /**\n * Handle worker errors\n */\n private handleWorkerError(error: ErrorEvent) {\n this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'Worker error:', error.message);\n }\n\n /**\n * Get the next available worker using round-robin\n */\n private getNextWorker(): Worker | null {\n if (this.workers.length === 0) {\n return null;\n }\n\n const worker = this.workers[this.nextWorkerId];\n this.nextWorkerId = (this.nextWorkerId + 1) % this.workers.length;\n return worker;\n }\n\n /**\n * Encode ImageData to Blob using a worker from the pool\n * @param imageData - Raw image data\n * @param imageType - Target image format\n * @param quality - Image quality (0-1) for lossy formats\n * @returns Promise that resolves to encoded Blob\n */\n encode(\n imageData: { data: Uint8ClampedArray; width: number; height: number },\n imageType: 'image/png' | 'image/jpeg' | 'image/webp' = 'image/webp',\n quality?: number,\n ): Promise<Blob> {\n return new Promise((resolve, reject) => {\n const worker = this.getNextWorker();\n\n if (!worker) {\n reject(new Error('No workers available in the pool'));\n return;\n }\n\n const requestId = `encode-${Date.now()}-${this.requestCounter++}`;\n this.pendingTasks.set(requestId, { resolve, reject });\n\n const request: EncodeImageRequest = {\n id: requestId,\n type: 'encode',\n data: {\n imageData: {\n data: imageData.data,\n width: imageData.width,\n height: imageData.height,\n },\n imageType,\n quality,\n },\n };\n\n this.logger.debug(\n LOG_SOURCE,\n LOG_CATEGORY,\n `Sending encoding request ${requestId} (${imageData.width}x${imageData.height})`,\n );\n\n // Transfer the buffer for better performance\n worker.postMessage(request, [imageData.data.buffer]);\n });\n }\n\n /**\n * Destroy all workers in the pool\n */\n destroy() {\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Destroying worker pool');\n\n // Reject all pending tasks\n this.pendingTasks.forEach((task, id) => {\n task.reject(new Error('Worker pool destroyed'));\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Rejected pending task: ${id}`);\n });\n this.pendingTasks.clear();\n\n // Terminate all workers\n this.workers.forEach((worker, index) => {\n worker.terminate();\n this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Worker ${index} terminated`);\n });\n this.workers = [];\n }\n\n /**\n * Get the number of active workers in the pool\n */\n get activeWorkers(): number {\n return this.workers.length;\n }\n\n /**\n * Get the number of pending encoding tasks\n */\n get pendingTasksCount(): number {\n return this.pendingTasks.size;\n }\n}\n"],"names":["LOG_SOURCE","LOG_CATEGORY"],"mappings":";;;AA6DA,MAAMA,eAAa;AACnB,MAAMC,iBAAe;AA0Dd,MAAM,kBAAN,MAAM,gBAA0C;AAAA,EAOrD,YACU,QACR,SACA;AAFQ,SAAA,SAAA;AANV,SAAQ,sCAAsB,IAAA;AAC9B,SAAQ,iBAAiB;AA4EzB,SAAQ,gBAAgB,CAAC,UAAwC;AAC/D,YAAM,WAAW,MAAM;AAGvB,UAAI,SAAS,SAAS,SAAS;AAC7B,aAAK,OAAO,MAAMD,cAAYC,gBAAc,iBAAiB;AAC7D,aAAK,UAAU,QAAQ,IAAI;AAC3B;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,gBAAgB,IAAI,SAAS,EAAE;A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,UAAU;AAAA,YACjB,QAAQ,UAAU;AAAA,UAAA;AAAA,UAEpB;AAAA,UACA;AAAA,QAAA;AAAA,MACF;AAGF,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,QACA,4BAA4B,SAAS,KAAK,UAAU,KAAK,IAAI,UAAU,MAAM;AAAA,MAAA;AAI/E,aAAO,YAAY,SAAS,CAAC,UAAU,KAAK,MAAM,CAAC;AAAA,IACrD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU;AACR,SAAK,OAAO,MAAM,YAAY,cAAc,wBAAwB;AAGpE,SAAK,aAAa,QAAQ,CAAC,MAAM,OAAO;AACtC,WAAK,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAC9C,WAAK,OAAO,MAAM,YAAY,cAAc,0BAA0B,EAAE,EAAE;AAAA,IAC5E,CAAC;AACD,SAAK,aAAa,MAAA;AAGlB,SAAK,QAAQ,QAAQ,CAAC,QAAQ,UAAU;AACtC,aAAO,UAAA;AACP,WAAK,OAAO,MAAM,YAAY,cAAc,UAAU,KAAK,aAAa;AAAA,IAC1E,CAAC;AACD,SAAK,UAAU,CAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,gBAAwB;AAC1B,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,oBAA4B;AAC9B,WAAO,KAAK,aAAa;AAAA,EAC3B;AACF;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact/hooks"),r=require("preact"),t=require("@embedpdf/models"),n=require("preact/jsx-runtime"),o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.2/dist/pdfium.wasm";const i=r.createContext(void 0);function u(){const r=e.useContext(i);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:t,error:o}){const u={engine:r,isLoading:t,error:o};return n.jsx(i.Provider,{value:u,children:e})},exports.useEngine=function(){const{engine:e,error:r}=u();if(r)throw r;return e},exports.useEngineContext=u,exports.usePdfiumEngine=function(r){const{wasmUrl:n=o,worker:i=!0,logger:u,encoderPoolSize:s}=r??{},[c,d]=e.useState(null),[l,a]=e.useState(!0),[p,g]=e.useState(null),f=e.useRef(null);return e.useEffect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(n,{logger:u,encoderPoolSize:s});f.current=r,d(r),a(!1)}catch(r){e||(g(r),a(!1))}})(),()=>{var r,n;e=!0,null==(n=null==(r=f.current)?void 0:r.closeAllDocuments)||n.call(r).wait(()=>{var e,r;null==(r=null==(e=f.current)?void 0:e.destroy)||r.call(e),f.current=null},t.ignore)}},[n,i,u]),{engine:c,isLoading:l,error:p}};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact/hooks"),r=require("preact"),t=require("@embedpdf/models"),n=require("preact/jsx-runtime"),o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm";const i=r.createContext(void 0);function u(){const r=e.useContext(i);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:t,error:o}){const u={engine:r,isLoading:t,error:o};return n.jsx(i.Provider,{value:u,children:e})},exports.useEngine=function(){const{engine:e,error:r}=u();if(r)throw r;return e},exports.useEngineContext=u,exports.usePdfiumEngine=function(r){const{wasmUrl:n=o,worker:i=!0,logger:u,encoderPoolSize:s,fontFallback:c}=r??{},[l,d]=e.useState(null),[a,p]=e.useState(!0),[g,f]=e.useState(null),m=e.useRef(null);return e.useEffect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(n,{logger:u,encoderPoolSize:s,fontFallback:c});m.current=r,d(r),p(!1)}catch(r){e||(f(r),p(!1))}})(),()=>{var r,n;e=!0,null==(n=null==(r=m.current)?void 0:r.closeAllDocuments)||n.call(r).wait(()=>{var e,r;null==(r=null==(e=m.current)?void 0:e.destroy)||r.call(e),m.current=null},t.ignore)}},[n,i,u,c]),{engine:l,isLoading:a,error:g}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","encoderPoolSize","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_b","_a","closeAllDocuments","call","wait","destroy","ignore"],"mappings":"uVAGMA,EAAiB,uECMhB,MAAMC,EAAmBC,EAAAA,mBAAiD,GCD1E,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWJ,GAEhC,QAAqB,IAAjBG,EACF,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAAC,UAAQA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,SAGF,aAAQT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACF,MAAMA,EAGR,OAAOF,CACT,qDFlBO,SAAyBK,GAC9B,MAAMC,QAAEA,EAAUd,EAAAe,OAAgBA,GAAS,SAAMC,EAAAC,gBAAQA,GAAoBJ,GAAU,CAAA,GAEhFL,EAAQU,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCT,EAAOY,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAgC3C,OA9BAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EAoBhB,MAlBA,WACE,IACE,MAAMC,mBAAEA,GAAuBZ,QACrBa,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBb,EAAS,CAAEE,SAAQC,oBAC9DM,EAAUO,QAAUD,EACpBX,EAAUW,GACVR,GAAW,EACb,OAASU,GACFL,IACHJ,EAASS,GACTV,GAAW,GAEf,CACF,EAhBA,GAkBO,aACLK,GAAY,EACZ,OAAAM,EAAA,OAAAC,EAAAV,EAAUO,cAAV,EAAAG,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCG,KAAK,aAC5C,OAAAJ,EAAA,OAAAC,EAAAV,EAAUO,gBAAVG,EAAmBI,UAAnBL,EAAAG,KAAAF,GACAV,EAAUO,QAAU,MACnBQ,EAAAA,UAEJ,CAACxB,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWW,EAASV,QACvC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const {\n wasmUrl = defaultWasmUrl,\n worker = true,\n logger,\n encoderPoolSize,\n fontFallback,\n } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, {\n logger,\n encoderPoolSize,\n fontFallback,\n });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger, fontFallback]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","encoderPoolSize","fontFallback","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_b","_a","closeAllDocuments","call","wait","destroy","ignore"],"mappings":"uVAIMA,EAAiB,uECKhB,MAAMC,EAAmBC,EAAAA,mBAAiD,GCD1E,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWJ,GAEhC,QAAqB,IAAjBG,EACF,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAAC,UAAQA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,SAGF,aAAQT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACF,MAAMA,EAGR,OAAOF,CACT,qDFbO,SAAyBK,GAC9B,MAAMC,QACJA,EAAUd,EAAAe,OACVA,GAAS,EAAAC,OACTA,EAAAC,gBACAA,EAAAC,aACAA,GACEL,GAAU,CAAA,GAEPL,EAAQW,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCV,EAAOa,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAoC3C,OAlCAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EAwBhB,MAtBA,WACE,IACE,MAAMC,mBAAEA,GAAuBb,QACrBc,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBd,EAAS,CAClDE,SACAC,kBACAC,iBAEFM,EAAUO,QAAUD,EACpBX,EAAUW,GACVR,GAAW,EACb,OAASU,GACFL,IACHJ,EAASS,GACTV,GAAW,GAEf,CACF,EApBA,GAsBO,aACLK,GAAY,EACZ,OAAAM,EAAA,OAAAC,EAAAV,EAAUO,cAAV,EAAAG,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCG,KAAK,aAC5C,OAAAJ,EAAA,OAAAC,EAAAV,EAAUO,gBAAVG,EAAmBI,UAAnBL,EAAAG,KAAAF,GACAV,EAAUO,QAAU,MACnBQ,EAAAA,UAEJ,CAACzB,EAASC,EAAQC,EAAQE,IAEtB,CAAEV,SAAQC,UAAWY,EAASX,QACvC"}
@@ -2,9 +2,15 @@ import { useState, useRef, useEffect, useContext } from "preact/hooks";
2
2
  import { createContext } from "preact";
3
3
  import { ignore } from "@embedpdf/models";
4
4
  import { jsx } from "preact/jsx-runtime";
5
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.2/dist/pdfium.wasm`;
5
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm`;
6
6
  function usePdfiumEngine(config) {
7
- const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};
7
+ const {
8
+ wasmUrl = defaultWasmUrl,
9
+ worker = true,
10
+ logger,
11
+ encoderPoolSize,
12
+ fontFallback
13
+ } = config ?? {};
8
14
  const [engine, setEngine] = useState(null);
9
15
  const [loading, setLoading] = useState(true);
10
16
  const [error, setError] = useState(null);
@@ -14,7 +20,11 @@ function usePdfiumEngine(config) {
14
20
  (async () => {
15
21
  try {
16
22
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
17
- const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });
23
+ const pdfEngine = await createPdfiumEngine(wasmUrl, {
24
+ logger,
25
+ encoderPoolSize,
26
+ fontFallback
27
+ });
18
28
  engineRef.current = pdfEngine;
19
29
  setEngine(pdfEngine);
20
30
  setLoading(false);
@@ -34,7 +44,7 @@ function usePdfiumEngine(config) {
34
44
  engineRef.current = null;
35
45
  }, ignore);
36
46
  };
37
- }, [wasmUrl, worker, logger]);
47
+ }, [wasmUrl, worker, logger, fontFallback]);
38
48
  return { engine, isLoading: loading, error };
39
49
  }
40
50
  const PdfEngineContext = createContext(void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;;AAGA,MAAM,iBAAiB;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACX,UAAI;AACF,cAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS,EAAE,QAAQ,iBAAiB;AAC/E,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,SAAS,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF,GAAA;AAEA,WAAO,MAAM;;AACX,kBAAY;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAA;AACvC;AC1CO,MAAM,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AACxD,QAAM,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const {\n wasmUrl = defaultWasmUrl,\n worker = true,\n logger,\n encoderPoolSize,\n fontFallback,\n } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, {\n logger,\n encoderPoolSize,\n fontFallback,\n });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger, fontFallback]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;;AAIA,MAAM,iBAAiB;AAahB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE,UAAU,CAAA;AAEd,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACX,UAAI;AACF,cAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS;AAAA,UAClD;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACD;AACD,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,SAAS,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF,GAAA;AAEA,WAAO,MAAM;;AACX,kBAAY;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,QAAQ,YAAY,CAAC;AAE1C,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAA;AACvC;ACzDO,MAAM,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AACxD,QAAM,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),r=require("@embedpdf/models"),t=require("react/jsx-runtime"),n="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.2/dist/pdfium.wasm";const o=e.createContext(void 0);function i(){const r=e.useContext(o);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:n,error:i}){const u={engine:r,isLoading:n,error:i};return t.jsx(o.Provider,{value:u,children:e})},exports.useEngine=function(){const{engine:e,error:r}=i();if(r)throw r;return e},exports.useEngineContext=i,exports.usePdfiumEngine=function(t){const{wasmUrl:o=n,worker:i=!0,logger:u,encoderPoolSize:s}=t??{},[c,d]=e.useState(null),[l,a]=e.useState(!0),[g,p]=e.useState(null),f=e.useRef(null);return e.useEffect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(o,{logger:u,encoderPoolSize:s});f.current=r,d(r),a(!1)}catch(r){e||(p(r),a(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=f.current)?void 0:t.closeAllDocuments)||n.call(t).wait(()=>{var e,r;null==(r=null==(e=f.current)?void 0:e.destroy)||r.call(e),f.current=null},r.ignore)}},[o,i,u]),{engine:c,isLoading:l,error:g}};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),r=require("@embedpdf/models"),t=require("react/jsx-runtime"),n="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm";const o=e.createContext(void 0);function i(){const r=e.useContext(o);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:n,error:i}){const u={engine:r,isLoading:n,error:i};return t.jsx(o.Provider,{value:u,children:e})},exports.useEngine=function(){const{engine:e,error:r}=i();if(r)throw r;return e},exports.useEngineContext=i,exports.usePdfiumEngine=function(t){const{wasmUrl:o=n,worker:i=!0,logger:u,encoderPoolSize:s,fontFallback:c}=t??{},[l,d]=e.useState(null),[a,g]=e.useState(!0),[f,p]=e.useState(null),m=e.useRef(null);return e.useEffect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(o,{logger:u,encoderPoolSize:s,fontFallback:c});m.current=r,d(r),g(!1)}catch(r){e||(p(r),g(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=m.current)?void 0:t.closeAllDocuments)||n.call(t).wait(()=>{var e,r;null==(r=null==(e=m.current)?void 0:e.destroy)||r.call(e),m.current=null},r.ignore)}},[o,i,u,c]),{engine:l,isLoading:a,error:f}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","encoderPoolSize","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_b","_a","closeAllDocuments","call","wait","destroy","ignore"],"mappings":"2TAGMA,EAAiB,uECMhB,MAAMC,EAAmBC,EAAAA,mBAAiD,GCD1E,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWJ,GAEhC,QAAqB,IAAjBG,EACF,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAAC,UAAQA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,SAGF,aAAQT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACF,MAAMA,EAGR,OAAOF,CACT,qDFlBO,SAAyBK,GAC9B,MAAMC,QAAEA,EAAUd,EAAAe,OAAgBA,GAAS,SAAMC,EAAAC,gBAAQA,GAAoBJ,GAAU,CAAA,GAEhFL,EAAQU,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCT,EAAOY,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAgC3C,OA9BAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EAoBhB,MAlBA,WACE,IACE,MAAMC,mBAAEA,GAAuBZ,QACrBa,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBb,EAAS,CAAEE,SAAQC,oBAC9DM,EAAUO,QAAUD,EACpBX,EAAUW,GACVR,GAAW,EACb,OAASU,GACFL,IACHJ,EAASS,GACTV,GAAW,GAEf,CACF,EAhBA,GAkBO,aACLK,GAAY,EACZ,OAAAM,EAAA,OAAAC,EAAAV,EAAUO,cAAV,EAAAG,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCG,KAAK,aAC5C,OAAAJ,EAAA,OAAAC,EAAAV,EAAUO,gBAAVG,EAAmBI,UAAnBL,EAAAG,KAAAF,GACAV,EAAUO,QAAU,MACnBQ,EAAAA,UAEJ,CAACxB,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWW,EAASV,QACvC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const {\n wasmUrl = defaultWasmUrl,\n worker = true,\n logger,\n encoderPoolSize,\n fontFallback,\n } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, {\n logger,\n encoderPoolSize,\n fontFallback,\n });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger, fontFallback]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","encoderPoolSize","fontFallback","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_b","_a","closeAllDocuments","call","wait","destroy","ignore"],"mappings":"2TAIMA,EAAiB,uECKhB,MAAMC,EAAmBC,EAAAA,mBAAiD,GCD1E,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWJ,GAEhC,QAAqB,IAAjBG,EACF,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAAC,UAAQA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,SAGF,aAAQT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACF,MAAMA,EAGR,OAAOF,CACT,qDFbO,SAAyBK,GAC9B,MAAMC,QACJA,EAAUd,EAAAe,OACVA,GAAS,EAAAC,OACTA,EAAAC,gBACAA,EAAAC,aACAA,GACEL,GAAU,CAAA,GAEPL,EAAQW,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCV,EAAOa,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAoC3C,OAlCAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EAwBhB,MAtBA,WACE,IACE,MAAMC,mBAAEA,GAAuBb,QACrBc,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBd,EAAS,CAClDE,SACAC,kBACAC,iBAEFM,EAAUO,QAAUD,EACpBX,EAAUW,GACVR,GAAW,EACb,OAASU,GACFL,IACHJ,EAASS,GACTV,GAAW,GAEf,CACF,EApBA,GAsBO,aACLK,GAAY,EACZ,OAAAM,EAAA,OAAAC,EAAAV,EAAUO,cAAV,EAAAG,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCG,KAAK,aAC5C,OAAAJ,EAAA,OAAAC,EAAAV,EAAUO,gBAAVG,EAAmBI,UAAnBL,EAAAG,KAAAF,GACAV,EAAUO,QAAU,MACnBQ,EAAAA,UAEJ,CAACzB,EAASC,EAAQC,EAAQE,IAEtB,CAAEV,SAAQC,UAAWY,EAASX,QACvC"}
@@ -1,9 +1,15 @@
1
1
  import { useState, useRef, useEffect, createContext, useContext } from "react";
2
2
  import { ignore } from "@embedpdf/models";
3
3
  import { jsx } from "react/jsx-runtime";
4
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.2/dist/pdfium.wasm`;
4
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm`;
5
5
  function usePdfiumEngine(config) {
6
- const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};
6
+ const {
7
+ wasmUrl = defaultWasmUrl,
8
+ worker = true,
9
+ logger,
10
+ encoderPoolSize,
11
+ fontFallback
12
+ } = config ?? {};
7
13
  const [engine, setEngine] = useState(null);
8
14
  const [loading, setLoading] = useState(true);
9
15
  const [error, setError] = useState(null);
@@ -13,7 +19,11 @@ function usePdfiumEngine(config) {
13
19
  (async () => {
14
20
  try {
15
21
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
16
- const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });
22
+ const pdfEngine = await createPdfiumEngine(wasmUrl, {
23
+ logger,
24
+ encoderPoolSize,
25
+ fontFallback
26
+ });
17
27
  engineRef.current = pdfEngine;
18
28
  setEngine(pdfEngine);
19
29
  setLoading(false);
@@ -33,7 +43,7 @@ function usePdfiumEngine(config) {
33
43
  engineRef.current = null;
34
44
  }, ignore);
35
45
  };
36
- }, [wasmUrl, worker, logger]);
46
+ }, [wasmUrl, worker, logger, fontFallback]);
37
47
  return { engine, isLoading: loading, error };
38
48
  }
39
49
  const PdfEngineContext = createContext(void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;AAGA,MAAM,iBAAiB;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACX,UAAI;AACF,cAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS,EAAE,QAAQ,iBAAiB;AAC/E,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,SAAS,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF,GAAA;AAEA,WAAO,MAAM;;AACX,kBAAY;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAA;AACvC;AC1CO,MAAM,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AACxD,QAAM,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n encoderPoolSize?: number;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const {\n wasmUrl = defaultWasmUrl,\n worker = true,\n logger,\n encoderPoolSize,\n fontFallback,\n } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, {\n logger,\n encoderPoolSize,\n fontFallback,\n });\n engineRef.current = pdfEngine;\n setEngine(pdfEngine);\n setLoading(false);\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger, fontFallback]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;AAIA,MAAM,iBAAiB;AAahB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE,UAAU,CAAA;AAEd,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACX,UAAI;AACF,cAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS;AAAA,UAClD;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACD;AACD,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,SAAS,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF,GAAA;AAEA,WAAO,MAAM;;AACX,kBAAY;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,QAAQ,YAAY,CAAC;AAE1C,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAA;AACvC;ACzDO,MAAM,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AACxD,QAAM,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
@@ -1,9 +1,14 @@
1
1
  import { Logger, PdfEngine } from '@embedpdf/models';
2
+ import { FontFallbackConfig } from '../../lib/index.ts';
2
3
  interface UsePdfiumEngineProps {
3
4
  wasmUrl?: string;
4
5
  worker?: boolean;
5
6
  logger?: Logger;
6
7
  encoderPoolSize?: number;
8
+ /**
9
+ * Font fallback configuration for handling missing fonts in PDFs.
10
+ */
11
+ fontFallback?: FontFallbackConfig;
7
12
  }
8
13
  export declare function usePdfiumEngine(config?: UsePdfiumEngineProps): {
9
14
  engine: PdfEngine<Blob> | null;
@@ -1,9 +1,14 @@
1
1
  import { Logger, PdfEngine } from '@embedpdf/models';
2
+ import { FontFallbackConfig } from '../../lib/index.ts';
2
3
  interface UsePdfiumEngineProps {
3
4
  wasmUrl?: string;
4
5
  worker?: boolean;
5
6
  logger?: Logger;
6
7
  encoderPoolSize?: number;
8
+ /**
9
+ * Font fallback configuration for handling missing fonts in PDFs.
10
+ */
11
+ fontFallback?: FontFallbackConfig;
7
12
  }
8
13
  export declare function usePdfiumEngine(config?: UsePdfiumEngineProps): {
9
14
  engine: PdfEngine<Blob> | null;
@@ -1,8 +1,13 @@
1
1
  import { Logger, PdfEngine } from '@embedpdf/models';
2
+ import { FontFallbackConfig } from '../../lib/index.ts';
2
3
  export interface UsePdfiumEngineProps {
3
4
  wasmUrl?: string;
4
5
  worker?: boolean;
5
6
  logger?: Logger;
7
+ /**
8
+ * Font fallback configuration for handling missing fonts in PDFs.
9
+ */
10
+ fontFallback?: FontFallbackConfig;
6
11
  }
7
12
  export declare function usePdfiumEngine(config?: UsePdfiumEngineProps): {
8
13
  engine: PdfEngine | null;
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("svelte"),n=require("@embedpdf/models"),r=require("@embedpdf/engines");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const o=i(e),s=Symbol("pdfEngineContext");function u(){const e=t.getContext(s);if(void 0===e)throw new Error("getPdfEngineContext must be used within a PdfEngineProvider");return e}exports.PdfEngineProvider=function(e,n){o.push(n,!0),o.user_effect(()=>{var e;e={engine:n.engine,isLoading:n.isLoading,error:n.error},t.setContext(s,e)});var r=o.comment(),i=o.first_child(r);o.snippet(i,()=>n.children),o.append(e,r),o.pop()},exports.useEngine=function(){const{engine:e,error:t}=u();if(t)throw t;return e},exports.useEngineContext=function(){const e=u();if(void 0===e)throw new Error("useEngineContext must be used within a PdfEngineProvider");return e},exports.usePdfiumEngine=function(e){const{wasmUrl:t=r.DEFAULT_PDFIUM_WASM_URL,worker:i=!0,logger:s}=e??{},u=o.proxy({engine:null,isLoading:!0,error:null});let l=o.state(null);return"undefined"!=typeof window&&o.user_effect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,{logger:s});o.set(l,n,!0),u.engine=n,u.isLoading=!1}catch(n){e||(u.error=n,u.isLoading=!1)}})(),()=>{var t,r;e=!0,null==(r=null==(t=o.get(l))?void 0:t.closeAllDocuments)||r.call(t).wait(()=>{var e,t;null==(t=null==(e=o.get(l))?void 0:e.destroy)||t.call(e),o.set(l,null)},n.ignore)}}),u};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("svelte"),n=require("@embedpdf/models");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const i=r(e),o=Symbol("pdfEngineContext");function s(){const e=t.getContext(o);if(void 0===e)throw new Error("getPdfEngineContext must be used within a PdfEngineProvider");return e}const l="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm";exports.PdfEngineProvider=function(e,n){i.push(n,!0),i.user_effect(()=>{var e;e={engine:n.engine,isLoading:n.isLoading,error:n.error},t.setContext(o,e)});var r=i.comment(),s=i.first_child(r);i.snippet(s,()=>n.children),i.append(e,r),i.pop()},exports.useEngine=function(){const{engine:e,error:t}=s();if(t)throw t;return e},exports.useEngineContext=function(){const e=s();if(void 0===e)throw new Error("useEngineContext must be used within a PdfEngineProvider");return e},exports.usePdfiumEngine=function(e){const{wasmUrl:t=l,worker:r=!0,logger:o,fontFallback:s}=e??{},d=i.proxy({engine:null,isLoading:!0,error:null});let c=i.state(null);return"undefined"!=typeof window&&i.user_effect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=r?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,{logger:o,fontFallback:s});i.set(c,n,!0),d.engine=n,d.isLoading=!1}catch(n){e||(d.error=n,d.isLoading=!1)}})(),()=>{var t,r;e=!0,null==(r=null==(t=i.get(c))?void 0:t.closeAllDocuments)||r.call(t).wait(()=>{var e,t;null==(t=null==(e=i.get(c))?void 0:e.destroy)||t.call(e),i.set(c,null)},n.ignore)}}),d};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger });\n engineRef = pdfEngine;\n state.engine = pdfEngine;\n state.isLoading = false;\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n"],"names":["PDF_ENGINE_CONTEXT_KEY","Symbol","getPdfEngineContext","context","getContext","Error","$","user_effect","value","engine","$$props","isLoading","error","setContext","contextValue","config","wasmUrl","DEFAULT_PDFIUM_WASM_URL","worker","logger","state","engineRef","window","cancelled","createPdfiumEngine","pdfEngine","set","e","closeAllDocuments","wait","get","destroy","ignore"],"mappings":"oqBASMA,EAAyBC,OAAO,oBAatB,SAAAC,UACRC,EAAUC,EAAAA,WAA8CJ,eAE1DG,EACQ,MAAA,IAAAE,MAAM,sEAGXF,CACT,sDCfEG,EAAAC,YAAO,SDD2BC,ICEb,CACjBC,OAAMC,EAAAD,OACNE,UAASD,EAAAC,UACTC,MAAKF,EAAAE,ODJTC,EAAAA,WAAWb,EAAwBQ,2FCOrC,oBCEO,WACL,MAAMC,OAAEA,EAAAG,MAAQA,GAAUV,IAE1B,GAAIU,EACF,MAAMA,EAGR,OAAOH,CACT,2BAtBO,WACL,MAAMK,EAAeZ,IAErB,QAAqB,IAAjBY,EACF,MAAM,IAAIT,MAAM,4DAGlB,OAAOS,CACT,mCCTgCC,iBACtBC,EAAUC,iCAAyBC,GAAS,EAAAC,OAAMA,GAAWJ,MAG/DK,WACJX,OAAQ,KACRE,WAAW,EACXC,MAAO,WAGLS,EAAYf,EAAAc,MAAyB,YAEL,oBAAXE,QAGvBhB,EAAAC,iBACM,IAAAgB,GAAY,uBAIJ,MAAAC,mBAAAA,GAAuBN,eACd,uDACA,0CAEXO,QAAkBD,EAAmBR,GAAWG,WACtDb,EAAAoB,IAAAL,EAAYI,GAAA,GACZL,EAAMX,OAASgB,EACfL,EAAMT,WAAY,CACpB,OAASgB,GACFJ,IACHH,EAAMR,MAAQe,EACdP,EAAMT,WAAY,EAEtB,CACF,kBAGEY,GAAY,0BACZF,aAAWO,8BAAsBC,kBAC/BvB,OAAAA,EAAAA,OAAAA,EAAAA,EAAAwB,IAAAT,SAAAf,EAAAA,EAAWyB,UAAXzB,EAAAA,KAAAA,GACAA,EAAAoB,IAAAL,EAAY,OACXW,EAAAA,WAMFZ,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte","../../src/svelte/hooks/use-engine-context.ts"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, fontFallback } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, fontFallback });\n engineRef = pdfEngine;\n state.engine = pdfEngine;\n state.isLoading = false;\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n"],"names":["PDF_ENGINE_CONTEXT_KEY","Symbol","getPdfEngineContext","context","getContext","Error","defaultWasmUrl","$","user_effect","value","engine","$$props","isLoading","error","setContext","contextValue","config","wasmUrl","worker","logger","fontFallback","state","engineRef","window","cancelled","createPdfiumEngine","pdfEngine","set","e","closeAllDocuments","wait","get","destroy","ignore"],"mappings":"qoBASMA,EAAyBC,OAAO,oBAatB,SAAAC,UACRC,EAAUC,EAAAA,WAA8CJ,eAE1DG,EACQ,MAAA,IAAAE,MAAM,sEAGXF,CACT,CC3BM,MAAAG,EACJ,4HCWAC,EAAAC,YAAO,SFD2BC,IEEb,CACjBC,OAAMC,EAAAD,OACNE,UAASD,EAAAC,UACTC,MAAKF,EAAAE,OFJTC,EAAAA,WAAWd,EAAwBS,2FEOrC,oBCEO,WACL,MAAMC,OAAEA,EAAAG,MAAQA,GAAUX,IAE1B,GAAIW,EACF,MAAMA,EAGR,OAAOH,CACT,2BAtBO,WACL,MAAMK,EAAeb,IAErB,QAAqB,IAAjBa,EACF,MAAM,IAAIV,MAAM,4DAGlB,OAAOU,CACT,mCFFgCC,iBACtBC,EAAUX,EAAAY,OAAgBA,GAAS,EAAAC,OAAMA,EAAAC,aAAQA,GAAiBJ,GAAA,CAAA,EAGpEK,WACJX,OAAQ,KACRE,WAAW,EACXC,MAAO,WAGLS,EAAYf,EAAAc,MAAyB,YAEL,oBAAXE,QAGvBhB,EAAAC,iBACM,IAAAgB,GAAY,uBAIJ,MAAAC,mBAAAA,GAAuBP,eACd,uDACA,0CAEXQ,QAAkBD,EAAmBR,GAAWE,SAAQC,iBAC9Db,EAAAoB,IAAAL,EAAYI,GAAA,GACZL,EAAMX,OAASgB,EACfL,EAAMT,WAAY,CACpB,OAASgB,GACFJ,IACHH,EAAMR,MAAQe,EACdP,EAAMT,WAAY,EAEtB,CACF,kBAGEY,GAAY,0BACZF,aAAWO,8BAAsBC,kBAC/BvB,OAAAA,EAAAA,OAAAA,EAAAA,EAAAwB,IAAAT,SAAAf,EAAAA,EAAWyB,UAAXzB,EAAAA,KAAAA,GACAA,EAAAoB,IAAAL,EAAY,OACXW,EAAAA,WAMFZ,CACT"}
@@ -1,7 +1,6 @@
1
1
  import * as $ from "svelte/internal/client";
2
2
  import { setContext, getContext } from "svelte";
3
3
  import { ignore } from "@embedpdf/models";
4
- import { DEFAULT_PDFIUM_WASM_URL } from "@embedpdf/engines";
5
4
  import "svelte/internal/disclose-version";
6
5
  const PDF_ENGINE_CONTEXT_KEY = Symbol("pdfEngineContext");
7
6
  function setPdfEngineContext(value) {
@@ -28,8 +27,14 @@ function useEngine() {
28
27
  }
29
28
  return engine;
30
29
  }
30
+ const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm";
31
31
  function usePdfiumEngine(config) {
32
- const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};
32
+ const {
33
+ wasmUrl = defaultWasmUrl,
34
+ worker = true,
35
+ logger,
36
+ fontFallback
37
+ } = config ?? {};
33
38
  const state = $.proxy({ engine: null, isLoading: true, error: null });
34
39
  let engineRef = $.state(null);
35
40
  const isBrowser = typeof window !== "undefined";
@@ -39,7 +44,7 @@ function usePdfiumEngine(config) {
39
44
  (async () => {
40
45
  try {
41
46
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
42
- const pdfEngine = await createPdfiumEngine(wasmUrl, { logger });
47
+ const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, fontFallback });
43
48
  $.set(engineRef, pdfEngine, true);
44
49
  state.engine = pdfEngine;
45
50
  state.isLoading = false;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger });\n engineRef = pdfEngine;\n state.engine = pdfEngine;\n state.isLoading = false;\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n"],"names":["_b","_a"],"mappings":";;;;;MASM,yBAAyB,OAAO,kBAAkB;SAKxC,oBAAoB,OAA8B;AAChE,aAAW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,MAAO;AACZ,wBAAmB;AAAA,MACjB,QAAM,QAAA;AAAA,MACN,WAAS,QAAA;AAAA,MACT,OAAK,QAAA;AAAA;EAET,CAAC;;;;;;AACH;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport type { FontFallbackConfig } from '@embedpdf/engines';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n /**\n * Font fallback configuration for handling missing fonts in PDFs.\n */\n fontFallback?: FontFallbackConfig;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, fontFallback } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, fontFallback });\n engineRef = pdfEngine;\n state.engine = pdfEngine;\n state.isLoading = false;\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n"],"names":["_b","_a"],"mappings":";;;;MASM,yBAAyB,OAAO,kBAAkB;SAKxC,oBAAoB,OAA8B;AAChE,aAAW,wB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A,IACF,CAAC;AAAA,EACH;SAGO;AACT;8CChEA;;AAeE,IAAA,YAAO,MAAO;AACZ,wBAAmB;AAAA,MACjB,QAAM,QAAA;AAAA,MACN,WAAS,QAAA;AAAA,MACT,OAAK,QAAA;AAAA;EAET,CAAC;;;;;;AACH;"}
@@ -1,9 +1,14 @@
1
1
  import { Ref } from 'vue';
2
2
  import { Logger, PdfEngine } from '@embedpdf/models';
3
+ import { FontFallbackConfig } from '../../lib/index.ts';
3
4
  interface UsePdfiumEngineProps {
4
5
  wasmUrl?: string;
5
6
  worker?: boolean;
6
7
  logger?: Logger;
8
+ /**
9
+ * Font fallback configuration for handling missing fonts in PDFs.
10
+ */
11
+ fontFallback?: FontFallbackConfig;
7
12
  }
8
13
  interface UsePdfiumEngineResult {
9
14
  engine: Ref<PdfEngine | null>;
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),r=Symbol("pdfEngineKey");function t(){const n=e.inject(r);if(!n)throw new Error("useEngineContext must be used within a PdfEngineProvider");return n}const o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.2/dist/pdfium.wasm";const i=e.defineComponent({__name:"pdf-engine-provider",props:{engine:{},isLoading:{type:Boolean},error:{}},setup(n){const t=n,{engine:o,isLoading:i,error:u}=e.toRefs(t);return e.provide(r,{engine:o,isLoading:i,error:u}),(n,r)=>e.renderSlot(n.$slots,"default")}});exports.PdfEngineProvider=i,exports.useEngine=function(){const{engine:e,error:n}=t();if(n.value)throw n.value;return e},exports.useEngineContext=t,exports.usePdfiumEngine=function(r={}){const{wasmUrl:t=o,worker:i=!0,logger:u}=r,s=e.ref(null),l=e.ref(!0),d=e.ref(null);async function a(){try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,{logger:u});s.value=n,l.value=!1}catch(e){d.value=e,l.value=!1}}function c(){var e,r;null==(r=null==(e=s.value)?void 0:e.closeAllDocuments)||r.call(e).wait(()=>{var e,n;null==(n=null==(e=s.value)?void 0:e.destroy)||n.call(e),s.value=null},n.ignore)}return e.onMounted(a),e.onBeforeUnmount(c),e.watch(()=>[t,i,u],()=>{c(),a()}),{engine:s,isLoading:l,error:d}};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),r=Symbol("pdfEngineKey");function t(){const n=e.inject(r);if(!n)throw new Error("useEngineContext must be used within a PdfEngineProvider");return n}const o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.1.0/dist/pdfium.wasm";const i=e.defineComponent({__name:"pdf-engine-provider",props:{engine:{},isLoading:{type:Boolean},error:{}},setup(n){const t=n,{engine:o,isLoading:i,error:u}=e.toRefs(t);return e.provide(r,{engine:o,isLoading:i,error:u}),(n,r)=>e.renderSlot(n.$slots,"default")}});exports.PdfEngineProvider=i,exports.useEngine=function(){const{engine:e,error:n}=t();if(n.value)throw n.value;return e},exports.useEngineContext=t,exports.usePdfiumEngine=function(r={}){const{wasmUrl:t=o,worker:i=!0,logger:u,fontFallback:l}=r,s=e.ref(null),a=e.ref(!0),d=e.ref(null);async function c(){try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,{logger:u,fontFallback:l});s.value=n,a.value=!1}catch(e){d.value=e,a.value=!1}}function p(){var e,r;null==(r=null==(e=s.value)?void 0:e.closeAllDocuments)||r.call(e).wait(()=>{var e,n;null==(n=null==(e=s.value)?void 0:e.destroy)||n.call(e),s.value=null},n.ignore)}return e.onMounted(c),e.onBeforeUnmount(p),e.watch(()=>[t,i,u,l],()=>{p(),c()}),{engine:s,isLoading:a,error:d}};
2
2
  //# sourceMappingURL=index.cjs.map