Investor Agreement Generator
Create a simple SAFE (Simple Agreement for Future Equity).
Name: _______________________
Title: ________________________
INVESTOR: ${data.investorName}
By: _________________________
`; }; // === Tab Navigation Logic === const validateTab = (tabIndex) => { const inputs = tabContents[tabIndex].querySelectorAll('input[required], select[required]'); for (const input of inputs) { if (!input.value.trim()) { input.classList.add('border-red-500'); return false; } input.classList.remove('border-red-500'); } return true; }; const updateTabs = () => { tabContents.forEach((content, index) => { content.classList.toggle('hidden', index !== currentTab); tabButtons[index].classList.toggle('active', index === currentTab); }); prevBtn.disabled = currentTab === 0; nextBtn.textContent = currentTab === tabButtons.length - 1 ? 'Finish' : 'Next'; nextBtn.disabled = currentTab === tabButtons.length - 1; if (currentTab === tabButtons.length - 1) { // Generate Tab document.getElementById('previewContent').innerHTML = generateAgreementText(); } }; prevBtn.addEventListener('click', () => { if (currentTab > 0) { currentTab--; updateTabs(); } }); nextBtn.addEventListener('click', () => { if (currentTab < tabButtons.length - 1) { if (!validateTab(currentTab)) return; currentTab++; updateTabs(); } }); // === PDF Download Logic (Text-based) === downloadPdfBtn.addEventListener('click', () => { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const agreementHTML = generateAgreementText(); // Create a temporary element to parse the HTML for text extraction const tempDiv = document.createElement('div'); tempDiv.innerHTML = agreementHTML; const margin = 60; const pdfWidth = pdf.internal.pageSize.getWidth(); const textWidth = pdfWidth - margin * 2; let y = margin; // Function to add text and handle page breaks const addText = (text, options, fontSize = 11) => { pdf.setFontSize(fontSize); const isBold = options.includes('bold'); const isCenter = options.includes('center'); pdf.setFont('times', isBold ? 'bold' : 'normal'); const lines = pdf.splitTextToSize(text, textWidth); lines.forEach(line => { if (y > pdf.internal.pageSize.getHeight() - margin) { pdf.addPage(); y = margin; } pdf.text(line, isCenter ? pdfWidth / 2 : margin, y, { align: isCenter ? 'center' : 'left' }); y += fontSize * 1.2; }); }; // Process each element Array.from(tempDiv.children).forEach(el => { let text = el.textContent || ''; let options = []; let fontSize = 11; if (el.tagName === 'H3') { options.push('bold', 'center'); fontSize = 14; y += 10; } if (el.tagName === 'STRONG') { options.push('bold'); } if (el.style.fontWeight === 'bold') { options.push('bold'); } if (el.style.textAlign === 'center') { options.push('center'); } addText(text, options, fontSize); y += 8; // Spacing between paragraphs }); pdf.save('Investor_Agreement_SAFE.pdf'); }); // === Initial setup calls === populateSelect('companyState', usStates); populateSelect('governingLaw', usStates); document.getElementById('companyState').value = 'Delaware'; // Common default document.getElementById('governingLaw').value = 'Delaware'; // Common default document.getElementById('agreementDate').valueAsDate = new Date(); // Today's date updateTabs(); });