// ============================================================================= // Privacy Policy PDF Export - Helper Functions // Private helpers extracted from pdf.ts to stay under 500 LOC hard cap // ============================================================================= import type { PDFExportOptions, PDFSection } from './pdf' // ============================================================================= // HELPER FUNCTIONS // ============================================================================= export function generateHTMLFromContent( content: PDFSection[], options: PDFExportOptions ): string { const pageWidth = options.pageSize === 'A4' ? '210mm' : '8.5in' const pageHeight = options.pageSize === 'A4' ? '297mm' : '11in' let html = ` ${options.language === 'de' ? 'Datenschutzerklaerung' : 'Privacy Policy'} ` for (const section of content) { switch (section.type) { case 'title': html += `
${escapeHtml(section.content || '')}
\n` break case 'heading': html += `

${escapeHtml(section.content || '')}

\n` break case 'subheading': html += `

${escapeHtml(section.content || '')}

\n` break case 'paragraph': { const alignClass = section.style?.align === 'center' ? ' class="center"' : '' html += `${escapeHtml(section.content || '')}

\n` break } case 'list': html += '\n' break case 'table': if (section.table) { html += '\n\n' for (const header of section.table.headers) { html += ` \n` } html += '\n\n' for (const row of section.table.rows) { html += '\n' for (const cell of row) { html += ` \n` } html += '\n' } html += '
${escapeHtml(header)}
${escapeHtml(cell)}
\n' } break case 'pagebreak': html += '
\n' break } } html += '' return html } export function getStyleString(style?: PDFSection['style']): string { if (!style) return '' const parts: string[] = [] if (style.color) parts.push(`color: ${style.color}`) if (style.fontSize) parts.push(`font-size: ${style.fontSize}pt`) if (style.bold) parts.push('font-weight: bold') if (style.italic) parts.push('font-style: italic') if (style.align) parts.push(`text-align: ${style.align}`) return parts.join('; ') } export function escapeHtml(text: string): string { return text .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') }