// 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 timelineStyles = ` @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; } .grid { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; } .sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: #111827; margin: 0; } .divider { border-top: 1px solid #e5e7eb; margin: 4px 0 8px; } .contact-list { font-size: 12px; color: #111827; } .timeline { position: relative; } .tl-row { display: grid; grid-template-columns: 24px 1fr; gap: 12px; margin-bottom: 16px; } .tl-dot { width: 10px; height: 10px; background: #2563eb; border-radius: 50%; margin-top: 3px; } .tl-line { position: absolute; left: 4px; top: 0; bottom: 0; width: 2px; background: #e5e7eb; } .small { font-size: 12px; color: #6b7280; } `; const stylesVariant = tid === 'classic' ? classicStyles : tid === 'modern' ? modernStyles : tid === 'minimal' ? minimalStyles : tid === 'timeline' ? timelineStyles : ''; 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 headline = Array.isArray(personal.extras) && personal.extras.length ? personal.extras[0] : ''; const headerHtml = tid === 'timeline' ? `

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

${headline ? `
${escapeText(headline)}
` : ''}
` : `
${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) ? ( tid === 'timeline' ? `

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) ? `
    ${job.bullets.map(b => `
  • ${escapeText(b)}
  • `).join('')}
` : ''}
`).join('')}
` : `

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' ? '
' : ''; // Sidebar for timeline theme: contact + skills/languages + references const referenceLines = (Array.isArray(personal.extras) ? personal.extras.slice(1) : []).filter(Boolean); const sidebar = tid === 'timeline' ? ` ` : ''; const bodyContent = tid === 'timeline' ? ` ${accentTop} ${headerHtml}
${sidebar}
${summarySection} ${workSection} ${eduSection} ${certsSection}
` : ` ${accentTop} ${headerHtml} ${summarySection} ${workSection} ${eduSection} ${skillsSection} ${languagesSection} ${certsSection} `; return ` Printable CV ${styles}
${bodyContent}
`; }