N/A
";
var html = '
';
items.forEach(function(item) {
html += '- ' + item.trim() + '
';
});
html += '
';
return html;
}
var generatePlan = function() {
var data = {
title: projectTitleInput.value || "[Sculpture Title]",
artist: artistNameInput.value || "[Artist Name]",
date: projectDateInput.value || "[Date Planned]",
concept: conceptNotesInput.value || "Conceptual notes have not been provided.",
materials: materialListInput.value,
tools: toolsProcessInput.value,
width: widthInput.value || "0",
height: heightInput.value || "0",
depth: depthInput.value || "0",
unit: unitSelect.value,
structural: structuralComplexityInput.value || "Structural requirements not specified."
};
var dateFormatted = data.date;
try {
if (data.date) {
var d = new Date(data.date);
dateFormatted = d.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}
} catch (e) { /* use raw date */ }
var planHtml = `
${data.title.toUpperCase()}
Artist: ${data.artist} | Date: ${dateFormatted}
1. Dimensions & Specifications
| Metric |
Width |
Height |
Depth |
Unit |
| Value |
${data.width} |
${data.height} |
${data.depth} |
${data.unit.toUpperCase()} |
2. Conceptual Vision
${data.concept}
3. Material List
${formatListHtml(data.materials)}
4. Process & Structural Notes
Key Processes:
${data.tools || 'Process notes not specified.'}
Structural Complexity:
${data.structural}
`;
planContentDiv.innerHTML = planHtml;
};
generateBtn.addEventListener("click", function() {
generatePlan();
showTab(1); // Switch to Dashboard
});
// --- Initial Date Setter ---
var today = new Date().toISOString().split('T')[0];
if (projectDateInput && !projectDateInput.value) {
projectDateInput.value = today;
}
// --- PDF Download ---
pdfBtn.addEventListener("click", function() {
var jsPDF = window.jspdf.jsPDF;
var titleSlug = projectTitleInput.value.replace(/[^a-zA-Z0-9\s]/g, '').replace(/\s/g, '_').substring(0, 30) || 'Sculpture_Plan';
var fileName = `${titleSlug}.pdf`;
html2canvas(exportArea, {
scale: 2,
useCORS: true,
backgroundColor: '#ffffff'
}).then(function(canvas) {
var imgData = canvas.toDataURL('image/png');
var doc = new jsPDF({
orientation: 'p',
unit: 'pt',
format: 'letter'
});
var pdfWidth = doc.internal.pageSize.getWidth();
var pdfHeight = doc.internal.pageSize.getHeight();
var imgProps = doc.getImageProperties(imgData);
var imgWidth = imgProps.width;
var imgHeight = imgProps.height;
var margin = 40;
var usableWidth = pdfWidth - (2 * margin);
var ratio = usableWidth / imgWidth;
var scaledHeight = imgHeight * ratio;
if (scaledHeight > pdfHeight - (2 * margin)) {
var pageHeight = pdfHeight - (2 * margin);
var heightLeft = scaledHeight;
var position = 0;
while (heightLeft > 0) {
doc.addImage(imgData, 'PNG', margin, position + margin, usableWidth, scaledHeight);
heightLeft -= pageHeight;
position -= pageHeight;
if (heightLeft > 0) {
doc.addPage();
}
}
} else {
// Single page
doc.addImage(imgData, 'PNG', margin, margin, usableWidth, scaledHeight);
}
doc.save(fileName);
}).catch(function(err) {
console.error("SPS PDF Error:", err);
// alert("An error occurred while generating the PDF."); // Per spec
});
});
// --- Initial Load ---
generatePlan();
showTab(0);
});