@libresign/pdf-elements 0.3.0 → 0.3.1

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@libresign/pdf-elements",
3
3
  "description": "PDF viewer with draggable and resizable element overlays for Vue 2",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "author": "LibreCode <contact@librecode.coop>",
6
6
  "private": false,
7
7
  "main": "dist/pdf-elements.umd.js",
@@ -1,11 +1,20 @@
1
1
  // SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
2
2
  // SPDX-License-Identifier: AGPL-3.0-or-later
3
3
 
4
- import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist'
4
+ import { getDocument, GlobalWorkerOptions, PDFWorker } from 'pdfjs-dist'
5
5
  import pdfWorkerCode from 'pdfjs-dist/build/pdf.worker.min.mjs'
6
6
 
7
7
  GlobalWorkerOptions.workerSrc = pdfWorkerCode
8
8
 
9
+ let sharedWorker = null
10
+
11
+ function getSharedWorker() {
12
+ if (!sharedWorker) {
13
+ sharedWorker = new PDFWorker({ name: 'libresign-pdf-worker' })
14
+ }
15
+ return sharedWorker
16
+ }
17
+
9
18
  export function setWorkerPath(path) {
10
19
  GlobalWorkerOptions.workerSrc = path
11
20
  }
@@ -20,5 +29,16 @@ export function readAsArrayBuffer(file) {
20
29
  }
21
30
 
22
31
  export function readAsPDF(file) {
23
- return getDocument(file).promise
32
+ const worker = getSharedWorker()
33
+ const isArrayBuffer = file instanceof ArrayBuffer
34
+ const isView = ArrayBuffer.isView(file)
35
+ const isBlob = typeof Blob !== 'undefined' && file instanceof Blob
36
+
37
+ if (file && typeof file === 'object' && !isArrayBuffer && !isView && !isBlob) {
38
+ return getDocument({ ...file, worker }).promise
39
+ }
40
+ if (typeof file === 'string') {
41
+ return getDocument({ url: file, worker }).promise
42
+ }
43
+ return getDocument({ data: file, worker }).promise
24
44
  }