document.addEventListener('DOMContentLoaded', function() { // DOM Elements const dropZone = document.getElementById('dropZone'); const fileInput = document.getElementById('fileInput'); const convertBtn = document.getElementById('convertBtn'); const previewContainer = document.getElementById('previewContainer'); const emptyPreview = document.getElementById('emptyPreview'); const downloadButtons = document.getElementById('downloadButtons'); const modeBtns = document.querySelectorAll('.mode-btn'); const downloadBtns = document.querySelectorAll('.download-btn'); // Settings elements const colorCount = document.getElementById('colorCount'); const colorCountValue = document.getElementById('colorCountValue'); const curveTolerance = document.getElementById('curveTolerance'); const curveToleranceValue = document.getElementById('curveToleranceValue'); const pathSimplify = document.getElementById('pathSimplify'); const pathSimplifyValue = document.getElementById('pathSimplifyValue'); const removeBackground = document.getElementById('removeBackground'); // State let currentFile = null; let currentMode = 'logo'; let convertedSVG = null; // Event Listeners dropZone.addEventListener('click', () => fileInput.click()); dropZone.addEventListener('dragover', (e) => { e.preventDefault(); dropZone.classList.add('drop-zone-active'); }); dropZone.addEventListener('dragleave', () => { dropZone.classList.remove('drop-zone-active'); }); dropZone.addEventListener('drop', (e) => { e.preventDefault(); dropZone.classList.remove('drop-zone-active'); if (e.dataTransfer.files.length) { handleFileUpload(e.dataTransfer.files[0]); } }); fileInput.addEventListener('change', () => { if (fileInput.files.length) { handleFileUpload(fileInput.files[0]); } }); modeBtns.forEach(btn => { btn.addEventListener('click', () => { currentMode = btn.dataset.mode; modeBtns.forEach(b => b.classList.remove('border-blue-500', 'bg-blue-100')); btn.classList.add('border-blue-500', 'bg-blue-100'); }); }); // Settings sliders colorCount.addEventListener('input', () => { colorCountValue.textContent = colorCount.value; }); curveTolerance.addEventListener('input', () => { curveToleranceValue.textContent = curveTolerance.value; }); pathSimplify.addEventListener('input', () => { pathSimplifyValue.textContent = pathSimplify.value; }); convertBtn.addEventListener('click', convertToVector); downloadBtns.forEach(btn => { btn.addEventListener('click', () => { if (!convertedSVG) return; const format = btn.dataset.format; if (format === 'copy') { navigator.clipboard.writeText(convertedSVG) .then(() => showToast('SVG copied to clipboard!', 'success')) .catch(() => showToast('Failed to copy SVG', 'error')); } else { downloadVector(format); } }); }); // Functions function handleFileUpload(file) { // Validate file const validTypes = ['image/jpeg', 'image/jpg', 'image/png']; if (!validTypes.includes(file.type)) { showToast('Please upload a JPG or PNG image', 'error'); return; } if (file.size > 25 * 1024 * 1024) { // 25MB showToast('File is too large (max 25MB)', 'error'); return; } currentFile = file; // Create preview const reader = new FileReader(); reader.onload = (e) => { emptyPreview.style.display = 'none'; previewContainer.innerHTML = `