@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.
- package/CHANGELOG.md +18 -0
- package/README.md +2 -2
- package/addons/slidevideo/geometry.ts +334 -1
- package/addons/slidevideo/global-top.vue +311 -24
- package/addons/slidevideo/preview.ts +242 -25
- package/assets/fonts/OFL-LICENSES.txt +95 -0
- package/assets/fonts/instrument-serif-latin-2.woff2 +0 -0
- package/assets/fonts/instrument-serif-latin-ext-1.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-4.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-ext-3.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-6.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-ext-5.woff2 +0 -0
- 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-preview.d.ts +1 -1
- package/dist/adapters/powerpoint-preview.js +13 -2
- package/dist/adapters/powerpoint.js +108 -16
- package/dist/adapters/slidev-inspection.js +7 -2
- package/dist/adapters/slidev.js +362 -3
- package/dist/annotation-paint.d.ts +195 -5
- package/dist/annotation-paint.js +1188 -2
- package/dist/annotations.d.ts +26 -2
- package/dist/annotations.js +1117 -29
- package/dist/captions.d.ts +6 -0
- package/dist/captions.js +320 -0
- package/dist/cli.js +40 -17
- package/dist/compositor.js +51 -3
- package/dist/contracts.d.ts +253 -14
- package/dist/pipeline.d.ts +6 -1
- package/dist/pipeline.js +66 -19
- package/dist/preview/contracts.d.ts +14 -0
- package/dist/preview/player.js +523 -33
- package/dist/preview/server.d.ts +1 -1
- package/dist/preview/server.js +124 -3
- package/dist/preview/view.d.ts +1 -1
- package/dist/preview/view.js +26 -7
- package/dist/run.d.ts +1 -0
- package/dist/run.js +20 -0
- package/dist/speech.d.ts +10 -1
- package/dist/speech.js +18 -2
- package/dist/stamp-fonts.d.ts +17 -0
- package/dist/stamp-fonts.js +202 -0
- package/dist/storyboard.js +60 -3
- package/dist/timing.d.ts +2 -0
- package/dist/timing.js +277 -11
- package/package.json +14 -1
- package/schemas/annotation-geometry.v1.json +111 -0
- package/schemas/schedule.v1.json +1672 -84
- package/schemas/storyboard.v1.json +3725 -85
- package/skills/slidevideo/SKILL.md +5 -5
- package/skills/slidevideo/references/decks.md +6 -4
- package/skills/slidevideo/references/production.md +12 -11
- package/skills/slidevideo/references/storyboard.md +268 -5
- package/tools/powerpoint/powerpoint.ps1 +278 -40
- package/tools/powerpoint/preview.ps1 +69 -1
|
@@ -2,7 +2,7 @@
|
|
|
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
|
+
import { activeViewTransform, geometryRequests, groupEffectsByBlend, hasActiveLaser, hasActiveSpotlight, hasActiveStamp, paintLasers, paintPrimitives, paintSpotlightMask, paintStamps, type PaintableEffect } from '../../dist/annotation-paint.js'
|
|
6
6
|
import { geometryCollector, inspectAudienceTargets } from './geometry'
|
|
7
7
|
import type { createPreview } from './preview'
|
|
8
8
|
import { playbackEntries } from './playback-entries'
|
|
@@ -12,12 +12,26 @@ const enabled = new URLSearchParams(location.search).has('slidevideo')
|
|
|
12
12
|
const previewEnabled = enabled && new URLSearchParams(location.search).has('slidevideo-preview')
|
|
13
13
|
const previewCanvases: HTMLCanvasElement[] = []
|
|
14
14
|
let preview: ReturnType<typeof createPreview> | undefined
|
|
15
|
+
let previewParentOrigin = ''
|
|
16
|
+
let lastPostedView = ''
|
|
17
|
+
function postPreviewView(view: ReturnType<typeof activeViewTransform>) {
|
|
18
|
+
if (!previewParentOrigin) return
|
|
19
|
+
const payload = view ? JSON.stringify(view) : ''
|
|
20
|
+
if (payload === lastPostedView) return
|
|
21
|
+
lastPostedView = payload
|
|
22
|
+
window.parent.postMessage({ type: 'slidevideo-preview-view', view: view ?? null }, previewParentOrigin)
|
|
23
|
+
}
|
|
15
24
|
function renderPreview(effects: PaintableEffect[], timeMs: number) {
|
|
25
|
+
postPreviewView(activeViewTransform(effects, timeMs))
|
|
26
|
+
const spotlightActive = hasActiveSpotlight(effects, timeMs)
|
|
27
|
+
const stampActive = hasActiveStamp(effects, timeMs)
|
|
28
|
+
const laserActive = hasActiveLaser(effects, timeMs)
|
|
16
29
|
const groups = groupEffectsByBlend(effects, timeMs)
|
|
17
|
-
|
|
30
|
+
const planeCount = (spotlightActive ? 1 : 0) + groups.length + (stampActive ? 1 : 0) + (laserActive ? 1 : 0)
|
|
31
|
+
while (previewCanvases.length > planeCount) previewCanvases.pop()!.remove()
|
|
18
32
|
const width = innerWidth
|
|
19
33
|
const height = innerHeight
|
|
20
|
-
|
|
34
|
+
const ensurePlane = (index: number, blend: 'normal' | 'darken') => {
|
|
21
35
|
let canvas = previewCanvases[index]
|
|
22
36
|
if (!canvas) {
|
|
23
37
|
canvas = document.createElement('canvas')
|
|
@@ -26,15 +40,34 @@ function renderPreview(effects: PaintableEffect[], timeMs: number) {
|
|
|
26
40
|
document.body.append(canvas)
|
|
27
41
|
previewCanvases.push(canvas)
|
|
28
42
|
}
|
|
29
|
-
|
|
30
|
-
if (canvas.style.mixBlendMode !== blendCss) canvas.style.mixBlendMode = blendCss
|
|
43
|
+
if (canvas.style.mixBlendMode !== blend) canvas.style.mixBlendMode = blend
|
|
31
44
|
if (canvas.width !== width) canvas.width = width
|
|
32
45
|
if (canvas.height !== height) canvas.height = height
|
|
33
46
|
const context = canvas.getContext('2d')
|
|
34
47
|
if (!context) throw new Error('2D canvas context is unavailable for preview')
|
|
35
48
|
context.clearRect(0, 0, width, height)
|
|
49
|
+
return context
|
|
50
|
+
}
|
|
51
|
+
let offset = 0
|
|
52
|
+
if (spotlightActive) {
|
|
53
|
+
const context = ensurePlane(0, 'normal')
|
|
54
|
+
paintSpotlightMask(context, effects, timeMs)
|
|
55
|
+
offset = 1
|
|
56
|
+
}
|
|
57
|
+
for (const [index, group] of groups.entries()) {
|
|
58
|
+
const context = ensurePlane(offset + index, group.blend === 'darken' ? 'darken' : 'normal')
|
|
36
59
|
paintPrimitives(context, group.primitives, { backdrop: false })
|
|
37
60
|
}
|
|
61
|
+
let topOffset = offset + groups.length
|
|
62
|
+
if (stampActive) {
|
|
63
|
+
const context = ensurePlane(topOffset, 'normal')
|
|
64
|
+
paintStamps(context, effects, timeMs)
|
|
65
|
+
topOffset += 1
|
|
66
|
+
}
|
|
67
|
+
if (laserActive) {
|
|
68
|
+
const context = ensurePlane(topOffset, 'normal')
|
|
69
|
+
paintLasers(context, effects, timeMs)
|
|
70
|
+
}
|
|
38
71
|
}
|
|
39
72
|
function silence(event: Event) {
|
|
40
73
|
if (event.target instanceof HTMLMediaElement && !event.target.muted) event.target.muted = true
|
|
@@ -45,25 +78,36 @@ if (previewEnabled) {
|
|
|
45
78
|
document.addEventListener('volumechange', silence, true)
|
|
46
79
|
for (const type of ['keydown', 'pointerdown', 'click', 'dblclick', 'wheel']) document.addEventListener(type, preventNavigation, { capture: true, passive: false })
|
|
47
80
|
}
|
|
48
|
-
|
|
81
|
+
type StaticSkip = { schedule_start_ms: number; schedule_end_ms: number; skip_ms: number }
|
|
82
|
+
type AppliedSkip = { record_at_ms: number; skip_ms: number }
|
|
83
|
+
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
84
|
let generation = 0
|
|
50
85
|
let origin = 0
|
|
86
|
+
let skippedMs = 0
|
|
87
|
+
const scheduleNow = () => (performance.now() - origin) + skippedMs
|
|
51
88
|
let schedule: Schedule
|
|
52
89
|
let visit = ''
|
|
53
90
|
let geometry: ReturnType<typeof geometryCollector> | undefined
|
|
54
|
-
const monitors = new Map<HTMLMediaElement, { timer:
|
|
91
|
+
const monitors = new Map<HTMLMediaElement, { timer: number; item: ScheduledAction }>()
|
|
55
92
|
function stopMedia(element: HTMLMediaElement, completed: boolean) {
|
|
56
93
|
const monitor = monitors.get(element)
|
|
57
94
|
if (!monitor) return
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
if (window.__slidevideoTimers) window.__slidevideoTimers.clearInternalInterval(monitor.timer)
|
|
96
|
+
else window.clearInterval(monitor.timer)
|
|
97
|
+
monitors.delete(element); element.pause()
|
|
98
|
+
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
99
|
}
|
|
61
|
-
const waits = new Map<
|
|
100
|
+
const waits = new Map<number, () => void>()
|
|
62
101
|
const wait = (ms: number) => new Promise<void>(resolve => {
|
|
63
|
-
const
|
|
102
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
103
|
+
const timer = scheduleTimer(() => { waits.delete(timer); resolve() }, Math.max(0, ms))
|
|
64
104
|
waits.set(timer, resolve)
|
|
65
105
|
})
|
|
66
|
-
function clearWaits() {
|
|
106
|
+
function clearWaits() {
|
|
107
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
108
|
+
for (const [timer, resolve] of waits) { cancelTimer(timer); resolve() }
|
|
109
|
+
waits.clear()
|
|
110
|
+
}
|
|
67
111
|
const painted = async () => {
|
|
68
112
|
await nextTick()
|
|
69
113
|
const first = await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
@@ -117,7 +161,7 @@ async function prepare(value: Schedule, expectedHashes: Record<string, string> =
|
|
|
117
161
|
generation++; clearWaits()
|
|
118
162
|
geometry?.stop(); geometry = undefined; visit = ''
|
|
119
163
|
for (const element of monitors.keys()) stopMedia(element, false)
|
|
120
|
-
state.phase = 'preparing'; state.events = []; state.markers = []; state.failure = ''; state.annotation_geometry = []; marker.value = ''
|
|
164
|
+
state.phase = 'preparing'; state.events = []; state.markers = []; state.failure = ''; state.annotation_geometry = []; state.applied_skips = []; marker.value = ''
|
|
121
165
|
schedule = value
|
|
122
166
|
for (const slide of nav.slides.value) { await navigate(slide.no); }
|
|
123
167
|
await document.fonts.ready
|
|
@@ -136,9 +180,11 @@ async function prepare(value: Schedule, expectedHashes: Record<string, string> =
|
|
|
136
180
|
}
|
|
137
181
|
element.muted = true; element.pause(); element.currentTime = 0; element.playbackRate = 1
|
|
138
182
|
if (element.readyState < 3) await new Promise<void>((resolve, reject) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
183
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
184
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
185
|
+
const timer = scheduleTimer(() => reject(new Error(`Media readiness timeout ${clip.id}`)), 10000)
|
|
186
|
+
element.addEventListener('canplay', () => { cancelTimer(timer); resolve() }, { once: true })
|
|
187
|
+
element.addEventListener('error', () => { cancelTimer(timer); reject(new Error(`Media cannot load ${clip.id}`)) }, { once: true })
|
|
142
188
|
})
|
|
143
189
|
}
|
|
144
190
|
let selected = nav.slides.value[0]
|
|
@@ -158,9 +204,231 @@ async function showMarker(color: string, current: number) {
|
|
|
158
204
|
await wait(350)
|
|
159
205
|
if (current !== generation) throw new Error('Playback reset')
|
|
160
206
|
}
|
|
161
|
-
|
|
207
|
+
const STATIC_RASTER_EXT = /\.(?:jpe?g|bmp|ico)$/i
|
|
208
|
+
const STATIC_RASTER_DATA = /^data:image\/(?:jpe?g|bmp|x-icon)(?:[;,]|$)/i
|
|
209
|
+
const SVG_EXT = /\.svg$/i
|
|
210
|
+
const SVG_DATA = /^data:image\/svg\+xml(?:[;,]|$)/i
|
|
211
|
+
const PNG_EXT = /\.png$/i
|
|
212
|
+
const PNG_DATA = /^data:image\/png(?:[;,]|$)/i
|
|
213
|
+
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
|
|
214
|
+
const svgStaticCache = new Map<string, boolean>()
|
|
215
|
+
const pngStaticCache = new Map<string, boolean>()
|
|
216
|
+
function isStaticPngBytes(bytes: Uint8Array): boolean {
|
|
217
|
+
if (bytes.length < 24 || bytes[0] !== 0x89 || bytes[1] !== 0x50 || bytes[2] !== 0x4e || bytes[3] !== 0x47) return false
|
|
218
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
219
|
+
let offset = 8
|
|
220
|
+
while (offset + 8 <= bytes.length) {
|
|
221
|
+
const length = view.getUint32(offset)
|
|
222
|
+
const type = String.fromCharCode(bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7])
|
|
223
|
+
if (type === 'acTL') return false
|
|
224
|
+
if (type === 'IDAT' || type === 'IEND') return true
|
|
225
|
+
offset += 12 + length
|
|
226
|
+
}
|
|
227
|
+
return false
|
|
228
|
+
}
|
|
229
|
+
async function isPngImageStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
230
|
+
const cached = pngStaticCache.get(src)
|
|
231
|
+
if (cached !== undefined) return cached
|
|
232
|
+
if (performance.now() >= deadlineMs) return false
|
|
233
|
+
try {
|
|
234
|
+
let bytes: Uint8Array
|
|
235
|
+
if (/^data:image\/png/i.test(src)) {
|
|
236
|
+
if (src.length > 262144) return false
|
|
237
|
+
const comma = src.indexOf(',')
|
|
238
|
+
const meta = comma >= 0 ? src.slice(0, comma) : ''
|
|
239
|
+
const payload = comma >= 0 ? src.slice(comma + 1) : ''
|
|
240
|
+
const raw = /;base64/i.test(meta) ? atob(payload) : decodeURIComponent(payload)
|
|
241
|
+
bytes = Uint8Array.from(raw, ch => ch.charCodeAt(0))
|
|
242
|
+
} else {
|
|
243
|
+
const remaining = deadlineMs - performance.now()
|
|
244
|
+
if (remaining <= 0) return false
|
|
245
|
+
const resolved = new URL(src, location.href)
|
|
246
|
+
if (resolved.origin !== location.origin) { pngStaticCache.set(src, false); return false }
|
|
247
|
+
const controller = new AbortController()
|
|
248
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
249
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
250
|
+
const timer = scheduleTimer(() => controller.abort(), remaining)
|
|
251
|
+
try {
|
|
252
|
+
const response = await fetch(resolved.href, { signal: controller.signal })
|
|
253
|
+
if (!response.ok) { pngStaticCache.set(src, false); return false }
|
|
254
|
+
bytes = new Uint8Array(await response.arrayBuffer())
|
|
255
|
+
} finally {
|
|
256
|
+
cancelTimer(timer)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const isStatic = isStaticPngBytes(bytes)
|
|
260
|
+
pngStaticCache.set(src, isStatic)
|
|
261
|
+
return isStatic
|
|
262
|
+
} catch {
|
|
263
|
+
return false
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function isSvgImageStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
267
|
+
const cached = svgStaticCache.get(src)
|
|
268
|
+
if (cached !== undefined) return cached
|
|
269
|
+
if (performance.now() >= deadlineMs) return false
|
|
270
|
+
try {
|
|
271
|
+
let text = ''
|
|
272
|
+
if (/^data:image\/svg\+xml/i.test(src)) {
|
|
273
|
+
if (src.length > 262144) return false
|
|
274
|
+
const comma = src.indexOf(',')
|
|
275
|
+
const meta = comma >= 0 ? src.slice(0, comma) : ''
|
|
276
|
+
const payload = comma >= 0 ? src.slice(comma + 1) : ''
|
|
277
|
+
text = /;base64/i.test(meta) ? atob(payload) : decodeURIComponent(payload)
|
|
278
|
+
} else {
|
|
279
|
+
const remaining = deadlineMs - performance.now()
|
|
280
|
+
if (remaining <= 0) return false
|
|
281
|
+
const resolved = new URL(src, location.href)
|
|
282
|
+
if (resolved.origin !== location.origin) { svgStaticCache.set(src, false); return false }
|
|
283
|
+
const controller = new AbortController()
|
|
284
|
+
const scheduleTimer = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalTimeout : (cb: () => void, delay: number) => window.setTimeout(cb, delay)
|
|
285
|
+
const cancelTimer = window.__slidevideoTimers ? window.__slidevideoTimers.clearInternalTimeout : (id: number) => window.clearTimeout(id)
|
|
286
|
+
const timer = scheduleTimer(() => controller.abort(), remaining)
|
|
287
|
+
try {
|
|
288
|
+
const response = await fetch(resolved.href, { signal: controller.signal })
|
|
289
|
+
if (!response.ok) { svgStaticCache.set(src, false); return false }
|
|
290
|
+
text = await response.text()
|
|
291
|
+
} finally {
|
|
292
|
+
cancelTimer(timer)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const isStatic = !SVG_DYNAMIC_CONTENT.test(text)
|
|
296
|
+
svgStaticCache.set(src, isStatic)
|
|
297
|
+
return isStatic
|
|
298
|
+
} catch {
|
|
299
|
+
return false
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async function isImageUrlStatic(src: string, deadlineMs: number): Promise<boolean> {
|
|
303
|
+
if (!src) return true
|
|
304
|
+
if (STATIC_RASTER_DATA.test(src)) return true
|
|
305
|
+
if (SVG_DATA.test(src)) return isSvgImageStatic(src, deadlineMs)
|
|
306
|
+
if (PNG_DATA.test(src)) return isPngImageStatic(src, deadlineMs)
|
|
307
|
+
if (/^data:/i.test(src) || /^blob:/i.test(src)) return false
|
|
308
|
+
let pathname = ''
|
|
309
|
+
try { pathname = new URL(src, location.href).pathname } catch { return false }
|
|
310
|
+
if (STATIC_RASTER_EXT.test(pathname)) return true
|
|
311
|
+
if (SVG_EXT.test(pathname)) return isSvgImageStatic(src, deadlineMs)
|
|
312
|
+
if (PNG_EXT.test(pathname)) return isPngImageStatic(src, deadlineMs)
|
|
313
|
+
return false
|
|
314
|
+
}
|
|
315
|
+
function hasSlideScriptOrMotion(): boolean {
|
|
316
|
+
const slide = nav.currentSlideRoute.value?.meta?.slide
|
|
317
|
+
if (!slide) return true
|
|
318
|
+
const raw = String(slide.content ?? '')
|
|
319
|
+
const stripped = raw.replace(/```[\s\S]*?```/g, '').replace(/`[^`]*`/g, '')
|
|
320
|
+
return /<script\b/i.test(stripped) || /\bv-motion\b/.test(stripped)
|
|
321
|
+
}
|
|
322
|
+
async function isSlideStatic(current: number, maxBudgetMs: number): Promise<boolean> {
|
|
323
|
+
if (monitors.size > 0 || hasSlideScriptOrMotion() || window.__slidevideoTimers?.hasPending()) return false
|
|
324
|
+
if (await window.__slidevideoHasInFlightRequests?.()) return false
|
|
325
|
+
const root = document.body
|
|
326
|
+
if (!root || window.__slidevideoTimers?.hasShadowHost(root)) return false
|
|
327
|
+
const svgDeadline = performance.now() + Math.min(100, Math.max(0, maxBudgetMs))
|
|
328
|
+
const hasDynamicDom = async () => {
|
|
329
|
+
for (const mediaEl of root.querySelectorAll<HTMLMediaElement>('video, audio')) {
|
|
330
|
+
if (!mediaEl.paused && !mediaEl.ended) return true
|
|
331
|
+
}
|
|
332
|
+
for (const element of root.querySelectorAll('canvas, iframe, object, embed, progress:not([value])')) {
|
|
333
|
+
if (element.tagName === 'CANVAS' && element.hasAttribute('data-slidevideo-canvas')) continue
|
|
334
|
+
if (element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) return true
|
|
335
|
+
}
|
|
336
|
+
if (root.querySelector('svg animate, svg animateTransform, svg animateMotion, svg animateColor, svg set, svg discard, svg foreignObject')) return true
|
|
337
|
+
for (const refEl of root.querySelectorAll('svg image, svg use')) {
|
|
338
|
+
const href = refEl.getAttribute('href') || refEl.getAttribute('xlink:href') || ''
|
|
339
|
+
if (href && !href.startsWith('#') && !(await isImageUrlStatic(href, svgDeadline))) return true
|
|
340
|
+
}
|
|
341
|
+
for (const img of root.querySelectorAll('img')) {
|
|
342
|
+
if (!img.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
343
|
+
if (!img.complete && (img.currentSrc || img.getAttribute('src') || img.getAttribute('srcset'))) return true
|
|
344
|
+
const src = img.currentSrc || img.getAttribute('src') || ''
|
|
345
|
+
if (src && !(await isImageUrlStatic(src, svgDeadline))) return true
|
|
346
|
+
}
|
|
347
|
+
for (const element of root.querySelectorAll('*')) {
|
|
348
|
+
if (!element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
349
|
+
for (const pseudo of [null, '::before', '::after'] as const) {
|
|
350
|
+
const style = getComputedStyle(element, pseudo)
|
|
351
|
+
for (const prop of ['backgroundImage', 'content', 'maskImage', 'borderImageSource', 'listStyleImage'] as const) {
|
|
352
|
+
const value = style[prop]
|
|
353
|
+
if (!value || value === 'none' || value === 'normal' || !value.includes('url(')) continue
|
|
354
|
+
for (const match of value.matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)\s]+))\s*\)/gi)) {
|
|
355
|
+
const bgUrl = match[1] ?? match[2] ?? match[3] ?? ''
|
|
356
|
+
if (!bgUrl) continue
|
|
357
|
+
if (!(await isImageUrlStatic(bgUrl, svgDeadline))) return true
|
|
358
|
+
if (!/^data:/i.test(bgUrl)) {
|
|
359
|
+
try {
|
|
360
|
+
const resolved = new URL(bgUrl, location.href).href
|
|
361
|
+
if (performance.getEntriesByName(resolved, 'resource').length === 0) return true
|
|
362
|
+
} catch {
|
|
363
|
+
return true
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return false
|
|
371
|
+
}
|
|
372
|
+
const hasRunningAnimation = () => document.getAnimations().some(animation => {
|
|
373
|
+
if (animation.playState !== 'running' && !animation.pending) return false
|
|
374
|
+
const effect = animation.effect
|
|
375
|
+
const target = effect instanceof KeyframeEffect ? effect.target : null
|
|
376
|
+
return target instanceof Node && root.contains(target)
|
|
377
|
+
})
|
|
378
|
+
if (await hasDynamicDom() || hasRunningAnimation()) return false
|
|
379
|
+
let mutated = false
|
|
380
|
+
const observer = new MutationObserver(() => { mutated = true })
|
|
381
|
+
observer.observe(root, { subtree: true, childList: true, attributes: true, characterData: true })
|
|
382
|
+
try {
|
|
383
|
+
await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
384
|
+
await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
385
|
+
} finally {
|
|
386
|
+
observer.disconnect()
|
|
387
|
+
}
|
|
388
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
389
|
+
if (mutated || monitors.size > 0 || window.__slidevideoTimers?.hasPending() || window.__slidevideoTimers?.hasShadowHost(root) || await window.__slidevideoHasInFlightRequests?.() || await hasDynamicDom() || hasRunningAnimation()) return false
|
|
390
|
+
return true
|
|
391
|
+
}
|
|
392
|
+
async function waitUntilSchedule(targetMs: number, current: number, plannedSkips: StaticSkip[], skipCursor: { index: number; startMs: number }) {
|
|
393
|
+
while (scheduleNow() < targetMs) {
|
|
394
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
395
|
+
if (state.failure) throw new Error(state.failure)
|
|
396
|
+
const skip = plannedSkips[skipCursor.index]
|
|
397
|
+
if (skip && skipCursor.startMs <= targetMs) {
|
|
398
|
+
if (scheduleNow() < skipCursor.startMs) {
|
|
399
|
+
await wait(skipCursor.startMs - scheduleNow())
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
const skipTarget = Math.min(skip.schedule_end_ms, targetMs)
|
|
403
|
+
const svgBudgetMs = Math.max(0, skipTarget - scheduleNow() - 50)
|
|
404
|
+
if (await isSlideStatic(current, svgBudgetMs)) {
|
|
405
|
+
const remainingSkip = skipTarget - scheduleNow()
|
|
406
|
+
if (remainingSkip > 0) {
|
|
407
|
+
state.applied_skips.push({ record_at_ms: performance.now() - origin, skip_ms: remainingSkip })
|
|
408
|
+
skippedMs += remainingSkip
|
|
409
|
+
}
|
|
410
|
+
if (skipTarget >= skip.schedule_end_ms) {
|
|
411
|
+
skipCursor.index++
|
|
412
|
+
skipCursor.startMs = plannedSkips[skipCursor.index]?.schedule_start_ms ?? Infinity
|
|
413
|
+
} else {
|
|
414
|
+
skipCursor.startMs = skipTarget
|
|
415
|
+
}
|
|
416
|
+
continue
|
|
417
|
+
}
|
|
418
|
+
skipCursor.index++
|
|
419
|
+
skipCursor.startMs = plannedSkips[skipCursor.index]?.schedule_start_ms ?? Infinity
|
|
420
|
+
continue
|
|
421
|
+
}
|
|
422
|
+
await wait(targetMs - scheduleNow())
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function play(verifyTiming = false, plannedSkips: StaticSkip[] = []) {
|
|
162
426
|
if (state.phase !== 'ready') throw new Error('Prepare playback first')
|
|
163
427
|
const current = generation
|
|
428
|
+
skippedMs = 0
|
|
429
|
+
state.applied_skips = []
|
|
430
|
+
const skips = verifyTiming ? [] : plannedSkips
|
|
431
|
+
const skipCursor = { index: 0, startMs: skips[0]?.schedule_start_ms ?? Infinity }
|
|
164
432
|
state.phase = 'recording'; origin = performance.now()
|
|
165
433
|
try {
|
|
166
434
|
await showMarker('#ff00ff', current)
|
|
@@ -171,9 +439,9 @@ async function play(verifyTiming = false) {
|
|
|
171
439
|
for (const event of state.markers) { event.observed_ms -= start - origin; event.rendered_by_ms -= start - origin }
|
|
172
440
|
origin = start
|
|
173
441
|
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 }), () =>
|
|
442
|
+
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
443
|
for (const entry of playbackEntries(schedule)) {
|
|
176
|
-
|
|
444
|
+
await waitUntilSchedule(entry.at, current, skips, skipCursor)
|
|
177
445
|
if (current !== generation) throw new Error('Playback reset')
|
|
178
446
|
if (state.failure) throw new Error(state.failure)
|
|
179
447
|
if (entry.type === 'geometry-start') { geometry!.start(entry.request); continue }
|
|
@@ -181,15 +449,16 @@ async function play(verifyTiming = false) {
|
|
|
181
449
|
if (entry.type === 'annotation-start' || entry.type === 'annotation-end') continue
|
|
182
450
|
const item = entry.item
|
|
183
451
|
await apply(item)
|
|
184
|
-
const observed_ms =
|
|
452
|
+
const observed_ms = scheduleNow()
|
|
185
453
|
if (verifyTiming && observed_ms - item.start_ms > 100) throw new Error(`Late action ${item.id}: ${observed_ms - item.start_ms} ms`)
|
|
186
454
|
state.events.push({ id: item.id, type: item.action.type, scheduled_ms: item.start_ms, observed_ms })
|
|
187
455
|
if (item.action.type === 'play') {
|
|
188
456
|
const action = item.action
|
|
189
457
|
const element = media(action.media)
|
|
190
|
-
const
|
|
458
|
+
const scheduleInterval = window.__slidevideoTimers ? window.__slidevideoTimers.setInternalInterval : (cb: () => void, delay: number) => window.setInterval(cb, delay)
|
|
459
|
+
const monitor = scheduleInterval(() => {
|
|
191
460
|
if (generation !== current) { stopMedia(element, false); return }
|
|
192
|
-
const expected = (
|
|
461
|
+
const expected = (scheduleNow() - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)
|
|
193
462
|
if (expected > (item.end_ms - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)) {
|
|
194
463
|
stopMedia(element, true)
|
|
195
464
|
} else if (Math.abs(element.currentTime * 1000 - expected) > 150) {
|
|
@@ -199,7 +468,7 @@ async function play(verifyTiming = false) {
|
|
|
199
468
|
monitors.set(element, { timer: monitor, item })
|
|
200
469
|
}
|
|
201
470
|
}
|
|
202
|
-
await
|
|
471
|
+
await waitUntilSchedule(schedule.duration_ms, current, skips, skipCursor)
|
|
203
472
|
for (const element of monitors.keys()) stopMedia(element, true)
|
|
204
473
|
if (state.failure) throw new Error(state.failure)
|
|
205
474
|
geometry?.complete(); geometry?.stop(); geometry = undefined
|
|
@@ -225,6 +494,7 @@ async function inspectTargets(): Promise<PresentationInspection['annotation_targ
|
|
|
225
494
|
}
|
|
226
495
|
onUnmounted(() => {
|
|
227
496
|
generation++; clearWaits(); geometry?.stop(); preview?.dispose()
|
|
497
|
+
postPreviewView(undefined)
|
|
228
498
|
previewCanvases.splice(0).forEach(canvas => canvas.remove())
|
|
229
499
|
for (const element of monitors.keys()) stopMedia(element, false)
|
|
230
500
|
document.removeEventListener('play', silence, true); document.removeEventListener('volumechange', silence, true)
|
|
@@ -239,8 +509,25 @@ onMounted(async () => {
|
|
|
239
509
|
const response = await fetch('/__slidevideo_preview')
|
|
240
510
|
if (!response.ok) throw new Error('Preview configuration is unavailable')
|
|
241
511
|
const config = await response.json()
|
|
512
|
+
previewParentOrigin = config.parentOrigin
|
|
513
|
+
try {
|
|
514
|
+
const fontResp = await fetch(`${config.parentOrigin}/fonts/manifest.json`)
|
|
515
|
+
if (fontResp.ok) {
|
|
516
|
+
const specs = await fontResp.json() as { family: string; files: { file: string; style: string; unicodeRange: string }[] }[]
|
|
517
|
+
const descriptors = specs.flatMap(spec => spec.files.map(entry => ({ family: spec.family, ...entry })))
|
|
518
|
+
const loaded = await Promise.all(descriptors.map(async entry => {
|
|
519
|
+
const face = new FontFace(entry.family, `url(${config.parentOrigin}/fonts/${entry.file}) format('woff2')`, {
|
|
520
|
+
weight: '400 800',
|
|
521
|
+
style: entry.style,
|
|
522
|
+
unicodeRange: entry.unicodeRange,
|
|
523
|
+
})
|
|
524
|
+
return face.load()
|
|
525
|
+
}))
|
|
526
|
+
for (const face of loaded) document.fonts.add(face)
|
|
527
|
+
}
|
|
528
|
+
} catch {}
|
|
242
529
|
const { createPreview } = await import('./preview')
|
|
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)
|
|
530
|
+
preview = createPreview(config.schedule, config.mediaHashes, config.parentOrigin, prepare, apply, async (slideTarget, visitId, click) => { visit = visitId; await navigate(slideIndex(slideTarget), click) }, () => ({ slide: String(nav.currentSlideRoute.value.meta.slide.frontmatter.name ?? `slide-${nav.currentSlideNo.value}`), visit, click: nav.clicks.value, index: nav.currentSlideNo.value }), renderPreview)
|
|
244
531
|
window.__slidevideo.preview = preview
|
|
245
532
|
await preview.initialize()
|
|
246
533
|
} catch (error) {
|