@slidevideo/cli 0.3.0 → 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 +12 -0
- package/README.md +2 -2
- 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/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/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 +17 -1
- 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 +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/dist/preview/server.js
CHANGED
|
@@ -8,17 +8,82 @@ import { ProductionError, requireCondition } from '../errors.js';
|
|
|
8
8
|
import { executionScope } from '../media.js';
|
|
9
9
|
import { loadStoryboard } from '../storyboard.js';
|
|
10
10
|
import { resolvePreviewTiming } from '../timing.js';
|
|
11
|
+
import { resolveSpeechCache } from '../speech.js';
|
|
12
|
+
import { BUNDLED_STAMP_FONTS, bundledFontPath } from '../stamp-fonts.js';
|
|
11
13
|
import { playerPage } from './view.js';
|
|
12
14
|
function send(res, status, contentType, body) {
|
|
13
15
|
res.writeHead(status, { 'Content-Type': contentType });
|
|
14
16
|
res.end(body);
|
|
15
17
|
}
|
|
18
|
+
function audioContentType(format) {
|
|
19
|
+
switch (format.toLowerCase()) {
|
|
20
|
+
case 'mp3': return 'audio/mpeg';
|
|
21
|
+
case 'wav': return 'audio/wav';
|
|
22
|
+
case 'ogg': return 'audio/ogg';
|
|
23
|
+
case 'm4a': return 'audio/mp4';
|
|
24
|
+
case 'webm': return 'audio/webm';
|
|
25
|
+
case 'aac': return 'audio/aac';
|
|
26
|
+
default: return 'application/octet-stream';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function sendAudio(req, res, filePath, format) {
|
|
30
|
+
const data = await readFile(filePath);
|
|
31
|
+
const contentType = audioContentType(format);
|
|
32
|
+
const range = req.headers.range;
|
|
33
|
+
if (range) {
|
|
34
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(range.trim());
|
|
35
|
+
if (!match || (!match[1] && !match[2]) || data.length === 0) {
|
|
36
|
+
res.writeHead(416, { 'Content-Range': `bytes */${data.length}` });
|
|
37
|
+
res.end();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let start;
|
|
41
|
+
let end;
|
|
42
|
+
if (!match[1]) {
|
|
43
|
+
const suffix = Number(match[2]);
|
|
44
|
+
if (suffix === 0) {
|
|
45
|
+
res.writeHead(416, { 'Content-Range': `bytes */${data.length}` });
|
|
46
|
+
res.end();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
start = Math.max(0, data.length - suffix);
|
|
50
|
+
end = data.length - 1;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
start = Number(match[1]);
|
|
54
|
+
end = match[2] ? Math.min(data.length - 1, Number(match[2])) : data.length - 1;
|
|
55
|
+
}
|
|
56
|
+
if (start >= data.length || start > end) {
|
|
57
|
+
res.writeHead(416, { 'Content-Range': `bytes */${data.length}` });
|
|
58
|
+
res.end();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const chunk = data.subarray(start, end + 1);
|
|
62
|
+
res.writeHead(206, {
|
|
63
|
+
'Content-Type': contentType,
|
|
64
|
+
'Content-Length': chunk.length,
|
|
65
|
+
'Content-Range': `bytes ${start}-${end}/${data.length}`,
|
|
66
|
+
'Accept-Ranges': 'bytes',
|
|
67
|
+
'Cache-Control': 'private, max-age=3600',
|
|
68
|
+
});
|
|
69
|
+
res.end(chunk);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
res.writeHead(200, {
|
|
73
|
+
'Content-Type': contentType,
|
|
74
|
+
'Content-Length': data.length,
|
|
75
|
+
'Accept-Ranges': 'bytes',
|
|
76
|
+
'Cache-Control': 'private, max-age=3600',
|
|
77
|
+
});
|
|
78
|
+
res.end(data);
|
|
79
|
+
}
|
|
16
80
|
export async function servePreview(storyboard, cache, port, viewport = defaultViewport, ready) {
|
|
17
81
|
let origin = '';
|
|
18
82
|
let config;
|
|
19
83
|
let session;
|
|
20
84
|
let adapter;
|
|
21
85
|
let directory;
|
|
86
|
+
let audioFiles = new Map();
|
|
22
87
|
let preserveDiagnostics = false;
|
|
23
88
|
const controller = new AbortController();
|
|
24
89
|
const stop = () => controller.abort();
|
|
@@ -38,12 +103,44 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
38
103
|
return send(res, 405, 'text/plain', 'Method not allowed');
|
|
39
104
|
if (pathname === '/')
|
|
40
105
|
return send(res, 200, 'text/html; charset=utf-8', playerPage);
|
|
106
|
+
if (pathname === '/favicon.ico') {
|
|
107
|
+
res.writeHead(204);
|
|
108
|
+
res.end();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
41
111
|
if (pathname === '/config.json')
|
|
42
112
|
return send(res, 200, 'application/json', JSON.stringify(config));
|
|
43
113
|
if (pathname === '/preview/player.js' || pathname === '/annotation-paint.js') {
|
|
44
114
|
const file = pathname === '/preview/player.js' ? './player.js' : '../annotation-paint.js';
|
|
45
115
|
return send(res, 200, 'text/javascript', await readFile(new URL(file, import.meta.url)));
|
|
46
116
|
}
|
|
117
|
+
if (pathname === '/fonts/manifest.json') {
|
|
118
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
119
|
+
res.setHeader('Cache-Control', 'private, max-age=3600');
|
|
120
|
+
return send(res, 200, 'application/json', JSON.stringify(BUNDLED_STAMP_FONTS));
|
|
121
|
+
}
|
|
122
|
+
if (pathname.startsWith('/fonts/')) {
|
|
123
|
+
const fontName = pathname.slice('/fonts/'.length);
|
|
124
|
+
const fontFile = bundledFontPath(fontName);
|
|
125
|
+
if (!fontFile)
|
|
126
|
+
return send(res, 404, 'text/plain', 'Not found');
|
|
127
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
128
|
+
res.setHeader('Cache-Control', 'private, max-age=3600');
|
|
129
|
+
return send(res, 200, 'font/woff2', await readFile(fontFile));
|
|
130
|
+
}
|
|
131
|
+
if (pathname.startsWith('/audio/')) {
|
|
132
|
+
let segment;
|
|
133
|
+
try {
|
|
134
|
+
segment = decodeURIComponent(pathname.slice('/audio/'.length));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return send(res, 400, 'text/plain', 'Invalid audio segment');
|
|
138
|
+
}
|
|
139
|
+
const file = audioFiles.get(segment);
|
|
140
|
+
if (!file)
|
|
141
|
+
return send(res, 404, 'text/plain', 'Not found');
|
|
142
|
+
return sendAudio(req, res, file.path, file.format);
|
|
143
|
+
}
|
|
47
144
|
send(res, 404, 'text/plain', 'Not found');
|
|
48
145
|
}
|
|
49
146
|
const server = createServer((req, res) => {
|
|
@@ -59,13 +156,15 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
59
156
|
process.once('SIGTERM', stop);
|
|
60
157
|
try {
|
|
61
158
|
await executionScope.run({ signal: controller.signal, bounded: false }, async () => {
|
|
62
|
-
const
|
|
159
|
+
const source = resolve(storyboard);
|
|
160
|
+
const story = await loadStoryboard(source);
|
|
63
161
|
requireCondition(!story.overlays?.length, 'PREVIEW_CAPABILITY', 'Image overlays require an exported video. Use slidevideo build to review them.', 3);
|
|
64
162
|
adapter = presentationAdapter(story.deck);
|
|
65
163
|
requireCondition(adapter.startPreview, 'PREVIEW_CAPABILITY', `Adapter ${adapter.id} does not support preview`, 3);
|
|
66
164
|
const inspection = await adapter.inspect(story.deck);
|
|
67
165
|
await adapter.validate(story, inspection, { viewport });
|
|
68
|
-
const { schedule, approximate } = await resolvePreviewTiming(story, ttsAdapters, cache);
|
|
166
|
+
const { schedule, approximate, audio: verifiedAudio } = await resolvePreviewTiming(story, ttsAdapters, resolveSpeechCache(source, cache));
|
|
167
|
+
audioFiles = verifiedAudio;
|
|
69
168
|
await adapter.validate(story, inspection, { viewport, schedule });
|
|
70
169
|
controller.signal.throwIfAborted();
|
|
71
170
|
await new Promise((resolve, reject) => {
|
|
@@ -79,8 +178,30 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
79
178
|
controller.signal.throwIfAborted();
|
|
80
179
|
session = await adapter.startPreview(story, schedule, directory, origin, viewport);
|
|
81
180
|
controller.signal.throwIfAborted();
|
|
181
|
+
const slideActions = schedule.actions.filter(item => item.action.type === 'slide');
|
|
182
|
+
const scenes = slideActions.map((item, index) => {
|
|
183
|
+
const target = item.action.type === 'slide' ? item.action.target : '';
|
|
184
|
+
const isSceneStart = item.id === `${item.scene}:slide`;
|
|
185
|
+
return {
|
|
186
|
+
id: isSceneStart ? item.scene : `${item.scene} · ${target}`,
|
|
187
|
+
slide: target,
|
|
188
|
+
start_ms: item.start_ms,
|
|
189
|
+
end_ms: slideActions[index + 1]?.start_ms ?? schedule.duration_ms,
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
const audio = [];
|
|
193
|
+
for (const item of schedule.actions) {
|
|
194
|
+
if (item.action.type === 'speak' && audioFiles.has(item.action.segment)) {
|
|
195
|
+
audio.push({
|
|
196
|
+
segment: item.action.segment,
|
|
197
|
+
start_ms: item.start_ms,
|
|
198
|
+
end_ms: item.end_ms,
|
|
199
|
+
url: `/audio/${encodeURIComponent(item.action.segment)}`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
82
203
|
config = { deck: basename(story.deck), width: viewport.width, height: viewport.height,
|
|
83
|
-
duration: schedule.duration_ms, approximate,
|
|
204
|
+
duration: schedule.duration_ms, approximate, scenes, audio,
|
|
84
205
|
stage: 'url' in session ? { url: session.url } : { annotations: schedule.annotations } };
|
|
85
206
|
ready(origin, approximate);
|
|
86
207
|
await new Promise(resolve => controller.signal.addEventListener('abort', () => resolve(), { once: true }));
|
package/dist/preview/view.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const playerPage
|
|
1
|
+
export declare const playerPage: string;
|
package/dist/preview/view.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { stampFontFaceCss } from '../stamp-fonts.js';
|
|
1
2
|
export const playerPage = `<!doctype html>
|
|
2
3
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
3
4
|
<title>Storyboard preview · SlideVideo</title>
|
|
4
5
|
<style>
|
|
6
|
+
${stampFontFaceCss()}
|
|
5
7
|
:root { color-scheme: dark; font: 15px Inter, system-ui, sans-serif; color: #e9edf1; background: #111419 }
|
|
6
8
|
* { box-sizing: border-box }
|
|
7
9
|
body { margin: 0; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto }
|
|
@@ -11,17 +13,31 @@ header { border-bottom: 1px solid #333942 }
|
|
|
11
13
|
header strong { letter-spacing: -.045em; font-size: 1.1rem }
|
|
12
14
|
#deck { color: #b7c0c9; padding-left: .75rem; border-left: 1px solid #525964; overflow-wrap: anywhere }
|
|
13
15
|
main { display: grid; place-items: center; min-height: 0; padding: clamp(.5rem, 2vw, 2rem) }
|
|
14
|
-
#stage { position: relative; width: min(100%, calc((100dvh -
|
|
16
|
+
#stage { position: relative; width: min(100%, calc((100dvh - 13rem) * var(--ratio, 1.7778))); aspect-ratio: var(--ratio, 1.7778); background: #090b0d; overflow: hidden; box-shadow: 0 8px 32px #0005 }
|
|
15
17
|
iframe, canvas { display: block; width: 100%; height: 100%; border: 0; object-fit: contain }
|
|
16
18
|
iframe { pointer-events: none }
|
|
17
19
|
footer { border-top: 1px solid #333942 }
|
|
18
20
|
.controls { flex-wrap: wrap; justify-content: space-between }
|
|
19
|
-
|
|
21
|
+
.transport { flex-wrap: wrap }
|
|
22
|
+
button, select { font: inherit; font-weight: 600; border: 1px solid #48515c; border-radius: .45rem; color: inherit; background: #272e36; padding: .5rem .85rem; cursor: pointer }
|
|
23
|
+
select { font-weight: 500; max-width: 18rem; text-overflow: ellipsis }
|
|
20
24
|
#play { background: #adedd6; border-color: transparent; color: #112a22 }
|
|
21
|
-
|
|
22
|
-
button:
|
|
25
|
+
#mute[aria-pressed="true"] { color: #9aa5b1 }
|
|
26
|
+
button:disabled, select:disabled { opacity: .42; cursor: default }
|
|
27
|
+
button:focus-visible, select:focus-visible, #timeline:focus-visible { outline: 2px solid #adedd6; outline-offset: 3px }
|
|
23
28
|
#clock { font-variant-numeric: tabular-nums; white-space: nowrap }
|
|
24
|
-
|
|
29
|
+
#timeline { position: relative; height: 1.5rem; display: flex; align-items: center; margin: 0 0 .85rem; cursor: pointer; touch-action: none; user-select: none; border-radius: .25rem }
|
|
30
|
+
#timeline[aria-disabled="true"] { opacity: .42; cursor: default; pointer-events: none }
|
|
31
|
+
.timeline-track { position: relative; width: 100%; height: .35rem; background: #303742; border-radius: 999px; transition: height .12s ease }
|
|
32
|
+
#timeline:hover .timeline-track, #timeline:focus-visible .timeline-track, #timeline.dragging .timeline-track { height: .48rem }
|
|
33
|
+
#timeline-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: #adedd6; border-radius: 999px; pointer-events: none }
|
|
34
|
+
#timeline-markers { position: absolute; inset: 0; pointer-events: none }
|
|
35
|
+
.scene-marker { position: absolute; top: 50%; transform: translate(-50%, -50%); width: 10px; height: 1.1rem; padding: 0; border: 0; border-radius: 2px; background: transparent; pointer-events: auto; cursor: pointer }
|
|
36
|
+
.scene-marker::after { content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 2px; height: .75rem; border-radius: 1px; background: #8a96a6; transition: background-color .12s ease, height .12s ease }
|
|
37
|
+
.scene-marker:hover::after, .scene-marker:focus-visible::after { background: #ffffff; height: 1rem }
|
|
38
|
+
.scene-marker.active::after { background: #adedd6 }
|
|
39
|
+
#timeline-thumb { position: absolute; top: 50%; left: 0%; width: .85rem; height: .85rem; border-radius: 50%; background: #adedd6; border: 2px solid #111419; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 1px 4px #0008; transition: transform .12s ease }
|
|
40
|
+
#timeline:hover #timeline-thumb, #timeline.dragging #timeline-thumb { transform: translate(-50%, -50%) scale(1.18) }
|
|
25
41
|
#status, #pacing { color: #bbc4ce }
|
|
26
42
|
#pacing { margin: .75rem 0 0; font-size: .9rem }
|
|
27
43
|
[data-error] #status { color: #ffb9ad }
|
|
@@ -29,8 +45,11 @@ progress { width: 100%; height: .25rem; accent-color: #adedd6; display: block; m
|
|
|
29
45
|
</style></head>
|
|
30
46
|
<body><header><strong>SlideVideo</strong><span id="deck">Storyboard preview</span></header>
|
|
31
47
|
<main><div id="stage"></div></main>
|
|
32
|
-
<footer
|
|
48
|
+
<footer>
|
|
49
|
+
<div id="timeline" role="slider" tabindex="0" aria-label="Playback position" aria-valuemin="0" aria-valuemax="1" aria-valuenow="0" aria-valuetext="0:00" aria-disabled="true">
|
|
50
|
+
<div class="timeline-track"><div id="timeline-fill"></div><div id="timeline-markers"></div><div id="timeline-thumb"></div></div>
|
|
51
|
+
</div>
|
|
33
52
|
<div class="controls"><div class="transport">
|
|
34
|
-
<button id="play" disabled>Play</button><button id="pause" disabled>Pause</button><button id="restart" disabled>Replay</button>
|
|
53
|
+
<button id="play" disabled>Play</button><button id="pause" disabled>Pause</button><button id="restart" disabled>Replay</button><button id="mute" type="button" aria-pressed="false" disabled>Audio</button><select id="scene" aria-label="Jump to scene" disabled></select>
|
|
35
54
|
</div><span id="status" role="status">Loading presentation…</span><span id="clock"></span></div><p id="pacing" hidden></p></footer>
|
|
36
55
|
<script type="module" src="/preview/player.js"></script></body></html>`;
|
package/dist/run.d.ts
CHANGED
package/dist/run.js
CHANGED
|
@@ -4,6 +4,26 @@ import { randomUUID } from 'node:crypto';
|
|
|
4
4
|
import { hashFile, json, saveJson } from './media.js';
|
|
5
5
|
import { requireCondition, ProductionError } from './errors.js';
|
|
6
6
|
import { packagePath } from './installation.js';
|
|
7
|
+
function formatRunTimestamp(now) {
|
|
8
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
9
|
+
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
10
|
+
}
|
|
11
|
+
export async function createDefaultRunDirectory(baseDir = resolve('runs'), now = new Date()) {
|
|
12
|
+
await mkdir(baseDir, { recursive: true });
|
|
13
|
+
const stamp = formatRunTimestamp(now);
|
|
14
|
+
for (let suffix = 1; suffix <= 1000; suffix++) {
|
|
15
|
+
const candidate = join(baseDir, suffix === 1 ? stamp : `${stamp}-${suffix}`);
|
|
16
|
+
try {
|
|
17
|
+
await mkdir(candidate);
|
|
18
|
+
return candidate;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'EEXIST')
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new ProductionError('NEW_RUN_REQUIRED', `Could not allocate a unique run directory under ${baseDir}`);
|
|
26
|
+
}
|
|
7
27
|
export class Run {
|
|
8
28
|
directory;
|
|
9
29
|
manifest;
|
package/dist/speech.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { SpeechManifest, Storyboard, Narration, Voice, TtsAdapter, SpeechAsset, ProgressReporter } from './contracts.js';
|
|
2
|
+
export declare function resolveSpeechCache(storyboard: string, cache?: string | false): string | undefined;
|
|
2
3
|
export declare function speechKey(segment: Narration, voice: Voice, adapter: Pick<TtsAdapter, 'id' | 'version'>): string;
|
|
4
|
+
export type VerifiedSpeechAudio = {
|
|
5
|
+
path: string;
|
|
6
|
+
format: string;
|
|
7
|
+
};
|
|
3
8
|
export type SpeechTiming = Pick<SpeechAsset, 'id' | 'duration_ms' | 'transcript' | 'alignment'>;
|
|
4
|
-
export
|
|
9
|
+
export type RetainedSpeech = {
|
|
10
|
+
timing: SpeechTiming;
|
|
11
|
+
audio?: VerifiedSpeechAudio;
|
|
12
|
+
};
|
|
13
|
+
export declare function retainedSpeechTiming(segment: Narration, voice: Voice, adapter: TtsAdapter, cache?: string): Promise<RetainedSpeech | undefined>;
|
|
5
14
|
export declare function checkSpeech(asset: SpeechAsset): Promise<void>;
|
|
6
15
|
export declare function generateSpeech(story: Storyboard, directory: string, adapters: Map<string, TtsAdapter>, cache?: string, progress?: ProgressReporter): Promise<SpeechManifest>;
|
package/dist/speech.js
CHANGED
|
@@ -10,6 +10,11 @@ function speechPath(directory, id, format) {
|
|
|
10
10
|
requireCondition(dirname(path) === resolve(directory), 'SPEECH_PATH', `Speech destination escapes its directory: ${id}`);
|
|
11
11
|
return path;
|
|
12
12
|
}
|
|
13
|
+
export function resolveSpeechCache(storyboard, cache) {
|
|
14
|
+
if (cache === false)
|
|
15
|
+
return undefined;
|
|
16
|
+
return resolve(cache ?? join(dirname(resolve(storyboard)), '.slidevideo', 'speech'));
|
|
17
|
+
}
|
|
13
18
|
export function speechKey(segment, voice, adapter) {
|
|
14
19
|
const options = Object.fromEntries(Object.entries(voice.options ?? {}).sort(([a], [b]) => a.localeCompare(b)));
|
|
15
20
|
return digest(JSON.stringify({ text: segment.text, provider: voice.provider, voice: voice.voice, options, adapter: adapter.id, version: adapter.version }));
|
|
@@ -54,7 +59,18 @@ export async function retainedSpeechTiming(segment, voice, adapter, cache) {
|
|
|
54
59
|
return undefined;
|
|
55
60
|
requireCondition(Number.isFinite(asset.duration_ms) && asset.duration_ms > 0, 'SPEECH_DURATION', `Invalid retained speech duration: ${segment.id}`);
|
|
56
61
|
checkAlignment(asset);
|
|
57
|
-
|
|
62
|
+
let audio;
|
|
63
|
+
if (/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(asset.format)) {
|
|
64
|
+
const audioPath = resolve(dirname(cached), asset.audio);
|
|
65
|
+
if (dirname(audioPath) === resolve(cache)) {
|
|
66
|
+
try {
|
|
67
|
+
if (await hashFile(audioPath) === asset.sha256)
|
|
68
|
+
audio = { path: audioPath, format: asset.format };
|
|
69
|
+
}
|
|
70
|
+
catch { }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { timing: { id: segment.id, duration_ms: asset.duration_ms, transcript: asset.transcript, alignment: asset.alignment }, ...(audio ? { audio } : {}) };
|
|
58
74
|
}
|
|
59
75
|
export async function checkSpeech(asset) {
|
|
60
76
|
requireCondition(/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(asset.format), 'SPEECH_FORMAT', `Invalid speech file format for ${asset.id}`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Annotation, StampFont } from './contracts.js';
|
|
2
|
+
export type BundledFontSpec = {
|
|
3
|
+
key: StampFont;
|
|
4
|
+
family: string;
|
|
5
|
+
files: {
|
|
6
|
+
file: string;
|
|
7
|
+
style: 'normal' | 'italic';
|
|
8
|
+
unicodeRange: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export declare const BUNDLED_STAMP_FONTS: readonly BundledFontSpec[];
|
|
12
|
+
export declare function bundledFontPath(file: string): string | undefined;
|
|
13
|
+
export declare function stampFontInputFiles(annotations: readonly Annotation[]): string[];
|
|
14
|
+
export declare function stampFontFaceCss(baseUrl?: string): string;
|
|
15
|
+
export declare function ensureStampFonts(): void;
|
|
16
|
+
export declare function unsupportedStampGlyph(text: string, font?: StampFont): string | undefined;
|
|
17
|
+
export declare function measureStampText(font: string, text: string): number;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { brotliDecompressSync } from 'node:zlib';
|
|
3
|
+
import { GlobalFonts, createCanvas } from '@napi-rs/canvas';
|
|
4
|
+
import { ProductionError } from './errors.js';
|
|
5
|
+
import { packagePath } from './installation.js';
|
|
6
|
+
export const BUNDLED_STAMP_FONTS = [
|
|
7
|
+
{
|
|
8
|
+
key: 'sans',
|
|
9
|
+
family: 'SlideVideoSans',
|
|
10
|
+
files: [
|
|
11
|
+
{ file: 'plus-jakarta-sans-latin-ext-5.woff2', style: 'normal', unicodeRange: 'U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF' },
|
|
12
|
+
{ file: 'plus-jakarta-sans-latin-6.woff2', style: 'normal', unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD' },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: 'mono',
|
|
17
|
+
family: 'SlideVideoMono',
|
|
18
|
+
files: [
|
|
19
|
+
{ file: 'jetbrains-mono-latin-ext-3.woff2', style: 'normal', unicodeRange: 'U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF' },
|
|
20
|
+
{ file: 'jetbrains-mono-latin-4.woff2', style: 'normal', unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD' },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: 'serif',
|
|
25
|
+
family: 'SlideVideoSerif',
|
|
26
|
+
files: [
|
|
27
|
+
{ file: 'instrument-serif-latin-ext-1.woff2', style: 'italic', unicodeRange: 'U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF' },
|
|
28
|
+
{ file: 'instrument-serif-latin-2.woff2', style: 'italic', unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD' },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const allowedFontFiles = new Set(BUNDLED_STAMP_FONTS.flatMap(spec => spec.files.map(entry => entry.file)));
|
|
33
|
+
export function bundledFontPath(file) {
|
|
34
|
+
if (!allowedFontFiles.has(file))
|
|
35
|
+
return undefined;
|
|
36
|
+
return packagePath('assets', 'fonts', file);
|
|
37
|
+
}
|
|
38
|
+
export function stampFontInputFiles(annotations) {
|
|
39
|
+
const fonts = new Set();
|
|
40
|
+
for (const annotation of annotations) {
|
|
41
|
+
if (annotation.effect === 'stamp' && annotation.appearance.text !== undefined) {
|
|
42
|
+
fonts.add(annotation.appearance.font ?? 'sans');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const files = [];
|
|
46
|
+
for (const spec of BUNDLED_STAMP_FONTS) {
|
|
47
|
+
if (!fonts.has(spec.key))
|
|
48
|
+
continue;
|
|
49
|
+
for (const entry of spec.files)
|
|
50
|
+
files.push(packagePath('assets', 'fonts', entry.file));
|
|
51
|
+
}
|
|
52
|
+
return files;
|
|
53
|
+
}
|
|
54
|
+
export function stampFontFaceCss(baseUrl = '') {
|
|
55
|
+
const prefix = baseUrl.replace(/\/$/, '');
|
|
56
|
+
const rules = [];
|
|
57
|
+
for (const spec of BUNDLED_STAMP_FONTS) {
|
|
58
|
+
for (const entry of spec.files) {
|
|
59
|
+
rules.push(`@font-face{font-family:'${spec.family}';src:url('${prefix}/fonts/${entry.file}') format('woff2');font-weight:400 800;font-style:${entry.style};font-display:block;unicode-range:${entry.unicodeRange};}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return rules.join('\n');
|
|
63
|
+
}
|
|
64
|
+
let registered = false;
|
|
65
|
+
let measureContext;
|
|
66
|
+
export function ensureStampFonts() {
|
|
67
|
+
if (registered)
|
|
68
|
+
return;
|
|
69
|
+
for (const spec of BUNDLED_STAMP_FONTS) {
|
|
70
|
+
for (const entry of spec.files) {
|
|
71
|
+
const filePath = packagePath('assets', 'fonts', entry.file);
|
|
72
|
+
if (!existsSync(filePath)) {
|
|
73
|
+
throw new ProductionError('STAMP_FONT', `Bundled stamp font is missing: ${filePath}`, 3);
|
|
74
|
+
}
|
|
75
|
+
const key = GlobalFonts.registerFromPath(filePath, spec.family);
|
|
76
|
+
if (!key) {
|
|
77
|
+
throw new ProductionError('STAMP_FONT', `Failed to register bundled stamp font ${spec.family} from ${filePath}`, 3);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!GlobalFonts.has(spec.family)) {
|
|
81
|
+
throw new ProductionError('STAMP_FONT', `Bundled stamp font family ${spec.family} is unavailable after registration`, 3);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
registered = true;
|
|
85
|
+
}
|
|
86
|
+
const WOFF2_KNOWN_TAGS = [
|
|
87
|
+
'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'glyf', 'loca', 'prep', 'CFF ', 'VORG',
|
|
88
|
+
'EBDT', 'EBLC', 'gasp', 'hdmx', 'kern', 'LTSH', 'PCLT', 'VDMX', 'vhea', 'vmtx', 'BASE', 'GDEF', 'GPOS', 'GSUB', 'EBSC',
|
|
89
|
+
'JSTF', 'MATH', 'CBDT', 'CBLC', 'COLR', 'CPAL', 'SVG ', 'sbix', 'acnt', 'avar', 'bdat', 'bloc', 'bsln', 'cvar', 'fdsc',
|
|
90
|
+
'feat', 'fmtx', 'fvar', 'gvar', 'hsty', 'just', 'lcar', 'mort', 'morx', 'opbd', 'prop', 'trak', 'Zapf', 'Silf', 'Glat',
|
|
91
|
+
'Gloc', 'Feat', 'Sill',
|
|
92
|
+
];
|
|
93
|
+
function readUIntBase128(buf, state) {
|
|
94
|
+
let accum = 0;
|
|
95
|
+
for (let i = 0; i < 5; i++) {
|
|
96
|
+
const b = buf[state.o++];
|
|
97
|
+
if (i === 0 && b === 0x80)
|
|
98
|
+
throw new Error('Invalid WOFF2 base128 leading zero');
|
|
99
|
+
accum = (accum << 7) | (b & 0x7f);
|
|
100
|
+
if ((b & 0x80) === 0)
|
|
101
|
+
return accum >>> 0;
|
|
102
|
+
}
|
|
103
|
+
throw new Error('Invalid WOFF2 base128 overflow');
|
|
104
|
+
}
|
|
105
|
+
function woff2Codepoints(filePath) {
|
|
106
|
+
const buf = readFileSync(filePath);
|
|
107
|
+
if (buf.toString('ascii', 0, 4) !== 'wOF2') {
|
|
108
|
+
throw new ProductionError('STAMP_FONT', `Bundled stamp font is not a valid WOFF2 file: ${filePath}`, 3);
|
|
109
|
+
}
|
|
110
|
+
const numTables = buf.readUInt16BE(12);
|
|
111
|
+
const totalCompressedSize = buf.readUInt32BE(20);
|
|
112
|
+
const state = { o: 48 };
|
|
113
|
+
const tables = [];
|
|
114
|
+
for (let i = 0; i < numTables; i++) {
|
|
115
|
+
const flags = buf[state.o++];
|
|
116
|
+
const tagIdx = flags & 0x3f;
|
|
117
|
+
const tag = tagIdx === 63 ? buf.toString('ascii', state.o, (state.o += 4)) : WOFF2_KNOWN_TAGS[tagIdx];
|
|
118
|
+
const transformVersion = (flags >> 6) & 3;
|
|
119
|
+
const origLength = readUIntBase128(buf, state);
|
|
120
|
+
const hasTransform = (tag === 'glyf' || tag === 'loca') ? transformVersion !== 3 : transformVersion !== 0;
|
|
121
|
+
const transformLength = hasTransform ? readUIntBase128(buf, state) : origLength;
|
|
122
|
+
tables.push({ tag, transformLength });
|
|
123
|
+
}
|
|
124
|
+
const stream = brotliDecompressSync(buf.subarray(state.o, state.o + totalCompressedSize));
|
|
125
|
+
let offset = 0;
|
|
126
|
+
let cmap;
|
|
127
|
+
for (const table of tables) {
|
|
128
|
+
if (table.tag === 'cmap') {
|
|
129
|
+
cmap = stream.subarray(offset, offset + table.transformLength);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
offset += table.transformLength;
|
|
133
|
+
}
|
|
134
|
+
const codepoints = new Set();
|
|
135
|
+
if (!cmap)
|
|
136
|
+
return codepoints;
|
|
137
|
+
const numSubtables = cmap.readUInt16BE(2);
|
|
138
|
+
for (let i = 0; i < numSubtables; i++) {
|
|
139
|
+
const subOff = cmap.readUInt32BE(4 + i * 8 + 4);
|
|
140
|
+
const fmt = cmap.readUInt16BE(subOff);
|
|
141
|
+
if (fmt === 4) {
|
|
142
|
+
const segCount = cmap.readUInt16BE(subOff + 6) / 2;
|
|
143
|
+
const endOff = subOff + 14;
|
|
144
|
+
const startOff = endOff + segCount * 2 + 2;
|
|
145
|
+
for (let s = 0; s < segCount; s++) {
|
|
146
|
+
const end = cmap.readUInt16BE(endOff + s * 2);
|
|
147
|
+
const start = cmap.readUInt16BE(startOff + s * 2);
|
|
148
|
+
if (start === 0xffff && end === 0xffff)
|
|
149
|
+
break;
|
|
150
|
+
for (let cp = start; cp <= end; cp++)
|
|
151
|
+
codepoints.add(cp);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (fmt === 12) {
|
|
155
|
+
const nGroups = cmap.readUInt32BE(subOff + 12);
|
|
156
|
+
for (let g = 0; g < nGroups; g++) {
|
|
157
|
+
const start = cmap.readUInt32BE(subOff + 16 + g * 12);
|
|
158
|
+
const end = cmap.readUInt32BE(subOff + 16 + g * 12 + 4);
|
|
159
|
+
for (let cp = start; cp <= end; cp++)
|
|
160
|
+
codepoints.add(cp);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return codepoints;
|
|
165
|
+
}
|
|
166
|
+
const fontCodepointsCache = new Map();
|
|
167
|
+
function stampFontCodepoints(font) {
|
|
168
|
+
const cached = fontCodepointsCache.get(font);
|
|
169
|
+
if (cached)
|
|
170
|
+
return cached;
|
|
171
|
+
const spec = BUNDLED_STAMP_FONTS.find(entry => entry.key === font);
|
|
172
|
+
if (!spec)
|
|
173
|
+
throw new ProductionError('STAMP_FONT', `Unknown bundled stamp font: ${font}`, 3);
|
|
174
|
+
const codepoints = new Set();
|
|
175
|
+
for (const entry of spec.files) {
|
|
176
|
+
const filePath = packagePath('assets', 'fonts', entry.file);
|
|
177
|
+
if (!existsSync(filePath)) {
|
|
178
|
+
throw new ProductionError('STAMP_FONT', `Bundled stamp font is missing: ${filePath}`, 3);
|
|
179
|
+
}
|
|
180
|
+
for (const cp of woff2Codepoints(filePath))
|
|
181
|
+
codepoints.add(cp);
|
|
182
|
+
}
|
|
183
|
+
fontCodepointsCache.set(font, codepoints);
|
|
184
|
+
return codepoints;
|
|
185
|
+
}
|
|
186
|
+
export function unsupportedStampGlyph(text, font = 'sans') {
|
|
187
|
+
const supported = stampFontCodepoints(font);
|
|
188
|
+
for (const ch of text) {
|
|
189
|
+
const cp = ch.codePointAt(0);
|
|
190
|
+
if (cp === 0x09 || cp === 0x0a || cp === 0x0d || cp === 0x20)
|
|
191
|
+
continue;
|
|
192
|
+
if (!supported.has(cp))
|
|
193
|
+
return ch;
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
export function measureStampText(font, text) {
|
|
198
|
+
ensureStampFonts();
|
|
199
|
+
measureContext ??= createCanvas(16, 16).getContext('2d');
|
|
200
|
+
measureContext.font = font;
|
|
201
|
+
return measureContext.measureText(text).width;
|
|
202
|
+
}
|
package/dist/storyboard.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, extname, isAbsolute, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { parse } from 'yaml';
|
|
5
5
|
import { Ajv } from 'ajv';
|
|
6
|
+
import { unsupportedStampGlyph } from './stamp-fonts.js';
|
|
6
7
|
import { requireCondition, ProductionError } from './errors.js';
|
|
7
8
|
import { hashFile, digest } from './media.js';
|
|
8
9
|
const validate = new Ajv({ allErrors: true }).compile(JSON.parse(await readFile(fileURLToPath(new URL('../schemas/storyboard.v1.json', import.meta.url)), 'utf8')));
|
|
@@ -43,7 +44,30 @@ export async function loadStoryboard(file) {
|
|
|
43
44
|
for (const annotation of data.annotations) {
|
|
44
45
|
const context = { annotation: annotation.id, target: annotation.target };
|
|
45
46
|
requireCondition(data.scenes.some(scene => scene.id === annotation.scene), 'ANNOTATION_SCENE', `Annotation ${annotation.id}: unknown scene ${annotation.scene}`, 2, context);
|
|
46
|
-
|
|
47
|
+
if ('at' in annotation && annotation.at !== undefined) {
|
|
48
|
+
if (typeof annotation.at !== 'number') {
|
|
49
|
+
requireCondition(segments.has(annotation.at.segment), 'CUE_REFERENCE', `Annotation ${annotation.id}: unknown narration ${annotation.at.segment}`, 2, context);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const follow = annotation.follow;
|
|
54
|
+
requireCondition(segments.has(follow.segment), 'CUE_REFERENCE', `Annotation ${annotation.id}: unknown narration ${follow.segment}`, 2, context);
|
|
55
|
+
requireCondition(follow.phrase === undefined || follow.phrase.trim().length > 0, 'CUE_PHRASE_MISSING', `Annotation ${annotation.id}: follow phrase cannot be empty or whitespace`, 2, context);
|
|
56
|
+
requireCondition(follow.occurrence === undefined || follow.phrase !== undefined, 'ANNOTATION_FOLLOW', `Annotation ${annotation.id}: follow occurrence requires an explicit phrase`, 2, context);
|
|
57
|
+
const mode = follow.mode ?? 'words';
|
|
58
|
+
if (mode === 'words') {
|
|
59
|
+
requireCondition(annotation.target.type === 'text', 'ANNOTATION_FOLLOW', `Annotation ${annotation.id}: word-following mode requires a text target`, 2, context);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
requireCondition(follow.tokens === undefined, 'ANNOTATION_FOLLOW', `Annotation ${annotation.id}: follow tokens require mode: words`, 2, context);
|
|
63
|
+
}
|
|
64
|
+
for (const token of follow.tokens ?? []) {
|
|
65
|
+
requireCondition(token.text.trim().length > 0 && token.phrase.trim().length > 0, 'ANNOTATION_FOLLOW', `Annotation ${annotation.id}: follow token text and phrase cannot be whitespace`, 2, context);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (annotation.target.type === 'text') {
|
|
69
|
+
requireCondition(annotation.target.text.trim().length > 0, 'ANNOTATION_TARGET', `Annotation ${annotation.id}: text target cannot be empty or whitespace`, 2, context);
|
|
70
|
+
}
|
|
47
71
|
if (annotation.target.type === 'region') {
|
|
48
72
|
const { x, y, width, height } = annotation.target;
|
|
49
73
|
requireCondition(x + width <= 1 && y + height <= 1, 'ANNOTATION_BOUNDS', `Annotation ${annotation.id}: region exceeds normalized slide bounds`, 2, context);
|
|
@@ -52,10 +76,43 @@ export async function loadStoryboard(file) {
|
|
|
52
76
|
requireCondition(top < 1 && top + annotation.appearance.width > 0, 'ANNOTATION_BOUNDS', `Annotation ${annotation.id}: underline offset places stroke outside normalized slide bounds`, 2, context);
|
|
53
77
|
}
|
|
54
78
|
}
|
|
55
|
-
if (annotation.effect === '
|
|
79
|
+
if (annotation.effect === 'laser') {
|
|
80
|
+
let totalDwell = 0;
|
|
81
|
+
for (const point of annotation.target.points) {
|
|
82
|
+
totalDwell += point.dwell_ms ?? 0;
|
|
83
|
+
if ('target' in point) {
|
|
84
|
+
if (point.target.type === 'text') {
|
|
85
|
+
requireCondition(point.target.text.trim().length > 0, 'ANNOTATION_TARGET', `Annotation ${annotation.id}: laser waypoint text target cannot be empty or whitespace`, 2, context);
|
|
86
|
+
}
|
|
87
|
+
if (point.target.type === 'region') {
|
|
88
|
+
const { x, y, width, height } = point.target;
|
|
89
|
+
requireCondition(x + width <= 1 && y + height <= 1, 'ANNOTATION_BOUNDS', `Annotation ${annotation.id}: laser waypoint region exceeds normalized slide bounds`, 2, context);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if ('duration_ms' in annotation && annotation.duration_ms !== undefined) {
|
|
94
|
+
const validDwell = annotation.target.points.length >= 2
|
|
95
|
+
? totalDwell < annotation.duration_ms
|
|
96
|
+
: totalDwell <= annotation.duration_ms;
|
|
97
|
+
requireCondition(validDwell, 'ANNOTATION_MOTION', `Annotation ${annotation.id}: laser waypoint dwell (${totalDwell} ms) leaves no traversal time within duration (${annotation.duration_ms} ms)`, 2, context);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (annotation.effect === 'zoom' && annotation.appearance?.scale !== undefined && annotation.appearance?.max_scale !== undefined) {
|
|
101
|
+
requireCondition(annotation.appearance.scale <= annotation.appearance.max_scale, 'ANNOTATION_ZOOM', `Annotation ${annotation.id}: zoom scale (${annotation.appearance.scale}) exceeds max_scale (${annotation.appearance.max_scale})`, 2, context);
|
|
102
|
+
}
|
|
103
|
+
if (annotation.effect === 'stamp') {
|
|
104
|
+
const text = annotation.appearance.text;
|
|
105
|
+
if (text !== undefined) {
|
|
106
|
+
requireCondition(text.trim().length > 0, 'STAMP_CONTENT', `Annotation ${annotation.id}: stamp text cannot be empty or whitespace`, 2, context);
|
|
107
|
+
const font = annotation.appearance.font ?? 'sans';
|
|
108
|
+
const badChar = unsupportedStampGlyph(text, font);
|
|
109
|
+
requireCondition(badChar === undefined, 'STAMP_GLYPH', `Annotation ${annotation.id}: character ${JSON.stringify(badChar)} is not supported by the bundled ${font} stamp font; use characters covered by the bundled font or appearance.symbol (check, cross, warning, star, info, arrow-right)`, 2, context);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if ((annotation.effect === 'underline' || annotation.effect === 'spotlight' || annotation.effect === 'zoom' || annotation.effect === 'laser' || annotation.effect === 'stamp') && annotation.motion && 'duration_ms' in annotation && annotation.duration_ms !== undefined) {
|
|
56
113
|
const inMs = annotation.motion.in_ms ?? 0;
|
|
57
114
|
const outMs = annotation.motion.out_ms ?? 0;
|
|
58
|
-
requireCondition(inMs + outMs <= annotation.duration_ms, 'ANNOTATION_MOTION', `Annotation ${annotation.id}:
|
|
115
|
+
requireCondition(inMs + outMs <= annotation.duration_ms, 'ANNOTATION_MOTION', `Annotation ${annotation.id}: ${annotation.motion.type} motion exceeds annotation duration`, 2, context);
|
|
59
116
|
}
|
|
60
117
|
}
|
|
61
118
|
const scenes = new Set(data.scenes.map(scene => scene.id));
|