@slidevideo/cli 0.1.2 → 0.2.1
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/CHANGELOG.md +41 -0
- package/IMPRESSUM.md +18 -4
- package/LICENSE-TERMS.md +46 -13
- package/README.md +5 -5
- package/addons/slidevideo/geometry.ts +63 -30
- package/addons/slidevideo/global-top.vue +41 -9
- package/addons/slidevideo/playback-entries.ts +17 -6
- package/addons/slidevideo/preview.ts +27 -15
- package/dist/adapters/browser-runtime.d.ts +3 -0
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +8 -4
- package/dist/adapters/powerpoint.d.ts +7 -4
- package/dist/adapters/powerpoint.js +123 -34
- package/dist/adapters/slidev-inspection.d.ts +5 -2
- package/dist/adapters/slidev-inspection.js +5 -6
- package/dist/adapters/slidev-server.js +136 -15
- package/dist/adapters/slidev.d.ts +12 -4
- package/dist/adapters/slidev.js +356 -70
- package/dist/annotation-paint.d.ts +65 -11
- package/dist/annotation-paint.js +290 -10
- package/dist/annotations.d.ts +13 -8
- package/dist/annotations.js +620 -89
- package/dist/assembly.d.ts +48 -40
- package/dist/assembly.js +72 -28
- package/dist/calibration.js +5 -4
- package/dist/cli.js +180 -39
- package/dist/compositor.d.ts +38 -6
- package/dist/compositor.js +299 -46
- package/dist/contracts.d.ts +96 -35
- package/dist/contracts.js +2 -1
- package/dist/executables.d.ts +2 -0
- package/dist/executables.js +27 -8
- package/dist/media.d.ts +12 -1
- package/dist/media.js +53 -4
- package/dist/pipeline.d.ts +36 -10
- package/dist/pipeline.js +163 -46
- package/dist/preview/contracts.d.ts +3 -3
- package/dist/preview/player.js +20 -15
- package/dist/preview/server.d.ts +2 -1
- package/dist/preview/server.js +8 -7
- package/dist/run.d.ts +1 -1
- package/dist/run.js +8 -3
- package/dist/setup-install.d.ts +1 -0
- package/dist/setup-install.js +8 -1
- package/dist/setup.d.ts +29 -8
- package/dist/setup.js +183 -76
- package/dist/skill-install.d.ts +35 -0
- package/dist/skill-install.js +132 -0
- package/dist/speech.js +10 -6
- package/dist/storyboard.js +12 -6
- package/dist/timing.js +2 -2
- package/package.json +4 -3
- package/schemas/annotation-geometry.v1.json +260 -28
- package/schemas/run-manifest.v1.json +31 -0
- package/schemas/schedule.v1.json +655 -1
- package/schemas/storyboard.v1.json +558 -33
- package/skills/slidevideo/SKILL.md +11 -9
- package/skills/slidevideo/references/decks.md +228 -0
- package/skills/slidevideo/references/production.md +17 -12
- package/skills/slidevideo/references/storyboard.md +71 -38
- package/tools/powerpoint/powerpoint.ps1 +52 -41
- package/tools/powerpoint/preview.ps1 +5 -5
- package/schemas/schedule.v2.json +0 -496
- package/schemas/storyboard.v2.json +0 -802
package/dist/adapters/slidev.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import './browser-runtime.js';
|
|
2
2
|
import { chromium } from 'playwright';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { createServer } from 'node:net';
|
|
5
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
6
7
|
import { dirname, join, resolve } from 'node:path';
|
|
7
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { defaultVideoOutput } from '../contracts.js';
|
|
10
|
+
import { geometryRequests } from '../annotation-paint.js';
|
|
8
11
|
import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
|
|
9
12
|
import { calibrate, estimateOrigin } from '../calibration.js';
|
|
10
|
-
import { probe, saveJson, hashFile, digest, videoFramePeriod,
|
|
13
|
+
import { execute, probe, saveJson, hashFile, digest, videoFramePeriod, executionSignal } from '../media.js';
|
|
11
14
|
import { requireCondition, ProductionError } from '../errors.js';
|
|
12
15
|
import { executable } from '../executables.js';
|
|
13
16
|
function browserFailure(error, phase) {
|
|
@@ -22,33 +25,96 @@ function browserFailure(error, phase) {
|
|
|
22
25
|
}
|
|
23
26
|
export class SlidevAdapter {
|
|
24
27
|
id = 'slidev';
|
|
25
|
-
version = '53.1.0-adapter-
|
|
28
|
+
version = '53.1.0-adapter-6';
|
|
26
29
|
browser;
|
|
27
30
|
page;
|
|
28
31
|
server;
|
|
29
32
|
log = '';
|
|
33
|
+
cleanupPromise;
|
|
34
|
+
closed = false;
|
|
35
|
+
stagingDirectory;
|
|
36
|
+
rawCaptureFile;
|
|
37
|
+
captureToken;
|
|
30
38
|
schedule;
|
|
31
|
-
story;
|
|
32
39
|
directory;
|
|
33
40
|
references = [];
|
|
34
|
-
production = { verify_timing: false };
|
|
41
|
+
production = { verify_timing: false, output: defaultVideoOutput };
|
|
35
42
|
inspect = inspectSlidev;
|
|
36
43
|
validate = validateSlidev;
|
|
37
|
-
async
|
|
44
|
+
async stopServer(server) {
|
|
45
|
+
const pid = server.pid;
|
|
46
|
+
if (server.exitCode !== null || server.signalCode !== null || !pid)
|
|
47
|
+
return;
|
|
48
|
+
if (process.platform === 'win32') {
|
|
49
|
+
await new Promise((resolve, reject) => {
|
|
50
|
+
const stop = spawn('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
51
|
+
const timer = setTimeout(() => stop.kill(), 5000);
|
|
52
|
+
stop.once('error', error => { clearTimeout(timer); reject(error); });
|
|
53
|
+
stop.once('close', code => {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
if (code === 0 || server.exitCode !== null || server.signalCode !== null)
|
|
56
|
+
resolve();
|
|
57
|
+
else
|
|
58
|
+
reject(new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process tree', 5));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const exited = new Promise(resolve => {
|
|
64
|
+
server.once('close', () => resolve());
|
|
65
|
+
server.once('error', () => resolve());
|
|
66
|
+
});
|
|
67
|
+
const wait = async (ms) => {
|
|
68
|
+
let timer;
|
|
69
|
+
try {
|
|
70
|
+
await Promise.race([exited, new Promise(resolve => { timer = setTimeout(resolve, ms); })]);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const signalGroup = (signal) => {
|
|
77
|
+
try {
|
|
78
|
+
process.kill(-pid, signal);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code !== 'ESRCH')
|
|
82
|
+
server.kill(signal);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
signalGroup('SIGTERM');
|
|
86
|
+
await wait(3000);
|
|
87
|
+
if (server.exitCode === null && server.signalCode === null) {
|
|
88
|
+
signalGroup('SIGKILL');
|
|
89
|
+
await wait(2000);
|
|
90
|
+
}
|
|
91
|
+
if (server.exitCode === null && server.signalCode === null) {
|
|
92
|
+
throw new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process', 5);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async startServer(deck, mode) {
|
|
97
|
+
executionSignal()?.throwIfAborted();
|
|
98
|
+
requireCondition(!this.closed, 'INTERRUPTED', 'Slidev startup aborted', 5);
|
|
38
99
|
const port = await new Promise((resolve, reject) => {
|
|
39
100
|
const socket = createServer();
|
|
40
101
|
socket.on('error', reject);
|
|
41
102
|
socket.listen(0, '127.0.0.1', () => { const address = socket.address(); const port = typeof address === 'object' && address ? address.port : 0; socket.close(() => resolve(port)); });
|
|
42
103
|
});
|
|
43
104
|
const server = fileURLToPath(new URL('./slidev-server.js', import.meta.url));
|
|
44
|
-
this.server = spawn(process.execPath, [server,
|
|
105
|
+
this.server = spawn(process.execPath, [server, deck, String(port), ...(mode ? [mode.kind, mode.file] : [])], { cwd: dirname(deck), stdio: ['ignore', 'pipe', 'pipe'], detached: process.platform !== 'win32', windowsHide: true });
|
|
45
106
|
this.server.stdout?.on('data', data => { this.log += data.toString(); });
|
|
46
107
|
this.server.stderr?.on('data', data => { this.log += data.toString(); });
|
|
108
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
109
|
+
await this.stopServer(this.server);
|
|
110
|
+
executionSignal()?.throwIfAborted();
|
|
111
|
+
throw new ProductionError('INTERRUPTED', 'Slidev startup aborted', 5);
|
|
112
|
+
}
|
|
47
113
|
const url = `http://127.0.0.1:${port}`;
|
|
48
114
|
const deadline = Date.now() + 120000;
|
|
49
115
|
let ready = false;
|
|
50
116
|
while (Date.now() < deadline) {
|
|
51
|
-
|
|
117
|
+
executionSignal()?.throwIfAborted();
|
|
52
118
|
requireCondition(this.server.exitCode === null && this.server.signalCode === null, 'SLIDEV_SERVER', 'Slidev exited before readiness', 5);
|
|
53
119
|
try {
|
|
54
120
|
if ((await fetch(url, { signal: AbortSignal.timeout(1000) })).ok) {
|
|
@@ -62,42 +128,45 @@ export class SlidevAdapter {
|
|
|
62
128
|
requireCondition(ready, 'SLIDEV_TIMEOUT', 'Slidev did not become ready', 5);
|
|
63
129
|
return url;
|
|
64
130
|
}
|
|
65
|
-
async startPreview(story, schedule, directory, parentOrigin) {
|
|
131
|
+
async startPreview(story, schedule, directory, parentOrigin, _viewport) {
|
|
66
132
|
this.directory = directory;
|
|
67
133
|
await mkdir(directory, { recursive: true });
|
|
68
134
|
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
69
135
|
const config = resolve(directory, 'preview.json');
|
|
70
136
|
await saveJson(config, { schedule, mediaHashes, parentOrigin });
|
|
71
|
-
const url = await this.startServer(story, config);
|
|
137
|
+
const url = await this.startServer(story.deck, { kind: 'preview', file: config });
|
|
72
138
|
return { url: `${url}/1?slidevideo=1&slidevideo-preview=1` };
|
|
73
139
|
}
|
|
74
|
-
async start(
|
|
140
|
+
async start(deck, viewport, mode) {
|
|
75
141
|
const executablePath = executable('browser');
|
|
76
|
-
const url = await this.startServer(
|
|
77
|
-
|
|
78
|
-
this.
|
|
142
|
+
const url = await this.startServer(deck, mode);
|
|
143
|
+
executionSignal()?.throwIfAborted();
|
|
144
|
+
requireCondition(!this.closed, 'INTERRUPTED', 'Browser startup aborted', 5);
|
|
145
|
+
this.browser = await chromium.launch({
|
|
146
|
+
executablePath,
|
|
147
|
+
headless: true,
|
|
148
|
+
...(this.stagingDirectory ? { downloadsPath: this.stagingDirectory } : {}),
|
|
149
|
+
args: ['--no-sandbox', '--enable-usermedia-screen-capturing', '--auto-select-tab-capture-source-by-title=SlideVideo capture', '--disable-features=WebRTCPipeWireCapturer', '--autoplay-policy=no-user-gesture-required', '--disable-dev-shm-usage'],
|
|
150
|
+
});
|
|
151
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
152
|
+
await this.browser.close().catch(() => { });
|
|
153
|
+
executionSignal()?.throwIfAborted();
|
|
154
|
+
throw new ProductionError('INTERRUPTED', 'Browser startup aborted', 5);
|
|
155
|
+
}
|
|
156
|
+
this.page = await this.browser.newPage({ viewport: { width: viewport.width, height: viewport.height }, deviceScaleFactor: 1, acceptDownloads: false });
|
|
157
|
+
this.page.setDefaultNavigationTimeout(120000);
|
|
79
158
|
this.page.on('pageerror', error => { this.log += `\nBrowser error: ${error.message}`; });
|
|
80
|
-
await this.page.addInitScript(
|
|
81
|
-
const getDisplayMedia = navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);
|
|
82
|
-
navigator.mediaDevices.getDisplayMedia = async (constraints) => {
|
|
83
|
-
const stream = await getDisplayMedia(constraints);
|
|
84
|
-
const track = stream.getVideoTracks()[0];
|
|
85
|
-
track.contentHint = 'motion';
|
|
86
|
-
await track.applyConstraints({ frameRate: { min: output.fps, max: output.fps, ideal: output.fps } });
|
|
87
|
-
return stream;
|
|
88
|
-
};
|
|
159
|
+
await this.page.addInitScript(() => {
|
|
89
160
|
localStorage.setItem('slidev-camera', 'none');
|
|
90
161
|
localStorage.setItem('slidev-mic', 'none');
|
|
91
|
-
|
|
92
|
-
localStorage.setItem('slidev-record-framerate', JSON.stringify(output.fps));
|
|
93
|
-
}, story.output);
|
|
162
|
+
});
|
|
94
163
|
await this.page.goto(`${url}/1?slidevideo=1`);
|
|
95
164
|
await this.page.waitForFunction(() => Boolean(window.__slidevideo), { timeout: 120000 });
|
|
96
165
|
return this.page;
|
|
97
166
|
}
|
|
98
|
-
async inspectTargets(
|
|
167
|
+
async inspectTargets(deck, viewport) {
|
|
99
168
|
try {
|
|
100
|
-
const page = await this.start(
|
|
169
|
+
const page = await this.start(deck, viewport);
|
|
101
170
|
return await page.evaluate(() => window.__slidevideo.inspectTargets());
|
|
102
171
|
}
|
|
103
172
|
catch (error) {
|
|
@@ -107,15 +176,48 @@ export class SlidevAdapter {
|
|
|
107
176
|
await this.cleanup();
|
|
108
177
|
}
|
|
109
178
|
}
|
|
110
|
-
async
|
|
111
|
-
|
|
179
|
+
async stopCapture(page, durationMs) {
|
|
180
|
+
const signal = executionSignal();
|
|
181
|
+
signal?.throwIfAborted();
|
|
182
|
+
const limit = Math.max(60_000, Math.ceil(durationMs * 0.25) + 60_000);
|
|
183
|
+
let timer;
|
|
184
|
+
let onAbort;
|
|
185
|
+
try {
|
|
186
|
+
return await Promise.race([
|
|
187
|
+
page.evaluate(() => {
|
|
188
|
+
if (!window.__slidevideoCapture)
|
|
189
|
+
throw new Error('Capture session was not initialized');
|
|
190
|
+
return window.__slidevideoCapture.stop();
|
|
191
|
+
}),
|
|
192
|
+
new Promise((_, reject) => {
|
|
193
|
+
timer = setTimeout(() => reject(new ProductionError('CAPTURE_TIMEOUT', `Capture finalization exceeded ${Math.round(limit / 1000)}s`, 5)), limit);
|
|
194
|
+
if (signal) {
|
|
195
|
+
onAbort = () => reject(signal.reason ?? new ProductionError('INTERRUPTED', 'Capture finalization aborted', 5));
|
|
196
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
197
|
+
}
|
|
198
|
+
}),
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
if (signal && onAbort)
|
|
204
|
+
signal.removeEventListener('abort', onAbort);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async prepare(story, schedule, directory, production = { verify_timing: false, output: defaultVideoOutput }) {
|
|
112
208
|
this.schedule = schedule;
|
|
113
209
|
this.directory = directory;
|
|
114
210
|
this.production = production;
|
|
115
211
|
this.references = [];
|
|
212
|
+
this.stagingDirectory = join(directory, '.downloads');
|
|
213
|
+
this.rawCaptureFile = join(this.stagingDirectory, 'capture.webm');
|
|
214
|
+
this.captureToken = randomUUID();
|
|
116
215
|
await mkdir(directory, { recursive: true });
|
|
216
|
+
await mkdir(this.stagingDirectory, { recursive: true, mode: 0o700 });
|
|
217
|
+
const captureConfig = join(this.stagingDirectory, 'capture.json');
|
|
218
|
+
await writeFile(captureConfig, JSON.stringify({ file: this.rawCaptureFile, token: this.captureToken }), { mode: 0o600 });
|
|
117
219
|
try {
|
|
118
|
-
const page = await this.start(story);
|
|
220
|
+
const page = await this.start(story.deck, production.output, { kind: 'capture', file: captureConfig });
|
|
119
221
|
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
120
222
|
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
121
223
|
await page.addStyleTag({ content: 'body.slidevideo-capture .slidev-nav-controls, body.slidevideo-capture .slidev-nav {display:none!important}' });
|
|
@@ -172,11 +274,111 @@ export class SlidevAdapter {
|
|
|
172
274
|
await saveJson(join(directory, 'references.json'), { version: 1, references: this.references });
|
|
173
275
|
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
174
276
|
}
|
|
175
|
-
await page.evaluate((
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
277
|
+
await page.evaluate(async ({ output, token }) => {
|
|
278
|
+
document.title = 'SlideVideo capture';
|
|
279
|
+
const post = async (op, body) => {
|
|
280
|
+
const response = await fetch(`/__slidevideo_capture?op=${op}`, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
headers: { 'x-slidevideo-token': token },
|
|
283
|
+
body,
|
|
284
|
+
});
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
const detail = await response.text().catch(() => '');
|
|
287
|
+
throw new Error(`Capture stream ${op} failed (${response.status})${detail ? `: ${detail}` : ''}`);
|
|
288
|
+
}
|
|
289
|
+
return response;
|
|
290
|
+
};
|
|
291
|
+
await post('start');
|
|
292
|
+
const videoConstraints = {
|
|
293
|
+
frameRate: output.fps,
|
|
294
|
+
width: output.width,
|
|
295
|
+
height: output.height,
|
|
296
|
+
cursor: 'motion',
|
|
297
|
+
resizeMode: 'crop-and-scale',
|
|
298
|
+
};
|
|
299
|
+
const displayOptions = {
|
|
300
|
+
video: videoConstraints,
|
|
301
|
+
selfBrowserSurface: 'include',
|
|
302
|
+
};
|
|
303
|
+
const display = await navigator.mediaDevices.getDisplayMedia(displayOptions);
|
|
304
|
+
const videoTracks = display.getVideoTracks();
|
|
305
|
+
if (!videoTracks.length) {
|
|
306
|
+
for (const track of display.getTracks())
|
|
307
|
+
track.stop();
|
|
308
|
+
throw new Error('Display capture produced no video track');
|
|
309
|
+
}
|
|
310
|
+
const primaryTrack = videoTracks[0];
|
|
311
|
+
primaryTrack.contentHint = 'motion';
|
|
312
|
+
await primaryTrack.applyConstraints({ frameRate: { min: output.fps, max: output.fps, ideal: output.fps } });
|
|
313
|
+
const slidesStream = new MediaStream(videoTracks);
|
|
314
|
+
const mimeType = typeof MediaRecorder.isTypeSupported === 'function' && MediaRecorder.isTypeSupported('video/webm')
|
|
315
|
+
? 'video/webm'
|
|
316
|
+
: undefined;
|
|
317
|
+
const recorder = new MediaRecorder(slidesStream, {
|
|
318
|
+
...(mimeType ? { mimeType } : {}),
|
|
319
|
+
bitsPerSecond: 8192 * 1024,
|
|
320
|
+
});
|
|
321
|
+
let chain = Promise.resolve();
|
|
322
|
+
let failure = '';
|
|
323
|
+
const recordFailure = (error) => {
|
|
324
|
+
if (!failure)
|
|
325
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
326
|
+
if (!window.__slidevideo.state.failure)
|
|
327
|
+
window.__slidevideo.state.failure = failure;
|
|
328
|
+
};
|
|
329
|
+
recorder.ondataavailable = event => {
|
|
330
|
+
if (!event.data || event.data.size === 0 || failure)
|
|
331
|
+
return;
|
|
332
|
+
const chunk = event.data;
|
|
333
|
+
chain = chain.then(async () => {
|
|
334
|
+
if (failure)
|
|
335
|
+
return;
|
|
336
|
+
await post('chunk', chunk);
|
|
337
|
+
}).catch(recordFailure);
|
|
338
|
+
};
|
|
339
|
+
const stopped = new Promise(resolve => {
|
|
340
|
+
recorder.onerror = event => {
|
|
341
|
+
const detail = 'error' in event && event.error instanceof Error ? event.error.message : 'MediaRecorder error';
|
|
342
|
+
recordFailure(detail);
|
|
343
|
+
resolve();
|
|
344
|
+
};
|
|
345
|
+
recorder.onstop = () => resolve();
|
|
346
|
+
});
|
|
347
|
+
display.addEventListener('inactive', () => {
|
|
348
|
+
if (recorder.state !== 'inactive')
|
|
349
|
+
recordFailure('Capture stream ended unexpectedly');
|
|
350
|
+
}, { once: true });
|
|
351
|
+
recorder.start(1000);
|
|
352
|
+
window.__slidevideoCapture = {
|
|
353
|
+
stop: async () => {
|
|
354
|
+
try {
|
|
355
|
+
if (recorder.state !== 'inactive')
|
|
356
|
+
recorder.stop();
|
|
357
|
+
await stopped;
|
|
358
|
+
}
|
|
359
|
+
finally {
|
|
360
|
+
for (const track of display.getTracks())
|
|
361
|
+
track.stop();
|
|
362
|
+
}
|
|
363
|
+
await chain;
|
|
364
|
+
let bytes = 0;
|
|
365
|
+
try {
|
|
366
|
+
const finishResponse = await post('finish');
|
|
367
|
+
const report = await finishResponse.json();
|
|
368
|
+
if (report && typeof report === 'object' && 'bytes' in report && typeof report.bytes === 'number')
|
|
369
|
+
bytes = report.bytes;
|
|
370
|
+
}
|
|
371
|
+
catch (finishError) {
|
|
372
|
+
recordFailure(finishError);
|
|
373
|
+
}
|
|
374
|
+
if (failure)
|
|
375
|
+
throw new Error(failure);
|
|
376
|
+
if (!bytes)
|
|
377
|
+
throw new Error('Capture stream produced an empty recording');
|
|
378
|
+
return bytes;
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}, { output: production.output, token: this.captureToken });
|
|
180
382
|
await page.waitForTimeout(500);
|
|
181
383
|
}
|
|
182
384
|
catch (error) {
|
|
@@ -195,26 +397,76 @@ export class SlidevAdapter {
|
|
|
195
397
|
catch (error) {
|
|
196
398
|
playbackError = error;
|
|
197
399
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
400
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
401
|
+
executionSignal()?.throwIfAborted();
|
|
402
|
+
throw new ProductionError('INTERRUPTED', 'Capture aborted', 5);
|
|
403
|
+
}
|
|
404
|
+
let observed;
|
|
405
|
+
try {
|
|
406
|
+
observed = await page.evaluate(() => ({ events: window.__slidevideo.state.events, markers: window.__slidevideo.state.markers, failure: window.__slidevideo.state.failure, annotation_geometry: window.__slidevideo.state.annotation_geometry }));
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
if (!playbackError)
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
const expectedGeometry = geometryRequests(this.schedule).length;
|
|
413
|
+
if (observed) {
|
|
414
|
+
await saveJson(join(this.directory, 'events.json'), observed);
|
|
415
|
+
if (expectedGeometry)
|
|
416
|
+
await saveJson(join(this.directory, 'annotation-geometry.json'), { version: 1, geometry: observed.annotation_geometry ?? [], failure: observed.failure });
|
|
417
|
+
}
|
|
418
|
+
let stopError;
|
|
419
|
+
let stoppedCleanly = false;
|
|
420
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
421
|
+
try {
|
|
422
|
+
await this.stopCapture(page, this.schedule.duration_ms);
|
|
423
|
+
stoppedCleanly = true;
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
stopError = error;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const rawFile = this.rawCaptureFile;
|
|
206
430
|
const file = join(this.directory, 'native.webm');
|
|
207
|
-
|
|
208
|
-
|
|
431
|
+
let remuxedOk = false;
|
|
432
|
+
if (stoppedCleanly && !this.closed && !executionSignal()?.aborted) {
|
|
433
|
+
const rawStats = await stat(rawFile).catch(() => undefined);
|
|
434
|
+
if (rawStats && rawStats.size > 0) {
|
|
435
|
+
const remuxed = join(this.stagingDirectory, 'remuxed.webm');
|
|
436
|
+
try {
|
|
437
|
+
await execute('ffmpeg', ['-v', 'error', '-xerror', '-y', '-i', rawFile, '-c', 'copy', remuxed]);
|
|
438
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
439
|
+
await rename(remuxed, file);
|
|
440
|
+
await rm(rawFile, { force: true });
|
|
441
|
+
remuxedOk = true;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
catch (remuxError) {
|
|
445
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
446
|
+
await this.preserveRawCapture();
|
|
447
|
+
if (!playbackError && !observed?.failure)
|
|
448
|
+
throw remuxError;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
454
|
+
executionSignal()?.throwIfAborted();
|
|
455
|
+
throw new ProductionError('INTERRUPTED', 'Capture aborted', 5);
|
|
456
|
+
}
|
|
457
|
+
if (playbackError || observed?.failure)
|
|
458
|
+
throw new ProductionError('PLAYBACK', observed?.failure || String(playbackError), 5);
|
|
459
|
+
if (stopError)
|
|
460
|
+
throw stopError;
|
|
461
|
+
requireCondition(remuxedOk && Boolean(observed), 'CAPTURE_STREAM', 'Capture stream did not complete', 5);
|
|
209
462
|
progress?.(this.production.verify_timing ? 'Verifying captured timing' : 'Locating capture origin; per-cue timing verification skipped');
|
|
210
463
|
const properties = await probe(file);
|
|
211
|
-
requireCondition(properties.width === this.
|
|
212
|
-
requireCondition(
|
|
213
|
-
requireCondition((observed.annotation_geometry?.length ?? 0) === (this.schedule.annotations?.length ?? 0), 'ANNOTATION_GEOMETRY', 'Annotation geometry collection did not complete. See annotation-geometry.json.', 5);
|
|
464
|
+
requireCondition(properties.width === this.production.output.width && properties.height === this.production.output.height, 'CAPTURE_DIMENSIONS', 'Capture dimensions differ from requested full audience frame', 5);
|
|
465
|
+
requireCondition((observed.annotation_geometry?.length ?? 0) === expectedGeometry, 'ANNOTATION_GEOMETRY', 'Annotation geometry collection did not complete. See annotation-geometry.json.', 5);
|
|
214
466
|
const timing = this.production.verify_timing
|
|
215
467
|
? await calibrate(file, observed.markers, this.references, this.schedule.duration_ms, this.directory)
|
|
216
468
|
: await estimateOrigin(file, observed.markers, this.schedule.duration_ms, this.directory);
|
|
217
|
-
const visual = { version: 1, file, ...(
|
|
469
|
+
const visual = { version: 1, file, ...(expectedGeometry ? { annotation_geometry: observed.annotation_geometry ?? [] } : {}), properties, events: observed.events, origin: { method: this.production.verify_timing ? 'decoded_markers' : 'opening_markers', uncertainty_ms: timing.uncertainty_ms, mapping: timing.mapping }, timing, provenance: { adapter: this.id, version: this.version, dependencies: { chromium: this.browser.version(), slidev: '53.1.0', playwright: '1.65.1' } } };
|
|
218
470
|
await saveJson(join(this.directory, 'visual.json'), visual);
|
|
219
471
|
requireCondition(!this.production.verify_timing || timing.status === 'accepted', 'TIMING_ACCEPTANCE', 'Capture completed but decoded timing evidence failed. See calibration.json.', 6);
|
|
220
472
|
return visual;
|
|
@@ -225,27 +477,61 @@ export class SlidevAdapter {
|
|
|
225
477
|
}
|
|
226
478
|
}
|
|
227
479
|
async cleanup() {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
stop.once('close', code => {
|
|
239
|
-
clearTimeout(timer);
|
|
240
|
-
if (code === 0 || server.exitCode !== null)
|
|
241
|
-
resolve();
|
|
242
|
-
else
|
|
243
|
-
reject(new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process tree', 5));
|
|
244
|
-
});
|
|
245
|
-
});
|
|
480
|
+
this.closed = true;
|
|
481
|
+
try {
|
|
482
|
+
await (this.cleanupPromise ??= this.cleanupOnce());
|
|
483
|
+
}
|
|
484
|
+
finally {
|
|
485
|
+
if (this.directory) {
|
|
486
|
+
try {
|
|
487
|
+
await writeFile(join(this.directory, 'slidev.log'), this.log);
|
|
488
|
+
}
|
|
489
|
+
catch { }
|
|
246
490
|
}
|
|
247
|
-
else
|
|
248
|
-
this.server.kill('SIGTERM');
|
|
249
491
|
}
|
|
250
492
|
}
|
|
493
|
+
async preserveRawCapture() {
|
|
494
|
+
if (!this.rawCaptureFile || !this.directory)
|
|
495
|
+
return true;
|
|
496
|
+
const target = join(this.directory, 'native.webm');
|
|
497
|
+
const existing = await stat(target).catch(() => undefined);
|
|
498
|
+
if (existing && existing.size > 0)
|
|
499
|
+
return true;
|
|
500
|
+
const raw = await stat(this.rawCaptureFile).catch(() => undefined);
|
|
501
|
+
if (!raw || raw.size === 0)
|
|
502
|
+
return true;
|
|
503
|
+
try {
|
|
504
|
+
await rename(this.rawCaptureFile, target);
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
catch {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
async cleanupOnce() {
|
|
512
|
+
let browserError;
|
|
513
|
+
let serverError;
|
|
514
|
+
try {
|
|
515
|
+
await this.browser?.close();
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
browserError = error;
|
|
519
|
+
}
|
|
520
|
+
if (this.server) {
|
|
521
|
+
try {
|
|
522
|
+
await this.stopServer(this.server);
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
serverError = error;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const safeToRemoveStaging = await this.preserveRawCapture();
|
|
529
|
+
if (this.stagingDirectory && safeToRemoveStaging) {
|
|
530
|
+
await rm(this.stagingDirectory, { recursive: true, force: true }).catch(() => { });
|
|
531
|
+
}
|
|
532
|
+
if (serverError)
|
|
533
|
+
throw serverError;
|
|
534
|
+
if (browserError)
|
|
535
|
+
throw browserError;
|
|
536
|
+
}
|
|
251
537
|
}
|
|
@@ -1,19 +1,73 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnnotationGeometry, GeometryRequest, GeometryTarget, Rectangle, ResolvedAnnotation, ResolvedHighlightAnnotation, ResolvedUnderlineAnnotation, Schedule } from './contracts.js';
|
|
2
|
+
export type BlendMode = 'source-over' | 'darken';
|
|
2
3
|
export type AnnotationPaint = {
|
|
3
4
|
rectangle: Rectangle;
|
|
4
5
|
color: string;
|
|
5
6
|
opacity: number;
|
|
6
|
-
blend:
|
|
7
|
+
blend: BlendMode;
|
|
7
8
|
};
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export type HighlightFragmentPaint = {
|
|
10
|
+
fill: AnnotationPaint;
|
|
11
|
+
bottom_border?: AnnotationPaint;
|
|
12
|
+
};
|
|
13
|
+
export type HighlightEffect = {
|
|
14
|
+
effect: 'highlight';
|
|
15
|
+
start_ms: number;
|
|
16
|
+
end_ms: number;
|
|
17
|
+
fragments: HighlightFragmentPaint[];
|
|
18
|
+
};
|
|
19
|
+
export type UnderlineFragmentPaint = {
|
|
20
|
+
rectangle: Rectangle;
|
|
16
21
|
color: string;
|
|
17
22
|
opacity: number;
|
|
18
|
-
blend:
|
|
23
|
+
blend: BlendMode;
|
|
24
|
+
style: 'solid' | 'dashed';
|
|
25
|
+
};
|
|
26
|
+
export type UnderlineEffect = {
|
|
27
|
+
effect: 'underline';
|
|
28
|
+
start_ms: number;
|
|
29
|
+
end_ms: number;
|
|
30
|
+
in_ms: number;
|
|
31
|
+
out_ms: number;
|
|
32
|
+
fragments: UnderlineFragmentPaint[];
|
|
33
|
+
};
|
|
34
|
+
export type PaintableEffect = HighlightEffect | UnderlineEffect;
|
|
35
|
+
export type BlendGroup = {
|
|
36
|
+
blend: BlendMode;
|
|
37
|
+
primitives: AnnotationPaint[];
|
|
38
|
+
};
|
|
39
|
+
export interface EffectCanvas2D<FillStyle = never, StrokeStyle = never, CompositeOp = never> {
|
|
40
|
+
save(): void;
|
|
41
|
+
restore(): void;
|
|
42
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
43
|
+
fillRect(x: number, y: number, width: number, height: number): void;
|
|
44
|
+
fillStyle: string | FillStyle;
|
|
45
|
+
strokeStyle: string | StrokeStyle;
|
|
46
|
+
lineWidth: number;
|
|
47
|
+
globalAlpha: number;
|
|
48
|
+
globalCompositeOperation: BlendMode | CompositeOp;
|
|
49
|
+
}
|
|
50
|
+
export declare function targetKey(target: GeometryTarget): string;
|
|
51
|
+
export declare function annotationTargets(annotation: ResolvedAnnotation): GeometryTarget[];
|
|
52
|
+
export declare function geometryRequests(schedule: Pick<Schedule, 'annotations'>): GeometryRequest[];
|
|
53
|
+
export declare function findTargetGeometry(observations: readonly AnnotationGeometry[], annotation: Pick<ResolvedAnnotation, 'scene' | 'slide' | 'visit' | 'click' | 'start_ms' | 'end_ms'>, target: GeometryTarget): AnnotationGeometry | undefined;
|
|
54
|
+
export declare function highlightPaint(annotation: Pick<ResolvedHighlightAnnotation, 'appearance' | 'start_ms' | 'end_ms'>, { content, fragments, viewport }: Pick<AnnotationGeometry, 'content' | 'fragments' | 'viewport'>): HighlightEffect;
|
|
55
|
+
export declare function underlinePaint(annotation: Pick<ResolvedUnderlineAnnotation, 'appearance' | 'motion' | 'start_ms' | 'end_ms'>, { content, fragments, viewport }: Pick<AnnotationGeometry, 'content' | 'fragments' | 'viewport'>): UnderlineEffect;
|
|
56
|
+
export declare function annotationPaint(annotation: Pick<ResolvedHighlightAnnotation, 'effect' | 'appearance' | 'start_ms' | 'end_ms'> | Pick<ResolvedUnderlineAnnotation, 'effect' | 'appearance' | 'motion' | 'start_ms' | 'end_ms'>, geometry: Pick<AnnotationGeometry, 'content' | 'fragments' | 'viewport'>): PaintableEffect;
|
|
57
|
+
export declare function underlineFragmentsVisible(effect: Pick<UnderlineEffect, 'fragments'>): boolean;
|
|
58
|
+
export declare function underlineWipeFractions(effect: Pick<UnderlineEffect, 'start_ms' | 'end_ms' | 'in_ms' | 'out_ms'>, timeMs: number): {
|
|
59
|
+
wipeStart: number;
|
|
60
|
+
wipeEnd: number;
|
|
19
61
|
};
|
|
62
|
+
export declare function underlineFragmentPrimitives(fragment: UnderlineFragmentPaint, spanLeft: number, spanRight: number): AnnotationPaint[];
|
|
63
|
+
export declare function effectPrimitives(effects: readonly PaintableEffect[], timeMs: number): AnnotationPaint[];
|
|
64
|
+
export declare function effectNeedsBaseFrames(effects: readonly PaintableEffect[], timeMs: number): boolean;
|
|
65
|
+
export declare function groupEffectsByBlend(effects: readonly PaintableEffect[], timeMs: number): BlendGroup[];
|
|
66
|
+
export declare function effectDirtyBounds(effects: readonly PaintableEffect[], timeMs: number, extraRectangles: readonly Rectangle[], viewport: {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}): Rectangle | undefined;
|
|
70
|
+
export declare function paintPrimitives<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, primitives: readonly AnnotationPaint[], options?: {
|
|
71
|
+
backdrop?: boolean;
|
|
72
|
+
}): void;
|
|
73
|
+
export declare function paintEffects<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effects: readonly PaintableEffect[], timeMs: number): void;
|