@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.
Files changed (64) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/IMPRESSUM.md +18 -4
  3. package/LICENSE-TERMS.md +46 -13
  4. package/README.md +5 -5
  5. package/addons/slidevideo/geometry.ts +63 -30
  6. package/addons/slidevideo/global-top.vue +41 -9
  7. package/addons/slidevideo/playback-entries.ts +17 -6
  8. package/addons/slidevideo/preview.ts +27 -15
  9. package/dist/adapters/browser-runtime.d.ts +3 -0
  10. package/dist/adapters/elevenlabs.d.ts +1 -0
  11. package/dist/adapters/elevenlabs.js +8 -4
  12. package/dist/adapters/powerpoint.d.ts +7 -4
  13. package/dist/adapters/powerpoint.js +123 -34
  14. package/dist/adapters/slidev-inspection.d.ts +5 -2
  15. package/dist/adapters/slidev-inspection.js +5 -6
  16. package/dist/adapters/slidev-server.js +136 -15
  17. package/dist/adapters/slidev.d.ts +12 -4
  18. package/dist/adapters/slidev.js +356 -70
  19. package/dist/annotation-paint.d.ts +65 -11
  20. package/dist/annotation-paint.js +290 -10
  21. package/dist/annotations.d.ts +13 -8
  22. package/dist/annotations.js +620 -89
  23. package/dist/assembly.d.ts +48 -40
  24. package/dist/assembly.js +72 -28
  25. package/dist/calibration.js +5 -4
  26. package/dist/cli.js +180 -39
  27. package/dist/compositor.d.ts +38 -6
  28. package/dist/compositor.js +299 -46
  29. package/dist/contracts.d.ts +96 -35
  30. package/dist/contracts.js +2 -1
  31. package/dist/executables.d.ts +2 -0
  32. package/dist/executables.js +27 -8
  33. package/dist/media.d.ts +12 -1
  34. package/dist/media.js +53 -4
  35. package/dist/pipeline.d.ts +36 -10
  36. package/dist/pipeline.js +163 -46
  37. package/dist/preview/contracts.d.ts +3 -3
  38. package/dist/preview/player.js +20 -15
  39. package/dist/preview/server.d.ts +2 -1
  40. package/dist/preview/server.js +8 -7
  41. package/dist/run.d.ts +1 -1
  42. package/dist/run.js +8 -3
  43. package/dist/setup-install.d.ts +1 -0
  44. package/dist/setup-install.js +8 -1
  45. package/dist/setup.d.ts +29 -8
  46. package/dist/setup.js +183 -76
  47. package/dist/skill-install.d.ts +35 -0
  48. package/dist/skill-install.js +132 -0
  49. package/dist/speech.js +10 -6
  50. package/dist/storyboard.js +12 -6
  51. package/dist/timing.js +2 -2
  52. package/package.json +4 -3
  53. package/schemas/annotation-geometry.v1.json +260 -28
  54. package/schemas/run-manifest.v1.json +31 -0
  55. package/schemas/schedule.v1.json +655 -1
  56. package/schemas/storyboard.v1.json +558 -33
  57. package/skills/slidevideo/SKILL.md +11 -9
  58. package/skills/slidevideo/references/decks.md +228 -0
  59. package/skills/slidevideo/references/production.md +17 -12
  60. package/skills/slidevideo/references/storyboard.md +71 -38
  61. package/tools/powerpoint/powerpoint.ps1 +52 -41
  62. package/tools/powerpoint/preview.ps1 +5 -5
  63. package/schemas/schedule.v2.json +0 -496
  64. package/schemas/storyboard.v2.json +0 -802
@@ -1,6 +1,10 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
+ import { configuredElevenLabsKey } from '../executables.js';
2
3
  import { requireCondition, ProductionError } from '../errors.js';
3
- import { decode, hashFile, probe, executionScope, audioDuration } from '../media.js';
4
+ import { decode, hashFile, probe, executionSignal, audioDuration } from '../media.js';
5
+ export function elevenLabsApiKey(environment = process.env) {
6
+ return environment.ELEVENLABS_API_KEY ?? environment.ELEVENLABS_KEY ?? configuredElevenLabsKey();
7
+ }
4
8
  export class ElevenLabsAdapter {
5
9
  id = 'elevenlabs';
6
10
  version = '1';
@@ -15,15 +19,15 @@ export class ElevenLabsAdapter {
15
19
  }
16
20
  }
17
21
  async synthesize(segment, voice, destination) {
18
- const key = process.env.ELEVENLABS_API_KEY ?? process.env.ELEVENLABS_KEY;
19
- requireCondition(key, 'TTS_CREDENTIAL', 'Set ELEVENLABS_API_KEY before generating speech', 4, { segment: segment.id });
22
+ const key = elevenLabsApiKey();
23
+ requireCondition(key, 'TTS_CREDENTIAL', 'Run slidevideo setup --provider elevenlabs to save an API key before generating speech', 4, { segment: segment.id });
20
24
  const options = voice.options ?? {};
21
25
  const { model_id = 'eleven_multilingual_v2', ...voice_settings } = options;
22
26
  let response;
23
27
  try {
24
28
  response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(voice.voice)}/with-timestamps?output_format=mp3_44100_128`, {
25
29
  method: 'POST', headers: { 'xi-api-key': key, 'Content-Type': 'application/json' },
26
- body: JSON.stringify({ text: segment.text, model_id, voice_settings }), signal: AbortSignal.any([AbortSignal.timeout(90000), ...executionScope.getStore() ? [executionScope.getStore()] : []]),
30
+ body: JSON.stringify({ text: segment.text, model_id, voice_settings }), signal: AbortSignal.any([AbortSignal.timeout(90000), ...executionSignal() ? [executionSignal()] : []]),
27
31
  });
28
32
  }
29
33
  catch {
@@ -1,5 +1,5 @@
1
1
  import type { NativePreview } from '../preview/contracts.js';
2
- import type { PresentationAdapter, PresentationInspection, ProductionOptions, ProgressReporter, Schedule, Storyboard, VisualArtifact } from '../contracts.js';
2
+ import { type PresentationAdapter, type PresentationInspection, type ProductionOptions, type ProgressReporter, type Schedule, type Storyboard, type Viewport, type VisualArtifact } from '../contracts.js';
3
3
  export declare class PowerPointAdapter implements PresentationAdapter {
4
4
  readonly id = "powerpoint";
5
5
  readonly version = "native-2";
@@ -9,12 +9,15 @@ export declare class PowerPointAdapter implements PresentationAdapter {
9
9
  private prepared?;
10
10
  inspect(file: string): Promise<PresentationInspection>;
11
11
  private targets;
12
- inspectTargets(_story: Storyboard): Promise<PresentationInspection['annotation_targets']>;
12
+ inspectTargets(_deck: string, viewport: Viewport): Promise<PresentationInspection['annotation_targets']>;
13
13
  private slide;
14
- validate(story: Storyboard, _inspection: PresentationInspection, schedule?: Schedule): void;
14
+ validate(story: Storyboard, _inspection: PresentationInspection, options?: {
15
+ viewport?: Viewport;
16
+ schedule?: Schedule;
17
+ }): Promise<void>;
15
18
  private operations;
16
19
  prepare(story: Storyboard, schedule: Schedule, directory: string, production?: ProductionOptions): Promise<void>;
17
- startPreview(story: Storyboard, schedule: Schedule, directory: string): Promise<NativePreview>;
20
+ startPreview(story: Storyboard, schedule: Schedule, directory: string, _parentOrigin?: string, viewport?: Viewport): Promise<NativePreview>;
18
21
  private openPlayback;
19
22
  execute(progress?: ProgressReporter): Promise<VisualArtifact>;
20
23
  cleanup(): Promise<void>;
@@ -1,12 +1,13 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { readFileSync } from 'node:fs';
3
2
  import { access, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
4
3
  import { tmpdir } from 'node:os';
5
4
  import { extname, join, resolve } from 'node:path';
6
5
  import { fileURLToPath } from 'node:url';
7
6
  import { nativePreview } from './powerpoint-preview.js';
7
+ import { defaultVideoOutput, defaultViewport } from '../contracts.js';
8
+ import { geometryRequests } from '../annotation-paint.js';
8
9
  import { calibrate, estimateOrigin } from '../calibration.js';
9
- import { digest, executionScope, hashFile, json, probe, saveJson, videoFramePeriod } from '../media.js';
10
+ import { executionSignal, hasStageDeadline, hashFile, json, probe, saveJson, videoFramePeriod } from '../media.js';
10
11
  import { ProductionError, requireCondition } from '../errors.js';
11
12
  import { packagePath } from '../installation.js';
12
13
  import { executable } from '../executables.js';
@@ -70,16 +71,32 @@ function parseDeck(value) {
70
71
  }
71
72
  return deck;
72
73
  }
73
- function parseEvidence(value, directory, verified, annotations, output) {
74
+ function validTarget(value, expected) {
75
+ if (!object(value) || value.type !== expected.type)
76
+ return false;
77
+ switch (expected.type) {
78
+ case 'slide': return true;
79
+ case 'region': return value.units === 'normalized' && value.x === expected.x && value.y === expected.y && value.width === expected.width && value.height === expected.height;
80
+ case 'element': return value.selector === expected.selector;
81
+ case 'shape': return value.id === expected.id;
82
+ }
83
+ }
84
+ function requestLabel(request) {
85
+ return request.annotations.length === 1
86
+ ? `Annotation ${request.annotations[0]}`
87
+ : `Annotations ${request.annotations.join(', ')}`;
88
+ }
89
+ function parseEvidence(value, directory, verified, requests, output) {
74
90
  requireCondition(object(value) && value.version === 1 && value.kind === 'recording' && value.file === join(directory, 'native.mp4') && Array.isArray(value.events) && Array.isArray(value.markers) && Array.isArray(value.references) && Array.isArray(value.annotation_geometry) && object(value.dependencies), 'POWERPOINT_PROTOCOL', 'Native recording returned invalid evidence', 5);
75
- requireCondition(value.annotation_geometry.length === annotations.length, 'ANNOTATION_GEOMETRY', 'Native recording did not measure every annotation interval', 5);
76
- for (const annotation of annotations) {
77
- const matches = value.annotation_geometry.filter(item => object(item) && item.id === annotation.id);
78
- requireCondition(matches.length === 1, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id} has missing or ambiguous native geometry`, 5);
91
+ requireCondition(value.annotation_geometry.length === requests.length, 'ANNOTATION_GEOMETRY', 'Native recording did not measure every target geometry interval', 5);
92
+ for (const request of requests) {
93
+ const label = `${requestLabel(request)} (${request.key}, ${request.slide}, visit ${request.visit})`;
94
+ const matches = value.annotation_geometry.filter(item => object(item) && item.key === request.key && item.scene === request.scene && item.slide === request.slide && item.visit === request.visit && item.click === request.click && item.start_ms === request.start_ms && item.end_ms === request.end_ms);
95
+ requireCondition(matches.length === 1, 'ANNOTATION_GEOMETRY', `${label} has missing or ambiguous native geometry`, 5);
79
96
  const geometry = matches[0];
80
- requireCondition(object(geometry) && geometry.id === annotation.id && geometry.scene === annotation.scene && geometry.slide === annotation.slide && geometry.visit === annotation.visit && geometry.click === annotation.click && geometry.start_ms === annotation.start_ms && geometry.end_ms === annotation.end_ms, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id} has invalid native playback state`, 5);
81
- requireCondition(finite(geometry.observed_start_ms) && finite(geometry.observed_end_ms) && geometry.observed_start_ms >= annotation.start_ms && geometry.observed_start_ms < annotation.end_ms && geometry.observed_start_ms - annotation.start_ms <= 100 && geometry.observed_end_ms >= annotation.end_ms && geometry.observed_end_ms - annotation.end_ms <= 100 && Number.isInteger(geometry.samples) && Number(geometry.samples) >= 2, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id} has incomplete native interval measurements`, 5);
82
- requireCondition(object(geometry.viewport) && geometry.viewport.width === output.width && geometry.viewport.height === output.height && rectangle(geometry.content) && geometry.content.x >= 0 && geometry.content.y >= 0 && geometry.content.x + geometry.content.width <= output.width && geometry.content.y + geometry.content.height <= output.height && rectangle(geometry.bounds) && geometry.bounds.x >= 0 && geometry.bounds.y >= 0 && geometry.bounds.x + geometry.bounds.width <= 1.000001 && geometry.bounds.y + geometry.bounds.height <= 1.000001, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id} has invalid native coordinate mapping`, 5);
97
+ requireCondition(object(geometry) && validTarget(geometry.target, request.target), 'ANNOTATION_GEOMETRY', `${label} has invalid native target metadata`, 5);
98
+ requireCondition(finite(geometry.observed_start_ms) && finite(geometry.observed_end_ms) && geometry.observed_start_ms >= request.start_ms && geometry.observed_start_ms < request.end_ms && geometry.observed_start_ms - request.start_ms <= 100 && geometry.observed_end_ms >= request.end_ms && geometry.observed_end_ms - request.end_ms <= 100 && Number.isInteger(geometry.samples) && Number(geometry.samples) >= 2, 'ANNOTATION_GEOMETRY', `${label} has incomplete native interval measurements`, 5);
99
+ requireCondition(object(geometry.viewport) && geometry.viewport.width === output.width && geometry.viewport.height === output.height && rectangle(geometry.content) && geometry.content.x >= 0 && geometry.content.y >= 0 && geometry.content.x + geometry.content.width <= output.width && geometry.content.y + geometry.content.height <= output.height && Array.isArray(geometry.fragments) && (request.target.type === 'slide' ? geometry.fragments.length === 0 : request.target.type === 'region' ? geometry.fragments.length === 1 : geometry.fragments.length >= 1) && geometry.fragments.every(bounds => rectangle(bounds) && bounds.x >= 0 && bounds.y >= 0 && bounds.x + bounds.width <= 1.000001 && bounds.y + bounds.height <= 1.000001), 'ANNOTATION_GEOMETRY', `${label} has invalid native coordinate mapping`, 5);
83
100
  }
84
101
  for (const event of value.events)
85
102
  requireCondition(object(event) && typeof event.id === 'string' && typeof event.type === 'string' && finite(event.scheduled_ms) && finite(event.observed_ms) && (event.media_ms === undefined || finite(event.media_ms)), 'POWERPOINT_PROTOCOL', 'Native execution returned an invalid observed event', 5);
@@ -167,9 +184,9 @@ class NativeSession {
167
184
  }
168
185
  }
169
186
  async waitFor(name, timeout) {
170
- const deadline = Date.now() + timeout;
187
+ const deadline = timeout === undefined ? Number.POSITIVE_INFINITY : Date.now() + timeout;
171
188
  while (Date.now() < deadline) {
172
- executionScope.getStore()?.throwIfAborted();
189
+ executionSignal()?.throwIfAborted();
173
190
  try {
174
191
  return await json(join(this.directory, name));
175
192
  }
@@ -234,6 +251,47 @@ class NativeSession {
234
251
  requireCondition(graceful && object(cleanup) && Array.isArray(cleanup.gaps) && cleanup.gaps.length === 0, 'POWERPOINT_CLEANUP', `Native cleanup could not be confirmed. Preserve the diagnostics in ${this.directory} and close only the identified private presentation if necessary.`, 5);
235
252
  }
236
253
  }
254
+ function isSupportedNativeEffect(deck, slide, effect, clicked) {
255
+ return [1, 10].includes(effect.type) && [1, 2, 3].includes(effect.trigger) && clicked && effect.duration_ms >= 0 && effect.delay_ms >= 0 && effect.repeat_count <= 1 && effect.repeat_count >= 0 && effect.repeat_duration_ms === 0 && effect.auto_reverse === 0 && effect.exit === 0 && !deck.media.some(media => media.native_id === slide.native_id && media.shape === effect.shape);
256
+ }
257
+ function isSupportedNativeMedia(media) {
258
+ return media.duration_ms > 0 && media.start_ms === 0 && Math.abs(media.end_ms - media.duration_ms) <= 1 && media.autoplay === 0 && media.loop === 0 && media.rewind === 0 && media.fullscreen === 0;
259
+ }
260
+ function deckCapabilityIssues(deck) {
261
+ const issues = deck.unsupported.map(item => ({
262
+ ...(item.slide ? { slide: item.slide } : {}),
263
+ reason: item.reason,
264
+ }));
265
+ const counts = new Map();
266
+ for (const slide of deck.slides)
267
+ if (slide.id)
268
+ counts.set(slide.id, (counts.get(slide.id) ?? 0) + 1);
269
+ for (const slide of deck.slides) {
270
+ const label = slide.id || `slide-${slide.native_id}`;
271
+ if (slide.id && (counts.get(slide.id) ?? 0) > 1) {
272
+ issues.push({ slide: label, reason: `Slide name ${slide.id} is ambiguous; use slide-${slide.native_id}` });
273
+ }
274
+ if (slide.transition !== 0 || slide.auto_advance !== 0 || slide.hidden !== 0 || slide.interactive !== 0) {
275
+ issues.push({ slide: label, reason: 'Requires slide cuts, manual advancement, visible slides and no interactive animation sequences' });
276
+ }
277
+ let clicked = false;
278
+ for (const effect of slide.effects) {
279
+ if (effect.trigger === 1)
280
+ clicked = true;
281
+ if (!isSupportedNativeEffect(deck, slide, effect, clicked)) {
282
+ issues.push({ slide: label, reason: 'Contains an unsupported effect; only finite click groups of entrance Appear and Fade effects are supported' });
283
+ break;
284
+ }
285
+ }
286
+ }
287
+ for (const media of deck.media) {
288
+ if (!isSupportedNativeMedia(media)) {
289
+ const owner = deck.slides.find(slide => slide.native_id === media.native_id);
290
+ issues.push({ slide: owner ? (owner.id || `slide-${owner.native_id}`) : `slide-${media.native_id}`, reason: `Video ${media.id} requires full-source playback with no native trim, autoplay, loop, rewind or fullscreen transform` });
291
+ }
292
+ }
293
+ return issues;
294
+ }
237
295
  export class PowerPointAdapter {
238
296
  id = 'powerpoint';
239
297
  version = 'native-2';
@@ -258,7 +316,34 @@ export class PowerPointAdapter {
258
316
  try {
259
317
  this.deck = parseDeck(await session.waitFor('result.json', 120000));
260
318
  completed = true;
261
- return { slides: this.deck.slides.map(slide => ({ id: slide.id || `slide-${slide.native_id}`, index: slide.index, clicks: slide.clicks.length, clicks_known: true })), media_ids: [...new Set(this.deck.media.map(media => media.id))], files: [resolve(file), helper, packagePath('tools', 'powerpoint', 'Native.cs'), fileURLToPath(import.meta.url)], capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:shape'], annotation_targets: this.targets() };
319
+ const unsupported = deckCapabilityIssues(this.deck);
320
+ return {
321
+ dimensions: { width: this.deck.width, height: this.deck.height },
322
+ slides: this.deck.slides.map(slide => ({
323
+ id: slide.id || `slide-${slide.native_id}`,
324
+ ...(slide.id ? { alias: `slide-${slide.native_id}` } : {}),
325
+ index: slide.index,
326
+ clicks: slide.clicks.length,
327
+ clicks_known: true,
328
+ ...(slide.clicks.length ? { click_durations_ms: [...slide.clicks] } : {}),
329
+ })),
330
+ media_ids: [...new Set(this.deck.media.map(media => media.id))],
331
+ ...(this.deck.media.length ? {
332
+ media: this.deck.media.map(media => {
333
+ const owner = this.deck.slides.find(slide => slide.native_id === media.native_id);
334
+ return {
335
+ id: media.id,
336
+ slide: owner ? (owner.id || `slide-${owner.native_id}`) : `slide-${media.native_id}`,
337
+ sha256: media.sha256,
338
+ duration_ms: media.duration_ms,
339
+ };
340
+ }),
341
+ } : {}),
342
+ files: [resolve(file), helper, packagePath('tools', 'powerpoint', 'Native.cs'), fileURLToPath(import.meta.url)],
343
+ capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:shape', 'underline:region', 'underline:shape'],
344
+ ...(unsupported.length ? { unsupported } : {}),
345
+ annotation_targets: this.targets(),
346
+ };
262
347
  }
263
348
  finally {
264
349
  await session.close();
@@ -267,10 +352,11 @@ export class PowerPointAdapter {
267
352
  }
268
353
  }
269
354
  targets() {
270
- return this.deck.slides.map(slide => ({ slide: slide.id || `slide-${slide.native_id}`, targets: slide.shapes.map(shape => ({ identity: String(shape.id), description: `Slide ${slide.index} (native ${slide.native_id}), shape ${shape.id}: ${shape.name}. ${shape.unsupported.length ? `Unsupported: ${shape.unsupported.join('; ')}` : `Stationary whole shape, visible from click ${shape.visible_from_click}`}` })) }));
355
+ return this.deck.slides.map(slide => ({ slide: slide.id || `slide-${slide.native_id}`, clicks: slide.clicks.length, targets: slide.shapes.map(shape => ({ identity: String(shape.id), description: `Slide ${slide.index} (native ${slide.native_id}), shape ${shape.id}: ${shape.name}. ${shape.unsupported.length ? `Unsupported: ${shape.unsupported.join('; ')}` : `Stationary whole shape, visible from click ${shape.visible_from_click}`}` })) }));
271
356
  }
272
- async inspectTargets(_story) {
357
+ async inspectTargets(_deck, viewport) {
273
358
  requireCondition(this.deck, 'POWERPOINT_INSPECTION', 'Inspect the native deck before discovering annotation targets', 3);
359
+ requireCondition(Math.abs(viewport.width / viewport.height - this.deck.width / this.deck.height) <= 2 / viewport.height, 'POWERPOINT_CAPABILITY', 'Native output aspect ratio must match the PowerPoint slide size. Adjust --width and --height or the deck page setup.', 3);
274
360
  return this.targets();
275
361
  }
276
362
  slide(id) {
@@ -278,10 +364,13 @@ export class PowerPointAdapter {
278
364
  requireCondition(slides.length === 1, 'SLIDE_REFERENCE', `Native slide ${id} is missing or ambiguous. Use a unique authored Slide.Name or slide-<SlideID>.`);
279
365
  return slides[0];
280
366
  }
281
- validate(story, _inspection, schedule) {
367
+ async validate(story, _inspection, options) {
282
368
  const deck = this.deck;
369
+ const schedule = options?.schedule;
283
370
  requireCondition(deck, 'POWERPOINT_INSPECTION', 'Inspect the native deck before validation', 3);
284
- requireCondition(Math.abs(story.output.width / story.output.height - deck.width / deck.height) <= 2 / story.output.height, 'POWERPOINT_CAPABILITY', 'Native output aspect ratio must match the PowerPoint slide size. Adjust storyboard output dimensions or the deck page setup.', 3);
371
+ if (options?.viewport) {
372
+ requireCondition(Math.abs(options.viewport.width / options.viewport.height - deck.width / deck.height) <= 2 / options.viewport.height, 'POWERPOINT_CAPABILITY', 'Native output aspect ratio must match the PowerPoint slide size. Adjust --width and --height or the deck page setup.', 3);
373
+ }
285
374
  requireCondition(deck.unsupported.length === 0, 'POWERPOINT_CAPABILITY', deck.unsupported.map(item => `${item.slide ? `Slide ${item.slide}: ` : ''}${item.reason}`).join('\n'), 3);
286
375
  for (const slide of deck.slides) {
287
376
  requireCondition(slide.transition === 0 && slide.auto_advance === 0 && slide.hidden === 0 && slide.interactive === 0, 'POWERPOINT_CAPABILITY', `Slide ${slide.id} requires slide cuts, manual advancement, visible slides and no interactive animation sequences`, 3);
@@ -289,17 +378,17 @@ export class PowerPointAdapter {
289
378
  for (const effect of slide.effects) {
290
379
  if (effect.trigger === 1)
291
380
  clicked = true;
292
- requireCondition([1, 10].includes(effect.type) && [1, 2, 3].includes(effect.trigger) && clicked && effect.duration_ms >= 0 && effect.delay_ms >= 0 && effect.repeat_count <= 1 && effect.repeat_count >= 0 && effect.repeat_duration_ms === 0 && effect.auto_reverse === 0 && effect.exit === 0 && !deck.media.some(media => media.native_id === slide.native_id && media.shape === effect.shape), 'POWERPOINT_CAPABILITY', `Slide ${slide.id} contains an unsupported effect. Only finite click groups of entrance Appear and Fade effects are supported; automatic entry, repeats, exits, interactive triggers and video animations are unsupported.`, 3);
381
+ requireCondition(isSupportedNativeEffect(deck, slide, effect, clicked), 'POWERPOINT_CAPABILITY', `Slide ${slide.id} contains an unsupported effect. Only finite click groups of entrance Appear and Fade effects are supported; automatic entry, repeats, exits, interactive triggers and video animations are unsupported.`, 3);
293
382
  }
294
383
  }
295
384
  for (const media of deck.media)
296
- requireCondition(media.duration_ms > 0 && media.start_ms === 0 && Math.abs(media.end_ms - media.duration_ms) <= 1 && media.autoplay === 0 && media.loop === 0 && media.rewind === 0 && media.fullscreen === 0, 'POWERPOINT_CAPABILITY', `Video ${media.id} requires full-source playback with no native trim, autoplay, loop, rewind or fullscreen transform`, 3);
385
+ requireCondition(isSupportedNativeMedia(media), 'POWERPOINT_CAPABILITY', `Video ${media.id} requires full-source playback with no native trim, autoplay, loop, rewind or fullscreen transform`, 3);
297
386
  for (const declaration of story.media) {
298
387
  const candidates = deck.media.filter(media => media.id === declaration.id);
299
388
  requireCondition(candidates.length > 0, 'MEDIA_TARGET', `The native deck has no embedded video named ${declaration.id}`, 3);
300
389
  let hash;
301
390
  try {
302
- hash = digest(readFileSync(declaration.src));
391
+ hash = await hashFile(declaration.src);
303
392
  }
304
393
  catch {
305
394
  throw new ProductionError('MISSING_MEDIA', `Cannot read media ${declaration.src}`);
@@ -315,11 +404,11 @@ export class PowerPointAdapter {
315
404
  if (action.type === 'play')
316
405
  requireCondition((action.trim_start_ms ?? 0) === 0 && action.trim_end_ms === undefined && (action.rate ?? 1) === 1, 'POWERPOINT_CAPABILITY', `Video action ${action.id} requires full-source playback at rate 1 without storyboard trims`, 3);
317
406
  }
318
- for (const annotation of story.annotations ?? [])
407
+ for (const annotation of story.annotations)
319
408
  requireCondition(annotation.target.type !== 'element', 'ANNOTATION_TARGET', `Annotation ${annotation.id} uses a Slidev selector. PowerPoint requires an existing shape ID or normalized region.`, 3);
320
409
  if (schedule) {
321
410
  this.operations(story, schedule);
322
- for (const annotation of schedule.annotations ?? []) {
411
+ for (const annotation of schedule.annotations) {
323
412
  const slide = this.slide(annotation.slide);
324
413
  if (annotation.target.type === 'shape') {
325
414
  const target = annotation.target;
@@ -381,15 +470,15 @@ export class PowerPointAdapter {
381
470
  }
382
471
  return operations;
383
472
  }
384
- async prepare(story, schedule, directory, production = { verify_timing: false }) {
385
- await this.openPlayback(story, schedule, directory, 'record', production.verify_timing);
386
- this.prepared = { story, schedule, directory: resolve(directory), production };
473
+ async prepare(story, schedule, directory, production = { verify_timing: false, output: defaultVideoOutput }) {
474
+ await this.openPlayback(story, schedule, directory, 'record', production.output, production.verify_timing);
475
+ this.prepared = { schedule, directory: resolve(directory), production };
387
476
  }
388
- async startPreview(story, schedule, directory) {
389
- await this.openPlayback(story, schedule, directory, 'preview', false);
477
+ async startPreview(story, schedule, directory, _parentOrigin, viewport = defaultViewport) {
478
+ await this.openPlayback(story, schedule, directory, 'preview', { ...viewport, fps: defaultVideoOutput.fps }, false);
390
479
  return nativePreview(command => this.session.preview(command));
391
480
  }
392
- async openPlayback(story, schedule, directory, mode, verifyTiming) {
481
+ async openPlayback(story, schedule, directory, mode, output, verifyTiming) {
393
482
  requireCondition(this.deck, 'POWERPOINT_INSPECTION', 'Inspect the native deck before playback', 3);
394
483
  requireCondition(!this.session, 'POWERPOINT_SESSION', 'This native adapter already owns a session', 5);
395
484
  directory = resolve(directory);
@@ -407,20 +496,20 @@ export class PowerPointAdapter {
407
496
  return source ? [{ ...clip, src: source.src }] : [];
408
497
  });
409
498
  const request = join(directory, 'request.json');
410
- const annotations = (schedule.annotations ?? []).map(annotation => ({ ...annotation, native_id: this.slide(annotation.slide).native_id }));
499
+ const geometry_requests = geometryRequests(schedule).map(item => ({ ...item, native_id: this.slide(item.slide).native_id }));
411
500
  const capture = mode === 'record' ? { ffmpeg: executable('ffmpeg'), ffprobe: executable('ffprobe') } : {};
412
- await saveJson(request, { version: 1, mode, directory, deck: story.deck, deck_sha256: this.deck.deck_sha256, parent_pid: process.pid, operations, annotations, media, output: story.output, duration_ms: schedule.duration_ms, verify_timing: verifyTiming, ...capture });
501
+ await saveJson(request, { version: 1, mode, directory, deck: story.deck, deck_sha256: this.deck.deck_sha256, parent_pid: process.pid, operations, geometry_requests, media, output, duration_ms: schedule.duration_ms, verify_timing: verifyTiming, ...capture });
413
502
  this.session = new NativeSession(directory, request);
414
- await this.session.waitFor('prepared.json', 120000);
503
+ await this.session.waitFor('prepared.json', hasStageDeadline() ? undefined : 120000);
415
504
  }
416
505
  async execute(progress) {
417
506
  requireCondition(this.session && this.prepared, 'POWERPOINT_SESSION', 'Prepare the native presentation before execution', 5);
418
- const { story, schedule, directory, production } = this.prepared;
507
+ const { schedule, directory, production } = this.prepared;
419
508
  progress?.('Recording native PowerPoint presentation');
420
509
  await writeFile(join(directory, 'start'), 'start\n');
421
- const observed = parseEvidence(await this.session.waitFor('result.json', schedule.duration_ms + 90000), directory, production.verify_timing, schedule.annotations ?? [], story.output);
510
+ const observed = parseEvidence(await this.session.waitFor('result.json', hasStageDeadline() ? undefined : schedule.duration_ms + 90000), directory, production.verify_timing, geometryRequests(schedule), production.output);
422
511
  const properties = await probe(observed.file);
423
- requireCondition(properties.width === story.output.width && properties.height === story.output.height && !properties.has_audio, 'CAPTURE_DIMENSIONS', 'Native capture must contain the requested audience dimensions and no audio', 5);
512
+ requireCondition(properties.width === production.output.width && properties.height === production.output.height && !properties.has_audio, 'CAPTURE_DIMENSIONS', 'Native capture must contain the requested audience dimensions and no audio', 5);
424
513
  progress?.(production.verify_timing ? 'Verifying captured timing' : 'Locating capture origin; per-cue timing verification skipped');
425
514
  const timing = production.verify_timing ? await calibrate(observed.file, observed.markers, observed.references, schedule.duration_ms, directory) : await estimateOrigin(observed.file, observed.markers, schedule.duration_ms, directory);
426
515
  const visual = { version: 1, file: observed.file, properties, events: observed.events, ...(observed.annotation_geometry.length ? { annotation_geometry: observed.annotation_geometry } : {}), origin: { method: production.verify_timing ? 'decoded_markers' : 'opening_markers', uncertainty_ms: timing.uncertainty_ms, mapping: timing.mapping }, timing, provenance: { adapter: this.id, version: this.version, dependencies: observed.dependencies } };
@@ -1,3 +1,6 @@
1
- import type { PresentationInspection, Storyboard, Schedule } from '../contracts.js';
1
+ import type { PresentationInspection, Storyboard, Schedule, Viewport } from '../contracts.js';
2
2
  export declare function inspectSlidev(deck: string): Promise<PresentationInspection>;
3
- export declare function validateSlidev(story: Storyboard, inspection: PresentationInspection, schedule?: Schedule): void;
3
+ export declare function validateSlidev(story: Storyboard, inspection: PresentationInspection, options?: {
4
+ viewport?: Viewport;
5
+ schedule?: Schedule;
6
+ }): void;
@@ -1,7 +1,7 @@
1
1
  import { access } from 'node:fs/promises';
2
2
  import { fork } from 'node:child_process';
3
3
  import { fileURLToPath } from 'node:url';
4
- import { dirname, extname } from 'node:path';
4
+ import { dirname } from 'node:path';
5
5
  import { slidevInputs } from './slidev-inputs.js';
6
6
  import { requireCondition, ProductionError } from '../errors.js';
7
7
  async function loadDeck(deck) {
@@ -28,7 +28,6 @@ async function loadDeck(deck) {
28
28
  }
29
29
  }
30
30
  export async function inspectSlidev(deck) {
31
- requireCondition(extname(deck) === '.md', 'PRESENTATION_ADAPTER', `Unsupported presentation format ${extname(deck)}`, 3);
32
31
  try {
33
32
  await access(deck);
34
33
  }
@@ -43,14 +42,14 @@ export async function inspectSlidev(deck) {
43
42
  }));
44
43
  requireCondition(new Set(slides.map(s => s.id)).size === slides.length, 'SLIDE_ID', 'Slide names must be unique');
45
44
  const media_ids = parsed.slides.flatMap(slide => [...slide.content.matchAll(/<(?:video|audio)\b[^>]*\bid=["']([^"']+)["']/g)].map(match => match[1]));
46
- return { slides, media_ids, files: await slidevInputs(deck, parsed.headmatter, parsed.files), capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:element'] };
45
+ return { slides, media_ids, files: await slidevInputs(deck, parsed.headmatter, parsed.files), capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:element', 'underline:region', 'underline:element'] };
47
46
  }
48
- export function validateSlidev(story, inspection, schedule) {
47
+ export function validateSlidev(story, inspection, options) {
48
+ const schedule = options?.schedule;
49
49
  for (const scene of story.scenes) {
50
50
  requireCondition(inspection.slides.some(s => s.id === scene.slide), 'SLIDE_REFERENCE', `Scene ${scene.id} has unknown slide ${scene.slide}`);
51
51
  }
52
- for (const annotation of story.annotations ?? []) {
53
- requireCondition(story.scenes.some(scene => scene.id === annotation.scene), 'ANNOTATION_SCENE', `Annotation ${annotation.id} has unknown scene ${annotation.scene}`);
52
+ for (const annotation of story.annotations) {
54
53
  requireCondition(annotation.target.type !== 'shape', 'ANNOTATION_TARGET', `Annotation ${annotation.id} uses a PowerPoint shape target unsupported by Slidev`, 3, { annotation: annotation.id });
55
54
  }
56
55
  const actions = [...story.scenes.flatMap(s => s.actions), ...story.cues.map(c => ({ ...c.action, id: c.id }))];
@@ -1,8 +1,18 @@
1
- import { createServer, resolveOptions, createDataUtils } from '@slidev/cli';
1
+ import { createServer, resolveOptions, createDataUtils, parser } from '@slidev/cli';
2
+ import { createWriteStream } from 'node:fs';
2
3
  import { readFile, realpath } from 'node:fs/promises';
4
+ import { createRequire } from 'node:module';
5
+ import { dirname } from 'node:path';
3
6
  import { packagePath } from '../installation.js';
4
- const [entry, port, previewFile] = process.argv.slice(2);
5
- const options = await resolveOptions({ entry, remote: '', base: '/' }, 'dev');
7
+ const [entry, port, mode, modeFile] = process.argv.slice(2);
8
+ const parsed = await parser.parse(await readFile(entry, 'utf8'), entry);
9
+ const declaredTheme = parsed.slides[0]?.frontmatter.theme;
10
+ let theme;
11
+ if (declaredTheme !== null && (!declaredTheme || declaredTheme === 'default' || declaredTheme === '@slidev/theme-default')) {
12
+ const manifest = createRequire(import.meta.url).resolve('@slidev/theme-default/package.json', { paths: [dirname(entry), packagePath()] });
13
+ theme = dirname(manifest).replaceAll('\\', '/');
14
+ }
15
+ const options = await resolveOptions({ entry, theme, remote: '', base: '/' }, 'dev');
6
16
  if (port === 'inspect') {
7
17
  if (!process.send || !process.disconnect)
8
18
  throw new Error('Inspection requires an IPC channel');
@@ -22,7 +32,36 @@ else {
22
32
  options.roots = [...new Set([...options.themeRoots, ...options.addonRoots, options.userRoot])];
23
33
  options.utils = await createDataUtils(options);
24
34
  }
25
- const config = previewFile ? await readFile(previewFile, 'utf8') : undefined;
35
+ const previewConfig = mode === 'preview' && modeFile ? await readFile(modeFile, 'utf8') : undefined;
36
+ let capture;
37
+ if (mode === 'capture' && modeFile) {
38
+ const parsed = JSON.parse(await readFile(modeFile, 'utf8'));
39
+ if (!parsed || typeof parsed !== 'object' || !('file' in parsed) || typeof parsed.file !== 'string' || !('token' in parsed) || typeof parsed.token !== 'string') {
40
+ throw new Error('Invalid Slidev capture configuration');
41
+ }
42
+ capture = { file: parsed.file, token: parsed.token };
43
+ }
44
+ let captureStream;
45
+ let bytesWritten = 0;
46
+ let streamError;
47
+ const closeCaptureStream = () => new Promise((resolve, reject) => {
48
+ const active = captureStream;
49
+ captureStream = undefined;
50
+ if (!active) {
51
+ resolve();
52
+ return;
53
+ }
54
+ if (streamError) {
55
+ active.destroy();
56
+ reject(streamError);
57
+ return;
58
+ }
59
+ const onClose = () => { active.off('error', onError); resolve(); };
60
+ const onError = (error) => { active.off('close', onClose); reject(error); };
61
+ active.once('close', onClose);
62
+ active.once('error', onError);
63
+ active.end();
64
+ });
26
65
  const server = await createServer(options, {
27
66
  server: {
28
67
  host: '127.0.0.1', port: Number(port), strictPort: true,
@@ -30,18 +69,100 @@ else {
30
69
  },
31
70
  logLevel: 'warn',
32
71
  base: '/',
33
- plugins: config ? [{
34
- name: 'slidevideo-preview',
35
- configureServer(server) {
36
- server.middlewares.use('/__slidevideo_preview', (_request, response) => {
37
- response.setHeader('Content-Type', 'application/json');
38
- response.setHeader('Cache-Control', 'no-store');
39
- response.end(config);
40
- });
41
- },
42
- }] : [],
72
+ plugins: [
73
+ ...(previewConfig ? [{
74
+ name: 'slidevideo-preview',
75
+ configureServer(viteServer) {
76
+ viteServer.middlewares.use('/__slidevideo_preview', (_request, response) => {
77
+ response.setHeader('Content-Type', 'application/json');
78
+ response.setHeader('Cache-Control', 'no-store');
79
+ response.end(previewConfig);
80
+ });
81
+ },
82
+ }] : []),
83
+ ...(capture ? [{
84
+ name: 'slidevideo-capture',
85
+ configureServer(viteServer) {
86
+ viteServer.middlewares.use('/__slidevideo_capture', (request, response) => {
87
+ void (async () => {
88
+ if (request.method !== 'POST' || request.headers['x-slidevideo-token'] !== capture.token) {
89
+ response.writeHead(403, { 'Content-Type': 'text/plain' });
90
+ response.end('Forbidden');
91
+ return;
92
+ }
93
+ const op = new URL(request.url ?? '', 'http://127.0.0.1').searchParams.get('op');
94
+ if (op === 'start') {
95
+ captureStream?.destroy();
96
+ bytesWritten = 0;
97
+ streamError = undefined;
98
+ const next = createWriteStream(capture.file, { flags: 'w', mode: 0o600 });
99
+ next.on('error', error => { streamError = error; });
100
+ await new Promise((resolve, reject) => {
101
+ next.once('open', () => resolve());
102
+ next.once('error', reject);
103
+ });
104
+ captureStream = next;
105
+ response.writeHead(204);
106
+ response.end();
107
+ return;
108
+ }
109
+ if (op === 'chunk') {
110
+ if (!captureStream)
111
+ throw new Error('Capture stream is not open');
112
+ if (streamError)
113
+ throw streamError;
114
+ for await (const chunk of request) {
115
+ if (streamError)
116
+ throw streamError;
117
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
118
+ bytesWritten += buffer.length;
119
+ if (!captureStream.write(buffer)) {
120
+ await new Promise((resolve, reject) => {
121
+ const active = captureStream;
122
+ if (!active) {
123
+ reject(new Error('Capture stream closed'));
124
+ return;
125
+ }
126
+ const onDrain = () => { active.off('error', onError); resolve(); };
127
+ const onError = (error) => { active.off('drain', onDrain); reject(error); };
128
+ active.once('drain', onDrain);
129
+ active.once('error', onError);
130
+ });
131
+ }
132
+ }
133
+ if (streamError)
134
+ throw streamError;
135
+ response.writeHead(204);
136
+ response.end();
137
+ return;
138
+ }
139
+ if (op === 'finish') {
140
+ await closeCaptureStream();
141
+ response.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
142
+ response.end(JSON.stringify({ bytes: bytesWritten }));
143
+ return;
144
+ }
145
+ response.writeHead(400, { 'Content-Type': 'text/plain' });
146
+ response.end('Unsupported capture operation');
147
+ })().catch(error => {
148
+ const message = error instanceof Error ? error.message : String(error);
149
+ if (!response.headersSent) {
150
+ response.writeHead(500, { 'Content-Type': 'text/plain' });
151
+ response.end(message);
152
+ }
153
+ else
154
+ response.destroy();
155
+ });
156
+ });
157
+ },
158
+ }] : []),
159
+ ],
43
160
  });
44
- const close = () => { void server.close().finally(() => process.exit()); };
161
+ const close = () => {
162
+ captureStream?.destroy();
163
+ captureStream = undefined;
164
+ void server.close().finally(() => process.exit());
165
+ };
45
166
  process.once('SIGINT', close);
46
167
  process.once('SIGTERM', close);
47
168
  await server.listen();
@@ -1,7 +1,7 @@
1
1
  import './browser-runtime.js';
2
2
  import { type Browser, type Page } from 'playwright';
3
3
  import { type ChildProcess } from 'node:child_process';
4
- import type { PresentationAdapter, Schedule, Storyboard, VisualArtifact, ProgressReporter, ProductionOptions, PresentationInspection } from '../contracts.js';
4
+ import { type PresentationAdapter, type Schedule, type Storyboard, type Viewport, type VisualArtifact, type ProgressReporter, type ProductionOptions, type PresentationInspection } from '../contracts.js';
5
5
  import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
6
6
  import { type Reference } from '../calibration.js';
7
7
  export declare class SlidevAdapter implements PresentationAdapter {
@@ -11,20 +11,28 @@ export declare class SlidevAdapter implements PresentationAdapter {
11
11
  page?: Page;
12
12
  server?: ChildProcess;
13
13
  log: string;
14
+ private cleanupPromise?;
15
+ private closed;
16
+ private stagingDirectory?;
17
+ private rawCaptureFile?;
18
+ private captureToken?;
14
19
  schedule: Schedule;
15
- story: Storyboard;
16
20
  directory: string;
17
21
  references: Reference[];
18
22
  production: ProductionOptions;
19
23
  inspect: typeof inspectSlidev;
20
24
  validate: typeof validateSlidev;
25
+ private stopServer;
21
26
  private startServer;
22
- startPreview(story: Storyboard, schedule: Schedule, directory: string, parentOrigin: string): Promise<{
27
+ startPreview(story: Storyboard, schedule: Schedule, directory: string, parentOrigin: string, _viewport?: Viewport): Promise<{
23
28
  url: string;
24
29
  }>;
25
30
  private start;
26
- inspectTargets(story: Storyboard): Promise<PresentationInspection['annotation_targets']>;
31
+ inspectTargets(deck: string, viewport: Viewport): Promise<PresentationInspection['annotation_targets']>;
32
+ private stopCapture;
27
33
  prepare(story: Storyboard, schedule: Schedule, directory: string, production?: ProductionOptions): Promise<void>;
28
34
  execute(progress?: ProgressReporter): Promise<VisualArtifact>;
29
35
  cleanup(): Promise<void>;
36
+ private preserveRawCapture;
37
+ private cleanupOnce;
30
38
  }