@drvillo/react-browser-e-signing 0.1.3 → 0.2.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.
- package/README.md +44 -12
- package/dist/pdf.worker.min.mjs +21 -0
- package/dist/worker.d.mts +1 -0
- package/dist/worker.mjs +3 -0
- package/package.json +23 -16
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ pnpm demo
|
|
|
62
62
|
### Configuration
|
|
63
63
|
|
|
64
64
|
- `configure(options)` — PDF worker URL, signature font mode (`network` | `local-only`), optional `fontUrlResolver`, optional `onWarning` callback
|
|
65
|
+
- `getPdfWorkerSrc()` — from `@drvillo/react-browser-e-signing/worker`; returns a bundler-resolved URL for the packaged `pdf.worker.min.mjs` (recommended default for `pdfWorkerSrc`)
|
|
65
66
|
- Types: `ESigningConfig`, `SignatureFontWarning`
|
|
66
67
|
|
|
67
68
|
### Types
|
|
@@ -126,9 +127,11 @@ pnpm test
|
|
|
126
127
|
pnpm typecheck
|
|
127
128
|
```
|
|
128
129
|
|
|
130
|
+
After a fresh clone, run **`pnpm build` once** so `dist/` includes the bundled worker, `worker.mjs`, and types (the copy step runs after tsup’s type emit).
|
|
131
|
+
|
|
129
132
|
## Notes
|
|
130
133
|
|
|
131
|
-
- **PDF worker:** the package does **not** inject a
|
|
134
|
+
- **PDF worker:** PDF.js **must** load its worker from a URL. This package ships `pdf.worker.min.mjs` built from the same `pdfjs-dist` version as `react-pdf` (see **Bundled PDF.js worker** below). The package does **not** inject a CDN URL by default; call `configure({ pdfWorkerSrc: getPdfWorkerSrc() })` or set `workerSrc` on `PdfViewer` so the worker loads (recommended for production). See **Production hardening** below.
|
|
132
135
|
- Browser test config skips execution when Playwright Chromium is not available in the environment.
|
|
133
136
|
- Demo theme switcher (`default` / `custom`) shows how a container app can fully re-theme the same components.
|
|
134
137
|
|
|
@@ -136,30 +139,59 @@ pnpm typecheck
|
|
|
136
139
|
|
|
137
140
|
Runtime calls to external CDNs (PDF.js worker, Google Fonts) often fail in real apps: **CSP** (`worker-src`, `connect-src`, `font-src`), ad blockers, corporate proxies, or offline users. They also add noisy console errors (`Failed to fetch`) even when the rest of the UI works. This library defaults to **no injected worker URL** and lets you control loading explicitly.
|
|
138
141
|
|
|
139
|
-
###
|
|
142
|
+
### Bundled PDF.js worker (recommended)
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
The npm package includes `pdf.worker.min.mjs` at the same path layout as `react-pdf`’s `pdfjs-dist` dependency, so you do **not** need unpkg or a manual copy script for the default flow.
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
cp node_modules/pdfjs-dist/build/pdf.worker.min.mjs public/pdf.worker.min.mjs
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Then configure once (e.g. in your app entry or root layout client component):
|
|
146
|
+
Configure once (e.g. app entry or a client-only module):
|
|
148
147
|
|
|
149
148
|
```tsx
|
|
150
149
|
import { configure } from '@drvillo/react-browser-e-signing'
|
|
150
|
+
import { getPdfWorkerSrc } from '@drvillo/react-browser-e-signing/worker'
|
|
151
151
|
|
|
152
|
-
configure({ pdfWorkerSrc:
|
|
152
|
+
configure({ pdfWorkerSrc: getPdfWorkerSrc() })
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
`getPdfWorkerSrc()` uses `new URL('./pdf.worker.min.mjs', import.meta.url)` so Vite, webpack 5, and similar bundlers emit the worker as an asset and rewrite the URL. **Do not** point at a third-party CDN in production if you can avoid it.
|
|
156
|
+
|
|
155
157
|
Or per viewer:
|
|
156
158
|
|
|
157
159
|
```tsx
|
|
158
|
-
|
|
160
|
+
import { getPdfWorkerSrc } from '@drvillo/react-browser-e-signing/worker'
|
|
161
|
+
|
|
162
|
+
<PdfViewer workerSrc={getPdfWorkerSrc()} {...pdfViewerProps} />
|
|
159
163
|
```
|
|
160
164
|
|
|
161
165
|
`workerSrc` on `PdfViewer` overrides `configure({ pdfWorkerSrc })`.
|
|
162
166
|
|
|
167
|
+
**Advanced:** import the raw file (e.g. Vite):
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
import workerUrl from '@drvillo/react-browser-e-signing/pdf.worker.min.mjs?url'
|
|
171
|
+
|
|
172
|
+
configure({ pdfWorkerSrc: workerUrl })
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Versioning:** when this library upgrades `react-pdf` / `pdfjs-dist`, the published worker file is regenerated from that `pdfjs-dist` version. Keep your app on the published package version you intend; do not mix a different `pdfjs-dist` worker binary with another API version.
|
|
176
|
+
|
|
177
|
+
**SSR / Next.js App Router:** PDF.js runs in the browser. Set `pdfWorkerSrc` only on the client — e.g. in `useEffect`, or in a file loaded via `dynamic(..., { ssr: false })`, or in a client-only entry — so `getPdfWorkerSrc()` and worker loading are not evaluated during SSR.
|
|
178
|
+
|
|
179
|
+
### Manual self-host (fallback)
|
|
180
|
+
|
|
181
|
+
If you prefer serving the worker from your own `public/` folder, copy the file that matches the `pdfjs-dist` version used by `react-pdf` (see `node_modules/react-pdf/package.json`):
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
cp node_modules/pdfjs-dist/build/pdf.worker.min.mjs public/pdf.worker.min.mjs
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Then:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { configure } from '@drvillo/react-browser-e-signing'
|
|
191
|
+
|
|
192
|
+
configure({ pdfWorkerSrc: '/pdf.worker.min.mjs' })
|
|
193
|
+
```
|
|
194
|
+
|
|
163
195
|
### Typed signatures: local-only fonts (no network)
|
|
164
196
|
|
|
165
197
|
Skip all font fetches (handwriting fonts won’t load from Google; the browser uses whatever faces are already available, with sensible fallback):
|
|
@@ -194,13 +226,13 @@ Warnings are non-throwing; signing flow should remain usable.
|
|
|
194
226
|
|
|
195
227
|
### CSP-oriented example
|
|
196
228
|
|
|
197
|
-
If everything is same-origin:
|
|
229
|
+
If everything is same-origin (including the worker URL after your bundler emits it):
|
|
198
230
|
|
|
199
231
|
```
|
|
200
232
|
Content-Security-Policy: worker-src 'self'; script-src 'self'; connect-src 'self'; font-src 'self';
|
|
201
233
|
```
|
|
202
234
|
|
|
203
|
-
Adjust `connect-src` / `font-src` if you still use Google Fonts or
|
|
235
|
+
A self-hosted worker loaded from the same origin as your app typically satisfies `worker-src 'self'`. Adjust `connect-src` / `font-src` if you still use Google Fonts or load scripts from elsewhere.
|
|
204
236
|
|
|
205
237
|
### Migration from v0.1.2 and earlier
|
|
206
238
|
|