@slidevideo/cli 0.2.2 → 0.3.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 (56) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -2
  3. package/addons/slidevideo/geometry.ts +334 -1
  4. package/addons/slidevideo/global-top.vue +311 -24
  5. package/addons/slidevideo/preview.ts +242 -25
  6. package/assets/fonts/OFL-LICENSES.txt +95 -0
  7. package/assets/fonts/instrument-serif-latin-2.woff2 +0 -0
  8. package/assets/fonts/instrument-serif-latin-ext-1.woff2 +0 -0
  9. package/assets/fonts/jetbrains-mono-latin-4.woff2 +0 -0
  10. package/assets/fonts/jetbrains-mono-latin-ext-3.woff2 +0 -0
  11. package/assets/fonts/plus-jakarta-sans-latin-6.woff2 +0 -0
  12. package/assets/fonts/plus-jakarta-sans-latin-ext-5.woff2 +0 -0
  13. package/dist/adapters/browser-runtime.d.ts +13 -1
  14. package/dist/adapters/capture-compression.d.ts +15 -0
  15. package/dist/adapters/capture-compression.js +69 -0
  16. package/dist/adapters/powerpoint-preview.d.ts +1 -1
  17. package/dist/adapters/powerpoint-preview.js +13 -2
  18. package/dist/adapters/powerpoint.js +108 -16
  19. package/dist/adapters/slidev-inspection.js +7 -2
  20. package/dist/adapters/slidev.js +362 -3
  21. package/dist/annotation-paint.d.ts +195 -5
  22. package/dist/annotation-paint.js +1188 -2
  23. package/dist/annotations.d.ts +26 -2
  24. package/dist/annotations.js +1117 -29
  25. package/dist/captions.d.ts +6 -0
  26. package/dist/captions.js +320 -0
  27. package/dist/cli.js +40 -17
  28. package/dist/compositor.js +51 -3
  29. package/dist/contracts.d.ts +253 -14
  30. package/dist/pipeline.d.ts +6 -1
  31. package/dist/pipeline.js +66 -19
  32. package/dist/preview/contracts.d.ts +14 -0
  33. package/dist/preview/player.js +523 -33
  34. package/dist/preview/server.d.ts +1 -1
  35. package/dist/preview/server.js +124 -3
  36. package/dist/preview/view.d.ts +1 -1
  37. package/dist/preview/view.js +26 -7
  38. package/dist/run.d.ts +1 -0
  39. package/dist/run.js +20 -0
  40. package/dist/speech.d.ts +10 -1
  41. package/dist/speech.js +18 -2
  42. package/dist/stamp-fonts.d.ts +17 -0
  43. package/dist/stamp-fonts.js +202 -0
  44. package/dist/storyboard.js +60 -3
  45. package/dist/timing.d.ts +2 -0
  46. package/dist/timing.js +277 -11
  47. package/package.json +14 -1
  48. package/schemas/annotation-geometry.v1.json +111 -0
  49. package/schemas/schedule.v1.json +1672 -84
  50. package/schemas/storyboard.v1.json +3725 -85
  51. package/skills/slidevideo/SKILL.md +5 -5
  52. package/skills/slidevideo/references/decks.md +6 -4
  53. package/skills/slidevideo/references/production.md +12 -11
  54. package/skills/slidevideo/references/storyboard.md +268 -5
  55. package/tools/powerpoint/powerpoint.ps1 +278 -40
  56. package/tools/powerpoint/preview.ps1 +69 -1
@@ -37,6 +37,10 @@ $locked = $false
37
37
  $createdApplication = $false
38
38
  $clock = [Diagnostics.Stopwatch]::StartNew()
39
39
  $origin = 0.0
40
+ $skippedMs = 0.0
41
+ $plannedSkips = @()
42
+ $nextSkipIndex = 0
43
+ $appliedSkips = [Collections.Generic.List[object]]::new()
40
44
  $events = [Collections.Generic.List[object]]::new()
41
45
  $markers = [Collections.Generic.List[object]]::new()
42
46
  $references = [Collections.Generic.List[object]]::new()
@@ -44,6 +48,7 @@ $cleanup = [Collections.Generic.List[string]]::new()
44
48
  $activeMedia = [Collections.Generic.List[object]]::new()
45
49
  $annotationMonitors = [Collections.Generic.List[object]]::new()
46
50
  $annotationGeometry = [Collections.Generic.List[object]]::new()
51
+ $resolvedTextTargets = @{}
47
52
  $collectAnnotations = $false
48
53
  $annotationStartBeforeMs = [double]::PositiveInfinity
49
54
  $activeVisit = ''
@@ -71,6 +76,9 @@ function Check-Cancel {
71
76
  if ($null -ne $parentStartedTicks -and $parent.StartTime.ToUniversalTime().Ticks -ne $parentStartedTicks) { Fail 'INTERRUPTED' 'The CLI process identity changed.' }
72
77
  }
73
78
  }
79
+ function Schedule-Now {
80
+ return ($clock.Elapsed.TotalMilliseconds - $origin) + $script:skippedMs
81
+ }
74
82
  function Wait-Until([double]$deadline) {
75
83
  while ($clock.Elapsed.TotalMilliseconds -lt $deadline) {
76
84
  Check-Cancel
@@ -80,7 +88,41 @@ function Wait-Until([double]$deadline) {
80
88
  $remaining = $deadline - $clock.Elapsed.TotalMilliseconds
81
89
  if ($collectAnnotations) {
82
90
  foreach ($monitor in $annotationMonitors) {
83
- if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $origin + $monitor.next_sample_ms - $clock.Elapsed.TotalMilliseconds) }
91
+ if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $monitor.next_sample_ms - (Schedule-Now)) }
92
+ }
93
+ }
94
+ if ($remaining -gt 4) { Start-Sleep -Milliseconds ([Math]::Min(20, [int]($remaining - 1))) }
95
+ else { [Threading.Thread]::Sleep(1) }
96
+ }
97
+ if ($collectAnnotations) { Check-Annotations }
98
+ }
99
+ function Wait-UntilSchedule([double]$targetMs) {
100
+ while ((Schedule-Now) -lt $targetMs) {
101
+ Check-Cancel
102
+ if ($null -ne $recorder -and $recorder.HasExited) { Fail 'POWERPOINT_CAPTURE' 'FFmpeg exited during native playback.' }
103
+ if ($activeMedia.Count -gt 0) { Check-Media }
104
+ if ($collectAnnotations) { Check-Annotations }
105
+ $now = Schedule-Now
106
+ if ($now -ge $targetMs) { break }
107
+ if ($script:nextSkipIndex -lt $script:plannedSkips.Count) {
108
+ $nextSkip = $script:plannedSkips[$script:nextSkipIndex]
109
+ if ([double]$nextSkip.schedule_start_ms -le $targetMs -and $now -ge [double]$nextSkip.schedule_start_ms) {
110
+ $script:nextSkipIndex++
111
+ $remainingSkip = [double]$nextSkip.schedule_end_ms - (Schedule-Now)
112
+ if ($remainingSkip -gt 0) {
113
+ $appliedSkips.Add(@{ record_at_ms = ($clock.Elapsed.TotalMilliseconds - $origin); skip_ms = $remainingSkip })
114
+ $script:skippedMs += $remainingSkip
115
+ }
116
+ continue
117
+ }
118
+ }
119
+ $remaining = $targetMs - $now
120
+ if ($script:nextSkipIndex -lt $script:plannedSkips.Count -and [double]$script:plannedSkips[$script:nextSkipIndex].schedule_start_ms -le $targetMs) {
121
+ $remaining = [Math]::Min($remaining, [double]$script:plannedSkips[$script:nextSkipIndex].schedule_start_ms - $now)
122
+ }
123
+ if ($collectAnnotations) {
124
+ foreach ($monitor in $annotationMonitors) {
125
+ if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $monitor.next_sample_ms - $now) }
84
126
  }
85
127
  }
86
128
  if ($remaining -gt 4) { Start-Sleep -Milliseconds ([Math]::Min(20, [int]($remaining - 1))) }
@@ -243,11 +285,45 @@ function Find-ShapeById($shapes, [int]$targetId, [bool]$ancestorInvalid = $false
243
285
  }
244
286
  return @($found.ToArray())
245
287
  }
246
- function Inspect-Shapes($slide, $shapes, $package, [bool]$ancestorTransformed, [int]$ancestorVisibleFromClick = 0, [string[]]$ancestorAnimReasons = @()) {
288
+ function Normalize-NativeText([string]$raw) {
289
+ $chars = [Text.StringBuilder]::new()
290
+ $starts = [Collections.Generic.List[int]]::new()
291
+ $ends = [Collections.Generic.List[int]]::new()
292
+ for ($i = 0; $i -lt $raw.Length; $i++) {
293
+ $ch = $raw[$i]
294
+ if ([char]::IsWhiteSpace($ch)) {
295
+ if ($chars.Length -gt 0) {
296
+ if ($chars[$chars.Length - 1] -ne [char]' ') {
297
+ [void]$chars.Append(' ')
298
+ $starts.Add($i)
299
+ $ends.Add($i + 1)
300
+ } else {
301
+ $ends[$ends.Count - 1] = $i + 1
302
+ }
303
+ }
304
+ } else {
305
+ [void]$chars.Append($ch)
306
+ $starts.Add($i)
307
+ $ends.Add($i + 1)
308
+ }
309
+ }
310
+ if ($chars.Length -gt 0 -and $chars[$chars.Length - 1] -eq [char]' ') {
311
+ $chars.Length = $chars.Length - 1
312
+ $starts.RemoveAt($starts.Count - 1)
313
+ $ends.RemoveAt($ends.Count - 1)
314
+ }
315
+ return @{ text = $chars.ToString(); starts = $starts; ends = $ends }
316
+ }
317
+ function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight, $shapes, $targetsByKey, $effectsByShape, [bool]$ancestorTransformed, [int]$ancestorVisibleFromClick = 0, [string[]]$ancestorAnimReasons = @()) {
247
318
  foreach ($shape in $shapes) {
248
319
  Check-Cancel
320
+ $shapeId = [int]$shape.Id
321
+ $shapeName = [string]$shape.Name
322
+ $shapeType = [int]$shape.Type
249
323
  $reasons = [Collections.Generic.List[string]]::new()
250
324
  $animReasons = [Collections.Generic.List[string]]::new()
325
+ $textReasons = [Collections.Generic.List[string]]::new()
326
+ $shapeText = $null
251
327
  $bounds = @{ x = 0.0; y = 0.0; width = 0.0; height = 0.0 }
252
328
  $visibleFromClick = $ancestorVisibleFromClick
253
329
  $isTransformed = $ancestorTransformed
@@ -256,7 +332,8 @@ function Inspect-Shapes($slide, $shapes, $package, [bool]$ancestorTransformed, [
256
332
  $animReasons.Add($inherited)
257
333
  }
258
334
  try {
259
- $metadata = @($package.targets | Where-Object { $_.native_id -eq $slide.SlideID -and $_.id -eq $shape.Id })
335
+ $targetKey = [string]$slideId + ':' + [string]$shapeId
336
+ $metadata = $(if ($targetsByKey.ContainsKey($targetKey)) { @($targetsByKey[$targetKey].ToArray()) } else { @() })
260
337
  if ($metadata.Count -ne 1) { $reasons.Add('shape identity is absent or ambiguous in the original slide package') }
261
338
  else {
262
339
  foreach ($reason in $metadata[0].unsupported) {
@@ -269,20 +346,28 @@ function Inspect-Shapes($slide, $shapes, $package, [bool]$ancestorTransformed, [
269
346
  if ([int]$shape.Visible -ne -1) { $reasons.Add('hidden shape'); $isTransformed = $true }
270
347
  if ([Math]::Abs([double]$shape.Rotation % 360) -gt 0.001 -or [int]$shape.ThreeD.Visible -ne 0) { $reasons.Add('rotated or three-dimensional shape'); $isTransformed = $true }
271
348
  if ([int]$shape.HorizontalFlip -ne 0 -or [int]$shape.VerticalFlip -ne 0) { $reasons.Add('flipped shape'); $isTransformed = $true }
272
- $bounds = @{ x = [double]$shape.Left / $presentation.PageSetup.SlideWidth; y = [double]$shape.Top / $presentation.PageSetup.SlideHeight; width = [double]$shape.Width / $presentation.PageSetup.SlideWidth; height = [double]$shape.Height / $presentation.PageSetup.SlideHeight }
349
+ $bounds = @{ x = [double]$shape.Left / $slideWidth; y = [double]$shape.Top / $slideHeight; width = [double]$shape.Width / $slideWidth; height = [double]$shape.Height / $slideHeight }
273
350
  if ($bounds.width -le 0 -or $bounds.height -le 0 -or $bounds.x -lt 0 -or $bounds.y -lt 0 -or $bounds.x + $bounds.width -gt 1.000001 -or $bounds.y + $bounds.height -gt 1.000001) { $reasons.Add('degenerate shape or shape clipped by slide bounds') }
274
- foreach ($effect in $slide.TimeLine.MainSequence) {
275
- if ([int]$effect.Shape.Id -ne [int]$shape.Id) { continue }
276
- if ([int]$effect.Exit -ne 0 -or [int]$effect.Timing.TriggerType -notin @(1, 2, 3) -or [int]$effect.Paragraph -gt 0 -or [int]$effect.EffectInformation.AfterEffect -ne 0 -or [double]$effect.Timing.RepeatCount -lt 0 -or [double]$effect.Timing.RepeatCount -gt 100 -or [double]$effect.Timing.RepeatDuration -lt 0) {
277
- $reason = 'exited, partial-text, hidden-after-animation or unbounded animated target'
278
- $reasons.Add($reason)
279
- $animReasons.Add($reason)
351
+ if ($effectsByShape.ContainsKey($shapeId)) {
352
+ foreach ($effect in $effectsByShape[$shapeId]) {
353
+ if ([int]$effect.exit -ne 0 -or [int]$effect.trigger -notin @(1, 2, 3) -or [int]$effect.paragraph -gt 0 -or [int]$effect.after_effect -ne 0 -or [double]$effect.repeat_count -lt 0 -or [double]$effect.repeat_count -gt 100 -or [double]$effect.repeat_duration_ms -lt 0) {
354
+ $reason = 'exited, partial-text, hidden-after-animation or unbounded animated target'
355
+ $reasons.Add($reason)
356
+ $animReasons.Add($reason)
357
+ }
280
358
  }
281
359
  }
360
+ if ([int]$shape.HasTextFrame -eq -1 -and [int]$shape.TextFrame.HasText -eq -1) {
361
+ $shapeText = (Normalize-NativeText ([string]$shape.TextFrame.TextRange.Text)).text
362
+ if ([int]$shape.TextFrame.Orientation -ne 1) { $textReasons.Add('non-horizontal text orientation') }
363
+ try {
364
+ if ($null -ne $shape.TextFrame2 -and [int]$shape.TextFrame2.WarpFormat -notin @(0, -2)) { $textReasons.Add('warped WordArt text') }
365
+ } catch {}
366
+ }
282
367
  } catch { $reasons.Add('native target geometry is unavailable: ' + $_.Exception.Message) }
283
368
  $children = @()
284
- if ([int]$shape.Type -eq 6) {
285
- $children = @(Inspect-Shapes $slide $shape.GroupItems $package $isTransformed $visibleFromClick @($animReasons.ToArray() | Select-Object -Unique))
369
+ if ($shapeType -eq 6) {
370
+ $children = @(Inspect-Shapes $slideId $slideWidth $slideHeight $shape.GroupItems $targetsByKey $effectsByShape $isTransformed $visibleFromClick @($animReasons.ToArray() | Select-Object -Unique))
286
371
  foreach ($child in $children) {
287
372
  $visibleFromClick = [Math]::Max($visibleFromClick, [int]$child.visible_from_click)
288
373
  foreach ($childReason in $child.unsupported) {
@@ -292,44 +377,61 @@ function Inspect-Shapes($slide, $shapes, $package, [bool]$ancestorTransformed, [
292
377
  }
293
378
  }
294
379
  }
295
- @{ id = [int]$shape.Id; name = [string]$shape.Name; bounds = $bounds; unsupported = @($reasons.ToArray() | Select-Object -Unique); visible_from_click = $visibleFromClick }
380
+ @{ id = $shapeId; name = $shapeName; bounds = $bounds; unsupported = @($reasons.ToArray() | Select-Object -Unique); visible_from_click = $visibleFromClick; text = $shapeText; text_unsupported = @($textReasons.ToArray() | Select-Object -Unique) }
296
381
  foreach ($child in $children) { $child }
297
382
  }
298
383
  }
299
384
  function Inspect-Native($package) {
385
+ $slideWidth = [double]$presentation.PageSetup.SlideWidth
386
+ $slideHeight = [double]$presentation.PageSetup.SlideHeight
387
+ $targetsByKey = @{}
388
+ foreach ($target in $package.targets) {
389
+ $key = [string]$target.native_id + ':' + [string]$target.id
390
+ if (!$targetsByKey.ContainsKey($key)) { $targetsByKey[$key] = [Collections.Generic.List[object]]::new() }
391
+ $targetsByKey[$key].Add($target)
392
+ }
300
393
  $slides = [Collections.Generic.List[object]]::new()
301
394
  foreach ($slide in $presentation.Slides) {
302
395
  Check-Cancel
396
+ $slideId = [int]$slide.SlideID
397
+ $slideName = [string]$slide.Name
303
398
  $effects = [Collections.Generic.List[object]]::new()
399
+ $effectsByShape = @{}
304
400
  foreach ($effect in $slide.TimeLine.MainSequence) {
305
401
  $timing = $effect.Timing
306
- $effects.Add(@{ type = [int]$effect.EffectType; trigger = [int]$timing.TriggerType; duration_ms = [double]$timing.Duration * 1000; delay_ms = [double]$timing.TriggerDelayTime * 1000; repeat_count = [double]$timing.RepeatCount; repeat_duration_ms = [double]$timing.RepeatDuration * 1000; auto_reverse = [int]$timing.AutoReverse; exit = [int]$effect.Exit; shape = [int]$effect.Shape.Id; paragraph = [int]$effect.Paragraph })
402
+ $effectShapeId = [int]$effect.Shape.Id
403
+ $entry = @{ type = [int]$effect.EffectType; trigger = [int]$timing.TriggerType; duration_ms = [double]$timing.Duration * 1000; delay_ms = [double]$timing.TriggerDelayTime * 1000; repeat_count = [double]$timing.RepeatCount; repeat_duration_ms = [double]$timing.RepeatDuration * 1000; auto_reverse = [int]$timing.AutoReverse; exit = [int]$effect.Exit; shape = $effectShapeId; paragraph = [int]$effect.Paragraph }
404
+ $effects.Add($entry)
405
+ if (!$effectsByShape.ContainsKey($effectShapeId)) { $effectsByShape[$effectShapeId] = [Collections.Generic.List[object]]::new() }
406
+ $effectsByShape[$effectShapeId].Add(@{ trigger = $entry.trigger; repeat_count = $entry.repeat_count; repeat_duration_ms = $entry.repeat_duration_ms; exit = $entry.exit; paragraph = $entry.paragraph; after_effect = [int]$effect.EffectInformation.AfterEffect })
307
407
  }
308
- $shapes = @(Inspect-Shapes $slide $slide.Shapes $package $false)
408
+ $shapes = @(Inspect-Shapes $slideId $slideWidth $slideHeight $slide.Shapes $targetsByKey $effectsByShape $false)
309
409
  $transitionEffect = [int]$slide.SlideShowTransition.EntryEffect
310
410
  $transitionDurationMs = $(if ($transitionEffect -ne 0) { [Math]::Round([double]$slide.SlideShowTransition.Duration * 1000) } else { 0 })
311
- $slides.Add(@{ id = [string]$slide.Name; native_id = [int]$slide.SlideID; index = [int]$slide.SlideIndex; effects = @($effects.ToArray()); shapes = $shapes; transition = $transitionEffect; transition_duration_ms = $transitionDurationMs; auto_advance = [int]$slide.SlideShowTransition.AdvanceOnTime; hidden = [int]$slide.SlideShowTransition.Hidden; interactive = [int]$slide.TimeLine.InteractiveSequences.Count })
411
+ $slides.Add(@{ id = $slideName; native_id = $slideId; index = [int]$slide.SlideIndex; effects = @($effects.ToArray()); shapes = $shapes; transition = $transitionEffect; transition_duration_ms = $transitionDurationMs; auto_advance = [int]$slide.SlideShowTransition.AdvanceOnTime; hidden = [int]$slide.SlideShowTransition.Hidden; interactive = [int]$slide.TimeLine.InteractiveSequences.Count })
312
412
  foreach ($shape in $slide.Shapes) {
313
413
  if ([int]$shape.Type -eq 16) {
314
- if ([int]$shape.MediaType -ne 3) { $package.unsupported += @{ slide = [string]$slide.Name; reason = ('Only native video media shapes are supported: ' + $shape.Name) }; continue }
315
- $matches = @($package.media | Where-Object { $_.native_id -eq $slide.SlideID -and $_.shape -eq $shape.Id })
316
- if ($matches.Count -ne 1) { $package.unsupported += @{ slide = [string]$slide.Name; reason = ('Cannot identify exact embedded video bytes: ' + $shape.Name) }; continue }
414
+ $videoShapeId = [int]$shape.Id
415
+ $videoShapeName = [string]$shape.Name
416
+ if ([int]$shape.MediaType -ne 3) { $package.unsupported += @{ slide = $slideName; reason = ('Only native video media shapes are supported: ' + $videoShapeName) }; continue }
417
+ $matches = @($package.media | Where-Object { $_.native_id -eq $slideId -and $_.shape -eq $videoShapeId })
418
+ if ($matches.Count -ne 1) { $package.unsupported += @{ slide = $slideName; reason = ('Cannot identify exact embedded video bytes: ' + $videoShapeName) }; continue }
317
419
  $media = $matches[0]
318
- $media.id = [string]$shape.Name
420
+ $media.id = $videoShapeName
319
421
  $media.duration_ms = [double]$shape.MediaFormat.Length
320
422
  $media.start_ms = [double]$shape.MediaFormat.StartPoint
321
423
  $media.end_ms = [double]$shape.MediaFormat.EndPoint
322
424
  $media.autoplay = [int]$shape.AnimationSettings.PlaySettings.PlayOnEntry
323
425
  $media.loop = [int]$shape.AnimationSettings.PlaySettings.LoopUntilStopped
324
426
  $media.rewind = [int]$shape.AnimationSettings.PlaySettings.RewindMovie
325
- $media.left = [double]$shape.Left / $presentation.PageSetup.SlideWidth
326
- $media.top = [double]$shape.Top / $presentation.PageSetup.SlideHeight
327
- $media.right = ([double]$shape.Left + $shape.Width) / $presentation.PageSetup.SlideWidth
328
- $media.bottom = ([double]$shape.Top + $shape.Height) / $presentation.PageSetup.SlideHeight
427
+ $media.left = [double]$shape.Left / $slideWidth
428
+ $media.top = [double]$shape.Top / $slideHeight
429
+ $media.right = ([double]$shape.Left + $shape.Width) / $slideWidth
430
+ $media.bottom = ([double]$shape.Top + $shape.Height) / $slideHeight
329
431
  }
330
432
  }
331
433
  }
332
- return @{ version = 1; kind = 'inspection'; deck_sha256 = $job.deck_sha256; width = [double]$presentation.PageSetup.SlideWidth; height = [double]$presentation.PageSetup.SlideHeight; slides = @($slides.ToArray()); media = $package.media; unsupported = $package.unsupported; dependencies = (Dependencies) }
434
+ return @{ version = 1; kind = 'inspection'; deck_sha256 = $job.deck_sha256; width = $slideWidth; height = $slideHeight; slides = @($slides.ToArray()); media = $package.media; unsupported = $package.unsupported; dependencies = (Dependencies) }
333
435
  }
334
436
  function Dependencies {
335
437
  $office = [Diagnostics.Process]::GetProcessById($officeProcess).MainModule.FileVersionInfo.FileVersion
@@ -352,8 +454,11 @@ function Apply-Operation($operation) {
352
454
  if ($operation.type -eq 'slide') { Select-Slide $operation.native_id; $script:activeVisit = [string]$operation.id; $script:activeScene = [string]$operation.scene }
353
455
  elseif ($operation.type -eq 'reveal') {
354
456
  if ([int]$show.View.Slide.SlideID -ne $operation.native_id) { Fail 'POWERPOINT_NAVIGATION' ('Wrong native slide for reveal ' + $operation.id) }
355
- $show.View.GotoClick([int]$operation.click)
356
- if ([int]$show.View.GetClickIndex() -ne $operation.click) { Fail 'POWERPOINT_REVEAL' ('Native click did not execute: ' + $operation.id) }
457
+ $currentClick = [int]$show.View.GetClickIndex()
458
+ $targetClick = [int]$operation.click
459
+ if ($targetClick -eq $currentClick + 1) { $show.View.Next() }
460
+ else { $show.View.GotoClick($targetClick) }
461
+ if ([int]$show.View.Slide.SlideID -ne $operation.native_id -or [int]$show.View.GetClickIndex() -ne $targetClick) { Fail 'POWERPOINT_REVEAL' ('Native click did not execute: ' + $operation.id) }
357
462
  } elseif ($operation.type -eq 'play') {
358
463
  if ([int]$show.View.Slide.SlideID -ne $operation.native_id) { Fail 'POWERPOINT_MEDIA' ('Wrong native slide for media ' + $operation.id) }
359
464
  $player = $show.View.Player([int]$operation.shape)
@@ -369,6 +474,9 @@ function Request-Context($request, [bool]$includeClick = $false) {
369
474
  $suffix = $(if ($includeClick) { ', click ' + $request.click } else { '' })
370
475
  return ($prefix + ' (' + $request.key + '), slide ' + $request.slide + ', visit ' + $request.visit + $suffix)
371
476
  }
477
+ function Request-Identity($request) {
478
+ return ([string]$request.key + '|' + [string]$request.scene + '|' + [string]$request.slide + '|' + [string]$request.visit + '|' + [string]$request.click + '|' + [string]$request.start_ms + '|' + [string]$request.end_ms)
479
+ }
372
480
  function Prepare-Annotations($catalog) {
373
481
  foreach ($request in $job.geometry_requests) {
374
482
  $context = Request-Context $request
@@ -385,16 +493,63 @@ function Prepare-Annotations($catalog) {
385
493
  } elseif ($operation.at_ms -lt $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': interval crosses a native slide or reveal action.') }
386
494
  }
387
495
  if ($visit -ne $request.visit -or $click -ne $request.click) { Fail 'ANNOTATION_STATE' ($context + ': resolved click or visit does not match native operations.') }
388
- if ($request.target.type -eq 'element') { Fail 'ANNOTATION_TARGET' ($context + ': use an existing native shape ID or normalized region; selectors are unsupported.') }
496
+ if ($request.target.type -eq 'element') { Fail 'ANNOTATION_TARGET' ($context + ': use an existing native shape ID, text target or normalized region; selectors are unsupported.') }
389
497
  if ($request.target.type -eq 'shape') {
390
498
  $slides = @($catalog.slides | Where-Object { $_.native_id -eq $request.native_id })
391
499
  $matches = @($slides[0].shapes | Where-Object { $_.id -eq $request.target.id })
392
500
  if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': identity is missing or ambiguous.') }
393
501
  if ($matches[0].unsupported.Count -gt 0 -or $request.click -lt $matches[0].visible_from_click) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ' (' + $matches[0].name + '): unsupported or hidden target. ' + ($matches[0].unsupported -join '; ')) }
394
502
  }
503
+ if ($request.target.type -eq 'text') {
504
+ $needle = (([string]$request.target.text) -replace '\s+', ' ').Trim()
505
+ if ([string]::IsNullOrEmpty($needle)) { Fail 'ANNOTATION_TARGET' ($context + ': empty text target.') }
506
+ $slides = @($catalog.slides | Where-Object { $_.native_id -eq $request.native_id })
507
+ if ($slides.Count -ne 1) { Fail 'ANNOTATION_STATE' ($context + ': slide is missing from native catalog.') }
508
+ $eligibleShapes = @()
509
+ $hasContainer = ($null -ne $request.target.PSObject.Properties['container'] -and $null -ne $request.target.container)
510
+ if ($hasContainer) {
511
+ if ($request.target.container.type -ne 'shape') { Fail 'ANNOTATION_TARGET' ($context + ': PowerPoint text container requires a native shape ID.') }
512
+ $matches = @($slides[0].shapes | Where-Object { $_.id -eq $request.target.container.id })
513
+ if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.container.id + ': identity is missing or ambiguous.') }
514
+ $allReasons = @($matches[0].unsupported) + @($matches[0].text_unsupported)
515
+ if ($allReasons.Count -gt 0 -or $request.click -lt $matches[0].visible_from_click -or [string]::IsNullOrWhiteSpace([string]$matches[0].text)) {
516
+ Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.container.id + ' (' + $matches[0].name + '): unsupported, hidden or textless target. ' + ($allReasons -join '; '))
517
+ }
518
+ $eligibleShapes = @($matches)
519
+ } else {
520
+ $eligibleShapes = @($slides[0].shapes | Where-Object { $_.unsupported.Count -eq 0 -and $_.text_unsupported.Count -eq 0 -and $request.click -ge $_.visible_from_click -and ![string]::IsNullOrWhiteSpace([string]$_.text) })
521
+ }
522
+ $catalogMatches = [Collections.Generic.List[object]]::new()
523
+ foreach ($catShape in $eligibleShapes) {
524
+ $catText = [string]$catShape.text
525
+ $pos = $catText.IndexOf($needle, [StringComparison]::Ordinal)
526
+ while ($pos -ge 0) {
527
+ $catalogMatches.Add(@{ shape = $catShape; pos = $pos })
528
+ $pos = $catText.IndexOf($needle, $pos + 1, [StringComparison]::Ordinal)
529
+ }
530
+ }
531
+ if ($catalogMatches.Count -eq 0) {
532
+ $unsupportedTextMatches = $(if (-not $hasContainer) { @($slides[0].shapes | Where-Object { $_.unsupported.Count -eq 0 -and $_.text_unsupported.Count -gt 0 -and $request.click -ge $_.visible_from_click -and ([string]$_.text).IndexOf($needle, [StringComparison]::Ordinal) -ge 0 }) } else { @() })
533
+ if ($unsupportedTextMatches.Count -gt 0) {
534
+ $u = $unsupportedTextMatches[0]
535
+ Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $u.id + ' (' + $u.name + '): ' + ($u.text_unsupported -join '; '))
536
+ }
537
+ Fail 'ANNOTATION_TARGET' ($context + ': text "' + $needle + '" was not found in visible supported shapes.')
538
+ }
539
+ $hasOcc = ($null -ne $request.target.PSObject.Properties['occurrence'] -and $null -ne $request.target.occurrence)
540
+ if ((-not $hasOcc) -and $catalogMatches.Count -gt 1) { Fail 'ANNOTATION_TARGET' ($context + ': text "' + $needle + '" matched ' + $catalogMatches.Count + ' times; specify container or occurrence.') }
541
+ $occIndex = $(if ($hasOcc) { [int]$request.target.occurrence - 1 } else { 0 })
542
+ if ($occIndex -lt 0 -or $occIndex -ge $catalogMatches.Count) { Fail 'ANNOTATION_TARGET' ($context + ': text occurrence does not exist.') }
543
+ $chosen = $catalogMatches[$occIndex]
544
+ $resolvedTextTargets[(Request-Identity $request)] = @{ shape_id = [int]$chosen.shape.id; pos = [int]$chosen.pos }
545
+ }
395
546
  $annotationMonitors.Add(@{ request = $request; geometry = $null; next_sample_ms = [double]$request.start_ms; complete = $false })
396
547
  }
397
548
  }
549
+ function Validate-FragmentBounds($bounds, [string]$context) {
550
+ foreach ($value in $bounds.Values) { if ([double]::IsNaN($value) -or [double]::IsInfinity($value)) { Fail 'ANNOTATION_GEOMETRY' ($context + ': nonfinite bounds.') } }
551
+ if ($bounds.x -lt 0 -or $bounds.y -lt 0 -or $bounds.width -le 0 -or $bounds.height -le 0 -or $bounds.x + $bounds.width -gt 1.000001 -or $bounds.y + $bounds.height -gt 1.000001) { Fail 'ANNOTATION_GEOMETRY' ($context + ': target is degenerate or clipped by the slide.') }
552
+ }
398
553
  function Measure-Annotation($request, [bool]$allowPaused = $false) {
399
554
  $context = Request-Context $request $true
400
555
  [SlideVideo.Native]::EnsureGeometry($window, $geometry)
@@ -402,16 +557,76 @@ function Measure-Annotation($request, [bool]$allowPaused = $false) {
402
557
  if ($request.target.type -eq 'slide') { return }
403
558
  if ($request.target.type -eq 'region') {
404
559
  $bounds = @{ x = [double]$request.target.x; y = [double]$request.target.y; width = [double]$request.target.width; height = [double]$request.target.height }
405
- } else {
560
+ Validate-FragmentBounds $bounds $context
561
+ return $bounds
562
+ }
563
+ if ($request.target.type -eq 'shape') {
406
564
  $matches = @(Find-ShapeById $show.View.Slide.Shapes ([int]$request.target.id))
407
565
  if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual shape is missing or ambiguous.') }
408
566
  $shape = $matches[0].shape
409
567
  if ($matches[0].invalid) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual target is hidden or transformed.') }
410
568
  $bounds = @{ x = [double]$shape.Left / $presentation.PageSetup.SlideWidth; y = [double]$shape.Top / $presentation.PageSetup.SlideHeight; width = [double]$shape.Width / $presentation.PageSetup.SlideWidth; height = [double]$shape.Height / $presentation.PageSetup.SlideHeight }
569
+ Validate-FragmentBounds $bounds $context
570
+ return $bounds
411
571
  }
412
- foreach ($value in $bounds.Values) { if ([double]::IsNaN($value) -or [double]::IsInfinity($value)) { Fail 'ANNOTATION_GEOMETRY' ($context + ': nonfinite bounds.') } }
413
- if ($bounds.x -lt 0 -or $bounds.y -lt 0 -or $bounds.width -le 0 -or $bounds.height -le 0 -or $bounds.x + $bounds.width -gt 1.000001 -or $bounds.y + $bounds.height -gt 1.000001) { Fail 'ANNOTATION_GEOMETRY' ($context + ': target is degenerate or clipped by the slide.') }
414
- return $bounds
572
+ if ($request.target.type -eq 'text') {
573
+ $needle = (([string]$request.target.text) -replace '\s+', ' ').Trim()
574
+ if ([string]::IsNullOrEmpty($needle)) { Fail 'ANNOTATION_TARGET' ($context + ': empty text target.') }
575
+ $requestKey = Request-Identity $request
576
+ if (!$resolvedTextTargets.ContainsKey($requestKey)) { Fail 'ANNOTATION_STATE' ($context + ': text target was not prepared against the inspected catalog.') }
577
+ $resolved = $resolvedTextTargets[$requestKey]
578
+ $found = @(Find-ShapeById $show.View.Slide.Shapes ([int]$resolved.shape_id))
579
+ if ($found.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': actual shape is missing or ambiguous.') }
580
+ if ($found[0].invalid) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': actual target is hidden or transformed.') }
581
+ $cand = $found[0].shape
582
+ if ([int]$cand.HasTextFrame -ne -1 -or [int]$cand.TextFrame.HasText -ne -1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': shape has no text.') }
583
+ if ([int]$cand.TextFrame.Orientation -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': non-horizontal text orientation.') }
584
+ try { if ($null -ne $cand.TextFrame2 -and [int]$cand.TextFrame2.WarpFormat -notin @(0, -2)) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': warped WordArt text.') } } catch {}
585
+ $raw = [string]$cand.TextFrame.TextRange.Text
586
+ $norm = Normalize-NativeText $raw
587
+ $pos = [int]$resolved.pos
588
+ if ($pos -lt 0 -or $pos + $needle.Length -gt $norm.text.Length -or $norm.text.Substring($pos, $needle.Length) -ne $needle) {
589
+ Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $resolved.shape_id + ': actual text changed during slideshow playback.')
590
+ }
591
+ $hasSlice = ($null -ne $request.target.PSObject.Properties['slice'] -and $null -ne $request.target.slice)
592
+ $startNorm = $pos + $(if ($hasSlice) { [int]$request.target.slice.start } else { 0 })
593
+ $endNorm = $pos + $(if ($hasSlice) { [int]$request.target.slice.end } else { $needle.Length })
594
+ while ($startNorm -lt $endNorm -and $norm.text[$startNorm] -eq [char]' ') { $startNorm++ }
595
+ while ($endNorm -gt $startNorm -and $norm.text[$endNorm - 1] -eq [char]' ') { $endNorm-- }
596
+ if ($startNorm -ge $endNorm -or $endNorm -gt $norm.starts.Count) { Fail 'ANNOTATION_TARGET' ($context + ': text slice is empty or out of bounds.') }
597
+ $rawStart0 = [int]$norm.starts[$startNorm]
598
+ $rawEnd0 = [int]$norm.ends[$endNorm - 1]
599
+ $tr = $cand.TextFrame.TextRange
600
+ $slideWidth = [double]$presentation.PageSetup.SlideWidth
601
+ $slideHeight = [double]$presentation.PageSetup.SlideHeight
602
+ $fragments = [Collections.Generic.List[object]]::new()
603
+ $lineCount = [int]$tr.Lines().Count
604
+ if ($lineCount -le 0) {
605
+ $sub = $tr.Characters($rawStart0 + 1, $rawEnd0 - $rawStart0)
606
+ $b = @{ x = [double]$sub.BoundLeft / $slideWidth; y = [double]$sub.BoundTop / $slideHeight; width = [double]$sub.BoundWidth / $slideWidth; height = [double]$sub.BoundHeight / $slideHeight }
607
+ Validate-FragmentBounds $b $context
608
+ $fragments.Add($b)
609
+ } else {
610
+ for ($lineIdx = 1; $lineIdx -le $lineCount; $lineIdx++) {
611
+ $lineRange = $tr.Lines($lineIdx)
612
+ $lineStart0 = [int]$lineRange.Start - 1
613
+ $lineEnd0 = $lineStart0 + [int]$lineRange.Length
614
+ $segStart0 = [Math]::Max($rawStart0, $lineStart0)
615
+ $segEnd0 = [Math]::Min($rawEnd0, $lineEnd0)
616
+ while ($segStart0 -lt $segEnd0 -and [char]::IsWhiteSpace($raw[$segStart0])) { $segStart0++ }
617
+ while ($segEnd0 -gt $segStart0 -and [char]::IsWhiteSpace($raw[$segEnd0 - 1])) { $segEnd0-- }
618
+ if ($segEnd0 -gt $segStart0) {
619
+ $sub = $tr.Characters($segStart0 + 1, $segEnd0 - $segStart0)
620
+ $b = @{ x = [double]$sub.BoundLeft / $slideWidth; y = [double]$sub.BoundTop / $slideHeight; width = [double]$sub.BoundWidth / $slideWidth; height = [double]$sub.BoundHeight / $slideHeight }
621
+ Validate-FragmentBounds $b $context
622
+ $fragments.Add($b)
623
+ }
624
+ }
625
+ }
626
+ if ($fragments.Count -eq 0) { Fail 'ANNOTATION_GEOMETRY' ($context + ': text range produced no visible fragments.') }
627
+ return @($fragments.ToArray())
628
+ }
629
+ Fail 'ANNOTATION_TARGET' ($context + ': unsupported target type ' + $request.target.type)
415
630
  }
416
631
  function Check-Annotations {
417
632
  foreach ($monitor in $annotationMonitors) {
@@ -419,11 +634,11 @@ function Check-Annotations {
419
634
  $request = $monitor.request
420
635
  $context = Request-Context $request $true
421
636
  if ($null -eq $monitor.geometry -and $request.start_ms -ge $annotationStartBeforeMs) { continue }
422
- $now = $clock.Elapsed.TotalMilliseconds - $origin
637
+ $now = Schedule-Now
423
638
  if ($now -lt $monitor.next_sample_ms -and $now -lt $request.end_ms) { continue }
424
639
  if ($null -eq $monitor.geometry -and $now -ge $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': native playback missed the entire interval.') }
425
640
  $fragments = @(Measure-Annotation $request)
426
- $observed = $clock.Elapsed.TotalMilliseconds - $origin
641
+ $observed = Schedule-Now
427
642
  if ($null -eq $monitor.geometry) {
428
643
  if ($observed -ge $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': initial measurement completed after the interval.') }
429
644
  if ($observed - $request.start_ms -gt 100) { Fail 'ANNOTATION_INTERVAL' ($context + ': initial native measurement exceeded the interval boundary by 100 ms.') }
@@ -448,7 +663,7 @@ function Check-Annotations {
448
663
  }
449
664
  }
450
665
  function Check-Media {
451
- $now = $clock.Elapsed.TotalMilliseconds - $origin
666
+ $now = Schedule-Now
452
667
  foreach ($monitor in @($activeMedia.ToArray())) {
453
668
  $position = [double]$monitor.player.CurrentPosition
454
669
  $state = [int]$monitor.player.State
@@ -567,6 +782,25 @@ function Rehearse {
567
782
  foreach ($slide in $presentation.Slides) { foreach ($shape in $slide.Shapes) { if ([int]$shape.Type -eq 16) { try { $show.View.Player([int]$shape.Id).Stop() } catch {} } } }
568
783
  Write-Json 'references.json' @{ version = 1; references = @($references.ToArray()) }
569
784
  }
785
+ function Wait-ShowView([double]$deadline) {
786
+ $lastError = ''
787
+ do {
788
+ Check-Cancel
789
+ try {
790
+ if ($null -eq $script:show) { $script:show = $presentation.SlideShowWindow }
791
+ $view = $script:show.View
792
+ if ($null -ne $view) { return [int]$view.State }
793
+ } catch {
794
+ $lastError = $_.Exception.Message
795
+ }
796
+ try {
797
+ if ($null -ne $presentation.SlideShowWindow) { $script:show = $presentation.SlideShowWindow }
798
+ } catch {}
799
+ Start-Sleep -Milliseconds 20
800
+ } while ($clock.Elapsed.TotalMilliseconds -lt $deadline)
801
+ if ($lastError) { Fail 'POWERPOINT_WINDOW' ('The slideshow view did not initialize: ' + $lastError) }
802
+ Fail 'POWERPOINT_WINDOW' 'The slideshow view did not initialize.'
803
+ }
570
804
  function Stop-Recorder {
571
805
  if ($null -eq $recorder) { return }
572
806
  if (!$recorder.HasExited) {
@@ -635,7 +869,7 @@ try {
635
869
  $deadline = $clock.Elapsed.TotalMilliseconds + 10000
636
870
  do { Check-Cancel; $window = [SlideVideo.Native]::FindShow($officeProcess, [IO.Path]::GetFileNameWithoutExtension($privateDeck), $editorWindow); if ($window -eq 0) { Start-Sleep -Milliseconds 20 } } while ($window -eq 0 -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
637
871
  if ($window -eq 0) { Fail 'POWERPOINT_WINDOW' 'Cannot identify one audience window owned by the private deck.' }
638
- $initialViewState = [int]$show.View.State
872
+ $initialViewState = Wait-ShowView ($clock.Elapsed.TotalMilliseconds + 10000)
639
873
  $show.View.State = 1
640
874
  $show.View.AcceleratorsEnabled = 0
641
875
  $windowMode = [SlideVideo.Native]::PlaceForAudience($window, [int]$job.output.width, [int]$job.output.height, $deckAspect, $true, $true)
@@ -732,17 +966,21 @@ try {
732
966
  foreach ($marker in $markers) { $marker.observed_ms -= $origin; $marker.rendered_by_ms -= $origin }
733
967
  $script:activeVisit = [string]$firstOperation.id
734
968
  $script:activeScene = [string]$firstOperation.scene
969
+ $script:skippedMs = 0.0
970
+ $script:nextSkipIndex = 0
971
+ $appliedSkips.Clear()
972
+ $script:plannedSkips = $(if (!$job.verify_timing -and $null -ne $job.PSObject.Properties['static_skips'] -and $null -ne $job.static_skips) { @($job.static_skips) } else { @() })
735
973
  $script:collectAnnotations = $job.geometry_requests.Count -gt 0
736
974
  $initial = $true
737
975
  for ($operationIndex = 0; $operationIndex -lt $job.operations.Count; $operationIndex++) {
738
976
  $operation = $job.operations[$operationIndex]
739
977
  $script:annotationStartBeforeMs = [double]$operation.at_ms
740
- Wait-Until ($origin + $operation.at_ms)
978
+ Wait-UntilSchedule ([double]$operation.at_ms)
741
979
  Check-Media
742
980
  if (!$initial -and $operation.type -in @('slide', 'play')) { Wait-MediaCompletion }
743
981
  [SlideVideo.Native]::EnsureGeometry($window, $geometry)
744
982
  if ($initial) { $player = $null; $now = 0.0; $initial = $false }
745
- else { $player = Apply-Operation $operation; $now = $clock.Elapsed.TotalMilliseconds - $origin }
983
+ else { $player = Apply-Operation $operation; $now = Schedule-Now }
746
984
  $entry = @{ id = $operation.id; type = $operation.type; scheduled_ms = $operation.at_ms; observed_ms = $now }
747
985
  if ($operation.type -eq 'play') {
748
986
  $entry.media_ms = [double]$player.CurrentPosition
@@ -756,7 +994,7 @@ try {
756
994
  Check-Annotations
757
995
  }
758
996
  }
759
- Wait-Until ($origin + $job.duration_ms)
997
+ Wait-UntilSchedule ([double]$job.duration_ms)
760
998
  Check-Annotations
761
999
  if (@($annotationMonitors | Where-Object { !$_.complete }).Count -gt 0) { Fail 'ANNOTATION_GEOMETRY' 'Native playback did not complete every annotation interval.' }
762
1000
  $script:collectAnnotations = $false
@@ -773,7 +1011,7 @@ try {
773
1011
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
774
1012
  Stop-Recorder
775
1013
  if ($recorder.ExitCode -ne 0) { Fail 'POWERPOINT_CAPTURE' ('FFmpeg exited ' + $recorder.ExitCode + '. See ffmpeg.log.') }
776
- $result = @{ version = 1; kind = 'recording'; file = $file; events = @($events.ToArray()); markers = @($markers.ToArray()); references = @($references.ToArray()); annotation_geometry = @($annotationGeometry.ToArray()); dependencies = (Dependencies) }
1014
+ $result = @{ version = 1; kind = 'recording'; file = $file; events = @($events.ToArray()); markers = @($markers.ToArray()); references = @($references.ToArray()); annotation_geometry = @($annotationGeometry.ToArray()); applied_skips = @($appliedSkips.ToArray()); dependencies = (Dependencies) }
777
1015
  }
778
1016
  } catch {
779
1017
  $message = $_.Exception.Message
@@ -14,6 +14,7 @@ function Run-Preview {
14
14
  if ($window -eq 0) { Start-Sleep -Milliseconds 20 }
15
15
  } while ($window -eq 0 -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
16
16
  if ($window -eq 0) { Fail 'POWERPOINT_WINDOW' 'Cannot identify the slideshow owned by the private preview deck.' }
17
+ [void](Wait-ShowView ($clock.Elapsed.TotalMilliseconds + 10000))
17
18
  $show.View.AcceleratorsEnabled = 0
18
19
  [void][SlideVideo.Native]::PlaceForAudience($window, [int]$job.output.width, [int]$job.output.height, $deckAspect, $false, $false)
19
20
  $first = $job.operations[0]
@@ -30,6 +31,7 @@ function Run-Preview {
30
31
  $previewViewportHeight = [int]$job.output.height
31
32
  $previewContent = [SlideVideo.Native]::OutputContent($geometry, $previewViewportWidth, $previewViewportHeight)
32
33
  $previewClock = [Diagnostics.Stopwatch]::new()
34
+ $clockOffsetMs = 0.0
33
35
  $status = 'paused'
34
36
  $nextOperation = 1
35
37
  [Console]::InputEncoding = $utf8
@@ -49,9 +51,75 @@ function Run-Preview {
49
51
  $activeMedia.Clear()
50
52
  $show.View.State = 1
51
53
  Apply-Operation $first
54
+ $clockOffsetMs = 0.0
52
55
  $previewClock.Restart()
53
56
  $nextOperation = 1
54
57
  $status = 'playing'
58
+ } elseif ($action -eq 'seek') {
59
+ $targetMs = [Math]::Max(0.0, [Math]::Min([double]$command.position_ms, [double]$job.duration_ms))
60
+ $wasPlaying = ($status -eq 'playing' -and $targetMs -lt [double]$job.duration_ms)
61
+ foreach ($monitor in $activeMedia) { $monitor.player.Stop() }
62
+ $activeMedia.Clear()
63
+ $show.View.State = 1
64
+ $targetSlideOp = $first
65
+ $targetRevealOp = $null
66
+ foreach ($op in $job.operations) {
67
+ if ([double]$op.at_ms -gt $targetMs) { break }
68
+ if ($op.type -eq 'slide') { $targetSlideOp = $op; $targetRevealOp = $null }
69
+ elseif ($op.type -eq 'reveal') { $targetRevealOp = $op }
70
+ }
71
+ Select-Slide $targetSlideOp.native_id $true
72
+ $script:activeVisit = [string]$targetSlideOp.id
73
+ $script:activeScene = [string]$targetSlideOp.scene
74
+ if ($null -ne $targetRevealOp) {
75
+ if ([int]$show.View.Slide.SlideID -ne $targetRevealOp.native_id) { Fail 'POWERPOINT_NAVIGATION' ('Wrong native slide for reveal ' + $targetRevealOp.id) }
76
+ $targetClick = [int]$targetRevealOp.click
77
+ $show.View.GotoClick($targetClick)
78
+ if ([int]$show.View.Slide.SlideID -ne $targetRevealOp.native_id -or [int]$show.View.GetClickIndex() -ne $targetClick) { Fail 'POWERPOINT_REVEAL' ('Native click did not execute: ' + $targetRevealOp.id) }
79
+ } else {
80
+ $slideObj = Slide-ById $targetSlideOp.native_id
81
+ $hasAutoEntry = $false
82
+ foreach ($eff in $slideObj.TimeLine.MainSequence) {
83
+ $trig = [int]$eff.Timing.TriggerType
84
+ if ($trig -eq 1) { break }
85
+ if ($trig -in @(2, 3)) { $hasAutoEntry = $true; break }
86
+ }
87
+ if ($hasAutoEntry -and [double]$targetSlideOp.settle_ms -gt 0) {
88
+ $settleWait = [Math]::Min([double]$targetSlideOp.settle_ms + 50.0, [Math]::Max(0.0, $targetMs - [double]$targetSlideOp.at_ms) + 50.0)
89
+ $settleDeadline = $clock.Elapsed.TotalMilliseconds + $settleWait
90
+ while ($clock.Elapsed.TotalMilliseconds -lt $settleDeadline) {
91
+ Check-Cancel
92
+ Start-Sleep -Milliseconds ([Math]::Min(20, [Math]::Max(1, [int]($settleDeadline - $clock.Elapsed.TotalMilliseconds))))
93
+ }
94
+ }
95
+ }
96
+ if (-not $wasPlaying) { Start-Sleep -Milliseconds 30 }
97
+ foreach ($op in $job.operations) {
98
+ if ($op.type -ne 'play') { continue }
99
+ if ([double]$op.at_ms -le $targetMs -and $targetMs -lt [double]$op.end_ms) {
100
+ $player = $show.View.Player([int]$op.shape)
101
+ $player.Stop()
102
+ $player.CurrentPosition = [int][Math]::Round([double]$op.trim_start_ms + ($targetMs - [double]$op.at_ms))
103
+ $player.Play()
104
+ if (-not $wasPlaying) { $player.Pause() }
105
+ $activeMedia.Add(@{ operation = $op; player = $player })
106
+ }
107
+ }
108
+ $nextOperation = 0
109
+ while ($nextOperation -lt $job.operations.Count -and [double]$job.operations[$nextOperation].at_ms -le $targetMs) { $nextOperation++ }
110
+ $clockOffsetMs = $targetMs
111
+ if ($targetMs -ge [double]$job.duration_ms) {
112
+ $previewClock.Reset()
113
+ $show.View.State = 2
114
+ $status = 'ended'
115
+ } elseif ($wasPlaying) {
116
+ $previewClock.Restart()
117
+ $status = 'playing'
118
+ } else {
119
+ $previewClock.Reset()
120
+ $show.View.State = 2
121
+ $status = 'paused'
122
+ }
55
123
  } elseif ($action -eq 'play' -and $status -eq 'paused') {
56
124
  $show.View.State = 1
57
125
  foreach ($monitor in $activeMedia) { $monitor.player.Play() }
@@ -63,7 +131,7 @@ function Run-Preview {
63
131
  foreach ($monitor in $activeMedia) { $monitor.player.Pause() }
64
132
  $status = 'paused'
65
133
  }
66
- $position = [Math]::Min($previewClock.Elapsed.TotalMilliseconds, [double]$job.duration_ms)
134
+ $position = [Math]::Min($clockOffsetMs + $previewClock.Elapsed.TotalMilliseconds, [double]$job.duration_ms)
67
135
  foreach ($monitor in @($activeMedia.ToArray())) {
68
136
  if ($monitor.operation.end_ms -le $position) { $monitor.player.Pause(); [void]$activeMedia.Remove($monitor) }
69
137
  }