) => {
if (e.target.files) {
setFiles(Array.from(e.target.files));
}
};
const simulateProcess = async () => {
if (files.length === 0 && !['pass-gen', 'age-calc', 'bmi-calc', 'json-fmt', 'tts', 'timer', 'color-picker'].includes(tool.id)) return;
setStatus('uploading');
let p = 0;
const interval = setInterval(() => {
p += 10;
setProgress(p);
if (p >= 100) {
clearInterval(interval);
setStatus('processing');
setTimeout(() => {
setStatus('done');
// For real tools, we'd set the result here
if (tool.category === 'pdf' || tool.category === 'image') {
setResult('download_ready');
}
}, 1500);
}
}, 100);
};
const generatePassword = () => {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+";
let retVal = "";
for (let i = 0; i < 16; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * charset.length));
}
setPassword(retVal);
};
const calculateBMI = () => {
const w = parseFloat(bmi.weight);
const h = parseFloat(bmi.height) / 100;
if (w > 0 && h > 0) {
const res = (w / (h * h)).toFixed(2);
setBmi(prev => ({ ...prev, result: res }));
}
};
const calculateAge = () => {
if (!age.birthDate) return;
const birth = new Date(age.birthDate);
const now = new Date();
let years = now.getFullYear() - birth.getFullYear();
const m = now.getMonth() - birth.getMonth();
if (m < 0 || (m === 0 && now.getDate() < birth.getDate())) {
years--;
}
setAge(prev => ({ ...prev, result: years.toString() }));
};
const formatJSON = () => {
try {
const obj = JSON.parse(jsonInput);
setJsonInput(JSON.stringify(obj, null, 2));
} catch (e) {
alert("Invalid JSON");
}
};
const convertUnits = () => {
const val = parseFloat(unit.value);
if (isNaN(val)) return;
let res = 0;
if (unit.from === 'cm' && unit.to === 'inch') res = val / 2.54;
if (unit.from === 'inch' && unit.to === 'cm') res = val * 2.54;
if (unit.from === 'kg' && unit.to === 'lb') res = val * 2.20462;
if (unit.from === 'lb' && unit.to === 'kg') res = val / 2.20462;
setUnit(prev => ({ ...prev, result: res.toFixed(2) }));
};
const processImage = async () => {
if (files.length === 0) return;
setStatus('processing');
const file = files[0];
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx?.drawImage(img, 0, 0);
let mime = 'image/jpeg';
if (tool.id === 'img-convert') {
// Simple toggle for demo
mime = file.type === 'image/png' ? 'image/jpeg' : 'image/png';
}
const dataUrl = canvas.toDataURL(mime, 0.7);
setResult(dataUrl);
setStatus('done');
};
img.src = e.target?.result as string;
};
reader.readAsDataURL(file);
};
const speakText = () => {
if (!textInput) return;
const utterance = new SpeechSynthesisUtterance(textInput);
window.speechSynthesis.speak(utterance);
};
const startListening = () => {
const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
if (!SpeechRecognition) {
alert("Speech recognition not supported in this browser.");
return;
}
const recognition = new SpeechRecognition();
recognition.onstart = () => setIsListening(true);
recognition.onend = () => setIsListening(false);
recognition.onresult = (event: any) => {
const transcript = event.results[0][0].transcript;
setTextInput(prev => prev + " " + transcript);
};
recognition.start();
};
const renderToolUI = () => {
switch (tool.id) {
case 'qr-gen':
return (
);
case 'pass-gen':
return (
{password || "••••••••••••••••"}
);
case 'bmi-calc':
return (
);
case 'age-calc':
return (
setAge(prev => ({ ...prev, birthDate: e.target.value }))}
/>
{age.result &&
Age: {age.result} Years
}
);
case 'json-fmt':
return (
);
case 'unit-conv':
return (
setUnit(prev => ({ ...prev, value: e.target.value }))}
/>
{unit.result &&
Result: {unit.result}
}
);
case 'img-compress':
case 'img-convert':
return (
fileInputRef.current?.click()}
className="border-2 border-dashed border-white/10 rounded-2xl p-12 flex flex-col items-center justify-center cursor-pointer hover:border-accent-cyan/50 hover:bg-accent-cyan/5 transition-all group"
>
Select Image
{files.length > 0 &&
{files[0].name}
}
);
case 'tts':
return (
);
case 'stt':
return (
{isListening ? 'Listening...' : 'Click to start transcribing'}
);
case 'timer':
const formatTime = (s: number) => {
const mins = Math.floor(s / 60);
const secs = s % 60;
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
};
return (
{formatTime(timer.time)}
);
case 'word-counter':
const words = textInput.trim() ? textInput.trim().split(/\s+/).length : 0;
const chars = textInput.length;
return (
);
case 'color-picker':
return (
);
default:
return (
fileInputRef.current?.click()}
className="border-2 border-dashed border-white/10 rounded-2xl p-12 flex flex-col items-center justify-center cursor-pointer hover:border-accent-cyan/50 hover:bg-accent-cyan/5 transition-all group"
>
Click or drag files here to upload
Supports PDF, JPG, PNG, DOCX, etc.
{files.length > 0 && (
Selected Files:
{files.map((f, i) => (
{f.name}
{(f.size / 1024 / 1024).toFixed(2)} MB
))}
)}
);
}
};
return (
{status === 'idle' && renderToolUI()}
{(status === 'uploading' || status === 'processing') && (
{status === 'uploading' ? `${progress}%` : '...'}
{status === 'uploading' ? 'Uploading Files...' : 'Processing Data...'}
Please do not close this window.
)}
{status === 'done' && (
Task Completed!
Your task has been processed successfully using our futuristic quantum algorithms.
{result && (
Download Result
)}
)}
{status === 'idle' && !['pass-gen', 'age-calc', 'bmi-calc', 'json-fmt', 'tts', 'timer', 'color-picker', 'word-counter'].includes(tool.id) && (
)}
);
};
const Footer = () => (
);
export default function App() {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const [activeCategory, setActiveCategory] = useState('all');
const [selectedTool, setSelectedTool] = useState(null);
const [searchQuery, setSearchQuery] = useState('');
const filteredTools = TOOLS.filter(tool => {
const matchesCategory = activeCategory === 'all' || tool.category === activeCategory;
const matchesSearch = tool.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
tool.description.toLowerCase().includes(searchQuery.toLowerCase());
return matchesCategory && matchesSearch;
});
return (
setIsSidebarOpen(!isSidebarOpen)} />
setIsSidebarOpen(false)}
activeCategory={activeCategory}
setActiveCategory={setActiveCategory}
/>
{/* Background Glows */}
{/* Hero Section */}
Every Tool You Need to
Master Your PDFs
Free and easy to use online PDF tools. Merge, split, compress, convert, rotate, unlock and watermark PDFs with just a few clicks.
{/* Tools Grid */}
{selectedTool && (
setSelectedTool(null)}
/>
)}
);
}