// ESM module: shared printable HTML builder // Note: callers must sanitize any HTML fields (e.g., summary) before passing. function escapeText(str) { if (str == null) return ''; return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/\"/g, '"') .replace(/'/g, '''); } export function buildPrintableHtml(cv, templateId) { const { personal = {}, summary = '', work = [], education = [], skills = [], languages = [], certifications = [], templateId: cvTemplateId } = cv || {}; const tid = templateId || cvTemplateId || 'ats'; const baseStyles = ` @page { size: A4; margin: 20mm; } body { font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans; color: #1f2937; } .page { width: 210mm; min-height: 297mm; margin: 0 auto; background: white; } h1 { font-size: 24px; margin: 0 0 6px 0; } h2 { font-size: 16px; margin: 16px 0 8px 0; padding-bottom: 4px; border-bottom: 1px solid #e5e7eb; color: #374151; } h3 { font-size: 14px; margin: 0; } .header { border-bottom: 1px solid #e5e7eb; padding-bottom: 12px; margin-bottom: 16px; } .meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: #6b7280; } .section { margin-bottom: 16px; } .job, .edu { margin-bottom: 12px; } .row { display: flex; justify-content: space-between; align-items: flex-start; } .small { font-size: 12px; color: #6b7280; } ul { padding-left: 20px; } li { margin: 4px 0; } .chips { display: flex; flex-wrap: wrap; gap: 6px; } .chip { background: #f3f4f6; color: #1f2937; padding: 2px 8px; border-radius: 12px; font-size: 12px; } `; const classicStyles = ` @page { size: A4; margin: 22mm; } body { font-family: Georgia, Cambria, 'Times New Roman', Times, serif; color: #111827; } h1 { font-size: 26px; } h2 { font-size: 16px; margin: 18px 0 6px 0; padding-bottom: 0; border-bottom: none; color: #374151; letter-spacing: 0.2px; } .header { border-bottom: none; padding-bottom: 0; margin-bottom: 10px; } .chip { background: #f9fafb; color: #111827; } `; const modernStyles = ` @page { size: A4; margin: 18mm; } body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans; color: #0f172a; } .accent { height: 6px; background: #0ea5e9; margin-bottom: 12px; } h1 { font-weight: 700; letter-spacing: 0.3px; } h2 { color: #0ea5e9; border-color: #bae6fd; } .header { border-left: 6px solid #0ea5e9; padding-left: 12px; } .chip { background: #e0f2fe; color: #0c4a6e; } `; const minimalStyles = ` @page { size: A4; margin: 25mm; } body { font-family: 'Source Serif Pro', Georgia, Cambria, 'Times New Roman', Times, serif; color: #1f2937; } h1 { font-size: 24px; font-weight: 600; } h2 { font-size: 15px; margin: 22px 0 6px 0; border-bottom: none; color: #374151; } .header { border-bottom: none; margin-bottom: 8px; } .section { margin-bottom: 22px; } .chip { background: #f3f4f6; color: #374151; } `; const stylesVariant = tid === 'classic' ? classicStyles : tid === 'modern' ? modernStyles : tid === 'minimal' ? minimalStyles : ''; const styles = ` `; const headerLinks = (personal.links || []) .map(l => `${escapeText(l.label || l.url)}`) .join(' · '); const safePhotoUrl = typeof personal.photoUrl === 'string' && /^(https?:\/\/)/i.test(personal.photoUrl) ? personal.photoUrl : ''; const headerPhoto = tid === 'modern' && safePhotoUrl ? `${escapeText((personal.firstName || '') + ' ' + (personal.lastName || ''))} photo` : ''; const headerHtml = `
${headerPhoto}

${escapeText(personal.firstName || '')} ${escapeText(personal.lastName || '')}

${personal.email ? `${escapeText(personal.email)}` : ''} ${personal.phone ? `${escapeText(personal.phone)}` : ''} ${(personal.city || personal.country) ? `${personal.city ? escapeText(personal.city) : ''}${personal.city && personal.country ? ', ' : ''}${personal.country ? escapeText(personal.country) : ''}` : ''} ${headerLinks ? `${headerLinks}` : ''}
`; const summarySection = summary ? `

Professional Summary

${summary}
` : ''; const workSection = (work && work.length) ? `

Work Experience

${work.map(job => `

${escapeText(job.title)}

${escapeText(job.company)}
${escapeText(job.startDate || '')} - ${escapeText(job.endDate || 'Present')} ${job.location ? `
${escapeText(job.location)}
` : ''}
${(job.bullets && job.bullets.length) ? ` ` : ''}
`).join('')}
` : ''; const eduSection = (education && education.length) ? `

Education

${education.map(ed => `

${escapeText(ed.degree)}

${escapeText(ed.school)}
${escapeText(ed.startDate || '')} - ${escapeText(ed.endDate || '')}
${ed.gpa ? `
GPA: ${escapeText(ed.gpa)}
` : ''}
`).join('')}
` : ''; const skillsSection = (skills && skills.length) ? `

Skills

${skills.map(s => `${escapeText(s.name)}${s.level ? ` — ${escapeText(s.level)}` : ''}`).join('')}
` : ''; const languagesSection = (languages && languages.length) ? `

Languages

${languages.map(l => `${escapeText(l.name)}${l.level ? ` — ${escapeText(l.level)}` : ''}`).join('')}
` : ''; const certsSection = (certifications && certifications.length) ? `

Certifications

` : ''; const accentTop = tid === 'modern' ? '
' : ''; return ` Printable CV ${styles}
${accentTop} ${headerHtml} ${summarySection} ${workSection} ${eduSection} ${skillsSection} ${languagesSection} ${certsSection}
`; }