@slidevideo/cli 0.3.0 → 0.3.2
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 +20 -0
- package/README.md +3 -3
- package/addons/slidevideo/geometry.ts +334 -1
- package/addons/slidevideo/global-top.vue +57 -6
- 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/edge.d.ts +1 -0
- package/dist/adapters/edge.js +4 -3
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +4 -3
- package/dist/adapters/powerpoint-preview.d.ts +1 -1
- package/dist/adapters/powerpoint-preview.js +13 -2
- package/dist/adapters/powerpoint.js +91 -14
- package/dist/adapters/slidev-inspection.js +7 -2
- 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/assembly.js +143 -37
- package/dist/captions.d.ts +6 -0
- package/dist/captions.js +320 -0
- package/dist/cli.js +59 -19
- package/dist/compositor.d.ts +17 -2
- package/dist/compositor.js +108 -26
- package/dist/contracts.d.ts +254 -14
- package/dist/media.js +24 -1
- package/dist/pipeline.d.ts +6 -1
- package/dist/pipeline.js +68 -20
- package/dist/preview/contracts.d.ts +15 -0
- package/dist/preview/player.js +527 -34
- package/dist/preview/server.d.ts +1 -1
- package/dist/preview/server.js +125 -4
- 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 +13 -3
- package/dist/speech.js +164 -45
- 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 +4 -1
- package/dist/timing.js +322 -14
- package/dist/update-check-worker.js +43 -11
- package/dist/update-check.js +14 -10
- package/package.json +12 -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 +155 -6
- package/tools/powerpoint/preview.ps1 +68 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.3.2
|
|
6
|
+
|
|
7
|
+
- Render the free-tier `slidevideo.io` export watermark in bundled Plus Jakarta Sans with adaptive dark-or-light ink based on corner brightness so it stays crisp and transparent on bright and dark slides alike.
|
|
8
|
+
- Check `slidevideo.io/release.json` (with an npm registry fallback) during the 24-hour background update check and honor `DO_NOT_TRACK=1` alongside `SLIDEVIDEO_NO_UPDATE_CHECK=1`.
|
|
9
|
+
- Replace per-segment FFmpeg `adelay`/`amix` narration fan-out in assembly with sequential PCM audio placement so open inputs and memory stay bounded on long storyboards.
|
|
10
|
+
- Bound concurrent TTS synthesis requests per provider, stream-count PCM bytes in `audioDuration` without retaining audio buffers, and skip redundant speech decode passes within a single run.
|
|
11
|
+
- Estimate approximate character-proportional phrase-cue and `follow` timing in `slidevideo play` for uncached segments while clearly labeling approximate cues in CLI, `--json`, and browser status output.
|
|
12
|
+
|
|
13
|
+
## 0.3.1
|
|
14
|
+
|
|
15
|
+
- Export speech-aligned `final.vtt` and `final.srt` captions by default on narrated `build` and `assemble` runs, with `--captions <vtt|srt|both|none>` to configure or export during `resolve`.
|
|
16
|
+
- Add storyboard-controlled `stamp` annotations with bundled reproducible fonts, vector symbols (`check`, `cross`, `warning`, `star`, `info`, `arrow-right`), target/point anchoring, multiline layout and overflow checks, optional rotation, and `fade` or `pop` motion for Slidev and PowerPoint.
|
|
17
|
+
- Make `--run` optional for `build` (without `--resume`) and `tts`, defaulting to a timestamped directory under `runs/` and reporting `run_dir` in CLI output.
|
|
18
|
+
- Default speech caching in `build`, `tts`, and `play` to `.slidevideo/speech` beside the storyboard, with `--cache-dir` to override and `--no-cache` to disable.
|
|
19
|
+
- Add storyboard-controlled `laser` pointer annotations with normalized or target-anchored paths, linear or smooth Catmull-Rom interpolation, waypoint dwell, glow, decaying trails, and fade transitions for Slidev and PowerPoint.
|
|
20
|
+
- Add storyboard-controlled `zoom` annotations with target fitting, padding, scale limits, smooth ease-in/hold/ease-out transitions, locked slide-attached annotations, and frame-fixed overlays for Slidev and PowerPoint.
|
|
21
|
+
- Add storyboard-controlled `spotlight` annotations with rounded-rectangle or elliptical apertures, optional edge softness and fades, and unified multi-spotlight compositing for Slidev and PowerPoint.
|
|
22
|
+
- Add declarative text-range targets (`type: text`) and narration-aligned word-following annotations (`follow`) for Slidev and PowerPoint.
|
|
23
|
+
- Add timeline scrubbing, scene jumping, and cached narration audio playback with mute/unmute to `slidevideo play`.
|
|
24
|
+
|
|
5
25
|
## 0.3.0
|
|
6
26
|
|
|
7
27
|
- Speed up normal Slidev and PowerPoint recording by compressing static slide holds while keeping dynamic slides and `--verify-timing` at `1.0x`.
|
package/README.md
CHANGED
|
@@ -13,14 +13,14 @@ Setup prepares shared tools, checks both speech providers, and detects Slidev an
|
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
15
|
slidevideo validate --storyboard slidevideo.yaml
|
|
16
|
-
slidevideo build --storyboard slidevideo.yaml
|
|
16
|
+
slidevideo build --storyboard slidevideo.yaml
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
A completed build writes `
|
|
19
|
+
A completed build writes `final.mp4` (plus `final.vtt` and `final.srt` captions for narrated decks) inside a fresh `runs/<timestamp>` directory (or the path passed to `--run`) at `1920x1080` and `30 fps` by default, and caches generated speech in `.slidevideo/speech` beside the storyboard for reuse across runs (override with `--cache-dir` or disable with `--no-cache`). Pass `--width` and `--height` together and optional `--fps` to select another resolution or frame rate, and `--captions <vtt|srt|both|none>` to control subtitle export. Use `slidevideo setup --license` to activate a key. The installed version checks its bundled revocation list offline. New exports using a revoked key include the watermark.
|
|
20
20
|
|
|
21
21
|
To draft or edit a storyboard with a coding agent, run `slidevideo skill --install` to link the bundled skill into `~/.agents/skills/slidevideo` and `~/.claude/skills/slidevideo` when Claude Code is detected, or ask the agent to run `slidevideo skill`. For non-interactive setup, run `slidevideo setup --install --json` and see `slidevideo setup --help` and `slidevideo skill --help` for provider and project flags. Use `slidevideo inspect --deck <file> --json` to list slide names, click counts, media IDs, and highlight targets before creating `slidevideo.yaml`. The CLI includes the skill and its storyboard, deck-compatibility, and recording references.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
CLI commands check `https://slidevideo.io/release.json` (falling back to npm) in the background at most once every 24 hours and show cached update notices on later interactive calls. Stable installations use `latest`; existing alpha installations use `alpha`. Notices include an exact-version upgrade command. If you installed with `--prefix`, add the same `--prefix` option to that command so npm updates the copy on your `PATH`. Set `SLIDEVIDEO_NO_UPDATE_CHECK=1` or `DO_NOT_TRACK=1` to disable checks and notices. CI, `--version`, `--help`, `setup --manual`, read-only `skill` views, `license`, and `impressum` skip both, and `--json` and `--quiet` suppress notices.
|
|
24
24
|
|
|
25
25
|
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.
|
|
26
26
|
|
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import type { AnnotationGeometry, GeometryRequest, Rectangle } from '../../dist/contracts.js'
|
|
1
|
+
import type { AnnotationGeometry, GeometryRequest, Rectangle, ResolvedTextTarget } from '../../dist/contracts.js'
|
|
2
2
|
|
|
3
3
|
type PlaybackPosition = { slide: string; visit: string; click: number; index: number }
|
|
4
4
|
type Measurement = { fragments: Rectangle[]; content: Rectangle; slide: Rectangle; viewport: { width: number; height: number }; elements: Element[] }
|
|
5
|
+
type DomCharSpan = { startNode: Text; startOffset: number; endNode: Text; endOffset: number }
|
|
6
|
+
const INLINE_FLOW_DISPLAY = new Set([
|
|
7
|
+
'inline',
|
|
8
|
+
'contents',
|
|
9
|
+
'ruby',
|
|
10
|
+
'ruby-base',
|
|
11
|
+
'ruby-text',
|
|
12
|
+
'ruby-base-container',
|
|
13
|
+
'ruby-text-container',
|
|
14
|
+
])
|
|
15
|
+
const ATOMIC_INLINE_DISPLAY = new Set([
|
|
16
|
+
'inline-block',
|
|
17
|
+
'inline-flex',
|
|
18
|
+
'inline-grid',
|
|
19
|
+
'inline-table',
|
|
20
|
+
])
|
|
5
21
|
const rectangle = (rect: DOMRect): Rectangle => ({ x: rect.x, y: rect.y, width: rect.width, height: rect.height })
|
|
22
|
+
function isElementVisible(element: Element): boolean {
|
|
23
|
+
const style = getComputedStyle(element)
|
|
24
|
+
if (style.display === 'none' || style.visibility !== 'visible' || Number(style.opacity) === 0) return false
|
|
25
|
+
if (style.display === 'contents') return element.parentElement ? isElementVisible(element.parentElement) : true
|
|
26
|
+
return element.checkVisibility({ opacityProperty: true, visibilityProperty: true })
|
|
27
|
+
}
|
|
6
28
|
function axisAligned(element: Element) {
|
|
7
29
|
const style = getComputedStyle(element)
|
|
8
30
|
if (style.clipPath !== 'none' || style.maskImage !== 'none' || style.clip !== 'auto') throw new Error('Clipped or masked targets are unsupported')
|
|
@@ -46,6 +68,311 @@ function visibleBounds(element: Element, content: HTMLElement): Rectangle {
|
|
|
46
68
|
}
|
|
47
69
|
return bounds
|
|
48
70
|
}
|
|
71
|
+
function checkTextAncestors(element: Element, bounds: Rectangle, content: HTMLElement, contentRect: Rectangle) {
|
|
72
|
+
if (!isElementVisible(element)) throw new Error('Target is hidden')
|
|
73
|
+
if (!(bounds.width > 0 && bounds.height > 0)) throw new Error('Target has empty bounds')
|
|
74
|
+
if (!within(bounds, contentRect)) throw new Error('Target is clipped by the slide-content rectangle')
|
|
75
|
+
for (let ancestor: Element | null = element; ancestor; ancestor = ancestor.parentElement) {
|
|
76
|
+
if (ancestor instanceof SVGGElement) throw new Error('Grouped SVG targets are unsupported')
|
|
77
|
+
const style = getComputedStyle(ancestor)
|
|
78
|
+
if (style.display !== 'contents') {
|
|
79
|
+
axisAligned(ancestor)
|
|
80
|
+
if (/(hidden|clip|scroll|auto)/.test(`${style.overflowX} ${style.overflowY}`)) {
|
|
81
|
+
const clip = rectangle(ancestor.getBoundingClientRect())
|
|
82
|
+
if (ancestor instanceof HTMLElement && ancestor.offsetWidth && ancestor.offsetHeight) {
|
|
83
|
+
const scaleX = clip.width / ancestor.offsetWidth, scaleY = clip.height / ancestor.offsetHeight
|
|
84
|
+
clip.x += ancestor.clientLeft * scaleX; clip.y += ancestor.clientTop * scaleY
|
|
85
|
+
clip.width = ancestor.clientWidth * scaleX; clip.height = ancestor.clientHeight * scaleY
|
|
86
|
+
}
|
|
87
|
+
if (!within(bounds, clip)) throw new Error('Target is clipped by an ancestor')
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (ancestor === content) break
|
|
91
|
+
}
|
|
92
|
+
if (element instanceof SVGGraphicsElement) {
|
|
93
|
+
const matrix = element.getScreenCTM()
|
|
94
|
+
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')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const SMALL_KANA_MAP: Record<string, string> = {
|
|
98
|
+
ぁ: 'あ', ぃ: 'い', ぅ: 'う', ぇ: 'え', ぉ: 'お', っ: 'つ', ゃ: 'や', ゅ: 'ゆ', ょ: 'よ', ゎ: 'わ', ゕ: 'か', ゖ: 'け',
|
|
99
|
+
ァ: 'ア', ィ: 'イ', ゥ: 'ウ', ェ: 'エ', ォ: 'オ', ッ: 'ツ', ャ: 'ヤ', ュ: 'ユ', ョ: 'ヨ', ヮ: 'ワ', ヵ: 'カ', ヶ: 'ケ',
|
|
100
|
+
ァ: 'ア', ィ: 'イ', ゥ: 'ウ', ェ: 'エ', ォ: 'オ', ッ: 'ツ', ャ: 'ヤ', ュ: 'ユ', ョ: 'ヨ',
|
|
101
|
+
}
|
|
102
|
+
type CaseMode = 'none' | 'uppercase' | 'lowercase' | 'capitalize'
|
|
103
|
+
type ParsedTextTransform = { caseMode: CaseMode; fullWidth: boolean; fullSizeKana: boolean; lang: string | undefined }
|
|
104
|
+
function effectiveLang(element: Element): string | undefined {
|
|
105
|
+
for (let el: Element | null = element; el; el = el.parentElement) {
|
|
106
|
+
const lang = el.getAttribute('lang') || el.getAttribute('xml:lang')
|
|
107
|
+
if (lang) return lang
|
|
108
|
+
}
|
|
109
|
+
return undefined
|
|
110
|
+
}
|
|
111
|
+
function parseTextTransform(textTransform: string, element: Element): ParsedTextTransform {
|
|
112
|
+
if (!textTransform || textTransform === 'none') {
|
|
113
|
+
return { caseMode: 'none', fullWidth: false, fullSizeKana: false, lang: undefined }
|
|
114
|
+
}
|
|
115
|
+
const tokens = new Set(textTransform.trim().split(/\s+/))
|
|
116
|
+
const caseMode: CaseMode = tokens.has('uppercase')
|
|
117
|
+
? 'uppercase'
|
|
118
|
+
: tokens.has('lowercase')
|
|
119
|
+
? 'lowercase'
|
|
120
|
+
: tokens.has('capitalize')
|
|
121
|
+
? 'capitalize'
|
|
122
|
+
: 'none'
|
|
123
|
+
const fullWidth = tokens.has('full-width')
|
|
124
|
+
const fullSizeKana = tokens.has('full-size-kana')
|
|
125
|
+
const lang = caseMode !== 'none' ? effectiveLang(element) : undefined
|
|
126
|
+
return { caseMode, fullWidth, fullSizeKana, lang }
|
|
127
|
+
}
|
|
128
|
+
function caseString(value: string, mode: 'uppercase' | 'lowercase', lang: string | undefined): string {
|
|
129
|
+
if (mode === 'uppercase') {
|
|
130
|
+
try { return lang ? value.toLocaleUpperCase(lang) : value.toUpperCase() } catch { return value.toUpperCase() }
|
|
131
|
+
}
|
|
132
|
+
try { return lang ? value.toLocaleLowerCase(lang) : value.toLowerCase() } catch { return value.toLowerCase() }
|
|
133
|
+
}
|
|
134
|
+
function graphemeSegmenter(lang: string | undefined): Intl.Segmenter {
|
|
135
|
+
try { return new Intl.Segmenter(lang || undefined, { granularity: 'grapheme' }) }
|
|
136
|
+
catch { return new Intl.Segmenter(undefined, { granularity: 'grapheme' }) }
|
|
137
|
+
}
|
|
138
|
+
function wordStartOffsets(fullRaw: string, lang: string | undefined): Set<number> {
|
|
139
|
+
let segmenter: Intl.Segmenter
|
|
140
|
+
try { segmenter = new Intl.Segmenter(lang || undefined, { granularity: 'word' }) }
|
|
141
|
+
catch { segmenter = new Intl.Segmenter(undefined, { granularity: 'word' }) }
|
|
142
|
+
const starts = new Set<number>()
|
|
143
|
+
for (const seg of segmenter.segment(fullRaw)) {
|
|
144
|
+
if (seg.isWordLike) starts.add(seg.index)
|
|
145
|
+
}
|
|
146
|
+
return starts
|
|
147
|
+
}
|
|
148
|
+
function extractNormalizedText(root: Element): { text: string; map: DomCharSpan[] } {
|
|
149
|
+
let text = ''
|
|
150
|
+
const map: DomCharSpan[] = []
|
|
151
|
+
let lastNode: Text | undefined
|
|
152
|
+
let lastOffset = 0
|
|
153
|
+
type SourceChar = { node: Text; offset: number; style: ParsedTextTransform }
|
|
154
|
+
let currentRunRaw = ''
|
|
155
|
+
let currentRunMap: SourceChar[] = []
|
|
156
|
+
function flushRun() {
|
|
157
|
+
if (!currentRunRaw) return
|
|
158
|
+
const fullRaw = currentRunRaw
|
|
159
|
+
const sourceMap = currentRunMap
|
|
160
|
+
currentRunRaw = ''
|
|
161
|
+
currentRunMap = []
|
|
162
|
+
const casedCache = new Map<string, string>()
|
|
163
|
+
const wordStartsCache = new Map<string, Set<number>>()
|
|
164
|
+
const getCasedFull = (mode: 'uppercase' | 'lowercase', lang: string | undefined) => {
|
|
165
|
+
const key = `${mode}\0${lang ?? ''}`
|
|
166
|
+
let cached = casedCache.get(key)
|
|
167
|
+
if (cached === undefined) {
|
|
168
|
+
cached = caseString(fullRaw, mode, lang)
|
|
169
|
+
casedCache.set(key, cached)
|
|
170
|
+
}
|
|
171
|
+
return cached
|
|
172
|
+
}
|
|
173
|
+
const getWordStarts = (lang: string | undefined) => {
|
|
174
|
+
const key = lang ?? ''
|
|
175
|
+
let cached = wordStartsCache.get(key)
|
|
176
|
+
if (!cached) {
|
|
177
|
+
cached = wordStartOffsets(fullRaw, lang)
|
|
178
|
+
wordStartsCache.set(key, cached)
|
|
179
|
+
}
|
|
180
|
+
return cached
|
|
181
|
+
}
|
|
182
|
+
const casedBoundary = (pos: number, fullCased: string, mode: 'uppercase' | 'lowercase', lang: string | undefined) => {
|
|
183
|
+
if (pos <= 0) return 0
|
|
184
|
+
if (pos >= fullRaw.length) return fullCased.length
|
|
185
|
+
if (fullCased.length === fullRaw.length) return pos
|
|
186
|
+
const probe = fullRaw.slice(0, pos) + (/^\p{L}/u.test(fullRaw.slice(pos)) ? 'a' : ' ')
|
|
187
|
+
return caseString(probe, mode, lang).length - 1
|
|
188
|
+
}
|
|
189
|
+
for (const g of graphemeSegmenter(sourceMap[0].style.lang).segment(fullRaw)) {
|
|
190
|
+
const gStart = g.index
|
|
191
|
+
const gEnd = g.index + g.segment.length
|
|
192
|
+
const startSrc = sourceMap[gStart]
|
|
193
|
+
const endSrc = sourceMap[gEnd - 1]
|
|
194
|
+
const { caseMode, fullWidth, fullSizeKana, lang } = startSrc.style
|
|
195
|
+
let rendered = g.segment
|
|
196
|
+
if (caseMode === 'uppercase' || caseMode === 'lowercase') {
|
|
197
|
+
const fullCased = getCasedFull(caseMode, lang)
|
|
198
|
+
rendered = fullCased.slice(casedBoundary(gStart, fullCased, caseMode, lang), casedBoundary(gEnd, fullCased, caseMode, lang))
|
|
199
|
+
} else if (caseMode === 'capitalize' && getWordStarts(lang).has(gStart) && /^\p{L}/u.test(rendered)) {
|
|
200
|
+
const firstCp = rendered.codePointAt(0)!
|
|
201
|
+
const firstLen = firstCp > 0xFFFF ? 2 : 1
|
|
202
|
+
rendered = caseString(rendered.slice(0, firstLen), 'uppercase', lang) + rendered.slice(firstLen)
|
|
203
|
+
}
|
|
204
|
+
if (fullSizeKana) {
|
|
205
|
+
let kanaOut = ''
|
|
206
|
+
for (const ch of rendered) kanaOut += SMALL_KANA_MAP[ch] ?? ch
|
|
207
|
+
rendered = kanaOut
|
|
208
|
+
}
|
|
209
|
+
if (fullWidth) {
|
|
210
|
+
let fwOut = ''
|
|
211
|
+
for (const ch of rendered) {
|
|
212
|
+
const cp = ch.codePointAt(0)!
|
|
213
|
+
if (cp === 0x20) fwOut += '\u3000'
|
|
214
|
+
else if (cp >= 0x21 && cp <= 0x7E) fwOut += String.fromCodePoint(cp + 0xFEE0)
|
|
215
|
+
else fwOut += ch
|
|
216
|
+
}
|
|
217
|
+
rendered = fwOut
|
|
218
|
+
}
|
|
219
|
+
if (/^\s+$/.test(rendered)) {
|
|
220
|
+
if (text.length > 0) {
|
|
221
|
+
if (text[text.length - 1] !== ' ') {
|
|
222
|
+
text += ' '
|
|
223
|
+
map.push({ startNode: startSrc.node, startOffset: startSrc.offset, endNode: endSrc.node, endOffset: endSrc.offset + 1 })
|
|
224
|
+
} else {
|
|
225
|
+
const prev = map[map.length - 1]
|
|
226
|
+
prev.endNode = endSrc.node
|
|
227
|
+
prev.endOffset = endSrc.offset + 1
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
for (let u = 0; u < rendered.length; u++) {
|
|
232
|
+
text += rendered[u]
|
|
233
|
+
map.push({ startNode: startSrc.node, startOffset: startSrc.offset, endNode: endSrc.node, endOffset: endSrc.offset + 1 })
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function pushSeparator() {
|
|
239
|
+
flushRun()
|
|
240
|
+
if (lastNode && text.length > 0 && text[text.length - 1] !== ' ') {
|
|
241
|
+
text += ' '
|
|
242
|
+
map.push({ startNode: lastNode, startOffset: lastOffset, endNode: lastNode, endOffset: lastOffset })
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function walk(node: Node) {
|
|
246
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
247
|
+
const textNode = node as Text
|
|
248
|
+
const data = textNode.data
|
|
249
|
+
if (!data) return
|
|
250
|
+
const parent = textNode.parentElement
|
|
251
|
+
if (!parent || !isElementVisible(parent)) return
|
|
252
|
+
const style = parseTextTransform(getComputedStyle(parent).textTransform, parent)
|
|
253
|
+
currentRunRaw += data
|
|
254
|
+
for (let i = 0; i < data.length; i++) {
|
|
255
|
+
currentRunMap.push({ node: textNode, offset: i, style })
|
|
256
|
+
}
|
|
257
|
+
lastNode = textNode
|
|
258
|
+
lastOffset = data.length
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return
|
|
262
|
+
const el = node as Element
|
|
263
|
+
if (el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || el.tagName === 'NOSCRIPT' || el.tagName === 'TEMPLATE') return
|
|
264
|
+
if (!isElementVisible(el)) return
|
|
265
|
+
if (el.tagName === 'BR') { pushSeparator(); return }
|
|
266
|
+
const style = getComputedStyle(el)
|
|
267
|
+
const display = style.display
|
|
268
|
+
const breaksFlow = !INLINE_FLOW_DISPLAY.has(display) && !ATOMIC_INLINE_DISPLAY.has(display)
|
|
269
|
+
const atomicPadLeft = ATOMIC_INLINE_DISPLAY.has(display) &&
|
|
270
|
+
(parseFloat(style.marginLeft) + parseFloat(style.borderLeftWidth) + parseFloat(style.paddingLeft) > 0.5)
|
|
271
|
+
const atomicPadRight = ATOMIC_INLINE_DISPLAY.has(display) &&
|
|
272
|
+
(parseFloat(style.marginRight) + parseFloat(style.borderRightWidth) + parseFloat(style.paddingRight) > 0.5)
|
|
273
|
+
if (breaksFlow || atomicPadLeft) pushSeparator()
|
|
274
|
+
for (let child = el.firstChild; child; child = child.nextSibling) walk(child)
|
|
275
|
+
if (breaksFlow || atomicPadRight) pushSeparator()
|
|
276
|
+
}
|
|
277
|
+
walk(root)
|
|
278
|
+
flushRun()
|
|
279
|
+
if (text.endsWith(' ')) {
|
|
280
|
+
text = text.slice(0, -1)
|
|
281
|
+
map.pop()
|
|
282
|
+
}
|
|
283
|
+
return { text, map }
|
|
284
|
+
}
|
|
285
|
+
function measureTextTarget(target: ResolvedTextTarget, slide: HTMLElement, content: HTMLElement, contentRect: Rectangle): { fragments: Rectangle[]; elements: Element[] } {
|
|
286
|
+
if (target.container?.type === 'shape') throw new Error('PowerPoint shape targets are unsupported by Slidev')
|
|
287
|
+
let root: Element = slide
|
|
288
|
+
if (target.container?.type === 'element') {
|
|
289
|
+
const candidates = slide.querySelectorAll(target.container.selector)
|
|
290
|
+
if (candidates.length !== 1) throw new Error(`Selector ${JSON.stringify(target.container.selector)} matched ${candidates.length} elements in the active audience slide`)
|
|
291
|
+
root = candidates[0]
|
|
292
|
+
if (!isElementVisible(root)) throw new Error('Target container is hidden')
|
|
293
|
+
}
|
|
294
|
+
const needle = target.text.trim().replace(/\s+/g, ' ')
|
|
295
|
+
if (!needle) throw new Error('Text target cannot be empty')
|
|
296
|
+
const { text, map } = extractNormalizedText(root)
|
|
297
|
+
const matches: number[] = []
|
|
298
|
+
let pos = text.indexOf(needle)
|
|
299
|
+
while (pos >= 0) {
|
|
300
|
+
matches.push(pos)
|
|
301
|
+
pos = text.indexOf(needle, pos + 1)
|
|
302
|
+
}
|
|
303
|
+
if (matches.length === 0) throw new Error(`Text ${JSON.stringify(needle)} was not found in the active audience slide`)
|
|
304
|
+
if (target.occurrence === undefined && matches.length > 1) throw new Error(`Text ${JSON.stringify(needle)} matched ${matches.length} times; specify container or occurrence`)
|
|
305
|
+
const matchPos = matches[(target.occurrence ?? 1) - 1]
|
|
306
|
+
if (matchPos === undefined) throw new Error(`Text ${JSON.stringify(needle)} occurrence ${target.occurrence} does not exist (matched ${matches.length})`)
|
|
307
|
+
let startIdx = matchPos + (target.slice?.start ?? 0)
|
|
308
|
+
let endIdx = matchPos + (target.slice?.end ?? needle.length)
|
|
309
|
+
while (startIdx < endIdx && text[startIdx] === ' ') startIdx++
|
|
310
|
+
while (endIdx > startIdx && text[endIdx - 1] === ' ') endIdx--
|
|
311
|
+
if (startIdx >= endIdx || endIdx > map.length) throw new Error(`Text slice for ${JSON.stringify(needle)} is empty or out of bounds`)
|
|
312
|
+
type NodeRun = { node: Text; start: number; end: number; parent: Element }
|
|
313
|
+
const runs: NodeRun[] = []
|
|
314
|
+
const addNodeSlice = (node: Text, start: number, end: number) => {
|
|
315
|
+
if (start >= end) return
|
|
316
|
+
const parent = node.parentElement
|
|
317
|
+
if (!parent) throw new Error('Target text node is detached')
|
|
318
|
+
const prev = runs.at(-1)
|
|
319
|
+
if (prev && prev.node === node && end >= prev.end) {
|
|
320
|
+
prev.end = Math.max(prev.end, end)
|
|
321
|
+
} else {
|
|
322
|
+
runs.push({ node, start, end, parent })
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
326
|
+
const span = map[i]
|
|
327
|
+
if (span.startNode === span.endNode) {
|
|
328
|
+
addNodeSlice(span.startNode, span.startOffset, span.endOffset)
|
|
329
|
+
} else if (text[i] !== ' ') {
|
|
330
|
+
addNodeSlice(span.startNode, span.startOffset, span.startNode.data.length)
|
|
331
|
+
addNodeSlice(span.endNode, 0, span.endOffset)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const rawRects: Rectangle[] = []
|
|
335
|
+
const elements: Element[] = []
|
|
336
|
+
const seen = new Set<Element>()
|
|
337
|
+
const subRange = document.createRange()
|
|
338
|
+
for (const run of runs) {
|
|
339
|
+
subRange.setStart(run.node, run.start)
|
|
340
|
+
subRange.setEnd(run.node, run.end)
|
|
341
|
+
const rects = [...subRange.getClientRects()].filter(r => r.width > 0.05 && r.height > 0.05).map(rectangle)
|
|
342
|
+
if (rects.length > 0 && !seen.has(run.parent)) {
|
|
343
|
+
seen.add(run.parent)
|
|
344
|
+
elements.push(run.parent)
|
|
345
|
+
}
|
|
346
|
+
for (const rect of rects) {
|
|
347
|
+
checkTextAncestors(run.parent, rect, content, contentRect)
|
|
348
|
+
rawRects.push(rect)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (rawRects.length === 0) throw new Error(`Text ${JSON.stringify(needle)} has empty rendered bounds`)
|
|
352
|
+
const mergedLines: Rectangle[] = []
|
|
353
|
+
for (const rect of rawRects) {
|
|
354
|
+
const prev = mergedLines.at(-1)
|
|
355
|
+
if (prev) {
|
|
356
|
+
const overlapY = Math.min(prev.y + prev.height, rect.y + rect.height) - Math.max(prev.y, rect.y)
|
|
357
|
+
if (overlapY > 0.5 * Math.min(prev.height, rect.height)) {
|
|
358
|
+
const left = Math.min(prev.x, rect.x)
|
|
359
|
+
const top = Math.min(prev.y, rect.y)
|
|
360
|
+
const right = Math.max(prev.x + prev.width, rect.x + rect.width)
|
|
361
|
+
const bottom = Math.max(prev.y + prev.height, rect.y + rect.height)
|
|
362
|
+
prev.x = left; prev.y = top; prev.width = right - left; prev.height = bottom - top
|
|
363
|
+
continue
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
mergedLines.push({ ...rect })
|
|
367
|
+
}
|
|
368
|
+
const fragments = mergedLines.map(rect => ({
|
|
369
|
+
x: (rect.x - contentRect.x) / contentRect.width,
|
|
370
|
+
y: (rect.y - contentRect.y) / contentRect.height,
|
|
371
|
+
width: rect.width / contentRect.width,
|
|
372
|
+
height: rect.height / contentRect.height,
|
|
373
|
+
}))
|
|
374
|
+
return { fragments, elements }
|
|
375
|
+
}
|
|
49
376
|
function measure(request: GeometryRequest, position: PlaybackPosition): Measurement {
|
|
50
377
|
if (position.slide !== request.slide || position.visit !== request.visit || position.click !== request.click) throw new Error('Slide visit or reveal state changed')
|
|
51
378
|
const { content, slide } = audience(position.index)
|
|
@@ -78,6 +405,12 @@ function measure(request: GeometryRequest, position: PlaybackPosition): Measurem
|
|
|
78
405
|
}
|
|
79
406
|
case 'shape':
|
|
80
407
|
throw new Error('PowerPoint shape targets are unsupported by Slidev')
|
|
408
|
+
case 'text': {
|
|
409
|
+
const measured = measureTextTarget(request.target, slide, content, contentRect)
|
|
410
|
+
fragments = measured.fragments
|
|
411
|
+
elements = measured.elements
|
|
412
|
+
break
|
|
413
|
+
}
|
|
81
414
|
}
|
|
82
415
|
return { fragments, content: contentRect, slide: rectangle(slide.getBoundingClientRect()), viewport: { width: innerWidth, height: innerHeight }, elements }
|
|
83
416
|
}
|
|
@@ -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
|
|
@@ -461,6 +494,7 @@ async function inspectTargets(): Promise<PresentationInspection['annotation_targ
|
|
|
461
494
|
}
|
|
462
495
|
onUnmounted(() => {
|
|
463
496
|
generation++; clearWaits(); geometry?.stop(); preview?.dispose()
|
|
497
|
+
postPreviewView(undefined)
|
|
464
498
|
previewCanvases.splice(0).forEach(canvas => canvas.remove())
|
|
465
499
|
for (const element of monitors.keys()) stopMedia(element, false)
|
|
466
500
|
document.removeEventListener('play', silence, true); document.removeEventListener('volumechange', silence, true)
|
|
@@ -475,8 +509,25 @@ onMounted(async () => {
|
|
|
475
509
|
const response = await fetch('/__slidevideo_preview')
|
|
476
510
|
if (!response.ok) throw new Error('Preview configuration is unavailable')
|
|
477
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 {}
|
|
478
529
|
const { createPreview } = await import('./preview')
|
|
479
|
-
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)
|
|
480
531
|
window.__slidevideo.preview = preview
|
|
481
532
|
await preview.initialize()
|
|
482
533
|
} catch (error) {
|