genus-pdf-viewer 0.2.3 → 0.2.11

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,16 @@ The viewer emits bubbling custom events:
104
108
  ## Package Exports
105
109
 
106
110
  - `genus-pdf-viewer`: main TypeScript and custom-element API
107
- - `genus-pdf-viewer/pdf.worker.min.mjs`: worker asset if you need to host it yourself
111
+ - `genus-pdf-viewer/pdf.worker.bootstrap.mjs`: optional bootstrap worker asset for strict CSP deployments
112
+ - `genus-pdf-viewer/pdf.worker.min.mjs`: optional 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
+ The default setup is npm-install-only. The viewer creates a self-contained Blob worker URL for pdf.js, so Angular, Vite, Amplify, and other static hosts do not need to copy `pdf.worker*.mjs` into `/assets`.
113
118
 
114
119
  ```ts
115
120
  import { createGenusPdfViewer } from "genus-pdf-viewer";
116
- import workerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url";
117
121
 
118
122
  const host = document.getElementById("pdf-root");
119
123
 
@@ -124,12 +128,51 @@ if (host) {
124
128
  continuous: true,
125
129
  showToolbar: true,
126
130
  zoomStep: 0.15,
127
- workerSrc: workerUrl,
128
131
  });
129
132
  }
130
133
  ```
131
134
 
132
- This is the setup used in `carewall_genusconnect` to avoid worker-path mismatches and fake-worker fallback.
135
+ If your app has a strict Content Security Policy that blocks `blob:` workers, copy the package worker assets into your app assets folder and pass `workerSrc` explicitly.
136
+
137
+ ```json
138
+ {
139
+ "glob": "pdf.worker*.mjs",
140
+ "input": "node_modules/genus-pdf-viewer/dist",
141
+ "output": "/assets"
142
+ }
143
+ ```
144
+
145
+ ```ts
146
+ import { createGenusPdfViewer } from "genus-pdf-viewer";
147
+
148
+ const host = document.getElementById("pdf-root");
149
+
150
+ if (host) {
151
+ createGenusPdfViewer(host, {
152
+ src: pdfUrl,
153
+ fit: "width",
154
+ continuous: true,
155
+ showToolbar: true,
156
+ zoomStep: 0.15,
157
+ workerSrc: "/assets/pdf.worker.bootstrap.mjs",
158
+ });
159
+ }
160
+ ```
161
+
162
+ 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:
163
+
164
+ - allowing your app origin in the PDF host's CORS policy
165
+ - fetching the PDF in your app/backend and passing a `Blob` or `Uint8Array` to the viewer instead of the remote URL
166
+ - routing the request through your own same-origin proxy and passing `proxyUrl`
167
+
168
+ ```ts
169
+ createGenusPdfViewer(host, {
170
+ src: pdfUrl,
171
+ fit: "width",
172
+ continuous: true,
173
+ proxyUrl: "/api/pdf-proxy",
174
+ });
175
+ ```
133
176
 
134
177
  ## Demo
135
178
 
@@ -151,7 +194,7 @@ npm pack --dry-run
151
194
 
152
195
  ## Publish
153
196
 
154
- This repo is configured for the existing public npm package `genus-pdf-viewer`.
197
+ This repo is configured to publish the npm package `genus-pdf-viewer`.
155
198
 
156
199
  ```bash
157
200
  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, releaseDefaultPdfWorkerSrc, 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,EAC1B,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, releaseDefaultPdfWorkerSrc, 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,EAC1B,0BAA0B,GAC3B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const PDF_WORKER_SOURCE: string;
2
+ //# sourceMappingURL=pdf-worker-source.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-worker-source.generated.d.ts","sourceRoot":"","sources":["../src/pdf-worker-source.generated.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,EAAE,MAAko8wC,CAAC"}