Personalized Cartoon Theme Song Generator
Briefly describe what the cartoon is about.
A catchy phrase to include, if any.
[Song Title]
${profile.lyrics.outro}
`; outputArea.style.display = 'block'; // Show output pdfBtn.disabled = false; // Enable PDF button console.log("Theme song displayed."); } // --- PDF Generation Function --- function generatePdf() { console.log("Generating PDF for Theme Song Lyrics"); if (!currentSongProfile || Object.keys(currentSongProfile).length === 0) { alert("Please generate a theme song first!"); return; } try { const { jsPDF } = window.jspdf; if (!jsPDF) { console.error("jsPDF not loaded!"); alert("Error: PDF library not found."); return; } const doc = new jsPDF(); // Colors const pdfTitleColor = '#4682B4'; // Blue const pdfHeadingColor = '#FF6347'; // Red const pdfTextColor = '#333333'; // Dark Grey const pdfSubtleColor = '#777777'; // Medium Grey // Setup const pageHeight = doc.internal.pageSize.height || doc.internal.pageSize.getHeight(); const pageWidth = doc.internal.pageSize.width || doc.internal.pageSize.getWidth(); const margin = 15; let currentY = margin; const lineHeight = 6; // Smaller line height for lyrics const titleSize = 16; const headingSize = 12; const textSize = 10; const subTextSize = 9; const contentWidth = pageWidth - (margin * 2); // Helper function addTextBlock(text, size, style, color, yPos, spaceAfter) { doc.setFontSize(size); doc.setTextColor(color); doc.setFont('helvetica', style); const lines = doc.splitTextToSize(text || "", contentWidth); const requiredHeight = lines.length * lineHeight * (size/10); if (yPos + requiredHeight > pageHeight - margin) { doc.addPage(); currentY = margin; yPos = margin; } doc.text(lines, margin, yPos); return yPos + requiredHeight + spaceAfter; } function addLyricSection(title, text, yPos) { if (!text) return yPos; // Skip empty sections const headingHeight = lineHeight * 1.5; const lines = doc.splitTextToSize(text, contentWidth); const requiredHeight = lines.length * lineHeight + headingHeight; if (yPos + requiredHeight > pageHeight - margin) { doc.addPage(); currentY = margin; yPos = margin; } doc.setFontSize(headingSize); doc.setTextColor(pdfHeadingColor); doc.setFont('helvetica', 'bold'); doc.text(title + ":", margin, yPos); yPos += headingHeight; doc.setFontSize(textSize); doc.setTextColor(pdfTextColor); doc.setFont('helvetica', 'italic'); doc.text(lines, margin + 5, yPos); // Indent lyrics yPos += (lines.length * lineHeight) + lineHeight; // Space after section return yPos; } // Add Title currentY = addTextBlock("Cartoon Theme Song Lyrics", titleSize, 'bold', pdfTitleColor, currentY, lineHeight * 0.5); currentY = addTextBlock(`"${currentSongProfile.title}"`, 14, 'italic', pdfHeadingColor, currentY, lineHeight * 1.5); // Add Context const contextText = `Parameters Used: Genre - ${currentSongProfile.inputs.genre}, Characters - ${currentSongProfile.inputs.chars}, Premise Hint - "${currentSongProfile.inputs.premise}"` + (currentSongProfile.inputs.catchphrase ? `, Catchphrase - "${currentSongProfile.inputs.catchphrase}"` : ''); currentY = addTextBlock(contextText, subTextSize, 'italic', pdfSubtleColor, currentY); currentY += lineHeight * 2; // Add Lyrics Sections currentY = addLyricSection("Verse 1", currentSongProfile.lyrics.verse1, currentY); currentY = addLyricSection("Chorus", currentSongProfile.lyrics.chorus, currentY); currentY = addLyricSection("Verse 2", currentSongProfile.lyrics.verse2, currentY); currentY = addLyricSection("Outro", currentSongProfile.lyrics.outro, currentY); doc.save('cartoon-theme-song.pdf'); console.log("Cartoon Theme Song PDF Generated."); } catch(error) { console.error("Error generating PDF:", error); alert("An error occurred while generating the PDF."); } } // --- Attach Event Listeners --- generateBtn.addEventListener('click', generateThemeSong); pdfBtn.addEventListener('click', generatePdf); console.log("Theme Song Gen Event listeners attached."); // --- Initial Setup --- populateDropdowns(); pdfBtn.disabled = true; console.log("Cartoon Theme Song Generator Initialized."); }); // End DOMContentLoaded listener })(); // End of IIFE