From 41067fb07fcb488e5018b367c12fec1421f52684 Mon Sep 17 00:00:00 2001 From: nati Date: Tue, 8 Sep 2026 06:36:08 +0000 Subject: [PATCH 1/2] feat: implement STCW certificate template conversion to canvas blocks --- .../config/stcw-canvas-conversion.ts | 222 ++++++++++++++++++ .../hooks/useTemplateDraft.ts | 14 ++ .../pages/CertificateDesignerPage.tsx | 92 ++++++++ 3 files changed, 328 insertions(+) create mode 100644 apps/backoffice/src/app/features/certificate-designer/config/stcw-canvas-conversion.ts diff --git a/apps/backoffice/src/app/features/certificate-designer/config/stcw-canvas-conversion.ts b/apps/backoffice/src/app/features/certificate-designer/config/stcw-canvas-conversion.ts new file mode 100644 index 000000000..ddca58e20 --- /dev/null +++ b/apps/backoffice/src/app/features/certificate-designer/config/stcw-canvas-conversion.ts @@ -0,0 +1,222 @@ +import type { TemplateFieldPlacement } from '@ema-platform/api'; + +/** + * One-time, one-way conversion of the hand-written STCW certificate template + * (`SEAFARER_CERTIFICATE_TEMPLATE` on the server) into an equivalent canvas + * layout. + * + * This is not a general HTML-to-blocks parser — none exists, and none is + * feasible: the canvas only ever emits absolute-positioned text/image blocks + * (see `layout-compiler.ts`), so a ``, a `{{#if}}` fallback chain, or a + * border/outline rule has no block equivalent to convert to. What this does + * is reproduce *this one template's* known field positions as blocks, by + * hand, from its own `mm`-based CSS — an approximation good enough to keep + * editing visually from here, not a lossless round-trip. Once converted, the + * canvas becomes the new source of truth for the draft, same as any + * canvas-authored design; the original HTML is gone unless the draft is + * reverted before saving. + * + * What is lost, deliberately, by this conversion: + * - The bordered/outlined sheet frame, the `facts` table's row lines, and + * every font/spacing rule in the template's `