Mindfulness Journal Assistant

Mindfulness Journal Assistant

Gently guide your thoughts and find your center.

${groundingSight}

`; if (groundingSound) journalText += `

${groundingSound}

`; } if (emotionsFelt) { journalText += `

My Feelings

${emotionsFelt}

`; } if (gratitudeSimple || gratitudePerson) { journalText += `

Gratitude

`; if (gratitudeSimple) journalText += `

${gratitudeSimple}

`; if (gratitudePerson) journalText += `

${gratitudePerson}

`; } if (intention) { journalText += `

My Intention

${intention}

`; } journalOutputDiv.innerHTML = journalText || "

Your journal entry will appear here. Go back and fill in some sections!

"; currentTab = tabs.length - 1; showTab(currentTab); }; const downloadPDF = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ unit: 'pt', format: 'a4' }); const filename = `Mindfulness-Journal-${today.toISOString().split('T')[0]}.pdf`; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const margin = 70; const contentWidth = pageWidth - margin * 2; let cursorY = margin; // --- Helper Function --- const addSection = (title, content) => { if (!content || content.trim() === '') return; doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.setTextColor(30, 41, 59); // Slate 800 const titleLines = doc.splitTextToSize(title, contentWidth); const titleHeight = titleLines.length * 16 + 10; doc.setFont('times', 'normal'); doc.setFontSize(12); const contentLines = doc.splitTextToSize(content, contentWidth); const contentHeight = contentLines.length * 14 + 20; if (cursorY + titleHeight + contentHeight > pageHeight - margin) { doc.addPage(); cursorY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.text(titleLines, margin, cursorY); cursorY += titleHeight; doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(51, 65, 85); // Slate 700 doc.text(contentLines, margin, cursorY); cursorY += contentHeight; }; // --- PDF Template: Mindfulness Report --- // Header doc.setFont('helvetica', 'bold'); doc.setFontSize(24); doc.setTextColor(30, 41, 59); doc.text("Mindfulness Journal", pageWidth / 2, cursorY, { align: 'center' }); cursorY += 25; const formattedDate = today.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(100, 116, 139); // Slate 500 doc.text(formattedDate, pageWidth / 2, cursorY, { align: 'center' }); cursorY += 40; // Decorative Line doc.setDrawColor(203, 213, 225); // Slate 300 doc.setLineWidth(1); doc.line(margin, cursorY, pageWidth - margin, cursorY); cursorY += 30; // Content const groundingContent = [document.getElementById('groundingSight').value.trim(), document.getElementById('groundingSound').value.trim()].filter(Boolean).join('\n\n'); addSection("In This Moment: A Grounding Exercise", groundingContent); addSection("Acknowledging My Emotions", document.getElementById('emotionsFelt').value.trim()); const gratitudeContent = [document.getElementById('gratitudeSimple').value.trim(), document.getElementById('gratitudePerson').value.trim()].filter(Boolean).join('\n\n'); addSection("Reflecting on Gratitude", gratitudeContent); addSection("Setting My Intention", document.getElementById('intention').value.trim()); doc.save(filename); }; // --- Event Handling --- nextButton.addEventListener('click', () => { if (currentTab < tabs.length - 2) { currentTab++; showTab(currentTab); } }); prevButton.addEventListener('click', () => { if (currentTab > 0) { currentTab--; showTab(currentTab); } }); generateButton.addEventListener('click', generateJournal); downloadPdfButton.addEventListener('click', downloadPDF); tabs.forEach(tab => { tab.addEventListener('click', () => { const tabIndex = parseInt(tab.dataset.tab, 10); if (tabIndex === tabs.length - 1 && journalOutputDiv.innerHTML.trim() === '') { generateJournal(); } else { currentTab = tabIndex; showTab(currentTab); } }); }); // --- Initialization --- showTab(0); });
Scroll to Top