Wherever you are, bring your awareness to your body.
- Feet on Floor: Feel the precise sensation of your feet touching the ground. Notice the pressure, the texture, the temperature.
- Body on Seat: Feel the weight of your body on the chair or surface you're sitting on. Notice the points of contact.
- Hands at Rest: Notice where your hands are resting. Feel the sensation of your skin, or the texture of the fabric they are touching.
" },
3: { title: "3-Minute Head-to-Heart Scan", content: "
Sit comfortably with your back straight. Close your eyes.
- Top of the Head: Bring your awareness to the very top of your head. Notice any sensations here—tingling, warmth, coolness.
- Face: Gently scan your awareness across your forehead, eyes, nose, and mouth. Notice the subtle sensations in the muscles of your face without trying to change them.
- Neck and Shoulders: Move your awareness down to your neck and shoulders, a common area for tension. Just notice what's there.
- Chest and Heart: Finally, rest your awareness in the area of your chest and heart. Feel the gentle rise and fall with each breath.
" },
5: { title: "5-Minute Full Body Scan", content: "
Lie down on your back if possible, or sit comfortably. Close your eyes.
- Feet and Toes (1 min): Bring your full attention to the toes of your left foot. Notice any sensations—tingling, warmth, numbness—without judgment. Slowly scan up through your foot to your ankle. Repeat with the right foot.
- Legs (1 min): Move your awareness up both legs, from your calves to your knees and up to your thighs and hips. Notice the weight of your legs on the surface beneath you.
- Torso (1 min): Scan your attention up through your pelvis, abdomen, and chest. Feel the gentle movement of your breath. Then scan across your lower and upper back.
- Arms and Hands (1 min): Bring your awareness to your fingertips. Scan up through your hands, wrists, and all the way up your arms to your shoulders.
- Neck, Face, and Head (1min): Finally, scan your neck, your jaw, your face, and all the way to the top of your head. Then, for a few moments, be aware of your whole body breathing before you finish.
" }
}
};
// --- DOM Elements ---
const focusAreaSelect = document.getElementById('focusArea');
const durationSelect = document.getElementById('duration');
const generateBtn = document.getElementById('generateBtn');
const resultsContainer = document.getElementById('resultsContainer');
const exerciseTitle = document.getElementById('exerciseTitle');
const exerciseContent = document.getElementById('exerciseContent');
const downloadPdfBtn = document.getElementById('downloadPdfBtn');
let lastExercise = null;
// --- Initialization ---
const init = () => {
generateBtn.addEventListener('click', generateExercise);
downloadPdfBtn.addEventListener('click', generatePDF);
};
// --- Core Logic ---
const generateExercise = () => {
const focus = focusAreaSelect.value;
const duration = durationSelect.value;
const exercise = exercises[focus]?.[duration];
if (exercise) {
lastExercise = exercise;
exerciseTitle.textContent = exercise.title;
exerciseContent.innerHTML = exercise.content;
resultsContainer.classList.remove('hidden');
resultsContainer.scrollIntoView({ behavior: 'smooth' });
} else {
alert("Sorry, an exercise for that combination could not be found.");
}
};
// --- PDF Generation ---
const generatePDF = () => {
if (!lastExercise) return;
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
const margin = 20;
const pdfWidth = pdf.internal.pageSize.getWidth();
let currentY = margin;
pdf.setFont('helvetica', 'bold').setFontSize(22).text('Your Mindfulness Exercise', pdfWidth / 2, currentY, { align: 'center' });
currentY += 15;
pdf.setFontSize(16).setFont('helvetica', 'bold').text(lastExercise.title, pdfWidth / 2, currentY, { align: 'center' });
currentY += 10;
pdf.setDrawColor(220, 220, 220).line(margin, currentY, pdfWidth - margin, currentY);
currentY += 15;
// Convert HTML content to text for PDF
const tempDiv = document.createElement('div');
tempDiv.innerHTML = lastExercise.content;
pdf.setFontSize(11).setFont('helvetica', 'normal');
Array.from(tempDiv.childNodes).forEach(node => {
if (currentY > 260) {
pdf.addPage();
currentY = margin;
}
let textToPrint = '';
let isListItem = false;
if (node.nodeName === 'P') {
textToPrint = node.innerText;
} else if (node.nodeName === 'OL') {
Array.from(node.children).forEach((li, index) => {
const itemText = li.innerText;
const lines = pdf.splitTextToSize(itemText, pdfWidth - (margin * 2) - 10);
pdf.setFont('helvetica', 'normal').text(lines, margin + 5, currentY);
currentY += lines.length * 5 + 2;
});
return; // Skip the generic text print below
}
const lines = pdf.splitTextToSize(textToPrint, pdfWidth - (margin * 2));
pdf.text(lines, margin, currentY);
currentY += lines.length * 5 + 5;
});
const pageHeight = pdf.internal.pageSize.getHeight();
pdf.setFontSize(9).setFont('helvetica', 'italic').text('Generated by the Mindfulness Exercise Generator.', pdfWidth / 2, pageHeight - 15, { align: 'center' });
pdf.save('My-Mindfulness-Exercise.pdf');
};
init();
});