@slidevideo/cli 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/init.js ADDED
@@ -0,0 +1,223 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { mkdir, writeFile } from 'node:fs/promises';
3
+ import { dirname, extname, isAbsolute, join, relative, resolve } from 'node:path';
4
+ import { parse, stringify } from 'yaml';
5
+ import { presentationAdapter, ttsAdapters } from './adapters/registry.js';
6
+ import { defaultViewport } from './contracts.js';
7
+ import { requireCondition } from './errors.js';
8
+ import { validateStoryboard } from './storyboard.js';
9
+ const defaultProvider = 'edge-tts';
10
+ const defaultEdgeVoice = 'en-US-AriaNeural';
11
+ const silentHoldMs = 3000;
12
+ const trailingHoldMs = 500;
13
+ const clickHoldMs = 1500;
14
+ const defaultRevealMs = 400;
15
+ const clickMarkerPattern = /\[click\]/i;
16
+ function sanitizeId(raw, fallback) {
17
+ const cleaned = raw
18
+ .trim()
19
+ .replace(/[^a-zA-Z0-9_-]+/g, '-')
20
+ .replace(/-+/g, '-')
21
+ .replace(/^-+|-+$/g, '');
22
+ if (!cleaned)
23
+ return fallback;
24
+ return /^[a-zA-Z]/.test(cleaned) ? cleaned : `s-${cleaned}`;
25
+ }
26
+ function relativeDeckPath(outputFile, deckFile) {
27
+ const raw = relative(dirname(outputFile), deckFile);
28
+ if (!raw)
29
+ return './';
30
+ const normalized = raw.replaceAll('\\', '/');
31
+ if (isAbsolute(raw) || /^[a-zA-Z]:\//.test(normalized) || normalized.startsWith('//')) {
32
+ return normalized;
33
+ }
34
+ return normalized.startsWith('.') ? normalized : `./${normalized}`;
35
+ }
36
+ function resolveInitVoice(providerInput, voiceInput) {
37
+ const provider = providerInput?.trim() || defaultProvider;
38
+ const tts = ttsAdapters.get(provider);
39
+ requireCondition(tts, 'TTS_ADAPTER', `Unsupported TTS provider ${provider}`, 3);
40
+ const voiceId = voiceInput?.trim() || (provider === defaultProvider ? defaultEdgeVoice : '');
41
+ requireCondition(voiceId.length > 0, 'OPTION', `Pass --voice <id> when using --provider ${provider}`);
42
+ const voice = { provider, voice: voiceId };
43
+ tts.validate(voice);
44
+ return voice;
45
+ }
46
+ function buildStoryboardFromInspection(inspection, deckRef, voice) {
47
+ const usedIds = new Set();
48
+ const allocateId = (base, fallback = 'item') => {
49
+ const stem = sanitizeId(base, fallback);
50
+ if (!usedIds.has(stem)) {
51
+ usedIds.add(stem);
52
+ return stem;
53
+ }
54
+ let suffix = 2;
55
+ while (usedIds.has(`${stem}-${suffix}`))
56
+ suffix++;
57
+ const candidate = `${stem}-${suffix}`;
58
+ usedIds.add(candidate);
59
+ return candidate;
60
+ };
61
+ const narration = [];
62
+ const scenes = [];
63
+ const unusedClickMarkerSlides = [];
64
+ let narratedSlides = 0;
65
+ for (const slide of inspection.slides) {
66
+ const base = sanitizeId(slide.id, `slide-${slide.index}`);
67
+ const sceneId = allocateId(base, `slide-${slide.index}`);
68
+ const actions = [];
69
+ const revealDuration = (click) => Math.max(0, Math.round(slide.click_durations_ms?.[click - 1] ?? defaultRevealMs));
70
+ const notes = slide.notes;
71
+ let slideHasNarration = false;
72
+ const addSpeech = (stem, text) => {
73
+ const segmentId = allocateId(`narration-${stem}`, `narration-${slide.index}`);
74
+ narration.push({ id: segmentId, text });
75
+ actions.push({ id: allocateId(`say-${stem}`, `say-${slide.index}`), type: 'speak', segment: segmentId });
76
+ slideHasNarration = true;
77
+ };
78
+ const addHold = (stem, durationMs) => {
79
+ actions.push({ id: allocateId(`hold-${stem}`, `hold-${slide.index}`), type: 'hold', duration_ms: durationMs });
80
+ };
81
+ const addReveal = (click) => {
82
+ actions.push({
83
+ id: allocateId(`reveal-${base}-${click}`, `reveal-${slide.index}-${click}`),
84
+ type: 'reveal',
85
+ click,
86
+ duration_ms: revealDuration(click),
87
+ });
88
+ };
89
+ if (slide.clicks > 0 && notes && clickMarkerPattern.test(notes)) {
90
+ const rawChunks = notes.split(clickMarkerPattern).map(part => part.trim());
91
+ const chunks = rawChunks.slice(0, slide.clicks + 1);
92
+ if (rawChunks.length > slide.clicks + 1) {
93
+ const overflow = rawChunks.slice(slide.clicks + 1).filter(Boolean);
94
+ if (overflow.length) {
95
+ chunks[slide.clicks] = [chunks[slide.clicks], ...overflow].filter(Boolean).join('\n\n');
96
+ }
97
+ }
98
+ for (let click = 0; click <= slide.clicks; click++) {
99
+ if (click > 0)
100
+ addReveal(click);
101
+ const chunk = chunks[click];
102
+ if (chunk)
103
+ addSpeech(click === 0 ? base : `${base}-${click}`, chunk);
104
+ else if (click > 0)
105
+ addHold(`${base}-${click}`, clickHoldMs);
106
+ }
107
+ if (actions.at(-1)?.type === 'speak')
108
+ addHold(`${base}-end`, trailingHoldMs);
109
+ }
110
+ else if (slide.clicks > 0 && notes) {
111
+ addSpeech(base, notes);
112
+ for (let click = 1; click <= slide.clicks; click++) {
113
+ addReveal(click);
114
+ addHold(`${base}-${click}`, clickHoldMs);
115
+ }
116
+ }
117
+ else if (slide.clicks > 0) {
118
+ addHold(`${base}-intro`, clickHoldMs);
119
+ for (let click = 1; click <= slide.clicks; click++) {
120
+ addReveal(click);
121
+ addHold(`${base}-${click}`, clickHoldMs);
122
+ }
123
+ }
124
+ else if (notes) {
125
+ const cleaned = clickMarkerPattern.test(notes)
126
+ ? notes.split(clickMarkerPattern).map(part => part.trim()).filter(Boolean).join('\n\n')
127
+ : notes;
128
+ if (clickMarkerPattern.test(notes))
129
+ unusedClickMarkerSlides.push(slide.id);
130
+ if (cleaned) {
131
+ addSpeech(base, cleaned);
132
+ addHold(`${base}-end`, trailingHoldMs);
133
+ }
134
+ else {
135
+ addHold(base, silentHoldMs);
136
+ }
137
+ }
138
+ else {
139
+ addHold(base, silentHoldMs);
140
+ }
141
+ if (slideHasNarration)
142
+ narratedSlides++;
143
+ scenes.push({ id: sceneId, slide: slide.id, actions });
144
+ }
145
+ return {
146
+ storyboard: {
147
+ version: 1,
148
+ deck: deckRef,
149
+ voice,
150
+ media: [],
151
+ narration,
152
+ scenes,
153
+ cues: [],
154
+ annotations: [],
155
+ },
156
+ narratedSlides,
157
+ unusedClickMarkerSlides,
158
+ };
159
+ }
160
+ export async function initStoryboard(options) {
161
+ const deck = resolve(options.deck);
162
+ const output = resolve(options.output ?? join(dirname(deck), 'slidevideo.yaml'));
163
+ requireCondition(/^\.ya?ml$/i.test(extname(output)), 'OPTION', '--output for init must end with .yaml or .yml');
164
+ requireCondition(Boolean(options.force) || !existsSync(output), 'OUTPUT_EXISTS', `Storyboard already exists at ${output}. Pass --force to overwrite or --output <file> to write elsewhere.`);
165
+ const voice = resolveInitVoice(options.provider, options.voice);
166
+ const adapter = presentationAdapter(deck);
167
+ let inspection;
168
+ try {
169
+ inspection = await adapter.inspect(deck);
170
+ if (inspection.slides.some(slide => slide.clicks_known === false) && adapter.inspectTargets) {
171
+ const targets = await adapter.inspectTargets(deck, inspection.dimensions ?? defaultViewport);
172
+ const clicksBySlide = new Map((targets ?? []).map(entry => [entry.slide, entry.clicks]));
173
+ inspection = {
174
+ ...inspection,
175
+ slides: inspection.slides.map(slide => {
176
+ if (slide.clicks_known !== false)
177
+ return slide;
178
+ const mountedClicks = clicksBySlide.get(slide.id);
179
+ return typeof mountedClicks === 'number' && Number.isInteger(mountedClicks) && mountedClicks >= 0
180
+ ? { ...slide, clicks: mountedClicks, clicks_known: true }
181
+ : slide;
182
+ }),
183
+ };
184
+ }
185
+ }
186
+ finally {
187
+ await adapter.cleanup();
188
+ }
189
+ const deckRef = relativeDeckPath(output, deck);
190
+ const { storyboard, narratedSlides, unusedClickMarkerSlides } = buildStoryboardFromInspection(inspection, deckRef, voice);
191
+ const yamlText = stringify(storyboard, { lineWidth: 100 });
192
+ const validated = validateStoryboard(parse(yamlText), output);
193
+ await adapter.validate(validated, inspection);
194
+ await mkdir(dirname(output), { recursive: true });
195
+ await writeFile(output, yamlText, 'utf8');
196
+ const warnings = [];
197
+ if (narratedSlides === 0) {
198
+ warnings.push('No speaker notes were found in this deck. Generated slides use silent holds until you add speaker notes or edit narration in slidevideo.yaml.');
199
+ }
200
+ if (unusedClickMarkerSlides.length > 0) {
201
+ warnings.push(`Removed [click] markers from speaker notes on slides without reveal clicks (${unusedClickMarkerSlides.join(', ')}).`);
202
+ }
203
+ if (inspection.slides.some(slide => slide.clicks_known === false)) {
204
+ warnings.push('Slides without explicit click bounds require runtime reveal checks before recording.');
205
+ }
206
+ if ((inspection.unsupported?.length ?? 0) > 0) {
207
+ warnings.push('Deck contains unsupported native features. Adjust the deck before production.');
208
+ }
209
+ if (inspection.media_ids.length > 0) {
210
+ warnings.push(`Deck contains media elements (${inspection.media_ids.join(', ')}). Add media entries and play actions in slidevideo.yaml if you want to play them.`);
211
+ }
212
+ return {
213
+ version: 1,
214
+ command: 'init',
215
+ status: 'completed',
216
+ deck,
217
+ output,
218
+ slides: inspection.slides.length,
219
+ narrated_slides: narratedSlides,
220
+ voice,
221
+ warnings,
222
+ };
223
+ }
@@ -65,6 +65,7 @@ export declare function produce(options: Options): Promise<{
65
65
  transition_duration_ms?: number;
66
66
  entry_duration_ms?: number;
67
67
  click_durations_ms?: number[];
68
+ notes?: string;
68
69
  }[];
69
70
  media_ids: string[];
70
71
  media?: {
package/dist/pipeline.js CHANGED
@@ -2,6 +2,7 @@ import { mkdir, readdir, rm } from 'node:fs/promises';
2
2
  import { dirname, join, resolve } from 'node:path';
3
3
  import { defaultVideoOutput, defaultViewport } from './contracts.js';
4
4
  import { loadStoryboard, fingerprint } from './storyboard.js';
5
+ import { hasSlideScenes, hasStandaloneMediaSchedule, projectDeckSchedule } from './standalone-media.js';
5
6
  import { presentationAdapter, ttsAdapters } from './adapters/registry.js';
6
7
  import { generateSpeech, resolveSpeechCache } from './speech.js';
7
8
  import { resolveTiming } from './timing.js';
@@ -93,14 +94,17 @@ export async function produce(options) {
93
94
  const source = resolve(options.storyboard);
94
95
  const story = await loadStoryboard(source);
95
96
  const overlays = story.overlays ?? [];
96
- const adapter = presentationAdapter(story.deck);
97
+ const adapter = hasSlideScenes(story) ? presentationAdapter(story.deck) : undefined;
97
98
  const initialViewport = options.command === 'inspect'
98
99
  ? (options.inspect?.kind === 'storyboard' ? options.inspect.viewport : undefined) ?? options.viewport ?? defaultViewport
99
100
  : options.command === 'validate'
100
101
  ? options.viewport ?? defaultViewport
101
102
  : undefined;
102
- const inspection = await adapter.inspect(story.deck);
103
- await adapter.validate(story, inspection, initialViewport ? { viewport: initialViewport } : undefined);
103
+ const inspection = adapter
104
+ ? await adapter.inspect(story.deck)
105
+ : { slides: [], media_ids: [], files: [], capabilities: ['standalone-media'] };
106
+ if (adapter)
107
+ await adapter.validate(story, inspection, initialViewport ? { viewport: initialViewport } : undefined);
104
108
  for (const segment of story.narration) {
105
109
  const voice = segment.voice ?? story.voice;
106
110
  requireCondition(voice, 'VOICE_REQUIRED', `Narration ${segment.id} needs a voice`);
@@ -115,6 +119,8 @@ export async function produce(options) {
115
119
  if (inspection.slides.some(slide => slide.clicks_known === false))
116
120
  result.warnings.push('Slides without explicit click bounds require runtime reveal checks before recording.');
117
121
  if (options.command === 'inspect') {
122
+ if (!adapter)
123
+ return { ...result, inspection: { ...inspection, annotation_targets: [] } };
118
124
  requireCondition(adapter.inspectTargets, 'ANNOTATION_CAPABILITY', `Adapter ${adapter.id} does not expose annotation targets`, 3);
119
125
  activeAdapter = adapter;
120
126
  try {
@@ -157,12 +163,13 @@ export async function produce(options) {
157
163
  throw error;
158
164
  }
159
165
  requireCondition(entries.length === 0, 'NEW_RUN_REQUIRED', 'build requires a new or empty directory. Use --resume for unchanged inputs.');
160
- await adapter.validate(story, inspection, { viewport: options.viewport ?? defaultViewport });
166
+ if (adapter)
167
+ await adapter.validate(story, inspection, { viewport: options.viewport ?? defaultViewport });
161
168
  }
162
169
  await mkdir(directory, { recursive: true });
163
170
  }
164
171
  else {
165
- if (options.command === 'build') {
172
+ if (options.command === 'build' && adapter) {
166
173
  await adapter.validate(story, inspection, { viewport: options.viewport ?? defaultViewport });
167
174
  }
168
175
  directory = await createDefaultRunDirectory();
@@ -193,7 +200,7 @@ export async function produce(options) {
193
200
  if (['build', 'record', 'assemble'].includes(options.command)) {
194
201
  requireCondition(recordedMode === undefined || recordedMode === production.verify_timing, 'RUN_MODE_MISMATCH', 'Timing verification differs from this run. Start a new run directory.');
195
202
  requireCondition(recordedVideo === undefined || (recordedVideo.width === video.width && recordedVideo.height === video.height && recordedVideo.fps === video.fps), 'RUN_MODE_MISMATCH', 'Output dimensions or frame rate differ from this run. Start a new run directory.');
196
- if (!(options.command === 'build' && !options.resume) && (options.command !== 'assemble' || recordedVideo !== undefined)) {
203
+ if (adapter && !(options.command === 'build' && !options.resume) && (options.command !== 'assemble' || recordedVideo !== undefined)) {
197
204
  await adapter.validate(story, inspection, { viewport: video });
198
205
  }
199
206
  if (options.command === 'build' || options.command === 'record') {
@@ -216,7 +223,8 @@ export async function produce(options) {
216
223
  const verifiedSpeech = new Map();
217
224
  const resolveSchedule = async () => {
218
225
  const schedule = await resolveTiming(story, await json(speechPath), verifiedSpeech);
219
- await adapter.validate(story, inspection, { ...(resolveViewport ? { viewport: resolveViewport } : {}), schedule });
226
+ if (adapter)
227
+ await adapter.validate(story, inspection, { ...(resolveViewport ? { viewport: resolveViewport } : {}), schedule });
220
228
  return schedule;
221
229
  };
222
230
  const selected = options.command === 'build' ? ['tts', 'resolve', 'record', 'assemble'] : [options.command];
@@ -299,34 +307,55 @@ export async function produce(options) {
299
307
  artifacts.push(schedulePath);
300
308
  }
301
309
  if (stage === 'record') {
302
- activeAdapter = adapter;
303
- let recordError;
304
- try {
305
- await adapter.prepare(story, schedule, join(directory, 'recording'), production);
306
- const visual = await adapter.execute(options.progress);
310
+ if (!adapter) {
311
+ const mapping = { offset_ms: 0, rate: 1, trim_start_ms: 0, trim_end_ms: schedule.duration_ms };
312
+ const visual = {
313
+ version: 1,
314
+ file: '',
315
+ properties: { width: video.width, height: video.height, duration_ms: schedule.duration_ms, fps: video.fps, has_audio: false },
316
+ events: [],
317
+ origin: { method: 'opening_markers', uncertainty_ms: 0, mapping },
318
+ timing: { version: 1, status: 'not_evaluated', target_ms: 100, uncertainty_ms: 0, mapping, checks: [], coverage: [], gaps: ['Standalone MP4 scenes are assembled directly from source media without presentation capture.'] },
319
+ provenance: { adapter: 'standalone-media', version: '1' },
320
+ };
307
321
  await saveJson(visualPath, visual);
308
- requireCondition(visual.timing.status !== 'failed' && (!production.verify_timing || visual.timing.status === 'accepted'), 'TIMING_ACCEPTANCE', 'Presentation artifact has no required timing result', 6);
309
- artifacts.push(visual.file, ...visual.timing.checks.map(check => check.evidence));
310
- Object.assign(run.manifest.versions, visual.provenance.dependencies, { [`presentation:${visual.provenance.adapter}`]: visual.provenance.version });
311
- }
312
- catch (error) {
313
- recordError = error;
314
- throw error;
322
+ artifacts.push(visualPath);
323
+ run.manifest.versions['presentation:standalone-media'] = '1';
324
+ run.manifest.versions.ffmpeg = (await execute('ffmpeg', ['-version'])).toString().split('\n')[0];
315
325
  }
316
- finally {
326
+ else {
327
+ const projection = hasStandaloneMediaSchedule(schedule) ? projectDeckSchedule(story, schedule) : undefined;
328
+ const recordStory = projection?.storyboard ?? story;
329
+ const recordSchedule = projection?.schedule ?? schedule;
330
+ activeAdapter = adapter;
331
+ let recordError;
317
332
  try {
318
- await adapter.cleanup();
333
+ await adapter.prepare(recordStory, recordSchedule, join(directory, 'recording'), production);
334
+ const visual = await adapter.execute(options.progress);
335
+ await saveJson(visualPath, visual);
336
+ requireCondition(visual.timing.status !== 'failed' && (!production.verify_timing || visual.timing.status === 'accepted'), 'TIMING_ACCEPTANCE', 'Presentation artifact has no required timing result', 6);
337
+ artifacts.push(visual.file, ...visual.timing.checks.map(check => check.evidence));
338
+ Object.assign(run.manifest.versions, visual.provenance.dependencies, { [`presentation:${visual.provenance.adapter}`]: visual.provenance.version });
319
339
  }
320
- catch (cleanupError) {
321
- if (!recordError && !interrupted && !controller.signal.aborted)
322
- throw cleanupError;
340
+ catch (error) {
341
+ recordError = error;
342
+ throw error;
323
343
  }
324
344
  finally {
325
- activeAdapter = undefined;
345
+ try {
346
+ await adapter.cleanup();
347
+ }
348
+ catch (cleanupError) {
349
+ if (!recordError && !interrupted && !controller.signal.aborted)
350
+ throw cleanupError;
351
+ }
352
+ finally {
353
+ activeAdapter = undefined;
354
+ }
326
355
  }
356
+ artifacts.push(...await filesIn(join(directory, 'recording')));
357
+ run.manifest.versions.ffmpeg = (await execute('ffmpeg', ['-version'])).toString().split('\n')[0];
327
358
  }
328
- artifacts.push(...await filesIn(join(directory, 'recording')));
329
- run.manifest.versions.ffmpeg = (await execute('ffmpeg', ['-version'])).toString().split('\n')[0];
330
359
  }
331
360
  if (stage === 'assemble') {
332
361
  requireCondition(run.manifest.video, 'RUN_MANIFEST', 'Run manifest has no recorded video output settings. Start a new run directory.');
@@ -8,9 +8,14 @@ export type PreviewSession = {
8
8
  } | NativePreview;
9
9
  export type PreviewScene = {
10
10
  id: string;
11
+ kind?: 'slide' | 'media';
11
12
  slide: string;
13
+ media?: string;
14
+ media_url?: string;
12
15
  start_ms: number;
13
16
  end_ms: number;
17
+ deck_start_ms?: number;
18
+ deck_end_ms?: number;
14
19
  };
15
20
  export type PreviewAudioCue = {
16
21
  segment: string;
@@ -18,6 +23,17 @@ export type PreviewAudioCue = {
18
23
  end_ms: number;
19
24
  url: string;
20
25
  };
26
+ export type PreviewMediaSlice = {
27
+ media: string;
28
+ scene: string;
29
+ start_ms: number;
30
+ end_ms: number;
31
+ trim_start_ms: number;
32
+ trim_end_ms: number;
33
+ rate: number;
34
+ audio?: 'source' | 'muted';
35
+ volume?: number;
36
+ };
21
37
  export type PlayerConfig = {
22
38
  deck: string;
23
39
  duration: number;
@@ -27,10 +43,14 @@ export type PlayerConfig = {
27
43
  approximate_cues: string[];
28
44
  scenes: PreviewScene[];
29
45
  audio: PreviewAudioCue[];
46
+ media?: PreviewMediaSlice[];
47
+ standalone_annotations?: ResolvedAnnotation[];
30
48
  stage: {
31
49
  url: string;
32
50
  } | {
33
51
  annotations: ResolvedAnnotation[];
52
+ } | {
53
+ standalone: true;
34
54
  };
35
55
  };
36
56
  export type NativeFrame = {