// Bakes live input values into their sibling .pv span before printing (so text doesn't clip // at a fixed .f width the way a raw would), then clears them after. One DOM, one // rendering — see app.css's @media print block for the corresponding display swap. export function initPrint({ form }) { document.getElementById("btn-print").addEventListener("click", () => window.print()); window.addEventListener("beforeprint", () => bakeValues(form)); window.addEventListener("afterprint", () => clearBaked(form)); } function bakeValues(form) { for (const el of form.querySelectorAll("input.ws-input, textarea.ws-input")) { if (el.type === "radio" || el.type === "checkbox") continue; const pv = el.nextElementSibling; if (pv && pv.classList.contains("pv")) pv.textContent = el.value || ""; } } function clearBaked(form) { for (const pv of form.querySelectorAll(".pv")) pv.textContent = ""; }