decklight 0.8.1 → 0.10.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.
- package/PLATFORM.md +707 -0
- package/README.md +226 -150
- package/SPEC.md +803 -888
- package/cli/agent-review.mjs +246 -0
- package/cli/agents.mjs +35 -9
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +190 -0
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +439 -35
- package/cli/cast.mjs +48 -12
- package/cli/check-fixes.mjs +186 -0
- package/cli/check.mjs +988 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +51 -22
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +64 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +666 -0
- package/cli/design-system.mjs +497 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +551 -0
- package/cli/edit-look.mjs +631 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2585 -855
- package/cli/enhance.mjs +485 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +78 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +407 -236
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +460 -29
- package/cli/narrate.mjs +251 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +961 -0
- package/cli/pdf.mjs +64 -17
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +63 -27
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +85 -23
- package/cli/remote.mjs +43 -17
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +236 -45
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +229 -35
- package/cli/skills.mjs +353 -26
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +527 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +112 -47
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1533 -59
- package/dist/decklight.js +258 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +778 -0
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +11 -3
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +270 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-clip.mjs +114 -0
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +530 -54
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- package/tools/publish-site-voices.mjs +0 -75
package/cli/banner.mjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* One banner for `decklight
|
|
5
|
+
* One banner for `decklight <deck>`, and the deck's URL is the last thing on it.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* the edit server runs its servers as child processes and used to let each one print its
|
|
8
8
|
* own startup lines through a pipe that did nothing but prefix them. That gave
|
|
9
9
|
* two problems no amount of rewording fixes:
|
|
10
10
|
*
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* together were a wall, because no single place could see them all and
|
|
18
18
|
* decide what mattered.
|
|
19
19
|
*
|
|
20
|
-
* So
|
|
20
|
+
* So `open` prints the banner and the children stop printing startup lines —
|
|
21
21
|
* they hand author a FACT instead, on the same pipe, behind a sentinel
|
|
22
|
-
* (`readyLine`). Only
|
|
22
|
+
* (`readyLine`). Only in write mode: with no `DECKLIGHT_BANNER` in the
|
|
23
23
|
* environment every child prints exactly what it printed before, which is what
|
|
24
24
|
* `decklight edit` and `decklight tts` run on their own still do.
|
|
25
25
|
*
|
|
@@ -54,17 +54,41 @@ export function parseReady(line) {
|
|
|
54
54
|
* The order rows appear in, whatever order the processes woke up in — which is
|
|
55
55
|
* the entire point of collecting them all before printing any.
|
|
56
56
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* The facts come first. Then the rows that are a THING TO DO rather than a
|
|
58
|
+
* thing that is merely true, `runtime` and `skill` (each ends in the command
|
|
59
|
+
* that fixes it), then `reviews`, which sits closest to the URL. `runtime` and
|
|
60
|
+
* `skill` used to be missing here, so they kept their arrival position after
|
|
61
|
+
* every known row and landed below `reviews`.
|
|
59
62
|
*/
|
|
60
|
-
export const ROW_ORDER = ['voice', 'lips', 'skipped', 'git', 'agents', 'reviews'];
|
|
63
|
+
export const ROW_ORDER = ['port', 'voice', 'lips', 'skipped', 'git', 'agents', 'plugins', 'runtime', 'skill', 'reviews'];
|
|
61
64
|
|
|
62
|
-
const ESC = { dim: '\x1b[2m', bold: '\x1b[1m', cyan: '\x1b[36m', under: '\x1b[4m', reset: '\x1b[0m' };
|
|
65
|
+
const ESC = { dim: '\x1b[2m', bold: '\x1b[1m', cyan: '\x1b[36m', green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m', under: '\x1b[4m', reset: '\x1b[0m' };
|
|
63
66
|
|
|
64
67
|
/**
|
|
65
|
-
* The
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
+
* The mark in front of a row: ✓ for something installed and on, ! for
|
|
69
|
+
* something to fix, ✗ for something that failed and is not running, nothing
|
|
70
|
+
* for a plain fact. A fact says which with `mark`.
|
|
71
|
+
*/
|
|
72
|
+
export function rowMark(mark, color = false) {
|
|
73
|
+
const c = (s, k) => (color ? ESC[k] + s + ESC.reset : s);
|
|
74
|
+
if (mark === 'ok') return c('\u2713', 'green');
|
|
75
|
+
if (mark === 'warn') return c('!', 'yellow');
|
|
76
|
+
if (mark === 'fail') return c('\u2717', 'red');
|
|
77
|
+
return ' ';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One row, as `renderBanner` prints it and as a late fact is printed after it. */
|
|
81
|
+
export function bannerRow({ key, text, mark }, { width = key.length, color = false } = {}) {
|
|
82
|
+
const k = color ? ESC.dim + key.padEnd(width) + ESC.reset : key.padEnd(width);
|
|
83
|
+
return ` ${rowMark(mark, color)} ${k} ${text}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The banner, as lines. `rows` is `[{ key, text, mark }]` in any order; a key
|
|
88
|
+
* not in ROW_ORDER keeps its arrival position after the known ones, so a
|
|
89
|
+
* service added later still appears without anyone having to remember to edit
|
|
90
|
+
* that list. `deck` is a header line, given only when debugging: the version
|
|
91
|
+
* line above the banner and the URL below it already name what is running.
|
|
68
92
|
*/
|
|
69
93
|
export function renderBanner({ deck, url, keys, rows = [], color = false } = {}) {
|
|
70
94
|
const c = (s, ...codes) => (color ? codes.map((k) => ESC[k]).join('') + s + ESC.reset : s);
|
|
@@ -74,11 +98,11 @@ export function renderBanner({ deck, url, keys, rows = [], color = false } = {})
|
|
|
74
98
|
.map((r, i) => ({ ...r, i }))
|
|
75
99
|
.sort((a, b) => rank(a.key) - rank(b.key) || a.i - b.i);
|
|
76
100
|
|
|
77
|
-
const out =
|
|
101
|
+
const out = deck ? [`decklight ${c('·', 'dim')} ${deck}`] : [];
|
|
78
102
|
if (shown.length) {
|
|
79
|
-
out.push('');
|
|
80
|
-
const
|
|
81
|
-
for (const r of shown) out.push(
|
|
103
|
+
if (out.length) out.push('');
|
|
104
|
+
const width = Math.max(...shown.map((r) => r.key.length));
|
|
105
|
+
for (const r of shown) out.push(bannerRow(r, { width, color }));
|
|
82
106
|
}
|
|
83
107
|
// The URL last, and the only coloured thing here, because a person scanning
|
|
84
108
|
// this is looking for exactly one thing and it is this.
|
|
@@ -110,13 +134,13 @@ export function nextFlushDelay({ waiting = 0, elapsed = 0, cap = 5000, grace = 3
|
|
|
110
134
|
* How anything WATCHING author's output finds the deck's url.
|
|
111
135
|
*
|
|
112
136
|
* Exported because six harnesses each carried their own copy of the old
|
|
113
|
-
* `decklight
|
|
137
|
+
* `decklight · <deck> on http://…`, and the day that line changed shape all six
|
|
114
138
|
* timed out for the same reason in six different files. A banner is a thing
|
|
115
139
|
* people read, so its wording will change again; this is the part that is a
|
|
116
140
|
* contract, and it lives next to the code that prints it.
|
|
117
141
|
*
|
|
118
142
|
* Group 1 is the port. Tolerant of the colour codes a terminal gets and a pipe
|
|
119
|
-
* does not, so it matches whichever way
|
|
143
|
+
* does not, so it matches whichever way `open` was run — and the escapes and
|
|
120
144
|
* the space INTERLEAVE: the reset that closes the ▸ lands between the arrow
|
|
121
145
|
* and the space before the url. A pattern that expected the whitespace first
|
|
122
146
|
* matched every piped harness and none of the ones driven through a pty,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The narration's recorded audio in a bundle (SPEC DECK_ANATOMY): which files a
|
|
5
|
+
// deck's tracks play, how big each way of carrying them would make the file,
|
|
6
|
+
// and the blocks that carry them.
|
|
7
|
+
//
|
|
8
|
+
// Three ways, and leaving it out is a fourth:
|
|
9
|
+
//
|
|
10
|
+
// original the files as recorded: nothing lost, nothing gained
|
|
11
|
+
// aac mono AAC at 32 kbps, about 4 KB a second of voice: plays in
|
|
12
|
+
// every browser, which is what a file that is SENT needs
|
|
13
|
+
// opus mono Opus at 24 kbps in WebM, about 3 KB a second and better
|
|
14
|
+
// at that rate than AAC: the smallest, for a recent browser
|
|
15
|
+
// (Safari from 17)
|
|
16
|
+
//
|
|
17
|
+
// A recorder WAV is about forty times the AAC. A re-encode that would not
|
|
18
|
+
// shrink a file leaves it as it was: encoding an already-small file again only
|
|
19
|
+
// loses. Every block is keyed by the URL the track would play, which is what
|
|
20
|
+
// the runtime looks up before playing that URL (narration.js bundledAudio).
|
|
21
|
+
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import os from 'node:os';
|
|
24
|
+
import path from 'node:path';
|
|
25
|
+
import { configuredTrackDirs } from './edit.mjs';
|
|
26
|
+
import { runAsync, CODEC_MS, PROBE_MS } from '../tools/exec.mjs';
|
|
27
|
+
import { renumber, sliceManifest } from './bundle-module.mjs';
|
|
28
|
+
|
|
29
|
+
export const AUDIO_CHOICES = ['original', 'aac', 'opus'];
|
|
30
|
+
|
|
31
|
+
export const CODECS = {
|
|
32
|
+
aac: {
|
|
33
|
+
label: 'AAC, mono 32 kbps', kbps: 32, overhead: 1.03, ext: 'm4a', mime: 'audio/mp4', encoder: 'aac',
|
|
34
|
+
args: ['-ac', '1', '-ar', '24000', '-c:a', 'aac', '-b:a', '32k', '-movflags', '+faststart'],
|
|
35
|
+
},
|
|
36
|
+
opus: {
|
|
37
|
+
label: 'Opus, mono 24 kbps', kbps: 24, overhead: 1.09, ext: 'webm', mime: 'audio/webm', encoder: 'libopus',
|
|
38
|
+
// constrained VBR: the size stays near the bitrate whatever was recorded,
|
|
39
|
+
// which is what lets the bundle card's estimate be one
|
|
40
|
+
args: ['-ac', '1', '-c:a', 'libopus', '-b:a', '24k', '-vbr', 'constrained', '-application', 'voip'],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const AUDIO_MIME = {
|
|
45
|
+
m4a: 'audio/mp4', mp4: 'audio/mp4', aac: 'audio/aac', mp3: 'audio/mpeg', wav: 'audio/wav',
|
|
46
|
+
ogg: 'audio/ogg', oga: 'audio/ogg', opus: 'audio/ogg', webm: 'audio/webm', flac: 'audio/flac',
|
|
47
|
+
};
|
|
48
|
+
const AUDIO_FILE = /^slide-\d+(?:-\d+)?\.(m4a|mp4|aac|mp3|wav|ogg|oga|opus|webm|flac)$/i;
|
|
49
|
+
const ABSOLUTE = /^[a-z][a-z0-9+.-]*:|^\/\//i;
|
|
50
|
+
|
|
51
|
+
/** "1.4 MB", "820.3 KB". */
|
|
52
|
+
export const sizeLabel = (n) => (n < 1048576 ? `${(n / 1024).toFixed(1)} KB` : `${(n / 1048576).toFixed(1)} MB`);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Every recorded file a deck's tracks would play from this disk: a
|
|
56
|
+
* `narration.files` folder's `slide-NN[-KK].<audio>`, and a local manifest's
|
|
57
|
+
* `file` entries. `found` maps the URL the runtime plays to the file;
|
|
58
|
+
* `folders` reads "voices/ (12), cloud/ (3)"; `remote` counts manifest entries
|
|
59
|
+
* with a `url` of their own (a bucket's, often signed), which stay there.
|
|
60
|
+
* With `mod` (`bundle --module`, cli/bundle-module.mjs) only that chapter's
|
|
61
|
+
* files are found, each under the slide number it has in the chapter.
|
|
62
|
+
*/
|
|
63
|
+
export function narrationAudio(html, deckDir, mod = null) {
|
|
64
|
+
const found = new Map();
|
|
65
|
+
const where = new Map();
|
|
66
|
+
const add = (key, abs) => {
|
|
67
|
+
if (found.has(key) || !fs.existsSync(abs) || !fs.statSync(abs).isFile()) return;
|
|
68
|
+
found.set(key, abs);
|
|
69
|
+
const folder = path.posix.dirname(key);
|
|
70
|
+
where.set(folder, (where.get(folder) ?? 0) + 1);
|
|
71
|
+
};
|
|
72
|
+
for (const d of configuredTrackDirs(html)) {
|
|
73
|
+
if (ABSOLUTE.test(d)) continue; // a public bucket's prefix: nothing on this disk
|
|
74
|
+
const abs = path.resolve(deckDir, d);
|
|
75
|
+
if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) continue;
|
|
76
|
+
for (const f of fs.readdirSync(abs).sort()) {
|
|
77
|
+
if (!AUDIO_FILE.test(f)) continue;
|
|
78
|
+
const as = renumber(f, mod);
|
|
79
|
+
if (as) add(`${d.replace(/\/+$/, '')}/${as}`, path.join(abs, f));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let remote = 0;
|
|
83
|
+
// `manifest: '…'` in a boot call, `"manifest": "…"` in a configuration block
|
|
84
|
+
for (const rel of new Set([...html.matchAll(/\bmanifest["']?\s*:\s*['"]([^'"]+)['"]/g)].map((m) => m[1]))) {
|
|
85
|
+
const abs = path.resolve(deckDir, rel);
|
|
86
|
+
let data = null;
|
|
87
|
+
try { data = JSON.parse(fs.readFileSync(abs, 'utf8')); } catch { continue; }
|
|
88
|
+
const clean = rel.replace(/[?#].*$/, '');
|
|
89
|
+
const base = clean.slice(0, clean.lastIndexOf('/') + 1); // voicetrack.js manifestBase
|
|
90
|
+
const entries = (sliceManifest(data, mod)?.slides ?? []).flatMap((e) => (e ? [e, ...(e.segments ?? []).filter(Boolean)] : []));
|
|
91
|
+
for (const e of entries) {
|
|
92
|
+
if (e.url) { remote++; continue; }
|
|
93
|
+
if (typeof e.file !== 'string' || ABSOLUTE.test(e.file)) continue;
|
|
94
|
+
add(base + e.file, path.resolve(path.dirname(abs), e.file));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { found, remote, folders: [...where].map(([f, n]) => `${f}/ (${n})`).join(', ') };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The block one file goes in, as the bundle writes it. */
|
|
101
|
+
function block(key, mime, buf) {
|
|
102
|
+
return `<script type="application/json" data-decklight-audio="${key.replace(/"/g, '"')}">`
|
|
103
|
+
+ `${JSON.stringify(`data:${mime};base64,${buf.toString('base64')}`)}</script>`;
|
|
104
|
+
}
|
|
105
|
+
/** That block's length for `n` bytes, without building it. */
|
|
106
|
+
const blockLength = (key, mime, n) => block(key, mime, Buffer.alloc(0)).length + 4 * Math.ceil(n / 3) + 1;
|
|
107
|
+
|
|
108
|
+
/** Which of the two encoders this machine's ffmpeg has: `{ aac, opus }`, both false without one. */
|
|
109
|
+
export async function encoders() {
|
|
110
|
+
try {
|
|
111
|
+
const out = String(await runAsync('ffmpeg', ['-hide_banner', '-encoders'], { timeout: PROBE_MS, why: 'listing encoders' }));
|
|
112
|
+
return { aac: /^\s*A\S*\s+aac\s/m.test(out), opus: /^\s*A\S*\s+libopus\s/m.test(out) };
|
|
113
|
+
} catch { return { aac: false, opus: false }; }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A file's length in seconds, or null when ffprobe cannot say. */
|
|
117
|
+
async function duration(abs) {
|
|
118
|
+
try {
|
|
119
|
+
const out = await runAsync('ffprobe', ['-v', 'error', '-show_entries', 'format=duration', '-of', 'csv=p=0', abs],
|
|
120
|
+
{ timeout: PROBE_MS, why: 'reading a duration' });
|
|
121
|
+
const s = Number.parseFloat(String(out));
|
|
122
|
+
return Number.isFinite(s) ? s : null;
|
|
123
|
+
} catch { return null; }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* What each choice would add to the file, in bytes, before anything is
|
|
128
|
+
* encoded: `original` exactly; `aac` and `opus` from each file's duration at
|
|
129
|
+
* the codec's bitrate, plus what its container adds (measured: 3% for MP4,
|
|
130
|
+
* 9% for WebM), never more than the file itself, because a re-encode that
|
|
131
|
+
* would not shrink it is skipped.
|
|
132
|
+
* A codec this ffmpeg lacks, or durations ffprobe cannot read, give null with
|
|
133
|
+
* the reason in `why`.
|
|
134
|
+
*/
|
|
135
|
+
export async function estimateAudio(found) {
|
|
136
|
+
const files = [...found];
|
|
137
|
+
const have = await encoders();
|
|
138
|
+
const seconds = await Promise.all(files.map(([, abs]) => duration(abs)));
|
|
139
|
+
const known = seconds.every((s) => s != null);
|
|
140
|
+
const sizes = files.map(([, abs]) => fs.statSync(abs).size);
|
|
141
|
+
const original = files.reduce((n, [key, abs], i) => n + blockLength(key, AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()], sizes[i]), 0);
|
|
142
|
+
const out = { files: files.length, bytes: sizes.reduce((a, b) => a + b, 0), seconds: known ? seconds.reduce((a, b) => a + b, 0) : null, original, why: {} };
|
|
143
|
+
for (const [name, c] of Object.entries(CODECS)) {
|
|
144
|
+
if (!have[name]) { out[name] = null; out.why[name] = `needs ffmpeg with ${c.encoder}`; continue; }
|
|
145
|
+
if (!known) { out[name] = null; out.why[name] = 'ffprobe could not read the durations'; continue; }
|
|
146
|
+
out[name] = files.reduce((n, [key, abs], i) => {
|
|
147
|
+
const encoded = Math.ceil(seconds[i] * c.kbps * 1000 / 8 * c.overhead) + 1024;
|
|
148
|
+
return n + (encoded < sizes[i] ? blockLength(key, c.mime, encoded)
|
|
149
|
+
: blockLength(key, AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()], sizes[i]));
|
|
150
|
+
}, 0);
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The blocks that carry `found`, as recorded or re-encoded with `codec`
|
|
157
|
+
* ('original' | 'aac' | 'opus'). Throws an Error with a sentence when ffmpeg
|
|
158
|
+
* is missing or refuses a file. Returns `{ blocks, bytes, before }`.
|
|
159
|
+
*/
|
|
160
|
+
export async function inlineAudio(found, codec = 'original') {
|
|
161
|
+
const c = CODECS[codec] ?? null;
|
|
162
|
+
const scratch = c ? fs.mkdtempSync(path.join(os.tmpdir(), 'decklight-audio-')) : null;
|
|
163
|
+
const blocks = [];
|
|
164
|
+
let bytes = 0, before = 0, nth = 0;
|
|
165
|
+
try {
|
|
166
|
+
for (const [key, abs] of found) {
|
|
167
|
+
let buf = fs.readFileSync(abs);
|
|
168
|
+
let mime = AUDIO_MIME[path.extname(abs).slice(1).toLowerCase()];
|
|
169
|
+
before += buf.length;
|
|
170
|
+
if (c) {
|
|
171
|
+
const out = path.join(scratch, `${++nth}.${c.ext}`);
|
|
172
|
+
try {
|
|
173
|
+
await runAsync('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-y', '-i', abs, '-vn', ...c.args, out],
|
|
174
|
+
{ timeout: CODEC_MS, why: `re-encoding ${key}` });
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (e.code === 'ENOENT') throw new Error(`--audio ${codec} re-encodes the narration with ffmpeg, which is not installed — install it, or bundle with --audio original to carry the files as they are`);
|
|
177
|
+
throw new Error(`--audio ${codec} could not re-encode ${key}: ${String(e.stderr || e.message).trim().split('\n')[0]}`);
|
|
178
|
+
}
|
|
179
|
+
const small = fs.readFileSync(out);
|
|
180
|
+
// an already-small file stays as it was: re-encoding it again only loses
|
|
181
|
+
if (small.length < buf.length) { buf = small; mime = c.mime; }
|
|
182
|
+
}
|
|
183
|
+
bytes += buf.length;
|
|
184
|
+
blocks.push(block(key, mime, buf));
|
|
185
|
+
}
|
|
186
|
+
} finally {
|
|
187
|
+
if (scratch) fs.rmSync(scratch, { recursive: true, force: true });
|
|
188
|
+
}
|
|
189
|
+
return { blocks, bytes, before };
|
|
190
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// One chapter of a deck as a bundle of its own (`bundle --module`, SPEC
|
|
5
|
+
// PRESENTING): the sections from a `data-module` marker up to the next one,
|
|
6
|
+
// and the narration that goes with them.
|
|
7
|
+
//
|
|
8
|
+
// The narration is the part that needs care. A track's files are named by
|
|
9
|
+
// slide number (`slide-07-02.wav`, `slide-07.visemes.json`) and a manifest is
|
|
10
|
+
// indexed by it (`slides[6]`), because the runtime builds those names from the
|
|
11
|
+
// slide it is on, counting from 1. Cut a chapter out and its slides are
|
|
12
|
+
// numbered from 1 again, so every name is moved down by the chapter's offset
|
|
13
|
+
// and anything outside the chapter is left out. Nothing is re-voiced: the
|
|
14
|
+
// clips are the same bytes under the number the bundle will ask for.
|
|
15
|
+
|
|
16
|
+
/** The top-level `<section>`s inside `[contentStart, contentEnd)`, depth-aware. */
|
|
17
|
+
function sectionSpans(html, contentStart, contentEnd) {
|
|
18
|
+
const spans = [];
|
|
19
|
+
const re = /<section\b[^>]*>|<\/section\s*>/gi;
|
|
20
|
+
re.lastIndex = contentStart;
|
|
21
|
+
let depth = 0, open = -1, m;
|
|
22
|
+
while ((m = re.exec(html)) && m.index < contentEnd) {
|
|
23
|
+
if (m[0][1] === '/') {
|
|
24
|
+
if (depth > 0 && --depth === 0) spans.push({ start: open, end: m.index + m[0].length, tag: html.slice(open, html.indexOf('>', open) + 1) });
|
|
25
|
+
} else if (depth++ === 0) open = m.index;
|
|
26
|
+
}
|
|
27
|
+
return spans;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const unescapeAttr = (s) => s.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&');
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The deck's chapters, in order: `{ n, title, offset, count }`, where `offset`
|
|
34
|
+
* is how many slides come before the chapter and `count` how many it holds.
|
|
35
|
+
* Slides before the first marker belong to no chapter.
|
|
36
|
+
*/
|
|
37
|
+
export function deckModules(html, bounds) {
|
|
38
|
+
const spans = sectionSpans(html, bounds.contentStart, bounds.contentEnd);
|
|
39
|
+
const out = [];
|
|
40
|
+
spans.forEach((s, i) => {
|
|
41
|
+
const m = s.tag.match(/\bdata-module\s*=\s*(?:"([^"]*)"|'([^']*)')/i);
|
|
42
|
+
if (!m) return;
|
|
43
|
+
if (out.length) out[out.length - 1].count = i - out[out.length - 1].offset;
|
|
44
|
+
out.push({ n: out.length + 1, title: unescapeAttr(m[1] ?? m[2]).trim(), offset: i, count: spans.length - i });
|
|
45
|
+
});
|
|
46
|
+
return { modules: out, spans };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The chapter `want` names: its number (1-based) or its title, case and
|
|
51
|
+
* surrounding space ignored. Throws an Error with a sentence that lists the
|
|
52
|
+
* chapters when nothing matches, or says there are none.
|
|
53
|
+
*/
|
|
54
|
+
export function pickModule(modules, want) {
|
|
55
|
+
if (!modules.length) {
|
|
56
|
+
throw new Error('--module: this deck has no chapters — a chapter starts at a <section data-module="…">');
|
|
57
|
+
}
|
|
58
|
+
const key = String(want).trim();
|
|
59
|
+
const byNumber = /^\d+$/.test(key) ? modules[Number(key) - 1] : null;
|
|
60
|
+
const hit = byNumber ?? modules.find((m) => m.title.toLowerCase() === key.toLowerCase());
|
|
61
|
+
if (hit) return hit;
|
|
62
|
+
throw new Error(`--module: no chapter "${key}" in this deck — its chapters are:\n`
|
|
63
|
+
+ modules.map((m) => ` ${m.n} ${m.title} (${m.count === 1 ? '1 slide' : `${m.count} slides`})`).join('\n'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The deck with only `mod`'s sections left inside the container. */
|
|
67
|
+
export function sliceModule(html, bounds, spans, mod) {
|
|
68
|
+
const keep = spans.slice(mod.offset, mod.offset + mod.count);
|
|
69
|
+
const inner = keep.map((s) => html.slice(s.start, s.end)).join('\n\n ');
|
|
70
|
+
return html.slice(0, bounds.contentStart) + '\n\n ' + inner + '\n\n ' + html.slice(bounds.contentEnd);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A track file's name moved into the chapter: `slide-07-02.wav` with an
|
|
75
|
+
* offset of 4 is `slide-03-02.wav`, and a slide outside the chapter is null.
|
|
76
|
+
* Works on a bare stem (`slide-07`) and on a path (`voices/slide-07.m4a`).
|
|
77
|
+
* With no `mod` the name is returned as it is.
|
|
78
|
+
*/
|
|
79
|
+
export function renumber(name, mod) {
|
|
80
|
+
if (!mod) return name;
|
|
81
|
+
const m = name.match(/^(.*?\bslide-)(\d+)((?:-\d+)?(?:\..*)?)$/);
|
|
82
|
+
if (!m) return name;
|
|
83
|
+
const n = Number(m[2]) - mod.offset;
|
|
84
|
+
if (n < 1 || n > mod.count) return null;
|
|
85
|
+
return `${m[1]}${String(n).padStart(Math.max(2, m[2].length), '0')}${m[3]}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A manifest's `slides` cut to the chapter (entry k is slide k + 1). */
|
|
89
|
+
export function sliceManifest(data, mod) {
|
|
90
|
+
if (!mod || !Array.isArray(data?.slides)) return data;
|
|
91
|
+
return { ...data, slides: data.slides.slice(mod.offset, mod.offset + mod.count) };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** "Foundations" → "foundations", for the default file name. */
|
|
95
|
+
export const slug = (s) => s.toLowerCase().normalize('NFKD').replace(/[^\w\s-]/g, '').trim().replace(/[\s_]+/g, '-').replace(/-+/g, '-') || 'module';
|