decklight 0.8.0 → 0.9.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 (133) hide show
  1. package/PLATFORM.md +666 -0
  2. package/README.md +224 -150
  3. package/SPEC.md +732 -886
  4. package/cli/agent-review.mjs +245 -0
  5. package/cli/agents.mjs +25 -5
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +183 -0
  10. package/cli/bundle.mjs +383 -31
  11. package/cli/cast.mjs +7 -7
  12. package/cli/check.mjs +961 -0
  13. package/cli/clone-deck.mjs +179 -0
  14. package/cli/commands.mjs +345 -0
  15. package/cli/comments.mjs +64 -18
  16. package/cli/commit-flow.mjs +44 -19
  17. package/cli/commit-message.mjs +51 -74
  18. package/cli/commit-split.mjs +601 -0
  19. package/cli/deck-refs.mjs +59 -0
  20. package/cli/deck-routes.mjs +67 -0
  21. package/cli/deckfile.mjs +3 -5
  22. package/cli/decklight.mjs +68 -289
  23. package/cli/design-system-deps.mjs +209 -0
  24. package/cli/design-system-edit.mjs +194 -0
  25. package/cli/design-system-refs.mjs +409 -0
  26. package/cli/design-system.mjs +429 -0
  27. package/cli/doctor.mjs +115 -0
  28. package/cli/edit-git.mjs +353 -0
  29. package/cli/edit-handover.mjs +445 -0
  30. package/cli/edit-look.mjs +388 -0
  31. package/cli/edit-slides.mjs +683 -0
  32. package/cli/edit.mjs +2126 -842
  33. package/cli/enhance.mjs +483 -0
  34. package/cli/extension.mjs +10 -10
  35. package/cli/font-refs.mjs +273 -0
  36. package/cli/font.mjs +246 -0
  37. package/cli/git-tree.mjs +1 -1
  38. package/cli/git.mjs +65 -11
  39. package/cli/import.mjs +56 -10
  40. package/cli/init.mjs +400 -234
  41. package/cli/library.mjs +127 -0
  42. package/cli/loader.mjs +3 -1
  43. package/cli/marketplace.mjs +215 -21
  44. package/cli/narrate.mjs +176 -0
  45. package/cli/open-browser.mjs +63 -0
  46. package/cli/open.mjs +943 -0
  47. package/cli/pdf.mjs +41 -13
  48. package/cli/pkg.mjs +44 -2
  49. package/cli/plugin.mjs +43 -41
  50. package/cli/port-conflict.mjs +53 -23
  51. package/cli/pptx-export.mjs +71 -26
  52. package/cli/publish.mjs +8 -4
  53. package/cli/qr.mjs +1 -1
  54. package/cli/record.mjs +14 -12
  55. package/cli/remote.mjs +11 -11
  56. package/cli/restore.mjs +11 -4
  57. package/cli/review-ref.mjs +125 -0
  58. package/cli/review-remote.mjs +92 -48
  59. package/cli/review-routes.mjs +254 -0
  60. package/cli/review-store.mjs +47 -7
  61. package/cli/review-submit.mjs +47 -57
  62. package/cli/runtime-link.mjs +560 -0
  63. package/cli/serve.mjs +235 -44
  64. package/cli/setup.mjs +112 -0
  65. package/cli/sign.mjs +1 -1
  66. package/cli/skill-content.mjs +190 -33
  67. package/cli/skills.mjs +107 -24
  68. package/cli/start.mjs +110 -0
  69. package/cli/supervise.mjs +6 -6
  70. package/cli/theme-refs.mjs +515 -0
  71. package/cli/theme.mjs +181 -137
  72. package/cli/trust.mjs +83 -0
  73. package/cli/units.mjs +39 -42
  74. package/cli/update-check.mjs +1 -5
  75. package/cli/upgrade.mjs +194 -28
  76. package/cli/upstream.mjs +4 -3
  77. package/cli/util.mjs +4 -4
  78. package/cli/wizard.mjs +6 -6
  79. package/dist/build-info.json +1 -1
  80. package/dist/decklight.css +1126 -49
  81. package/dist/decklight.js +212 -115
  82. package/dist/decklight.js.map +4 -4
  83. package/docs/GLOSSARY.md +141 -0
  84. package/docs/architecture.svg +17 -17
  85. package/package.json +4 -2
  86. package/themes/README.md +9 -8
  87. package/themes/reveal-solarized.css +10 -0
  88. package/tools/args.mjs +20 -0
  89. package/tools/atomic-write.mjs +48 -0
  90. package/tools/brand-palette.mjs +717 -0
  91. package/tools/bridge.mjs +1 -1
  92. package/tools/build-groups.mjs +42 -0
  93. package/tools/color.mjs +48 -0
  94. package/tools/deck-html.mjs +396 -11
  95. package/tools/design-system-format.mjs +753 -0
  96. package/tools/elevenlabs-tts.mjs +110 -17
  97. package/tools/exec.mjs +35 -2
  98. package/tools/extension-check.mjs +31 -7
  99. package/tools/font-format.mjs +190 -0
  100. package/tools/font-stacks.mjs +24 -0
  101. package/tools/gemini-tts.mjs +3 -0
  102. package/tools/lipsync-config.mjs +103 -0
  103. package/tools/lipsync-engines.mjs +205 -2
  104. package/tools/lipsync-server.mjs +264 -41
  105. package/tools/lipsync.mjs +37 -18
  106. package/tools/local-voice.mjs +32 -42
  107. package/tools/narration-manifest.mjs +196 -0
  108. package/tools/narration-synth.mjs +416 -0
  109. package/tools/pptx.mjs +776 -19
  110. package/tools/publish-targets.mjs +1 -1
  111. package/tools/publish-voices.mjs +3 -3
  112. package/tools/recording-impact.mjs +7 -3
  113. package/tools/render-theme.mjs +33 -0
  114. package/tools/review-anchor.mjs +28 -12
  115. package/tools/semver.mjs +40 -0
  116. package/tools/sentences.mjs +180 -0
  117. package/tools/shot.mjs +14 -7
  118. package/tools/site-voices.mjs +232 -0
  119. package/tools/template-theme.mjs +1 -1
  120. package/tools/test-impact.mjs +19 -10
  121. package/tools/theme-check.mjs +30 -3
  122. package/tools/tts-cache.mjs +4 -3
  123. package/tools/tts-engines.mjs +38 -20
  124. package/tools/tts-setup.mjs +7 -7
  125. package/tools/video-options.mjs +34 -0
  126. package/tools/video.mjs +461 -48
  127. package/tools/voiceover-server.mjs +185 -104
  128. package/tools/voiceover.mjs +119 -261
  129. package/tools/zip.mjs +1 -1
  130. package/cli/dev.mjs +0 -623
  131. package/cli/present.mjs +0 -853
  132. package/cli/review.mjs +0 -361
  133. package/tools/publish-site-voices.mjs +0 -75
package/cli/bundle.mjs CHANGED
@@ -16,10 +16,24 @@
16
16
  * - themes : the theme <link> is replaced by <style data-theme="name">
17
17
  * blocks (inactive ones carry media="not all"; the engine's
18
18
  * inline-theme mode toggles them — picker/?theme= work).
19
+ * Every theme the deck MARKS from a marketplace
20
+ * ("markedThemes") is inlined too, from this machine's
21
+ * copy of that marketplace (SPEC THEME_DISTRIBUTION).
19
22
  * - terminals : data-cast="url" casts are embedded and switched to
20
23
  * data-cast-inline (fetch is blocked on file://).
21
24
  * - images : <img src>, data-background-image and data-background-poster
22
25
  * → data: URIs (background VIDEOS stay external, with a notice).
26
+ * - design systems: every one the deck references ("designSystems") — its
27
+ * stylesheet with each relative url() as a data: URI, its
28
+ * meta and its layouts, the blocks every server injects
29
+ * (SPEC DESIGN_SYSTEMS), so layouts expand from file://.
30
+ * - audio : with --audio, every recorded narration file (a track's
31
+ * folder, a local manifest's files) as a data: URI the
32
+ * runtime plays in place of the path; `--audio aac|opus`
33
+ * re-encodes each small first. Off by default.
34
+ * - fonts : every font package the deck references ("fonts") — its
35
+ * faces as data: URIs in @font-face rules, and its meta
36
+ * (SPEC FONTS), so the type is the same from file://.
23
37
  *
24
38
  * MERGE mode (--all or several inputs): every module's <section>s are
25
39
  * concatenated into one deck, in order. Each module's first section gets
@@ -31,9 +45,15 @@
31
45
  import fs from 'node:fs';
32
46
  import path from 'node:path';
33
47
  import { makeFail, scriptSafe, runMain } from './util.mjs';
34
- import { inlineRuntime } from './pkg.mjs';
48
+ import { inlineRuntime, packageAsset, PKG, THEMES_DIR } from './pkg.mjs';
49
+ import { configBlock, configTheme, firstExecutableScript, hasEmbeddedRuntime, hasRuntime, linkRuntime } from './runtime-link.mjs';
50
+ import { addedThemeStyle, markedRefs, markedShipped, markedSources, resolveThemeRef, stillValid } from './theme-refs.mjs';
51
+ import { bundleDesignSystem, designSystemRefs, packageVerdict, resolveDesignSystemRef } from './design-system-refs.mjs';
52
+ import { bundleFont, fontRefs, fontVerdict, resolveFontRef } from './font-refs.mjs';
53
+ import { MarketplaceError } from './marketplace.mjs';
35
54
  import { escapeHtml } from '../tools/escape.mjs';
36
55
  import { isMain } from '../tools/args.mjs';
56
+ import { AUDIO_CHOICES, CODECS, estimateAudio, inlineAudio, narrationAudio, sizeLabel } from './bundle-audio.mjs';
37
57
  import { injectBeforeBodyEnd } from '../tools/deck-html.mjs';
38
58
 
39
59
  const fail = makeFail('bundle');
@@ -67,7 +87,7 @@ function containerBounds(html) {
67
87
  }
68
88
 
69
89
  /** Cut `const PLAYLIST = {…};` (brace-matched) and the `playlist: X` init
70
- * property out of a merged deck — cross-file navigation has no meaning
90
+ * property out of the deck being bundled — cross-file navigation has no meaning
71
91
  * inside one file; in-file data-module markers replace it. */
72
92
  function stripPlaylist(html) {
73
93
  const declM = html.match(/const\s+PLAYLIST\s*=\s*/);
@@ -185,13 +205,13 @@ function mergeDecks(jobs, baseDir, notices) {
185
205
  // ---------------------------------------------------------------- arguments
186
206
 
187
207
  /** `client` is the sigstore seam — see publishMain; omitted, the real one is used. */
188
- export async function bundleMain(argv = process.argv.slice(2), { client } = {}) {
208
+ export async function bundleMain(argv = process.argv.slice(2), { client, estimate = false } = {}) {
189
209
 
190
210
  if (!argv.length || argv.includes('--help') || argv.includes('-h')) {
191
211
  process.stdout.write(`decklight bundle — flatten deck(s) into one self-contained HTML file
192
212
 
193
213
  Usage:
194
- decklight bundle <deck.html> [-o out.html] [--sign] [--deck] [--themes current|all|…]
214
+ decklight bundle <deck.html> [-o out.html] [--audio [original|aac|opus]] [--sign] [--deck] [--themes current|all|…]
195
215
  decklight bundle <deck.html> --all [-o out.html] [--title "…"] [--themes …]
196
216
  decklight bundle <a.html> <b.html> … [-o out.html] [--title "…"] [--themes …]
197
217
 
@@ -212,26 +232,53 @@ Options:
212
232
  --sign, because the container is the signed artifact. A
213
233
  .decklight renamed to .html still plays in a browser: the
214
234
  deck comes first in the file and the metadata is appended.
215
- --title <t> <title> for a merged presentation
216
- --transform <name> run an installed build-time transform (decklight transform
217
- add <name>) on the deck's own source before anything else
235
+ --title <t> <title> for the multi-module deck
236
+ --transform <name> run an installed build-time transform (decklight library
237
+ add transform <name>) on the deck's own source before anything else
218
238
  is inlined — repeatable, applied in the order given
219
- --themes <sel> which themes to embed:
239
+ --themes <sel> which shipped themes to embed:
220
240
  current just the deck's linked theme (default)
221
241
  all every theme in the deck's themes/ directory
222
242
  name,name,… an explicit list (the deck's linked theme
223
243
  stays active when included, else the first)
244
+ every theme the deck MARKS ("markedThemes") is embedded as
245
+ well, whichever you choose
246
+ --theme <name> the theme the bundle opens on — a shipped theme (embedded
247
+ alongside the others) or one the deck marks
248
+ --audio [how] carry the narration's recorded audio inside the file, so
249
+ it plays from disk with nothing beside it:
250
+ original the files as recorded (the default)
251
+ aac mono AAC at 32 kbps, ~4 KB a second of
252
+ voice, plays in every browser
253
+ opus mono Opus at 24 kbps, ~3 KB a second,
254
+ the smallest (Safari from 17)
255
+ aac and opus need ffmpeg and cost some quality. Off by
256
+ default: a talk's audio is tens of MB, so it stays beside
257
+ the deck and the bundle names the folder to send with it
258
+ (--no-audio says so explicitly)
259
+ --allow-missing-design-systems
260
+ bundle even when a design system the deck uses cannot be
261
+ read on this machine: it is left out, and the slides that
262
+ name its layouts render plainly wherever the file opens
263
+ --allow-missing-fonts
264
+ bundle even when a font the deck references cannot be read
265
+ on this machine: it is left out, and the theme's own font
266
+ stack shows wherever the file opens
224
267
  `);
225
268
  return 0;
226
269
  }
227
270
 
228
271
  const inputs = [];
229
- let outPath = null, themesSel = 'current', all = false, mergedTitle = null, sign = false, deckFile = false;
272
+ let outPath = null, themesSel = 'current', all = false, mergedTitle = null, sign = false, deckFile = false, openOn = null;
273
+ let allowMissingSystems = false;
274
+ let allowMissingFonts = false;
275
+ let audioChoice = null;
230
276
  const transformNames = [];
231
277
  for (let i = 0; i < argv.length; i++) {
232
278
  const a = argv[i];
233
279
  if (a === '-o') outPath = argv[++i];
234
280
  else if (a === '--themes') themesSel = argv[++i];
281
+ else if (a === '--theme') openOn = argv[++i];
235
282
  else if (a === '--all') all = true;
236
283
  else if (a === '--transform') transformNames.push(argv[++i]);
237
284
  else if (a === '--sign') sign = true;
@@ -240,6 +287,11 @@ for (let i = 0; i < argv.length; i++) {
240
287
  // an attestation. Naming the implication beats refusing the obvious command.
241
288
  else if (a === '--deck') { deckFile = true; sign = true; }
242
289
  else if (a === '--title') mergedTitle = argv[++i];
290
+ else if (a === '--allow-missing-design-systems') allowMissingSystems = true;
291
+ else if (a === '--allow-missing-fonts') allowMissingFonts = true;
292
+ // `--audio` alone is the files as recorded; a codec after it re-encodes them
293
+ else if (a === '--audio') audioChoice = AUDIO_CHOICES.includes(argv[i + 1]) ? argv[++i] : 'original';
294
+ else if (a === '--no-audio') audioChoice = null;
243
295
  else if (!a.startsWith('-')) inputs.push(a);
244
296
  else fail(`unknown argument: ${a}`);
245
297
  }
@@ -284,10 +336,18 @@ if (jobs) {
284
336
  path.join(deckDir, path.basename(firstPath, '.html') + '-standalone.html'));
285
337
  }
286
338
 
339
+ // What went into the file and where each piece came from, said once at the end
340
+ // as two lines — the runtime and the themes — rather than a note per file.
341
+ const fromInstall = new Set(); // decklight.js / decklight.css read from the installed package
287
342
  const read = (rel) => {
288
343
  const p = path.resolve(deckDir, rel);
289
- if (!fs.existsSync(p)) fail(`referenced file not found: ${rel} (${p})`);
290
- return fs.readFileSync(p, 'utf8');
344
+ if (fs.existsSync(p)) return fs.readFileSync(p, 'utf8');
345
+ // A deck that LINKS the runtime ships no decklight.js beside itself: the
346
+ // servers answer it from the installed package, and so does this (#517) —
347
+ // what a bundle carries is what the deck was playing with.
348
+ const asset = packageAsset(rel);
349
+ if (asset) { fromInstall.add(path.basename(rel)); return fs.readFileSync(asset.file, 'utf8'); }
350
+ fail(`referenced file not found: ${rel} (${p})`);
291
351
  };
292
352
 
293
353
  // --------------------------------------------------------------- transforms
@@ -315,47 +375,223 @@ if (transformNames.length) {
315
375
 
316
376
  // ---------------------------------------------------------- theme selection
317
377
 
378
+ // The deck as the author wrote it, before anything is spliced in. The playlist
379
+ // check below reads THIS: the runtime's own source says `playlist:` too, and
380
+ // matching the inlined page flagged every deck that links the runtime.
381
+ const sourceHtml = html;
382
+
383
+ // A deck as data (#520) carries no runtime at all: the servers reference it
384
+ // on the way out, and so does this — the same references, added by the same
385
+ // function — after which it is the linked deck the sections below already
386
+ // know how to flatten. What a bundle embeds is what the deck was playing with.
387
+ const linked = !hasRuntime(html);
388
+ if (linked) {
389
+ html = linkRuntime(html);
390
+ // said in the summary: the source deck carries no runtime of its own
391
+ }
392
+
318
393
  const themeLinkRe = /<link\b[^>]*rel=["']stylesheet["'][^>]*href=["']([^"']*themes\/([\w-]+)\.css)["'][^>]*>/i;
319
394
  const themeLinkM = html.match(themeLinkRe);
320
- if (!themeLinkM) {
395
+ // An imported deck whose theme was derived from the file's own palette embeds
396
+ // that one theme and nothing else (DECK_IMPORT): it has no link to flatten and
397
+ // no runtime yet, and the theme it has is the theme it keeps. An ADDED theme
398
+ // (`data-theme-added`, what `theme add` pasted in before 0.9.0) is not the
399
+ // deck's own: it is an extra over the base theme, and taking it for the base
400
+ // bundled a deck whose only theme was somebody else's.
401
+ const OWN_THEME_STYLE = /<style\b(?![^>]*\bdata-theme-added\b)[^>]*\bdata-theme\b/i;
402
+ const ownTheme = !themeLinkM && linked && OWN_THEME_STYLE.test(html);
403
+ if (!themeLinkM && !ownTheme) {
321
404
  // A deck with its themes already INLINE is the common way to arrive here —
322
405
  // `decklight init` scaffolds one, and the README's own quick start goes
323
406
  // straight from init to bundle. Blaming a missing <link> sends that reader
324
407
  // looking for markup they were never supposed to have, when the honest
325
408
  // answer is that there is nothing left to flatten.
326
- const inlined = /<style\b[^>]*\bdata-theme\b/i.test(html);
409
+ const inlined = OWN_THEME_STYLE.test(html);
327
410
  fail(inlined
328
411
  ? 'this deck is already self-contained — its themes are inline <style data-theme> blocks.\n'
329
412
  + ' bundle is for a deck that REFERENCES dist/ and themes/ by URL; there is nothing here to flatten.\n'
330
413
  + ' to refresh its inlined runtime and themes instead: decklight upgrade <deck.html>'
331
414
  : 'no theme <link> (href matching themes/<name>.css) found in the deck');
332
415
  }
333
- const [themeLinkTag, themeHref, linkedTheme] = themeLinkM;
416
+ const [themeLinkTag, themeHref, linkedTheme] = themeLinkM ?? [null, 'themes/', null];
334
417
  const themesDir = path.resolve(deckDir, path.dirname(themeHref));
418
+ // A linked deck ships no themes/ beside itself: what it links is answered by
419
+ // the installed package when served, and inlined from there here (#517). A
420
+ // folder on disk wins, per theme and for the `all` listing alike.
421
+ const themeFile = (name) => {
422
+ const own = path.join(themesDir, `${name}.css`);
423
+ if (fs.existsSync(own)) return own;
424
+ const shipped = path.join(THEMES_DIR, `${name}.css`);
425
+ return fs.existsSync(shipped) ? shipped : null;
426
+ };
335
427
 
336
428
  let themeNames;
337
- if (themesSel === 'current') {
429
+ if (ownTheme) {
430
+ themeNames = [html.match(/<style\b(?![^>]*\bdata-theme-added\b)[^>]*\bdata-theme\s*=\s*["']([\w-]+)["']/i)?.[1] ?? 'own'];
431
+ if (themesSel !== 'all' && themesSel !== 'current') notices.push('--themes ignored: the deck embeds a theme of its own, and that is the one it keeps');
432
+ } else if (themesSel === 'current') {
338
433
  themeNames = [linkedTheme];
339
434
  } else if (themesSel === 'all') {
340
- themeNames = fs.readdirSync(themesDir).filter((f) => f.endsWith('.css'))
435
+ themeNames = fs.readdirSync(fs.existsSync(themesDir) ? themesDir : THEMES_DIR).filter((f) => f.endsWith('.css'))
341
436
  .map((f) => f.replace(/\.css$/, '')).sort();
342
437
  } else {
343
438
  themeNames = themesSel.split(',').map((s) => s.trim()).filter(Boolean);
344
439
  }
440
+ // The themes the deck MARKS travel with it: resolved from this machine's
441
+ // marketplaces now, inlined below, and never linked — a reference to a
442
+ // marketplace means nothing to whoever opens the file (SPEC THEME_DISTRIBUTION).
443
+ // A marked name is not a file in themes/, so it leaves the shipped list here.
444
+ const markedFrom = markedSources(sourceHtml);
445
+ const marked = markedRefs(sourceHtml).map((r) => {
446
+ const hit = resolveThemeRef(r, undefined, { source: markedFrom[r.marketplace] ?? null });
447
+ if (!hit.file) fail(`the deck marks ${r.ref}, and this machine cannot read it — ${hit.missing}`);
448
+ const valid = stillValid(hit.file);
449
+ if (!valid.ok) fail(`the deck marks ${r.ref}, and ${valid.why}`);
450
+ return hit;
451
+ });
452
+ const markedNames = marked.map((r) => r.name);
453
+ // Design systems (SPEC DESIGN_SYSTEMS) travel like marked themes: resolved
454
+ // from this machine's checkouts now, carried as bytes, never linked. Merged,
455
+ // every module's count — once per name and version; one name at two
456
+ // versions has no single right answer, so it is refused.
457
+ const systems = []; // { ref, name, version, marketplace, block }
458
+ const systemsLeftOut = []; // { ref, why }
459
+ {
460
+ const decks = jobs
461
+ ? jobs.map((j) => ({ label: j.title, html: fs.readFileSync(j.path, 'utf8') }))
462
+ : [{ label: path.basename(firstPath), html: sourceHtml }];
463
+ const byName = new Map();
464
+ for (const d of decks) {
465
+ const from = markedSources(d.html);
466
+ for (const ref of designSystemRefs(d.html)) {
467
+ const r = resolveDesignSystemRef(ref, undefined, { source: from[ref.marketplace] ?? null });
468
+ const verdict = r.dir ? packageVerdict(r.dir) : null;
469
+ // a package that is HERE but broken is its author's bug, never papered over
470
+ if (verdict && !verdict.ok) fail(`the deck uses the design system ${ref.ref}, and ${verdict.why}`);
471
+ const why = r.missing;
472
+ if (why) {
473
+ if (!allowMissingSystems) {
474
+ fail(`the deck uses the design system ${ref.ref}, and this machine cannot read it — ${why}
475
+ `
476
+ + ' (--allow-missing-design-systems bundles without it: its slides render plainly)');
477
+ }
478
+ if (!systemsLeftOut.some((x) => x.ref === ref.ref)) systemsLeftOut.push({ ref: ref.ref, why });
479
+ continue;
480
+ }
481
+ const version = String(verdict.manifest.version ?? '');
482
+ const seen = byName.get(ref.name);
483
+ if (seen) {
484
+ if (seen.version !== version) {
485
+ fail(`two modules use the design system "${ref.name}" at different versions — ${seen.label} has ${seen.version}, ${d.label} has ${version}; one file can carry one`);
486
+ }
487
+ continue;
488
+ }
489
+ let block;
490
+ try { block = bundleDesignSystem(r, verdict); } catch (e) {
491
+ if (e instanceof MarketplaceError) fail(`the design system ${ref.ref}: ${e.message}`);
492
+ throw e;
493
+ }
494
+ byName.set(ref.name, { version, label: d.label });
495
+ systems.push({ ref: ref.ref, name: ref.name, version, marketplace: ref.marketplace, block });
496
+ for (const url of block.external) notices.push(`design system ${ref.ref}: url(${url}) stays external — it will not show offline`);
497
+ }
498
+ }
499
+ for (const x of systemsLeftOut) notices.push(`design system ${x.ref} not carried — ${x.why}; the slides that use it render plainly`);
500
+ }
501
+
502
+ // Fonts (SPEC FONTS) the same way: resolved from the checkouts, carried as
503
+ // bytes, once per name; a font here but broken is refused whatever the flag.
504
+ const fonts = []; // { ref, name, version, marketplace, block }
505
+ const fontsLeftOut = []; // { ref, why }
506
+ {
507
+ const decks = jobs
508
+ ? jobs.map((j) => ({ label: j.title, html: fs.readFileSync(j.path, 'utf8') }))
509
+ : [{ label: path.basename(firstPath), html: sourceHtml }];
510
+ const byName = new Map();
511
+ for (const d of decks) {
512
+ const from = markedSources(d.html);
513
+ for (const ref of fontRefs(d.html)) {
514
+ const r = resolveFontRef(ref, undefined, { source: from[ref.marketplace] ?? null });
515
+ const verdict = r.dir ? fontVerdict(r.dir) : null;
516
+ if (verdict && !verdict.ok) fail(`the deck uses the font ${ref.ref}, and ${verdict.why}`);
517
+ if (r.missing) {
518
+ if (!allowMissingFonts) {
519
+ fail(`the deck uses the font ${ref.ref}, and this machine cannot read it — ${r.missing}\n`
520
+ + ' (--allow-missing-fonts bundles without it: the theme\'s own font stack shows instead)');
521
+ }
522
+ if (!fontsLeftOut.some((x) => x.ref === ref.ref)) fontsLeftOut.push({ ref: ref.ref, why: r.missing });
523
+ continue;
524
+ }
525
+ const version = String(verdict.manifest.version ?? '');
526
+ const seen = byName.get(ref.name);
527
+ if (seen) {
528
+ if (seen.version !== version) fail(`two modules use the font "${ref.name}" at different versions — ${seen.label} has ${seen.version}, ${d.label} has ${version}; one file can carry one`);
529
+ continue;
530
+ }
531
+ byName.set(ref.name, { version, label: d.label });
532
+ fonts.push({ ref: ref.ref, name: ref.name, version, marketplace: ref.marketplace, family: verdict.manifest.family, block: bundleFont(r, verdict) });
533
+ }
534
+ }
535
+ for (const x of fontsLeftOut) notices.push(`font ${x.ref} not carried — ${x.why}; the theme's own font stack shows instead`);
536
+ }
537
+ if (openOn !== null && !/^[\w-]+$/.test(openOn)) fail(`--theme ${JSON.stringify(openOn)} is not a theme name`);
538
+ // a design system's own themes (SPEC BRAND_PALETTE) come in its blocks, like a marked theme's
539
+ const brandNames = systems.flatMap((s) => s.block.brandThemes ?? []);
540
+ const carried = (n) => markedNames.includes(n) || brandNames.includes(n);
541
+ if (openOn && !ownTheme && !carried(openOn) && !themeNames.includes(openOn)) themeNames.push(openOn);
542
+ themeNames = themeNames.filter((n) => !carried(n));
543
+ // A marked SHIPPED theme travels too: embedded beside the one the file opens
544
+ // on, whatever --themes chose, because marking it is how the author said so.
545
+ const markedShippedNames = markedShipped(sourceHtml).filter((n) => !themeNames.includes(n));
546
+ if (!ownTheme) themeNames.push(...markedShippedNames);
345
547
  if (!themeNames.length) fail('no themes selected');
346
- const activeTheme = themeNames.includes(linkedTheme) ? linkedTheme : themeNames[0];
347
- if (activeTheme !== linkedTheme) {
548
+ const activeTheme = openOn && themeNames.includes(openOn) ? openOn
549
+ : themeNames.includes(linkedTheme) ? linkedTheme : themeNames[0];
550
+ if (!ownTheme && activeTheme !== linkedTheme && !openOn) {
348
551
  notices.push(`linked theme "${linkedTheme}" not in --themes list; "${activeTheme}" is active`);
349
552
  }
350
553
 
351
- const themeBlocks = themeNames.map((name) => {
352
- const cssPath = path.join(themesDir, name + '.css');
353
- if (!fs.existsSync(cssPath)) fail(`theme not found: ${name} (${cssPath})`);
554
+ const ownThemeFiles = new Set(); // themes read from a themes/ folder beside the deck
555
+ const themeBlocks = ownTheme ? null : themeNames.map((name) => {
556
+ const cssPath = themeFile(name);
557
+ if (!cssPath) fail(`theme not found: ${name} (${path.join(themesDir, `${name}.css`)}, and not shipped)`);
558
+ if (cssPath.startsWith(themesDir)) ownThemeFiles.add(name);
354
559
  const css = fs.readFileSync(cssPath, 'utf8');
355
560
  const media = name === activeTheme ? '' : ' media="not all"';
356
561
  return `<style data-theme="${name}"${media}>\n${css}\n</style>`;
357
562
  }).join('\n');
358
- html = html.replace(themeLinkTag, themeBlocks);
563
+ if (themeBlocks !== null) html = html.replace(themeLinkTag, themeBlocks);
564
+ // A deck that keeps a theme of its own (DECK_IMPORT) carries marked shipped
565
+ // themes as further inline blocks, off until picked.
566
+ if (ownTheme && markedShippedNames.length) {
567
+ const extra = markedShippedNames.map((name) => {
568
+ const cssPath = themeFile(name);
569
+ if (!cssPath) fail(`theme not found: ${name}`);
570
+ return `<style data-theme="${name}" media="not all">\n${fs.readFileSync(cssPath, 'utf8')}\n</style>`;
571
+ }).join('\n');
572
+ const headEnd = html.search(/<\/head>/i);
573
+ html = headEnd === -1 ? `${extra}\n${html}` : `${html.slice(0, headEnd)}${extra}\n${html.slice(headEnd)}`;
574
+ }
575
+ if (marked.length) {
576
+ const blocks = marked.map((r) => addedThemeStyle(r, fs.readFileSync(r.file, 'utf8'))).join('\n');
577
+ const headEnd = html.search(/<\/head>/i);
578
+ html = headEnd === -1 ? `${blocks}\n${html}` : `${html.slice(0, headEnd)}${blocks}\n${html.slice(headEnd)}`;
579
+ }
580
+ // The theme the bundle opens on is the configured one, and the runtime reads
581
+ // it from the configuration block — so `--theme` is written THERE, which is
582
+ // what makes a marked theme (an added block, not an inline one) the one a
583
+ // double-clicked file opens on.
584
+ if (openOn) {
585
+ const block = configBlock(html);
586
+ if (block?.config) {
587
+ const inner = /"theme"\s*:\s*"[^"]*"/.test(block.inner)
588
+ ? block.inner.replace(/"theme"\s*:\s*"[^"]*"/, `"theme": ${JSON.stringify(openOn)}`)
589
+ : block.inner.replace('{', `{ "theme": ${JSON.stringify(openOn)},`);
590
+ html = html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd);
591
+ } else if (carried(openOn)) {
592
+ fail(`--theme ${openOn}: the deck has no configuration block to open it from`);
593
+ }
594
+ }
359
595
 
360
596
  // ------------------------------------------------- structure stylesheet(s)
361
597
 
@@ -409,10 +645,14 @@ html = html.replace(
409
645
  // ------------------------------------------------------------ runtime script
410
646
 
411
647
  html = html.replace(
412
- /<script\b[^>]*src=["']([^"']+)["'][^>]*>\s*<\/script>/gi,
413
- (tag, src) => {
648
+ /<script\b([^>]*)src=["']([^"']+)["']([^>]*)>\s*<\/script>/gi,
649
+ (tag, pre, src, post) => {
414
650
  if (/^(https?:)?\/\//.test(src)) { notices.push(`external script kept as src: ${src}`); return tag; }
415
- return `<script>\n${inlineRuntime(read(src))}\n</script>`;
651
+ // the runtime's marker rides along (#520): a bundle that boots from its
652
+ // configuration block has no init call for the audit and upgrade to
653
+ // locate the engine by, so the mark is how they find it
654
+ const marked = /\bdata-decklight-runtime\s*=\s*["']js["']/i.test(pre + post) ? ' data-decklight-runtime="js"' : '';
655
+ return `<script${marked}>\n${inlineRuntime(read(src))}\n</script>`;
416
656
  });
417
657
 
418
658
  // ------------------------------------------------------------------- casts
@@ -439,8 +679,9 @@ html = html.replace(
439
679
  // 50–150 MB), same posture as playlist links.
440
680
  {
441
681
  const seen = new Set();
682
+ // `dir: 'voices'` in a boot call, `"dir": "voices"` in a configuration block
442
683
  const narrDirs = [...new Set(
443
- [...html.matchAll(/\b(?:dir|files)\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))];
684
+ [...html.matchAll(/\b(?:dir|files)["']?\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))];
444
685
  for (const d of narrDirs) {
445
686
  const abs = path.resolve(deckDir, d);
446
687
  if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) continue;
@@ -470,7 +711,7 @@ html = html.replace(
470
711
  if (seen.size) {
471
712
  const beats = [...seen].filter((k) => /^slide-\d+-\d+$/.test(k)).length;
472
713
  notices.push(`character visemes: inlined ${seen.size} timeline(s)`
473
- + (beats ? ` (${seen.size - beats} slides + ${beats} ⟨CLICK⟩ beats)` : ''));
714
+ + (beats ? ` (${seen.size - beats} slides + ${beats} [click] beats)` : ''));
474
715
  }
475
716
  }
476
717
 
@@ -484,8 +725,9 @@ html = html.replace(
484
725
  // the manifest, and inlining it would undo the feature.
485
726
  {
486
727
  let n = 0;
728
+ // `manifest: '…'` in a boot call, `"manifest": "…"` in a configuration block
487
729
  const manifests = [...new Set(
488
- [...html.matchAll(/\bmanifest\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))];
730
+ [...html.matchAll(/\bmanifest["']?\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))];
489
731
  for (const rel of manifests) {
490
732
  const abs = path.resolve(deckDir, rel);
491
733
  if (!fs.existsSync(abs) || !fs.statSync(abs).isFile()) {
@@ -499,6 +741,60 @@ html = html.replace(
499
741
  if (n) notices.push(`narration: inlined ${n} voice manifest(s) — the audio stays in its bucket`);
500
742
  }
501
743
 
744
+ // ------------------------------------------------------ narration audio
745
+
746
+ // A recorded track's audio is the one part of a deck too big to carry by
747
+ // default: a slide's clip is half a megabyte to a few, a talk's worth tens,
748
+ // and base64 adds a third. So it stays beside the deck unless asked for:
749
+ // `--audio` carries it inside as recorded, `--audio aac` / `--audio opus`
750
+ // re-encoded small (cli/bundle-audio.mjs). Either way the bundle says which
751
+ // files it left out or took in.
752
+ let audioEstimate = null;
753
+ {
754
+ const { found, remote, folders } = narrationAudio(html, deckDir);
755
+ if (estimate) {
756
+ if (found.size) audioEstimate = { ...(await estimateAudio(found)), folders };
757
+ } else if (found.size && audioChoice) {
758
+ let carried;
759
+ try { carried = await inlineAudio(found, audioChoice); } catch (e) { fail(e.message); }
760
+ embeds.push(...carried.blocks);
761
+ notices.push(`narration audio: inlined ${found.size} file(s), ${sizeLabel(carried.bytes)}`
762
+ + `${CODECS[audioChoice] ? ` (re-encoded from ${sizeLabel(carried.before)}, ${CODECS[audioChoice].label})` : ''}, from ${folders}`);
763
+ } else if (found.size) {
764
+ notices.push(`narration audio: ${found.size} file(s) stay beside the deck, in ${folders} — ship them next to the bundle, or bundle with --audio [original|aac|opus] to carry them inside`);
765
+ }
766
+ if (remote && audioChoice) notices.push(`narration audio: ${remote} manifest file(s) live at a URL and stay there`);
767
+ }
768
+
769
+ // -------------------------------------------------------- design systems
770
+
771
+ // The stylesheets where every server links them — the end of <head>, after
772
+ // the themes, so the cascade is the one the author saw — and the meta and
773
+ // layouts before the runtime too: classic scripts execute mid-parse, so they
774
+ // must be in the document when the engine looks for them.
775
+ if (systems.length) {
776
+ const at = (withScript) => {
777
+ const masked = html.replace(/<!--[\s\S]*?-->/g, (m) => ' '.repeat(m.length));
778
+ const marks = [masked.search(/<\/head>/i), withScript ? firstExecutableScript(html) ?? -1 : -1].filter((i) => i !== -1);
779
+ return marks.length ? Math.min(...marks) : 0;
780
+ };
781
+ const insert = (i, tags) => { html = `${html.slice(0, i)}${tags.join('\n')}\n${html.slice(i)}`; };
782
+ insert(at(true), systems.flatMap((x) => x.block.tags.slice(1)));
783
+ insert(at(false), systems.map((x) => x.block.tags[0]));
784
+ }
785
+ // The fonts the same way: their @font-face at the end of <head>, where the
786
+ // servers link them, their meta before the runtime reads it.
787
+ if (fonts.length) {
788
+ const at = (withScript) => {
789
+ const masked = html.replace(/<!--[\s\S]*?-->/g, (m) => ' '.repeat(m.length));
790
+ const marks = [masked.search(/<\/head>/i), withScript ? firstExecutableScript(html) ?? -1 : -1].filter((i) => i !== -1);
791
+ return marks.length ? Math.min(...marks) : 0;
792
+ };
793
+ const insert = (i, tags) => { html = `${html.slice(0, i)}${tags.join('\n')}\n${html.slice(i)}`; };
794
+ insert(at(true), fonts.map((x) => x.block.tags[1]));
795
+ insert(at(false), fonts.map((x) => x.block.tags[0]));
796
+ }
797
+
502
798
  // -------------------------------------------------------------- assemble
503
799
 
504
800
  if (embeds.length) {
@@ -508,9 +804,9 @@ if (embeds.length) {
508
804
  }
509
805
 
510
806
  if (!jobs) {
511
- const playlistM = html.match(/playlist\s*:/);
807
+ const playlistM = sourceHtml.match(/playlist\s*:/);
512
808
  if (playlistM) {
513
- const hrefs = [...html.matchAll(/href:\s*['"]([^'"]+\.html)['"]/g)].map((m) => m[1]);
809
+ const hrefs = [...sourceHtml.matchAll(/href:\s*['"]([^'"]+\.html)['"]/g)].map((m) => m[1]);
514
810
  notices.push('deck has a playlist — cross-file module links cannot resolve inside a single file:' +
515
811
  (hrefs.length ? '\n ' + [...new Set(hrefs)].join('\n ') : ''));
516
812
  }
@@ -520,6 +816,10 @@ if (!jobs) {
520
816
  // (INTEGRITY#SIGNING): a failed signature must leave no artifact behind, or
521
817
  // the unsigned file sitting there afterwards gets picked up later and sent as
522
818
  // though it were finished. Bytes, not a path, for exactly this reason.
819
+ // An estimate (the edit server's bundle card) stops here: the file as it
820
+ // would be without its audio, and what each way of carrying the audio adds.
821
+ if (estimate) return { base: Buffer.byteLength(html, 'utf8'), audio: audioEstimate };
822
+
523
823
  let bundleSig = null;
524
824
  if (sign) {
525
825
  const { signBytes } = await import('./sign.mjs');
@@ -531,7 +831,59 @@ if (sign) {
531
831
  fs.writeFileSync(outPath, html);
532
832
  const kb = (fs.statSync(outPath).size / 1024).toFixed(1);
533
833
  const what = jobs ? `${jobs.length} modules` : path.basename(firstPath);
534
- process.stdout.write(`bundled ${what} → ${outPath} (${kb} KB, themes: ${themeNames.join(', ')}; active: ${activeTheme})\n`);
834
+ process.stdout.write(`bundled ${what} → ${outPath} (${kb} KB)\n`);
835
+ // The runtime: where the copy in the file came from. A deck that is data (#520)
836
+ // carries none — which reads like a warning unless it says it is the SOURCE deck
837
+ // that carried none, and the file that has one.
838
+ const runtimeFrom = linked ? 'embedded from this install (the source deck carries no runtime)'
839
+ : fromInstall.has('decklight.js') ? 'embedded from this install (the source deck links it)'
840
+ : "embedded from the source deck's own copy";
841
+ process.stdout.write(` runtime decklight ${PKG.version} — ${runtimeFrom}\n`);
842
+ // The themes: the one it opens on, the others it can switch to, and why each
843
+ // is there — marked, or asked for with --themes — and where one came from when
844
+ // it was not this install (a themes/ folder beside the deck, a marketplace).
845
+ {
846
+ // a brand theme opens on top of the base, which is then the one embedded as active
847
+ const opening = (openOn && !brandNames.includes(openOn) ? openOn : null) ?? (ownTheme ? themeNames[0] : activeTheme);
848
+ const tagged = (n, ...why) => {
849
+ const bits = [...why, ownThemeFiles.has(n) ? 'own file' : null].filter(Boolean);
850
+ return bits.length ? `${n} (${bits.join(', ')})` : n;
851
+ };
852
+ const parts = [tagged(opening, 'opens on', ownTheme ? 'its own' : null)];
853
+ const chosen = themeNames.filter((n) => n !== opening && !markedShippedNames.includes(n));
854
+ if (chosen.length) parts.push(chosen.map((n) => tagged(n)).join(', '));
855
+ const shippedMarked = markedShippedNames.filter((n) => n !== opening);
856
+ if (shippedMarked.length) parts.push(`${shippedMarked.join(', ')} (marked)`);
857
+ const byMarket = new Map();
858
+ for (const r of marked) {
859
+ const m = r.ref.split('@')[1];
860
+ byMarket.set(m, [...(byMarket.get(m) ?? []), r.name]);
861
+ }
862
+ for (const [m, names] of byMarket) parts.push(`${names.join(', ')} (marked, from ${m})`);
863
+ // the design systems' own themes, and the one it opens on when that is one of them
864
+ const opensBrand = [openOn, configTheme(html)].find((n) => n && brandNames.includes(n));
865
+ if (opensBrand) parts[0] = tagged(opening, 'under it');
866
+ for (const s of systems) {
867
+ const names = s.block.brandThemes ?? [];
868
+ if (names.length) parts.push(`${names.map((n) => (n === opensBrand ? `${n} (opens on)` : n)).join(', ')} (${s.name}'s own)`);
869
+ }
870
+ process.stdout.write(` themes ${parts.join(' · ')}\n`);
871
+ }
872
+ // The design systems: name, version, the catalog it came from, what went in.
873
+ if (systems.length || systemsLeftOut.length) {
874
+ const parts = systems.map(({ name, version, marketplace, block }) => {
875
+ const assets = block.assets ? `, ${block.assets} asset${block.assets === 1 ? '' : 's'} (${(block.bytes / 1024).toFixed(1)} KB)` : '';
876
+ return `${name} ${version} (from ${marketplace}) — stylesheet${assets}, ${block.templates} template${block.templates === 1 ? '' : 's'}`;
877
+ });
878
+ for (const x of systemsLeftOut) parts.push(`${x.ref} — not carried`);
879
+ process.stdout.write(` designs ${parts.join(' · ')}\n`);
880
+ }
881
+ if (fonts.length || fontsLeftOut.length) {
882
+ const parts = fonts.map(({ name, version, marketplace, family, block }) =>
883
+ `${name} ${version} (from ${marketplace}) — '${family}', ${block.faces} face${block.faces === 1 ? '' : 's'} (${(block.bytes / 1024).toFixed(1)} KB)`);
884
+ for (const x of fontsLeftOut) parts.push(`${x.ref} — not carried`);
885
+ process.stdout.write(` fonts ${parts.join(' · ')}\n`);
886
+ }
535
887
  if (bundleSig) {
536
888
  const { writeSidecar, verifyBytes, formatSignature } = await import('./sign.mjs');
537
889
  const sidecar = writeSidecar(outPath, bundleSig);
package/cli/cast.mjs CHANGED
@@ -6,7 +6,7 @@
6
6
  * decklight-cast — record truthful terminal casts for Decklight decks (SPEC RECORDER_CLI/CAST_FORMAT).
7
7
  *
8
8
  * decklight cast <script.term.yaml> [-o out.cast.json] [--allow-fail] [--quiet]
9
- * decklight refresh <dir | cast.json…> [--allow-fail]
9
+ * decklight cast refresh <dir | cast.json…> [--allow-fail]
10
10
  *
11
11
  * This briefly shipped as `decklight rec`, a name dropped without an alias or
12
12
  * a refusal stub: `rec` reads as an abbreviation of `record`, and `decklight
@@ -457,12 +457,12 @@ async function refresh(targets, { allowFail }) {
457
457
  // --------------------------------------------------------------------- main
458
458
 
459
459
  const HELP = `decklight cast — record terminal casts for Decklight decks
460
- (recording your VOICE narrating a deck is a different command: decklight record)
460
+ (recording your VOICE narrating a deck is a different command: decklight narrate --mic)
461
461
 
462
462
  Usage:
463
463
  decklight cast <script.term.yaml> [-o out.cast.json] [--allow-fail] [--quiet]
464
- decklight refresh <dir | cast.json…> [--allow-fail]
465
- decklight export <cast.json> [-o out.cast] # asciicast v2
464
+ decklight cast refresh <dir | cast.json…> [--allow-fail]
465
+ decklight cast export <cast.json> [-o out.cast] # asciicast v2
466
466
 
467
467
  Script format (YAML):
468
468
  shell: zsh # default: $SHELL (rc files are skipped: zsh -f / bash --norc)
@@ -496,9 +496,9 @@ Notes:
496
496
  that step's output and are stored as ▓▓▓ in the cast's input record. Prefer the
497
497
  $ENV form — a literal secret is scrubbed from the embedded script, which makes
498
498
  that cast non-refreshable.
499
- • --refresh re-executes the script embedded in each cast and rewrites on drift.
500
- • export writes asciicast v2 for the asciinema ecosystem — e.g. a GIF for docs:
501
- decklight export demo.cast.json && agg demo.cast demo.gif
499
+ • cast refresh re-executes the script embedded in each cast and rewrites on drift.
500
+ • cast export writes asciicast v2 for the asciinema ecosystem — e.g. a GIF for docs:
501
+ decklight cast export demo.cast.json && agg demo.cast demo.gif
502
502
  `;
503
503
 
504
504
  export async function castMain(argv = process.argv.slice(2)) {