Live Preview
Auto-updates
`); printWindow.document.close(); printWindow.focus(); setTimeout(() => printWindow.print(), 250); } function copyToClipboard() { const content = document.getElementById('documentPreview'); const range = document.createRange(); range.selectNodeContents(content); const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); selection.removeAllRanges(); showToast('NDA copied to clipboard!'); } async function downloadDocx() { try { const { Document, Packer, Paragraph, TextRun, AlignmentType } = docx; const content = document.getElementById('documentPreview'); const plainText = content.textContent || content.innerText; const paragraphs = plainText.split('\n').filter(p => p.trim()).map(p => { const isHeading = /^\d+\./.test(p) || p === p.toUpperCase(); return new Paragraph({ children: [new TextRun({ text: p.trim(), bold: isHeading })], spacing: { after: 200 }, alignment: p.includes('NON-DISCLOSURE AGREEMENT') || p.includes('CONFIDENTIALITY AGREEMENT') ? AlignmentType.CENTER : AlignmentType.JUSTIFIED }); }); const doc = new Document({ sections: [{ properties: {}, children: paragraphs }] }); const blob = await Packer.toBlob(doc); const scenarios = { business: 'Business', employee: 'Employee', contractor: 'Contractor', investor: 'Investor', merger: 'M&A', tech: 'Tech' }; const fileName = `${scenarios[scenario] || 'NDA'}-${isMutual ? 'Mutual' : 'Unilateral'}-NDA-${new Date().toISOString().split('T')[0]}.docx`; saveAs(blob, fileName); showToast('NDA downloaded successfully!'); } catch (error) { console.error('DOCX generation error:', error); showToast('Error generating DOCX. Please try copying instead.'); } } // ============================================ // INITIALIZATION // ============================================ document.addEventListener('DOMContentLoaded', () => { // Set default date document.getElementById('effectiveDate').value = new Date().toISOString().split('T')[0]; // Check URL params const params = new URLSearchParams(window.location.search); const urlScenario = params.get('scenario') || params.get('type'); const urlMutual = params.get('mutual'); if (urlScenario && ['business', 'employee', 'contractor', 'investor', 'merger', 'tech'].includes(urlScenario)) { selectScenario(urlScenario); } if (urlMutual === 'false') { setDirection('oneway'); } // Initial render updatePreview(); });