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 +34 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pdf.worker.bootstrap.mjs +43 -0
- package/dist/pdf.worker.min.mjs +4 -4
- package/dist/styles.css +211 -34
- package/dist/styles.d.ts +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +211 -34
- package/dist/styles.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -0
- package/dist/types.js.map +0 -0
- package/dist/viewer.d.ts +6 -0
- package/dist/viewer.d.ts.map +1 -1
- package/dist/viewer.js +640 -85
- package/dist/viewer.js.map +1 -1
- package/package.json +3 -5
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.
|
|
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
|
|
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:
|
|
141
|
+
workerSrc: resolveDefaultPdfWorkerSrc(),
|
|
128
142
|
});
|
|
129
143
|
}
|
|
130
144
|
```
|
|
131
145
|
|
|
132
|
-
|
|
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
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,
|
|
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,
|
|
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");
|