bookcover-core 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { find_builtin_icon } from './builtin_icons.js';
4
4
  import { find_preset_icon_svg } from './preset_icons_svg.js';
5
5
  // Module-level in-memory cache: iconify ID → raw SVG string
6
6
  const svg_cache = new Map();
7
- // This package has no i18n/UI concerns (see repo CLAUDE.md — generator is pure TS core), so
7
+ // This package has no i18n/UI concerns (see repo AGENTS.md — generator is pure TS core), so
8
8
  // errors reachable via user input (a mistyped icon field) carry a translation code + params
9
9
  // alongside a default English message; the widget translates at the point it catches them
10
10
  // (generator_client.ts / PreviewPane.vue), falling back to `message` for anything else.
@@ -0,0 +1,11 @@
1
+ import type { GetDimensionsResult } from './dimensions.js';
2
+ /**
3
+ * Turn a one-page wraparound cover PDF into two pages: the front, then the back. Any spine is left
4
+ * out, as there's nothing to print it on once the faces are apart. Each page keeps the cover's
5
+ * bleed on every side, as each is trimmed on its own (on the inner side that bleed is the spine's
6
+ * or the other face's artwork). Both pages share one copy of the source page's content and
7
+ * resources, each just boxed to its own face. `dims` must be in mm, as resolve_dimensions()
8
+ * returns them.
9
+ */
10
+ export declare function split_pdf_pages(pdf: Uint8Array, dims: GetDimensionsResult): Promise<Uint8Array>;
11
+ //# sourceMappingURL=pdf_pages.d.ts.map
@@ -0,0 +1,38 @@
1
+ // Re-cutting a wraparound cover PDF into a page for the front and one for the back, for printing
2
+ // them separately (generate()'s `pdf_pages` option). Not re-exported from the main barrel, since
3
+ // it brings pdf-lib with it: reach it via the `bookcover-core/pdf-pages` subpath, which the
4
+ // platform wrappers import lazily only when asked for pages
5
+ import { PDFDocument } from 'pdf-lib';
6
+ /** Convert mm to pt — the PDF coordinate system uses pt (1mm = 72/25.4pt) */
7
+ function mm_to_pt(mm) {
8
+ return mm / 25.4 * 72;
9
+ }
10
+ /**
11
+ * Turn a one-page wraparound cover PDF into two pages: the front, then the back. Any spine is left
12
+ * out, as there's nothing to print it on once the faces are apart. Each page keeps the cover's
13
+ * bleed on every side, as each is trimmed on its own (on the inner side that bleed is the spine's
14
+ * or the other face's artwork). Both pages share one copy of the source page's content and
15
+ * resources, each just boxed to its own face. `dims` must be in mm, as resolve_dimensions()
16
+ * returns them.
17
+ */
18
+ export async function split_pdf_pages(pdf, dims) {
19
+ const bleed = dims.cover_has_bleed ? dims.cover_bleed.toNumber() : 0;
20
+ const source = await PDFDocument.load(pdf);
21
+ const sheet = source.getPage(0).getMediaBox();
22
+ // One copier call for both pages, so the background image etc. is only embedded once
23
+ const out = await PDFDocument.create();
24
+ const [front, back] = await out.copyPages(source, [0, 0]);
25
+ const faces = [[front, dims.cover_region_front], [back, dims.cover_region_back]];
26
+ for (const [page, region] of faces) {
27
+ // Regions are mm from the top-left, PDF boxes are pt from the bottom-left
28
+ const x = sheet.x + mm_to_pt(region.x.toNumber() - bleed);
29
+ const width = mm_to_pt(region.w.toNumber() + bleed * 2);
30
+ const height = mm_to_pt(region.h.toNumber() + bleed * 2);
31
+ const y = sheet.y + sheet.height - mm_to_pt(region.y.toNumber() - bleed) - height;
32
+ page.setMediaBox(x, y, width, height);
33
+ page.setCropBox(x, y, width, height);
34
+ out.addPage(page);
35
+ }
36
+ return await out.save();
37
+ }
38
+ //# sourceMappingURL=pdf_pages.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bookcover-core",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "license": "MIT-0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/preset_icons_svg.d.ts",
26
26
  "default": "./dist/preset_icons_svg.js"
27
27
  },
28
+ "./pdf-pages": {
29
+ "types": "./dist/pdf_pages.d.ts",
30
+ "default": "./dist/pdf_pages.js"
31
+ },
28
32
  "./package.json": "./package.json"
29
33
  },
30
34
  "files": [
@@ -41,6 +45,7 @@
41
45
  "big.js": "^7.0.1",
42
46
  "bwip-js": "^4.9.0",
43
47
  "chroma-js": "^3.2.0",
48
+ "pdf-lib": "^1.17.1",
44
49
  "pm-to-typst": "^0.1.2",
45
50
  "printing-services": "^1.5.1",
46
51
  "typst-fonts": "^0.1.4",