đĸ Please Rnter your name to generate a Christmas greeting ...
+âšī¸ Generating your Christmas greeting
+${step}
`; + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + }; + + const showProgress = async () => { + progressContainer.classList.remove('is-hidden'); + for (let i = 0; i <= 100; i++) { + await new Promise((resolve) => setTimeout(resolve, 30)); + progressBar.value = i; + } + progressContainer.classList.add('is-hidden'); + }; + + nameForm.addEventListener('submit', async (e) => { + e.preventDefault(); + + const name = sanitizeInput(nameInput.value); + + try { + output.innerHTML = ''; + greetingImage.classList.add('is-hidden'); + + validateInput(name); + + await terminalProcess([ + 'âšī¸ Validating input ...', + 'â Input validation successful', + 'đĨ¤ Loading resources ...', + 'âšī¸ Preparing your greeting ...', + ]); + + nameInput.value = ''; + + await showProgress(); + + const imageSrc = await generateGreetingImage(name); + + generatedImage.src = imageSrc; + downloadImage.href = imageSrc; + const timestamp = new Date().getTime(); + downloadImage.download = `christmas-greeting-${timestamp}.png`; + greetingImage.classList.remove('is-hidden'); + + output.innerHTML += `đ Greeting generated successfully
`; + } catch (err) { + output.innerHTML += `đ´ ${err.message}
`; + } + }); + }); + \ No newline at end of file