@slidevideo/cli 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/addons/slidevideo/global-top.vue +254 -18
- package/dist/adapters/browser-runtime.d.ts +13 -1
- package/dist/adapters/capture-compression.d.ts +15 -0
- package/dist/adapters/capture-compression.js +69 -0
- package/dist/adapters/powerpoint.d.ts +1 -1
- package/dist/adapters/powerpoint.js +63 -32
- package/dist/adapters/slidev.js +362 -3
- package/dist/contracts.d.ts +2 -0
- package/dist/pipeline.d.ts +2 -0
- package/dist/speech.js +1 -1
- package/package.json +3 -1
- package/skills/slidevideo/references/decks.md +6 -6
- package/skills/slidevideo/references/production.md +1 -1
- package/skills/slidevideo/references/storyboard.md +6 -6
- package/tools/powerpoint/Native.cs +85 -1
- package/tools/powerpoint/powerpoint.ps1 +254 -89
- package/tools/powerpoint/preview.ps1 +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.3.0
|
|
6
|
+
|
|
7
|
+
- Speed up normal Slidev and PowerPoint recording by compressing static slide holds while keeping dynamic slides and `--verify-timing` at `1.0x`.
|
|
8
|
+
- Fix native PowerPoint inspection timeouts on larger decks, slideshow startup races, and sequential click-reveal playback.
|
|
9
|
+
- Make speech caches portable across directories by storing relative audio paths in cache metadata.
|
|
10
|
+
|
|
11
|
+
## 0.2.2
|
|
12
|
+
|
|
13
|
+
- Support finite native PowerPoint slide transitions, broader finite `MainSequence` animations (including `Wipe`, `Split`, `Fly In`, emphasis, exit, motion paths, and automatic pre-click entry), static `.svg` graphics, cropped pictures, grouped shape targets, dynamic full-resolution window capture with output letterboxing, and storyboard video trims (`trim_start_ms` / `trim_end_ms`).
|
|
14
|
+
|
|
5
15
|
## 0.2.1
|
|
6
16
|
|
|
7
17
|
- Add storyboard-controlled underline annotations with solid or dashed strokes and optional left-to-right wipes.
|
|
@@ -45,25 +45,36 @@ if (previewEnabled) {
|
|
|
45
45
|
document.addEventListener('volumechange', silence, true)
|
|
46
46
|
for (const type of ['keydown', 'pointerdown', 'click', 'dblclick', 'wheel']) document.addEventListener(type, preventNavigation, { capture: true, passive: false })
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
type StaticSkip = { schedule_start_ms: number; schedule_end_ms: number; skip_ms: number }
|
|
49
|
+
type AppliedSkip = { record_at_ms: number; skip_ms: number }
|
|
50
|
+
const state = { version: 1, phase: 'idle', events: [] as ObservedEvent[], markers: [] as { color: string; observed_ms: number; paint_interval_ms: number; rendered_by_ms: number }[], failure: '', annotation_geometry: [] as AnnotationGeometry[], applied_skips: [] as AppliedSkip[] }
|
|
49
51
|
let generation = 0
|
|
50
52
|
let origin = 0
|
|
53
|
+
let skippedMs = 0
|
|
54
|
+
const scheduleNow = () => (performance.now() - origin) + skippedMs
|
|
51
55
|
let schedule: Schedule
|
|
52
56
|
let visit = ''
|
|
53
57
|
let geometry: ReturnType<typeof geometryCollector> | undefined
|
|
54
|
-
const monitors = new Map<HTMLMediaElement, { timer:
|
|
58
|
+
const monitors = new Map<HTMLMediaElement, { timer: number; item: ScheduledAction }>()
|
|
55
59
|
function stopMedia(element: HTMLMediaElement, completed: boolean) {
|
|
56
60
|
const monitor = monitors.get(element)
|
|
57
61
|
if (!monitor) return
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
if (window.__slidevideoTimers) window.__slidevideoTimers.clearInternalInterval(monitor.timer)
|
|
63
|
+
else window.clearInterval(monitor.timer)
|
|
64
|
+
monitors.delete(element); element.pause()
|
|
65
|
+
if (completed) state.events.push({ id: `${monitor.item.id}:ended`, type: 'media-ended', scheduled_ms: monitor.item.end_ms, observed_ms: scheduleNow(), media_ms: element.currentTime * 1000 })
|
|
60
66
|
}
|
|
61
|
-
const waits = new Map<
|
|
67
|
+
const waits = new Map<number, () => void>()
|
|
62
68
|
const wait = (ms: number) => new Promise<void>(resolve => {
|
|
63
|
-
const
|
|
69
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
70
|
+
const timer = scheduleTimer(() => { waits.delete(timer); resolve() }, Math.max(0, ms))
|
|
64
71
|
waits.set(timer, resolve)
|
|
65
72
|
})
|
|
66
|
-
function clearWaits() {
|
|
73
|
+
function clearWaits() {
|
|
74
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
75
|
+
for (const [timer, resolve] of waits) { cancelTimer(timer); resolve() }
|
|
76
|
+
waits.clear()
|
|
77
|
+
}
|
|
67
78
|
const painted = async () => {
|
|
68
79
|
await nextTick()
|
|
69
80
|
const first = await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
@@ -117,7 +128,7 @@ async function prepare(value: Schedule, expectedHashes: Record<string, string> =
|
|
|
117
128
|
generation++; clearWaits()
|
|
118
129
|
geometry?.stop(); geometry = undefined; visit = ''
|
|
119
130
|
for (const element of monitors.keys()) stopMedia(element, false)
|
|
120
|
-
state.phase = 'preparing'; state.events = []; state.markers = []; state.failure = ''; state.annotation_geometry = []; marker.value = ''
|
|
131
|
+
state.phase = 'preparing'; state.events = []; state.markers = []; state.failure = ''; state.annotation_geometry = []; state.applied_skips = []; marker.value = ''
|
|
121
132
|
schedule = value
|
|
122
133
|
for (const slide of nav.slides.value) { await navigate(slide.no); }
|
|
123
134
|
await document.fonts.ready
|
|
@@ -136,9 +147,11 @@ async function prepare(value: Schedule, expectedHashes: Record<string, string> =
|
|
|
136
147
|
}
|
|
137
148
|
element.muted = true; element.pause(); element.currentTime = 0; element.playbackRate = 1
|
|
138
149
|
if (element.readyState < 3) await new Promise<void>((resolve, reject) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
151
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
152
|
+
const timer = scheduleTimer(() => reject(new Error(`Media readiness timeout ${clip.id}`)), 10000)
|
|
153
|
+
element.addEventListener('canplay', () => { cancelTimer(timer); resolve() }, { once: true })
|
|
154
|
+
element.addEventListener('error', () => { cancelTimer(timer); reject(new Error(`Media cannot load ${clip.id}`)) }, { once: true })
|
|
142
155
|
})
|
|
143
156
|
}
|
|
144
157
|
let selected = nav.slides.value[0]
|
|
@@ -158,9 +171,231 @@ async function showMarker(color: string, current: number) {
|
|
|
158
171
|
await wait(350)
|
|
159
172
|
if (current !== generation) throw new Error('Playback reset')
|
|
160
173
|
}
|
|
161
|
-
|
|
174
|
+
const STATIC_RASTER_EXT = /\.(?:jpe?g|bmp|ico)$/i
|
|
175
|
+
const STATIC_RASTER_DATA = /^data:image\/(?:jpe?g|bmp|x-icon)(?:[;,]|$)/i
|
|
176
|
+
const SVG_EXT = /\.svg$/i
|
|
177
|
+
const SVG_DATA = /^data:image\/svg\+xml(?:[;,]|$)/i
|
|
178
|
+
const PNG_EXT = /\.png$/i
|
|
179
|
+
const PNG_DATA = /^data:image\/png(?:[;,]|$)/i
|
|
180
|
+
const SVG_DYNAMIC_CONTENT = /<(?:[a-z_][\w.-]*:)?(?:animate|animateTransform|animateMotion|animateColor|set|discard|script|foreignObject|image)\b|<(?:[a-z_][\w.-]*:)?use\b[^>]*\bhref\s*=\s*["'](?!#)|@keyframes\b|\banimation(?:-name)?\s*:/i
|
|
181
|
+
const svgStaticCache = new Map<string, boolean>()
|
|
182
|
+
const pngStaticCache = new Map<string, boolean>()
|
|
183
|
+
function isStaticPngBytes(bytes: Uint8Array): boolean {
|
|
184
|
+
if (bytes.length < 24 || bytes[0] !== 0x89 || bytes[1] !== 0x50 || bytes[2] !== 0x4e || bytes[3] !== 0x47) return false
|
|
185
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
186
|
+
let offset = 8
|
|
187
|
+
while (offset + 8 <= bytes.length) {
|
|
188
|
+
const length = view.getUint32(offset)
|
|
189
|
+
const type = String.fromCharCode(bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7])
|
|
190
|
+
if (type === 'acTL') return false
|
|
191
|
+
if (type === 'IDAT' || type === 'IEND') return true
|
|
192
|
+
offset += 12 + length
|
|
193
|
+
}
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
async function isPngImageStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
197
|
+
const cached = pngStaticCache.get(src)
|
|
198
|
+
if (cached !== undefined) return cached
|
|
199
|
+
if (performance.now() >= deadlineMs) return false
|
|
200
|
+
try {
|
|
201
|
+
let bytes: Uint8Array
|
|
202
|
+
if (/^data:image\/png/i.test(src)) {
|
|
203
|
+
if (src.length > 262144) return false
|
|
204
|
+
const comma = src.indexOf(',')
|
|
205
|
+
const meta = comma >= 0 ? src.slice(0, comma) : ''
|
|
206
|
+
const payload = comma >= 0 ? src.slice(comma + 1) : ''
|
|
207
|
+
const raw = /;base64/i.test(meta) ? atob(payload) : decodeURIComponent(payload)
|
|
208
|
+
bytes = Uint8Array.from(raw, ch => ch.charCodeAt(0))
|
|
209
|
+
} else {
|
|
210
|
+
const remaining = deadlineMs - performance.now()
|
|
211
|
+
if (remaining <= 0) return false
|
|
212
|
+
const resolved = new URL(src, location.href)
|
|
213
|
+
if (resolved.origin !== location.origin) { pngStaticCache.set(src, false); return false }
|
|
214
|
+
const controller = new AbortController()
|
|
215
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
216
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
217
|
+
const timer = scheduleTimer(() => controller.abort(), remaining)
|
|
218
|
+
try {
|
|
219
|
+
const response = await fetch(resolved.href, { signal: controller.signal })
|
|
220
|
+
if (!response.ok) { pngStaticCache.set(src, false); return false }
|
|
221
|
+
bytes = new Uint8Array(await response.arrayBuffer())
|
|
222
|
+
} finally {
|
|
223
|
+
cancelTimer(timer)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const isStatic = isStaticPngBytes(bytes)
|
|
227
|
+
pngStaticCache.set(src, isStatic)
|
|
228
|
+
return isStatic
|
|
229
|
+
} catch {
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function isSvgImageStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
234
|
+
const cached = svgStaticCache.get(src)
|
|
235
|
+
if (cached !== undefined) return cached
|
|
236
|
+
if (performance.now() >= deadlineMs) return false
|
|
237
|
+
try {
|
|
238
|
+
let text = ''
|
|
239
|
+
if (/^data:image\/svg\+xml/i.test(src)) {
|
|
240
|
+
if (src.length > 262144) return false
|
|
241
|
+
const comma = src.indexOf(',')
|
|
242
|
+
const meta = comma >= 0 ? src.slice(0, comma) : ''
|
|
243
|
+
const payload = comma >= 0 ? src.slice(comma + 1) : ''
|
|
244
|
+
text = /;base64/i.test(meta) ? atob(payload) : decodeURIComponent(payload)
|
|
245
|
+
} else {
|
|
246
|
+
const remaining = deadlineMs - performance.now()
|
|
247
|
+
if (remaining <= 0) return false
|
|
248
|
+
const resolved = new URL(src, location.href)
|
|
249
|
+
if (resolved.origin !== location.origin) { svgStaticCache.set(src, false); return false }
|
|
250
|
+
const controller = new AbortController()
|
|
251
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
252
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
253
|
+
const timer = scheduleTimer(() => controller.abort(), remaining)
|
|
254
|
+
try {
|
|
255
|
+
const response = await fetch(resolved.href, { signal: controller.signal })
|
|
256
|
+
if (!response.ok) { svgStaticCache.set(src, false); return false }
|
|
257
|
+
text = await response.text()
|
|
258
|
+
} finally {
|
|
259
|
+
cancelTimer(timer)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const isStatic = !SVG_DYNAMIC_CONTENT.test(text)
|
|
263
|
+
svgStaticCache.set(src, isStatic)
|
|
264
|
+
return isStatic
|
|
265
|
+
} catch {
|
|
266
|
+
return false
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function isImageUrlStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
270
|
+
if (!src) return true
|
|
271
|
+
if (STATIC_RASTER_DATA.test(src)) return true
|
|
272
|
+
if (SVG_DATA.test(src)) return isSvgImageStatic(src, deadlineMs)
|
|
273
|
+
if (PNG_DATA.test(src)) return isPngImageStatic(src, deadlineMs)
|
|
274
|
+
if (/^data:/i.test(src) || /^blob:/i.test(src)) return false
|
|
275
|
+
let pathname = ''
|
|
276
|
+
try { pathname = new URL(src, location.href).pathname } catch { return false }
|
|
277
|
+
if (STATIC_RASTER_EXT.test(pathname)) return true
|
|
278
|
+
if (SVG_EXT.test(pathname)) return isSvgImageStatic(src, deadlineMs)
|
|
279
|
+
if (PNG_EXT.test(pathname)) return isPngImageStatic(src, deadlineMs)
|
|
280
|
+
return false
|
|
281
|
+
}
|
|
282
|
+
function hasSlideScriptOrMotion(): boolean {
|
|
283
|
+
const slide = nav.currentSlideRoute.value?.meta?.slide
|
|
284
|
+
if (!slide) return true
|
|
285
|
+
const raw = String(slide.content ?? '')
|
|
286
|
+
const stripped = raw.replace(/```[\s\S]*?```/g, '').replace(/`[^`]*`/g, '')
|
|
287
|
+
return /<script\b/i.test(stripped) || /\bv-motion\b/.test(stripped)
|
|
288
|
+
}
|
|
289
|
+
async function isSlideStatic(current: number, maxBudgetMs: number): Promise<boolean> {
|
|
290
|
+
if (monitors.size > 0 || hasSlideScriptOrMotion() || window.__slidevideoTimers?.hasPending()) return false
|
|
291
|
+
if (await window.__slidevideoHasInFlightRequests?.()) return false
|
|
292
|
+
const root = document.body
|
|
293
|
+
if (!root || window.__slidevideoTimers?.hasShadowHost(root)) return false
|
|
294
|
+
const svgDeadline = performance.now() + Math.min(100, Math.max(0, maxBudgetMs))
|
|
295
|
+
const hasDynamicDom = async () => {
|
|
296
|
+
for (const mediaEl of root.querySelectorAll<HTMLMediaElement>('video, audio')) {
|
|
297
|
+
if (!mediaEl.paused && !mediaEl.ended) return true
|
|
298
|
+
}
|
|
299
|
+
for (const element of root.querySelectorAll('canvas, iframe, object, embed, progress:not([value])')) {
|
|
300
|
+
if (element.tagName === 'CANVAS' && element.hasAttribute('data-slidevideo-canvas')) continue
|
|
301
|
+
if (element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) return true
|
|
302
|
+
}
|
|
303
|
+
if (root.querySelector('svg animate, svg animateTransform, svg animateMotion, svg animateColor, svg set, svg discard, svg foreignObject')) return true
|
|
304
|
+
for (const refEl of root.querySelectorAll('svg image, svg use')) {
|
|
305
|
+
const href = refEl.getAttribute('href') || refEl.getAttribute('xlink:href') || ''
|
|
306
|
+
if (href && !href.startsWith('#') && !(await isImageUrlStatic(href, svgDeadline))) return true
|
|
307
|
+
}
|
|
308
|
+
for (const img of root.querySelectorAll('img')) {
|
|
309
|
+
if (!img.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
310
|
+
if (!img.complete && (img.currentSrc || img.getAttribute('src') || img.getAttribute('srcset'))) return true
|
|
311
|
+
const src = img.currentSrc || img.getAttribute('src') || ''
|
|
312
|
+
if (src && !(await isImageUrlStatic(src, svgDeadline))) return true
|
|
313
|
+
}
|
|
314
|
+
for (const element of root.querySelectorAll('*')) {
|
|
315
|
+
if (!element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
316
|
+
for (const pseudo of [null, '::before', '::after'] as const) {
|
|
317
|
+
const style = getComputedStyle(element, pseudo)
|
|
318
|
+
for (const prop of ['backgroundImage', 'content', 'maskImage', 'borderImageSource', 'listStyleImage'] as const) {
|
|
319
|
+
const value = style[prop]
|
|
320
|
+
if (!value || value === 'none' || value === 'normal' || !value.includes('url(')) continue
|
|
321
|
+
for (const match of value.matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)\s]+))\s*\)/gi)) {
|
|
322
|
+
const bgUrl = match[1] ?? match[2] ?? match[3] ?? ''
|
|
323
|
+
if (!bgUrl) continue
|
|
324
|
+
if (!(await isImageUrlStatic(bgUrl, svgDeadline))) return true
|
|
325
|
+
if (!/^data:/i.test(bgUrl)) {
|
|
326
|
+
try {
|
|
327
|
+
const resolved = new URL(bgUrl, location.href).href
|
|
328
|
+
if (performance.getEntriesByName(resolved, 'resource').length === 0) return true
|
|
329
|
+
} catch {
|
|
330
|
+
return true
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false
|
|
338
|
+
}
|
|
339
|
+
const hasRunningAnimation = () => document.getAnimations().some(animation => {
|
|
340
|
+
if (animation.playState !== 'running' && !animation.pending) return false
|
|
341
|
+
const effect = animation.effect
|
|
342
|
+
const target = effect instanceof KeyframeEffect ? effect.target : null
|
|
343
|
+
return target instanceof Node && root.contains(target)
|
|
344
|
+
})
|
|
345
|
+
if (await hasDynamicDom() || hasRunningAnimation()) return false
|
|
346
|
+
let mutated = false
|
|
347
|
+
const observer = new MutationObserver(() => { mutated = true })
|
|
348
|
+
observer.observe(root, { subtree: true, childList: true, attributes: true, characterData: true })
|
|
349
|
+
try {
|
|
350
|
+
await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
351
|
+
await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
352
|
+
} finally {
|
|
353
|
+
observer.disconnect()
|
|
354
|
+
}
|
|
355
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
356
|
+
if (mutated || monitors.size > 0 || window.__slidevideoTimers?.hasPending() || window.__slidevideoTimers?.hasShadowHost(root) || await window.__slidevideoHasInFlightRequests?.() || await hasDynamicDom() || hasRunningAnimation()) return false
|
|
357
|
+
return true
|
|
358
|
+
}
|
|
359
|
+
async function waitUntilSchedule(targetMs: number, current: number, plannedSkips: StaticSkip[], skipCursor: { index: number; startMs: number }) {
|
|
360
|
+
while (scheduleNow() < targetMs) {
|
|
361
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
362
|
+
if (state.failure) throw new Error(state.failure)
|
|
363
|
+
const skip = plannedSkips[skipCursor.index]
|
|
364
|
+
if (skip && skipCursor.startMs <= targetMs) {
|
|
365
|
+
if (scheduleNow() < skipCursor.startMs) {
|
|
366
|
+
await wait(skipCursor.startMs - scheduleNow())
|
|
367
|
+
continue
|
|
368
|
+
}
|
|
369
|
+
const skipTarget = Math.min(skip.schedule_end_ms, targetMs)
|
|
370
|
+
const svgBudgetMs = Math.max(0, skipTarget - scheduleNow() - 50)
|
|
371
|
+
if (await isSlideStatic(current, svgBudgetMs)) {
|
|
372
|
+
const remainingSkip = skipTarget - scheduleNow()
|
|
373
|
+
if (remainingSkip > 0) {
|
|
374
|
+
state.applied_skips.push({ record_at_ms: performance.now() - origin, skip_ms: remainingSkip })
|
|
375
|
+
skippedMs += remainingSkip
|
|
376
|
+
}
|
|
377
|
+
if (skipTarget >= skip.schedule_end_ms) {
|
|
378
|
+
skipCursor.index++
|
|
379
|
+
skipCursor.startMs = plannedSkips[skipCursor.index]?.schedule_start_ms ?? Infinity
|
|
380
|
+
} else {
|
|
381
|
+
skipCursor.startMs = skipTarget
|
|
382
|
+
}
|
|
383
|
+
continue
|
|
384
|
+
}
|
|
385
|
+
skipCursor.index++
|
|
386
|
+
skipCursor.startMs = plannedSkips[skipCursor.index]?.schedule_start_ms ?? Infinity
|
|
387
|
+
continue
|
|
388
|
+
}
|
|
389
|
+
await wait(targetMs - scheduleNow())
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async function play(verifyTiming = false, plannedSkips: StaticSkip[] = []) {
|
|
162
393
|
if (state.phase !== 'ready') throw new Error('Prepare playback first')
|
|
163
394
|
const current = generation
|
|
395
|
+
skippedMs = 0
|
|
396
|
+
state.applied_skips = []
|
|
397
|
+
const skips = verifyTiming ? [] : plannedSkips
|
|
398
|
+
const skipCursor = { index: 0, startMs: skips[0]?.schedule_start_ms ?? Infinity }
|
|
164
399
|
state.phase = 'recording'; origin = performance.now()
|
|
165
400
|
try {
|
|
166
401
|
await showMarker('#ff00ff', current)
|
|
@@ -171,9 +406,9 @@ async function play(verifyTiming = false) {
|
|
|
171
406
|
for (const event of state.markers) { event.observed_ms -= start - origin; event.rendered_by_ms -= start - origin }
|
|
172
407
|
origin = start
|
|
173
408
|
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 }), () =>
|
|
409
|
+
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 }), () => scheduleNow(), message => { state.failure = message })
|
|
175
410
|
for (const entry of playbackEntries(schedule)) {
|
|
176
|
-
|
|
411
|
+
await waitUntilSchedule(entry.at, current, skips, skipCursor)
|
|
177
412
|
if (current !== generation) throw new Error('Playback reset')
|
|
178
413
|
if (state.failure) throw new Error(state.failure)
|
|
179
414
|
if (entry.type === 'geometry-start') { geometry!.start(entry.request); continue }
|
|
@@ -181,15 +416,16 @@ async function play(verifyTiming = false) {
|
|
|
181
416
|
if (entry.type === 'annotation-start' || entry.type === 'annotation-end') continue
|
|
182
417
|
const item = entry.item
|
|
183
418
|
await apply(item)
|
|
184
|
-
const observed_ms =
|
|
419
|
+
const observed_ms = scheduleNow()
|
|
185
420
|
if (verifyTiming && observed_ms - item.start_ms > 100) throw new Error(`Late action ${item.id}: ${observed_ms - item.start_ms} ms`)
|
|
186
421
|
state.events.push({ id: item.id, type: item.action.type, scheduled_ms: item.start_ms, observed_ms })
|
|
187
422
|
if (item.action.type === 'play') {
|
|
188
423
|
const action = item.action
|
|
189
424
|
const element = media(action.media)
|
|
190
|
-
const
|
|
425
|
+
const scheduleInterval = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalInterval : (cb: () => void, delay: number) => window.setInterval(cb, delay)
|
|
426
|
+
const monitor = scheduleInterval(() => {
|
|
191
427
|
if (generation !== current) { stopMedia(element, false); return }
|
|
192
|
-
const expected = (
|
|
428
|
+
const expected = (scheduleNow() - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)
|
|
193
429
|
if (expected > (item.end_ms - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)) {
|
|
194
430
|
stopMedia(element, true)
|
|
195
431
|
} else if (Math.abs(element.currentTime * 1000 - expected) > 150) {
|
|
@@ -199,7 +435,7 @@ async function play(verifyTiming = false) {
|
|
|
199
435
|
monitors.set(element, { timer: monitor, item })
|
|
200
436
|
}
|
|
201
437
|
}
|
|
202
|
-
await
|
|
438
|
+
await waitUntilSchedule(schedule.duration_ms, current, skips, skipCursor)
|
|
203
439
|
for (const element of monitors.keys()) stopMedia(element, true)
|
|
204
440
|
if (state.failure) throw new Error(state.failure)
|
|
205
441
|
geometry?.complete(); geometry?.stop(); geometry = undefined
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Schedule, ScheduledAction, ObservedEvent, AnnotationGeometry, PresentationInspection } from '../contracts.js';
|
|
2
|
+
import type { AppliedSkip, StaticSkip } from './capture-compression.js';
|
|
2
3
|
export type PlaybackState = {
|
|
3
4
|
version: number;
|
|
4
5
|
phase: string;
|
|
@@ -11,12 +12,13 @@ export type PlaybackState = {
|
|
|
11
12
|
}[];
|
|
12
13
|
failure: string;
|
|
13
14
|
annotation_geometry?: AnnotationGeometry[];
|
|
15
|
+
applied_skips?: AppliedSkip[];
|
|
14
16
|
};
|
|
15
17
|
export interface PlaybackRuntime {
|
|
16
18
|
version: number;
|
|
17
19
|
state: PlaybackState;
|
|
18
20
|
prepare(schedule: Schedule, expectedHashes?: Record<string, string>): Promise<void>;
|
|
19
|
-
play(verifyTiming?: boolean): Promise<void>;
|
|
21
|
+
play(verifyTiming?: boolean, plannedSkips?: StaticSkip[]): Promise<void>;
|
|
20
22
|
apply(action: ScheduledAction): Promise<void>;
|
|
21
23
|
navigate(index: number, click?: number): Promise<void>;
|
|
22
24
|
inspectTargets(): Promise<PresentationInspection['annotation_targets']>;
|
|
@@ -30,11 +32,21 @@ export interface PlaybackRuntime {
|
|
|
30
32
|
restart(): Promise<void>;
|
|
31
33
|
};
|
|
32
34
|
}
|
|
35
|
+
export type TimerTracker = {
|
|
36
|
+
hasPending(): boolean;
|
|
37
|
+
hasShadowHost(root: Element): boolean;
|
|
38
|
+
setInternalTimeout(callback: () => void, ms: number): number;
|
|
39
|
+
clearInternalTimeout(id: number): void;
|
|
40
|
+
setInternalInterval(callback: () => void, ms: number): number;
|
|
41
|
+
clearInternalInterval(id: number): void;
|
|
42
|
+
};
|
|
33
43
|
declare global {
|
|
34
44
|
interface Window {
|
|
35
45
|
__slidevideo: PlaybackRuntime;
|
|
36
46
|
__slidevideoCapture?: {
|
|
37
47
|
stop(): Promise<number>;
|
|
38
48
|
};
|
|
49
|
+
__slidevideoTimers?: TimerTracker;
|
|
50
|
+
__slidevideoHasInFlightRequests?: () => Promise<boolean>;
|
|
39
51
|
}
|
|
40
52
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type DynamicWindow = {
|
|
2
|
+
start_ms: number;
|
|
3
|
+
end_ms: number;
|
|
4
|
+
};
|
|
5
|
+
export type StaticSkip = {
|
|
6
|
+
schedule_start_ms: number;
|
|
7
|
+
schedule_end_ms: number;
|
|
8
|
+
skip_ms: number;
|
|
9
|
+
};
|
|
10
|
+
export type AppliedSkip = {
|
|
11
|
+
record_at_ms: number;
|
|
12
|
+
skip_ms: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function planStaticSkips(dynamicWindows: DynamicWindow[], checkpoints: number[], durationMs: number): StaticSkip[];
|
|
15
|
+
export declare function remapCaptureTimestamps(file: string, offsetMs: number, skips: AppliedSkip[]): Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { rename, rm } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, join } from 'node:path';
|
|
3
|
+
import { execute } from '../media.js';
|
|
4
|
+
const LEADING_SETTLE_MS = 250;
|
|
5
|
+
const TRAILING_GUARD_MS = 200;
|
|
6
|
+
const CHECKPOINT_LEADING_MS = 50;
|
|
7
|
+
const CHECKPOINT_TRAILING_MS = 20;
|
|
8
|
+
const MIN_SKIP_MS = 500;
|
|
9
|
+
export function planStaticSkips(dynamicWindows, checkpoints, durationMs) {
|
|
10
|
+
if (!Number.isFinite(durationMs) || durationMs <= LEADING_SETTLE_MS + TRAILING_GUARD_MS + MIN_SKIP_MS)
|
|
11
|
+
return [];
|
|
12
|
+
const keep = [
|
|
13
|
+
[0, Math.min(durationMs, LEADING_SETTLE_MS)],
|
|
14
|
+
[Math.max(0, durationMs - TRAILING_GUARD_MS), durationMs],
|
|
15
|
+
];
|
|
16
|
+
for (const window of dynamicWindows) {
|
|
17
|
+
const start = Math.max(0, Math.min(durationMs, window.start_ms) - TRAILING_GUARD_MS);
|
|
18
|
+
const end = Math.min(durationMs, Math.max(window.start_ms, window.end_ms) + LEADING_SETTLE_MS);
|
|
19
|
+
keep.push([start, end]);
|
|
20
|
+
}
|
|
21
|
+
for (const point of checkpoints) {
|
|
22
|
+
if (!Number.isFinite(point))
|
|
23
|
+
continue;
|
|
24
|
+
const start = Math.max(0, point - CHECKPOINT_TRAILING_MS);
|
|
25
|
+
const end = Math.min(durationMs, point + CHECKPOINT_LEADING_MS);
|
|
26
|
+
keep.push([start, end]);
|
|
27
|
+
}
|
|
28
|
+
keep.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
29
|
+
const merged = [];
|
|
30
|
+
for (const interval of keep) {
|
|
31
|
+
const last = merged[merged.length - 1];
|
|
32
|
+
if (!last || interval[0] > last[1])
|
|
33
|
+
merged.push([interval[0], interval[1]]);
|
|
34
|
+
else if (interval[1] > last[1])
|
|
35
|
+
last[1] = interval[1];
|
|
36
|
+
}
|
|
37
|
+
const skips = [];
|
|
38
|
+
for (let i = 0; i < merged.length - 1; i++) {
|
|
39
|
+
const start = merged[i][1];
|
|
40
|
+
const end = merged[i + 1][0];
|
|
41
|
+
const skip = end - start;
|
|
42
|
+
if (skip >= MIN_SKIP_MS) {
|
|
43
|
+
skips.push({ schedule_start_ms: start, schedule_end_ms: end, skip_ms: skip });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return skips;
|
|
47
|
+
}
|
|
48
|
+
export async function remapCaptureTimestamps(file, offsetMs, skips) {
|
|
49
|
+
const valid = skips
|
|
50
|
+
.filter(skip => Number.isFinite(skip.record_at_ms) && skip.record_at_ms >= 0 && Number.isFinite(skip.skip_ms) && skip.skip_ms > 0)
|
|
51
|
+
.sort((a, b) => a.record_at_ms - b.record_at_ms);
|
|
52
|
+
if (!valid.length)
|
|
53
|
+
return;
|
|
54
|
+
const terms = valid.map(skip => {
|
|
55
|
+
const thresholdSec = ((offsetMs + skip.record_at_ms) / 1000).toFixed(6);
|
|
56
|
+
const skipSec = (skip.skip_ms / 1000).toFixed(6);
|
|
57
|
+
return `if(gte(TS*TB,${thresholdSec}),${skipSec},0)`;
|
|
58
|
+
});
|
|
59
|
+
const bsf = `setts=ts='TS+(${terms.join('+')})/TB'`;
|
|
60
|
+
const temporary = join(dirname(file), `.remapped-${Date.now()}${extname(file)}`);
|
|
61
|
+
try {
|
|
62
|
+
await execute('ffmpeg', ['-v', 'error', '-xerror', '-y', '-i', file, '-c:v', 'copy', '-bsf:v', bsf, temporary]);
|
|
63
|
+
await rename(temporary, file);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
await rm(temporary, { force: true }).catch(() => { });
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -9,7 +9,7 @@ export declare class PowerPointAdapter implements PresentationAdapter {
|
|
|
9
9
|
private prepared?;
|
|
10
10
|
inspect(file: string): Promise<PresentationInspection>;
|
|
11
11
|
private targets;
|
|
12
|
-
inspectTargets(_deck: string,
|
|
12
|
+
inspectTargets(_deck: string, _viewport: Viewport): Promise<PresentationInspection['annotation_targets']>;
|
|
13
13
|
private slide;
|
|
14
14
|
validate(story: Storyboard, _inspection: PresentationInspection, options?: {
|
|
15
15
|
viewport?: Viewport;
|