@slidevideo/cli 0.2.1 → 0.3.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.
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url';
6
6
  import { nativePreview } from './powerpoint-preview.js';
7
7
  import { defaultVideoOutput, defaultViewport } from '../contracts.js';
8
8
  import { geometryRequests } from '../annotation-paint.js';
9
+ import { planStaticSkips, remapCaptureTimestamps } from './capture-compression.js';
9
10
  import { calibrate, estimateOrigin } from '../calibration.js';
10
11
  import { executionSignal, hasStageDeadline, hashFile, json, probe, saveJson, videoFramePeriod } from '../media.js';
11
12
  import { ProductionError, requireCondition } from '../errors.js';
@@ -31,10 +32,21 @@ function nativeFailure(failure) {
31
32
  function object(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
32
33
  function finite(value) { return typeof value === 'number' && Number.isFinite(value); }
33
34
  function rectangle(value) { return object(value) && ['x', 'y', 'width', 'height'].every(key => finite(value[key])) && Number(value.width) > 0 && Number(value.height) > 0; }
35
+ function effectSpanMs(effect) {
36
+ const cycleMs = effect.duration_ms * (effect.auto_reverse !== 0 ? 2 : 1);
37
+ const countSpan = effect.repeat_count > 0 ? cycleMs * effect.repeat_count : cycleMs;
38
+ if (effect.repeat_duration_ms > 0) {
39
+ return Math.max(0, effect.repeat_count > 0 ? Math.min(countSpan, effect.repeat_duration_ms) : effect.repeat_duration_ms);
40
+ }
41
+ return Math.max(0, countSpan);
42
+ }
43
+ function slideEntrySettleMs(slide) {
44
+ return Math.max(0, slide.transition_duration_ms) + Math.max(0, slide.entry_duration_ms);
45
+ }
34
46
  function parseDeck(value) {
35
47
  requireCondition(object(value) && value.version === 1 && value.kind === 'inspection' && typeof value.deck_sha256 === 'string' && finite(value.width) && finite(value.height) && value.width > 0 && value.height > 0 && Array.isArray(value.slides) && value.slides.length > 0 && Array.isArray(value.media) && Array.isArray(value.unsupported) && object(value.dependencies), 'POWERPOINT_PROTOCOL', 'Native inspection returned an invalid catalog', 5);
36
48
  for (const slide of value.slides) {
37
- requireCondition(object(slide) && typeof slide.id === 'string' && ['native_id', 'index', 'transition', 'auto_advance', 'hidden', 'interactive'].every(key => finite(slide[key])) && Array.isArray(slide.effects) && Array.isArray(slide.shapes), 'POWERPOINT_PROTOCOL', 'Native inspection returned an invalid slide', 5);
49
+ requireCondition(object(slide) && typeof slide.id === 'string' && ['native_id', 'index', 'transition', 'transition_duration_ms', 'auto_advance', 'hidden', 'interactive'].every(key => finite(slide[key])) && Array.isArray(slide.effects) && Array.isArray(slide.shapes), 'POWERPOINT_PROTOCOL', 'Native inspection returned an invalid slide', 5);
38
50
  for (const shape of slide.shapes) {
39
51
  requireCondition(object(shape), 'POWERPOINT_PROTOCOL', 'Native inspection returned an invalid shape identity', 5);
40
52
  const bounds = shape.bounds;
@@ -51,6 +63,7 @@ function parseDeck(value) {
51
63
  requireCondition(typeof version === 'string', 'POWERPOINT_PROTOCOL', 'Native inspection returned invalid dependency versions', 5);
52
64
  const deck = value;
53
65
  for (const slide of deck.slides) {
66
+ slide.entry_duration_ms = 0;
54
67
  slide.clicks = [];
55
68
  let previousStart = 0;
56
69
  let previousEnd = 0;
@@ -60,11 +73,12 @@ function parseDeck(value) {
60
73
  previousStart = 0;
61
74
  previousEnd = 0;
62
75
  }
63
- if (!slide.clicks.length)
64
- continue;
65
76
  const start = (effect.trigger === 3 ? previousEnd : previousStart) + effect.delay_ms;
66
- const end = start + effect.duration_ms;
67
- slide.clicks[slide.clicks.length - 1] = Math.max(slide.clicks[slide.clicks.length - 1], end);
77
+ const end = start + effectSpanMs(effect);
78
+ if (slide.clicks.length)
79
+ slide.clicks[slide.clicks.length - 1] = Math.max(slide.clicks[slide.clicks.length - 1], end);
80
+ else
81
+ slide.entry_duration_ms = Math.max(slide.entry_duration_ms, end);
68
82
  previousStart = start;
69
83
  previousEnd = end;
70
84
  }
@@ -106,6 +120,12 @@ function parseEvidence(value, directory, verified, requests, output) {
106
120
  requireCondition(object(marker) && marker.color === colors[index] && finite(marker.observed_ms) && finite(marker.rendered_by_ms) && finite(marker.paint_interval_ms) && marker.rendered_by_ms >= marker.observed_ms && marker.paint_interval_ms >= 0, 'POWERPOINT_PROTOCOL', 'Native marker has no measured paint interval', 6);
107
121
  for (const reference of value.references)
108
122
  requireCondition(object(reference) && typeof reference.id === 'string' && finite(reference.expected_ms) && typeof reference.before === 'string' && typeof reference.after === 'string' && ['transition', 'sample'].includes(String(reference.mode)) && finite(reference.frame_period_ms), 'POWERPOINT_PROTOCOL', 'Native verification returned an invalid reference', 6);
123
+ if (value.applied_skips !== undefined) {
124
+ requireCondition(Array.isArray(value.applied_skips), 'POWERPOINT_PROTOCOL', 'Native recording returned invalid static skip evidence', 5);
125
+ for (const skip of value.applied_skips) {
126
+ requireCondition(object(skip) && finite(skip.record_at_ms) && Number(skip.record_at_ms) >= 0 && finite(skip.skip_ms) && Number(skip.skip_ms) > 0, 'POWERPOINT_PROTOCOL', 'Native recording returned an invalid static skip entry', 5);
127
+ }
128
+ }
109
129
  for (const version of Object.values(value.dependencies))
110
130
  requireCondition(typeof version === 'string', 'POWERPOINT_PROTOCOL', 'Native recording returned invalid dependency versions', 5);
111
131
  return value;
@@ -251,8 +271,8 @@ class NativeSession {
251
271
  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);
252
272
  }
253
273
  }
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);
274
+ function isSupportedNativeEffect(deck, slide, effect) {
275
+ return [1, 2, 3].includes(effect.trigger) && effect.duration_ms >= 0 && effect.delay_ms >= 0 && effect.repeat_count >= 0 && effect.repeat_count <= 100 && effect.repeat_duration_ms >= 0 && effect.repeat_duration_ms <= 600000 && !deck.media.some(media => media.native_id === slide.native_id && media.shape === effect.shape);
256
276
  }
257
277
  function isSupportedNativeMedia(media) {
258
278
  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;
@@ -271,15 +291,12 @@ function deckCapabilityIssues(deck) {
271
291
  if (slide.id && (counts.get(slide.id) ?? 0) > 1) {
272
292
  issues.push({ slide: label, reason: `Slide name ${slide.id} is ambiguous; use slide-${slide.native_id}` });
273
293
  }
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' });
294
+ if (slide.transition_duration_ms < 0 || slide.auto_advance !== 0 || slide.hidden !== 0 || slide.interactive !== 0) {
295
+ issues.push({ slide: label, reason: 'Requires manual advancement, visible slides, finite transitions and no interactive animation sequences' });
276
296
  }
277
- let clicked = false;
278
297
  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' });
298
+ if (!isSupportedNativeEffect(deck, slide, effect)) {
299
+ issues.push({ slide: label, reason: 'Contains an unsupported effect; only finite MainSequence animations without unbounded repeats, interactive triggers or video animations are supported' });
283
300
  break;
284
301
  }
285
302
  }
@@ -325,6 +342,8 @@ export class PowerPointAdapter {
325
342
  index: slide.index,
326
343
  clicks: slide.clicks.length,
327
344
  clicks_known: true,
345
+ ...(slide.transition_duration_ms > 0 ? { transition_duration_ms: slide.transition_duration_ms } : {}),
346
+ ...(slide.entry_duration_ms > 0 ? { entry_duration_ms: slide.entry_duration_ms } : {}),
328
347
  ...(slide.clicks.length ? { click_durations_ms: [...slide.clicks] } : {}),
329
348
  })),
330
349
  media_ids: [...new Set(this.deck.media.map(media => media.id))],
@@ -354,9 +373,8 @@ export class PowerPointAdapter {
354
373
  targets() {
355
374
  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}`}` })) }));
356
375
  }
357
- async inspectTargets(_deck, viewport) {
376
+ async inspectTargets(_deck, _viewport) {
358
377
  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);
360
378
  return this.targets();
361
379
  }
362
380
  slide(id) {
@@ -368,21 +386,15 @@ export class PowerPointAdapter {
368
386
  const deck = this.deck;
369
387
  const schedule = options?.schedule;
370
388
  requireCondition(deck, 'POWERPOINT_INSPECTION', 'Inspect the native deck before validation', 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
- }
374
389
  requireCondition(deck.unsupported.length === 0, 'POWERPOINT_CAPABILITY', deck.unsupported.map(item => `${item.slide ? `Slide ${item.slide}: ` : ''}${item.reason}`).join('\n'), 3);
375
390
  for (const slide of deck.slides) {
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);
377
- let clicked = false;
391
+ requireCondition(slide.transition_duration_ms >= 0 && slide.auto_advance === 0 && slide.hidden === 0 && slide.interactive === 0, 'POWERPOINT_CAPABILITY', `Slide ${slide.id} requires manual advancement, visible slides, finite transitions and no interactive animation sequences`, 3);
378
392
  for (const effect of slide.effects) {
379
- if (effect.trigger === 1)
380
- clicked = true;
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);
393
+ requireCondition(isSupportedNativeEffect(deck, slide, effect), 'POWERPOINT_CAPABILITY', `Slide ${slide.id} contains an unsupported effect. Only finite MainSequence animations without unbounded repeats, interactive triggers or video animations are supported.`, 3);
382
394
  }
383
395
  }
384
396
  for (const media of deck.media)
385
- requireCondition(isSupportedNativeMedia(media), 'POWERPOINT_CAPABILITY', `Video ${media.id} requires full-source playback with no native trim, autoplay, loop, rewind or fullscreen transform`, 3);
397
+ requireCondition(isSupportedNativeMedia(media), 'POWERPOINT_CAPABILITY', `Video ${media.id} requires full-source embedded media with no native trim, autoplay, loop, rewind or fullscreen transform`, 3);
386
398
  for (const declaration of story.media) {
387
399
  const candidates = deck.media.filter(media => media.id === declaration.id);
388
400
  requireCondition(candidates.length > 0, 'MEDIA_TARGET', `The native deck has no embedded video named ${declaration.id}`, 3);
@@ -399,10 +411,13 @@ export class PowerPointAdapter {
399
411
  this.slide(scene.slide);
400
412
  const actions = [...story.scenes.flatMap(scene => scene.actions), ...story.cues.map(cue => ({ ...cue.action, id: cue.id }))];
401
413
  for (const action of actions) {
402
- if (action.type === 'slide')
403
- this.slide(action.target);
414
+ if (action.type === 'slide') {
415
+ const targetSlide = this.slide(action.target);
416
+ const requiredSettle = slideEntrySettleMs(targetSlide);
417
+ requireCondition(action.duration_ms + 0.1 >= requiredSettle, 'SLIDE_TRANSITION_DURATION', `Slide action ${action.id} must reserve at least ${requiredSettle} ms for ${targetSlide.id} transition and automatic entry animations`, 3);
418
+ }
404
419
  if (action.type === 'play')
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);
420
+ requireCondition((action.rate ?? 1) === 1, 'POWERPOINT_CAPABILITY', `Video action ${action.id} requires playback rate 1 in native PowerPoint playback`, 3);
406
421
  }
407
422
  for (const annotation of story.annotations)
408
423
  requireCondition(annotation.target.type !== 'element', 'ANNOTATION_TARGET', `Annotation ${annotation.id} uses a Slidev selector. PowerPoint requires an existing shape ID or normalized region.`, 3);
@@ -447,7 +462,13 @@ export class PowerPointAdapter {
447
462
  if (action.type === 'slide') {
448
463
  slide = this.slide(action.target);
449
464
  click = 0;
450
- operations.push({ id: item.id, scene: item.scene, type: 'slide', at_ms: item.start_ms, end_ms: item.end_ms, native_id: slide.native_id, settle_ms: action.duration_ms });
465
+ const requiredSettle = item.start_ms > 0 ? slideEntrySettleMs(slide) : slide.entry_duration_ms;
466
+ if (item.start_ms > 0 && !item.id.endsWith(':slide')) {
467
+ requireCondition(action.duration_ms + 0.1 >= requiredSettle, 'SLIDE_TRANSITION_DURATION', `Slide action ${item.id} must reserve at least ${requiredSettle} ms for ${slide.id} transition and automatic entry animations`, 3);
468
+ }
469
+ const settleMs = Math.max(action.duration_ms, requiredSettle);
470
+ requireCondition(item.start_ms + settleMs <= schedule.duration_ms + 0.1, 'SLIDE_TRANSITION_DURATION', `Slide ${item.id} requires ${settleMs} ms to settle on ${slide.id}, exceeding the resolved schedule duration`, 3);
471
+ operations.push({ id: item.id, scene: item.scene, type: 'slide', at_ms: item.start_ms, end_ms: item.start_ms + settleMs, native_id: slide.native_id, settle_ms: settleMs });
451
472
  }
452
473
  if (action.type === 'reveal') {
453
474
  requireCondition(slide && action.click === click + 1 && action.click <= slide.clicks.length && action.duration_ms + 0.1 >= slide.clicks[action.click - 1], 'REVEAL_TARGET', `Reveal ${item.id} must execute the next native click and include its complete duration`, 3);
@@ -460,7 +481,9 @@ export class PowerPointAdapter {
460
481
  const source = schedule.media.find(media => media.id === action.media);
461
482
  requireCondition(candidates.length === 1 && declaration && source, 'MEDIA_TARGET', `Video ${action.media} is missing or ambiguous on the active native slide`, 3);
462
483
  requireCondition(Math.abs(source.duration_ms - candidates[0].duration_ms) <= 100, 'MEDIA_SOURCE_MISMATCH', `Native video duration differs from source for ${action.media}`);
463
- operations.push({ id: item.id, scene: item.scene, type: 'play', at_ms: item.start_ms, end_ms: item.end_ms, native_id: candidates[0].native_id, shape: candidates[0].shape, source_duration_ms: source.duration_ms, frame_period_ms: 0 });
484
+ const trimStart = action.trim_start_ms ?? 0;
485
+ const trimEnd = action.trim_end_ms ?? source.duration_ms;
486
+ operations.push({ id: item.id, scene: item.scene, type: 'play', at_ms: item.start_ms, end_ms: item.end_ms, native_id: candidates[0].native_id, shape: candidates[0].shape, source_duration_ms: source.duration_ms, trim_start_ms: trimStart, trim_end_ms: trimEnd, frame_period_ms: 0 });
464
487
  }
465
488
  }
466
489
  for (const [index, operation] of operations.entries())
@@ -497,8 +520,11 @@ export class PowerPointAdapter {
497
520
  });
498
521
  const request = join(directory, 'request.json');
499
522
  const geometry_requests = geometryRequests(schedule).map(item => ({ ...item, native_id: this.slide(item.slide).native_id }));
523
+ const static_skips = mode === 'record' && !verifyTiming
524
+ ? planStaticSkips(operations.map(operation => ({ start_ms: operation.at_ms, end_ms: operation.end_ms })), geometry_requests.flatMap(item => [item.start_ms, item.end_ms]), schedule.duration_ms)
525
+ : [];
500
526
  const capture = mode === 'record' ? { ffmpeg: executable('ffmpeg'), ffprobe: executable('ffprobe') } : {};
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 });
527
+ 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, static_skips, ...capture });
502
528
  this.session = new NativeSession(directory, request);
503
529
  await this.session.waitFor('prepared.json', hasStageDeadline() ? undefined : 120000);
504
530
  }
@@ -512,7 +538,12 @@ export class PowerPointAdapter {
512
538
  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);
513
539
  progress?.(production.verify_timing ? 'Verifying captured timing' : 'Locating capture origin; per-cue timing verification skipped');
514
540
  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);
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 } };
541
+ let finalProperties = properties;
542
+ if (!production.verify_timing && observed.applied_skips?.length) {
543
+ await remapCaptureTimestamps(observed.file, timing.mapping.offset_ms, observed.applied_skips);
544
+ finalProperties = await probe(observed.file);
545
+ }
546
+ const visual = { version: 1, file: observed.file, properties: finalProperties, 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 } };
516
547
  await saveJson(join(directory, 'visual.json'), visual);
517
548
  requireCondition(!production.verify_timing || timing.status === 'accepted', 'TIMING_ACCEPTANCE', 'Native capture completed but decoded timing evidence failed. See calibration.json.', 6);
518
549
  return visual;
@@ -8,6 +8,7 @@ import { dirname, join, resolve } from 'node:path';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { defaultVideoOutput } from '../contracts.js';
10
10
  import { geometryRequests } from '../annotation-paint.js';
11
+ import { planStaticSkips, remapCaptureTimestamps } from './capture-compression.js';
11
12
  import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
12
13
  import { calibrate, estimateOrigin } from '../calibration.js';
13
14
  import { execute, probe, saveJson, hashFile, digest, videoFramePeriod, executionSignal } from '../media.js';
@@ -156,9 +157,351 @@ export class SlidevAdapter {
156
157
  this.page = await this.browser.newPage({ viewport: { width: viewport.width, height: viewport.height }, deviceScaleFactor: 1, acceptDownloads: false });
157
158
  this.page.setDefaultNavigationTimeout(120000);
158
159
  this.page.on('pageerror', error => { this.log += `\nBrowser error: ${error.message}`; });
160
+ const inFlightRequests = new Set();
161
+ const serverOrigin = new URL(url).origin;
162
+ const isInternalCaptureRequest = (requestUrl) => {
163
+ try {
164
+ const parsed = new URL(requestUrl);
165
+ return parsed.origin === serverOrigin && (parsed.pathname === '/__slidevideo_capture' || parsed.pathname === '/__slidevideo_preview');
166
+ }
167
+ catch {
168
+ return false;
169
+ }
170
+ };
171
+ this.page.on('request', request => {
172
+ if (!isInternalCaptureRequest(request.url()))
173
+ inFlightRequests.add(request);
174
+ });
175
+ this.page.on('requestfinished', request => { inFlightRequests.delete(request); });
176
+ this.page.on('requestfailed', request => { inFlightRequests.delete(request); });
177
+ await this.page.exposeFunction('__slidevideoHasInFlightRequests', () => inFlightRequests.size > 0);
159
178
  await this.page.addInitScript(() => {
160
179
  localStorage.setItem('slidev-camera', 'none');
161
180
  localStorage.setItem('slidev-mic', 'none');
181
+ const nativeSetTimeout = window.setTimeout.bind(window);
182
+ const nativeClearTimeout = window.clearTimeout.bind(window);
183
+ const nativeSetInterval = window.setInterval.bind(window);
184
+ const nativeClearInterval = window.clearInterval.bind(window);
185
+ const nativeRequestAnimationFrame = window.requestAnimationFrame.bind(window);
186
+ const nativeCancelAnimationFrame = window.cancelAnimationFrame.bind(window);
187
+ const pendingTimeouts = new Set();
188
+ const stringTimeoutCleanups = new Map();
189
+ const activeIntervals = new Set();
190
+ const pendingAnimationFrames = new Set();
191
+ const pendingIdleCallbacks = new Set();
192
+ const activeExternalSources = new Set();
193
+ const shadowHosts = new WeakSet();
194
+ let pendingAsync = 0;
195
+ if (typeof Element !== 'undefined' && typeof Element.prototype.attachShadow === 'function') {
196
+ const nativeAttachShadow = Element.prototype.attachShadow;
197
+ Element.prototype.attachShadow = function (init) {
198
+ shadowHosts.add(this);
199
+ return nativeAttachShadow.call(this, init);
200
+ };
201
+ }
202
+ const isFrameworkCaller = () => {
203
+ const frames = (new Error().stack ?? '').split('\n').slice(1).map(line => line.trim());
204
+ const caller = frames[2] ?? '';
205
+ return /\/@vite\/client|\/node_modules\/(?:@slidev\/|vue\/|@vue\/|\.vite\/deps\/(?:vue|vue-router|@vue_[^/?]+|@slidev_[^/?]+)\.js(?:[?:#]|$))|\/addons\/slidevideo\//.test(caller);
206
+ };
207
+ let internalDepth = 0;
208
+ window.setTimeout = ((handler, timeout, ...args) => {
209
+ if (internalDepth > 0 || isFrameworkCaller())
210
+ return nativeSetTimeout(handler, timeout, ...args);
211
+ let id = 0;
212
+ if (typeof handler === 'function') {
213
+ const wrapped = (...cbArgs) => { pendingTimeouts.delete(id); return handler.apply(window, cbArgs); };
214
+ id = nativeSetTimeout(wrapped, timeout, ...args);
215
+ pendingTimeouts.add(id);
216
+ }
217
+ else {
218
+ id = nativeSetTimeout(handler, timeout, ...args);
219
+ pendingTimeouts.add(id);
220
+ const delay = Math.max(0, Number(timeout) || 0) + 50;
221
+ const cleanupId = nativeSetTimeout(() => { pendingTimeouts.delete(id); stringTimeoutCleanups.delete(id); }, delay);
222
+ stringTimeoutCleanups.set(id, cleanupId);
223
+ }
224
+ return id;
225
+ });
226
+ const clearTrackedTimer = (id) => {
227
+ if (id === undefined || id === null)
228
+ return;
229
+ const numericId = Number(id);
230
+ if (!Number.isFinite(numericId))
231
+ return;
232
+ pendingTimeouts.delete(numericId);
233
+ activeIntervals.delete(numericId);
234
+ const cleanupId = stringTimeoutCleanups.get(numericId);
235
+ if (cleanupId !== undefined) {
236
+ nativeClearTimeout(cleanupId);
237
+ stringTimeoutCleanups.delete(numericId);
238
+ }
239
+ };
240
+ window.clearTimeout = ((id) => {
241
+ clearTrackedTimer(id);
242
+ return nativeClearTimeout(id);
243
+ });
244
+ window.setInterval = ((handler, timeout, ...args) => {
245
+ if (internalDepth > 0 || isFrameworkCaller())
246
+ return nativeSetInterval(handler, timeout, ...args);
247
+ const id = nativeSetInterval(handler, timeout, ...args);
248
+ activeIntervals.add(id);
249
+ return id;
250
+ });
251
+ window.clearInterval = ((id) => {
252
+ clearTrackedTimer(id);
253
+ return nativeClearInterval(id);
254
+ });
255
+ window.requestAnimationFrame = ((callback) => {
256
+ if (internalDepth > 0 || isFrameworkCaller())
257
+ return nativeRequestAnimationFrame(callback);
258
+ let id = 0;
259
+ id = nativeRequestAnimationFrame((time) => {
260
+ pendingAnimationFrames.delete(id);
261
+ return callback(time);
262
+ });
263
+ pendingAnimationFrames.add(id);
264
+ return id;
265
+ });
266
+ window.cancelAnimationFrame = ((id) => {
267
+ const numericId = Number(id);
268
+ if (Number.isFinite(numericId))
269
+ pendingAnimationFrames.delete(numericId);
270
+ return nativeCancelAnimationFrame(id);
271
+ });
272
+ if (typeof window.requestIdleCallback === 'function' && typeof window.cancelIdleCallback === 'function') {
273
+ const nativeRequestIdleCallback = window.requestIdleCallback.bind(window);
274
+ const nativeCancelIdleCallback = window.cancelIdleCallback.bind(window);
275
+ window.requestIdleCallback = ((callback, options) => {
276
+ if (internalDepth > 0 || isFrameworkCaller())
277
+ return nativeRequestIdleCallback(callback, options);
278
+ let id = 0;
279
+ id = nativeRequestIdleCallback((deadline) => {
280
+ pendingIdleCallbacks.delete(id);
281
+ return callback(deadline);
282
+ }, options);
283
+ pendingIdleCallbacks.add(id);
284
+ return id;
285
+ });
286
+ window.cancelIdleCallback = ((id) => {
287
+ const numericId = Number(id);
288
+ if (Number.isFinite(numericId))
289
+ pendingIdleCallbacks.delete(numericId);
290
+ return nativeCancelIdleCallback(id);
291
+ });
292
+ }
293
+ if (typeof window.fetch === 'function') {
294
+ const nativeFetch = window.fetch.bind(window);
295
+ const bodyMethods = ['arrayBuffer', 'blob', 'bytes', 'formData', 'json', 'text'];
296
+ const trackStream = (stream) => {
297
+ if (!stream)
298
+ return;
299
+ const record = stream;
300
+ if (typeof record.getReader === 'function') {
301
+ const origGetReader = record.getReader.bind(stream);
302
+ record.getReader = (...readerArgs) => {
303
+ const reader = origGetReader(...readerArgs);
304
+ if (reader && typeof reader.read === 'function') {
305
+ const origRead = reader.read.bind(reader);
306
+ reader.read = (...readArgs) => {
307
+ pendingAsync++;
308
+ return Promise.resolve(origRead(...readArgs)).finally(() => { pendingAsync--; });
309
+ };
310
+ }
311
+ return reader;
312
+ };
313
+ }
314
+ if (typeof record.pipeTo === 'function') {
315
+ const origPipeTo = record.pipeTo.bind(stream);
316
+ record.pipeTo = (...pipeArgs) => {
317
+ pendingAsync++;
318
+ return Promise.resolve(origPipeTo(...pipeArgs)).finally(() => { pendingAsync--; });
319
+ };
320
+ }
321
+ if (typeof record.pipeThrough === 'function') {
322
+ const origPipeThrough = record.pipeThrough.bind(stream);
323
+ record.pipeThrough = (...pipeArgs) => {
324
+ const derived = origPipeThrough(...pipeArgs);
325
+ trackStream(derived);
326
+ return derived;
327
+ };
328
+ }
329
+ if (typeof record.tee === 'function') {
330
+ const origTee = record.tee.bind(stream);
331
+ record.tee = () => {
332
+ const branches = origTee();
333
+ for (const branch of branches)
334
+ trackStream(branch);
335
+ return branches;
336
+ };
337
+ }
338
+ for (const key of [Symbol.asyncIterator, 'values']) {
339
+ if (typeof record[key] !== 'function')
340
+ continue;
341
+ const origIter = record[key].bind(stream);
342
+ record[key] = (...iterArgs) => {
343
+ const iterator = origIter(...iterArgs);
344
+ if (iterator && typeof iterator.next === 'function') {
345
+ const origNext = iterator.next.bind(iterator);
346
+ iterator.next = () => {
347
+ pendingAsync++;
348
+ return Promise.resolve(origNext()).finally(() => { pendingAsync--; });
349
+ };
350
+ }
351
+ return iterator;
352
+ };
353
+ }
354
+ };
355
+ const trackResponse = (response) => {
356
+ const record = response;
357
+ for (const method of bodyMethods) {
358
+ const orig = record[method];
359
+ if (typeof orig !== 'function')
360
+ continue;
361
+ record[method] = function (...bodyArgs) {
362
+ pendingAsync++;
363
+ return Promise.resolve(orig.apply(this, bodyArgs)).finally(() => { pendingAsync--; });
364
+ };
365
+ }
366
+ if (typeof record.clone === 'function') {
367
+ const origClone = record.clone.bind(response);
368
+ record.clone = () => trackResponse(origClone());
369
+ }
370
+ trackStream(response.body);
371
+ return response;
372
+ };
373
+ const isInternalEndpoint = (requestUrl) => {
374
+ try {
375
+ const parsed = new URL(requestUrl, location.href);
376
+ return parsed.origin === location.origin && (parsed.pathname === '/__slidevideo_capture' || parsed.pathname === '/__slidevideo_preview');
377
+ }
378
+ catch {
379
+ return false;
380
+ }
381
+ };
382
+ window.fetch = ((input, init) => {
383
+ const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
384
+ if (internalDepth > 0 || isInternalEndpoint(url) || isFrameworkCaller())
385
+ return nativeFetch(input, init);
386
+ pendingAsync++;
387
+ return nativeFetch(input, init).then(trackResponse).finally(() => { pendingAsync--; });
388
+ });
389
+ }
390
+ if (typeof XMLHttpRequest !== 'undefined') {
391
+ const nativeSend = XMLHttpRequest.prototype.send;
392
+ XMLHttpRequest.prototype.send = function (body) {
393
+ if (internalDepth === 0 && !isFrameworkCaller()) {
394
+ let settled = false;
395
+ const release = () => { if (!settled) {
396
+ settled = true;
397
+ pendingAsync--;
398
+ } };
399
+ pendingAsync++;
400
+ this.addEventListener('loadend', release, { once: true });
401
+ try {
402
+ return nativeSend.call(this, body);
403
+ }
404
+ catch (error) {
405
+ this.removeEventListener('loadend', release);
406
+ release();
407
+ throw error;
408
+ }
409
+ }
410
+ return nativeSend.call(this, body);
411
+ };
412
+ }
413
+ if (typeof IDBFactory !== 'undefined') {
414
+ for (const method of ['open', 'deleteDatabase']) {
415
+ const orig = IDBFactory.prototype[method];
416
+ if (typeof orig !== 'function')
417
+ continue;
418
+ IDBFactory.prototype[method] = function (...idbArgs) {
419
+ const request = orig.apply(this, idbArgs);
420
+ if (!isFrameworkCaller() && request && typeof request.addEventListener === 'function') {
421
+ let settled = false;
422
+ const release = () => { if (!settled) {
423
+ settled = true;
424
+ pendingAsync--;
425
+ } };
426
+ pendingAsync++;
427
+ request.addEventListener('success', release, { once: true });
428
+ request.addEventListener('error', release, { once: true });
429
+ }
430
+ return request;
431
+ };
432
+ }
433
+ }
434
+ if (typeof IDBDatabase !== 'undefined' && typeof IDBDatabase.prototype.transaction === 'function') {
435
+ const origTx = IDBDatabase.prototype.transaction;
436
+ IDBDatabase.prototype.transaction = function (...txArgs) {
437
+ const tx = origTx.apply(this, txArgs);
438
+ if (!isFrameworkCaller() && tx && typeof tx.addEventListener === 'function') {
439
+ let settled = false;
440
+ const release = () => { if (!settled) {
441
+ settled = true;
442
+ pendingAsync--;
443
+ } };
444
+ pendingAsync++;
445
+ tx.addEventListener('complete', release, { once: true });
446
+ tx.addEventListener('abort', release, { once: true });
447
+ tx.addEventListener('error', release, { once: true });
448
+ }
449
+ return tx;
450
+ };
451
+ }
452
+ for (const name of ['Worker', 'WebSocket', 'EventSource']) {
453
+ const NativeCtor = window[name];
454
+ if (typeof NativeCtor !== 'function')
455
+ continue;
456
+ window[name] = new Proxy(NativeCtor, {
457
+ construct(target, args, newTarget) {
458
+ const track = !isFrameworkCaller();
459
+ const instance = Reflect.construct(target, args, newTarget);
460
+ if (track) {
461
+ activeExternalSources.add(instance);
462
+ const release = () => { activeExternalSources.delete(instance); };
463
+ if (name === 'Worker' && typeof instance.terminate === 'function') {
464
+ const orig = instance.terminate.bind(instance);
465
+ instance.terminate = () => { release(); return orig(); };
466
+ }
467
+ if (name === 'EventSource' && typeof instance.close === 'function') {
468
+ const orig = instance.close.bind(instance);
469
+ instance.close = (...closeArgs) => { release(); return orig(...closeArgs); };
470
+ }
471
+ if (name === 'WebSocket' && typeof instance.addEventListener === 'function') {
472
+ instance.addEventListener('close', release, { once: true });
473
+ }
474
+ }
475
+ return instance;
476
+ },
477
+ });
478
+ }
479
+ window.__slidevideoTimers = {
480
+ hasPending: () => pendingTimeouts.size > 0 || activeIntervals.size > 0 || pendingAnimationFrames.size > 0 || pendingIdleCallbacks.size > 0 || pendingAsync > 0 || activeExternalSources.size > 0,
481
+ hasShadowHost: (root) => {
482
+ if (root.shadowRoot || shadowHosts.has(root))
483
+ return true;
484
+ for (const element of root.querySelectorAll('*')) {
485
+ if (element.shadowRoot || shadowHosts.has(element))
486
+ return true;
487
+ }
488
+ return false;
489
+ },
490
+ setInternalTimeout: (callback, ms) => { internalDepth++; try {
491
+ return nativeSetTimeout(callback, ms);
492
+ }
493
+ finally {
494
+ internalDepth--;
495
+ } },
496
+ clearInternalTimeout: id => nativeClearTimeout(id),
497
+ setInternalInterval: (callback, ms) => { internalDepth++; try {
498
+ return nativeSetInterval(callback, ms);
499
+ }
500
+ finally {
501
+ internalDepth--;
502
+ } },
503
+ clearInternalInterval: id => nativeClearInterval(id),
504
+ };
162
505
  });
163
506
  await this.page.goto(`${url}/1?slidevideo=1`);
164
507
  await this.page.waitForFunction(() => Boolean(window.__slidevideo), { timeout: 120000 });
@@ -390,9 +733,20 @@ export class SlidevAdapter {
390
733
  try {
391
734
  progress?.('Recording presentation');
392
735
  const page = this.page;
736
+ const plannedSkips = this.production.verify_timing
737
+ ? []
738
+ : planStaticSkips(this.schedule.actions.reduce((windows, item) => {
739
+ if (item.action.type === 'slide' || item.action.type === 'reveal') {
740
+ windows.push({ start_ms: item.start_ms, end_ms: item.start_ms + Math.max(0, item.action.duration_ms) });
741
+ }
742
+ else if (item.action.type === 'play') {
743
+ windows.push({ start_ms: item.start_ms, end_ms: item.end_ms });
744
+ }
745
+ return windows;
746
+ }, []), geometryRequests(this.schedule).flatMap(request => [request.start_ms, request.end_ms]), this.schedule.duration_ms);
393
747
  let playbackError;
394
748
  try {
395
- await page.evaluate(verify => window.__slidevideo.play(verify), this.production.verify_timing);
749
+ await page.evaluate(({ verify, skips }) => window.__slidevideo.play(verify, skips), { verify: this.production.verify_timing, skips: plannedSkips });
396
750
  }
397
751
  catch (error) {
398
752
  playbackError = error;
@@ -403,7 +757,7 @@ export class SlidevAdapter {
403
757
  }
404
758
  let observed;
405
759
  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 }));
760
+ 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, applied_skips: window.__slidevideo.state.applied_skips }));
407
761
  }
408
762
  catch (error) {
409
763
  if (!playbackError)
@@ -466,7 +820,12 @@ export class SlidevAdapter {
466
820
  const timing = this.production.verify_timing
467
821
  ? await calibrate(file, observed.markers, this.references, this.schedule.duration_ms, this.directory)
468
822
  : await estimateOrigin(file, observed.markers, this.schedule.duration_ms, this.directory);
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' } } };
823
+ let finalProperties = properties;
824
+ if (!this.production.verify_timing && observed.applied_skips?.length) {
825
+ await remapCaptureTimestamps(file, timing.mapping.offset_ms, observed.applied_skips);
826
+ finalProperties = await probe(file);
827
+ }
828
+ const visual = { version: 1, file, ...(expectedGeometry ? { annotation_geometry: observed.annotation_geometry ?? [] } : {}), properties: finalProperties, 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' } } };
470
829
  await saveJson(join(this.directory, 'visual.json'), visual);
471
830
  requireCondition(!this.production.verify_timing || timing.status === 'accepted', 'TIMING_ACCEPTANCE', 'Capture completed but decoded timing evidence failed. See calibration.json.', 6);
472
831
  return visual;
@@ -357,6 +357,8 @@ export type PresentationInspection = {
357
357
  index: number;
358
358
  clicks: number;
359
359
  clicks_known?: boolean;
360
+ transition_duration_ms?: number;
361
+ entry_duration_ms?: number;
360
362
  click_durations_ms?: number[];
361
363
  }[];
362
364
  media_ids: string[];
@@ -57,6 +57,8 @@ export declare function produce(options: Options): Promise<{
57
57
  index: number;
58
58
  clicks: number;
59
59
  clicks_known?: boolean;
60
+ transition_duration_ms?: number;
61
+ entry_duration_ms?: number;
60
62
  click_durations_ms?: number[];
61
63
  }[];
62
64
  media_ids: string[];