From a11826e91236bb5839a5de0765fac13038528586 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:50:59 -0600 Subject: [PATCH] feat: add booklet download button, remove pdfjs-dist dependency - Add save/download button to booklet toolbar with native file dialog - Add v2_booklet_save command to copy PDF to user-chosen location - Remove pdfjs-dist npm package (replaced by MuPDF backend) - Delete static/pdfjs/ files (~1.9MB: worker, WASM decoders, fallbacks) - Add bookletDownload i18n keys to all 4 locales --- package-lock.json | 271 ----------------------- package.json | 1 - src-tauri/src/lib.rs | 1 + src-tauri/src/pdf_viewer.rs | 20 ++ src/lib/components/BookletViewer.svelte | 27 ++- src/lib/i18n/locales/de.json | 3 +- src/lib/i18n/locales/en.json | 3 +- src/lib/i18n/locales/es.json | 3 +- src/lib/i18n/locales/fr.json | 3 +- static/pdfjs/jbig2.wasm | Bin 105557 -> 0 bytes static/pdfjs/openjpeg.wasm | Bin 250009 -> 0 bytes static/pdfjs/openjpeg_nowasm_fallback.js | 17 -- static/pdfjs/pdf.worker.min.mjs | 28 --- static/pdfjs/qcms_bg.wasm | Bin 94519 -> 0 bytes 14 files changed, 55 insertions(+), 322 deletions(-) delete mode 100644 static/pdfjs/jbig2.wasm delete mode 100644 static/pdfjs/openjpeg.wasm delete mode 100644 static/pdfjs/openjpeg_nowasm_fallback.js delete mode 100644 static/pdfjs/pdf.worker.min.mjs delete mode 100644 static/pdfjs/qcms_bg.wasm diff --git a/package-lock.json b/package-lock.json index 0258e593b..87e7a2f9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@tauri-apps/plugin-dialog": "^2.5.0", "@tauri-apps/plugin-opener": "^2", "lucide-svelte": "^0.562.0", - "pdfjs-dist": "^5.4.624", "svelte-i18n": "^4.0.0" }, "devDependencies": { @@ -773,256 +772,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@napi-rs/canvas": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-0.1.95.tgz", - "integrity": "sha512-lkg23ge+rgyhgUwXmlbkPEhuhHq/hUi/gXKH+4I7vO+lJrbNfEYcQdJLIGjKyXLQzgFiiyDAwh5vAe/tITAE+w==", - "license": "MIT", - "optional": true, - "workspaces": [ - "e2e/*" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - }, - "optionalDependencies": { - "@napi-rs/canvas-android-arm64": "0.1.95", - "@napi-rs/canvas-darwin-arm64": "0.1.95", - "@napi-rs/canvas-darwin-x64": "0.1.95", - "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.95", - "@napi-rs/canvas-linux-arm64-gnu": "0.1.95", - "@napi-rs/canvas-linux-arm64-musl": "0.1.95", - "@napi-rs/canvas-linux-riscv64-gnu": "0.1.95", - "@napi-rs/canvas-linux-x64-gnu": "0.1.95", - "@napi-rs/canvas-linux-x64-musl": "0.1.95", - "@napi-rs/canvas-win32-arm64-msvc": "0.1.95", - "@napi-rs/canvas-win32-x64-msvc": "0.1.95" - } - }, - "node_modules/@napi-rs/canvas-android-arm64": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.95.tgz", - "integrity": "sha512-SqTh0wsYbetckMXEvHqmR7HKRJujVf1sYv1xdlhkifg6TlCSysz1opa49LlS3+xWuazcQcfRfmhA07HxxxGsAA==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-darwin-arm64": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.95.tgz", - "integrity": "sha512-F7jT0Syu+B9DGBUBcMk3qCRIxAWiDXmvEjamwbYfbZl7asI1pmXZUnCOoIu49Wt0RNooToYfRDxU9omD6t5Xuw==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-darwin-x64": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.95.tgz", - "integrity": "sha512-54eb2Ho15RDjYGXO/harjRznBrAvu+j5nQ85Z4Qd6Qg3slR8/Ja+Yvvy9G4yo7rdX6NR9GPkZeSTf2UcKXwaXw==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-arm-gnueabihf": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.95.tgz", - "integrity": "sha512-hYaLCSLx5bmbnclzQc3ado3PgZ66blJWzjXp0wJmdwpr/kH+Mwhj6vuytJIomgksyJoCdIqIa4N6aiqBGJtJ5Q==", - "cpu": [ - "arm" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-arm64-gnu": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.95.tgz", - "integrity": "sha512-J7VipONahKsmScPZsipHVQBqpbZx4favaD8/enWzzlGcjiwycOoymL7f4tNeqdjK0su19bDOUt6mjp9gsPWYlw==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-arm64-musl": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.95.tgz", - "integrity": "sha512-PXy0UT1J/8MPG8UAkWp6Fd51ZtIZINFzIjGH909JjQrtCuJf3X6nanHYdz1A+Wq9o4aoPAw1YEUpFS1lelsVlg==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-riscv64-gnu": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-0.1.95.tgz", - "integrity": "sha512-2IzCkW2RHRdcgF9W5/plHvYFpc6uikyjMb5SxjqmNxfyDFz9/HB89yhi8YQo0SNqrGRI7yBVDec7Pt+uMyRWsg==", - "cpu": [ - "riscv64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-x64-gnu": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.95.tgz", - "integrity": "sha512-OV/ol/OtcUr4qDhQg8G7SdViZX8XyQeKpPsVv/j3+7U178FGoU4M+yIocdVo1ih/A8GQ63+LjF4jDoEjaVU8Pw==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-linux-x64-musl": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.95.tgz", - "integrity": "sha512-Z5KzqBK/XzPz5+SFHKz7yKqClEQ8pOiEDdgk5SlphBLVNb8JFIJkxhtJKSvnJyHh2rjVgiFmvtJzMF0gNwwKyQ==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-win32-arm64-msvc": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-arm64-msvc/-/canvas-win32-arm64-msvc-0.1.95.tgz", - "integrity": "sha512-aj0YbRpe8qVJ4OzMsK7NfNQePgcf9zkGFzNZ9mSuaxXzhpLHmlF2GivNdCdNOg8WzA/NxV6IU4c5XkXadUMLeA==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, - "node_modules/@napi-rs/canvas-win32-x64-msvc": { - "version": "0.1.95", - "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.95.tgz", - "integrity": "sha512-GA8leTTCfdjuHi8reICTIxU0081PhXvl3lzIniLUjeLACx9GubUiyzkwFb+oyeKLS5IAGZFLKnzAf4wm2epRlA==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - } - }, "node_modules/@polka/url": { "version": "1.0.0-next.29", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz", @@ -2720,13 +2469,6 @@ "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", "license": "ISC" }, - "node_modules/node-readable-to-web-readable-stream": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/node-readable-to-web-readable-stream/-/node-readable-to-web-readable-stream-0.4.2.tgz", - "integrity": "sha512-/cMZNI34v//jUTrI+UIo4ieHAB5EZRY/+7OmXZgBxaWBMcW2tGdceIw06RFxWxrKZ5Jp3sI2i5TsRo+CBhtVLQ==", - "license": "MIT", - "optional": true - }, "node_modules/obug": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz", @@ -2758,19 +2500,6 @@ "dev": true, "license": "MIT" }, - "node_modules/pdfjs-dist": { - "version": "5.4.624", - "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.4.624.tgz", - "integrity": "sha512-sm6TxKTtWv1Oh6n3C6J6a8odejb5uO4A4zo/2dgkHuC0iu8ZMAXOezEODkVaoVp8nX1Xzr+0WxFJJmUr45hQzg==", - "license": "Apache-2.0", - "engines": { - "node": ">=20.16.0 || >=22.3.0" - }, - "optionalDependencies": { - "@napi-rs/canvas": "^0.1.88", - "node-readable-to-web-readable-stream": "^0.4.2" - } - }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", diff --git a/package.json b/package.json index 53caafa8f..2a95ffe70 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "@tauri-apps/plugin-dialog": "^2.5.0", "@tauri-apps/plugin-opener": "^2", "lucide-svelte": "^0.562.0", - "pdfjs-dist": "^5.4.624", "svelte-i18n": "^4.0.0" }, "devDependencies": { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a301384e1..2ba3e396d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1431,6 +1431,7 @@ pub fn run() { // PDF booklet viewer (MuPDF backend) pdf_viewer::v2_booklet_open, pdf_viewer::v2_booklet_render_page, + pdf_viewer::v2_booklet_save, pdf_viewer::v2_booklet_close, ]) .run(tauri::generate_context!()) diff --git a/src-tauri/src/pdf_viewer.rs b/src-tauri/src/pdf_viewer.rs index c009da8e0..4d9e71352 100644 --- a/src-tauri/src/pdf_viewer.rs +++ b/src-tauri/src/pdf_viewer.rs @@ -232,6 +232,26 @@ pub async fn v2_booklet_render_page( .map_err(|e| format!("Render task failed: {}", e))? } +/// Copy the current booklet PDF to a user-chosen destination. +#[tauri::command] +pub async fn v2_booklet_save( + dest: String, + state: tauri::State<'_, BookletState>, +) -> Result<(), String> { + let src = { + let path_lock = state.current_path.lock().map_err(|e| e.to_string())?; + path_lock + .as_ref() + .ok_or_else(|| "No booklet is open".to_string())? + .clone() + }; + + std::fs::copy(&src, &dest) + .map_err(|e| format!("Failed to save booklet: {}", e))?; + + Ok(()) +} + /// Clean up the current booklet temp file. #[tauri::command] pub async fn v2_booklet_close( diff --git a/src/lib/components/BookletViewer.svelte b/src/lib/components/BookletViewer.svelte index 9bb9ca7f2..211757bc5 100644 --- a/src/lib/components/BookletViewer.svelte +++ b/src/lib/components/BookletViewer.svelte @@ -2,7 +2,8 @@ import { tick } from 'svelte'; import { t } from 'svelte-i18n'; import { invoke } from '@tauri-apps/api/core'; - import { X, ChevronLeft, ChevronRight, ZoomIn, ZoomOut, Maximize, RotateCw } from 'lucide-svelte'; + import { X, ChevronLeft, ChevronRight, ZoomIn, ZoomOut, Maximize, RotateCw, Download } from 'lucide-svelte'; + import { save } from '@tauri-apps/plugin-dialog'; interface PageSize { width: number; @@ -174,6 +175,26 @@ renderPage(); } + async function downloadBooklet() { + if (!bookletLoaded) return; + + const defaultName = title + ? `${title}.pdf` + : 'Booklet.pdf'; + + const dest = await save({ + filters: [{ name: 'PDF', extensions: ['pdf'] }], + defaultPath: defaultName, + }); + if (!dest) return; + + try { + await invoke('v2_booklet_save', { dest }); + } catch (err: any) { + console.error('[BookletViewer] Save error:', err); + } + } + function handleKeydown(e: KeyboardEvent) { if (!isOpen) return; @@ -270,6 +291,10 @@ +
+