Repository navigation
Description
Refs: #438
Depends on: #440, #441
Can parallel with: G, H
Related: #284 (future consumer of MessageBlock/banner)
Context
This is the epic's pivotal milestone: a renderer-independent semantic receipt document. Today every renderer re-derives layout from raw bill/order rows and re-implements formatting; the merchant-template vision (#447/#448) and multi-renderer consistency are impossible until an authoritative semantic representation exists.
Per epic principle, the first consumer must be a FloCafe-owned core path — the classic receipt rendered through the preview pipeline — never a plugin/compliance renderer.
Architectural Decisions Relevant to This Issue
PrintData= normalized authoritative values passed in by callers (bill, order, business/tenant snapshot, resolved language policy from kernel C). Renderers/builders perform no DB IO and no financial recomputation — tax/totals arrive as printed truth.PrintContext= paper columns, resolved languages + directions, capability hints, locale-formatting prefs (currency/digits/calendar via existing regionalization helpers).PrintDocumentv1 = ordered semantic blocks. Smallest useful set (names may adjust to code evidence, but semantics fixed): BusinessHeader, DocumentMeta (invoice number/date/table/reprint flag), CustomerBlock, ItemTableBlock (rows with addons + special instructions), TaxBreakdownBlock, TotalsBlock (with optional BilingualLabels), PaymentsBlock, MessageBlock (banner/footer/thank-you — designed so Feature: Add Online order type, external order ID mapping, & online receipt header banner #284's online-order banner becomes one block), LtrIsland-wrapped values where direction kernel says so.- Labels inside blocks are carried as concept references + resolved strings (from B's catalog) or explicit BilingualLabel pairs — never pre-concatenated
"A / B"strings. - No transport APIs, no byte tokens (
{CENTER}etc.) in the model.
Scope / What to do
- Define types + pure builders in
shared/print/document.ts(or split files):buildBillDocument(printData, printContext)producing PrintDocument v1. - Wire ONE consumer end-to-end: backend preview path — extend
prepareReceiptpreview branch so the returned text is produced bydocument → ESC-POS-token lines → escPosToTextusing the existing classic layout logic refactored into a document-driven function. Legacy classic path remains untouched for actual printing this issue. - Prove parity using test(printing): establish cross-renderer receipt parity and regression contract #439's harness: same fixtures → legacy classic output vs document-driven output → semantic assertions identical (items incl. Persian names per current legacy rules, totals, payments, banner, widths 32/42/48).
- Unit tests: block construction from fixture bill; bilingual label resolution into TotalsBlock; direction annotations present for fa primary.
Compatibility / Migration
Purely additive module + preview-path change. Preview output may gain richer fidelity but must remain semantically equal for EN baseline. No settings/API changes.
What NOT to do
- Do NOT migrate compact/KOT/browser/WebUSB renderers here (E/F own those).
- Do NOT touch plugin renderer
renderEscposLineTemplateV1(G/I territory). - Do NOT define merchant template schema (I).
- Do NOT add raster/QR/barcode blocks speculatively beyond type headroom noted in docs.
- Do NOT let builders query the DB or call transport code.
Acceptance Criteria
- PrintData/PrintContext/PrintDocument types + pure builders exist in shared kernel layer.
- Classic-receipt-via-preview consumes: authoritative data → PrintData/PrintContext → PrintDocument → single renderer → text output.
- Semantic parity vs legacy classic proven on the full #A fixture matrix at 32/42/48 columns (including Persian item names under current legacy skip rules).
- Blocks carry direction metadata and bilingual labels semantically (no concatenation).
- No IO imports in document/builder modules (enforced by review checklist in PR).
Verification
npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.ts # extended with document-vs-legacy mode
npx ts-node --transpile-only -P tests/tsconfig.json tests/<document-unit-tests>.test.ts
npm run build && npm run lintDocumentation
Inline TSDoc on block types; schema summary added later by docs issue #449 (link it).
Activity
refactor(printing): introduce renderer-independent PrintDocument v1 (#…
refactor(printing): migrate backend thermal receipts, KOT, and previe…
refactor(printing): migrate backend thermal receipts, KOT, and previe…
feat(print): migrate browser and WebUSB printing to semantic PrintDoc…