decklight 0.6.0 → 0.8.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.
Files changed (61) hide show
  1. package/README.md +23 -11
  2. package/SPEC.md +187 -23
  3. package/cli/agents.mjs +52 -2
  4. package/cli/associate.mjs +2 -2
  5. package/cli/banner.mjs +125 -0
  6. package/cli/bundle.mjs +15 -5
  7. package/cli/{rec.mjs → cast.mjs} +25 -8
  8. package/cli/comments.mjs +389 -0
  9. package/cli/commit-flow.mjs +157 -0
  10. package/cli/commit-message.mjs +125 -0
  11. package/cli/decklight.mjs +96 -25
  12. package/cli/dev.mjs +159 -13
  13. package/cli/edit.mjs +981 -40
  14. package/cli/git-tree.mjs +87 -0
  15. package/cli/git.mjs +22 -0
  16. package/cli/import.mjs +41 -11
  17. package/cli/init.mjs +37 -5
  18. package/cli/pdf.mjs +59 -14
  19. package/cli/port-conflict.mjs +187 -16
  20. package/cli/pptx-export.mjs +107 -0
  21. package/cli/present.mjs +8 -4
  22. package/cli/publish.mjs +25 -42
  23. package/cli/record.mjs +154 -0
  24. package/cli/review-remote.mjs +330 -0
  25. package/cli/review-store.mjs +107 -0
  26. package/cli/review-submit.mjs +292 -0
  27. package/cli/review.mjs +361 -0
  28. package/cli/serve.mjs +36 -1
  29. package/cli/skill-content.mjs +4 -1
  30. package/cli/units.mjs +2 -2
  31. package/cli/util.mjs +59 -0
  32. package/dist/build-info.json +1 -0
  33. package/dist/decklight.css +254 -1
  34. package/dist/decklight.js +153 -79
  35. package/dist/decklight.js.map +4 -4
  36. package/docs/architecture.svg +10 -3
  37. package/package.json +3 -1
  38. package/tools/args.mjs +20 -0
  39. package/tools/bridge.mjs +25 -2
  40. package/tools/deck-html.mjs +59 -0
  41. package/tools/elevenlabs-tts.mjs +3 -3
  42. package/tools/exec.mjs +54 -0
  43. package/tools/gemini-tts.mjs +4 -4
  44. package/tools/lipsync-server.mjs +70 -2
  45. package/tools/lipsync.mjs +46 -30
  46. package/tools/local-voice.mjs +243 -19
  47. package/tools/pptx-write.mjs +151 -0
  48. package/tools/pptx.mjs +82 -2
  49. package/tools/publish-site-voices.mjs +2 -2
  50. package/tools/publish-targets.mjs +39 -2
  51. package/tools/publish-voices.mjs +80 -20
  52. package/tools/recording-impact.mjs +110 -0
  53. package/tools/review-anchor.mjs +180 -0
  54. package/tools/template-theme.mjs +154 -0
  55. package/tools/test-impact.mjs +266 -0
  56. package/tools/tts-cache.mjs +191 -0
  57. package/tools/tts-engines.mjs +85 -8
  58. package/tools/tts-setup.mjs +4 -3
  59. package/tools/video.mjs +21 -6
  60. package/tools/voiceover-server.mjs +163 -17
  61. package/tools/voiceover.mjs +124 -16
@@ -0,0 +1,87 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Building a git tree without touching the working tree.
5
+ //
6
+ // Lifted out of cli/publish.mjs, which invented this, when `review submit`
7
+ // turned out to need exactly the same thing. It is the mechanism behind every "push something without checking
8
+ // anything out" in decklight: objects land in the repository's database,
9
+ // nothing references them until the push, and neither the working tree, the
10
+ // index nor the checked-out branch ever hears about it.
11
+ //
12
+ // Extracted rather than copied because the one subtle line here — git's tree
13
+ // ordering, which compares a directory as if its name ended in `/` — is exactly
14
+ // the kind of thing two copies diverge on silently. A tree sorted the other way
15
+ // is accepted by `mktree` and then reported by `git fsck`, long after whoever
16
+ // wrote the second copy has moved on.
17
+ //
18
+ // Every function takes the caller's own `git(args, input)` runner, so the cwd,
19
+ // the failure convention and the error wording stay the caller's business.
20
+
21
+ /**
22
+ * One tree's entries: `<mode> <type> <sha>\t<name>` per line.
23
+ *
24
+ * `--full-tree` is load-bearing and not a flourish. Plain `git ls-tree <tree>`
25
+ * is implicitly scoped to the CURRENT PATH PREFIX: run from `talks/` it lists
26
+ * `<tree>:talks` rather than the root. Both callers run git in the deck's own
27
+ * directory, so without this a deck in a subdirectory rebuilds the repository's
28
+ * whole tree from that subdirectory's contents — every sibling above it silently
29
+ * deleted in the pushed commit, and no error anywhere.
30
+ */
31
+ export function lsTree(git, sha) {
32
+ return git(['ls-tree', '--full-tree', sha]).split('\n').filter(Boolean).map((l) => {
33
+ const [meta, name] = l.split('\t');
34
+ const [mode, type, entrySha] = meta.split(/\s+/);
35
+ return { mode, type, sha: entrySha, name };
36
+ });
37
+ }
38
+
39
+ /**
40
+ * Write a tree object from entries.
41
+ *
42
+ * The sort is git's own: byte-wise, with a tree's name compared as `name/`.
43
+ * Get it wrong and `mktree` still accepts the tree — `git fsck` is where you
44
+ * find out, which is much later and somewhere else.
45
+ */
46
+ export function mktree(git, entries) {
47
+ const key = (e) => (e.type === 'tree' ? `${e.name}/` : e.name);
48
+ entries.sort((a, b) => (key(a) < key(b) ? -1 : 1));
49
+ return git(['mktree'], entries.map((e) => `${e.mode} ${e.type} ${e.sha}\t${e.name}\n`).join(''));
50
+ }
51
+
52
+ /**
53
+ * A copy of the tree at `treeish` with `blobSha` placed at `pathParts`,
54
+ * building intermediate trees and **keeping every sibling entry**.
55
+ *
56
+ * `treeish` may be a commit — `ls-tree` resolves it — which is why a caller can
57
+ * hand it the parent commit directly. `null`/`undefined` means "nothing there
58
+ * yet", which is how a missing intermediate directory gets created and how an
59
+ * orphan commit's tree is built.
60
+ */
61
+ export function putBlob(git, treeish, pathParts, blobSha) {
62
+ const entries = treeish ? lsTree(git, treeish) : [];
63
+ const name = pathParts[0];
64
+ const kept = entries.filter((e) => e.name !== name);
65
+ if (pathParts.length === 1) {
66
+ kept.push({ mode: '100644', type: 'blob', sha: blobSha, name });
67
+ } else {
68
+ const sub = entries.find((e) => e.name === name && e.type === 'tree');
69
+ kept.push({ mode: '040000', type: 'tree', sha: putBlob(git, sub?.sha, pathParts.slice(1), blobSha), name });
70
+ }
71
+ return mktree(git, kept);
72
+ }
73
+
74
+ /**
75
+ * The commit a remote ref points at, fetched into FETCH_HEAD — or null when
76
+ * the remote has no such ref.
77
+ *
78
+ * The other half of pushing without a checkout: the PARENT, as the REMOTE has
79
+ * it. `ls-remote` first so a missing ref is an answer rather than a fetch
80
+ * error, then a destination-less fetch, so no local ref is created or moved —
81
+ * FETCH_HEAD is a file, not a ref, and nothing in the repository changes.
82
+ */
83
+ export function remoteHead(git, remote, ref) {
84
+ if (!git(['ls-remote', remote, ref])) return null;
85
+ git(['fetch', '--quiet', remote, ref]);
86
+ return git(['rev-parse', 'FETCH_HEAD']);
87
+ }
package/cli/git.mjs CHANGED
@@ -177,6 +177,28 @@ export function gitAutocommit(deckPath, cwd, message = `decklight: autosave ${ba
177
177
  // LOCAL read of remote-tracking refs and needs no network at all. `behind` is
178
178
  // therefore as fresh as your last fetch, and saying so is better than fetching
179
179
  // behind someone's back.
180
+ //
181
+ // ONE named exception: the review check at `decklight author` startup
182
+ // (cli/review-remote.mjs), which exists precisely because "somebody reviewed
183
+ // your deck" is only useful unasked. It is once, detached, off by three
184
+ // switches that each say why, and nowhere near a SIGINT handler — the shape
185
+ // update-check.mjs established. SPEC REVIEW states the contract; anything
186
+ // else that wants to fetch unasked argues there, not here.
187
+
188
+ /**
189
+ * `owner/repo` from a GitHub remote URL, or null for anything else.
190
+ *
191
+ * THE one parser — `pagesUrl` (cli/publish.mjs) derives the Pages site from it
192
+ * and `review submit` hands it to `gh --repo`. It lived in both files as the
193
+ * same regex for a while, which is exactly how one copy grows a spelling the
194
+ * other refuses.
195
+ */
196
+ export function ownerRepo(remoteUrl) {
197
+ const m = (remoteUrl || '').trim().match(
198
+ /^(?:https?:\/\/(?:[^/@]+@)?|git@|ssh:\/\/git@)github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
199
+ );
200
+ return m ? { owner: m[1], repo: m[2] } : null;
201
+ }
180
202
 
181
203
  /** The env every remote-touching git call runs under. See the note above. */
182
204
  export function noPromptEnv(env = process.env) {
package/cli/import.mjs CHANGED
@@ -29,6 +29,7 @@ import { THEMES_DIR, themeCss as shippedThemeCss, runtimeCss, runtimeJs } from '
29
29
  import { unzip } from '../tools/zip.mjs';
30
30
  import { decodeEntities } from '../tools/ooxml.mjs';
31
31
  import { parseRels, resolvePart, slideOrder, parseSlide, notesText, slideSection, mimeOf } from '../tools/pptx.mjs';
32
+ import { parseTemplateTheme, themeFromTemplate } from '../tools/template-theme.mjs';
32
33
 
33
34
 
34
35
  const USAGE = `usage: decklight import <deck.pptx | deck.key | google-slides-url> [options]
@@ -36,14 +37,16 @@ const USAGE = `usage: decklight import <deck.pptx | deck.key | google-slides-url
36
37
 
37
38
  -o <file> output path [the source's, with .html]
38
39
  --theme <name> theme to open in [midnight]
40
+ 'template' derives one from the file's own palette and
41
+ fonts (its ppt/theme part), gated like any shipped theme
39
42
  --build all|none|auto
40
43
  which lists step in [auto]
41
44
  auto follows PowerPoint's own per-paragraph build list
42
45
  --force overwrite an existing output file
43
46
  -v, --verbose print every slide's line, not just the ones with drops
44
47
 
45
- content crosses over — titles, bullets (nested), paragraphs, tables, images
46
- and speaker notes. The template's LOOK does not: the result is themed by
48
+ content crosses over — titles, bullets (nested), paragraphs, tables, images,
49
+ charts (as data-chart, from the values the file carries) and speaker notes. The template's LOOK does not: the result is themed by
47
50
  decklight. Anything that cannot cross is named on stderr with its slide
48
51
  number, so you know what to rebuild by hand.
49
52
 
@@ -183,9 +186,9 @@ export function convert(zip, { build = 'auto' } = {}) {
183
186
  const bytes = zip.get(p);
184
187
  return bytes ? { bytes, mime: mimeOf(p) } : null;
185
188
  },
189
+ chartOf: (target) => zip.get(resolvePart(slidePath, target))?.toString() ?? null,
186
190
  });
187
191
  n += 1;
188
- if (slide.hidden) { report.push({ n, hidden: true, title: slide.title }); continue; }
189
192
 
190
193
  const notesRel = [...rels.values()].find((r) => r.type.endsWith('/notesSlide'));
191
194
  const notes = notesRel
@@ -193,16 +196,20 @@ export function convert(zip, { build = 'auto' } = {}) {
193
196
  : [];
194
197
  const { html, did } = slideSection(slide, notes, { build });
195
198
  sections.push(html);
196
- report.push({ n, title: slide.title, did, drops: slide.drops });
199
+ // PowerPoint's hidden slide is decklight's (HIDDEN_SLIDES): kept, numbered,
200
+ // marked — never thrown away on the way in. One report row either way.
201
+ report.push({ n, title: slide.title, did, drops: slide.drops, ...(slide.hidden ? { hidden: true } : {}) });
197
202
  }
198
203
  if (!sections.length) throw new Error('every slide in this file is hidden — nothing to import');
199
204
  return { sections, report };
200
205
  }
201
206
 
202
207
  /** The self-contained deck, runtime and theme inlined — the `init` output shape. */
203
- export function deckHtml(sections, { title, theme }) {
208
+ export function deckHtml(sections, { title, theme, themeCss = null }) {
204
209
  const css = runtimeCss();
205
- const theme_ = shippedThemeCss(theme);
210
+ // `themeCss` is a theme that is not shipped — the one derived from the
211
+ // template's own palette and fonts (tools/template-theme.mjs)
212
+ const theme_ = themeCss ?? shippedThemeCss(theme);
206
213
  // runtimeJs() applies the SAME transform init/upgrade/bundle use and audit
207
214
  // recomputes. This used to be a local escape that missed `<!--`, which made
208
215
  // every imported deck audit as "runtime DIFFERS from this install's build".
@@ -270,7 +277,10 @@ export async function importMain(args = []) {
270
277
  const source = args.find((a, i) => !a.startsWith('-') && !VALUE.has(args[i - 1]));
271
278
  if (!source) { console.error(`decklight import: needs a file or a Google Slides URL\n\n${USAGE}`); return 1; }
272
279
 
273
- const theme = opt('--theme', 'midnight');
280
+ const themeFlag = opt('--theme', 'midnight');
281
+ const wantTemplate = themeFlag === 'template';
282
+ let theme = wantTemplate ? 'midnight' : themeFlag;
283
+ let themeCss = null;
274
284
  if (!existsSync(join(THEMES_DIR, `${theme}.css`))) {
275
285
  const all = readdirSync(THEMES_DIR).filter((f) => f.endsWith('.css')).map((f) => f.replace(/\.css$/, ''));
276
286
  console.error(`decklight import: no theme "${theme}"`);
@@ -359,7 +369,26 @@ export async function importMain(args = []) {
359
369
  // ---- convert ----------------------------------------------------------
360
370
  let result;
361
371
  try {
362
- result = convert(unzip(bytes), { build });
372
+ const zip = unzip(bytes);
373
+ result = convert(zip, { build });
374
+ // The template's palette and fonts — most of what "our template" means —
375
+ // are in ppt/theme/theme1.xml. Derived only when asked, because the
376
+ // default (a shipped theme) is what every existing import produced.
377
+ const themePart = [...zip.keys()].find((k) => /^ppt\/theme\/theme\d*\.xml$/.test(k));
378
+ if (wantTemplate) {
379
+ const parsed = themePart ? parseTemplateTheme(zip.get(themePart).toString()) : null;
380
+ const derived = parsed ? themeFromTemplate(parsed) : null;
381
+ if (derived?.ok) {
382
+ theme = derived.name; themeCss = derived.css;
383
+ console.error(` theme: ${derived.name} — derived from the template's palette and fonts`
384
+ + `${parsed.fonts.heading || parsed.fonts.body ? ` (${[parsed.fonts.heading, parsed.fonts.body].filter(Boolean).join(' / ')})` : ''}`);
385
+ } else {
386
+ console.error(` theme: ${!themePart ? 'this file carries no theme part' : !parsed ? 'the theme part has no colour scheme' : `the derived theme failed its contrast gates: ${derived.errors[0]}`}`
387
+ + ' — opening in midnight instead');
388
+ }
389
+ } else if (themePart) {
390
+ console.error(' this file carries a theme — `--theme template` imports its palette and fonts');
391
+ }
363
392
  } catch (e) {
364
393
  console.error(`decklight import: ${e.message}`);
365
394
  return 1;
@@ -372,7 +401,7 @@ export async function importMain(args = []) {
372
401
  for (const row of result.report) {
373
402
  if (row.hidden) {
374
403
  const t = decodeEntities((row.title ?? '').replace(/<[^>]+>/g, ''));
375
- console.error(` ${String(row.n).padStart(3)} ⊘ hidden slide skipped${t ? ` — ${t}` : ''}`);
404
+ console.error(` ${String(row.n).padStart(3)} ⊘ hidden — kept as data-hidden${t ? ` — ${t}` : ''}`);
376
405
  continue;
377
406
  }
378
407
  // the title is HTML by now; the terminal wants the words back
@@ -387,9 +416,10 @@ export async function importMain(args = []) {
387
416
  }
388
417
 
389
418
  const title = basename(out).replace(/\.html$/, '').replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase());
390
- writeFileSync(out, deckHtml(result.sections, { title, theme }));
419
+ writeFileSync(out, deckHtml(result.sections, { title, theme, themeCss }));
391
420
  const kb = Math.round(readFileSync(out).length / 1024);
392
- console.error(`${out} · ${result.sections.length} slides · theme ${theme} · ${kb} KB`
421
+ const hiddenCount = result.report.filter((r) => r.hidden).length;
422
+ console.error(`${out} · ${result.sections.length} slides${hiddenCount ? ` (${hiddenCount} hidden)` : ''} · theme ${theme} · ${kb} KB`
393
423
  + (dropped ? ` · ${dropped} thing(s) dropped — see ⚠ above` : ''));
394
424
  if (!verbose && !dropped) console.error(' everything converted; -v lists each slide');
395
425
  return 0;
package/cli/init.mjs CHANGED
@@ -48,7 +48,10 @@ import {
48
48
  } from './skill-content.mjs';
49
49
  import { THEMES_DIR, themeCss, runtimeCss, runtimeJs } from './pkg.mjs';
50
50
  import { TARGETS, detectedTargets, installGlobalSkill, display } from './skills.mjs';
51
- import { onPath } from './agents.mjs';
51
+ import { onPath, detectAgents } from './agents.mjs';
52
+ import {
53
+ ASK_MESSAGES, planCommitMessages, rememberPref, storedPref,
54
+ } from './commit-message.mjs';
52
55
  import { escapeHtml } from './edit.mjs';
53
56
  import {
54
57
  classifyRemoteError, createRepo, foreignWarning, git as gitRun, inGitRepo, isIdentityError,
@@ -375,13 +378,26 @@ export function openCommand(platform, url) {
375
378
  * cannot launch (headless, no xdg-open) gets one dim line and a normal exit:
376
379
  * the deck was created, which is the product.
377
380
  */
378
- export async function openDeck(deckPath, { platform = process.platform, spawnFn = spawn, out = process.stdout } = {}) {
379
- const url = pathToFileURL(deckPath).href;
380
- const { cmd, args } = openCommand(platform, url);
381
+ export async function openDeck(deckPath, opts = {}) {
381
382
  const rel = path.relative('.', deckPath) || deckPath;
383
+ // the prefix names the FLAG that asked, which is what a reader of the line
384
+ // needs: --open is opt-in, and its one dim failure line has to say so
385
+ return openUrl(pathToFileURL(deckPath).href, { ...opts, what: rel, prefix: '--open: ' });
386
+ }
387
+
388
+ /**
389
+ * The same launcher, for a URL that is not a file — `decklight record` serves
390
+ * the deck over http://127.0.0.1 precisely because a browser will not open a
391
+ * microphone for a `file://` page.
392
+ */
393
+ export async function openUrl(url, {
394
+ platform = process.platform, spawnFn = spawn, out = process.stdout, what = url, prefix = '',
395
+ } = {}) {
396
+ const { cmd, args } = openCommand(platform, url);
397
+ const rel = what;
382
398
  const dim = (s) => (out.isTTY && !process.env.NO_COLOR ? `${DIM}${s}${RESET}` : s);
383
399
  const skipped = (err) =>
384
- out.write(dim(`--open: could not launch a browser (${cmd}: ${err.code ?? err.message}) — open ${rel} yourself\n`));
400
+ out.write(dim(`${prefix}could not launch a browser (${cmd}: ${err.code ?? err.message}) — open ${rel} yourself\n`));
385
401
  await new Promise((resolve) => {
386
402
  let child;
387
403
  try {
@@ -670,6 +686,22 @@ unless --no-skill is given. The deck file is only touched with --force.
670
686
  // would only offer what is on. The line names the flag that turns it off.
671
687
  note(" commits land one per agent edit, with the agent's own message"
672
688
  + ' (--git-mode timer for a plain cadence)');
689
+ // …and the OTHER half of what those commits say. Asked here, once, because
690
+ // this is the moment the commits it governs start existing — and asked at
691
+ // all, rather than defaulted silently, because the answer sends the deck's
692
+ // diffs to an agent. Default yes; a person still has to let it through.
693
+ const msgs = planCommitMessages({
694
+ args: argv, tty, agents: detectAgents().length, creatingRepo: true,
695
+ stored: storedPref(root),
696
+ });
697
+ if (msgs.action === 'ask' || msgs.action === 'on' || msgs.action === 'off') {
698
+ const on = msgs.action === 'ask' ? await askYes(ASK_MESSAGES, true) : msgs.action === 'on';
699
+ rememberPref(root, on);
700
+ note(on
701
+ ? ' commit subjects are written by an agent, from the diff'
702
+ + ' (git config decklight.commit-messages false turns it off)'
703
+ : ' commit subjects stay generic (--commit-messages turns it on)');
704
+ }
673
705
  }
674
706
  else if (action === 'hint') note(' git: no repository here — pass --git to create one and auto-commit the deck');
675
707
 
package/cli/pdf.mjs CHANGED
@@ -18,17 +18,40 @@
18
18
  // URL reads those back and names them on stderr. A clipped slide in a PDF you
19
19
  // have already emailed is a slide nobody can fix.
20
20
 
21
- import { execFileSync } from 'node:child_process';
22
21
  import { existsSync, readFileSync, rmSync, statSync } from 'node:fs';
23
22
  import { basename, resolve } from 'node:path';
24
23
  import { chromeBin, chromeArgs } from '../tools/chrome.mjs';
25
24
  import { argReader, isMain } from '../tools/args.mjs';
25
+ import { run, CODEC_MS } from '../tools/exec.mjs';
26
+ import { sectionBodies, isHiddenSection } from '../tools/deck-html.mjs';
27
+
28
+ /**
29
+ * How many slides the handout puts on a page — the runtime's own number,
30
+ * RESTATED rather than imported.
31
+ *
32
+ * `src/core/print.js` exports it and this file used to import it, which works
33
+ * in a clone and cannot work in an install: the package ships `cli/`, `tools/`,
34
+ * `dist/`, `themes/` and `docs/` — never `src/`, whose only shipped form is the
35
+ * bundle. `npm test` and `npm run verify` both drive the CLI out of the working
36
+ * tree, so both were green while `decklight pdf` was a `Cannot find module` for
37
+ * everyone who had installed it. `npm run soak` caught it at step 40.
38
+ *
39
+ * The pair is kept honest by test/pdf.test.mjs, which reads the number out of
40
+ * both sources and fails when they drift — the same shape as the harness list
41
+ * that verify.mjs spells out for tools/test-impact.mjs.
42
+ */
43
+ export const HANDOUT_PER_PAGE = 3;
26
44
 
27
45
  const USAGE = `usage: decklight pdf <deck.html> [-o out.pdf] [--theme <name>] [--wait <ms>]
46
+ [--notes | --handout]
28
47
  renders the deck's ?print view to a PDF — one slide per page, at the deck's
29
48
  own 1280×720, in its theme, with every build complete
30
49
 
31
50
  -o <file> output path [the deck's, with .pdf]
51
+ --notes one slide per page with its speaker notes underneath —
52
+ the presenter's copy [out: <deck>.notes.pdf]
53
+ --handout three slides a page, portrait, ruled lines beside each for
54
+ the audience to write on [out: <deck>.handout.pdf]
32
55
  --theme <name> export in another theme (rides ?theme=)
33
56
  --wait <ms> render budget for heavy decks [8000]
34
57
 
@@ -36,20 +59,32 @@ const USAGE = `usage: decklight pdf <deck.html> [-o out.pdf] [--theme <name>] [-
36
59
  is still written (a clipped slide is worth knowing about, not worth refusing)`;
37
60
 
38
61
  /** The deck's path with .pdf in place of .html — or whatever -o said. */
39
- export function pdfOut(deckPath, oFlag) {
62
+ export function pdfOut(deckPath, oFlag, variant = '') {
40
63
  if (oFlag) return resolve(oFlag);
41
- return resolve(deckPath.replace(/\.html?$/i, '') + '.pdf');
64
+ // a variant gets its own name, so the handout never overwrites the slides
65
+ return resolve(deckPath.replace(/\.html?$/i, '') + (variant ? `.${variant}` : '') + '.pdf');
42
66
  }
43
67
 
44
68
  /**
45
69
  * The URL to print. `?print` is the whole rendering contract; `?theme=` is the
46
70
  * existing startup override, so exporting in another theme costs nothing here.
47
71
  */
48
- export function printUrl(absDeckPath, { theme } = {}) {
49
- const q = theme ? `?print&theme=${encodeURIComponent(theme)}` : '?print';
72
+ export function printUrl(absDeckPath, { theme, variant = '' } = {}) {
73
+ // `?print=notes` / `?print=handout` are the runtime's own variants (src/core/print.js)
74
+ const print = variant ? `?print=${variant}` : '?print';
75
+ const q = theme ? `${print}&theme=${encodeURIComponent(theme)}` : print;
50
76
  return `file://${absDeckPath}${q}`;
51
77
  }
52
78
 
79
+ /**
80
+ * How many pages the PDF should have: one per slide, except the handout,
81
+ * which groups HANDOUT_PER_PAGE to a page — the same number print.js
82
+ * paginates with, held to it by a test rather than by an import.
83
+ */
84
+ export function expectedPages(slides, variant = '') {
85
+ return variant === 'handout' ? Math.ceil(slides / HANDOUT_PER_PAGE) : slides;
86
+ }
87
+
53
88
  /**
54
89
  * How many pages Chrome actually wrote.
55
90
  *
@@ -95,7 +130,7 @@ export const overflowSlides = (html) => flaggedSlides(html, 'data-overflow');
95
130
  export const splitConflictSlides = (html) => flaggedSlides(html, 'data-split-conflict');
96
131
 
97
132
  /** Slides in the printed deck — the number the page count should equal. */
98
- export const slideCount = (html) => (html.match(/<section\b/g) ?? []).length;
133
+ export const slideCount = (html) => sectionBodies(html).filter((b) => !isHiddenSection(b)).length;
99
134
 
100
135
  const KB = (n) => (n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / 1048576).toFixed(1)} MB`);
101
136
 
@@ -107,10 +142,15 @@ export async function pdfMain(args = []) {
107
142
  const src = resolve(deck);
108
143
  if (!existsSync(src)) { console.error(`decklight pdf: no such deck: ${deck}`); return 1; }
109
144
 
110
- const out = pdfOut(src, opt('-o'));
145
+ const variant = args.includes('--notes') ? 'notes' : args.includes('--handout') ? 'handout' : '';
146
+ if (args.includes('--notes') && args.includes('--handout')) {
147
+ console.error('decklight pdf: --notes and --handout are two different PDFs — run it twice');
148
+ return 1;
149
+ }
150
+ const out = pdfOut(src, opt('-o'), variant);
111
151
  const theme = opt('--theme');
112
152
  const wait = Number(opt('--wait', 8000));
113
- const url = printUrl(src, { theme });
153
+ const url = printUrl(src, { theme, variant });
114
154
  const bin = chromeBin('pdf');
115
155
  // file:// decks load their runtime, themes and casts as siblings
116
156
  const shared = chromeArgs('--allow-file-access-from-files', `--virtual-time-budget=${wait}`);
@@ -120,17 +160,17 @@ export async function pdfMain(args = []) {
120
160
  // about to hide.
121
161
  let html = '';
122
162
  try {
123
- html = execFileSync(bin, [...shared, '--dump-dom', url],
124
- { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
163
+ html = run(bin, [...shared, '--dump-dom', url],
164
+ { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'], timeout: CODEC_MS, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
125
165
  } catch { /* the print pass below is the one that must succeed */ }
126
166
  const slides = slideCount(html);
127
- console.error(`pdf: rendering ${basename(src)}?print${theme ? ` · theme ${theme}` : ''}`
167
+ console.error(`pdf: rendering ${basename(src)}?print${variant ? `=${variant}` : ''}${theme ? ` · theme ${theme}` : ''}`
128
168
  + `${slides ? ` — ${slides} slides, builds complete, casts expanded` : ''}`);
129
169
 
130
170
  rmSync(out, { force: true }); // never leave a stale PDF looking like a fresh one
131
171
  try {
132
- execFileSync(bin, [...shared, '--no-pdf-header-footer', `--print-to-pdf=${out}`, url],
133
- { stdio: ['ignore', 'ignore', 'ignore'] });
172
+ run(bin, [...shared, '--no-pdf-header-footer', `--print-to-pdf=${out}`, url],
173
+ { stdio: ['ignore', 'ignore', 'ignore'], timeout: CODEC_MS, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
134
174
  } catch (e) {
135
175
  console.error(`decklight pdf: Chrome failed — ${String(e.message ?? e).split('\n')[0]}`);
136
176
  return 1;
@@ -149,7 +189,12 @@ export async function pdfMain(args = []) {
149
189
  }
150
190
  const buf = readFileSync(out);
151
191
  const pages = pdfPageCount(buf);
152
- console.log(`${out} · ${pages || '?'} pages · 1280×720 (16:9) · ${KB(buf.length)}`);
192
+ const want = slides ? expectedPages(slides, variant) : 0;
193
+ const geometry = variant === 'handout' ? 'portrait, 3 slides a page' : variant === 'notes' ? 'slide + notes per page' : '1280×720 (16:9)';
194
+ console.log(`${out} · ${pages || '?'} pages · ${geometry} · ${KB(buf.length)}`);
195
+ if (want && pages && pages !== want) {
196
+ console.error(`pdf: ⚠ expected ${want} pages for ${slides} slides${variant ? ` (${variant})` : ''}, got ${pages}`);
197
+ }
153
198
  return 0;
154
199
  }
155
200