svelte-pdf-view 0.1.10 → 0.1.12
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 +5 -4
- package/dist/PdfViewer.svelte +30 -30
- package/dist/pdf-viewer/context.d.ts +1 -1
- package/package.json +1 -1
package/dist/PdfRenderer.svelte
CHANGED
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
scrollbarWidth = '10px'
|
|
37
37
|
}: Props = $props();
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const context = getPdfViewerContext();
|
|
40
|
+
const { state: viewerState, _registerRenderer } = context;
|
|
40
41
|
|
|
41
|
-
// Use prop src if provided, otherwise fall back to context src
|
|
42
|
-
let src = $derived(srcProp ??
|
|
42
|
+
// Use prop src if provided, otherwise fall back to context src (via getter for reactivity)
|
|
43
|
+
let src = $derived(srcProp ?? context.src);
|
|
43
44
|
|
|
44
45
|
let hostEl: HTMLDivElement | undefined = $state();
|
|
45
46
|
let shadowRoot: ShadowRoot | null = null;
|
|
@@ -166,7 +167,7 @@
|
|
|
166
167
|
viewerState.searchTotal = 0;
|
|
167
168
|
}
|
|
168
169
|
},
|
|
169
|
-
download: () => {} // Download is handled by PdfViewer, not renderer
|
|
170
|
+
download: async () => {} // Download is handled by PdfViewer, not renderer
|
|
170
171
|
};
|
|
171
172
|
|
|
172
173
|
onMount(async () => {
|
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
|
|
@@ -117,7 +115,9 @@
|
|
|
117
115
|
setPdfViewerContext({
|
|
118
116
|
state,
|
|
119
117
|
actions,
|
|
120
|
-
src
|
|
118
|
+
get src() {
|
|
119
|
+
return src;
|
|
120
|
+
},
|
|
121
121
|
_registerRenderer: (renderer: PdfViewerActions) => {
|
|
122
122
|
rendererActions = renderer;
|
|
123
123
|
}
|
|
@@ -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