task(G5): browser print stylesheet - @media print A4 landscape, screen-only chrome hidden, print-area fill, print service with cleanup

This commit is contained in:
Agent Zero
2026-08-29 02:52:12 +02:00
parent a093630d34
commit d9a0dffb05
4 changed files with 162 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
/**
* Task G5 Browser-Print-Service.
*
* Bereitet die App für window.print() vor: Der Body erhält die Klasse
* `print-layout`, das @media print Stylesheet blendet das UI-Chrome aus
* und zeigt nur den Druckbereich (Canvas/Layout). Nach dem Druck wird
* die Klasse wieder entfernt (kein DOM-Mutation-Restzustand).
*/
const PRINT_CLASS = 'print-layout';
/** Setzt den Print-Modus (Body-Klasse; @media print regelt das Rendering). */
export function preparePrintLayout(): void {
document.body.classList.add(PRINT_CLASS);
}
/** Entfernt den Print-Modus (nach Druck oder bei Abbruch). */
export function cleanupPrintLayout(): void {
document.body.classList.remove(PRINT_CLASS);
}
/**
* Druck-Flow: Vorbereitung → Rendern der nächsten Frames (Styles müssen
* greifen, bevor der Browser den Print-Dialog aufbaut) → window.print
* → Aufräumen. await-fähig für Tests (window.print wird gemockt).
*/
export async function printLayout(): Promise<void> {
preparePrintLayout();
// Zwei Frames warten: Style-Anwendung + Layout der Print-Ansicht
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
try {
window.print();
} finally {
cleanupPrintLayout();
}
}