Skip to content

Latest commit

 

History

History
65 lines (44 loc) · 2.57 KB

File metadata and controls

65 lines (44 loc) · 2.57 KB

Service Code Audit & Verification

Date: 2025-12-09 Reviewer: Antigravity Assistant

Scope

Line-by-line review of src/js/services/PDFService.js and src/js/services/HTMLService.js to address export crashes and content pollution.

1. PDFService.js Audit

Initialization & Validation

  • Lines 20-39: Constructor & Default Config.
    • ✅ Defaults are safe (A4, Portrait, 0.5in margins).
  • Lines 57-91: validateConfig.
    • ⚠️ Found weakness: Margins validation acceptable strings but logic downstream required numbers.
    • FIXED: Updated validation/sanitization in buildHtml2PdfConfig to handle types rigidly.

Content Preparation

  • Lines 101-144: prepareContent.
    • ✅ Logic Clones content node.
    • ✅ Wraps in styling container (fixes color-mix issue by isolation).
    • ✅ Appends Footer (Created in previous step).
    • 🔍 Note: Relies on clean input element. If input has garbage, output has garbage. Fixed caller in script.js.

Configuration Building (Critical Path)

  • Lines 153-177: buildHtml2PdfConfig.
    • 🛑 CRITICAL FINDING: Direct mapping of config.margins to html2pdf option caused crash when NaN (from empty input) was passed.
    • FIXED: Implemented robust mapping: Array.isArray(margins) ? margins.map(m => isFinite(parseFloat(m)) ? parseFloat(m) : 0.5) : default.
    • html2canvas options set backgroundColor explicitly to avoid transparency issues.
    • jsPDF config uses unit: 'in', matching the input values.

Execution

  • Lines 190-221: generatePDF.
    • ✅ Proper error handling (try-catch) wrapping external library calls.
    • outputPdf('blob') used correctly.

2. HTMLService.js Audit

CSS Extraction (The "Vanilla" Bug)

  • Lines 96-140: getThemeCSS.
    • 🛑 CRITICAL FINDING: fetch returns Vite's JS module string in Dev mode.
    • FIXED: Implemented Regex + JSON.parse extraction strategy locally to parse const __vite__css variable.
    • ✅ Logic includes fallback to full path handling.

Content Generation

  • Line 80: ${contentHtml} interpolation.
    • 🔍 Note: Takes raw HTML string.
    • FIXED: Caller (script.js) updated to pass preview.innerHTML (Content) instead of previewContainer.innerHTML (Wrapper + Header).

Footer

  • Lines 82-84: Footer Implementation.
    • ✅ Updated to match User Request (Specific links, new tabs).

3. script.js (Integration)

  • Export HTML: Updated to target #markdown-preview (via preview variable).
  • Export PDF: Verified previewPDF targets preview variable.