decklight 0.9.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 +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- 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 +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- 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/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- 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 +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- 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 +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- 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 +825 -117
- 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/edit-handover.mjs
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
// waiting on it. Nothing here reads those bindings until a request arrives.
|
|
23
23
|
|
|
24
24
|
import { existsSync } from 'node:fs';
|
|
25
|
-
import {
|
|
25
|
+
import { randomUUID } from 'node:crypto';
|
|
26
|
+
import { keepAwake } from './keep-awake.mjs';
|
|
27
|
+
import { basename, dirname, relative, resolve, sep } from 'node:path';
|
|
26
28
|
import { fileURLToPath } from 'node:url';
|
|
27
29
|
import { spawn } from 'node:child_process';
|
|
28
30
|
|
|
@@ -30,9 +32,25 @@ import { EXPORT_KINDS, alreadyOneFile, videoExportProblem } from './edit.mjs';
|
|
|
30
32
|
import { oneline, remoteLine, remoteState } from './git.mjs';
|
|
31
33
|
import { configTheme } from './runtime-link.mjs';
|
|
32
34
|
import { CommandError } from './util.mjs';
|
|
35
|
+
import { unleashedEnv } from './supervise.mjs';
|
|
33
36
|
import { THEME_NAME, GEN_THEME } from '../tools/render-theme.mjs';
|
|
34
37
|
import { locateSlide, sectionChildRanges } from '../tools/deck-html.mjs';
|
|
35
38
|
|
|
39
|
+
/** How long a stopped child has to clean up after SIGTERM before SIGKILL. */
|
|
40
|
+
const STOP_GRACE_MS = 5000;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Why `module` cannot name a chapter to bundle, or null when it can (or is
|
|
44
|
+
* absent: the whole deck). The bundle card sends the chapter's NUMBER, never
|
|
45
|
+
* its title: `--module` takes a full title too, but a title is free text and
|
|
46
|
+
* a number is the one thing the picker and the CLI count the same way.
|
|
47
|
+
* Whether the deck has that chapter is the bundler's to say.
|
|
48
|
+
*/
|
|
49
|
+
export function moduleProblem(module) {
|
|
50
|
+
if (module == null) return null;
|
|
51
|
+
return /^[1-9]\d{0,3}$/.test(String(module)) ? null : 'the module is a chapter number, counting from 1';
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
/**
|
|
37
55
|
* Put the hand-over routes into `routes`, the table cli/edit.mjs dispatches
|
|
38
56
|
* on, and hand it back.
|
|
@@ -43,10 +61,15 @@ import { locateSlide, sectionChildRanges } from '../tools/deck-html.mjs';
|
|
|
43
61
|
* `broadcast` for the export's progress, and `gitOn()` for whether this
|
|
44
62
|
* session has a repository to publish from: a getter, not a copy, because it
|
|
45
63
|
* is a `let` of editMain's and the answer is whatever it holds when a publish
|
|
46
|
-
* asks.
|
|
64
|
+
* asks. `onExport` hears `{ kind, what }` when an export starts and null when
|
|
65
|
+
* it ends, so `/deck/ping` can tell a page that loads mid-render there is one
|
|
66
|
+
* to stop.
|
|
47
67
|
*/
|
|
48
|
-
export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn, broadcast = () => {} }) {
|
|
68
|
+
export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn, broadcast = () => {}, onExport = () => {}, inhibit = keepAwake }) {
|
|
49
69
|
let exporting = false; // an export in flight — one browser, one output path, any kind
|
|
70
|
+
let latest = null;
|
|
71
|
+
const results = new Map();
|
|
72
|
+
let stopExport = null; // stops it, while it is one that can be stopped
|
|
50
73
|
let publishing = false; // a publish in flight — one push at a time
|
|
51
74
|
|
|
52
75
|
// ── hand-over: the files this deck can be written out as, and publishing ───
|
|
@@ -79,8 +102,35 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
79
102
|
* - it must SAY WHERE IT IS. An export is tens of seconds, so each slide
|
|
80
103
|
* is announced on the `export` channel of the same SSE stream the agent
|
|
81
104
|
* chip rides, and the deck rewrites its one progress row from it.
|
|
105
|
+
*
|
|
106
|
+
* And it can be STOPPED (`exportStopRoute`), so a ten-minute video started
|
|
107
|
+
* on the wrong slides is not a reason to kill the session it runs in.
|
|
82
108
|
*/
|
|
83
|
-
async function exportRoute(
|
|
109
|
+
async function exportRoute(request) {
|
|
110
|
+
const id = request.url.searchParams.get('id') ?? randomUUID();
|
|
111
|
+
if (!/^[a-z0-9-]{1,80}$/i.test(id)) return request.json(400, { ok: false, error: 'invalid export ID' });
|
|
112
|
+
if (results.has(id)) return request.json(409, { ok: false, error: 'export ID already used' });
|
|
113
|
+
let snapshot = { id, state: 'pending' };
|
|
114
|
+
results.set(id, snapshot);
|
|
115
|
+
const update = (data) => {
|
|
116
|
+
snapshot = { ...snapshot, ...data };
|
|
117
|
+
results.set(id, snapshot);
|
|
118
|
+
latest = snapshot;
|
|
119
|
+
broadcast('export', snapshot);
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
const { code, result } = await runExport(request, { update, json: (code, result) => ({ code, result }) });
|
|
123
|
+
if (snapshot.state === 'pending') results.set(id, { id, state: 'done', kind: result.kind, result });
|
|
124
|
+
else update({ state: 'done', result, ...result });
|
|
125
|
+
return request.json(code, result);
|
|
126
|
+
} finally {
|
|
127
|
+
if (results.get(id)?.state === 'pending') results.delete(id);
|
|
128
|
+
const finished = [...results].filter(([, job]) => job.state === 'done');
|
|
129
|
+
for (const [key] of finished.slice(0, -32)) results.delete(key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function runExport({ body }, { update, json }) {
|
|
84
134
|
const req = JSON.parse(body || '{}');
|
|
85
135
|
const kind = req.kind ?? 'pptx';
|
|
86
136
|
const job = EXPORT_KINDS[kind];
|
|
@@ -108,6 +158,8 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
108
158
|
if (alreadyOneFile(readDeck())) {
|
|
109
159
|
return json(409, { ok: false, error: 'this deck is already one file — send it as it is' });
|
|
110
160
|
}
|
|
161
|
+
const bad = moduleProblem(req.module);
|
|
162
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
111
163
|
}
|
|
112
164
|
const unmarked = await unmarkedOnScreen(req.theme, { carried: kind === 'bundle' });
|
|
113
165
|
if (unmarked) return json(409, { ok: false, unmarked, error: `${unmarked} is not marked for this deck` });
|
|
@@ -117,90 +169,208 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
117
169
|
if (bad) return json(400, { ok: false, error: bad });
|
|
118
170
|
}
|
|
119
171
|
if (exporting) return json(409, { ok: false, error: 'an export is already running' });
|
|
172
|
+
const video = kind === 'video' ? await import('../tools/video.mjs') : null;
|
|
173
|
+
const narration = req.synthesize?.dir ?? req.narration ?? null;
|
|
174
|
+
let track, report, html, range;
|
|
175
|
+
const anyway = req.allowStale === true;
|
|
176
|
+
const readTrack = () => {
|
|
177
|
+
if (req.silent) return null;
|
|
178
|
+
const dir = narration ? resolve(dirname(deckPath), narration) : null;
|
|
179
|
+
if (req.synthesize && !existsSync(resolve(dir, 'manifest.json'))) return { dir, slides: [], fresh: true };
|
|
180
|
+
return video.resolveNarration(deckPath, dir, { allowEmpty: true });
|
|
181
|
+
};
|
|
182
|
+
const checkTrack = () => video.checkVideoTrack(html, track, range, { face: req.face !== 'off', character: req.character });
|
|
183
|
+
const needsFix = () => report.missing.length || report.stale.length || report.lipsync.length;
|
|
184
|
+
const hasTrackVoice = () => track?.fresh || !!(track?.engine && (track.voice || track.voiceId));
|
|
185
|
+
const preflight = () => {
|
|
186
|
+
const engine = track?.engine ?? (track?.fresh ? req.synthesize.engine : null);
|
|
187
|
+
const audioSlides = new Set([...report.missing, ...report.stale]).size;
|
|
188
|
+
return json(409, { ok: false, error: 'the selected voice needs attention before recording', preflight: {
|
|
189
|
+
...report, engine, audioSlides, canFix: !audioSlides || hasTrackVoice(),
|
|
190
|
+
...(audioSlides && engine && !hasTrackVoice() ? { voiceUnknown: true } : {}),
|
|
191
|
+
metered: ['elevenlabs', 'gemini', 'chirp'].includes(engine),
|
|
192
|
+
} });
|
|
193
|
+
};
|
|
194
|
+
if (video) {
|
|
195
|
+
try {
|
|
196
|
+
html = readDeck();
|
|
197
|
+
range = video.parseSlideRange(req.slides, video.extractHolds(html).length);
|
|
198
|
+
track = readTrack();
|
|
199
|
+
if (!anyway) report = await checkTrack();
|
|
200
|
+
} catch (e) {
|
|
201
|
+
return json(400, { ok: false, error: oneline(e) });
|
|
202
|
+
}
|
|
203
|
+
if (!anyway && needsFix() && (req.fix !== true || ((report.missing.length || report.stale.length)
|
|
204
|
+
&& !hasTrackVoice()))) return preflight();
|
|
205
|
+
}
|
|
120
206
|
const { findChrome } = await import('../tools/chrome.mjs');
|
|
121
207
|
// every file but the bundle is a render; the bundle launches no browser
|
|
122
208
|
if (kind !== 'bundle' && !findChrome()) {
|
|
123
209
|
return json(503, { ok: false, error: 'no Chrome found — install one, or point $CHROME at it' });
|
|
124
210
|
}
|
|
211
|
+
if (exporting) return json(409, { ok: false, error: 'an export is already running' });
|
|
125
212
|
exporting = true;
|
|
213
|
+
// Every kind but the bundle: the bundle launches nothing and is seconds
|
|
214
|
+
// from done, so there is nothing to stop part-way.
|
|
215
|
+
const stop = new AbortController();
|
|
216
|
+
stopExport = kind === 'bundle' ? null : () => stop.abort();
|
|
217
|
+
onExport({ kind, what: job.what });
|
|
126
218
|
const started = Date.now();
|
|
127
219
|
console.log(` export: ${basename(deckPath)} → ${job.what}${req.slides ? ` of slides ${req.slides}` : ''}`
|
|
128
220
|
+ `${req.synthesize ? `, voiced by ${req.synthesize.engine} into ${req.synthesize.dir}/` : ''} …`);
|
|
129
|
-
|
|
221
|
+
let awake;
|
|
130
222
|
try {
|
|
131
|
-
|
|
223
|
+
awake = await inhibit({ display: kind === 'video' && req.render === 'live' });
|
|
224
|
+
update({ state: 'start', kind, what: job.what, awake: awake.active, displayAwake: awake.displayActive });
|
|
225
|
+
if (stop.signal.aborted) return stopped();
|
|
226
|
+
let out, code, reason = null, subs = null, notes = null, droppedFrames = 0;
|
|
132
227
|
if (kind === 'video') {
|
|
133
|
-
const { videoOut, videoProgress, voiceoverProgress, subtitlesOut } =
|
|
228
|
+
const { videoOut, videoProgress, voiceoverProgress, subtitlesOut, revoiceStale } = video;
|
|
134
229
|
out = videoOut(deckPath, req.slides || null, req.format || 'mp4');
|
|
135
230
|
subs = req.subtitles === 'file' ? subtitlesOut(out, req.format || 'mp4') : null;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
231
|
+
const tick = (phase) => (n, of) => update({ state: 'slide', phase, n, of });
|
|
232
|
+
if (!anyway && needsFix()) {
|
|
233
|
+
const slides = [...new Set([...report.missing, ...report.stale])].sort((a, b) => a - b);
|
|
234
|
+
if (slides.length && track.engine) {
|
|
235
|
+
const result = await revoiceStale({
|
|
236
|
+
html, narration: track, stale: slides, missing: report.missing, lipsync: null,
|
|
237
|
+
onSlide: tick('voice'), signal: stop.signal,
|
|
238
|
+
});
|
|
239
|
+
if (!result.ok) ({ code, reason } = { code: 1, reason: result.why });
|
|
240
|
+
} else if (slides.length) {
|
|
241
|
+
({ code, reason } = await runTool('voiceover', [...await voiceoverArgv(req), '--no-face'],
|
|
242
|
+
voiceoverProgress(tick('voice')), stop.signal));
|
|
243
|
+
}
|
|
244
|
+
if (!code && !stop.signal.aborted) {
|
|
245
|
+
track = readTrack();
|
|
246
|
+
report = await checkTrack();
|
|
247
|
+
if (report.lipsync.length) {
|
|
248
|
+
let done = 0;
|
|
249
|
+
const files = [...new Set(report.lipsync.map((item) => item.audio))];
|
|
250
|
+
const lipTick = tick('lipsync');
|
|
251
|
+
lipTick(0, files.length);
|
|
252
|
+
({ code, reason } = await runTool('lipsync',
|
|
253
|
+
[track.dir, '--visemes', '--no-veo', '--audio-files', JSON.stringify(files)],
|
|
254
|
+
(line) => { if (/cues →/.test(line)) lipTick(++done, files.length); }, stop.signal));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (!stop.signal.aborted) {
|
|
258
|
+
html = readDeck();
|
|
259
|
+
range = video.parseSlideRange(req.slides, video.extractHolds(html).length);
|
|
260
|
+
track = readTrack();
|
|
261
|
+
report = await checkTrack();
|
|
262
|
+
if (needsFix()) {
|
|
263
|
+
if (reason) report.repairError = reason;
|
|
264
|
+
return preflight();
|
|
265
|
+
}
|
|
266
|
+
code = 0;
|
|
267
|
+
}
|
|
142
268
|
}
|
|
143
|
-
if (!code) {
|
|
144
|
-
const
|
|
269
|
+
if (!code && !stop.signal.aborted) {
|
|
270
|
+
const progress = videoProgress(tick('render'));
|
|
145
271
|
({ code, reason } = await runTool('video', [deckPath, '-o', out, ...themed,
|
|
146
272
|
...(req.slides ? ['--slides', req.slides] : []),
|
|
147
273
|
...(req.format ? ['--format', req.format] : []),
|
|
148
274
|
...(req.quality ? ['--quality', req.quality] : []),
|
|
275
|
+
...(req.render ? ['--render', req.render] : []),
|
|
149
276
|
...(req.subtitles ? ['--subtitles', req.subtitles] : []),
|
|
150
|
-
...(
|
|
151
|
-
|
|
152
|
-
...(
|
|
153
|
-
|
|
277
|
+
...(req.face === 'off' ? ['--no-face'] : []),
|
|
278
|
+
...(req.character ? ['--character', req.character] : []),
|
|
279
|
+
...(narration && track?.slides.length ? ['--narration', track.dir] : narration || req.silent ? ['--no-narration'] : []),
|
|
280
|
+
// Preflight owns repairs for the card, including the as-is path.
|
|
281
|
+
'--no-revoice', '--no-remake-visemes',
|
|
282
|
+
...(anyway ? ['--allow-stale'] : [])],
|
|
283
|
+
(line) => {
|
|
284
|
+
const dropped = /^\s+live capture: warning — (\d+) dropped/.exec(line);
|
|
285
|
+
if (dropped) droppedFrames = Number(dropped[1]);
|
|
286
|
+
progress(line);
|
|
287
|
+
}, stop.signal));
|
|
154
288
|
}
|
|
155
289
|
} else if (kind === 'bundle') {
|
|
156
|
-
//
|
|
157
|
-
// `decklight bundle` write the same one
|
|
158
|
-
// (
|
|
159
|
-
//
|
|
160
|
-
//
|
|
290
|
+
// No -o: the CLI names the file, beside the deck, so the row and
|
|
291
|
+
// `decklight bundle` write the same one — `<deck>-standalone.html`,
|
|
292
|
+
// or for one chapter (`module`, its number: --module) the chapter's
|
|
293
|
+
// own name, which never overwrites the whole deck's. `audio` is its
|
|
294
|
+
// --audio ('original', 'aac' or 'opus'), the recorded voice carried
|
|
295
|
+
// inside. bundleMain returns nothing on success and throws a sentence
|
|
296
|
+
// on a refusal (an unknown chapter among them, before any file is
|
|
297
|
+
// written) — the catch below says it. The notes it prints after the
|
|
298
|
+
// file come back too: which chapter went in, and where the audio is.
|
|
161
299
|
const { bundleMain } = await import('./bundle.mjs');
|
|
162
300
|
const { AUDIO_CHOICES } = await import('./bundle-audio.mjs');
|
|
163
|
-
|
|
164
|
-
code = (await bundleMain([deckPath,
|
|
165
|
-
...(
|
|
301
|
+
const report = {};
|
|
302
|
+
code = (await bundleMain([deckPath, ...(req.theme ? ['--theme', req.theme] : []),
|
|
303
|
+
...(req.module != null ? ['--module', String(req.module)] : []),
|
|
304
|
+
...(AUDIO_CHOICES.includes(req.audio) ? ['--audio', req.audio] : [])], { report })) ?? 0;
|
|
305
|
+
out = report.out;
|
|
306
|
+
notes = report.notices;
|
|
166
307
|
} else if (kind === 'pptx') {
|
|
167
308
|
const { pptxMain, pptxOut } = await import('./pptx-export.mjs');
|
|
168
309
|
out = pptxOut(deckPath);
|
|
169
310
|
code = await pptxMain([deckPath, ...themed], {
|
|
170
311
|
log: (line) => console.log(` ${line}`),
|
|
171
|
-
onSlide: (n, of) =>
|
|
312
|
+
onSlide: (n, of) => update({ state: 'slide', n, of }),
|
|
313
|
+
signal: stop.signal,
|
|
172
314
|
});
|
|
173
315
|
} else {
|
|
174
316
|
const { pdfMain, pdfOut } = await import('./pdf.mjs');
|
|
175
317
|
out = pdfOut(deckPath, null, job.variant);
|
|
176
|
-
code = await pdfMain([deckPath, ...themed, ...(job.variant ? [`--${job.variant}`] : [])]);
|
|
318
|
+
code = await pdfMain([deckPath, ...themed, ...(job.variant ? [`--${job.variant}`] : [])], { signal: stop.signal });
|
|
177
319
|
}
|
|
320
|
+
if (stop.signal.aborted) return stopped();
|
|
178
321
|
const file = relative(process.cwd(), out) || basename(out);
|
|
179
322
|
const seconds = Math.round((Date.now() - started) / 100) / 10;
|
|
180
323
|
if (code !== 0) {
|
|
181
|
-
broadcast('export', { state: 'done', kind, ok: false });
|
|
182
324
|
return json(500, { ok: false, error: reason ?? 'the export refused — see the edit server\'s output' });
|
|
183
325
|
}
|
|
184
326
|
// A render with nothing spoken writes no subtitles and says so; the deck
|
|
185
327
|
// is told of a file only when there is one to open.
|
|
186
328
|
const voiced = {
|
|
187
|
-
...(req.synthesize ? { voiced: req.synthesize.dir } : {}),
|
|
329
|
+
...(req.synthesize && track?.slides.length ? { voiced: req.synthesize.dir } : {}),
|
|
188
330
|
...(subs && existsSync(subs) ? { subtitles: relative(process.cwd(), subs) || basename(subs) } : {}),
|
|
189
331
|
};
|
|
190
|
-
|
|
191
|
-
|
|
332
|
+
return json(200, { ok: true, kind, what: job.what, file, seconds, ...voiced,
|
|
333
|
+
...(notes ? { notes } : {}), ...(droppedFrames ? { droppedFrames } : {}) });
|
|
192
334
|
} catch (e) {
|
|
335
|
+
if (stop.signal.aborted) return stopped();
|
|
193
336
|
// A render that hangs or a Chrome that dies is the export's problem,
|
|
194
337
|
// never the session's: the message goes back to the palette and the
|
|
195
|
-
// server carries on serving the deck.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
338
|
+
// server carries on serving the deck. A command's refusal is a sentence
|
|
339
|
+
// and then, at most, a list it introduces ("— its chapters are:"); the
|
|
340
|
+
// sentence is what fits on a card, and the card has the list already.
|
|
341
|
+
const said = e instanceof CommandError ? e.message.split('\n')[0].replace(/\s+—[^—]*:$/, '') : oneline(e);
|
|
342
|
+
console.log(` export: ${job.what} failed — ${said}`);
|
|
343
|
+
return json(500, { ok: false, error: said });
|
|
199
344
|
} finally {
|
|
345
|
+
await awake?.release();
|
|
200
346
|
exporting = false;
|
|
347
|
+
stopExport = null;
|
|
348
|
+
onExport(null);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Not a failure: what was asked for. The voice a stopped export had
|
|
352
|
+
// already synthesized stays where it was written — it is the deck's own
|
|
353
|
+
// folder, and the next export finds those slides done.
|
|
354
|
+
function stopped() {
|
|
355
|
+
const kept = req.synthesize && existsSync(resolve(dirname(deckPath), req.synthesize.dir)) ? { voiced: req.synthesize.dir } : {};
|
|
356
|
+
console.log(` export: ${job.what} stopped — nothing written`);
|
|
357
|
+
return json(200, { ok: false, stopped: true, kind, what: job.what, ...kept });
|
|
201
358
|
}
|
|
202
359
|
}
|
|
203
360
|
|
|
361
|
+
/**
|
|
362
|
+
* POST /deck/edit/export/stop — stop the export in flight. Answers at once;
|
|
363
|
+
* the export's own request is the one that says it stopped (`{ stopped }`),
|
|
364
|
+
* once its children are gone and its scratch files with them.
|
|
365
|
+
*/
|
|
366
|
+
function exportStopRoute({ json }) {
|
|
367
|
+
if (!exporting) return json(409, { ok: false, error: 'no export is running' });
|
|
368
|
+
if (!stopExport) return json(409, { ok: false, error: 'a bundle cannot be stopped part-way — it is seconds from done' });
|
|
369
|
+
console.log(' export: stopping …');
|
|
370
|
+
stopExport();
|
|
371
|
+
return json(200, { ok: true });
|
|
372
|
+
}
|
|
373
|
+
|
|
204
374
|
/**
|
|
205
375
|
* `decklight video` (and `decklight narrate` before it, when the export
|
|
206
376
|
* voices its slides), run as CHILDREN rather than through their `main`s like
|
|
@@ -211,12 +381,25 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
211
381
|
*
|
|
212
382
|
* Served from the same root `pptx` picks: the current directory when the deck
|
|
213
383
|
* is under it, its own directory otherwise.
|
|
384
|
+
*
|
|
385
|
+
* `signal` stops it: SIGTERM, which `decklight video` answers by killing its
|
|
386
|
+
* Chrome and ffmpeg and clearing its scratch frames, then SIGKILL for a child
|
|
387
|
+
* that has not gone a few seconds later.
|
|
214
388
|
*/
|
|
215
|
-
function runTool(name, argv, onLine) {
|
|
389
|
+
function runTool(name, argv, onLine, signal = null) {
|
|
216
390
|
const script = fileURLToPath(new URL(`../tools/${name}.mjs`, import.meta.url));
|
|
217
391
|
const cwd = deckPath.startsWith(process.cwd() + sep) ? process.cwd() : dirname(deckPath);
|
|
218
392
|
return new Promise((done) => {
|
|
219
|
-
const
|
|
393
|
+
const stopOverIPC = process.platform === 'win32' && name === 'video';
|
|
394
|
+
const stdio = ['ignore', 'pipe', 'pipe', ...(stopOverIPC ? ['ipc'] : [])];
|
|
395
|
+
const child = spawn(process.execPath, [script, ...argv], { cwd, env: unleashedEnv(), stdio });
|
|
396
|
+
let hard = null;
|
|
397
|
+
const stop = () => {
|
|
398
|
+
if (stopOverIPC && child.connected) child.send('stop-video', () => {});
|
|
399
|
+
else child.kill('SIGTERM');
|
|
400
|
+
hard = setTimeout(() => child.kill('SIGKILL'), STOP_GRACE_MS);
|
|
401
|
+
};
|
|
402
|
+
if (signal?.aborted) stop(); else signal?.addEventListener('abort', stop, { once: true });
|
|
220
403
|
let pending = '', err = '';
|
|
221
404
|
child.stdout.on('data', (chunk) => {
|
|
222
405
|
pending += chunk;
|
|
@@ -230,6 +413,8 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
230
413
|
child.stderr.on('data', (chunk) => { err += chunk; process.stdout.write(String(chunk).replace(/^/gm, ' ')); });
|
|
231
414
|
child.on('error', (e) => done({ code: 1, reason: oneline(e) }));
|
|
232
415
|
child.on('close', (code) => {
|
|
416
|
+
clearTimeout(hard);
|
|
417
|
+
signal?.removeEventListener('abort', stop);
|
|
233
418
|
// the command's own refusal is the sentence the deck shows
|
|
234
419
|
const said = err.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
235
420
|
const prefix = `decklight ${name}:`;
|
|
@@ -358,8 +543,12 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
358
543
|
if (kind !== 'bundle') return json(400, { ok: false, error: `no estimate for ${kind ?? 'that'} — only a bundle has one` });
|
|
359
544
|
const theme = url.searchParams.get('theme');
|
|
360
545
|
if (theme != null && !THEME_NAME.test(theme)) return json(400, { ok: false, error: 'the theme is a theme name' });
|
|
546
|
+
// one chapter is estimated as one chapter: its slides, its share of the audio
|
|
547
|
+
const module = url.searchParams.get('module');
|
|
548
|
+
const bad = moduleProblem(module);
|
|
549
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
361
550
|
const { bundleMain } = await import('./bundle.mjs');
|
|
362
|
-
const estimate = (argv) => bundleMain([deckPath, ...argv], { estimate: true });
|
|
551
|
+
const estimate = (argv) => bundleMain([deckPath, ...argv, ...(module != null ? ['--module', module] : [])], { estimate: true });
|
|
363
552
|
try {
|
|
364
553
|
// in the theme on screen, as the export will be — or, when that one
|
|
365
554
|
// cannot be bundled yet (the export asks to mark it first), in the
|
|
@@ -413,6 +602,28 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
413
602
|
return json(200, { ok: true, file: basename(deckPath), lines: span(range.start, range.end), blocks, findings });
|
|
414
603
|
}
|
|
415
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Every finding `decklight check`'s static half has for the whole deck,
|
|
607
|
+
* for Check deck… (PRESENTING_EDITING): head-level ones (a design system
|
|
608
|
+
* the deck is behind, a theme off the brand, a missing file) with
|
|
609
|
+
* `slide: null`, then each slide's, the same rule ids `check --json`
|
|
610
|
+
* prints — and on each the quick fix the server could apply for it
|
|
611
|
+
* (cli/check-fixes.mjs), so the row says what pressing it would do. Read-
|
|
612
|
+
* only, like the inspector's read above; the render half is the open
|
|
613
|
+
* page's own (src/core/deckcheck.js measures it).
|
|
614
|
+
*/
|
|
615
|
+
async function checkRoute({ json }) {
|
|
616
|
+
const { sectionRanges, staticFindings } = await import('./check.mjs');
|
|
617
|
+
const { quickFixes } = await import('./check-fixes.mjs');
|
|
618
|
+
const html = readDeck();
|
|
619
|
+
const dir = dirname(deckPath);
|
|
620
|
+
const found = staticFindings(html, { dir, deck: basename(deckPath) });
|
|
621
|
+
return json(200, {
|
|
622
|
+
ok: true, file: basename(deckPath), slides: sectionRanges(html).length,
|
|
623
|
+
findings: quickFixes(found, html, dir, { deck: basename(deckPath) }),
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
416
627
|
/**
|
|
417
628
|
* The marketplace theme on screen that this deck does not mark, as a
|
|
418
629
|
* reference — or null. An export or a publish of an unmarked theme would
|
|
@@ -437,8 +648,14 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
437
648
|
}
|
|
438
649
|
|
|
439
650
|
routes.set('POST /deck/edit/export', exportRoute);
|
|
651
|
+
routes.set('GET /deck/edit/export/status', ({ url, json }) => {
|
|
652
|
+
const id = url.searchParams.get('id');
|
|
653
|
+
return json(200, { ok: true, job: id ? results.get(id) ?? null : latest });
|
|
654
|
+
});
|
|
655
|
+
routes.set('POST /deck/edit/export/stop', exportStopRoute);
|
|
440
656
|
routes.set('GET /deck/edit/export/estimate', exportEstimateRoute);
|
|
441
657
|
routes.set('GET /deck/edit/inspect', inspectRoute);
|
|
658
|
+
routes.set('GET /deck/edit/check', checkRoute);
|
|
442
659
|
routes.set('GET /deck/edit/publish/plan', publishPlanRoute);
|
|
443
660
|
routes.set('POST /deck/edit/publish', publishRoute);
|
|
444
661
|
return routes;
|