@slidevideo/cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +2 -2
  3. package/addons/slidevideo/geometry.ts +63 -30
  4. package/addons/slidevideo/global-top.vue +41 -9
  5. package/addons/slidevideo/playback-entries.ts +16 -5
  6. package/addons/slidevideo/preview.ts +26 -14
  7. package/dist/adapters/powerpoint.d.ts +7 -4
  8. package/dist/adapters/powerpoint.js +116 -26
  9. package/dist/adapters/slidev-inspection.d.ts +5 -2
  10. package/dist/adapters/slidev-inspection.js +3 -2
  11. package/dist/adapters/slidev.d.ts +3 -4
  12. package/dist/adapters/slidev.js +20 -19
  13. package/dist/annotation-paint.d.ts +65 -11
  14. package/dist/annotation-paint.js +290 -10
  15. package/dist/annotations.d.ts +13 -8
  16. package/dist/annotations.js +619 -88
  17. package/dist/assembly.d.ts +4 -2
  18. package/dist/assembly.js +23 -18
  19. package/dist/cli.js +102 -16
  20. package/dist/compositor.d.ts +10 -5
  21. package/dist/compositor.js +215 -128
  22. package/dist/contracts.d.ts +91 -30
  23. package/dist/contracts.js +2 -1
  24. package/dist/media.d.ts +5 -0
  25. package/dist/media.js +30 -0
  26. package/dist/pipeline.d.ts +35 -9
  27. package/dist/pipeline.js +62 -10
  28. package/dist/preview/contracts.d.ts +3 -3
  29. package/dist/preview/player.js +20 -15
  30. package/dist/preview/server.d.ts +2 -1
  31. package/dist/preview/server.js +6 -5
  32. package/dist/setup.d.ts +3 -0
  33. package/dist/setup.js +16 -1
  34. package/dist/skill-install.d.ts +35 -0
  35. package/dist/skill-install.js +132 -0
  36. package/dist/storyboard.js +9 -0
  37. package/package.json +4 -1
  38. package/schemas/annotation-geometry.v1.json +260 -28
  39. package/schemas/run-manifest.v1.json +31 -0
  40. package/schemas/schedule.v1.json +448 -182
  41. package/schemas/storyboard.v1.json +358 -174
  42. package/skills/slidevideo/SKILL.md +11 -9
  43. package/skills/slidevideo/references/decks.md +228 -0
  44. package/skills/slidevideo/references/production.md +14 -10
  45. package/skills/slidevideo/references/storyboard.md +65 -33
  46. package/tools/powerpoint/powerpoint.ps1 +52 -41
  47. package/tools/powerpoint/preview.ps1 +5 -5
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.1
6
+
7
+ - Add storyboard-controlled underline annotations with solid or dashed strokes and optional left-to-right wipes.
8
+ - Inspect Slidev and PowerPoint decks directly with `slidevideo inspect --deck <file>` before creating a storyboard.
9
+ - Register the bundled coding-agent skill with `slidevideo skill --install`, inspect deck-compatibility rules with `slidevideo skill decks`, and report skill status in `slidevideo setup`.
10
+ - Configure video dimensions and frame rate on the CLI with `--width`, `--height`, and `--fps` instead of a storyboard `output` block.
11
+
5
12
  ## 0.2.0
6
13
 
7
14
  - Speed up video assembly with sparse marker highlights or overlays by restricting Canvas compositing to active frame intervals and dirty regions while compositing static top layers in FFmpeg.
package/README.md CHANGED
@@ -16,9 +16,9 @@ slidevideo validate --storyboard slidevideo.yaml
16
16
  slidevideo build --storyboard slidevideo.yaml --run runs/hello-001
17
17
  ```
18
18
 
19
- A completed build writes `runs/hello-001/final.mp4`. Use `slidevideo setup --license` to activate a key. The installed version checks its bundled revocation list offline. New exports using a revoked key include the watermark.
19
+ A completed build writes `runs/hello-001/final.mp4` at `1920x1080` and `30 fps` by default. Pass `--width` and `--height` together and optional `--fps` to select another resolution or frame rate. Use `slidevideo setup --license` to activate a key. The installed version checks its bundled revocation list offline. New exports using a revoked key include the watermark.
20
20
 
21
- To draft or edit a storyboard, open your presentation folder in your coding agent and ask it to run `slidevideo skill`. The CLI includes the skill and its storyboard and recording references.
21
+ To draft or edit a storyboard with a coding agent, run `slidevideo skill --install` to link the bundled skill into `~/.agents/skills/slidevideo` and `~/.claude/skills/slidevideo` when Claude Code is detected, or ask the agent to run `slidevideo skill`. For non-interactive setup, run `slidevideo setup --install --json` and see `slidevideo setup --help` and `slidevideo skill --help` for provider and project flags. Use `slidevideo inspect --deck <file> --json` to list slide names, click counts, media IDs, and highlight targets before creating `slidevideo.yaml`. The CLI includes the skill and its storyboard, deck-compatibility, and recording references.
22
22
 
23
23
  Interactive calls check npm in the background at most once every 24 hours and show cached update notices on later calls. Stable installations use `latest`; existing alpha installations use `alpha`. Notices include an exact-version upgrade command. If you installed with `--prefix`, add the same `--prefix` option to that command so npm updates the copy on your `PATH`. Set `SLIDEVIDEO_NO_UPDATE_CHECK=1` to disable checks and notices. CI, noninteractive calls, `--json` and `--quiet` skip both.
24
24
 
@@ -1,7 +1,7 @@
1
- import type { AnnotationGeometry, Rectangle, ResolvedAnnotation } from '../../dist/contracts.js'
1
+ import type { AnnotationGeometry, GeometryRequest, Rectangle } from '../../dist/contracts.js'
2
2
 
3
3
  type PlaybackPosition = { slide: string; visit: string; click: number; index: number }
4
- type Measurement = { bounds: Rectangle; content: Rectangle; slide: Rectangle; viewport: { width: number; height: number }; element?: Element }
4
+ type Measurement = { fragments: Rectangle[]; content: Rectangle; slide: Rectangle; viewport: { width: number; height: number }; elements: Element[] }
5
5
  const rectangle = (rect: DOMRect): Rectangle => ({ x: rect.x, y: rect.y, width: rect.width, height: rect.height })
6
6
  function axisAligned(element: Element) {
7
7
  const style = getComputedStyle(element)
@@ -46,8 +46,8 @@ function visibleBounds(element: Element, content: HTMLElement): Rectangle {
46
46
  }
47
47
  return bounds
48
48
  }
49
- function measure(annotation: ResolvedAnnotation, position: PlaybackPosition): Measurement {
50
- if (position.slide !== annotation.slide || position.visit !== annotation.visit || position.click !== annotation.click) throw new Error('Slide visit or reveal state changed')
49
+ function measure(request: GeometryRequest, position: PlaybackPosition): Measurement {
50
+ if (position.slide !== request.slide || position.visit !== request.visit || position.click !== request.click) throw new Error('Slide visit or reveal state changed')
51
51
  const { content, slide } = audience(position.index)
52
52
  for (let ancestor: Element | null = content; ancestor; ancestor = ancestor.parentElement) axisAligned(ancestor)
53
53
  for (let ancestor: Element | null = slide; ancestor && ancestor !== content; ancestor = ancestor.parentElement) {
@@ -56,53 +56,86 @@ function measure(annotation: ResolvedAnnotation, position: PlaybackPosition): Me
56
56
  }
57
57
  const contentRect = rectangle(content.getBoundingClientRect())
58
58
  if (!(contentRect.width > 0 && contentRect.height > 0) || !within(contentRect, { x: 0, y: 0, width: innerWidth, height: innerHeight })) throw new Error('Slide-content rectangle is empty or clipped by the capture viewport')
59
- let bounds: Rectangle, element: Element | undefined
60
- if (annotation.target.type === 'region') {
61
- const target = annotation.target
62
- bounds = { x: target.x, y: target.y, width: target.width, height: target.height }
63
- } else if (annotation.target.type === 'element') {
64
- const candidates = slide.querySelectorAll(annotation.target.selector)
65
- if (candidates.length !== 1) throw new Error(`Selector ${JSON.stringify(annotation.target.selector)} matched ${candidates.length} elements in the active audience slide`)
66
- element = candidates[0]
67
- const rect = visibleBounds(element, content)
68
- bounds = { x: (rect.x - contentRect.x) / contentRect.width, y: (rect.y - contentRect.y) / contentRect.height, width: rect.width / contentRect.width, height: rect.height / contentRect.height }
69
- } else throw new Error('PowerPoint shape targets are unsupported by Slidev')
70
- return { bounds, content: contentRect, slide: rectangle(slide.getBoundingClientRect()), viewport: { width: innerWidth, height: innerHeight }, element }
59
+ let fragments: Rectangle[]
60
+ let elements: Element[] = []
61
+ switch (request.target.type) {
62
+ case 'slide':
63
+ fragments = []
64
+ break
65
+ case 'region': {
66
+ const target = request.target
67
+ fragments = [{ x: target.x, y: target.y, width: target.width, height: target.height }]
68
+ break
69
+ }
70
+ case 'element': {
71
+ const candidates = slide.querySelectorAll(request.target.selector)
72
+ if (candidates.length !== 1) throw new Error(`Selector ${JSON.stringify(request.target.selector)} matched ${candidates.length} elements in the active audience slide`)
73
+ const element = candidates[0]
74
+ const rect = visibleBounds(element, content)
75
+ fragments = [{ x: (rect.x - contentRect.x) / contentRect.width, y: (rect.y - contentRect.y) / contentRect.height, width: rect.width / contentRect.width, height: rect.height / contentRect.height }]
76
+ elements = [element]
77
+ break
78
+ }
79
+ case 'shape':
80
+ throw new Error('PowerPoint shape targets are unsupported by Slidev')
81
+ }
82
+ return { fragments, content: contentRect, slide: rectangle(slide.getBoundingClientRect()), viewport: { width: innerWidth, height: innerHeight }, elements }
71
83
  }
72
84
  const difference = (a: Rectangle, b: Rectangle) => Math.max(...(['x', 'y', 'width', 'height'] as const).map(key => Math.abs(a[key] - b[key])))
73
- export function geometryCollector(annotations: ResolvedAnnotation[], output: AnnotationGeometry[], position: () => PlaybackPosition, elapsed: () => number, fail: (message: string) => void) {
74
- const active = new Map<string, { annotation: ResolvedAnnotation; first: Measurement; record: AnnotationGeometry }>()
85
+ const requestId = (request: GeometryRequest) => `${request.scene}\0${request.slide}\0${request.visit}\0${request.click}\0${request.key}\0${request.start_ms}\0${request.end_ms}`
86
+ const requestLabel = (request: GeometryRequest) => request.annotations.length === 1
87
+ ? `Annotation ${request.annotations[0]}`
88
+ : `Annotations ${request.annotations.join(', ')}`
89
+ export function geometryCollector(requests: GeometryRequest[], output: AnnotationGeometry[], position: () => PlaybackPosition, elapsed: () => number, fail: (message: string) => void) {
90
+ const active = new Map<string, { request: GeometryRequest; first: Measurement; record: AnnotationGeometry }>()
75
91
  let frame = 0
76
92
  let running = true
77
- function sample(annotation: ResolvedAnnotation) {
93
+ function sample(request: GeometryRequest) {
78
94
  try {
79
- const measurement = measure(annotation, position())
80
- const existing = active.get(annotation.id)
95
+ const id = requestId(request)
96
+ const measurement = measure(request, position())
97
+ const existing = active.get(id)
81
98
  if (!existing) {
82
- const record: AnnotationGeometry = { id: annotation.id, scene: annotation.scene, slide: annotation.slide, visit: annotation.visit, click: annotation.click, start_ms: annotation.start_ms, end_ms: annotation.end_ms, observed_start_ms: elapsed(), observed_end_ms: elapsed(), viewport: measurement.viewport, content: measurement.content, bounds: measurement.bounds, samples: 1 }
83
- output.push(record); active.set(annotation.id, { annotation, first: measurement, record })
99
+ const now = elapsed()
100
+ const { annotations: _annotations, ...targetWindow } = request
101
+ const record: AnnotationGeometry = { ...targetWindow, observed_start_ms: now, observed_end_ms: now, viewport: measurement.viewport, content: measurement.content, fragments: measurement.fragments, samples: 1 }
102
+ output.push(record); active.set(id, { request, first: measurement, record })
84
103
  } else {
85
104
  const first = existing.first
86
- const delta = { x: (measurement.bounds.x - first.bounds.x) * first.content.width, y: (measurement.bounds.y - first.bounds.y) * first.content.height, width: (measurement.bounds.width - first.bounds.width) * first.content.width, height: (measurement.bounds.height - first.bounds.height) * first.content.height }
87
- if (measurement.element !== first.element || measurement.viewport.width !== first.viewport.width || measurement.viewport.height !== first.viewport.height || difference(measurement.content, first.content) > 0.5 || difference(measurement.slide, first.slide) > 0.5 || Math.max(...Object.values(delta).map(Math.abs)) > 0.5) throw new Error('Target or slide layout moved during the annotation interval')
105
+ const elementsChanged = measurement.elements.length !== first.elements.length || measurement.elements.some((element, index) => element !== first.elements[index])
106
+ const fragmentsMoved = measurement.fragments.length !== first.fragments.length || measurement.fragments.some((bounds, index) => {
107
+ const reference = first.fragments[index]
108
+ const delta = [
109
+ (bounds.x - reference.x) * first.content.width,
110
+ (bounds.y - reference.y) * first.content.height,
111
+ (bounds.width - reference.width) * first.content.width,
112
+ (bounds.height - reference.height) * first.content.height,
113
+ ]
114
+ return Math.max(...delta.map(Math.abs)) > 0.5
115
+ })
116
+ if (elementsChanged || measurement.viewport.width !== first.viewport.width || measurement.viewport.height !== first.viewport.height || difference(measurement.content, first.content) > 0.5 || difference(measurement.slide, first.slide) > 0.5 || fragmentsMoved) {
117
+ throw new Error('Target or slide layout moved during the annotation interval')
118
+ }
88
119
  existing.record.samples++; existing.record.observed_end_ms = elapsed()
89
120
  }
90
- } catch (error) { throw new Error(`Annotation ${annotation.id} (${annotation.target.type === 'element' ? annotation.target.selector : annotation.target.type}): ${error instanceof Error ? error.message : String(error)}`) }
121
+ } catch (error) {
122
+ throw new Error(`${requestLabel(request)} (${request.key}, ${request.slide}, visit ${request.visit}, click ${request.click}): ${error instanceof Error ? error.message : String(error)}`)
123
+ }
91
124
  }
92
125
  function tick() {
93
126
  if (!running) return
94
- try { for (const { annotation } of active.values()) sample(annotation) }
127
+ try { for (const { request } of active.values()) sample(request) }
95
128
  catch (error) { fail(String(error)); stop(); return }
96
129
  frame = requestAnimationFrame(tick)
97
130
  }
98
131
  function stop() { running = false; cancelAnimationFrame(frame); active.clear() }
99
132
  frame = requestAnimationFrame(tick)
100
133
  return {
101
- start(annotation: ResolvedAnnotation) { sample(annotation) },
102
- end(annotation: ResolvedAnnotation) { sample(annotation); active.delete(annotation.id) },
134
+ start(request: GeometryRequest) { sample(request) },
135
+ end(request: GeometryRequest) { sample(request); active.delete(requestId(request)) },
103
136
  stop,
104
137
  complete() {
105
- if (output.length !== annotations.length || active.size) throw new Error('Annotation geometry collection did not complete')
138
+ if (output.length !== requests.length || active.size) throw new Error('Annotation geometry collection did not complete')
106
139
  },
107
140
  }
108
141
  }
@@ -2,15 +2,40 @@
2
2
  import { ref, nextTick, onMounted, onUnmounted } from 'vue'
3
3
  import { useNav } from '@slidev/client'
4
4
  import type { Schedule, ObservedEvent, ScheduledAction, AnnotationGeometry, PresentationInspection } from '../../dist/contracts.js'
5
+ import { geometryRequests, groupEffectsByBlend, paintPrimitives, type PaintableEffect } from '../../dist/annotation-paint.js'
5
6
  import { geometryCollector, inspectAudienceTargets } from './geometry'
6
- import type { createPreview, PreviewLayer } from './preview'
7
+ import type { createPreview } from './preview'
7
8
  import { playbackEntries } from './playback-entries'
8
9
  const nav = useNav()
9
10
  const marker = ref('')
10
11
  const enabled = new URLSearchParams(location.search).has('slidevideo')
11
12
  const previewEnabled = enabled && new URLSearchParams(location.search).has('slidevideo-preview')
12
- const previewLayers = ref<PreviewLayer[]>([])
13
+ const previewCanvases: HTMLCanvasElement[] = []
13
14
  let preview: ReturnType<typeof createPreview> | undefined
15
+ function renderPreview(effects: PaintableEffect[], timeMs: number) {
16
+ const groups = groupEffectsByBlend(effects, timeMs)
17
+ while (previewCanvases.length > groups.length) previewCanvases.pop()!.remove()
18
+ const width = innerWidth
19
+ const height = innerHeight
20
+ for (const [index, group] of groups.entries()) {
21
+ let canvas = previewCanvases[index]
22
+ if (!canvas) {
23
+ canvas = document.createElement('canvas')
24
+ canvas.dataset.slidevideoCanvas = String(index)
25
+ Object.assign(canvas.style, { position: 'fixed', inset: '0', width: '100%', height: '100%', zIndex: '999998', pointerEvents: 'none' })
26
+ document.body.append(canvas)
27
+ previewCanvases.push(canvas)
28
+ }
29
+ const blendCss = group.blend === 'darken' ? 'darken' : 'normal'
30
+ if (canvas.style.mixBlendMode !== blendCss) canvas.style.mixBlendMode = blendCss
31
+ if (canvas.width !== width) canvas.width = width
32
+ if (canvas.height !== height) canvas.height = height
33
+ const context = canvas.getContext('2d')
34
+ if (!context) throw new Error('2D canvas context is unavailable for preview')
35
+ context.clearRect(0, 0, width, height)
36
+ paintPrimitives(context, group.primitives, { backdrop: false })
37
+ }
38
+ }
14
39
  function silence(event: Event) {
15
40
  if (event.target instanceof HTMLMediaElement && !event.target.muted) event.target.muted = true
16
41
  }
@@ -50,11 +75,16 @@ const media = (id: string) => {
50
75
  if (!(element instanceof HTMLMediaElement)) throw new Error(`Missing media ${id}`)
51
76
  return element
52
77
  }
78
+ function slideReady(index: number) {
79
+ const page = document.querySelector(`#slide-content #slideshow > .slidev-page[data-slidev-no="${index}"]`)
80
+ return Boolean(page?.firstElementChild && !page.querySelector('.slidev-slide-loading'))
81
+ }
53
82
  async function navigate(index: number, click = 0) {
83
+ await nav.slides.value[index - 1]?.load()
54
84
  await nav.go(index, click, true); await painted()
55
85
  const deadline = performance.now() + 10000
56
86
  let waited = false
57
- while (!document.querySelector(`#slide-content #slideshow > .slidev-page[data-slidev-no="${index}"]`)?.firstElementChild) {
87
+ while (!slideReady(index)) {
58
88
  if (performance.now() >= deadline) throw new Error(`Slide ${index} did not finish loading`)
59
89
  waited = true; await wait(10)
60
90
  }
@@ -140,13 +170,15 @@ async function play(verifyTiming = false) {
140
170
  const start = performance.now()
141
171
  for (const event of state.markers) { event.observed_ms -= start - origin; event.rendered_by_ms -= start - origin }
142
172
  origin = start
143
- if (schedule.annotations.length) geometry = geometryCollector(schedule.annotations, state.annotation_geometry, () => ({ slide: String(nav.currentSlideRoute.value.meta.slide.frontmatter.name ?? `slide-${nav.currentSlideNo.value}`), visit, click: nav.clicks.value, index: nav.currentSlideNo.value }), () => performance.now() - origin, message => { state.failure = message })
173
+ const requests = geometryRequests(schedule)
174
+ if (requests.length) geometry = geometryCollector(requests, state.annotation_geometry, () => ({ slide: String(nav.currentSlideRoute.value.meta.slide.frontmatter.name ?? `slide-${nav.currentSlideNo.value}`), visit, click: nav.clicks.value, index: nav.currentSlideNo.value }), () => performance.now() - origin, message => { state.failure = message })
144
175
  for (const entry of playbackEntries(schedule)) {
145
176
  while (performance.now() - origin < entry.at) await wait(entry.at - (performance.now() - origin))
146
177
  if (current !== generation) throw new Error('Playback reset')
147
178
  if (state.failure) throw new Error(state.failure)
148
- if (entry.type === 'start') { geometry!.start(entry.annotation); continue }
149
- if (entry.type === 'end') { geometry!.end(entry.annotation); continue }
179
+ if (entry.type === 'geometry-start') { geometry!.start(entry.request); continue }
180
+ if (entry.type === 'geometry-end') { geometry!.end(entry.request); continue }
181
+ if (entry.type === 'annotation-start' || entry.type === 'annotation-end') continue
150
182
  const item = entry.item
151
183
  await apply(item)
152
184
  const observed_ms = performance.now() - origin
@@ -186,13 +218,14 @@ async function inspectTargets(): Promise<PresentationInspection['annotation_targ
186
218
  if (click) await navigate(slide.no, click)
187
219
  for (const target of inspectAudienceTargets(slide.no)) if (!targets.has(target.identity)) targets.set(target.identity, `click ${click}; ${target.description}`)
188
220
  }
189
- result.push({ slide: String(slide.meta.slide.frontmatter.name ?? `slide-${slide.no}`), targets: [...targets].map(([identity, description]) => ({ identity, description })) })
221
+ result.push({ slide: String(slide.meta.slide.frontmatter.name ?? `slide-${slide.no}`), clicks: nav.clicksTotal.value, targets: [...targets].map(([identity, description]) => ({ identity, description })) })
190
222
  }
191
223
  await navigate(1)
192
224
  return result
193
225
  }
194
226
  onUnmounted(() => {
195
227
  generation++; clearWaits(); geometry?.stop(); preview?.dispose()
228
+ previewCanvases.splice(0).forEach(canvas => canvas.remove())
196
229
  for (const element of monitors.keys()) stopMedia(element, false)
197
230
  document.removeEventListener('play', silence, true); document.removeEventListener('volumechange', silence, true)
198
231
  for (const type of ['keydown', 'pointerdown', 'click', 'dblclick', 'wheel']) document.removeEventListener(type, preventNavigation, true)
@@ -207,7 +240,7 @@ onMounted(async () => {
207
240
  if (!response.ok) throw new Error('Preview configuration is unavailable')
208
241
  const config = await response.json()
209
242
  const { createPreview } = await import('./preview')
210
- preview = createPreview(config.schedule, config.mediaHashes, config.parentOrigin, prepare, apply, () => ({ slide: String(nav.currentSlideRoute.value.meta.slide.frontmatter.name ?? `slide-${nav.currentSlideNo.value}`), visit, click: nav.clicks.value, index: nav.currentSlideNo.value }), value => { previewLayers.value = value })
243
+ preview = createPreview(config.schedule, config.mediaHashes, config.parentOrigin, prepare, apply, () => ({ slide: String(nav.currentSlideRoute.value.meta.slide.frontmatter.name ?? `slide-${nav.currentSlideNo.value}`), visit, click: nav.clicks.value, index: nav.currentSlideNo.value }), renderPreview)
211
244
  window.__slidevideo.preview = preview
212
245
  await preview.initialize()
213
246
  } catch (error) {
@@ -222,7 +255,6 @@ onMounted(async () => {
222
255
  <template>
223
256
  <Teleport to="body">
224
257
  <div v-if="enabled && marker" :style="{ position: 'fixed', inset: '0', zIndex: 999999, background: marker, pointerEvents: 'none' }" />
225
- <div v-for="layer in previewLayers" :key="layer.id" :data-slidevideo-annotation="layer.id" :style="{ position: 'fixed', left: `${layer.rectangle.x}px`, top: `${layer.rectangle.y}px`, width: `${layer.rectangle.width}px`, height: `${layer.rectangle.height}px`, background: layer.color, opacity: layer.opacity, mixBlendMode: layer.blend === 'darken' ? 'darken' : 'normal', zIndex: 999998, pointerEvents: 'none' }" />
226
258
  </Teleport>
227
259
  </template>
228
260
 
@@ -1,14 +1,25 @@
1
- import type { ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
1
+ import type { GeometryRequest, ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
2
+ import { geometryRequests } from '../../dist/annotation-paint.js'
2
3
 
3
- type PlaybackEntry = { at: number; order: number } & (
4
- { type: 'action'; item: ScheduledAction } |
5
- { type: 'start' | 'end'; annotation: ResolvedAnnotation }
4
+ export type PlaybackEntry = { at: number; order: number } & (
5
+ | { type: 'action'; item: ScheduledAction }
6
+ | { type: 'geometry-start' | 'geometry-end'; request: GeometryRequest }
7
+ | { type: 'annotation-start' | 'annotation-end'; annotation: ResolvedAnnotation }
6
8
  )
7
9
 
8
10
  export function playbackEntries(schedule: Schedule): PlaybackEntry[] {
9
11
  const entries: PlaybackEntry[] = schedule.actions.map(item => ({ at: item.start_ms, order: 1, type: 'action', item }))
12
+ for (const request of geometryRequests(schedule)) {
13
+ entries.push(
14
+ { at: request.start_ms, order: 2, type: 'geometry-start', request },
15
+ { at: request.end_ms, order: -1, type: 'geometry-end', request },
16
+ )
17
+ }
10
18
  for (const annotation of schedule.annotations) {
11
- entries.push({ at: annotation.start_ms, order: 2, type: 'start', annotation }, { at: annotation.end_ms, order: 0, type: 'end', annotation })
19
+ entries.push(
20
+ { at: annotation.start_ms, order: 3, type: 'annotation-start', annotation },
21
+ { at: annotation.end_ms, order: -2, type: 'annotation-end', annotation },
22
+ )
12
23
  }
13
24
  return entries.sort((a, b) => a.at - b.at || a.order - b.order)
14
25
  }
@@ -1,10 +1,9 @@
1
1
  import type { AnnotationGeometry, ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
2
- import { annotationPaint, type AnnotationPaint } from '../../dist/annotation-paint.js'
2
+ import { annotationPaint, findTargetGeometry, geometryRequests, underlineFragmentsVisible, type PaintableEffect } from '../../dist/annotation-paint.js'
3
3
  import { playbackEntries } from './playback-entries'
4
4
  import { geometryCollector } from './geometry'
5
5
 
6
6
  type PreviewStatus = 'loading' | 'ready' | 'playing' | 'paused' | 'ended' | 'error'
7
- export type PreviewLayer = AnnotationPaint & { id: string }
8
7
  type Position = { slide: string; visit: string; click: number; index: number }
9
8
  export function createPreview(
10
9
  schedule: Schedule,
@@ -13,7 +12,7 @@ export function createPreview(
13
12
  prepare: (schedule: Schedule, hashes: Record<string, string>) => Promise<void>,
14
13
  apply: (item: ScheduledAction) => Promise<void>,
15
14
  position: () => Position,
16
- layers: (value: PreviewLayer[]) => void,
15
+ render: (effects: PaintableEffect[], timeMs: number) => void,
17
16
  ) {
18
17
  let status: PreviewStatus = 'loading'
19
18
  let message = ''
@@ -51,23 +50,31 @@ export function createPreview(
51
50
  generation++; interruptWait(); cancelAnimationFrame(frame)
52
51
  collector?.stop(); collector = undefined
53
52
  for (const element of media) element.pause()
54
- media.clear(); active.clear(); layers([])
53
+ media.clear(); active.clear(); render([], elapsed())
55
54
  }
56
55
  function fail(error: unknown) {
57
56
  offset = elapsed(); status = 'error'; message = error instanceof Error ? error.message : String(error)
58
57
  freeze(); stop(); notify()
59
58
  }
60
59
  function paint() {
61
- const output: PreviewLayer[] = []
60
+ const output: PaintableEffect[] = []
62
61
  for (const annotation of schedule.annotations) {
63
62
  if (!active.has(annotation.id)) continue
64
- const record = geometry.find(item => item.id === annotation.id)
65
- if (!record) throw new Error(`Annotation ${annotation.id}: preview geometry is unavailable`)
66
- const { bottom_border, ...fill } = annotationPaint(annotation, record)
67
- output.push({ id: annotation.id, ...fill })
68
- if (bottom_border) output.push({ id: `${annotation.id}:border`, ...bottom_border })
63
+ switch (annotation.effect) {
64
+ case 'highlight':
65
+ case 'underline': {
66
+ const record = findTargetGeometry(geometry, annotation, annotation.target)
67
+ if (!record) throw new Error(`Annotation ${annotation.id}: preview geometry is unavailable`)
68
+ const painted = annotationPaint(annotation, record)
69
+ if (painted.effect === 'underline' && !underlineFragmentsVisible(painted)) {
70
+ throw new Error(`Annotation ${annotation.id}: underline is clipped outside the slide-content rectangle`)
71
+ }
72
+ output.push(painted)
73
+ break
74
+ }
75
+ }
69
76
  }
70
- layers(output)
77
+ render(output, elapsed())
71
78
  }
72
79
  async function waitUntil(at: number, current: number) {
73
80
  while (current === generation) {
@@ -80,16 +87,21 @@ export function createPreview(
80
87
  function tick() {
81
88
  if (status !== 'playing' && status !== 'paused') return
82
89
  if (status === 'paused') freeze()
90
+ else if (active.size) {
91
+ try { paint() } catch (error) { fail(error); return }
92
+ }
83
93
  if (performance.now() - lastNotification > 200) { notify(); lastNotification = performance.now() }
84
94
  frame = requestAnimationFrame(tick)
85
95
  }
86
96
  async function run(current: number) {
87
97
  try {
88
- collector = geometryCollector(schedule.annotations, geometry, position, elapsed, fail)
98
+ collector = geometryCollector(geometryRequests(schedule), geometry, position, elapsed, fail)
89
99
  for (const entry of entries) {
90
100
  if (!await waitUntil(entry.at, current)) return
91
- if (entry.type === 'start') { collector!.start(entry.annotation); active.set(entry.annotation.id, entry.annotation); paint() }
92
- else if (entry.type === 'end') { collector!.end(entry.annotation); active.delete(entry.annotation.id); paint() }
101
+ if (entry.type === 'geometry-start') collector!.start(entry.request)
102
+ else if (entry.type === 'geometry-end') collector!.end(entry.request)
103
+ else if (entry.type === 'annotation-start') { active.set(entry.annotation.id, entry.annotation); paint() }
104
+ else if (entry.type === 'annotation-end') { active.delete(entry.annotation.id); paint() }
93
105
  else if (entry.type === 'media-end') {
94
106
  const element = document.getElementById(entry.id)
95
107
  if (element instanceof HTMLMediaElement) { element.pause(); media.delete(element) }
@@ -1,5 +1,5 @@
1
1
  import type { NativePreview } from '../preview/contracts.js';
2
- import type { PresentationAdapter, PresentationInspection, ProductionOptions, ProgressReporter, Schedule, Storyboard, VisualArtifact } from '../contracts.js';
2
+ import { type PresentationAdapter, type PresentationInspection, type ProductionOptions, type ProgressReporter, type Schedule, type Storyboard, type Viewport, type VisualArtifact } from '../contracts.js';
3
3
  export declare class PowerPointAdapter implements PresentationAdapter {
4
4
  readonly id = "powerpoint";
5
5
  readonly version = "native-2";
@@ -9,12 +9,15 @@ export declare class PowerPointAdapter implements PresentationAdapter {
9
9
  private prepared?;
10
10
  inspect(file: string): Promise<PresentationInspection>;
11
11
  private targets;
12
- inspectTargets(_story: Storyboard): Promise<PresentationInspection['annotation_targets']>;
12
+ inspectTargets(_deck: string, viewport: Viewport): Promise<PresentationInspection['annotation_targets']>;
13
13
  private slide;
14
- validate(story: Storyboard, _inspection: PresentationInspection, schedule?: Schedule): Promise<void>;
14
+ validate(story: Storyboard, _inspection: PresentationInspection, options?: {
15
+ viewport?: Viewport;
16
+ schedule?: Schedule;
17
+ }): Promise<void>;
15
18
  private operations;
16
19
  prepare(story: Storyboard, schedule: Schedule, directory: string, production?: ProductionOptions): Promise<void>;
17
- startPreview(story: Storyboard, schedule: Schedule, directory: string): Promise<NativePreview>;
20
+ startPreview(story: Storyboard, schedule: Schedule, directory: string, _parentOrigin?: string, viewport?: Viewport): Promise<NativePreview>;
18
21
  private openPlayback;
19
22
  execute(progress?: ProgressReporter): Promise<VisualArtifact>;
20
23
  cleanup(): Promise<void>;