openfig-cli 0.3.18 → 0.3.19

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.
package/bin/cli.mjs CHANGED
@@ -30,6 +30,7 @@ const COMMANDS = {
30
30
  'remove-slide': './commands/remove-slide.mjs',
31
31
  'roundtrip': './commands/roundtrip.mjs',
32
32
  'export': './commands/export.mjs',
33
+ 'pdf': './commands/pdf.mjs',
33
34
  };
34
35
 
35
36
  const arg2 = process.argv[2];
@@ -40,6 +41,7 @@ if (!arg2 || arg2 === '--help' || arg2 === '-h') {
40
41
  console.log('Usage: openfig <command> [args...]\n');
41
42
  console.log('Commands:');
42
43
  console.log(' export Export slides as images (PNG/JPG/WEBP)');
44
+ console.log(' pdf Export slides as a multi-page PDF');
43
45
  console.log(' inspect Show document structure (node hierarchy tree)');
44
46
  console.log(' list-text List all text content in the deck');
45
47
  console.log(' list-overrides List editable override keys per symbol');
@@ -0,0 +1,66 @@
1
+ /**
2
+ * pdf — Export slides from a .deck file to a multi-page PDF.
3
+ *
4
+ * Usage:
5
+ * openfig pdf <file.deck> [options]
6
+ *
7
+ * Options:
8
+ * -o <file.pdf> Output PDF path (default: <deckname>.pdf)
9
+ * --slide <n> Export only slide N (1-based). Omit to export all.
10
+ * --scale <n> Zoom factor: 1 = 1920×1080, 0.5 = 960×540 (default: 1)
11
+ * --width <px> Output width in pixels (height scales proportionally)
12
+ * --fonts <dir> Extra font directory to load (can repeat)
13
+ */
14
+
15
+ import { writeFileSync } from 'fs';
16
+ import { parse, resolve } from 'path';
17
+ import { PDFDocument } from 'pdf-lib';
18
+ import { FigDeck } from '../../lib/core/fig-deck.mjs';
19
+ import { renderDeck, registerFontDir } from '../../lib/rasterizer/deck-rasterizer.mjs';
20
+ import { resolveFonts } from '../../lib/rasterizer/font-resolver.mjs';
21
+
22
+ export async function run(args, flags) {
23
+ const file = args[0];
24
+ if (!file) {
25
+ console.error('Usage: openfig pdf <file.deck> [options]\n');
26
+ console.error('Options:');
27
+ console.error(' -o <file.pdf> Output PDF path (default: <deckname>.pdf)');
28
+ console.error(' --slide <n> Export only slide N (1-based)');
29
+ console.error(' --scale <n> Zoom factor: 1 = 1920×1080 (default: 1)');
30
+ console.error(' --width <px> Output width in pixels');
31
+ console.error(' --fonts <dir> Extra font directory to load');
32
+ process.exit(1);
33
+ }
34
+
35
+ const defaultOut = parse(file).name + '.pdf';
36
+ const outPath = resolve(flags.o ?? flags.output ?? defaultOut);
37
+
38
+ const renderOpts = {};
39
+ if (flags.width) renderOpts.width = parseInt(flags.width);
40
+ else if (flags.scale) renderOpts.scale = parseFloat(flags.scale);
41
+
42
+ const fontDirs = [].concat(flags.fonts ?? []);
43
+ for (const d of fontDirs) registerFontDir(resolve(d));
44
+
45
+ const deck = await FigDeck.fromDeckFile(file);
46
+ await resolveFonts(deck, { quiet: false });
47
+
48
+ const slideFilter = flags.slide ? parseInt(flags.slide) : null;
49
+ const slides = await renderDeck(deck, renderOpts);
50
+
51
+ const doc = await PDFDocument.create();
52
+
53
+ let count = 0;
54
+ for (const { index, png } of slides) {
55
+ if (slideFilter && index + 1 !== slideFilter) continue;
56
+ const image = await doc.embedPng(png);
57
+ const page = doc.addPage([image.width, image.height]);
58
+ page.drawImage(image, { x: 0, y: 0, width: image.width, height: image.height });
59
+ count++;
60
+ console.log(` slide ${index + 1} → page ${count}`);
61
+ }
62
+
63
+ const pdfBytes = await doc.save();
64
+ writeFileSync(outPath, pdfBytes);
65
+ console.log(`\nExported ${count} slide(s) to ${outPath} (${pdfBytes.length} bytes)`);
66
+ }
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": "0.2",
3
3
  "name": "openfig",
4
- "version": "0.3.18",
4
+ "version": "0.3.19",
5
5
  "description": "Open-source tools for Figma file parsing and rendering",
6
6
  "author": {
7
7
  "name": "OpenFig Contributors"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openfig-cli",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "description": "OpenFig — Open-source tools for Figma file parsing and rendering",
5
5
  "type": "module",
6
6
  "bin": {
@@ -49,6 +49,7 @@
49
49
  "fzstd": "^0.1.1",
50
50
  "kiwi-schema": "^0.5.0",
51
51
  "pako": "^2.1.0",
52
+ "pdf-lib": "^1.17.1",
52
53
  "sharp": "^0.34.5",
53
54
  "ssim.js": "^3.5.0",
54
55
  "yazl": "^3.3.1",