Skip to content

refactor(printing): migrate browser and WebUSB printing to semantic print model #444

Closed

Description

@khaira777

Refs: #438
Depends on: #442
Can parallel with: E
Related: #185, #184 (browser-print history), #206

Context

Frontend print surfaces — browser receipt HTML, WebUSB ESC-POS receipts, and the KOT browser fallback — currently duplicate all layout/label logic independently. The KOT fallback is semantically broken today: it decodes raw ESC-POS bytes with TextDecoder and prints the resulting control-character-laden text inside a <pre> HTML page. With PrintDocument available, frontend renderers should consume the same semantic truth as the backend.

Architectural Decisions Relevant to This Issue

  • One PrintDocument, three presentations: HTML (browser receipt + proper semantic KOT HTML) and ESC-POS bytes (WebUSB).
  • Browser output keeps its existing bidi/LTR-island quality (dir, ltrSpan) driven now by kernel DirectionSpec rather than ad-hoc language checks.
  • WebUSB renderer keeps safePrinterText capability behavior (skip+warn for unencodable scripts) — content preserved in document; warnings surfaced via existing toast path.
  • The detailed-tax encoder is legacy/diagnostic (print-test only): migrate it minimally onto the document or formally mark it legacy-frozen with a documented exemption decision in this PR — do not let it silently fork semantics.
  • No duplicated business calculations: currency/date formatting helpers already shared remain; anything re-implemented moves behind document/context values.

Scope / What to do

  1. web-print.generateBillHtml: consume PrintDocument (+context) instead of raw bill fields; preserve popup/user-activation flow and paper-size styles.
  2. receipt-encoder.ts classic/compact: build token stream from document blocks; delete now-dead per-template label literals (labels arrive resolved).
  3. Replace KOT browser fallback: render a real semantic KOT HTML (mirroring E's KOT document) instead of decoding byte buffers; remove the TextDecoder-of-bytes hack.
  4. Print-test page: align bill/KOT test surfaces with new paths; apply the test-page localization policy (human-facing translated; technical literals verbatim: protocol names, encodings/codepages, hex/bytes, addresses/ports, model identifiers, capability IDs).
  5. Decide-and-document detailed-tax encoder fate in PR description (migrate minimal vs freeze-legacy), updating parity harness accordingly.

Compatibility / Migration

  • No persisted settings changes; WebUSB device flows unchanged.
  • EN semantic parity enforced by harness on browser/WebUSB outputs at 32/42/48 column equivalents.

What NOT to do

  • Do NOT change PrinterService transport internals or USB device selection.
  • Do NOT modify backend files except importing shared kernel/document modules.
  • Do NOT implement merchant template rendering (I/J) or raster (H outcome).
  • Do NOT drop warning surfacing toasts.

Acceptance Criteria

  • Browser receipt, WebUSB classic/compact, and KOT browser fallback all render from PrintDocument.
  • Raw-bytes→TextDecoder→<pre> KOT path removed; semantic KOT HTML prints correctly at 58/80mm styles.
  • Parity harness green across browser + WebUSB outputs (EN baseline; fa labels where policy set).
  • DirectionSpec-driven bidi isolation verified in generated HTML (RTL primary test fixture includes LTR islands for phone/invoice number).
  • npm run lint + npm run build:frontend green; manual print-test checklist documented in PR.

Verification

cd frontend && npx tsc --noEmit && npm run lint && npm run build && cd ..
npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.ts
npm run i18n:check

Documentation

PR documents any user-visible print-dialog changes; docs issue #449 covers renderer architecture.

Activity

  1. added
    area:frontend
    on Aug 21, 2026
  2. khaira777 commented on Aug 23, 2026

    @khaira777
    ContributorAuthor

    Landed via PR #474 (squash-merged to main): browser and WebUSB print surfaces now render through the shared semantic PrintDocument v1 model. Review findings resolved on-thread (safePrinterText guard c407f98; KOT locale cold-start 6e7561f; locale-load failure surfaces PrintWarning ca41a73 with regression coverage in tests/kot-locale-cold-start.test.ts). All 13 CI checks green at merge.

  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:frontend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions