6.8 KiB
6.8 KiB
Tasks — @suaveplan/pdf migration
Chunk A — Foundation (THIS CHANGE)
Status: SHIPPED in this change.
- Scaffold
packages/devtools/docs/pdf/(package.json, vite, vitest, tsconfig.lib.json, README, biome). src/types/— page-size enum, dimensions table, margins, document / page / element types, colour types, unit type. One.mdper.ts.src/error-codes/—PDF_CODESviadefineCodes,PdfErrorclass,asPdfErrorhelper.src/schemas/— Zod schemas (UnitSchema,HexColorSchema,RgbColorSchema,MarginsSchema,PageConfigSchema,DocumentMetadataSchema) +parseOrThrowhelper raisingPdfError.src/telemetry/— six OTel instruments +createPdfObservabilityfactory + recording helpers.src/units/—toPoints,fromPoints,convert,parseUnit,formatUnitraising typed errors.src/colors/—hexToRgb,rgbToPdfColor,hexToPdfColor,rgbToHex,lighten,darken,COLORS,isTransparent.- Pre-publish gate:
bunx turbo lint typecheck test build --filter=@suaveplan/pdfgreen,bunx turbo test:coverage --filter=@suaveplan/pdf100 / 100 / 100 / 100. - Refresh
MANIFEST.md.
Chunk B — Low-level writer
Status: SHIPPED in this change.
src/pdf-writer/— hand-rolled PDF 1.4 writer with: indirect-object table, font registry for the 14 standard fonts, stream-object assembly (raw + FlateDecode vianode:zlib), xref + trailer, deterministic ordering, injectableClockfor/CreationDate, AbortSignal-awaregenerate,dispose()guard.src/content-stream/— encoder forBT/ET,Td/T*/TL/Tm,Tj/Tf,q/Q,rg/RG,m/l/h/S/s/f/B,re,cm,w, and image XObjectDoplacement with text-mode invariants.- Real PDF parse verification via
pdf-parse@^2.4round-trip (text content + page count + metadata + ProducerInfo).
Chunk C — Elements
Status: SHIPPED in this change.
src/text-element/—TextElementclass +wrapText+resolveStandardFont+measureLineWidthwith alignment, max-lines overflow flag, kerning,AbortSignal.src/table-element/—TableElement<TRow>with column-width auto-distribution, header repeat across pages viarenderPage(context, rowStart), alternating row backgrounds, border + column dividers,LAYOUT_OVERFLOWtyped error.src/image-element/—ImageElementwith PNG decode viapngjs(RGB + optional SMask alpha plane), JPEG pass-through via SOF-marker walk for width/height,detectImageFormat,scaleToFit,validateImageProps, declared-format mismatch detection.src/divider-element/—DividerElementwith horizontal / vertical orientation, dash pattern, spacing above / below,computeDividerSpacingflow helper.- Zod input schema per element type.
- Real pdf-parse round-trip per text + table element.
- Pre-publish gate: lint + typecheck + test + build green, coverage 100 / 100 / 100 / 100.
Chunk D — Layout, styles, document builder, renderer
Status: SHIPPED in this change.
src/style-resolver/—StyleResolvercascade (DEFAULT_STYLE→ theme → base → overrides),mergeStyles,mergeThemedeep merge incl.headingSizes,normalizeSpacingwithPDF.INVALID_ELEMENTon non-finite input,DEFAULT_THEMEpalette.src/layout-engine/—LayoutEnginewith cursor + content-area + header/footer slot rectangles, landscape orientation swap,advance(cursor, height)returning{ fit, remaining },nextPage,computeTextHeight,applyMargin, AbortSignal propagation, typedPDF.LAYOUT_OVERFLOW/PDF.INVALID_PAGE_CONFIGerrors.src/document-builder/—DocumentBuilder<TData>fluent API (title/author/subject/keywords/creator/creationDate/pageConfig/withData/addText/addTable/addImage/addDivider/newPage/setHeader/setFooter/build) +createDocument<TData>()factory.src/image-registry/—ImageRegistry+registerImageXObjectthat allocate per-element PDF XObjects (DCTDecode for JPEG, FlateDecode for PNG RGB plane) and share them across logical pages.src/render-pipeline/—placeNode/renderTableSlice/renderSlot/pickFontResourcehelpers operating on aPipelineStatebundle.src/renderer/— top-levelrenderDocument(doc, opts)returning{ bytes, pageCount, durationMs }. AbortSignal-aware, emits six OTel instruments (documents-rendered counter, pages-emitted counter, render-errors counter tagged by code, validation-failures counter, render-duration histogram, document-size histogram). Page-break + table-continuation loop; raisesPDF.LAYOUT_OVERFLOWfor elements that cannot fit on a fresh page.- Real pdf-parse round-trip tests covering text, multi-page flow, oversize-table pagination with header repeat, header / footer stamping across emitted pages, image XObject embedding.
- Pre-publish gate:
bunx turbo lint typecheck test build --filter=@suaveplan/pdfgreen ANDbunx turbo test:coverage --filter=@suaveplan/pdf100 / 100 / 100 / 100.
Chunk E — Templates
Status: SHIPPED in this change.
src/templates/invoice-template/—createInvoiceTemplate+InvoiceDataSchema+computeInvoiceTotals+formatInvoiceAmount.src/templates/receipt-template/—createReceiptTemplate+ReceiptDataSchema+computeReceiptTotals+formatReceiptAmount.src/templates/report-template/—createReportTemplate+ReportDataSchema.- Zod input schema per template with
PDF.INVALID_TEMPLATE_INPUTerror path attaching the failing issue paths. - Real pdf-parse round-trip per template.
- Pre-publish gate:
bunx turbo lint typecheck test build --filter=@suaveplan/pdfgreen ANDbunx turbo test:coverage --filter=@suaveplan/pdf100 / 100 / 100 / 100.
React PDF preview component — deferred to a follow-up change
(enterprise-react-pdf-preview stub left under openspec/changes/).
Cross-chunk invariants (preserved at every step)
- One
.mdper.ts≥ 200 words covering Purpose, Features, Usage: Basic, Usage: Advanced, API Reference, Implementation Notes. - 100 / 100 / 100 / 100 Istanbul coverage on every touched module — no
istanbul ignorecomments, no// biome-ignore. - Every
it/testcarries{ timeout: 5000 }(30 000 for async). - Tests import from
@suaveplan/testing/runnerper rule 11. - No
export *in non-root barrels (rule 10).