From f4243887cccad174903d9262bd07d9d5a3ec153e Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 3 Jun 2026 13:32:20 -0400 Subject: [PATCH] book(E1): vendor pdf-lib + book PDF export skeleton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First slice of Phase E. The Pages overview now has an Export PDF… button that walks the physical-page sequence, renders each page at print DPI, and stamps them into a single PDF via pdf-lib. Library: - Vendored pdf-lib@1.17.1 as src/vendor/pdf-lib.min.js (~513 KB, MIT). Lazy-loaded through loadPdfLibOnce() so the cost is only paid when an author actually exports. Pipeline: - exportBookToPdf({ dpi, includeCover }) walks enumerateBookPhysicalPages(book), rendering each slot at the resolved DPI (default 200) onto a trim-sized canvas: * Designed pages → master underlay + page layers via drawLayerToCanvas, with token substitution applied to master text layers (book.spec.textStyles tokens resolve per page). * Reflow physical pages → master underlay (with text-frame outline stripped) + the pagination engine's block output drawn via fillText at the frame's coordinates. * Cover → wide spread canvas, all book-cover-* / book-spine layers drawn in place. - Each canvas converts to PNG via canvas.toBlob → Uint8Array, then pdf-lib's embedPng + addPage at trimW×trimH points (cover spread is its own landscape page at the end). UI: - Export PDF… button in the Pages overview toolbar with a status line that surfaces progress + warnings (failed image embeds, per-page render errors). - Filename = `.pdf`. Known v1 limitations (handled in later E phases): - Raster-only: every page is a PNG inside the PDF. Real PDF text for embeddable-allowlist fonts comes in E3. - No bleed-inclusive output / crop marks / page-range / two-file modes yet (E2). - Linked-design layers + premium-gated content not exercised. Co-Authored-By: Claude Opus 4.7 --- src/index.html | 278 +++++++++++++++++++++++++++++++++++++- src/vendor/pdf-lib.min.js | 16 +++ 2 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 src/vendor/pdf-lib.min.js diff --git a/src/index.html b/src/index.html index 5697578..7230f07 100644 --- a/src/index.html +++ b/src/index.html @@ -4417,10 +4417,12 @@ + +
-

Click a designed-page tile to edit it on the canvas. Click a chapter tile to edit its markdown. Per-page Nostr publish (per-event sidecars + manifest) lands in Phase D1.

+

Click a designed-page tile to edit it on the canvas. Click a chapter tile to edit its markdown. PDF export is raster-only in v1 (real-text mode for embeddable fonts lands in a follow-up slice).