@slidevideo/cli 0.3.0 → 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 (52) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -2
  3. package/addons/slidevideo/geometry.ts +334 -1
  4. package/addons/slidevideo/global-top.vue +57 -6
  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/powerpoint-preview.d.ts +1 -1
  14. package/dist/adapters/powerpoint-preview.js +13 -2
  15. package/dist/adapters/powerpoint.js +91 -14
  16. package/dist/adapters/slidev-inspection.js +7 -2
  17. package/dist/annotation-paint.d.ts +195 -5
  18. package/dist/annotation-paint.js +1188 -2
  19. package/dist/annotations.d.ts +26 -2
  20. package/dist/annotations.js +1117 -29
  21. package/dist/captions.d.ts +6 -0
  22. package/dist/captions.js +320 -0
  23. package/dist/cli.js +40 -17
  24. package/dist/compositor.js +51 -3
  25. package/dist/contracts.d.ts +253 -14
  26. package/dist/pipeline.d.ts +6 -1
  27. package/dist/pipeline.js +66 -19
  28. package/dist/preview/contracts.d.ts +14 -0
  29. package/dist/preview/player.js +523 -33
  30. package/dist/preview/server.d.ts +1 -1
  31. package/dist/preview/server.js +124 -3
  32. package/dist/preview/view.d.ts +1 -1
  33. package/dist/preview/view.js +26 -7
  34. package/dist/run.d.ts +1 -0
  35. package/dist/run.js +20 -0
  36. package/dist/speech.d.ts +10 -1
  37. package/dist/speech.js +17 -1
  38. package/dist/stamp-fonts.d.ts +17 -0
  39. package/dist/stamp-fonts.js +202 -0
  40. package/dist/storyboard.js +60 -3
  41. package/dist/timing.d.ts +2 -0
  42. package/dist/timing.js +277 -11
  43. package/package.json +12 -1
  44. package/schemas/annotation-geometry.v1.json +111 -0
  45. package/schemas/schedule.v1.json +1672 -84
  46. package/schemas/storyboard.v1.json +3725 -85
  47. package/skills/slidevideo/SKILL.md +5 -5
  48. package/skills/slidevideo/references/decks.md +6 -4
  49. package/skills/slidevideo/references/production.md +12 -11
  50. package/skills/slidevideo/references/storyboard.md +268 -5
  51. package/tools/powerpoint/powerpoint.ps1 +155 -6
  52. package/tools/powerpoint/preview.ps1 +68 -1
@@ -48,6 +48,7 @@ $cleanup = [Collections.Generic.List[string]]::new()
48
48
  $activeMedia = [Collections.Generic.List[object]]::new()
49
49
  $annotationMonitors = [Collections.Generic.List[object]]::new()
50
50
  $annotationGeometry = [Collections.Generic.List[object]]::new()
51
+ $resolvedTextTargets = @{}
51
52
  $collectAnnotations = $false
52
53
  $annotationStartBeforeMs = [double]::PositiveInfinity
53
54
  $activeVisit = ''
@@ -284,6 +285,35 @@ function Find-ShapeById($shapes, [int]$targetId, [bool]$ancestorInvalid = $false
284
285
  }
285
286
  return @($found.ToArray())
286
287
  }
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
+ }
287
317
  function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight, $shapes, $targetsByKey, $effectsByShape, [bool]$ancestorTransformed, [int]$ancestorVisibleFromClick = 0, [string[]]$ancestorAnimReasons = @()) {
288
318
  foreach ($shape in $shapes) {
289
319
  Check-Cancel
@@ -292,6 +322,8 @@ function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight
292
322
  $shapeType = [int]$shape.Type
293
323
  $reasons = [Collections.Generic.List[string]]::new()
294
324
  $animReasons = [Collections.Generic.List[string]]::new()
325
+ $textReasons = [Collections.Generic.List[string]]::new()
326
+ $shapeText = $null
295
327
  $bounds = @{ x = 0.0; y = 0.0; width = 0.0; height = 0.0 }
296
328
  $visibleFromClick = $ancestorVisibleFromClick
297
329
  $isTransformed = $ancestorTransformed
@@ -325,6 +357,13 @@ function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight
325
357
  }
326
358
  }
327
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
+ }
328
367
  } catch { $reasons.Add('native target geometry is unavailable: ' + $_.Exception.Message) }
329
368
  $children = @()
330
369
  if ($shapeType -eq 6) {
@@ -338,7 +377,7 @@ function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight
338
377
  }
339
378
  }
340
379
  }
341
- @{ id = $shapeId; name = $shapeName; 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) }
342
381
  foreach ($child in $children) { $child }
343
382
  }
344
383
  }
@@ -435,6 +474,9 @@ function Request-Context($request, [bool]$includeClick = $false) {
435
474
  $suffix = $(if ($includeClick) { ', click ' + $request.click } else { '' })
436
475
  return ($prefix + ' (' + $request.key + '), slide ' + $request.slide + ', visit ' + $request.visit + $suffix)
437
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
+ }
438
480
  function Prepare-Annotations($catalog) {
439
481
  foreach ($request in $job.geometry_requests) {
440
482
  $context = Request-Context $request
@@ -451,16 +493,63 @@ function Prepare-Annotations($catalog) {
451
493
  } elseif ($operation.at_ms -lt $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': interval crosses a native slide or reveal action.') }
452
494
  }
453
495
  if ($visit -ne $request.visit -or $click -ne $request.click) { Fail 'ANNOTATION_STATE' ($context + ': resolved click or visit does not match native operations.') }
454
- 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.') }
455
497
  if ($request.target.type -eq 'shape') {
456
498
  $slides = @($catalog.slides | Where-Object { $_.native_id -eq $request.native_id })
457
499
  $matches = @($slides[0].shapes | Where-Object { $_.id -eq $request.target.id })
458
500
  if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': identity is missing or ambiguous.') }
459
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 '; ')) }
460
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
+ }
461
546
  $annotationMonitors.Add(@{ request = $request; geometry = $null; next_sample_ms = [double]$request.start_ms; complete = $false })
462
547
  }
463
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
+ }
464
553
  function Measure-Annotation($request, [bool]$allowPaused = $false) {
465
554
  $context = Request-Context $request $true
466
555
  [SlideVideo.Native]::EnsureGeometry($window, $geometry)
@@ -468,16 +557,76 @@ function Measure-Annotation($request, [bool]$allowPaused = $false) {
468
557
  if ($request.target.type -eq 'slide') { return }
469
558
  if ($request.target.type -eq 'region') {
470
559
  $bounds = @{ x = [double]$request.target.x; y = [double]$request.target.y; width = [double]$request.target.width; height = [double]$request.target.height }
471
- } else {
560
+ Validate-FragmentBounds $bounds $context
561
+ return $bounds
562
+ }
563
+ if ($request.target.type -eq 'shape') {
472
564
  $matches = @(Find-ShapeById $show.View.Slide.Shapes ([int]$request.target.id))
473
565
  if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual shape is missing or ambiguous.') }
474
566
  $shape = $matches[0].shape
475
567
  if ($matches[0].invalid) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual target is hidden or transformed.') }
476
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
477
571
  }
478
- foreach ($value in $bounds.Values) { if ([double]::IsNaN($value) -or [double]::IsInfinity($value)) { Fail 'ANNOTATION_GEOMETRY' ($context + ': nonfinite bounds.') } }
479
- 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.') }
480
- 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)
481
630
  }
482
631
  function Check-Annotations {
483
632
  foreach ($monitor in $annotationMonitors) {
@@ -31,6 +31,7 @@ function Run-Preview {
31
31
  $previewViewportHeight = [int]$job.output.height
32
32
  $previewContent = [SlideVideo.Native]::OutputContent($geometry, $previewViewportWidth, $previewViewportHeight)
33
33
  $previewClock = [Diagnostics.Stopwatch]::new()
34
+ $clockOffsetMs = 0.0
34
35
  $status = 'paused'
35
36
  $nextOperation = 1
36
37
  [Console]::InputEncoding = $utf8
@@ -50,9 +51,75 @@ function Run-Preview {
50
51
  $activeMedia.Clear()
51
52
  $show.View.State = 1
52
53
  Apply-Operation $first
54
+ $clockOffsetMs = 0.0
53
55
  $previewClock.Restart()
54
56
  $nextOperation = 1
55
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
+ }
56
123
  } elseif ($action -eq 'play' -and $status -eq 'paused') {
57
124
  $show.View.State = 1
58
125
  foreach ($monitor in $activeMedia) { $monitor.player.Play() }
@@ -64,7 +131,7 @@ function Run-Preview {
64
131
  foreach ($monitor in $activeMedia) { $monitor.player.Pause() }
65
132
  $status = 'paused'
66
133
  }
67
- $position = [Math]::Min($previewClock.Elapsed.TotalMilliseconds, [double]$job.duration_ms)
134
+ $position = [Math]::Min($clockOffsetMs + $previewClock.Elapsed.TotalMilliseconds, [double]$job.duration_ms)
68
135
  foreach ($monitor in @($activeMedia.ToArray())) {
69
136
  if ($monitor.operation.end_ms -le $position) { $monitor.player.Pause(); [void]$activeMedia.Remove($monitor) }
70
137
  }