Skip to content

refactor(printing): introduce renderer-independent PrintDocument v1 #442

Closed

Description

@khaira777

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).
  • PrintDocument v1 = 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

  1. Define types + pure builders in shared/print/document.ts (or split files): buildBillDocument(printData, printContext) producing PrintDocument v1.
  2. Wire ONE consumer end-to-end: backend preview path — extend prepareReceipt preview branch so the returned text is produced by document → ESC-POS-token lines → escPosToText using the existing classic layout logic refactored into a document-driven function. Legacy classic path remains untouched for actual printing this issue.
  3. 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).
  4. 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 lint

Documentation

Inline TSDoc on block types; schema summary added later by docs issue #449 (link it).

Activity

  1. added
    area:backend
    on Aug 21, 2026
  2. added 4 commits that reference this issue on Aug 22, 2026
    5d95d30
    42ffa82
    40b5925
    5ea929a
  3. self-assigned this
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:backend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions