@slidevideo/cli 0.1.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 +33 -0
- package/IMPRESSUM.md +13 -0
- package/LICENSE-TERMS.md +58 -0
- package/README.md +25 -0
- package/addons/slidevideo/geometry.ts +127 -0
- package/addons/slidevideo/global-top.vue +232 -0
- package/addons/slidevideo/package.json +1 -0
- package/addons/slidevideo/playback-entries.ts +14 -0
- package/addons/slidevideo/preview.ts +157 -0
- package/dist/adapters/browser-runtime.d.ts +37 -0
- package/dist/adapters/browser-runtime.js +1 -0
- package/dist/adapters/edge.d.ts +7 -0
- package/dist/adapters/edge.js +46 -0
- package/dist/adapters/elevenlabs.d.ts +7 -0
- package/dist/adapters/elevenlabs.js +58 -0
- package/dist/adapters/powerpoint-preview.d.ts +2 -0
- package/dist/adapters/powerpoint-preview.js +18 -0
- package/dist/adapters/powerpoint.d.ts +21 -0
- package/dist/adapters/powerpoint.js +434 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/slidev-inputs.d.ts +1 -0
- package/dist/adapters/slidev-inputs.js +86 -0
- package/dist/adapters/slidev-inspection.d.ts +3 -0
- package/dist/adapters/slidev-inspection.js +79 -0
- package/dist/adapters/slidev-server.d.ts +1 -0
- package/dist/adapters/slidev-server.js +48 -0
- package/dist/adapters/slidev.d.ts +30 -0
- package/dist/adapters/slidev.js +251 -0
- package/dist/annotation-paint.d.ts +19 -0
- package/dist/annotation-paint.js +13 -0
- package/dist/annotations.d.ts +27 -0
- package/dist/annotations.js +115 -0
- package/dist/assembly.d.ts +48 -0
- package/dist/assembly.js +138 -0
- package/dist/calibration.d.ts +24 -0
- package/dist/calibration.js +346 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/compositor.d.ts +18 -0
- package/dist/compositor.js +155 -0
- package/dist/contracts.d.ts +358 -0
- package/dist/contracts.js +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/executables.d.ts +23 -0
- package/dist/executables.js +165 -0
- package/dist/installation.d.ts +6 -0
- package/dist/installation.js +32 -0
- package/dist/license-key.d.ts +12 -0
- package/dist/license-key.js +55 -0
- package/dist/license-status.d.ts +16 -0
- package/dist/license-status.js +12 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.js +57 -0
- package/dist/overlay-assets.d.ts +2 -0
- package/dist/overlay-assets.js +58 -0
- package/dist/pipeline.d.ts +50 -0
- package/dist/pipeline.js +257 -0
- package/dist/preview/contracts.d.ts +34 -0
- package/dist/preview/contracts.js +1 -0
- package/dist/preview/player.d.ts +1 -0
- package/dist/preview/player.js +129 -0
- package/dist/preview/server.d.ts +1 -0
- package/dist/preview/server.js +112 -0
- package/dist/preview/view.d.ts +1 -0
- package/dist/preview/view.js +36 -0
- package/dist/revoked-keys.json +1 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +109 -0
- package/dist/setup-install.d.ts +7 -0
- package/dist/setup-install.js +98 -0
- package/dist/setup-license.d.ts +2 -0
- package/dist/setup-license.js +63 -0
- package/dist/setup.d.ts +34 -0
- package/dist/setup.js +218 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +125 -0
- package/dist/storyboard.d.ts +6 -0
- package/dist/storyboard.js +86 -0
- package/dist/timing.d.ts +6 -0
- package/dist/timing.js +162 -0
- package/package.json +134 -0
- package/schemas/annotation-geometry.v1.json +130 -0
- package/schemas/revoked-keys.schema.json +11 -0
- package/schemas/run-manifest.v1.json +96 -0
- package/schemas/schedule.v1.json +108 -0
- package/schemas/schedule.v2.json +496 -0
- package/schemas/speech.v1.json +173 -0
- package/schemas/storyboard.v1.json +461 -0
- package/schemas/storyboard.v2.json +802 -0
- package/schemas/timing-evidence.v1.json +129 -0
- package/skills/slidevideo/SKILL.md +56 -0
- package/skills/slidevideo/references/production.md +76 -0
- package/skills/slidevideo/references/storyboard.md +272 -0
- package/tools/edge-tts/edge-tts.py +19 -0
- package/tools/edge-tts/requirements.lock +34 -0
- package/tools/powerpoint/Native.cs +277 -0
- package/tools/powerpoint/powerpoint.ps1 +714 -0
- package/tools/powerpoint/preview.ps1 +100 -0
- package/tools/powerpoint/requirements.json +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SlideVideo changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.1
|
|
6
|
+
|
|
7
|
+
### Changes
|
|
8
|
+
|
|
9
|
+
- Choose a patch, minor or major version bump in the npm release workflow. The workflow commits the version and release notes to main, then publishes that exact source commit.
|
|
10
|
+
- Wait for npm registry processing after publishing instead of failing after a few seconds.
|
|
11
|
+
- Publish npm releases from `main` using the version in `package.json` and the `latest` tag. Use pending changelog notes without entering a release version or tag in Actions.
|
|
12
|
+
- Verify npm releases through tarball integrity, external installation and the installed CLI version. Keep video production as a separate optional local check.
|
|
13
|
+
- Deploy the website from `main` without entering a release version. The website includes unreleased changes; npm release artifacts retain their selected version's notes.
|
|
14
|
+
- Open live Stripe checkout from the protected pricing page, with links to contact, cancellation and withdrawal forms.
|
|
15
|
+
- Apply the license terms from 21 November 2026.
|
|
16
|
+
|
|
17
|
+
## 0.1.0-alpha.1
|
|
18
|
+
|
|
19
|
+
The first alpha adds an npm install and guides you through setting up a local video project.
|
|
20
|
+
|
|
21
|
+
### Changes
|
|
22
|
+
|
|
23
|
+
- Use `slidevideo setup` to check your presentation and speech workflow, install supported dependencies, and save tool paths across projects.
|
|
24
|
+
- Turn a Slidev deck and YAML storyboard into an H.264 MP4 with narration, timed reveals, local video clips, and optional marker highlights.
|
|
25
|
+
- Use Edge TTS for generated speech or supply your own ElevenLabs API key and voice ID. Reuse matching narration from a local cache.
|
|
26
|
+
- Use `slidevideo play` to review the storyboard and live annotations in a silent browser preview.
|
|
27
|
+
- Give a coding agent the bundled authoring instructions with `slidevideo skill` from your presentation folder.
|
|
28
|
+
- Read the bundled license terms and provider contact details offline with `slidevideo license` and `slidevideo impressum`.
|
|
29
|
+
|
|
30
|
+
### Known limits
|
|
31
|
+
|
|
32
|
+
- The packaged release check covers Slidev production on Linux with Chromium and retained Edge TTS speech. Windows and native PowerPoint package verification are pending.
|
|
33
|
+
- Marker highlights require visible, stationary targets. Timing verification is opt-in, and you review the delivered video.
|
package/IMPRESSUM.md
ADDED
package/LICENSE-TERMS.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# SlideVideo license terms
|
|
2
|
+
|
|
3
|
+
Effective 21 November 2026.
|
|
4
|
+
|
|
5
|
+
## Who provides SlideVideo
|
|
6
|
+
|
|
7
|
+
Christian Pietsch, Kirchenstr. 22A, 22869 Schenefeld, Germany, provides SlideVideo. Contact us at [hello@slidevideo.io](mailto:hello@slidevideo.io) or [+49 40 40196280](tel:+494040196280).
|
|
8
|
+
|
|
9
|
+
We grant you permission to install and use the SlideVideo CLI under these terms. SlideVideo and its contributors retain their rights in the software. Third-party components are subject to their own licenses.
|
|
10
|
+
|
|
11
|
+
## Free use
|
|
12
|
+
|
|
13
|
+
You may use SlideVideo at no charge to create and share watermarked videos for personal, professional or commercial purposes. You may show, publish, sell or deliver those videos to clients, subject to the rights you hold in the content. Keep the SlideVideo watermark visible when you use or share the videos, including after editing. You need an active paid license that covers your use to produce a version that omits, hides or removes the watermark.
|
|
14
|
+
|
|
15
|
+
## Watermark-Free License
|
|
16
|
+
|
|
17
|
+
Each person who independently creates or adapts a SlideVideo storyboard for watermark-free delivery is a producer and needs a license covering their work. This applies when a colleague runs the export on their behalf.
|
|
18
|
+
|
|
19
|
+
An active Watermark-Free License covers one named producer across all the storyboards they produce for personal, professional or commercial use. That person may use their own devices and ask a coding agent or remote runner to perform an individual export. Colleagues may supply slides or give feedback under the free terms. Producers may share finished videos with colleagues or clients, subject to their rights in the content.
|
|
20
|
+
|
|
21
|
+
## Automation License
|
|
22
|
+
|
|
23
|
+
A separate Automation License is required to produce watermark-free videos through a scheduled or event-triggered workflow, a shared export queue or an automated batch job that creates multiple finished videos. This requirement applies whoever configures or starts the workflow. The Automation agreement identifies the organization and the workflows it covers.
|
|
24
|
+
|
|
25
|
+
## Individual billing, activation and cancellation
|
|
26
|
+
|
|
27
|
+
The individual subscription costs €4.99 per month, including applicable taxes. It continues indefinitely and we charge you monthly until the subscription ends. Before you order, checkout shows the total monthly price, billing interval and cancellation terms. We email your contract confirmation and license key.
|
|
28
|
+
|
|
29
|
+
Enter your key using `slidevideo setup --license` and keep it private. The CLI checks the key locally. You are responsible for using it only while you hold a current license.
|
|
30
|
+
|
|
31
|
+
You may cancel at any time by email or post using the contact details above. When we offer subscriptions for purchase online, use the cancellation link on the [SlideVideo website](https://slidevideo.io). We email your declaration, receipt time and intended end date. Ordinary cancellation takes effect at the end of the current billing period, or on a later date you request. If you request the earliest available date, the notice period is at most one month. You may end the contract sooner when the law gives you that right.
|
|
32
|
+
|
|
33
|
+
When your paid license ends, remove the activation using `slidevideo setup --license` and use the free tier for new exports. After ordinary cancellation, you may continue to use, share and sell videos you lawfully produced without a watermark while the paid license was active.
|
|
34
|
+
|
|
35
|
+
## Right of withdrawal for consumers
|
|
36
|
+
|
|
37
|
+
If you buy the subscription as a consumer online, you may withdraw within 14 days of entering into the contract without giving a reason. The same period applies if you receive or activate your key immediately. Any longer period available under law applies.
|
|
38
|
+
|
|
39
|
+
Send a clear statement that you wish to withdraw by email or post using the contact details above. You may use the form below. We email your declaration and receipt time. Send your declaration before the withdrawal period ends to meet the deadline.
|
|
40
|
+
|
|
41
|
+
We refund payments for the withdrawn subscription without undue delay and within 14 days of receiving your withdrawal. We use your original payment method unless you expressly agree to another one. We charge no fees for the refund.
|
|
42
|
+
|
|
43
|
+
### Optional withdrawal form
|
|
44
|
+
|
|
45
|
+
Send to Christian Pietsch, Kirchenstr. 22A, 22869 Schenefeld, Germany, or [hello@slidevideo.io](mailto:hello@slidevideo.io).
|
|
46
|
+
|
|
47
|
+
I wish to withdraw from my SlideVideo Watermark-Free License subscription.
|
|
48
|
+
|
|
49
|
+
- Order date and order reference, if available
|
|
50
|
+
- Your name and postal address
|
|
51
|
+
- Date of this notice
|
|
52
|
+
- Your signature, for paper submissions only
|
|
53
|
+
|
|
54
|
+
## Your content and your rights
|
|
55
|
+
|
|
56
|
+
You keep the rights you hold in your slides, scripts, media and finished videos. Make sure you have permission to use the content you include and comply with the terms of any third-party media, fonts or speech services you choose.
|
|
57
|
+
|
|
58
|
+
Consumers have statutory rights if we fail to supply the digital product or it is defective. You may ask us to fix a defect, and you may be entitled to a price reduction, termination or compensation when the legal conditions for those remedies apply. We provide and notify you of required updates, including security updates, for the period required by law. Your mandatory consumer protections apply throughout these terms.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# SlideVideo
|
|
2
|
+
|
|
3
|
+
SlideVideo turns a slide deck into a narrated video. It reads a `slidevideo.yaml` storyboard that specifies narration and when to advance slides, reveal content or play clips.
|
|
4
|
+
|
|
5
|
+
Install Node.js 22.22.0 or later, then run:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install --global @slidevideo/cli
|
|
9
|
+
slidevideo setup
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Setup checks FFmpeg and the tools for your presentation format and speech provider. In your project folder, put `slidevideo.yaml` next to your presentation. Run:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
slidevideo validate --storyboard slidevideo.yaml
|
|
16
|
+
slidevideo build --storyboard slidevideo.yaml --run runs/hello-001
|
|
17
|
+
```
|
|
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.
|
|
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.
|
|
22
|
+
|
|
23
|
+
See the [user manual](https://slidevideo.io/guide.html) for host prerequisites and a first build, and the [changelog](CHANGELOG.md) for release notes. Run `slidevideo --help` for the installed command reference.
|
|
24
|
+
|
|
25
|
+
Run `slidevideo license` for the bundled license terms or `slidevideo impressum` for the provider's contact details. Both commands work offline. You can also read the [license terms](https://slidevideo.io/license.html) and [Impressum](https://slidevideo.io/impressum.html) on the website.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { AnnotationGeometry, Rectangle, ResolvedAnnotation } from '../../dist/contracts.js'
|
|
2
|
+
|
|
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 }
|
|
5
|
+
const rectangle = (rect: DOMRect): Rectangle => ({ x: rect.x, y: rect.y, width: rect.width, height: rect.height })
|
|
6
|
+
function axisAligned(element: Element) {
|
|
7
|
+
const style = getComputedStyle(element)
|
|
8
|
+
if (style.clipPath !== 'none' || style.maskImage !== 'none' || style.clip !== 'auto') throw new Error('Clipped or masked targets are unsupported')
|
|
9
|
+
if (style.rotate !== 'none' && style.rotate !== '0deg') throw new Error('Rotated targets are unsupported')
|
|
10
|
+
if (style.scale.split(/\s+/).some(value => Number(value) < 0)) throw new Error('Reflected targets are unsupported')
|
|
11
|
+
if (style.transform !== 'none') {
|
|
12
|
+
const matrix = new DOMMatrixReadOnly(style.transform)
|
|
13
|
+
if (!matrix.is2D || Math.abs(matrix.b) > 0.00001 || Math.abs(matrix.c) > 0.00001 || matrix.a <= 0 || matrix.d <= 0) throw new Error('Rotated, skewed or reflected targets are unsupported')
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const within = (inner: Rectangle, outer: Rectangle) => inner.x >= outer.x - 0.25 && inner.y >= outer.y - 0.25 && inner.x + inner.width <= outer.x + outer.width + 0.25 && inner.y + inner.height <= outer.y + outer.height + 0.25
|
|
17
|
+
function audience(index: number) {
|
|
18
|
+
const content = document.querySelector<HTMLElement>('#slide-container > #slide-content')
|
|
19
|
+
const slides = content?.querySelectorAll<HTMLElement>(`#slideshow > .slidev-page[data-slidev-no="${index}"]`)
|
|
20
|
+
if (!content || slides?.length !== 1 || !slides[0].checkVisibility({ opacityProperty: true, visibilityProperty: true })) throw new Error('Active audience slide is unavailable or ambiguous')
|
|
21
|
+
return { content, slide: slides[0] }
|
|
22
|
+
}
|
|
23
|
+
function visibleBounds(element: Element, content: HTMLElement): Rectangle {
|
|
24
|
+
if (!element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) throw new Error('Target is hidden')
|
|
25
|
+
const bounds = rectangle(element.getBoundingClientRect())
|
|
26
|
+
if (!(bounds.width > 0 && bounds.height > 0)) throw new Error('Target has empty bounds')
|
|
27
|
+
if (!within(bounds, rectangle(content.getBoundingClientRect()))) throw new Error('Target is clipped by the slide-content rectangle')
|
|
28
|
+
for (let ancestor: Element | null = element; ancestor; ancestor = ancestor.parentElement) {
|
|
29
|
+
if (ancestor instanceof SVGGElement) throw new Error('Grouped SVG targets are unsupported')
|
|
30
|
+
axisAligned(ancestor)
|
|
31
|
+
const style = getComputedStyle(ancestor)
|
|
32
|
+
if (ancestor !== element && /(hidden|clip|scroll|auto)/.test(`${style.overflowX} ${style.overflowY}`)) {
|
|
33
|
+
const clip = rectangle(ancestor.getBoundingClientRect())
|
|
34
|
+
if (ancestor instanceof HTMLElement && ancestor.offsetWidth && ancestor.offsetHeight) {
|
|
35
|
+
const scaleX = clip.width / ancestor.offsetWidth, scaleY = clip.height / ancestor.offsetHeight
|
|
36
|
+
clip.x += ancestor.clientLeft * scaleX; clip.y += ancestor.clientTop * scaleY
|
|
37
|
+
clip.width = ancestor.clientWidth * scaleX; clip.height = ancestor.clientHeight * scaleY
|
|
38
|
+
}
|
|
39
|
+
if (!within(bounds, clip)) throw new Error('Target is clipped by an ancestor')
|
|
40
|
+
}
|
|
41
|
+
if (ancestor === content) break
|
|
42
|
+
}
|
|
43
|
+
if (element instanceof SVGGraphicsElement) {
|
|
44
|
+
const matrix = element.getScreenCTM()
|
|
45
|
+
if (!matrix || Math.abs(matrix.b) > 0.00001 || Math.abs(matrix.c) > 0.00001 || matrix.a <= 0 || matrix.d <= 0) throw new Error('Rotated, skewed or reflected SVG targets are unsupported')
|
|
46
|
+
}
|
|
47
|
+
return bounds
|
|
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')
|
|
51
|
+
const { content, slide } = audience(position.index)
|
|
52
|
+
for (let ancestor: Element | null = content; ancestor; ancestor = ancestor.parentElement) axisAligned(ancestor)
|
|
53
|
+
for (let ancestor: Element | null = slide; ancestor && ancestor !== content; ancestor = ancestor.parentElement) {
|
|
54
|
+
axisAligned(ancestor)
|
|
55
|
+
if (ancestor.getAnimations().some(animation => animation.playState === 'running' || animation.pending)) throw new Error('Slide transition is still active')
|
|
56
|
+
}
|
|
57
|
+
const contentRect = rectangle(content.getBoundingClientRect())
|
|
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 }
|
|
71
|
+
}
|
|
72
|
+
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 }>()
|
|
75
|
+
let frame = 0
|
|
76
|
+
let running = true
|
|
77
|
+
function sample(annotation: ResolvedAnnotation) {
|
|
78
|
+
try {
|
|
79
|
+
const measurement = measure(annotation, position())
|
|
80
|
+
const existing = active.get(annotation.id)
|
|
81
|
+
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 })
|
|
84
|
+
} else {
|
|
85
|
+
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')
|
|
88
|
+
existing.record.samples++; existing.record.observed_end_ms = elapsed()
|
|
89
|
+
}
|
|
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)}`) }
|
|
91
|
+
}
|
|
92
|
+
function tick() {
|
|
93
|
+
if (!running) return
|
|
94
|
+
try { for (const { annotation } of active.values()) sample(annotation) }
|
|
95
|
+
catch (error) { fail(String(error)); stop(); return }
|
|
96
|
+
frame = requestAnimationFrame(tick)
|
|
97
|
+
}
|
|
98
|
+
function stop() { running = false; cancelAnimationFrame(frame); active.clear() }
|
|
99
|
+
frame = requestAnimationFrame(tick)
|
|
100
|
+
return {
|
|
101
|
+
start(annotation: ResolvedAnnotation) { sample(annotation) },
|
|
102
|
+
end(annotation: ResolvedAnnotation) { sample(annotation); active.delete(annotation.id) },
|
|
103
|
+
stop,
|
|
104
|
+
complete() {
|
|
105
|
+
if (output.length !== annotations.length || active.size) throw new Error('Annotation geometry collection did not complete')
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function inspectAudienceTargets(index: number) {
|
|
110
|
+
const { content, slide } = audience(index)
|
|
111
|
+
const targets = new Map<string, string>()
|
|
112
|
+
for (const element of slide.querySelectorAll('*')) {
|
|
113
|
+
const selectors: string[] = []
|
|
114
|
+
if (element.id) selectors.push(`#${CSS.escape(element.id)}`)
|
|
115
|
+
if (element.hasAttribute('data-testid')) selectors.push(`[data-testid=${JSON.stringify(element.getAttribute('data-testid'))}]`)
|
|
116
|
+
if (/^(H[1-6]|P|IMG|VIDEO|TABLE|SVG)$/.test(element.tagName)) selectors.push(element.tagName.toLowerCase())
|
|
117
|
+
for (const name of element.classList) if (!name.startsWith('slidev-') && !name.startsWith('v-')) selectors.push(`${element.tagName.toLowerCase()}.${CSS.escape(name)}`)
|
|
118
|
+
for (const selector of selectors) {
|
|
119
|
+
if (slide.querySelectorAll(selector).length !== 1) continue
|
|
120
|
+
try { visibleBounds(element, content) } catch { continue }
|
|
121
|
+
const description = `${element.tagName.toLowerCase()} ${(element.getAttribute('alt') || element.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 120)}`.trim()
|
|
122
|
+
targets.set(selector, description)
|
|
123
|
+
break
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return [...targets].map(([identity, description]) => ({ identity, description }))
|
|
127
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, nextTick, onMounted, onUnmounted } from 'vue'
|
|
3
|
+
import { useNav } from '@slidev/client'
|
|
4
|
+
import type { Schedule, ObservedEvent, ScheduledAction, AnnotationGeometry, PresentationInspection } from '../../dist/contracts.js'
|
|
5
|
+
import { geometryCollector, inspectAudienceTargets } from './geometry'
|
|
6
|
+
import type { createPreview, PreviewLayer } from './preview'
|
|
7
|
+
import { playbackEntries } from './playback-entries'
|
|
8
|
+
const nav = useNav()
|
|
9
|
+
const marker = ref('')
|
|
10
|
+
const enabled = new URLSearchParams(location.search).has('slidevideo')
|
|
11
|
+
const previewEnabled = enabled && new URLSearchParams(location.search).has('slidevideo-preview')
|
|
12
|
+
const previewLayers = ref<PreviewLayer[]>([])
|
|
13
|
+
let preview: ReturnType<typeof createPreview> | undefined
|
|
14
|
+
function silence(event: Event) {
|
|
15
|
+
if (event.target instanceof HTMLMediaElement && !event.target.muted) event.target.muted = true
|
|
16
|
+
}
|
|
17
|
+
function preventNavigation(event: Event) { event.preventDefault(); event.stopImmediatePropagation() }
|
|
18
|
+
if (previewEnabled) {
|
|
19
|
+
document.addEventListener('play', silence, true)
|
|
20
|
+
document.addEventListener('volumechange', silence, true)
|
|
21
|
+
for (const type of ['keydown', 'pointerdown', 'click', 'dblclick', 'wheel']) document.addEventListener(type, preventNavigation, { capture: true, passive: false })
|
|
22
|
+
}
|
|
23
|
+
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[] }
|
|
24
|
+
let generation = 0
|
|
25
|
+
let origin = 0
|
|
26
|
+
let schedule: Schedule
|
|
27
|
+
let visit = ''
|
|
28
|
+
let geometry: ReturnType<typeof geometryCollector> | undefined
|
|
29
|
+
const monitors = new Map<HTMLMediaElement, { timer: ReturnType<typeof setInterval>; item: ScheduledAction }>()
|
|
30
|
+
function stopMedia(element: HTMLMediaElement, completed: boolean) {
|
|
31
|
+
const monitor = monitors.get(element)
|
|
32
|
+
if (!monitor) return
|
|
33
|
+
clearInterval(monitor.timer); monitors.delete(element); element.pause()
|
|
34
|
+
if (completed) state.events.push({ id: `${monitor.item.id}:ended`, type: 'media-ended', scheduled_ms: monitor.item.end_ms, observed_ms: performance.now() - origin, media_ms: element.currentTime * 1000 })
|
|
35
|
+
}
|
|
36
|
+
const waits = new Map<ReturnType<typeof setTimeout>, () => void>()
|
|
37
|
+
const wait = (ms: number) => new Promise<void>(resolve => {
|
|
38
|
+
const timer = setTimeout(() => { waits.delete(timer); resolve() }, Math.max(0, ms))
|
|
39
|
+
waits.set(timer, resolve)
|
|
40
|
+
})
|
|
41
|
+
function clearWaits() { for (const [timer, resolve] of waits) { clearTimeout(timer); resolve() }; waits.clear() }
|
|
42
|
+
const painted = async () => {
|
|
43
|
+
await nextTick()
|
|
44
|
+
const first = await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
45
|
+
const second = await new Promise<number>(resolve => requestAnimationFrame(resolve))
|
|
46
|
+
return second - first
|
|
47
|
+
}
|
|
48
|
+
const media = (id: string) => {
|
|
49
|
+
const element = document.getElementById(id)
|
|
50
|
+
if (!(element instanceof HTMLMediaElement)) throw new Error(`Missing media ${id}`)
|
|
51
|
+
return element
|
|
52
|
+
}
|
|
53
|
+
async function navigate(index: number, click = 0) {
|
|
54
|
+
await nav.go(index, click, true); await painted()
|
|
55
|
+
const deadline = performance.now() + 10000
|
|
56
|
+
let waited = false
|
|
57
|
+
while (!document.querySelector(`#slide-content #slideshow > .slidev-page[data-slidev-no="${index}"]`)?.firstElementChild) {
|
|
58
|
+
if (performance.now() >= deadline) throw new Error(`Slide ${index} did not finish loading`)
|
|
59
|
+
waited = true; await wait(10)
|
|
60
|
+
}
|
|
61
|
+
if (waited) await painted()
|
|
62
|
+
}
|
|
63
|
+
function slideIndex(id: string) {
|
|
64
|
+
const slide = nav.slides.value.find(s => (s.meta.slide.frontmatter.name ?? `slide-${s.no}`) === id)
|
|
65
|
+
if (!slide) throw new Error(`Unknown slide ${id}`)
|
|
66
|
+
return slide.no
|
|
67
|
+
}
|
|
68
|
+
async function apply(item: ScheduledAction) {
|
|
69
|
+
for (const [element, monitor] of monitors) if (item.start_ms >= monitor.item.end_ms) stopMedia(element, true)
|
|
70
|
+
const action = item.action
|
|
71
|
+
if (action.type === 'slide') { await navigate(slideIndex(action.target)); visit = item.id }
|
|
72
|
+
if (action.type === 'reveal') {
|
|
73
|
+
if (action.click > nav.clicksTotal.value) throw new Error(`Unsupported reveal ${item.id}`)
|
|
74
|
+
await navigate(nav.currentSlideNo.value, action.click)
|
|
75
|
+
}
|
|
76
|
+
if (action.type === 'play') {
|
|
77
|
+
const element = media(action.media)
|
|
78
|
+
stopMedia(element, true)
|
|
79
|
+
element.currentTime = (action.trim_start_ms ?? 0) / 1000
|
|
80
|
+
element.playbackRate = action.rate ?? 1
|
|
81
|
+
element.muted = true
|
|
82
|
+
await element.play()
|
|
83
|
+
await painted()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function prepare(value: Schedule, expectedHashes: Record<string, string> = {}) {
|
|
87
|
+
generation++; clearWaits()
|
|
88
|
+
geometry?.stop(); geometry = undefined; visit = ''
|
|
89
|
+
for (const element of monitors.keys()) stopMedia(element, false)
|
|
90
|
+
state.phase = 'preparing'; state.events = []; state.markers = []; state.failure = ''; state.annotation_geometry = []; marker.value = ''
|
|
91
|
+
schedule = value
|
|
92
|
+
for (const slide of nav.slides.value) { await navigate(slide.no); }
|
|
93
|
+
await document.fonts.ready
|
|
94
|
+
for (const clip of schedule.media) {
|
|
95
|
+
const owner = nav.slides.value.find(slide => { const content = slide.meta.slide.content; return content.includes(`id="${clip.id}"`) || content.includes(`id='${clip.id}'`) })
|
|
96
|
+
if (!owner) throw new Error(`Missing media declaration ${clip.id}`)
|
|
97
|
+
await navigate(owner.no)
|
|
98
|
+
const deadline = performance.now() + 10000
|
|
99
|
+
while (!document.getElementById(clip.id) && performance.now() < deadline) await wait(20)
|
|
100
|
+
const element = media(clip.id)
|
|
101
|
+
if (expectedHashes[clip.id]) {
|
|
102
|
+
const response = await fetch(element.currentSrc || element.src)
|
|
103
|
+
if (!response.ok) throw new Error(`MEDIA_SOURCE_UNAVAILABLE ${clip.id}`)
|
|
104
|
+
const hash = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', await response.arrayBuffer())), value => value.toString(16).padStart(2, '0')).join('')
|
|
105
|
+
if (hash !== expectedHashes[clip.id]) throw new Error(`MEDIA_SOURCE_MISMATCH ${clip.id}`)
|
|
106
|
+
}
|
|
107
|
+
element.muted = true; element.pause(); element.currentTime = 0; element.playbackRate = 1
|
|
108
|
+
if (element.readyState < 3) await new Promise<void>((resolve, reject) => {
|
|
109
|
+
element.addEventListener('canplay', () => resolve(), { once: true })
|
|
110
|
+
element.addEventListener('error', () => reject(new Error(`Media cannot load ${clip.id}`)), { once: true })
|
|
111
|
+
setTimeout(() => reject(new Error(`Media readiness timeout ${clip.id}`)), 10000)
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
let selected = nav.slides.value[0]
|
|
115
|
+
for (const item of schedule.actions) {
|
|
116
|
+
if (item.action.type === 'slide') selected = nav.slides.value[slideIndex(item.action.target) - 1]
|
|
117
|
+
if (item.action.type === 'reveal' && item.action.click > nav.getPrimaryClicks(selected).total) throw new Error(`Unsupported reveal ${item.id}`)
|
|
118
|
+
}
|
|
119
|
+
await navigate(1)
|
|
120
|
+
state.phase = 'ready'
|
|
121
|
+
}
|
|
122
|
+
async function showMarker(color: string, current: number) {
|
|
123
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
124
|
+
marker.value = color; await nextTick()
|
|
125
|
+
const observed_ms = performance.now() - origin
|
|
126
|
+
const paint_interval_ms = await painted()
|
|
127
|
+
state.markers.push({ color, observed_ms, paint_interval_ms, rendered_by_ms: performance.now() - origin })
|
|
128
|
+
await wait(350)
|
|
129
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
130
|
+
}
|
|
131
|
+
async function play(verifyTiming = false) {
|
|
132
|
+
if (state.phase !== 'ready') throw new Error('Prepare playback first')
|
|
133
|
+
const current = generation
|
|
134
|
+
state.phase = 'recording'; origin = performance.now()
|
|
135
|
+
try {
|
|
136
|
+
await showMarker('#ff00ff', current)
|
|
137
|
+
if (verifyTiming) await showMarker('#00ffff', current)
|
|
138
|
+
await showMarker('#ffff00', current)
|
|
139
|
+
marker.value = ''; await painted();
|
|
140
|
+
const start = performance.now()
|
|
141
|
+
for (const event of state.markers) { event.observed_ms -= start - origin; event.rendered_by_ms -= start - origin }
|
|
142
|
+
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 })
|
|
144
|
+
for (const entry of playbackEntries(schedule)) {
|
|
145
|
+
while (performance.now() - origin < entry.at) await wait(entry.at - (performance.now() - origin))
|
|
146
|
+
if (current !== generation) throw new Error('Playback reset')
|
|
147
|
+
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 }
|
|
150
|
+
const item = entry.item
|
|
151
|
+
await apply(item)
|
|
152
|
+
const observed_ms = performance.now() - origin
|
|
153
|
+
if (verifyTiming && observed_ms - item.start_ms > 100) throw new Error(`Late action ${item.id}: ${observed_ms - item.start_ms} ms`)
|
|
154
|
+
state.events.push({ id: item.id, type: item.action.type, scheduled_ms: item.start_ms, observed_ms })
|
|
155
|
+
if (item.action.type === 'play') {
|
|
156
|
+
const action = item.action
|
|
157
|
+
const element = media(action.media)
|
|
158
|
+
const monitor = setInterval(() => {
|
|
159
|
+
if (generation !== current) { stopMedia(element, false); return }
|
|
160
|
+
const expected = (performance.now() - origin - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)
|
|
161
|
+
if (expected > (item.end_ms - item.start_ms) * (action.rate ?? 1) + (action.trim_start_ms ?? 0)) {
|
|
162
|
+
stopMedia(element, true)
|
|
163
|
+
} else if (Math.abs(element.currentTime * 1000 - expected) > 150) {
|
|
164
|
+
state.failure = `Media stall ${item.id}`; stopMedia(element, false)
|
|
165
|
+
}
|
|
166
|
+
}, 50)
|
|
167
|
+
monitors.set(element, { timer: monitor, item })
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
await wait(schedule.duration_ms - (performance.now() - origin))
|
|
171
|
+
for (const element of monitors.keys()) stopMedia(element, true)
|
|
172
|
+
if (state.failure) throw new Error(state.failure)
|
|
173
|
+
geometry?.complete(); geometry?.stop(); geometry = undefined
|
|
174
|
+
if (verifyTiming) { await showMarker('#00ff00', current); await showMarker('#ff0000', current); await showMarker('#0000ff', current) }
|
|
175
|
+
state.phase = 'completed'
|
|
176
|
+
} catch (error) { if (current !== generation) return; state.failure = String(error); state.phase = 'failed'; throw error }
|
|
177
|
+
finally { if (current === generation) { geometry?.stop(); geometry = undefined; for (const element of monitors.keys()) stopMedia(element, false) } }
|
|
178
|
+
}
|
|
179
|
+
async function inspectTargets(): Promise<PresentationInspection['annotation_targets']> {
|
|
180
|
+
const result: NonNullable<PresentationInspection['annotation_targets']> = []
|
|
181
|
+
await document.fonts.ready
|
|
182
|
+
for (const slide of nav.slides.value) {
|
|
183
|
+
const targets = new Map<string, string>()
|
|
184
|
+
await navigate(slide.no)
|
|
185
|
+
for (let click = 0; click <= nav.clicksTotal.value; click++) {
|
|
186
|
+
if (click) await navigate(slide.no, click)
|
|
187
|
+
for (const target of inspectAudienceTargets(slide.no)) if (!targets.has(target.identity)) targets.set(target.identity, `click ${click}; ${target.description}`)
|
|
188
|
+
}
|
|
189
|
+
result.push({ slide: String(slide.meta.slide.frontmatter.name ?? `slide-${slide.no}`), targets: [...targets].map(([identity, description]) => ({ identity, description })) })
|
|
190
|
+
}
|
|
191
|
+
await navigate(1)
|
|
192
|
+
return result
|
|
193
|
+
}
|
|
194
|
+
onUnmounted(() => {
|
|
195
|
+
generation++; clearWaits(); geometry?.stop(); preview?.dispose()
|
|
196
|
+
for (const element of monitors.keys()) stopMedia(element, false)
|
|
197
|
+
document.removeEventListener('play', silence, true); document.removeEventListener('volumechange', silence, true)
|
|
198
|
+
for (const type of ['keydown', 'pointerdown', 'click', 'dblclick', 'wheel']) document.removeEventListener(type, preventNavigation, true)
|
|
199
|
+
document.body.classList.remove('slidevideo-preview')
|
|
200
|
+
})
|
|
201
|
+
onMounted(async () => {
|
|
202
|
+
if (enabled) Object.assign(window, { __slidevideo: { version: 1, state, prepare, play, apply, navigate, media, inspectTargets } })
|
|
203
|
+
if (previewEnabled) {
|
|
204
|
+
document.body.classList.add('slidevideo-preview')
|
|
205
|
+
try {
|
|
206
|
+
const response = await fetch('/__slidevideo_preview')
|
|
207
|
+
if (!response.ok) throw new Error('Preview configuration is unavailable')
|
|
208
|
+
const config = await response.json()
|
|
209
|
+
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 })
|
|
211
|
+
window.__slidevideo.preview = preview
|
|
212
|
+
await preview.initialize()
|
|
213
|
+
} catch (error) {
|
|
214
|
+
state.failure = String(error); state.phase = 'failed'
|
|
215
|
+
const parentOrigin = document.referrer ? new URL(document.referrer).origin : location.origin
|
|
216
|
+
window.parent.postMessage({ type: 'slidevideo-preview-state', status: 'error', elapsedMs: 0, durationMs: 0, message: String(error) }, parentOrigin)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<template>
|
|
223
|
+
<Teleport to="body">
|
|
224
|
+
<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
|
+
</Teleport>
|
|
227
|
+
</template>
|
|
228
|
+
|
|
229
|
+
<style>
|
|
230
|
+
body.slidevideo-preview .slidev-nav-controls,
|
|
231
|
+
body.slidevideo-preview .slidev-nav { display: none !important; }
|
|
232
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "name": "slidev-addon-slidevideo", "version": "0.1.0", "private": true, "type": "module" }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
|
|
2
|
+
|
|
3
|
+
type PlaybackEntry = { at: number; order: number } & (
|
|
4
|
+
{ type: 'action'; item: ScheduledAction } |
|
|
5
|
+
{ type: 'start' | 'end'; annotation: ResolvedAnnotation }
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
export function playbackEntries(schedule: Schedule): PlaybackEntry[] {
|
|
9
|
+
const entries: PlaybackEntry[] = schedule.actions.map(item => ({ at: item.start_ms, order: 1, type: 'action', item }))
|
|
10
|
+
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 })
|
|
12
|
+
}
|
|
13
|
+
return entries.sort((a, b) => a.at - b.at || a.order - b.order)
|
|
14
|
+
}
|