@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
package/dist/preview/player.js
CHANGED
|
@@ -1,29 +1,219 @@
|
|
|
1
|
-
import { annotationPaint, paintEffects, targetKey, underlineFragmentsVisible } from '../annotation-paint.js';
|
|
1
|
+
import { activeViewTransform, annotationPaint, hasActiveSpotlight, laserPaint, laserVisible, paintEffects, spotlightAperturesVisible, stampPaint, stampVisible, targetKey, underlineFragmentsVisible, zoomTransformVisible } from '../annotation-paint.js';
|
|
2
2
|
const labels = { loading: 'Loading presentation…', ready: 'Ready', playing: 'Playing', paused: 'Paused', ended: 'Finished', error: 'Playback failed' };
|
|
3
3
|
const stage = document.querySelector('#stage');
|
|
4
4
|
const status = document.querySelector('#status');
|
|
5
5
|
const clock = document.querySelector('#clock');
|
|
6
|
-
const
|
|
6
|
+
const timeline = document.querySelector('#timeline');
|
|
7
|
+
const timelineFill = document.querySelector('#timeline-fill');
|
|
8
|
+
const timelineThumb = document.querySelector('#timeline-thumb');
|
|
9
|
+
const timelineMarkers = document.querySelector('#timeline-markers');
|
|
7
10
|
const play = document.querySelector('#play');
|
|
8
11
|
const pause = document.querySelector('#pause');
|
|
9
12
|
const restart = document.querySelector('#restart');
|
|
13
|
+
const mute = document.querySelector('#mute');
|
|
14
|
+
const sceneSelect = document.querySelector('#scene');
|
|
15
|
+
let durationMs = 1;
|
|
16
|
+
let currentState = 'loading';
|
|
17
|
+
let anchorElapsedMs = 0;
|
|
18
|
+
let anchorTime = performance.now();
|
|
19
|
+
let dragging = false;
|
|
20
|
+
let activeSeekId = 0;
|
|
21
|
+
let confirmedSeekId = 0;
|
|
22
|
+
let forceAudioAlign = false;
|
|
23
|
+
let scenes = [];
|
|
24
|
+
let markerButtons = [];
|
|
25
|
+
let audioSync;
|
|
26
|
+
let rafId = 0;
|
|
10
27
|
function time(ms) {
|
|
11
|
-
const seconds = Math.floor(ms / 1000);
|
|
28
|
+
const seconds = Math.floor(Math.max(0, ms) / 1000);
|
|
12
29
|
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
|
|
13
30
|
}
|
|
14
|
-
function
|
|
31
|
+
function seekPending() {
|
|
32
|
+
return confirmedSeekId < activeSeekId;
|
|
33
|
+
}
|
|
34
|
+
function liveElapsedMs() {
|
|
35
|
+
if (currentState !== 'playing' || seekPending())
|
|
36
|
+
return anchorElapsedMs;
|
|
37
|
+
return Math.min(durationMs, anchorElapsedMs + (performance.now() - anchorTime));
|
|
38
|
+
}
|
|
39
|
+
function updateScrubber(elapsed) {
|
|
40
|
+
const clamped = Math.max(0, Math.min(durationMs, elapsed));
|
|
41
|
+
const pct = durationMs > 0 ? (clamped / durationMs) * 100 : 0;
|
|
42
|
+
timelineFill.style.width = `${pct}%`;
|
|
43
|
+
timelineThumb.style.left = `${pct}%`;
|
|
44
|
+
timeline.setAttribute('aria-valuenow', String(Math.round(clamped)));
|
|
45
|
+
timeline.setAttribute('aria-valuetext', `${time(clamped)} of ${time(durationMs)}`);
|
|
46
|
+
clock.textContent = `${time(clamped)} / ${time(durationMs)}`;
|
|
47
|
+
if (scenes.length) {
|
|
48
|
+
let activeIndex = 0;
|
|
49
|
+
for (let i = 0; i < scenes.length; i++) {
|
|
50
|
+
if (scenes[i].start_ms <= clamped + 1)
|
|
51
|
+
activeIndex = i;
|
|
52
|
+
else
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
if (sceneSelect.selectedIndex !== activeIndex)
|
|
56
|
+
sceneSelect.selectedIndex = activeIndex;
|
|
57
|
+
for (let i = 0; i < markerButtons.length; i++) {
|
|
58
|
+
markerButtons[i].classList.toggle('active', i === activeIndex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function createAudioSync(cues) {
|
|
63
|
+
let isMuted = false;
|
|
64
|
+
let activeCue;
|
|
65
|
+
let activeEl;
|
|
66
|
+
let lastSeekAt = 0;
|
|
67
|
+
const elements = new Map();
|
|
68
|
+
const playPending = new WeakSet();
|
|
69
|
+
const metadataHooked = new WeakSet();
|
|
70
|
+
function elementFor(url) {
|
|
71
|
+
let el = elements.get(url);
|
|
72
|
+
if (!el) {
|
|
73
|
+
el = new Audio(url);
|
|
74
|
+
el.preload = 'auto';
|
|
75
|
+
elements.set(url, el);
|
|
76
|
+
}
|
|
77
|
+
return el;
|
|
78
|
+
}
|
|
79
|
+
function pauseActive() {
|
|
80
|
+
if (activeEl)
|
|
81
|
+
activeEl.pause();
|
|
82
|
+
activeCue = undefined;
|
|
83
|
+
}
|
|
84
|
+
function sync(state, elapsedMs, forceSeek = false) {
|
|
85
|
+
if (!cues.length || state !== 'playing' || isMuted || seekPending()) {
|
|
86
|
+
pauseActive();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const cue = cues.find(item => item.start_ms <= elapsedMs && elapsedMs < item.end_ms);
|
|
90
|
+
if (!cue) {
|
|
91
|
+
pauseActive();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const el = elementFor(cue.url);
|
|
95
|
+
if (activeEl && activeEl !== el)
|
|
96
|
+
activeEl.pause();
|
|
97
|
+
const cueChanged = activeCue !== cue;
|
|
98
|
+
activeEl = el;
|
|
99
|
+
activeCue = cue;
|
|
100
|
+
const expected = Math.max(0, (elapsedMs - cue.start_ms) / 1000);
|
|
101
|
+
if (!forceSeek && !cueChanged && el.ended)
|
|
102
|
+
return;
|
|
103
|
+
if (Number.isFinite(el.duration) && expected >= el.duration - 0.04) {
|
|
104
|
+
el.pause();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (el.seeking)
|
|
108
|
+
return;
|
|
109
|
+
const drift = Math.abs(el.currentTime - expected);
|
|
110
|
+
const shouldSeek = forceSeek
|
|
111
|
+
|| (cueChanged && drift > 0.05)
|
|
112
|
+
|| (!el.paused && el.readyState >= 3 && drift > 0.45 && performance.now() - lastSeekAt > 1500);
|
|
113
|
+
if (shouldSeek) {
|
|
114
|
+
lastSeekAt = performance.now();
|
|
115
|
+
if (el.readyState >= 1) {
|
|
116
|
+
el.currentTime = expected;
|
|
117
|
+
}
|
|
118
|
+
else if (!metadataHooked.has(el)) {
|
|
119
|
+
metadataHooked.add(el);
|
|
120
|
+
el.addEventListener('loadedmetadata', () => {
|
|
121
|
+
metadataHooked.delete(el);
|
|
122
|
+
if (activeCue === cue)
|
|
123
|
+
el.currentTime = Math.max(0, (liveElapsedMs() - cue.start_ms) / 1000);
|
|
124
|
+
}, { once: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (el.paused && !el.ended && !playPending.has(el)) {
|
|
128
|
+
playPending.add(el);
|
|
129
|
+
void el.play().catch(() => { }).finally(() => playPending.delete(el));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function setMuted(next) {
|
|
133
|
+
isMuted = next;
|
|
134
|
+
if (isMuted || seekPending()) {
|
|
135
|
+
if (!isMuted)
|
|
136
|
+
forceAudioAlign = true;
|
|
137
|
+
pauseActive();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
sync(currentState, liveElapsedMs(), true);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
get muted() { return isMuted; },
|
|
145
|
+
get available() { return cues.length > 0; },
|
|
146
|
+
sync,
|
|
147
|
+
setMuted,
|
|
148
|
+
pause: pauseActive,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function updateMuteButton() {
|
|
152
|
+
if (!audioSync?.available) {
|
|
153
|
+
mute.disabled = true;
|
|
154
|
+
mute.textContent = 'No audio';
|
|
155
|
+
mute.title = 'Run tts or build first (or pass --cache-dir) to listen to cached narration during preview';
|
|
156
|
+
mute.setAttribute('aria-pressed', 'true');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
mute.disabled = currentState === 'loading';
|
|
160
|
+
mute.textContent = audioSync.muted ? 'Unmute' : 'Mute';
|
|
161
|
+
mute.title = audioSync.muted ? 'Unmute cached narration audio' : 'Mute cached narration audio';
|
|
162
|
+
mute.setAttribute('aria-pressed', String(audioSync.muted));
|
|
163
|
+
}
|
|
164
|
+
function startPlaybackLoop() {
|
|
165
|
+
cancelAnimationFrame(rafId);
|
|
166
|
+
const step = () => {
|
|
167
|
+
if (currentState !== 'playing')
|
|
168
|
+
return;
|
|
169
|
+
if (!seekPending()) {
|
|
170
|
+
const elapsed = liveElapsedMs();
|
|
171
|
+
if (!dragging)
|
|
172
|
+
updateScrubber(elapsed);
|
|
173
|
+
audioSync?.sync('playing', elapsed);
|
|
174
|
+
}
|
|
175
|
+
rafId = requestAnimationFrame(step);
|
|
176
|
+
};
|
|
177
|
+
rafId = requestAnimationFrame(step);
|
|
178
|
+
}
|
|
179
|
+
function display(state, elapsed, message, seekId) {
|
|
180
|
+
let seekJustConfirmed = false;
|
|
181
|
+
if (typeof seekId === 'number' && seekId > confirmedSeekId) {
|
|
182
|
+
confirmedSeekId = seekId;
|
|
183
|
+
if (confirmedSeekId >= activeSeekId)
|
|
184
|
+
seekJustConfirmed = true;
|
|
185
|
+
}
|
|
186
|
+
if (seekPending() && state !== 'error')
|
|
187
|
+
return;
|
|
188
|
+
if (state === 'error')
|
|
189
|
+
confirmedSeekId = activeSeekId;
|
|
190
|
+
currentState = state;
|
|
191
|
+
anchorElapsedMs = Math.max(0, Math.min(durationMs, elapsed));
|
|
192
|
+
anchorTime = performance.now();
|
|
15
193
|
const label = message || labels[state];
|
|
16
194
|
if (status.textContent !== label)
|
|
17
195
|
status.textContent = label;
|
|
18
196
|
document.body.toggleAttribute('data-error', state === 'error');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
197
|
+
if (!dragging)
|
|
198
|
+
updateScrubber(anchorElapsedMs);
|
|
199
|
+
const interactive = state !== 'loading';
|
|
200
|
+
timeline.setAttribute('aria-disabled', String(!interactive));
|
|
201
|
+
sceneSelect.disabled = !interactive || scenes.length === 0;
|
|
202
|
+
play.disabled = state !== 'ready' && state !== 'paused' && state !== 'ended';
|
|
22
203
|
pause.disabled = state !== 'playing';
|
|
23
|
-
restart.disabled = state === 'loading' || state === 'ready';
|
|
204
|
+
restart.disabled = state === 'loading' || (state === 'ready' && anchorElapsedMs === 0);
|
|
205
|
+
updateMuteButton();
|
|
206
|
+
const forceAlign = seekJustConfirmed || (state === 'playing' && forceAudioAlign);
|
|
207
|
+
if (state === 'playing')
|
|
208
|
+
forceAudioAlign = false;
|
|
209
|
+
audioSync?.sync(state, anchorElapsedMs, forceAlign);
|
|
210
|
+
if (state === 'playing')
|
|
211
|
+
startPlaybackLoop();
|
|
212
|
+
else
|
|
213
|
+
cancelAnimationFrame(rafId);
|
|
24
214
|
}
|
|
25
215
|
function failed(error) {
|
|
26
|
-
display('error',
|
|
216
|
+
display('error', anchorElapsedMs, error instanceof Error ? error.message : String(error));
|
|
27
217
|
}
|
|
28
218
|
async function request(path, method = 'GET') {
|
|
29
219
|
const response = await fetch(path, { method });
|
|
@@ -32,6 +222,11 @@ async function request(path, method = 'GET') {
|
|
|
32
222
|
return response.json();
|
|
33
223
|
}
|
|
34
224
|
function slidevPlayer(url, width, height) {
|
|
225
|
+
const viewport = document.createElement('div');
|
|
226
|
+
viewport.style.position = 'relative';
|
|
227
|
+
viewport.style.width = '100%';
|
|
228
|
+
viewport.style.height = '100%';
|
|
229
|
+
viewport.style.overflow = 'hidden';
|
|
35
230
|
const frame = document.createElement('iframe');
|
|
36
231
|
frame.title = 'Slide presentation';
|
|
37
232
|
frame.tabIndex = -1;
|
|
@@ -39,32 +234,79 @@ function slidevPlayer(url, width, height) {
|
|
|
39
234
|
frame.style.width = `${width}px`;
|
|
40
235
|
frame.style.height = `${height}px`;
|
|
41
236
|
frame.style.transformOrigin = 'top left';
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
237
|
+
let currentView = null;
|
|
238
|
+
const applyTransform = () => {
|
|
239
|
+
const baseScale = stage.clientWidth / width;
|
|
240
|
+
if (currentView && currentView.scale > 1.0001) {
|
|
241
|
+
const { content: c, source: s, scale } = currentView;
|
|
242
|
+
frame.style.transform = `scale(${baseScale}) translate(${c.x}px, ${c.y}px) scale(${scale}) translate(${-s.x}px, ${-s.y}px)`;
|
|
243
|
+
const topPct = (c.y / height) * 100;
|
|
244
|
+
const leftPct = (c.x / width) * 100;
|
|
245
|
+
const rightPct = ((width - (c.x + c.width)) / width) * 100;
|
|
246
|
+
const bottomPct = ((height - (c.y + c.height)) / height) * 100;
|
|
247
|
+
viewport.style.clipPath = topPct > 0.01 || leftPct > 0.01 || rightPct > 0.01 || bottomPct > 0.01
|
|
248
|
+
? `inset(${topPct}% ${rightPct}% ${bottomPct}% ${leftPct}%)`
|
|
249
|
+
: '';
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
frame.style.transform = `scale(${baseScale})`;
|
|
253
|
+
viewport.style.clipPath = '';
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
new ResizeObserver(applyTransform).observe(stage);
|
|
257
|
+
applyTransform();
|
|
45
258
|
const origin = new URL(url).origin;
|
|
46
|
-
const send = (action) =>
|
|
259
|
+
const send = (action, positionMs, seekId) => {
|
|
260
|
+
frame.contentWindow?.postMessage({ type: 'slidevideo-preview', action, ...(positionMs !== undefined ? { positionMs } : {}), ...(seekId !== undefined ? { seekId } : {}) }, origin);
|
|
261
|
+
};
|
|
47
262
|
window.addEventListener('message', event => {
|
|
48
263
|
if (event.source !== frame.contentWindow || event.origin !== origin)
|
|
49
264
|
return;
|
|
50
265
|
const data = event.data;
|
|
266
|
+
if (data?.type === 'slidevideo-preview-view') {
|
|
267
|
+
currentView = data.view ?? null;
|
|
268
|
+
applyTransform();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
51
271
|
if (data?.type === 'slidevideo-preview-state' && Object.hasOwn(labels, data.status)) {
|
|
52
|
-
display(data.status, data.elapsedMs, data.message);
|
|
272
|
+
display(data.status, data.elapsedMs, data.message, typeof data.seekId === 'number' ? data.seekId : undefined);
|
|
53
273
|
}
|
|
54
274
|
});
|
|
55
275
|
frame.addEventListener('load', () => send('hello'));
|
|
56
276
|
frame.src = url;
|
|
57
|
-
|
|
58
|
-
|
|
277
|
+
viewport.append(frame);
|
|
278
|
+
stage.append(viewport);
|
|
279
|
+
return {
|
|
280
|
+
play: () => send('play'),
|
|
281
|
+
pause: () => send('pause'),
|
|
282
|
+
restart: () => send('restart'),
|
|
283
|
+
seek: (positionMs, seekId) => send('seek', positionMs, seekId),
|
|
284
|
+
};
|
|
59
285
|
}
|
|
60
286
|
function nativePlayer(annotations) {
|
|
61
287
|
const canvas = document.createElement('canvas');
|
|
62
288
|
canvas.setAttribute('aria-label', 'PowerPoint presentation');
|
|
63
289
|
const context = canvas.getContext('2d');
|
|
290
|
+
let maskCanvas;
|
|
291
|
+
let maskContext;
|
|
292
|
+
const ensureSpotlightScratch = () => {
|
|
293
|
+
maskCanvas ??= document.createElement('canvas');
|
|
294
|
+
if (maskCanvas.width !== canvas.width)
|
|
295
|
+
maskCanvas.width = canvas.width;
|
|
296
|
+
if (maskCanvas.height !== canvas.height)
|
|
297
|
+
maskCanvas.height = canvas.height;
|
|
298
|
+
maskContext ??= maskCanvas.getContext('2d');
|
|
299
|
+
return {
|
|
300
|
+
context: maskContext,
|
|
301
|
+
drawTo: (target, { x, y, width, height }) => {
|
|
302
|
+
target.drawImage(maskCanvas, x, y, width, height, x, y, width, height);
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
};
|
|
64
306
|
stage.append(canvas);
|
|
65
307
|
let refreshTimer;
|
|
66
308
|
let revision = 0;
|
|
67
|
-
async function refresh(current) {
|
|
309
|
+
async function refresh(current, seekId) {
|
|
68
310
|
const frame = await request('/native/frame');
|
|
69
311
|
const image = new Image();
|
|
70
312
|
image.src = frame.image;
|
|
@@ -83,7 +325,9 @@ function nativePlayer(annotations) {
|
|
|
83
325
|
continue;
|
|
84
326
|
switch (marker.effect) {
|
|
85
327
|
case 'highlight':
|
|
86
|
-
case 'underline':
|
|
328
|
+
case 'underline':
|
|
329
|
+
case 'spotlight':
|
|
330
|
+
case 'zoom': {
|
|
87
331
|
const fragments = targets.get(targetKey(marker.target));
|
|
88
332
|
if (!fragments)
|
|
89
333
|
throw new Error(`Missing native target geometry for ${marker.id}`);
|
|
@@ -91,43 +335,289 @@ function nativePlayer(annotations) {
|
|
|
91
335
|
if (painted.effect === 'underline' && !underlineFragmentsVisible(painted)) {
|
|
92
336
|
throw new Error(`Annotation ${marker.id}: underline is clipped outside the slide-content rectangle`);
|
|
93
337
|
}
|
|
338
|
+
if (painted.effect === 'spotlight' && !spotlightAperturesVisible(painted)) {
|
|
339
|
+
throw new Error(`Annotation ${marker.id}: spotlight aperture is clipped outside the slide-content rectangle`);
|
|
340
|
+
}
|
|
341
|
+
if (painted.effect === 'zoom' && !zoomTransformVisible(painted)) {
|
|
342
|
+
throw new Error(`Annotation ${marker.id}: zoom target and padding leave no magnification room inside the slide-content rectangle`);
|
|
343
|
+
}
|
|
344
|
+
activeEffects.push(painted);
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case 'laser': {
|
|
348
|
+
const painted = laserPaint(marker, { viewport: frame.viewport, content: frame.content }, target => targets.get(targetKey(target)));
|
|
349
|
+
if (!laserVisible(painted)) {
|
|
350
|
+
throw new Error(`Annotation ${marker.id}: laser path has no visible pointer inside the slide-content rectangle`);
|
|
351
|
+
}
|
|
352
|
+
activeEffects.push(painted);
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case 'stamp': {
|
|
356
|
+
const fragments = marker.target.type === 'point' ? [] : targets.get(targetKey(marker.target));
|
|
357
|
+
if (!fragments)
|
|
358
|
+
throw new Error(`Missing native target geometry for ${marker.id}`);
|
|
359
|
+
const painted = stampPaint(marker, { viewport: frame.viewport, content: frame.content, fragments }, (font, text) => {
|
|
360
|
+
context.save();
|
|
361
|
+
context.font = font;
|
|
362
|
+
const width = context.measureText(text).width;
|
|
363
|
+
context.restore();
|
|
364
|
+
return width;
|
|
365
|
+
});
|
|
366
|
+
if (painted.overflow_error)
|
|
367
|
+
throw new Error(`Annotation ${marker.id}: ${painted.overflow_error}`);
|
|
368
|
+
if (!stampVisible(painted)) {
|
|
369
|
+
throw new Error(`Annotation ${marker.id}: stamp is clipped outside the slide-content rectangle`);
|
|
370
|
+
}
|
|
94
371
|
activeEffects.push(painted);
|
|
95
372
|
break;
|
|
96
373
|
}
|
|
97
374
|
}
|
|
98
375
|
}
|
|
99
|
-
|
|
100
|
-
|
|
376
|
+
const view = activeViewTransform(activeEffects, frame.position_ms);
|
|
377
|
+
if (view) {
|
|
378
|
+
const { content: c, source: s, scale } = view;
|
|
379
|
+
context.save();
|
|
380
|
+
context.beginPath();
|
|
381
|
+
context.rect(c.x, c.y, c.width, c.height);
|
|
382
|
+
context.clip();
|
|
383
|
+
context.translate(c.x, c.y);
|
|
384
|
+
context.scale(scale, scale);
|
|
385
|
+
context.translate(-s.x, -s.y);
|
|
386
|
+
context.imageSmoothingEnabled = true;
|
|
387
|
+
context.imageSmoothingQuality = 'high';
|
|
388
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
389
|
+
paintEffects(context, activeEffects, frame.position_ms, {
|
|
390
|
+
backdrop: true,
|
|
391
|
+
spotlightScratch: hasActiveSpotlight(activeEffects, frame.position_ms) ? ensureSpotlightScratch() : undefined,
|
|
392
|
+
});
|
|
393
|
+
context.restore();
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
paintEffects(context, activeEffects, frame.position_ms, {
|
|
397
|
+
backdrop: true,
|
|
398
|
+
spotlightScratch: hasActiveSpotlight(activeEffects, frame.position_ms) ? ensureSpotlightScratch() : undefined,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
display(frame.status, frame.position_ms, undefined, seekId);
|
|
101
402
|
refreshTimer = window.setTimeout(() => refresh(current).catch(failed), frame.status === 'playing' ? 16 : 500);
|
|
102
403
|
}
|
|
103
404
|
void refresh(revision).catch(failed);
|
|
104
|
-
|
|
405
|
+
let controlLoop;
|
|
406
|
+
const controlQueue = [];
|
|
407
|
+
let pendingConfirmSeekId;
|
|
408
|
+
function enqueueNative(op) {
|
|
105
409
|
clearTimeout(refreshTimer);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
410
|
+
revision++;
|
|
411
|
+
if (op.type === 'command' && op.isRestart) {
|
|
412
|
+
controlQueue.length = 0;
|
|
413
|
+
pendingConfirmSeekId = undefined;
|
|
414
|
+
controlQueue.push(op);
|
|
415
|
+
}
|
|
416
|
+
else if (op.type === 'seek' && controlQueue.at(-1)?.type === 'seek') {
|
|
417
|
+
controlQueue[controlQueue.length - 1] = op;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
controlQueue.push(op);
|
|
111
421
|
}
|
|
112
|
-
|
|
113
|
-
|
|
422
|
+
if (controlLoop)
|
|
423
|
+
return;
|
|
424
|
+
controlLoop = (async () => {
|
|
425
|
+
while (controlQueue.length) {
|
|
426
|
+
const next = controlQueue.shift();
|
|
427
|
+
let path;
|
|
428
|
+
if (next.type === 'seek') {
|
|
429
|
+
pendingConfirmSeekId = next.seekId;
|
|
430
|
+
path = `/native/control?command=seek&position_ms=${Math.round(next.positionMs)}`;
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
if (next.isRestart)
|
|
434
|
+
pendingConfirmSeekId = undefined;
|
|
435
|
+
path = next.path;
|
|
436
|
+
}
|
|
437
|
+
const current = ++revision;
|
|
438
|
+
try {
|
|
439
|
+
await request(path, 'POST');
|
|
440
|
+
if (!controlQueue.length && current === revision) {
|
|
441
|
+
const confirmed = pendingConfirmSeekId;
|
|
442
|
+
pendingConfirmSeekId = undefined;
|
|
443
|
+
await refresh(current, confirmed);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
controlQueue.length = 0;
|
|
448
|
+
pendingConfirmSeekId = undefined;
|
|
449
|
+
failed(error);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
})().finally(() => { controlLoop = undefined; });
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
play: () => enqueueNative({ type: 'command', path: '/native/control?command=play' }),
|
|
457
|
+
pause: () => enqueueNative({ type: 'command', path: '/native/control?command=pause' }),
|
|
458
|
+
restart: () => enqueueNative({ type: 'command', path: '/native/control?command=restart', isRestart: true }),
|
|
459
|
+
seek: (positionMs, seekId) => enqueueNative({ type: 'seek', positionMs, seekId }),
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function setupScenes(list, onSeek) {
|
|
463
|
+
scenes = list;
|
|
464
|
+
sceneSelect.replaceChildren();
|
|
465
|
+
timelineMarkers.replaceChildren();
|
|
466
|
+
markerButtons = [];
|
|
467
|
+
if (!scenes.length) {
|
|
468
|
+
sceneSelect.hidden = true;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
sceneSelect.hidden = false;
|
|
472
|
+
for (const [index, scene] of scenes.entries()) {
|
|
473
|
+
const option = document.createElement('option');
|
|
474
|
+
option.value = String(scene.start_ms);
|
|
475
|
+
option.textContent = `${index + 1}. ${scene.id} (${time(scene.start_ms)})`;
|
|
476
|
+
sceneSelect.append(option);
|
|
477
|
+
const marker = document.createElement('button');
|
|
478
|
+
marker.type = 'button';
|
|
479
|
+
marker.className = 'scene-marker';
|
|
480
|
+
marker.style.left = `${durationMs > 0 ? (scene.start_ms / durationMs) * 100 : 0}%`;
|
|
481
|
+
marker.title = `${scene.id} (${scene.slide}) · ${time(scene.start_ms)}`;
|
|
482
|
+
marker.setAttribute('aria-label', `Jump to scene ${scene.id} at ${time(scene.start_ms)}`);
|
|
483
|
+
marker.addEventListener('pointerdown', event => event.stopPropagation());
|
|
484
|
+
marker.addEventListener('click', event => {
|
|
485
|
+
event.stopPropagation();
|
|
486
|
+
if (currentState !== 'loading')
|
|
487
|
+
onSeek(scene.start_ms);
|
|
488
|
+
});
|
|
489
|
+
timelineMarkers.append(marker);
|
|
490
|
+
markerButtons.push(marker);
|
|
491
|
+
}
|
|
492
|
+
sceneSelect.addEventListener('change', () => {
|
|
493
|
+
const target = Number(sceneSelect.value);
|
|
494
|
+
if (Number.isFinite(target) && currentState !== 'loading')
|
|
495
|
+
onSeek(target);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function setupScrubber(onSeek) {
|
|
499
|
+
let lastSeekSent = 0;
|
|
500
|
+
let latestTarget = 0;
|
|
501
|
+
function positionFromEvent(event) {
|
|
502
|
+
const rect = timeline.getBoundingClientRect();
|
|
503
|
+
const ratio = rect.width > 0 ? Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width)) : 0;
|
|
504
|
+
return Math.round(ratio * durationMs);
|
|
505
|
+
}
|
|
506
|
+
timeline.addEventListener('pointerdown', event => {
|
|
507
|
+
if (event.button !== 0 || currentState === 'loading')
|
|
508
|
+
return;
|
|
509
|
+
dragging = true;
|
|
510
|
+
timeline.classList.add('dragging');
|
|
511
|
+
timeline.setPointerCapture(event.pointerId);
|
|
512
|
+
latestTarget = positionFromEvent(event);
|
|
513
|
+
updateScrubber(latestTarget);
|
|
514
|
+
lastSeekSent = performance.now();
|
|
515
|
+
onSeek(latestTarget);
|
|
516
|
+
});
|
|
517
|
+
timeline.addEventListener('pointermove', event => {
|
|
518
|
+
if (!dragging)
|
|
519
|
+
return;
|
|
520
|
+
latestTarget = positionFromEvent(event);
|
|
521
|
+
updateScrubber(latestTarget);
|
|
522
|
+
if (performance.now() - lastSeekSent >= 60) {
|
|
523
|
+
lastSeekSent = performance.now();
|
|
524
|
+
onSeek(latestTarget);
|
|
114
525
|
}
|
|
526
|
+
});
|
|
527
|
+
const finishDrag = (event) => {
|
|
528
|
+
if (!dragging)
|
|
529
|
+
return;
|
|
530
|
+
dragging = false;
|
|
531
|
+
timeline.classList.remove('dragging');
|
|
532
|
+
if (timeline.hasPointerCapture(event.pointerId))
|
|
533
|
+
timeline.releasePointerCapture(event.pointerId);
|
|
534
|
+
latestTarget = positionFromEvent(event);
|
|
535
|
+
updateScrubber(latestTarget);
|
|
536
|
+
onSeek(latestTarget);
|
|
115
537
|
};
|
|
538
|
+
timeline.addEventListener('pointerup', finishDrag);
|
|
539
|
+
timeline.addEventListener('pointercancel', finishDrag);
|
|
540
|
+
timeline.addEventListener('keydown', event => {
|
|
541
|
+
if (currentState === 'loading')
|
|
542
|
+
return;
|
|
543
|
+
const step = event.shiftKey ? 5000 : 1000;
|
|
544
|
+
const current = liveElapsedMs();
|
|
545
|
+
let target;
|
|
546
|
+
if (event.key === 'ArrowLeft')
|
|
547
|
+
target = Math.max(0, current - step);
|
|
548
|
+
else if (event.key === 'ArrowRight')
|
|
549
|
+
target = Math.min(durationMs, current + step);
|
|
550
|
+
else if (event.key === 'Home')
|
|
551
|
+
target = 0;
|
|
552
|
+
else if (event.key === 'End')
|
|
553
|
+
target = durationMs;
|
|
554
|
+
if (target !== undefined) {
|
|
555
|
+
event.preventDefault();
|
|
556
|
+
updateScrubber(target);
|
|
557
|
+
onSeek(target);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
116
560
|
}
|
|
117
561
|
try {
|
|
118
562
|
const config = await request('/config.json');
|
|
119
563
|
document.getElementById('deck').textContent = config.deck;
|
|
120
564
|
stage.style.setProperty('--ratio', String(config.width / config.height));
|
|
121
|
-
|
|
565
|
+
durationMs = Math.max(1, config.duration);
|
|
566
|
+
timeline.setAttribute('aria-valuemax', String(Math.round(durationMs)));
|
|
122
567
|
if (config.approximate.length) {
|
|
123
568
|
const pacing = document.getElementById('pacing');
|
|
124
569
|
pacing.textContent = `Estimated narration timing (150 words/min): ${config.approximate.join(', ')}`;
|
|
125
570
|
pacing.hidden = false;
|
|
126
571
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
572
|
+
audioSync = createAudioSync(config.audio ?? []);
|
|
573
|
+
updateMuteButton();
|
|
574
|
+
if (!('url' in config.stage) && config.stage.annotations.some(a => a.effect === 'stamp' && a.appearance.text !== undefined)) {
|
|
575
|
+
const specs = await request('/fonts/manifest.json');
|
|
576
|
+
const descriptors = specs.flatMap(spec => spec.files.map(entry => ({ family: spec.family, ...entry })));
|
|
577
|
+
const loaded = await Promise.all(descriptors.map(entry => new FontFace(entry.family, `url(/fonts/${entry.file}) format('woff2')`, {
|
|
578
|
+
weight: '400 800',
|
|
579
|
+
style: entry.style,
|
|
580
|
+
unicodeRange: entry.unicodeRange,
|
|
581
|
+
}).load()));
|
|
582
|
+
for (const face of loaded)
|
|
583
|
+
document.fonts.add(face);
|
|
584
|
+
await document.fonts.ready;
|
|
585
|
+
}
|
|
586
|
+
const controller = 'url' in config.stage ? slidevPlayer(config.stage.url, config.width, config.height) : nativePlayer(config.stage.annotations);
|
|
587
|
+
const performSeek = (ms) => {
|
|
588
|
+
const clamped = Math.max(0, Math.min(durationMs, ms));
|
|
589
|
+
const seekId = ++activeSeekId;
|
|
590
|
+
anchorElapsedMs = clamped;
|
|
591
|
+
anchorTime = performance.now();
|
|
592
|
+
updateScrubber(clamped);
|
|
593
|
+
if (currentState !== 'loading')
|
|
594
|
+
restart.disabled = currentState === 'ready' && clamped === 0;
|
|
595
|
+
audioSync?.pause();
|
|
596
|
+
controller.seek(clamped, seekId);
|
|
597
|
+
};
|
|
598
|
+
setupScenes(config.scenes ?? [], performSeek);
|
|
599
|
+
setupScrubber(performSeek);
|
|
600
|
+
play.onclick = () => {
|
|
601
|
+
forceAudioAlign = true;
|
|
602
|
+
controller.play();
|
|
603
|
+
};
|
|
604
|
+
pause.onclick = () => {
|
|
605
|
+
forceAudioAlign = false;
|
|
606
|
+
audioSync?.pause();
|
|
607
|
+
controller.pause();
|
|
608
|
+
};
|
|
609
|
+
restart.onclick = () => {
|
|
610
|
+
confirmedSeekId = activeSeekId;
|
|
611
|
+
forceAudioAlign = true;
|
|
612
|
+
audioSync?.pause();
|
|
613
|
+
controller.restart();
|
|
614
|
+
};
|
|
615
|
+
mute.onclick = () => {
|
|
616
|
+
if (!audioSync?.available)
|
|
617
|
+
return;
|
|
618
|
+
audioSync.setMuted(!audioSync.muted);
|
|
619
|
+
updateMuteButton();
|
|
620
|
+
};
|
|
131
621
|
}
|
|
132
622
|
catch (error) {
|
|
133
623
|
failed(error);
|
package/dist/preview/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Viewport } from '../contracts.js';
|
|
2
|
-
export declare function servePreview(storyboard: string, cache: string | undefined, port: number, viewport: Viewport | undefined, ready: (url: string, approximate: string[]) => void): Promise<void>;
|
|
2
|
+
export declare function servePreview(storyboard: string, cache: string | false | undefined, port: number, viewport: Viewport | undefined, ready: (url: string, approximate: string[]) => void): Promise<void>;
|