decklight 0.10.0 → 0.11.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/NOTICE +2 -0
- package/PLATFORM.md +17 -0
- package/README.md +53 -25
- package/SPEC.md +1239 -67
- package/cli/agents.mjs +139 -15
- package/cli/bundle.mjs +68 -2
- package/cli/cast.mjs +45 -14
- package/cli/check-fixes.mjs +12 -4
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +460 -71
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-message.mjs +34 -7
- package/cli/commit-split.mjs +123 -23
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +21 -4
- package/cli/edit-handover.mjs +136 -25
- package/cli/edit-look.mjs +45 -1
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3182 -267
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +148 -20
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/init.mjs +93 -19
- package/cli/keep-awake.mjs +68 -0
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +51 -10
- package/cli/open.mjs +29 -9
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +61 -2
- package/cli/pptx-export.mjs +3 -1
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +19 -8
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +7 -4
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +212 -8
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +36 -13
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2087 -91
- package/dist/decklight.js +367 -203
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +15 -1
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +24 -4
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +772 -127
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- package/dist/build-info.json +0 -1
package/cli/pdf.mjs
CHANGED
|
@@ -26,6 +26,9 @@ import { argReader, isMain } from '../tools/args.mjs';
|
|
|
26
26
|
import { renderThemeParams } from '../tools/render-theme.mjs';
|
|
27
27
|
import { runAsync, CODEC_MS } from '../tools/exec.mjs';
|
|
28
28
|
import { sectionBodies, isHiddenSection } from '../tools/deck-html.mjs';
|
|
29
|
+
import { INVISIBLE_ADVICE, invisibleSaidOf } from '../tools/invisible-in-print.mjs';
|
|
30
|
+
|
|
31
|
+
export { INVISIBLE_ADVICE };
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* How many slides the handout puts on a page — the runtime's own number,
|
|
@@ -128,6 +131,59 @@ function flaggedSlides(html, attr) {
|
|
|
128
131
|
/** Slides the overflow guardrail flagged (SPEC PRESENTING). */
|
|
129
132
|
export const overflowSlides = (html) => flaggedSlides(html, 'data-overflow');
|
|
130
133
|
|
|
134
|
+
/**
|
|
135
|
+
* What the guardrail said about a clipped slide's section tag: what is cut
|
|
136
|
+
* (`data-overflow="a diagram"`) and by how much (`data-overflow-by`), as the
|
|
137
|
+
* runtime measured it (#1183). An older runtime wrote a bare attribute: then
|
|
138
|
+
* only that the slide is clipped.
|
|
139
|
+
*/
|
|
140
|
+
export function clipSaid(tag) {
|
|
141
|
+
const what = /\sdata-overflow="([^"]+)"/.exec(tag)?.[1]?.replace(/&/g, '&');
|
|
142
|
+
const by = Number(/\sdata-overflow-by="(\d+)"/.exec(tag)?.[1]);
|
|
143
|
+
if (!what || !(by > 0)) return '';
|
|
144
|
+
return `${what} runs ${by}px past what the slide shows`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Each flagged slide with what its guardrail said: `[{ n, said }]`. */
|
|
148
|
+
export function overflowReport(html) {
|
|
149
|
+
const out = [];
|
|
150
|
+
let n = 0;
|
|
151
|
+
for (const m of html.matchAll(/<section\b[^>]*>/g)) {
|
|
152
|
+
n += 1;
|
|
153
|
+
if (/\bdata-overflow\b/.test(m[0])) out.push({ n, said: clipSaid(m[0]) });
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** An attribute's value out of a dumped section tag, its entities undone. */
|
|
159
|
+
const attrOf = (tag, name) => new RegExp(`\\s${name}="([^"]*)"`).exec(tag)?.[1]
|
|
160
|
+
?.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(/ /g, ' ').replace(/&/g, '&');
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* What a slide's section tag says it does not show in print (#1184): the
|
|
164
|
+
* runtime names the first element still at opacity 0 or visibility hidden once
|
|
165
|
+
* builds are complete and the deck's own animations finished
|
|
166
|
+
* (`data-invisible="a box “Batch” (opacity 0)"`) and counts the others
|
|
167
|
+
* (`data-invisible-more`). '' when it shows everything.
|
|
168
|
+
*/
|
|
169
|
+
export function invisibleSaid(tag) {
|
|
170
|
+
return invisibleSaidOf(attrOf(tag, 'data-invisible'), attrOf(tag, 'data-invisible-more'));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Each slide with something invisible in print, and what: `[{ n, said }]`. */
|
|
174
|
+
export function invisibleReport(html) {
|
|
175
|
+
const out = [];
|
|
176
|
+
let n = 0;
|
|
177
|
+
for (const m of html.matchAll(/<section\b[^>]*>/g)) {
|
|
178
|
+
n += 1;
|
|
179
|
+
const said = invisibleSaid(m[0]);
|
|
180
|
+
if (said) out.push({ n, said });
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// INVISIBLE_ADVICE, said by pdf, check and the Check deck… panel alike, is tools/invisible-in-print.mjs's
|
|
186
|
+
|
|
131
187
|
/**
|
|
132
188
|
* Slides mixing data-layout="split" with their own column flexbox (SPEC
|
|
133
189
|
* COMPARISON_SLIDES) — the engine marks the cause the overflow guardrail
|
|
@@ -220,8 +276,11 @@ async function printDeck({ src, out, url, bin, shared, variant, theme, signal })
|
|
|
220
276
|
return 1;
|
|
221
277
|
}
|
|
222
278
|
|
|
223
|
-
for (const n of
|
|
224
|
-
console.error(`pdf: ⚠ slide ${n} overflows — it will be clipped in the PDF`);
|
|
279
|
+
for (const { n, said } of overflowReport(html)) {
|
|
280
|
+
console.error(`pdf: ⚠ slide ${n} overflows${said ? `: ${said}` : ''} — it will be clipped in the PDF`);
|
|
281
|
+
}
|
|
282
|
+
for (const { n, said } of invisibleReport(html)) {
|
|
283
|
+
console.error(`pdf: ⚠ slide ${n} prints with a hole: ${said} is invisible — ${INVISIBLE_ADVICE}`);
|
|
225
284
|
}
|
|
226
285
|
for (const n of splitConflictSlides(html)) {
|
|
227
286
|
console.error(`pdf: ⚠ slide ${n} mixes data-layout="split" with its own column flexbox — `
|
package/cli/pptx-export.mjs
CHANGED
|
@@ -111,7 +111,9 @@ export async function pptxMain(args = [], { render = chromeShot, log = console.e
|
|
|
111
111
|
// --theme rides the URL (`?theme=`), which the runtime applies to any kind
|
|
112
112
|
// of theme the deck holds — a <link> to themes/<name>.css reached only file
|
|
113
113
|
// themes, and missed a deck whose themes are inline blocks (#547).
|
|
114
|
-
|
|
114
|
+
// `capture=print`: each picture is the slide as it prints, so a stepped code
|
|
115
|
+
// block is whole unless it asks for its last step (CODE_AND_MATH)
|
|
116
|
+
const renderQuery = `?${['capture=print', ...themeParams].join('&')}`;
|
|
115
117
|
const server = await serveForRender(root);
|
|
116
118
|
const scratch = mkdtempSync(join(tmpdir(), 'decklight-pptx-'));
|
|
117
119
|
const slides = [];
|
package/cli/publish.mjs
CHANGED
|
@@ -39,6 +39,7 @@ import { putBlob, remoteHead } from './git-tree.mjs';
|
|
|
39
39
|
import { ownerRepo } from './git.mjs';
|
|
40
40
|
import { TARGETS, schemaFor, envVarsFor, envAnswers, deploy } from '../tools/publish-targets.mjs';
|
|
41
41
|
import { checkAnswers } from './wizard.mjs';
|
|
42
|
+
import { AUDIO_CHOICES } from './bundle-audio.mjs';
|
|
42
43
|
|
|
43
44
|
const fail = makeFail('publish');
|
|
44
45
|
|
|
@@ -78,7 +79,8 @@ if (!argv.length || argv.includes('--help') || argv.includes('-h')) {
|
|
|
78
79
|
Usage:
|
|
79
80
|
decklight publish <deck.html> [--branch gh-pages] [--remote origin]
|
|
80
81
|
[--no-bundle] [--no-sign] [--deck] [--path <subdir>]
|
|
81
|
-
[--theme <name>] [--
|
|
82
|
+
[--theme <name>] [--audio [original|aac|opus]] [--languages all|fr,es]
|
|
83
|
+
[--target gh-pages|netlify|vercel|folder]
|
|
82
84
|
|
|
83
85
|
Options:
|
|
84
86
|
--branch <name> branch to publish to (default: gh-pages; gh-pages target only)
|
|
@@ -87,6 +89,13 @@ Options:
|
|
|
87
89
|
--no-sign publish without a Sigstore signature
|
|
88
90
|
--theme <name> the theme the published page opens on — a shipped theme or
|
|
89
91
|
one the deck marks (default: the deck's own "theme")
|
|
92
|
+
--audio [how] carry the narration's recorded audio inside the published
|
|
93
|
+
page, as \`bundle --audio\` does: original (the default), aac
|
|
94
|
+
(plays everywhere) or opus (the smallest). Without it the
|
|
95
|
+
clips stay beside the deck and the page plays no voice
|
|
96
|
+
--languages <sel> publish the deck's translations beside it (decklight
|
|
97
|
+
translate): all, or fr,es — each a page of its own,
|
|
98
|
+
index.fr.html beside index.html, switching to the others
|
|
90
99
|
--deck also publish index.decklight — the signed container, which
|
|
91
100
|
is the file a visitor downloads and forwards
|
|
92
101
|
--path <subdir> publish under a subdirectory of the site (other content
|
|
@@ -114,7 +123,7 @@ orphan; later publishes append to its history.
|
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
let deck = null, branch = 'gh-pages', remote = 'origin', bundle = true, subdir = '', sign = true, deckFile = false,
|
|
117
|
-
target = 'gh-pages', branchGiven = false, remoteGiven = false, theme = null;
|
|
126
|
+
target = 'gh-pages', branchGiven = false, remoteGiven = false, theme = null, audio = null, languages = null;
|
|
118
127
|
for (let i = 0; i < argv.length; i++) {
|
|
119
128
|
const a = argv[i];
|
|
120
129
|
if (a === '--branch') { branch = argv[++i]; branchGiven = true; }
|
|
@@ -123,6 +132,11 @@ for (let i = 0; i < argv.length; i++) {
|
|
|
123
132
|
else if (a === '--no-sign') sign = false;
|
|
124
133
|
else if (a === '--deck') deckFile = true;
|
|
125
134
|
else if (a === '--theme') theme = argv[++i];
|
|
135
|
+
// each language beside index.html as index.<lang>.html (TRANSLATION_SWITCH)
|
|
136
|
+
else if (a === '--languages') languages = argv[++i];
|
|
137
|
+
// `--audio` alone carries the files as recorded; a codec after it re-encodes
|
|
138
|
+
// them (bundle's own choices, read from the same list)
|
|
139
|
+
else if (a === '--audio') audio = AUDIO_CHOICES.includes(argv[i + 1]) ? argv[++i] : 'original';
|
|
126
140
|
else if (a === '--path') subdir = argv[++i];
|
|
127
141
|
else if (a === '--target') target = argv[++i];
|
|
128
142
|
// the folder target's two answers, as flags — a directory is not a secret,
|
|
@@ -133,6 +147,7 @@ for (let i = 0; i < argv.length; i++) {
|
|
|
133
147
|
else fail(`unknown argument: ${a}`);
|
|
134
148
|
}
|
|
135
149
|
if (!deck) fail('no deck given');
|
|
150
|
+
if (audio && !bundle) fail('--audio carries the narration inside the bundle, and --no-bundle publishes the deck as it is: use one or the other');
|
|
136
151
|
// Checked here rather than at pack time: an argument that cannot work should
|
|
137
152
|
// be refused before the command starts doing things.
|
|
138
153
|
if (deckFile && !sign) fail('--deck packs the SIGNED deck — it cannot be combined with --no-sign');
|
|
@@ -196,8 +211,10 @@ if (bundle) {
|
|
|
196
211
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'decklight-publish-'));
|
|
197
212
|
sitePage = path.join(tmpDir, 'index.html');
|
|
198
213
|
const { bundleMain } = await import('./bundle.mjs');
|
|
199
|
-
await bundleMain([deckPath, '-o', sitePage, ...(theme ? ['--theme', theme] : [])]);
|
|
214
|
+
await bundleMain([deckPath, '-o', sitePage, ...(theme ? ['--theme', theme] : []), ...(audio ? ['--audio', audio] : []), ...(languages ? ['--languages', languages] : [])]);
|
|
200
215
|
}
|
|
216
|
+
// the languages bundled beside the page, published beside it
|
|
217
|
+
const languagePages = tmpDir ? fs.readdirSync(tmpDir).filter((n) => /^index\.[a-z]{2,3}(?:-[a-z0-9]{2,8})*\.html$/i.test(n)) : [];
|
|
201
218
|
|
|
202
219
|
// --------------------------------------------------------------- plumbing
|
|
203
220
|
|
|
@@ -241,8 +258,10 @@ if (target !== 'gh-pages') {
|
|
|
241
258
|
// tree, no history, and nothing else on the site to preserve or diff
|
|
242
259
|
// against — the files below are simply what gets sent, in full, every time.
|
|
243
260
|
const pageBytes = fs.readFileSync(sitePage);
|
|
261
|
+
const languageBytes = new Map(languagePages.map((n) => [n, fs.readFileSync(path.join(tmpDir, n))]));
|
|
244
262
|
if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
245
263
|
const files = [{ path: [...parts, 'index.html'].join('/'), data: pageBytes }];
|
|
264
|
+
for (const n of languagePages) files.push({ path: [...parts, n].join('/'), data: languageBytes.get(n) });
|
|
246
265
|
if (signature) files.push({ path: [...parts, 'index.html.sig'].join('/'), data: `${JSON.stringify(signature, null, 2)}\n` });
|
|
247
266
|
if (deckBytes) files.push({ path: [...parts, 'index.decklight'].join('/'), data: deckBytes });
|
|
248
267
|
|
|
@@ -257,6 +276,7 @@ if (target !== 'gh-pages') {
|
|
|
257
276
|
// Objects land in the repo's database; nothing references them until the
|
|
258
277
|
// push, and neither the working tree nor the index ever hears about it.
|
|
259
278
|
const pageBlob = git(['hash-object', '-w', '--', sitePage]);
|
|
279
|
+
const languageBlobs = languagePages.map((n) => [n, git(['hash-object', '-w', '--', path.join(tmpDir, n)])]);
|
|
260
280
|
const nojekyllBlob = git(['hash-object', '-w', '--stdin'], '');
|
|
261
281
|
const sigBlob = signature ? git(['hash-object', '-w', '--stdin'], `${JSON.stringify(signature, null, 2)}\n`) : null;
|
|
262
282
|
const deckBlob = deckBytes
|
|
@@ -276,6 +296,7 @@ const put = (treeish, parts_, blob) => putBlob(git, treeish, parts_, blob);
|
|
|
276
296
|
|
|
277
297
|
let tree = put(parent, ['.nojekyll'], nojekyllBlob);
|
|
278
298
|
tree = put(tree, [...parts, 'index.html'], pageBlob);
|
|
299
|
+
for (const [n, blob] of languageBlobs) tree = put(tree, [...parts, n], blob);
|
|
279
300
|
// Beside the page it covers, under the name a verifier will look for.
|
|
280
301
|
if (sigBlob) tree = put(tree, [...parts, 'index.html.sig'], sigBlob);
|
|
281
302
|
if (deckBlob) tree = put(tree, [...parts, 'index.decklight'], deckBlob);
|
package/cli/record.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// decklight narrate --mic <deck.html> [--port 8788] [--dir voices/me] [--no-open]
|
|
8
8
|
//
|
|
9
9
|
// WHY THIS IS A COMMAND AND NOT JUST A KEY. The recorder itself lives in the
|
|
10
|
-
// deck (V →
|
|
10
|
+
// deck (V → My voice → Record…, or your voice's card): it has to, because the notes, the builds and the microphone are
|
|
11
11
|
// all in the browser. But a browser will not open a microphone for a page it
|
|
12
12
|
// loaded from `file://` — getUserMedia needs a secure context, and a local file
|
|
13
13
|
// is not one, no matter how many times you click Allow. `http://127.0.0.1` IS
|
|
@@ -24,13 +24,15 @@
|
|
|
24
24
|
// Deliberately NOT `decklight <deck>`: recording is not editing. Git is off,
|
|
25
25
|
// no bridge is started, nothing is spent. You are reading your own notes aloud.
|
|
26
26
|
|
|
27
|
+
import { resolve } from 'node:path';
|
|
27
28
|
import { editMain } from './edit.mjs';
|
|
29
|
+
import { deckFamily, tracksRoot } from '../tools/deck-family.mjs';
|
|
28
30
|
import { openUrl } from './open-browser.mjs';
|
|
29
31
|
import { argReader, firstPositional, isMain } from '../tools/args.mjs';
|
|
30
32
|
import { runMain, wrongRecorder } from './util.mjs';
|
|
31
33
|
import { exitWhenOrphaned } from './supervise.mjs';
|
|
32
34
|
|
|
33
|
-
const USAGE = `usage: decklight narrate --mic <deck.html> [--port 8788] [--dir voices/me] [--slides a-b [--beats k-l]] [--takes slide|beat] [--countdown N] [--remote] [--no-open]
|
|
35
|
+
const USAGE = `usage: decklight narrate --mic <deck.html> [--port 8788] [--dir voices/me] [--slides a-b [--beats k-l]] [--takes slide|beat] [--countdown N] [--camera] [--remote] [--no-open]
|
|
34
36
|
serves the deck over http://127.0.0.1 and opens it with the voice recorder up
|
|
35
37
|
|
|
36
38
|
the deck reads you its notes one [click] beat at a time; → ends a beat, which
|
|
@@ -51,9 +53,15 @@ const USAGE = `usage: decklight narrate --mic <deck.html> [--port 8788] [--dir v
|
|
|
51
53
|
also start from any beat: ← → pick it before you press Enter
|
|
52
54
|
--takes slide|beat one take per slide, read straight through, or per beat,
|
|
53
55
|
each counted in and retaken on its own
|
|
54
|
-
[the
|
|
56
|
+
[per slide, every visit: the card's choice lasts the visit]
|
|
55
57
|
--countdown N seconds of count-in before each take, 0 for none (0-9)
|
|
56
58
|
[the recorder card's count-in: 3 s, 1 s or off, remembered]
|
|
59
|
+
--camera film your face too, beat by beat, beside the audio (the
|
|
60
|
+
recorder card's Camera option, for this visit; it is offered
|
|
61
|
+
only when the browser finds a camera). The deck plays it in the
|
|
62
|
+
character's medallion with your voice, or full screen where a
|
|
63
|
+
slide says data-face="full 1.4"; decklight video shows it too.
|
|
64
|
+
Needs ffmpeg to save it [the card's choice, remembered]
|
|
57
65
|
--remote the phone remote too, so recording needs no keyboard: its next
|
|
58
66
|
ends a beat and its retake redoes one, and a tap is not in the
|
|
59
67
|
take the way a keystroke is. The recorder's card shows the QR;
|
|
@@ -100,13 +108,14 @@ export function dirProblem(name) {
|
|
|
100
108
|
* record against the slides your audience will see, at the build they will see
|
|
101
109
|
* them at.
|
|
102
110
|
*/
|
|
103
|
-
export function recordUrl(port, deckUrl, dir, slides, beats, countdown, takes) {
|
|
111
|
+
export function recordUrl(port, deckUrl, dir, slides, beats, countdown, takes, camera = false) {
|
|
104
112
|
const q = ['record',
|
|
105
113
|
...(dir ? [`dir=${encodeURIComponent(dir)}`] : []),
|
|
106
114
|
...(slides ? [`slides=${encodeURIComponent(slides)}`] : []),
|
|
107
115
|
...(beats ? [`beats=${encodeURIComponent(beats)}`] : []),
|
|
108
116
|
...(countdown != null ? [`countdown=${countdown}`] : []),
|
|
109
|
-
...(takes ? [`takes=${takes}`] : [])
|
|
117
|
+
...(takes ? [`takes=${takes}`] : []),
|
|
118
|
+
...(camera ? ['camera'] : [])].join('&');
|
|
110
119
|
return `http://127.0.0.1:${port}${deckUrl}?${q}`;
|
|
111
120
|
}
|
|
112
121
|
|
|
@@ -198,11 +207,13 @@ export async function recordMain(args, { open = openUrl, out = process.stdout, o
|
|
|
198
207
|
// missing or outside the served root — say nothing on top of it.
|
|
199
208
|
if (!started) return process.exitCode ?? 1;
|
|
200
209
|
|
|
201
|
-
const url = recordUrl(started.port, started.deckUrl, dir, slides, beats, countdown == null ? null : Number(countdown), takes);
|
|
210
|
+
const url = recordUrl(started.port, started.deckUrl, dir, slides, beats, countdown == null ? null : Number(countdown), takes, args.includes('--camera'));
|
|
202
211
|
out.write(`decklight narrate --mic on ${url}\n`);
|
|
203
|
-
out.write(' V →
|
|
212
|
+
out.write(' V → My voice opens the recorder again · → ends a beat and reveals the next build · Esc stops\n');
|
|
204
213
|
if (remote) out.write(' the phone remote is on: scan the QR on the recorder\'s card; next ends a beat, retake redoes it\n');
|
|
205
|
-
out.write(
|
|
214
|
+
if (args.includes('--camera')) out.write(' the camera is on: your face is filmed with every beat, beside its audio\n');
|
|
215
|
+
// `voices/me`, or `voices-fr/me` for the French of a deck (PRESENTING_VOICE)
|
|
216
|
+
out.write(` files land in ${dir ?? `${tracksRoot(deckFamily(resolve(deck)))}/me`}, next to the deck.`
|
|
206
217
|
+ `${dir ? '' : ' Recording again refreshes it.'}`
|
|
207
218
|
+ `${slides ? ` Only slide${/-/.test(slides) ? 's' : ''} ${slides}${beats ? `, beat${/-/.test(beats) ? 's' : ''} ${beats}` : ''}.` : ''}`
|
|
208
219
|
+ ' Ctrl-C when you are done.\n');
|
package/cli/rewrite.mjs
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The slide-text writing tools (SPEC PRESENTING_WRITING): the words ON the
|
|
6
|
+
* slide, rewritten by the locally installed agent and reviewed before they
|
|
7
|
+
* land, the way the script rewrites are (cli/enhance.mjs, #907).
|
|
8
|
+
*
|
|
9
|
+
* THE AGENT SEES TEXT RUNS, NOT MARKUP. A slide's visible text is cut into
|
|
10
|
+
* runs, the text between tags outside the notes, code, scripts, styles and
|
|
11
|
+
* SVG, numbered, and the agent is asked for the same numbered runs back.
|
|
12
|
+
* Decklight puts them into the slide where they came from. So a tool can
|
|
13
|
+
* only change words: the slide's structure, its builds, attributes, styles
|
|
14
|
+
* and classes cannot move, which is what makes it safe to run on a whole
|
|
15
|
+
* deck. An answer with markup in it, a run skipped or emptied, or a change a
|
|
16
|
+
* tool does not allow (a typo fix that rewords, a tighten that lengthens)
|
|
17
|
+
* fails its check, and that slide is left exactly as it was, with why.
|
|
18
|
+
*
|
|
19
|
+
* Four tools (TOOLS): `tighten` (shorter, same meaning), `typos` (spelling,
|
|
20
|
+
* grammar and punctuation, nothing else), `match` (reworded to agree with the
|
|
21
|
+
* speaker notes, which are sent along) and `custom` (one instruction of the
|
|
22
|
+
* author's, with the same check as match).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { agentAsk, agentUnavailable, detectAgents } from './agents.mjs';
|
|
26
|
+
import { ask, unwrapAnswer, ENHANCE_TIMEOUT_MS, ENHANCE_CONCURRENCY } from './enhance.mjs';
|
|
27
|
+
import { sectionBodies, sectionCloseIndex, isHiddenSection, locateSlide, cleanNotes, NOTES_ASIDE } from '../tools/deck-html.mjs';
|
|
28
|
+
|
|
29
|
+
/** Where the slide's text stops being the slide's: containers whose insides are not words to rewrite. */
|
|
30
|
+
const SKIP = /<!--[\s\S]*?-->|<(script|style|pre|code|svg|aside|textarea|kbd|samp)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
31
|
+
const TAG = /<[^>]+>/g;
|
|
32
|
+
|
|
33
|
+
const decode = (s) => String(s).replace(/&(#x[0-9a-f]+|#\d+|amp|lt|gt|quot|#39|apos|nbsp);/gi, (m, b) => {
|
|
34
|
+
const low = b.toLowerCase();
|
|
35
|
+
if (low === 'amp') return '&';
|
|
36
|
+
if (low === 'lt') return '<';
|
|
37
|
+
if (low === 'gt') return '>';
|
|
38
|
+
if (low === 'quot') return '"';
|
|
39
|
+
if (low === '#39' || low === 'apos') return "'";
|
|
40
|
+
if (low === 'nbsp') return ' ';
|
|
41
|
+
const code = low.startsWith('#x') ? parseInt(low.slice(2), 16) : parseInt(low.slice(1), 10);
|
|
42
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : m;
|
|
43
|
+
});
|
|
44
|
+
const encode = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A slide's visible text as numbered runs: `[{ n, start, end, text }]`, each
|
|
48
|
+
* a stretch of text between tags with at least one word in it, `start`/`end`
|
|
49
|
+
* its place in `content` (the section's inside), `text` decoded. Pure.
|
|
50
|
+
*/
|
|
51
|
+
export function textRuns(content) {
|
|
52
|
+
const src = String(content ?? '');
|
|
53
|
+
const runs = [];
|
|
54
|
+
// what is skipped is blanked to a mark, same length, so offsets stay the
|
|
55
|
+
// offsets and a run that touches it is not a run; then the text is walked
|
|
56
|
+
// by tag boundaries, so a run never crosses a tag
|
|
57
|
+
const skipped = src.replace(SKIP, (x) => '\u0000'.repeat(x.length));
|
|
58
|
+
const bounds = [];
|
|
59
|
+
for (const m of skipped.matchAll(TAG)) bounds.push([m.index, m.index + m[0].length]);
|
|
60
|
+
let at = 0;
|
|
61
|
+
for (const [s, e] of [...bounds, [src.length, src.length]]) {
|
|
62
|
+
const piece = skipped.slice(at, s);
|
|
63
|
+
if (/\S/.test(piece) && !piece.includes('\u0000')) {
|
|
64
|
+
const lead = piece.match(/^\s*/)[0].length, trail = piece.match(/\s*$/)[0].length;
|
|
65
|
+
const text = decode(piece.slice(lead, piece.length - trail));
|
|
66
|
+
if (/[\p{L}\p{N}]/u.test(text)) runs.push({ n: runs.length + 1, start: at + lead, end: at + piece.length - trail, text });
|
|
67
|
+
}
|
|
68
|
+
at = e;
|
|
69
|
+
}
|
|
70
|
+
return runs;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** `content` with each run's text replaced by `texts[n]` (encoded), from the back so offsets hold. Pure. */
|
|
74
|
+
export function withRuns(content, runs, texts) {
|
|
75
|
+
let out = String(content ?? '');
|
|
76
|
+
for (const r of [...runs].sort((a, b) => b.start - a.start)) {
|
|
77
|
+
const t = texts.get?.(r.n) ?? texts[r.n];
|
|
78
|
+
if (typeof t !== 'string' || t === r.text) continue;
|
|
79
|
+
out = out.slice(0, r.start) + encode(t) + out.slice(r.end);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The runs as the agent is shown them: one per line, numbered. */
|
|
85
|
+
export const runsText = (runs) => runs.map((r) => `${r.n}: ${r.text.replace(/\s*\n\s*/g, ' ')}`).join('\n');
|
|
86
|
+
|
|
87
|
+
/** The agent's answer as a map n → text; a line that is not `n: text` is ignored. Pure. */
|
|
88
|
+
export function parseRuns(answer) {
|
|
89
|
+
const out = new Map();
|
|
90
|
+
for (const line of unwrapAnswer(answer).split('\n')) {
|
|
91
|
+
const m = /^\s*(\d+)\s*[:.)]\s?(.*)$/.exec(line);
|
|
92
|
+
if (m) out.set(Number(m[1]), m[2].trim());
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const RULES = `# About this text
|
|
98
|
+
|
|
99
|
+
These are the text runs of one presentation slide, the words the audience reads, numbered in reading order. Each run is one stretch of text between the slide's tags; the layout, builds and styling around them belong to the presentation software and are not shown.
|
|
100
|
+
|
|
101
|
+
Answer with the same numbered runs, one per line, in the form \`N: text\`, every number present and in order. A run you leave unchanged, repeat exactly as it is. Never merge, split, reorder, add or drop a run. No markup, no quotes around a run, no code fences, no commentary before or after. Keep the language of the original.`;
|
|
102
|
+
|
|
103
|
+
/** The four tools: what each asks for, and how its answer is checked. */
|
|
104
|
+
export const TOOLS = {
|
|
105
|
+
tighten: {
|
|
106
|
+
label: 'tighten', done: 'tightened', what: 'text: tightened',
|
|
107
|
+
ask: 'Make each run shorter while keeping its meaning, its voice and its terms. Fewer words, not fewer points: cut filler, hedges and repetition, prefer the plain word. A run that is already tight stays exactly as it is. Never make a run longer.',
|
|
108
|
+
},
|
|
109
|
+
typos: {
|
|
110
|
+
label: 'fix typos and grammar', done: 'fixed', what: 'text: typos and grammar',
|
|
111
|
+
ask: 'Fix spelling, grammar, punctuation and capitalisation only. Change nothing else: not the wording, not the order of the words, not the terms, not the language. A run with nothing wrong stays exactly as it is.',
|
|
112
|
+
},
|
|
113
|
+
match: {
|
|
114
|
+
label: 'match the script', done: 'matched to the script', what: 'text: matched to the script',
|
|
115
|
+
ask: 'The slide\'s speaker notes, what the presenter says while this slide is on screen, are given under # Notes. Reword the runs so they agree with the notes: the same terms, the same claims, the same order of ideas. Keep each run about as long as it is; a run that already agrees stays exactly as it is.',
|
|
116
|
+
},
|
|
117
|
+
custom: {
|
|
118
|
+
label: 'custom instruction', done: 'rewritten', what: 'text: rewritten',
|
|
119
|
+
ask: null, // the author's own words (`instruction`)
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** The whole ask for one slide's runs. */
|
|
124
|
+
export function rewritePrompt(tool, runs, { instruction = '', notes = '' } = {}) {
|
|
125
|
+
const t = TOOLS[tool] ?? TOOLS.custom;
|
|
126
|
+
const task = t.ask ?? `Apply this instruction to every run it applies to, and leave the others exactly as they are: ${String(instruction).trim()}`;
|
|
127
|
+
return `# Instructions\n\n${task}\n\n${RULES}${tool === 'match' && notes ? `\n\n# Notes\n\n${notes}` : ''}\n\n# Runs\n\n${runsText(runs)}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Character edit distance, for the typo check — the runs are short. */
|
|
131
|
+
export function editDistance(a, b) {
|
|
132
|
+
const m = a.length, n = b.length;
|
|
133
|
+
if (!m) return n;
|
|
134
|
+
if (!n) return m;
|
|
135
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
136
|
+
for (let i = 1; i <= m; i++) {
|
|
137
|
+
const cur = [i];
|
|
138
|
+
for (let j = 1; j <= n; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
139
|
+
prev = cur;
|
|
140
|
+
}
|
|
141
|
+
return prev[n];
|
|
142
|
+
}
|
|
143
|
+
const words = (s) => String(s).trim().split(/\s+/).filter(Boolean).length;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Why an answer cannot be written, or null: every run answered, none
|
|
147
|
+
* emptied, no markup, and the tool's own rule — a typo fix that changed more
|
|
148
|
+
* than a few characters per word reworded; a tighten that lengthened a run;
|
|
149
|
+
* a match or a custom rewrite that doubled or halved the slide. Pure.
|
|
150
|
+
*/
|
|
151
|
+
export function rewriteProblem(tool, runs, answers) {
|
|
152
|
+
if (!answers?.size) return 'the agent answered nothing the check could read';
|
|
153
|
+
for (const r of runs) {
|
|
154
|
+
if (!answers.has(r.n)) return `the agent skipped run ${r.n}`;
|
|
155
|
+
const a = answers.get(r.n);
|
|
156
|
+
if (!a.trim()) return `the agent emptied run ${r.n}`;
|
|
157
|
+
if (/[<>]/.test(a)) return `the agent answered run ${r.n} with markup`;
|
|
158
|
+
if (tool === 'typos' && editDistance(r.text, a) > 3 * words(r.text) + 2) return `the agent reworded run ${r.n} — a typo fix changes a few characters, not the words`;
|
|
159
|
+
if (tool === 'tighten' && a.length > r.text.length + 2) return `the agent made run ${r.n} longer`;
|
|
160
|
+
}
|
|
161
|
+
const before = runs.reduce((n, r) => n + words(r.text), 0);
|
|
162
|
+
const after = runs.reduce((n, r) => n + words(answers.get(r.n)), 0);
|
|
163
|
+
if (tool !== 'typos' && tool !== 'tighten') {
|
|
164
|
+
if (after > 2.5 * Math.max(1, before)) return 'the agent\'s answer is far longer than the slide — commentary, not a rewrite';
|
|
165
|
+
if (after < 0.4 * before) return 'the agent\'s answer is far shorter than the slide — points were dropped';
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A section body's inside: from after its opening tag to its own close. */
|
|
171
|
+
function insideOf(body) {
|
|
172
|
+
const open = body.indexOf('>');
|
|
173
|
+
const close = sectionCloseIndex(body);
|
|
174
|
+
if (open < 0 || close < 0 || close < open) return null;
|
|
175
|
+
return { from: open + 1, to: close };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The slides a tool can work on: `[{ slide, runs, notes }]` for every shown
|
|
180
|
+
* section with text (or those in `only`). Pure.
|
|
181
|
+
*/
|
|
182
|
+
export function rewritable(html, only = null) {
|
|
183
|
+
const bodies = sectionBodies(html);
|
|
184
|
+
return bodies.flatMap((body, i) => {
|
|
185
|
+
const slide = i + 1;
|
|
186
|
+
if (only && !only.includes(slide)) return [];
|
|
187
|
+
if (isHiddenSection(body)) return [];
|
|
188
|
+
const at = insideOf(body);
|
|
189
|
+
if (!at) return [];
|
|
190
|
+
const runs = textRuns(body.slice(at.from, at.to));
|
|
191
|
+
if (!runs.length) return [];
|
|
192
|
+
const aside = NOTES_ASIDE.exec(body);
|
|
193
|
+
return [{ slide, runs, notes: aside ? cleanNotes(aside[1]) : '' }];
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* One slide's runs, rewritten: the agent is asked, its answer parsed and
|
|
199
|
+
* checked. Resolves to `{ ok, texts }` (a Map n → text) or `{ ok: false, why }`.
|
|
200
|
+
*/
|
|
201
|
+
export async function rewriteRuns(tool, runs, {
|
|
202
|
+
instruction = '', notes = '', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
|
|
203
|
+
resolveAgent = agentAsk, exec = ask, signal = null,
|
|
204
|
+
} = {}) {
|
|
205
|
+
const cmd = resolveAgent(agent, rewritePrompt(tool, runs, { instruction, notes }), { env });
|
|
206
|
+
if (!cmd) return { ok: false, why: agentUnavailable(agent, detectAgents({ env })) };
|
|
207
|
+
const out = await exec(cmd, cwd, timeoutMs, signal);
|
|
208
|
+
if (signal?.aborted) return { ok: false, why: 'stopped' };
|
|
209
|
+
if (out == null) return { ok: false, why: 'the agent did not answer in time' };
|
|
210
|
+
const texts = parseRuns(out);
|
|
211
|
+
const why = rewriteProblem(tool, runs, texts);
|
|
212
|
+
if (why) return { ok: false, why };
|
|
213
|
+
const changed = runs.some((r) => texts.get(r.n) !== r.text);
|
|
214
|
+
return { ok: true, texts, changed };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The answers written into `html`: each slide that passed and changed, and
|
|
219
|
+
* only if its runs still read exactly as they did when the agent was asked.
|
|
220
|
+
* Returns `{ html, stale }`.
|
|
221
|
+
*/
|
|
222
|
+
export function applyRewritten(html, answers) {
|
|
223
|
+
let out = html;
|
|
224
|
+
const stale = [];
|
|
225
|
+
for (const a of answers) {
|
|
226
|
+
if (!a.ok || !a.changed) continue;
|
|
227
|
+
const { parts, idx } = locateSlide(out, a.slide);
|
|
228
|
+
const body = parts[idx];
|
|
229
|
+
const at = insideOf(body);
|
|
230
|
+
const now = at ? textRuns(body.slice(at.from, at.to)) : [];
|
|
231
|
+
if (!at || now.length !== a.runs.length || now.some((r, i) => r.text !== a.runs[i].text)) { stale.push(a.slide); continue; }
|
|
232
|
+
parts[idx] = body.slice(0, at.from) + withRuns(body.slice(at.from, at.to), now, a.texts) + body.slice(at.to);
|
|
233
|
+
out = parts.join('');
|
|
234
|
+
}
|
|
235
|
+
return { html: out, stale };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Ask the agent to run `tool` over `slides` (1-based, or null for every shown
|
|
240
|
+
* slide with text) of the deck in `html`. Resolves to `{ html, results,
|
|
241
|
+
* answers }` like enhanceDeck: one `{ slide, ok, changed, why }` per slide,
|
|
242
|
+
* and the raw answers for a caller that applies them to a newer copy.
|
|
243
|
+
*/
|
|
244
|
+
export async function rewriteDeck(html, tool, slides = null, {
|
|
245
|
+
instruction = '', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
|
|
246
|
+
concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onSlide = () => {}, signal = null,
|
|
247
|
+
} = {}) {
|
|
248
|
+
if (!resolveAgent(agent, 'x', { env })) throw new Error(agentUnavailable(agent, detectAgents({ env })));
|
|
249
|
+
const todo = rewritable(html, slides);
|
|
250
|
+
const answers = [];
|
|
251
|
+
let next = 0, finished = 0;
|
|
252
|
+
const worker = async () => {
|
|
253
|
+
while (next < todo.length && !signal?.aborted) {
|
|
254
|
+
const { slide, runs, notes } = todo[next++];
|
|
255
|
+
const a = await rewriteRuns(tool, runs, { instruction, notes, agent, cwd, env, timeoutMs, resolveAgent, exec, signal });
|
|
256
|
+
const r = { slide, ok: a.ok, changed: !!(a.ok && a.changed), ...(a.ok ? {} : { why: a.why }) };
|
|
257
|
+
answers.push({ ...r, runs, texts: a.texts ?? null });
|
|
258
|
+
onSlide({ ...r, done: ++finished, of: todo.length });
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, todo.length) }, worker));
|
|
262
|
+
answers.sort((a, b) => a.slide - b.slide);
|
|
263
|
+
const results = answers.map(({ runs, texts, ...r }) => r);
|
|
264
|
+
return { html: applyRewritten(html, answers).html, results, answers };
|
|
265
|
+
}
|