// Shared functions
function openImageEditor(imageSrc) {
const editor = document.querySelector('custom-image-editor');
if (editor) {
editor.style.display = 'flex';
// In a real app, this would load the image into the canvas
}
}
function generateFaceSwap() {
const resultsContainer = document.getElementById('results-container');
const selectedImages = document.querySelectorAll('#image-preview img');
const faceSelection = document.querySelectorAll('#face-selection .ring-purple-600');
if (selectedImages.length < 2) {
alert('Please upload at least 2 images for face swapping');
return;
}
if (faceSelection.length < 2) {
alert('Please select at least 2 faces to swap');
return;
}
// Show loading state
resultsContainer.innerHTML = `
Your face swaps will appear here
`;
if (typeof feather !== 'undefined') {
feather.replace();
}
}
});
}
// Image upload functionality
const uploadArea = document.getElementById('upload-area');
const fileInput = document.getElementById('file-input');
const imagePreview = document.getElementById('image-preview');
// Handle file selection
fileInput.addEventListener('change', function(e) {
handleFiles(e.target.files);
});
// Handle drag and drop
uploadArea.addEventListener('dragover', function(e) {
e.preventDefault();
uploadArea.classList.add('border-purple-500', 'bg-purple-50');
});
uploadArea.addEventListener('dragleave', function() {
uploadArea.classList.remove('border-purple-500', 'bg-purple-50');
});
uploadArea.addEventListener('drop', function(e) {
e.preventDefault();
uploadArea.classList.remove('border-purple-500', 'bg-purple-50');
if (e.dataTransfer.files.length) {
handleFiles(e.dataTransfer.files);
}
});
function handleFiles(files) {
// Process each file
Array.from(files).forEach(file => {
if (!file.type.match('image.*')) return;
const reader = new FileReader();
reader.onload = function(e) {
// Create container for the image and remove button
const container = document.createElement('div');
container.className = 'relative group';
// Create image element
const img = document.createElement('img');
img.src = e.target.result;
img.alt = file.name;
img.className = 'w-full h-full object-cover rounded-lg';
// Create remove button
const removeBtn = document.createElement('button');
removeBtn.className = 'absolute top-2 right-2 bg-red-500 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity';
removeBtn.innerHTML = '