genus-pdf-viewer 0.2.3 → 0.2.10

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/README.md CHANGED
@@ -15,7 +15,7 @@ Framework-agnostic PDF viewer built on `pdfjs-dist` with a custom element and a
15
15
  npm install genus-pdf-viewer
16
16
  ```
17
17
 
18
- The package ships `pdf.worker.min.mjs` and resolves it automatically from the built package. Override `workerSrc` only if your app needs a custom asset location.
18
+ The package ships `pdf.worker.bootstrap.mjs` and `pdf.worker.min.mjs`. Unbundled package usage resolves the worker beside the built package; bundled app usage resolves `assets/pdf.worker.bootstrap.mjs`, so host apps should copy both worker files into their deployed assets.
19
19
 
20
20
  ## Breaking Change
21
21
 
@@ -56,6 +56,7 @@ defineGenusPdfViewerElement();
56
56
  ```html
57
57
  <genus-pdf-viewer
58
58
  src="https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf"
59
+ proxy-url="/api/pdf-proxy"
59
60
  page="1"
60
61
  zoom="1"
61
62
  fit="width"
@@ -77,6 +78,9 @@ Config fields:
77
78
  - `fit?`: `"width" | "page" | "none"`
78
79
  - `continuous?`, `showToolbar?`, `allowDownload?`
79
80
  - `workerSrc?`: override the default worker URL
81
+ - `proxyUrl?`: route cross-origin URL PDFs through your own same-origin proxy endpoint
82
+ If omitted, the viewer first tries `"/__proxy"` for cross-origin URL sources and falls back to the direct URL if that route is unavailable.
83
+ Set `proxyUrl: false` if you want to skip the proxy attempt.
80
84
  - `withCredentials?`, `httpHeaders?`: network request options for URL sources
81
85
 
82
86
  Element methods:
@@ -104,16 +108,26 @@ The viewer emits bubbling custom events:
104
108
  ## Package Exports
105
109
 
106
110
  - `genus-pdf-viewer`: main TypeScript and custom-element API
111
+ - `genus-pdf-viewer/pdf.worker.bootstrap.mjs`: bootstrap worker asset for host app copying
107
112
  - `genus-pdf-viewer/pdf.worker.min.mjs`: worker asset if you need to host it yourself
108
113
  - `genus-pdf-viewer/styles.css`: packaged stylesheet export
109
114
 
110
115
  ## Angular / Vite Setup
111
116
 
112
- If your Angular app is using Vite-based dev/build tooling, prefer the JS API and pass a worker URL from the app's own `pdfjs-dist` install so the API and worker versions always match.
117
+ If your Angular app bundles dependencies, copy the package worker assets into the app assets folder so the default worker URL can be served from `assets/pdf.worker.bootstrap.mjs`.
118
+
119
+ ```json
120
+ {
121
+ "glob": "pdf.worker*.mjs",
122
+ "input": "node_modules/genus-pdf-viewer/dist",
123
+ "output": "/assets"
124
+ }
125
+ ```
126
+
127
+ Override `workerSrc` only when your app needs a different asset location.
113
128
 
114
129
  ```ts
115
- import { createGenusPdfViewer } from "genus-pdf-viewer";
116
- import workerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url";
130
+ import { createGenusPdfViewer, resolveDefaultPdfWorkerSrc } from "genus-pdf-viewer";
117
131
 
118
132
  const host = document.getElementById("pdf-root");
119
133
 
@@ -124,12 +138,25 @@ if (host) {
124
138
  continuous: true,
125
139
  showToolbar: true,
126
140
  zoomStep: 0.15,
127
- workerSrc: workerUrl,
141
+ workerSrc: resolveDefaultPdfWorkerSrc(),
128
142
  });
129
143
  }
130
144
  ```
131
145
 
132
- This is the setup used in `carewall_genusconnect` to avoid worker-path mismatches and fake-worker fallback.
146
+ If a remote PDF URL loads in the browser but fails inside the viewer with a CORS-style error, the PDF host is blocking fetch access for your app origin. This package cannot bypass that browser restriction. Fix it by either:
147
+
148
+ - allowing your app origin in the PDF host's CORS policy
149
+ - fetching the PDF in your app/backend and passing a `Blob` or `Uint8Array` to the viewer instead of the remote URL
150
+ - routing the request through your own same-origin proxy and passing `proxyUrl`
151
+
152
+ ```ts
153
+ createGenusPdfViewer(host, {
154
+ src: pdfUrl,
155
+ fit: "width",
156
+ continuous: true,
157
+ proxyUrl: "/api/pdf-proxy",
158
+ });
159
+ ```
133
160
 
134
161
  ## Demo
135
162
 
@@ -151,7 +178,7 @@ npm pack --dry-run
151
178
 
152
179
  ## Publish
153
180
 
154
- This repo is configured for the existing public npm package `genus-pdf-viewer`.
181
+ This repo is configured to publish the npm package `genus-pdf-viewer`.
155
182
 
156
183
  ```bash
157
184
  npm publish
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { createGenusPdfViewer, defineGenusPdfViewerElement, GenusPdfViewerElement, } from "./viewer.js";
1
+ export { createGenusPdfViewer, defineGenusPdfViewerElement, GenusPdfViewerElement, PDF_WORKER_BOOTSTRAP_ASSET_PATH, resolveDefaultPdfWorkerSrc, } from "./viewer.js";
2
+ export type { ResolveDefaultPdfWorkerSrcOptions } from "./viewer.js";
2
3
  export type { GenusPdfViewerConfig, GenusPdfViewerErrorEventDetail, GenusPdfViewerEventMap, GenusPdfViewerFit, GenusPdfViewerPageChangeEventDetail, GenusPdfViewerReadyEventDetail, GenusPdfViewerSource, GenusPdfViewerZoomChangeEventDetail, } from "./types.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,sBAAsB,EACtB,iBAAiB,EACjB,mCAAmC,EACnC,8BAA8B,EAC9B,oBAAoB,EACpB,mCAAmC,GACpC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAErE,YAAY,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,sBAAsB,EACtB,iBAAiB,EACjB,mCAAmC,EACnC,8BAA8B,EAC9B,oBAAoB,EACpB,mCAAmC,GACpC,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { createGenusPdfViewer, defineGenusPdfViewerElement, GenusPdfViewerElement, } from "./viewer.js";
1
+ export { createGenusPdfViewer, defineGenusPdfViewerElement, GenusPdfViewerElement, PDF_WORKER_BOOTSTRAP_ASSET_PATH, resolveDefaultPdfWorkerSrc, } from "./viewer.js";
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,43 @@
1
+ if (typeof Promise.try !== "function") {
2
+ Promise.try = (callback, ...args) =>
3
+ new Promise((resolve, reject) => {
4
+ try {
5
+ resolve(callback(...args));
6
+ } catch (error) {
7
+ reject(error);
8
+ }
9
+ });
10
+ }
11
+
12
+ if (typeof Promise.withResolvers !== "function") {
13
+ Promise.withResolvers = () => {
14
+ let resolve;
15
+ let reject;
16
+ const promise = new Promise((promiseResolve, promiseReject) => {
17
+ resolve = promiseResolve;
18
+ reject = promiseReject;
19
+ });
20
+
21
+ return {
22
+ promise,
23
+ resolve,
24
+ reject,
25
+ };
26
+ };
27
+ }
28
+
29
+ if (typeof URL !== "undefined" && typeof URL.parse !== "function") {
30
+ URL.parse = (input, base) => {
31
+ try {
32
+ if (typeof base === "undefined") {
33
+ return new URL(input);
34
+ }
35
+
36
+ return new URL(input, base);
37
+ } catch {
38
+ return null;
39
+ }
40
+ };
41
+ }
42
+
43
+ await import("./pdf.worker.min.mjs");