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
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The routes that HAND THE DECK OVER: writing it out as another file (pptx,
|
|
5
|
+
// pdf, a one-file bundle, a video), saying how big a bundle would be before
|
|
6
|
+
// it is written, and publishing it to a page the world can read (SPEC
|
|
7
|
+
// PRESENTING). The inspector's read of where a slide lives in the file sits
|
|
8
|
+
// here too: like the rest, it reads the deck and never writes it.
|
|
9
|
+
//
|
|
10
|
+
// They came out of cli/edit.mjs because none of them edits the deck. What they
|
|
11
|
+
// share is the machinery of a long job run beside a live session: a headless
|
|
12
|
+
// Chrome or a child process, a progress feed on the event channel, a flag
|
|
13
|
+
// that keeps two of them from running at once, and the question every one of
|
|
14
|
+
// them asks first, whether the theme on screen is one the deck marks
|
|
15
|
+
// (`unmarkedOnScreen`). Between them they want five of editMain's bindings,
|
|
16
|
+
// and the two in-flight flags they own outright, so those live here with them.
|
|
17
|
+
//
|
|
18
|
+
// The import back to edit.mjs, for the export table and the two checks it
|
|
19
|
+
// shares with the command line, is a deliberate STATIC cycle, for the reason
|
|
20
|
+
// cli/edit-slides.mjs gives: edit.mjs ends in a top-level `await`, so a
|
|
21
|
+
// dynamic import from inside editMain would wait on an evaluation that is
|
|
22
|
+
// waiting on it. Nothing here reads those bindings until a request arrives.
|
|
23
|
+
|
|
24
|
+
import { existsSync } from 'node:fs';
|
|
25
|
+
import { basename, dirname, relative, resolve, sep } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
import { spawn } from 'node:child_process';
|
|
28
|
+
|
|
29
|
+
import { EXPORT_KINDS, alreadyOneFile, videoExportProblem } from './edit.mjs';
|
|
30
|
+
import { oneline, remoteLine, remoteState } from './git.mjs';
|
|
31
|
+
import { configTheme } from './runtime-link.mjs';
|
|
32
|
+
import { CommandError } from './util.mjs';
|
|
33
|
+
import { THEME_NAME, GEN_THEME } from '../tools/render-theme.mjs';
|
|
34
|
+
import { locateSlide, sectionChildRanges } from '../tools/deck-html.mjs';
|
|
35
|
+
|
|
36
|
+
/** How long a stopped child has to clean up after SIGTERM before SIGKILL. */
|
|
37
|
+
const STOP_GRACE_MS = 5000;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Why `module` cannot name a chapter to bundle, or null when it can (or is
|
|
41
|
+
* absent: the whole deck). The bundle card sends the chapter's NUMBER, never
|
|
42
|
+
* its title: `--module` takes a full title too, but a title is free text and
|
|
43
|
+
* a number is the one thing the picker and the CLI count the same way.
|
|
44
|
+
* Whether the deck has that chapter is the bundler's to say.
|
|
45
|
+
*/
|
|
46
|
+
export function moduleProblem(module) {
|
|
47
|
+
if (module == null) return null;
|
|
48
|
+
return /^[1-9]\d{0,3}$/.test(String(module)) ? null : 'the module is a chapter number, counting from 1';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Put the hand-over routes into `routes`, the table cli/edit.mjs dispatches
|
|
53
|
+
* on, and hand it back.
|
|
54
|
+
*
|
|
55
|
+
* `ctx` is the whole of what these handlers may touch: `readDeck()` for the
|
|
56
|
+
* current file, `deckPath` because every export is written beside the deck
|
|
57
|
+
* and named after it, `root` for the repository a publish pushes from,
|
|
58
|
+
* `broadcast` for the export's progress, and `gitOn()` for whether this
|
|
59
|
+
* session has a repository to publish from: a getter, not a copy, because it
|
|
60
|
+
* is a `let` of editMain's and the answer is whatever it holds when a publish
|
|
61
|
+
* asks. `onExport` hears `{ kind, what }` when an export starts and null when
|
|
62
|
+
* it ends, so `/deck/ping` can tell a page that loads mid-render there is one
|
|
63
|
+
* to stop.
|
|
64
|
+
*/
|
|
65
|
+
export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn, broadcast = () => {}, onExport = () => {} }) {
|
|
66
|
+
let exporting = false; // an export in flight — one browser, one output path, any kind
|
|
67
|
+
let stopExport = null; // stops it, while it is one that can be stopped
|
|
68
|
+
let publishing = false; // a publish in flight — one push at a time
|
|
69
|
+
|
|
70
|
+
// ── hand-over: the files this deck can be written out as, and publishing ───
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Write the deck out as a file, for the palette's hand-over rows
|
|
74
|
+
* (PRESENTING) — `{ kind }`, one of EXPORT_KINDS.
|
|
75
|
+
*
|
|
76
|
+
* `decklight pptx` and `decklight pdf` need Node and a headless Chrome,
|
|
77
|
+
* so the deck cannot do this itself — the same reason `A` asks the
|
|
78
|
+
* server to run an agent. The work is the commands' own `main`s,
|
|
79
|
+
* unchanged, so what a row writes is exactly what the command line
|
|
80
|
+
* writes.
|
|
81
|
+
*
|
|
82
|
+
* Four things this route owes the session it is running inside:
|
|
83
|
+
*
|
|
84
|
+
* - it must not TAKE THE SERVER DOWN. `chromeBin` exits the process when
|
|
85
|
+
* there is no browser — correct for a one-shot command, fatal here, so
|
|
86
|
+
* Chrome is resolved with the non-fatal `findChrome` first and a machine
|
|
87
|
+
* without one gets a sentence instead of a dead edit server.
|
|
88
|
+
* - it must not run twice at once. Two exports write the same path
|
|
89
|
+
* through two browsers; the second caller is told to wait. ONE flag for
|
|
90
|
+
* every kind, deliberately: two different exports at once is still two
|
|
91
|
+
* browsers on one machine, and the second would only be slower.
|
|
92
|
+
* - it must not block. Both `main`s are async all the way down (pptx
|
|
93
|
+
* serves the deck from THIS process while Chrome fetches it; pdf is
|
|
94
|
+
* async so the session stays answerable while Chrome prints), so live
|
|
95
|
+
* reload, the SSE stream and every other route keep answering while a
|
|
96
|
+
* slide renders. That is also why a row can say "rendering…" and mean it.
|
|
97
|
+
* - it must SAY WHERE IT IS. An export is tens of seconds, so each slide
|
|
98
|
+
* is announced on the `export` channel of the same SSE stream the agent
|
|
99
|
+
* chip rides, and the deck rewrites its one progress row from it.
|
|
100
|
+
*
|
|
101
|
+
* And it can be STOPPED (`exportStopRoute`), so a ten-minute video started
|
|
102
|
+
* on the wrong slides is not a reason to kill the session it runs in.
|
|
103
|
+
*/
|
|
104
|
+
async function exportRoute({ url, body, json }) {
|
|
105
|
+
const req = JSON.parse(body || '{}');
|
|
106
|
+
const kind = req.kind ?? 'pptx';
|
|
107
|
+
const job = EXPORT_KINDS[kind];
|
|
108
|
+
if (!job) {
|
|
109
|
+
return json(400, { ok: false, error: `not a file this server writes: ${kind} — try ${Object.keys(EXPORT_KINDS).join(', ')}` });
|
|
110
|
+
}
|
|
111
|
+
// The theme on screen, which the render is told because it cannot see the
|
|
112
|
+
// browser's pick (#547): a name — what `--theme` takes — or, for a theme
|
|
113
|
+
// that lives only in that browser, its tokens as `--gen` takes them
|
|
114
|
+
// (base64url JSON, the form `?gen=` loads; the runtime vets every token).
|
|
115
|
+
if (req.theme != null && !(typeof req.theme === 'string' && THEME_NAME.test(req.theme))) {
|
|
116
|
+
return json(400, { ok: false, error: 'the theme is a theme name' });
|
|
117
|
+
}
|
|
118
|
+
if (req.gen != null && !(typeof req.gen === 'string' && GEN_THEME.test(req.gen))) {
|
|
119
|
+
return json(400, { ok: false, error: 'the generated theme is base64url, at most 16 KB' });
|
|
120
|
+
}
|
|
121
|
+
if (req.theme != null && req.gen != null) return json(400, { ok: false, error: 'one theme — a name or a generated one' });
|
|
122
|
+
if (kind === 'bundle') {
|
|
123
|
+
// A bundle EMBEDS its themes, and a generated one is tokens in this
|
|
124
|
+
// browser with no file to embed. Bundling in the configured theme
|
|
125
|
+
// instead would hand over a file that does not look like the screen.
|
|
126
|
+
if (req.gen != null) {
|
|
127
|
+
return json(400, { ok: false, error: 'a generated theme lives only in this browser — save it (⌃⇧T) and add it with decklight theme add to bundle it' });
|
|
128
|
+
}
|
|
129
|
+
if (alreadyOneFile(readDeck())) {
|
|
130
|
+
return json(409, { ok: false, error: 'this deck is already one file — send it as it is' });
|
|
131
|
+
}
|
|
132
|
+
const bad = moduleProblem(req.module);
|
|
133
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
134
|
+
}
|
|
135
|
+
const unmarked = await unmarkedOnScreen(req.theme, { carried: kind === 'bundle' });
|
|
136
|
+
if (unmarked) return json(409, { ok: false, unmarked, error: `${unmarked} is not marked for this deck` });
|
|
137
|
+
const themed = req.theme ? ['--theme', req.theme] : req.gen ? ['--gen', req.gen] : [];
|
|
138
|
+
if (kind === 'video') {
|
|
139
|
+
const bad = videoExportProblem(req, dirname(deckPath));
|
|
140
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
141
|
+
}
|
|
142
|
+
if (exporting) return json(409, { ok: false, error: 'an export is already running' });
|
|
143
|
+
const { findChrome } = await import('../tools/chrome.mjs');
|
|
144
|
+
// every file but the bundle is a render; the bundle launches no browser
|
|
145
|
+
if (kind !== 'bundle' && !findChrome()) {
|
|
146
|
+
return json(503, { ok: false, error: 'no Chrome found — install one, or point $CHROME at it' });
|
|
147
|
+
}
|
|
148
|
+
exporting = true;
|
|
149
|
+
// Every kind but the bundle: the bundle launches nothing and is seconds
|
|
150
|
+
// from done, so there is nothing to stop part-way.
|
|
151
|
+
const stop = new AbortController();
|
|
152
|
+
stopExport = kind === 'bundle' ? null : () => stop.abort();
|
|
153
|
+
onExport({ kind, what: job.what });
|
|
154
|
+
const started = Date.now();
|
|
155
|
+
console.log(` export: ${basename(deckPath)} → ${job.what}${req.slides ? ` of slides ${req.slides}` : ''}`
|
|
156
|
+
+ `${req.synthesize ? `, voiced by ${req.synthesize.engine} into ${req.synthesize.dir}/` : ''} …`);
|
|
157
|
+
broadcast('export', { state: 'start', kind, what: job.what });
|
|
158
|
+
try {
|
|
159
|
+
let out, code, reason = null, subs = null, notes = null;
|
|
160
|
+
if (kind === 'video') {
|
|
161
|
+
const { videoOut, videoProgress, voiceoverProgress, subtitlesOut } = await import('../tools/video.mjs');
|
|
162
|
+
out = videoOut(deckPath, req.slides || null, req.format || 'mp4');
|
|
163
|
+
subs = req.subtitles === 'file' ? subtitlesOut(out, req.format || 'mp4') : null;
|
|
164
|
+
// Two phases, each told apart on the channel: voicing is minutes on a
|
|
165
|
+
// cloud engine, and a row that said "rendering" through all of it would
|
|
166
|
+
// read as stuck on slide one.
|
|
167
|
+
if (req.synthesize) {
|
|
168
|
+
({ code, reason } = await runTool('voiceover', await voiceoverArgv(req),
|
|
169
|
+
voiceoverProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'voice', n, of })), stop.signal));
|
|
170
|
+
}
|
|
171
|
+
if (!code && !stop.signal.aborted) {
|
|
172
|
+
const narration = req.synthesize?.dir ?? req.narration ?? null;
|
|
173
|
+
({ code, reason } = await runTool('video', [deckPath, '-o', out, ...themed,
|
|
174
|
+
...(req.slides ? ['--slides', req.slides] : []),
|
|
175
|
+
...(req.format ? ['--format', req.format] : []),
|
|
176
|
+
...(req.quality ? ['--quality', req.quality] : []),
|
|
177
|
+
...(req.subtitles ? ['--subtitles', req.subtitles] : []),
|
|
178
|
+
...(narration ? ['--narration', resolve(dirname(deckPath), narration)] : req.silent ? ['--no-narration'] : []),
|
|
179
|
+
// the card showed the track as recorded from older notes and it was picked anyway (#536)
|
|
180
|
+
...(req.allowStale === true ? ['--allow-stale'] : [])],
|
|
181
|
+
videoProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'render', n, of })), stop.signal));
|
|
182
|
+
}
|
|
183
|
+
} else if (kind === 'bundle') {
|
|
184
|
+
// No -o: the CLI names the file, beside the deck, so the row and
|
|
185
|
+
// `decklight bundle` write the same one — `<deck>-standalone.html`,
|
|
186
|
+
// or for one chapter (`module`, its number: --module) the chapter's
|
|
187
|
+
// own name, which never overwrites the whole deck's. `audio` is its
|
|
188
|
+
// --audio ('original', 'aac' or 'opus'), the recorded voice carried
|
|
189
|
+
// inside. bundleMain returns nothing on success and throws a sentence
|
|
190
|
+
// on a refusal (an unknown chapter among them, before any file is
|
|
191
|
+
// written) — the catch below says it. The notes it prints after the
|
|
192
|
+
// file come back too: which chapter went in, and where the audio is.
|
|
193
|
+
const { bundleMain } = await import('./bundle.mjs');
|
|
194
|
+
const { AUDIO_CHOICES } = await import('./bundle-audio.mjs');
|
|
195
|
+
const report = {};
|
|
196
|
+
code = (await bundleMain([deckPath, ...(req.theme ? ['--theme', req.theme] : []),
|
|
197
|
+
...(req.module != null ? ['--module', String(req.module)] : []),
|
|
198
|
+
...(AUDIO_CHOICES.includes(req.audio) ? ['--audio', req.audio] : [])], { report })) ?? 0;
|
|
199
|
+
out = report.out;
|
|
200
|
+
notes = report.notices;
|
|
201
|
+
} else if (kind === 'pptx') {
|
|
202
|
+
const { pptxMain, pptxOut } = await import('./pptx-export.mjs');
|
|
203
|
+
out = pptxOut(deckPath);
|
|
204
|
+
code = await pptxMain([deckPath, ...themed], {
|
|
205
|
+
log: (line) => console.log(` ${line}`),
|
|
206
|
+
onSlide: (n, of) => broadcast('export', { state: 'slide', kind, n, of }),
|
|
207
|
+
signal: stop.signal,
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
const { pdfMain, pdfOut } = await import('./pdf.mjs');
|
|
211
|
+
out = pdfOut(deckPath, null, job.variant);
|
|
212
|
+
code = await pdfMain([deckPath, ...themed, ...(job.variant ? [`--${job.variant}`] : [])], { signal: stop.signal });
|
|
213
|
+
}
|
|
214
|
+
if (stop.signal.aborted) return stopped();
|
|
215
|
+
const file = relative(process.cwd(), out) || basename(out);
|
|
216
|
+
const seconds = Math.round((Date.now() - started) / 100) / 10;
|
|
217
|
+
if (code !== 0) {
|
|
218
|
+
broadcast('export', { state: 'done', kind, ok: false });
|
|
219
|
+
return json(500, { ok: false, error: reason ?? 'the export refused — see the edit server\'s output' });
|
|
220
|
+
}
|
|
221
|
+
// A render with nothing spoken writes no subtitles and says so; the deck
|
|
222
|
+
// is told of a file only when there is one to open.
|
|
223
|
+
const voiced = {
|
|
224
|
+
...(req.synthesize ? { voiced: req.synthesize.dir } : {}),
|
|
225
|
+
...(subs && existsSync(subs) ? { subtitles: relative(process.cwd(), subs) || basename(subs) } : {}),
|
|
226
|
+
};
|
|
227
|
+
broadcast('export', { state: 'done', kind, ok: true, file, seconds, ...voiced });
|
|
228
|
+
return json(200, { ok: true, kind, what: job.what, file, seconds, ...voiced, ...(notes ? { notes } : {}) });
|
|
229
|
+
} catch (e) {
|
|
230
|
+
if (stop.signal.aborted) return stopped();
|
|
231
|
+
// A render that hangs or a Chrome that dies is the export's problem,
|
|
232
|
+
// never the session's: the message goes back to the palette and the
|
|
233
|
+
// server carries on serving the deck. A command's refusal is a sentence
|
|
234
|
+
// and then, at most, a list it introduces ("— its chapters are:"); the
|
|
235
|
+
// sentence is what fits on a card, and the card has the list already.
|
|
236
|
+
const said = e instanceof CommandError ? e.message.split('\n')[0].replace(/\s+—[^—]*:$/, '') : oneline(e);
|
|
237
|
+
console.log(` export: ${job.what} failed — ${said}`);
|
|
238
|
+
broadcast('export', { state: 'done', kind, ok: false, error: said });
|
|
239
|
+
return json(500, { ok: false, error: said });
|
|
240
|
+
} finally {
|
|
241
|
+
exporting = false;
|
|
242
|
+
stopExport = null;
|
|
243
|
+
onExport(null);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Not a failure: what was asked for. The voice a stopped export had
|
|
247
|
+
// already synthesized stays where it was written — it is the deck's own
|
|
248
|
+
// folder, and the next export finds those slides done.
|
|
249
|
+
function stopped() {
|
|
250
|
+
const kept = req.synthesize && existsSync(resolve(dirname(deckPath), req.synthesize.dir)) ? { voiced: req.synthesize.dir } : {};
|
|
251
|
+
console.log(` export: ${job.what} stopped — nothing written`);
|
|
252
|
+
broadcast('export', { state: 'done', kind, ok: false, stopped: true, ...kept });
|
|
253
|
+
return json(200, { ok: false, stopped: true, kind, what: job.what, ...kept });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* POST /deck/edit/export/stop — stop the export in flight. Answers at once;
|
|
259
|
+
* the export's own request is the one that says it stopped (`{ stopped }`),
|
|
260
|
+
* once its children are gone and its scratch files with them.
|
|
261
|
+
*/
|
|
262
|
+
function exportStopRoute({ json }) {
|
|
263
|
+
if (!exporting) return json(409, { ok: false, error: 'no export is running' });
|
|
264
|
+
if (!stopExport) return json(409, { ok: false, error: 'a bundle cannot be stopped part-way — it is seconds from done' });
|
|
265
|
+
console.log(' export: stopping …');
|
|
266
|
+
stopExport();
|
|
267
|
+
return json(200, { ok: true });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* `decklight video` (and `decklight narrate` before it, when the export
|
|
272
|
+
* voices its slides), run as CHILDREN rather than through their `main`s like
|
|
273
|
+
* the other exports: both end in `process.exit` on every refusal, and each
|
|
274
|
+
* would take this session down or freeze it. A child keeps that where it
|
|
275
|
+
* belongs, and its output is read line by line for the progress it already
|
|
276
|
+
* prints.
|
|
277
|
+
*
|
|
278
|
+
* Served from the same root `pptx` picks: the current directory when the deck
|
|
279
|
+
* is under it, its own directory otherwise.
|
|
280
|
+
*
|
|
281
|
+
* `signal` stops it: SIGTERM, which `decklight video` answers by killing its
|
|
282
|
+
* Chrome and ffmpeg and clearing its scratch frames, then SIGKILL for a child
|
|
283
|
+
* that has not gone a few seconds later.
|
|
284
|
+
*/
|
|
285
|
+
function runTool(name, argv, onLine, signal = null) {
|
|
286
|
+
const script = fileURLToPath(new URL(`../tools/${name}.mjs`, import.meta.url));
|
|
287
|
+
const cwd = deckPath.startsWith(process.cwd() + sep) ? process.cwd() : dirname(deckPath);
|
|
288
|
+
return new Promise((done) => {
|
|
289
|
+
const child = spawn(process.execPath, [script, ...argv], { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
290
|
+
let hard = null;
|
|
291
|
+
const stop = () => {
|
|
292
|
+
child.kill('SIGTERM');
|
|
293
|
+
hard = setTimeout(() => child.kill('SIGKILL'), STOP_GRACE_MS);
|
|
294
|
+
};
|
|
295
|
+
if (signal?.aborted) stop(); else signal?.addEventListener('abort', stop, { once: true });
|
|
296
|
+
let pending = '', err = '';
|
|
297
|
+
child.stdout.on('data', (chunk) => {
|
|
298
|
+
pending += chunk;
|
|
299
|
+
for (let i; (i = pending.indexOf('\n')) >= 0;) {
|
|
300
|
+
const line = pending.slice(0, i);
|
|
301
|
+
pending = pending.slice(i + 1);
|
|
302
|
+
console.log(` ${line}`);
|
|
303
|
+
onLine(line);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
child.stderr.on('data', (chunk) => { err += chunk; process.stdout.write(String(chunk).replace(/^/gm, ' ')); });
|
|
307
|
+
child.on('error', (e) => done({ code: 1, reason: oneline(e) }));
|
|
308
|
+
child.on('close', (code) => {
|
|
309
|
+
clearTimeout(hard);
|
|
310
|
+
signal?.removeEventListener('abort', stop);
|
|
311
|
+
// the command's own refusal is the sentence the deck shows
|
|
312
|
+
const said = err.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
313
|
+
const prefix = `decklight ${name}:`;
|
|
314
|
+
const refusal = said.findLast((l) => l.startsWith(prefix)) ?? said.at(-1);
|
|
315
|
+
done({ code, reason: code === 0 ? null : (refusal?.replace(prefix, '').trim() ?? null) });
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* argv for voicing an export: the live voice the deck is speaking with, as
|
|
322
|
+
* `decklight narrate` spells it. The deck sends what only it knows — the
|
|
323
|
+
* engine and model the bridge answered with, the voice and tone picked in V —
|
|
324
|
+
* and the rest comes from where the bridge itself reads it (the environment,
|
|
325
|
+
* then ~/.config/decklight/tts.json for the same engine), so a sentence
|
|
326
|
+
* already heard live is a cache hit here and not a second bill.
|
|
327
|
+
*/
|
|
328
|
+
async function voiceoverArgv({ slides, synthesize: s }) {
|
|
329
|
+
const { loadTtsConfig } = await import('../tools/tts-setup.mjs');
|
|
330
|
+
const { piperModelDir } = await import('../tools/tts-engines.mjs');
|
|
331
|
+
const saved = loadTtsConfig();
|
|
332
|
+
const savedFor = saved?.engine === s.engine ? saved : null;
|
|
333
|
+
const project = process.env.GOOGLE_CLOUD_PROJECT ?? saved?.project;
|
|
334
|
+
const dataDir = savedFor?.dataDir ?? (s.engine === 'piper' ? piperModelDir() : null);
|
|
335
|
+
return [deckPath, '-o', resolve(dirname(deckPath), s.dir), '--engine', s.engine,
|
|
336
|
+
...(s.voice ? ['--voice', s.voice] : []),
|
|
337
|
+
...(s.style ? ['--style', s.style] : []),
|
|
338
|
+
...(s.model ? ['--tts-model', s.model] : []),
|
|
339
|
+
...(savedFor?.format ? ['--tts-format', savedFor.format] : []),
|
|
340
|
+
...(dataDir ? ['--data-dir', dataDir] : []),
|
|
341
|
+
...(project && (s.engine === 'gemini' || s.engine === 'chirp') ? ['--project', project] : []),
|
|
342
|
+
...(slides ? ['--slides', slides] : [])];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Publish the deck — and, before that, say where to (PRESENTING).
|
|
347
|
+
*
|
|
348
|
+
* The one row in the palette that reaches OFF this machine. Everything
|
|
349
|
+
* else the deck can ask this server for writes a file beside it; this
|
|
350
|
+
* pushes a page the world can read, and `Z` does not take that back. So
|
|
351
|
+
* it is two routes, not one: the deck asks for the PLAN, shows a person
|
|
352
|
+
* the remote and the URL, and only posts after a second, deliberate
|
|
353
|
+
* press. The arming lives in the deck, not here — an unarmed POST
|
|
354
|
+
* publishes, exactly as the command line does, because a confirmation
|
|
355
|
+
* belongs to the surface that can show somebody what they are agreeing
|
|
356
|
+
* to.
|
|
357
|
+
*
|
|
358
|
+
* `GIT_TERMINAL_PROMPT=0` matters more here than anywhere else: publish
|
|
359
|
+
* pushes with a synchronous git, so a credential prompt would not be
|
|
360
|
+
* asking anybody anything — it would hang the write-mode session on a
|
|
361
|
+
* terminal nobody is looking at.
|
|
362
|
+
*/
|
|
363
|
+
async function publishPlanRoute({ json }) {
|
|
364
|
+
if (!gitOn()) return json(409, { ok: false, error: 'git is off for this session — there is nothing to publish from' });
|
|
365
|
+
const remote = remoteState(root);
|
|
366
|
+
if (!remote.url) {
|
|
367
|
+
return json(409, { ok: false, error: `nowhere to publish to — ${remoteLine(remote) || remote.state}` });
|
|
368
|
+
}
|
|
369
|
+
const { pagesUrl } = await import('./publish.mjs');
|
|
370
|
+
// Whether it COULD sign is part of the plan, not a failure after the
|
|
371
|
+
// fact: publish signs by default and refuses rather than publishing
|
|
372
|
+
// unsigned (INTEGRITY), and the deck would otherwise show somebody a
|
|
373
|
+
// URL, take their confirmation, and only then say it cannot.
|
|
374
|
+
//
|
|
375
|
+
// The SENTENCE is built here, not in the deck. The runtime must never
|
|
376
|
+
// so much as name the signing client (test/sign.test.mjs greps src/
|
|
377
|
+
// and dist/ for it — the invariant is that the browser never reaches
|
|
378
|
+
// for it), so the server hands over words the deck only has to show.
|
|
379
|
+
const { loadClient, INSTALL_HINT } = await import('./sign.mjs');
|
|
380
|
+
const canSign = Boolean(await loadClient());
|
|
381
|
+
return json(200, {
|
|
382
|
+
ok: true, remote: remote.remote, branch: 'gh-pages',
|
|
383
|
+
url: pagesUrl(remote.url), bundled: !alreadyOneFile(readDeck()),
|
|
384
|
+
signing: canSign,
|
|
385
|
+
why: canSign ? null : `publish signs the deck first, and that client is not installed — ${INSTALL_HINT}`,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function publishRoute({ body, json }) {
|
|
390
|
+
if (!gitOn()) return json(409, { ok: false, error: 'git is off for this session — there is nothing to publish from' });
|
|
391
|
+
if (publishing) return json(409, { ok: false, error: 'a publish is already running' });
|
|
392
|
+
// The theme on screen is the one the page opens on (SPEC THEME_DISTRIBUTION)
|
|
393
|
+
// — the same question the export card answers, asked the same way.
|
|
394
|
+
const { theme = null } = JSON.parse(body || '{}');
|
|
395
|
+
if (theme != null && !(typeof theme === 'string' && THEME_NAME.test(theme))) {
|
|
396
|
+
return json(400, { ok: false, error: 'the theme is a theme name' });
|
|
397
|
+
}
|
|
398
|
+
const unmarked = await unmarkedOnScreen(theme);
|
|
399
|
+
if (unmarked) return json(409, { ok: false, unmarked, error: `${unmarked} is not marked for this deck` });
|
|
400
|
+
publishing = true;
|
|
401
|
+
const before = process.env.GIT_TERMINAL_PROMPT;
|
|
402
|
+
process.env.GIT_TERMINAL_PROMPT = '0';
|
|
403
|
+
console.log(` publish: ${basename(deckPath)} → gh-pages …`);
|
|
404
|
+
try {
|
|
405
|
+
const { publishMain } = await import('./publish.mjs');
|
|
406
|
+
// A deck that is already one file has nothing to flatten, and the
|
|
407
|
+
// bundler rightly refuses it — the same two cases `decklight
|
|
408
|
+
// publish` has, decided here rather than made the presenter's
|
|
409
|
+
// problem. Everything else is the command's own default, signature
|
|
410
|
+
// included.
|
|
411
|
+
const oneFile = alreadyOneFile(readDeck());
|
|
412
|
+
const args = [deckPath, ...(oneFile ? ['--no-bundle'] : theme ? ['--theme', theme] : [])];
|
|
413
|
+
const r = await publishMain(args);
|
|
414
|
+
console.log(` publish: ${r.url ?? `${r.remote} ${r.branch}`}`);
|
|
415
|
+
return json(200, { ok: true, url: r.url ?? null, branch: r.branch, remote: r.remote, commit: r.commit });
|
|
416
|
+
} catch (e) {
|
|
417
|
+
console.log(` publish: refused — ${oneline(e)}`);
|
|
418
|
+
return json(500, { ok: false, error: oneline(e) });
|
|
419
|
+
} finally {
|
|
420
|
+
process.env.GIT_TERMINAL_PROMPT = before ?? '';
|
|
421
|
+
if (before === undefined) delete process.env.GIT_TERMINAL_PROMPT;
|
|
422
|
+
publishing = false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* GET /deck/edit/export/estimate?kind=bundle — how big an export would be, before
|
|
428
|
+
* it is written. Only the bundle has one today: the file without its audio
|
|
429
|
+
* (`base`), and what each way of carrying the narration's recorded audio
|
|
430
|
+
* would add (cli/bundle-audio.mjs), so the bundle card can say "Opus — ≈ 2.1
|
|
431
|
+
* MB" before anybody chooses. `audio` is null for a deck with no recorded
|
|
432
|
+
* audio on this disk.
|
|
433
|
+
*/
|
|
434
|
+
async function exportEstimateRoute({ url, json }) {
|
|
435
|
+
const kind = url.searchParams.get('kind');
|
|
436
|
+
if (kind !== 'bundle') return json(400, { ok: false, error: `no estimate for ${kind ?? 'that'} — only a bundle has one` });
|
|
437
|
+
const theme = url.searchParams.get('theme');
|
|
438
|
+
if (theme != null && !THEME_NAME.test(theme)) return json(400, { ok: false, error: 'the theme is a theme name' });
|
|
439
|
+
// one chapter is estimated as one chapter: its slides, its share of the audio
|
|
440
|
+
const module = url.searchParams.get('module');
|
|
441
|
+
const bad = moduleProblem(module);
|
|
442
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
443
|
+
const { bundleMain } = await import('./bundle.mjs');
|
|
444
|
+
const estimate = (argv) => bundleMain([deckPath, ...argv, ...(module != null ? ['--module', module] : [])], { estimate: true });
|
|
445
|
+
try {
|
|
446
|
+
// in the theme on screen, as the export will be — or, when that one
|
|
447
|
+
// cannot be bundled yet (the export asks to mark it first), in the
|
|
448
|
+
// deck's own: an estimate a theme's stylesheet away is still one
|
|
449
|
+
let r;
|
|
450
|
+
try { r = await estimate(theme ? ['--theme', theme] : []); } catch (e) {
|
|
451
|
+
if (!theme || !(e instanceof CommandError)) throw e;
|
|
452
|
+
r = await estimate([]);
|
|
453
|
+
}
|
|
454
|
+
return json(200, { ok: true, base: r.base, audio: r.audio });
|
|
455
|
+
} catch (e) {
|
|
456
|
+
if (!(e instanceof CommandError)) throw e;
|
|
457
|
+
return json(409, { ok: false, error: e.message.split('\n')[0] });
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Where slide N lives in the file, for the inspector (`I`, PRESENTING): the
|
|
463
|
+
* slide's lines, each authored top-level child's lines by the same raw index
|
|
464
|
+
* the element routes use, and what `decklight check` would say about it.
|
|
465
|
+
* Read-only, and only the static half of the check: the render half needs a
|
|
466
|
+
* browser and takes seconds, and the panel asks on every slide change.
|
|
467
|
+
*/
|
|
468
|
+
async function inspectRoute({ url, json }) {
|
|
469
|
+
const { sectionRanges, staticFindings } = await import('./check.mjs');
|
|
470
|
+
const html = readDeck();
|
|
471
|
+
const ranges = sectionRanges(html);
|
|
472
|
+
const slide = Number(url.searchParams.get('slide'));
|
|
473
|
+
if (!Number.isInteger(slide) || slide < 1 || slide > ranges.length) {
|
|
474
|
+
return json(400, { ok: false, error: `no slide ${url.searchParams.get('slide') ?? ''} — the deck has ${ranges.length}`.trim() });
|
|
475
|
+
}
|
|
476
|
+
// 1-based line of an offset: the newlines before it, plus one
|
|
477
|
+
const breaks = [];
|
|
478
|
+
for (let i = html.indexOf('\n'); i !== -1; i = html.indexOf('\n', i + 1)) breaks.push(i);
|
|
479
|
+
const lineAt = (at) => {
|
|
480
|
+
let lo = 0, hi = breaks.length;
|
|
481
|
+
while (lo < hi) { const mid = (lo + hi) >> 1; if (breaks[mid] < at) lo = mid + 1; else hi = mid; }
|
|
482
|
+
return lo + 1;
|
|
483
|
+
};
|
|
484
|
+
const span = (start, end) => [lineAt(start), lineAt(Math.max(start, end - 1))];
|
|
485
|
+
const range = ranges[slide - 1];
|
|
486
|
+
const { parts, idx } = locateSlide(html, slide);
|
|
487
|
+
const segAt = parts.slice(0, idx).join('').length;
|
|
488
|
+
let blocks = [];
|
|
489
|
+
try {
|
|
490
|
+
blocks = sectionChildRanges(parts[idx]).map((r) => ({ tag: r.tag, lines: span(segAt + r.start, segAt + r.end) }));
|
|
491
|
+
} catch { /* a malformed section still has its own lines */ }
|
|
492
|
+
const findings = staticFindings(html, { dir: dirname(deckPath) })
|
|
493
|
+
.filter((f) => f.slide === slide)
|
|
494
|
+
.map(({ level, rule, message }) => ({ level, rule, message }));
|
|
495
|
+
return json(200, { ok: true, file: basename(deckPath), lines: span(range.start, range.end), blocks, findings });
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Every finding `decklight check`'s static half has for the whole deck,
|
|
500
|
+
* for Check deck… (PRESENTING_EDITING): head-level ones (a design system
|
|
501
|
+
* the deck is behind, a theme off the brand, a missing file) with
|
|
502
|
+
* `slide: null`, then each slide's, the same rule ids `check --json`
|
|
503
|
+
* prints — and on each the quick fix the server could apply for it
|
|
504
|
+
* (cli/check-fixes.mjs), so the row says what pressing it would do. Read-
|
|
505
|
+
* only, like the inspector's read above; the render half is the open
|
|
506
|
+
* page's own (src/core/deckcheck.js measures it).
|
|
507
|
+
*/
|
|
508
|
+
async function checkRoute({ json }) {
|
|
509
|
+
const { sectionRanges, staticFindings } = await import('./check.mjs');
|
|
510
|
+
const { quickFixes } = await import('./check-fixes.mjs');
|
|
511
|
+
const html = readDeck();
|
|
512
|
+
const dir = dirname(deckPath);
|
|
513
|
+
const found = staticFindings(html, { dir, deck: basename(deckPath) });
|
|
514
|
+
return json(200, {
|
|
515
|
+
ok: true, file: basename(deckPath), slides: sectionRanges(html).length,
|
|
516
|
+
findings: quickFixes(found, html, dir, { deck: basename(deckPath) }),
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* The marketplace theme on screen that this deck does not mark, as a
|
|
522
|
+
* reference — or null. An export or a publish of an unmarked theme would
|
|
523
|
+
* come out in a theme the deck does not carry; the card asks first
|
|
524
|
+
* (`409 { unmarked }`), and marking is one more press.
|
|
525
|
+
*/
|
|
526
|
+
async function unmarkedOnScreen(theme, { carried = false } = {}) {
|
|
527
|
+
if (!theme) return null;
|
|
528
|
+
const html = readDeck();
|
|
529
|
+
const { markedRefs, markedShipped, marketplaceThemes, shippedThemes } = await import('./theme-refs.mjs');
|
|
530
|
+
if (shippedThemes().includes(theme)) {
|
|
531
|
+
// A render shows a shipped theme without carrying it — every install has
|
|
532
|
+
// it. A BUNDLE carries only what the deck marks, plus the theme it opens
|
|
533
|
+
// on: one it opens on in some other theme is a question first (Gilles'
|
|
534
|
+
// rule), so the file never leaves carrying a theme nobody chose to send.
|
|
535
|
+
if (!carried) return null;
|
|
536
|
+
return markedShipped(html).includes(theme) || theme === configTheme(html) ? null : theme;
|
|
537
|
+
}
|
|
538
|
+
if (markedRefs(html).some((r) => r.name === theme)) return null;
|
|
539
|
+
if (new RegExp(`<style\\b[^>]*\\bdata-theme\\s*=\\s*["']${theme}["']`, 'i').test(html)) return null;
|
|
540
|
+
return marketplaceThemes().themes.find((t) => t.name === theme)?.qualified ?? null;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
routes.set('POST /deck/edit/export', exportRoute);
|
|
544
|
+
routes.set('POST /deck/edit/export/stop', exportStopRoute);
|
|
545
|
+
routes.set('GET /deck/edit/export/estimate', exportEstimateRoute);
|
|
546
|
+
routes.set('GET /deck/edit/inspect', inspectRoute);
|
|
547
|
+
routes.set('GET /deck/edit/check', checkRoute);
|
|
548
|
+
routes.set('GET /deck/edit/publish/plan', publishPlanRoute);
|
|
549
|
+
routes.set('POST /deck/edit/publish', publishRoute);
|
|
550
|
+
return routes;
|
|
551
|
+
}
|