/** * PaperKnife - The Swiss Army Knife for PDFs * Copyright (C) 2026 potatameister * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. */ import { useState, useEffect, Suspense } from 'react' import { Layers, Scissors, Zap, Smartphone as SmartphoneIcon, Monitor as MonitorIcon, Lock, Unlock, RotateCw, Type, Hash, Tags, FileText, ArrowUpDown, PenTool, Wrench, ImagePlus, FileImage, Palette, X, ChevronDown } from 'lucide-react' import { HashRouter, Routes, Route, useNavigate, useLocation } from 'react-router-dom' import { Toaster, toast } from 'sonner' import { Capacitor } from '@capacitor/core' import { App as CapApp } from '@capacitor/app' import { Filesystem } from '@capacitor/filesystem' import { Theme, ViewMode, Tool } from './types' import Layout from './components/Layout' import { PipelineProvider, usePipeline } from './utils/pipelineContext' import { ViewModeProvider } from './utils/viewModeContext' import { clearActivity, updateLastSeen, getLastSeen } from './utils/recentActivity' import { useBackHandler, ensureBackListening, setBackFallback } from './utils/backHandler' import ScrollToTop from './components/ScrollToTop' // Critical Views - No lazy loading to prevent dynamic import errors on Android import WebView from './components/WebView' import AndroidView from './components/AndroidView' import AndroidToolsView from './components/AndroidToolsView' import AndroidHistoryView from './components/AndroidHistoryView' import About from './components/About' import Thanks from './components/Thanks' import SettingsView from './components/Settings' import PdfPreview from './components/PdfPreview' // Tools - Also moving to static imports for stability in APK import MergeTool from './components/tools/MergeTool' import SplitTool from './components/tools/SplitTool' import ProtectTool from './components/tools/ProtectTool' import CompressTool from './components/tools/CompressTool' import UnlockTool from './components/tools/UnlockTool' import PdfToImageTool from './components/tools/PdfToImageTool' import RotateTool from './components/tools/RotateTool' import PdfToTextTool from './components/tools/PdfToTextTool' import RearrangeTool from './components/tools/RearrangeTool' import WatermarkTool from './components/tools/WatermarkTool' import PageNumberTool from './components/tools/PageNumberTool' import MetadataTool from './components/tools/MetadataTool' import ImageToPdfTool from './components/tools/ImageToPdfTool' import SignatureTool from './components/tools/SignatureTool' import RepairTool from './components/tools/RepairTool' import ExtractImagesTool from './components/tools/ExtractImagesTool' import GrayscaleTool from './components/tools/GrayscaleTool' const tools: Tool[] = [ { title: 'Merge PDF', desc: 'Combine multiple PDF files into one document.', icon: Layers, implemented: true, path: '/merge', category: 'Edit', color: 'text-rose-500', bg: 'bg-rose-50 dark:bg-rose-900/20' }, { title: 'Split PDF', desc: 'Visually extract specific pages or ranges.', icon: Scissors, implemented: true, path: '/split', category: 'Edit', color: 'text-blue-500', bg: 'bg-blue-50 dark:bg-blue-900/20' }, { title: 'Compress PDF', desc: 'Optimize your file size for easier sharing.', icon: Zap, implemented: true, path: '/compress', category: 'Optimize', color: 'text-amber-500', bg: 'bg-amber-50 dark:bg-amber-900/20' }, { title: 'Protect PDF', desc: 'Secure your documents with strong encryption.', icon: Lock, implemented: true, path: '/protect', category: 'Secure', color: 'text-indigo-500', bg: 'bg-indigo-50 dark:bg-indigo-900/20' }, { title: 'Unlock PDF', desc: 'Remove passwords from your protected files.', icon: Unlock, implemented: true, path: '/unlock', category: 'Secure', color: 'text-violet-500', bg: 'bg-violet-50 dark:bg-violet-900/20' }, { title: 'Rotate PDF', desc: 'Fix page orientation permanently.', icon: RotateCw, implemented: true, path: '/rotate-pdf', category: 'Edit', color: 'text-orange-500', bg: 'bg-orange-50 dark:bg-orange-900/20' }, { title: 'Rearrange PDF', desc: 'Drag and drop pages to reorder them.', icon: ArrowUpDown, implemented: true, path: '/rearrange-pdf', category: 'Edit', color: 'text-emerald-500', bg: 'bg-emerald-50 dark:bg-emerald-900/20' }, { title: 'Page Numbers', desc: 'Add numbering to your documents automatically.', icon: Hash, implemented: true, path: '/page-numbers', category: 'Edit', color: 'text-sky-500', bg: 'bg-sky-50 dark:bg-sky-900/20' }, { title: 'Watermark', desc: 'Overlay custom text for branding or security.', icon: Type, implemented: true, path: '/watermark', category: 'Edit', color: 'text-purple-500', bg: 'bg-purple-50 dark:bg-purple-900/20' }, { title: 'Metadata', desc: 'Edit document properties for better privacy.', icon: Tags, implemented: true, path: '/metadata', category: 'Secure', color: 'text-cyan-500', bg: 'bg-cyan-50 dark:bg-cyan-900/20' }, { title: 'Signature', desc: 'Add your electronic signature to any document.', icon: PenTool, implemented: true, path: '/signature', category: 'Edit', color: 'text-pink-500', bg: 'bg-pink-50 dark:bg-pink-900/20' }, { title: 'Grayscale', desc: 'Convert all document pages to black and white.', icon: Palette, implemented: true, path: '/grayscale', category: 'Optimize', color: 'text-zinc-500', bg: 'bg-zinc-50 dark:bg-zinc-900/20' }, { title: 'PDF to Image', desc: 'Convert document pages into high-quality images.', icon: FileImage, implemented: true, path: '/pdf-to-image', category: 'Convert', color: 'text-lime-500', bg: 'bg-lime-50 dark:bg-lime-900/20' }, { title: 'Image to PDF', desc: 'Convert JPG, PNG, and WebP into a professional PDF.', icon: ImagePlus, implemented: true, path: '/image-to-pdf', category: 'Convert', color: 'text-teal-500', bg: 'bg-teal-50 dark:bg-teal-900/20' }, { title: 'Extract Images', desc: 'Pull out all original images embedded in a PDF.', icon: FileImage, implemented: true, path: '/extract-images', category: 'Convert', color: 'text-yellow-500', bg: 'bg-yellow-50 dark:bg-yellow-900/20' }, { title: 'PDF to Text', desc: 'Extract plain text from your PDF documents.', icon: FileText, implemented: true, path: '/pdf-to-text', category: 'Convert', color: 'text-blue-600', bg: 'bg-blue-100 dark:bg-blue-900/20' }, { title: 'Repair PDF', desc: 'Attempt to fix corrupted or unreadable documents.', icon: Wrench, implemented: true, path: '/repair', category: 'Optimize', color: 'text-red-500', bg: 'bg-red-50 dark:bg-red-900/20' }, ] export const IS_OCR_DISABLED = import.meta.env.VITE_DISABLE_OCR === 'true' export const activeTools = IS_OCR_DISABLED ? tools.filter(t => t.path !== '/pdf-to-text') : tools export const PRIVACY_URL = 'https://potatameister.github.io/privacy/paperknife' // Privacy spec lives on the support site; the in-app route hands off. function PrivacyRedirect() { useEffect(() => { window.location.replace(PRIVACY_URL) }, []) return null } function QuickDropModal({ file, onClear, onBack }: { file: File, onClear: () => void, onBack?: () => void }) { const navigate = useNavigate() const { setPipelineFile } = usePipeline() const [showMore, setShowMore] = useState(false) const essentials = activeTools.slice(0, 4) const otherTools = activeTools.slice(4) const handleAction = async (path: string, title: string) => { toast.loading(`Importing ${file.name}...`, { id: 'quick-load' }) try { const buffer = await file.arrayBuffer() setPipelineFile({ buffer: new Uint8Array(buffer), name: file.name, type: file.type || (file.name.endsWith('.zip') ? 'application/zip' : 'application/pdf') }) onClear() navigate(path) toast.success(`Opened in ${title}`, { id: 'quick-load' }) } catch (err) { toast.error('Failed to process file', { id: 'quick-load' }) } } return (
{(file.size / (1024*1024)).toFixed(2)} MB • PDF Document