svelte-pdf-view 0.1.10 → 0.1.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/dist/PdfRenderer.svelte +1 -1
- package/dist/PdfViewer.svelte +27 -29
- package/dist/pdf-viewer/context.d.ts +1 -1
- package/package.json +1 -1
package/dist/PdfRenderer.svelte
CHANGED
package/dist/PdfViewer.svelte
CHANGED
|
@@ -52,46 +52,44 @@
|
|
|
52
52
|
let rendererActions: PdfViewerActions | null = null;
|
|
53
53
|
|
|
54
54
|
// Download helper function
|
|
55
|
-
function downloadPdf(filenameOverride?: string) {
|
|
55
|
+
async function downloadPdf(filenameOverride?: string) {
|
|
56
56
|
const downloadName =
|
|
57
57
|
filenameOverride ||
|
|
58
58
|
downloadFilename ||
|
|
59
59
|
(typeof src === 'string' ? src.split('/').pop() : 'document.pdf') ||
|
|
60
60
|
'document.pdf';
|
|
61
61
|
|
|
62
|
+
let blob: Blob;
|
|
63
|
+
|
|
62
64
|
if (typeof src === 'string') {
|
|
63
|
-
// URL - fetch
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
// URL - fetch first to handle cross-origin URLs (e.g., Firebase Storage)
|
|
66
|
+
// The download attribute is ignored for cross-origin URLs
|
|
67
|
+
try {
|
|
68
|
+
const response = await fetch(src);
|
|
69
|
+
blob = await response.blob();
|
|
70
|
+
} catch {
|
|
71
|
+
// Fallback for same-origin URLs if fetch fails
|
|
72
|
+
const link = document.createElement('a');
|
|
73
|
+
link.href = src;
|
|
74
|
+
link.download = downloadName;
|
|
75
|
+
link.click();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
68
78
|
} else if (src instanceof Blob) {
|
|
69
|
-
|
|
70
|
-
const url = URL.createObjectURL(src);
|
|
71
|
-
const link = document.createElement('a');
|
|
72
|
-
link.href = url;
|
|
73
|
-
link.download = downloadName;
|
|
74
|
-
link.click();
|
|
75
|
-
URL.revokeObjectURL(url);
|
|
79
|
+
blob = src;
|
|
76
80
|
} else if (src instanceof ArrayBuffer) {
|
|
77
|
-
|
|
78
|
-
const blob = new Blob([src], { type: 'application/pdf' });
|
|
79
|
-
const url = URL.createObjectURL(blob);
|
|
80
|
-
const link = document.createElement('a');
|
|
81
|
-
link.href = url;
|
|
82
|
-
link.download = downloadName;
|
|
83
|
-
link.click();
|
|
84
|
-
URL.revokeObjectURL(url);
|
|
81
|
+
blob = new Blob([src], { type: 'application/pdf' });
|
|
85
82
|
} else {
|
|
86
|
-
// Uint8Array
|
|
87
|
-
|
|
88
|
-
const url = URL.createObjectURL(blob);
|
|
89
|
-
const link = document.createElement('a');
|
|
90
|
-
link.href = url;
|
|
91
|
-
link.download = downloadName;
|
|
92
|
-
link.click();
|
|
93
|
-
URL.revokeObjectURL(url);
|
|
83
|
+
// Uint8Array
|
|
84
|
+
blob = new Blob([new Uint8Array(src)], { type: 'application/pdf' });
|
|
94
85
|
}
|
|
86
|
+
|
|
87
|
+
const url = URL.createObjectURL(blob);
|
|
88
|
+
const link = document.createElement('a');
|
|
89
|
+
link.href = url;
|
|
90
|
+
link.download = downloadName;
|
|
91
|
+
link.click();
|
|
92
|
+
URL.revokeObjectURL(url);
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
// Actions that proxy to the renderer
|
|
@@ -23,7 +23,7 @@ export interface PdfViewerActions {
|
|
|
23
23
|
searchNext: () => void;
|
|
24
24
|
searchPrevious: () => void;
|
|
25
25
|
clearSearch: () => void;
|
|
26
|
-
download: (filename?: string) => void
|
|
26
|
+
download: (filename?: string) => Promise<void>;
|
|
27
27
|
}
|
|
28
28
|
export interface PdfViewerContext {
|
|
29
29
|
state: PdfViewerState;
|
package/package.json
CHANGED