@beff/aula-cli 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +11 -1
  2. package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
  3. package/dist/licenses/espeak-ng-COPYING.txt +674 -0
  4. package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
  5. package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
  6. package/dist/src/aula-render.core.wasm +0 -0
  7. package/dist/src/aula-voice-tts-ZXQ7XXHJ.js +14 -0
  8. package/dist/src/chunk-2XGNOG2U.js +28 -0
  9. package/dist/src/chunk-46KT47TH.js +21 -0
  10. package/dist/src/chunk-7KT36JRP.js +1282 -0
  11. package/dist/src/chunk-GFCJYE75.js +42 -0
  12. package/dist/src/chunk-IAQZ6DTC.js +271 -0
  13. package/dist/src/chunk-QWNBVWUQ.js +1105 -0
  14. package/dist/src/chunk-XUBCUJW5.js +104 -0
  15. package/dist/src/chunk-YX73KJQ6.js +577 -0
  16. package/dist/src/cli.js +334 -0
  17. package/dist/src/commands-M246OWYJ.js +27 -0
  18. package/dist/src/problems-Y67BY7WB.js +12 -0
  19. package/dist/src/project-NWT5MDQI.js +11 -0
  20. package/dist/src/render-child.js +3771 -0
  21. package/dist/src/run-CTVGU7EK.js +127 -0
  22. package/dist/src/server-5OGXX6BF.js +220 -0
  23. package/dist/web/app/assets/__vite-browser-external-BN30sEqc.js +1 -0
  24. package/dist/web/app/assets/__vite-browser-external-BtQTJ51O.js +1 -0
  25. package/dist/web/app/assets/aula-method.js +1 -0
  26. package/dist/web/app/assets/aula-voice-worker-DymX5vwM.js +52 -0
  27. package/dist/web/app/assets/aula.core-BtiPQSZi.wasm +0 -0
  28. package/dist/web/app/assets/aula.core5-YhDIb7Me.wasm +0 -0
  29. package/dist/web/app/assets/aula.js +1 -0
  30. package/dist/web/app/assets/build-worker.js +696 -0
  31. package/dist/web/app/assets/esbuild-BaXVPFT2.wasm +0 -0
  32. package/dist/web/app/assets/index-B8_aMtuI.js +53 -0
  33. package/dist/web/app/assets/index-cL-Dm_aw.css +2 -0
  34. package/dist/web/app/assets/protocol-CnlzsyRt.js +15 -0
  35. package/dist/web/app/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
  36. package/dist/web/app/assets/src-CmWmmzpF.js +25 -0
  37. package/dist/web/app/index.html +15 -0
  38. package/package.json +27 -5
@@ -0,0 +1,42 @@
1
+ import {
2
+ run
3
+ } from "./chunk-2XGNOG2U.js";
4
+
5
+ // src/media.ts
6
+ import path from "node:path";
7
+ var VIDEO = { width: 1280, height: 720, fps: 30 };
8
+ async function ffmpeg(capabilities, args) {
9
+ const ran = await run(capabilities, "ffmpeg", ["-hide_banner", "-loglevel", "error", "-nostdin", "-y", ...args]);
10
+ if (ran.code !== 0) throw new Error(`ffmpeg failed: ${ran.stderr.trim()}`);
11
+ }
12
+ async function duration(capabilities, file) {
13
+ const { stderr } = await run(capabilities, "ffmpeg", ["-i", file]);
14
+ const stamp = stderr.split("Duration: ")[1]?.split(",")[0];
15
+ if (stamp === void 0) throw new Error(`${file}: ffmpeg reports no duration`);
16
+ const [h, m, s, ...rest] = stamp.split(":").map((p) => Number(p.trim()));
17
+ if (h === void 0 || m === void 0 || s === void 0 || rest.length || [h, m, s].some(Number.isNaN)) {
18
+ throw new Error(`${file}: unreadable duration ${stamp}`);
19
+ }
20
+ return h * 3600 + m * 60 + s;
21
+ }
22
+ var signed = (x) => `${x >= 0 ? "+" : ""}${x.toFixed(2)}`;
23
+ async function assemble(capabilities, options) {
24
+ const concat = path.join(options.work, "concat.txt");
25
+ await capabilities.fs.writeFile(concat, options.clips.map((v) => `file '${v}'
26
+ `).join(""));
27
+ const join = ["-f", "concat", "-safe", "0", "-i", concat, "-i", options.audio, "-map", "0:v:0", "-map", "1:a:0"];
28
+ const codecs = ["-c:v", "copy", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart"];
29
+ await ffmpeg(capabilities, [...join, ...codecs, options.out]);
30
+ const video = await duration(capabilities, options.out);
31
+ const diff = video - options.seconds;
32
+ capabilities.log.out(`video ${video.toFixed(2)}s narration ${options.seconds.toFixed(2)}s diff ${signed(diff)}s`);
33
+ if (Math.abs(diff) > 1 / VIDEO.fps) {
34
+ throw new Error(`Out of sync: video and narration differ by more than one frame (${options.out})`);
35
+ }
36
+ }
37
+
38
+ export {
39
+ VIDEO,
40
+ ffmpeg,
41
+ assemble
42
+ };
@@ -0,0 +1,271 @@
1
+ import {
2
+ timeChapter
3
+ } from "./chunk-XUBCUJW5.js";
4
+ import {
5
+ Problems,
6
+ error,
7
+ isError,
8
+ withSource,
9
+ wrongArgument
10
+ } from "./chunk-7KT36JRP.js";
11
+
12
+ // src/problems.ts
13
+ import { loadEngine as loadEngine2 } from "@beff/aula/run";
14
+ import { renderDiagnostic } from "@beff/aula/text";
15
+
16
+ // ../aula-project/src/chapters.ts
17
+ import { readChapter } from "@beff/aula";
18
+ import { paragraphAt, scriptMarkdown } from "@beff/aula/text";
19
+ function chapterIndex(names, name) {
20
+ const at = names.indexOf(name);
21
+ if (at >= 0) return at;
22
+ throw wrongArgument(`No chapter '${name}': use one of [${names.join(", ")}]`);
23
+ }
24
+ function header(project) {
25
+ const body = project.storyboard.trim();
26
+ return body === "" ? `# ${project.title}
27
+ ` : `# ${project.title}
28
+
29
+ ${body}
30
+ `;
31
+ }
32
+ function placeText(place) {
33
+ return `${place.file}:${String(place.line)}`;
34
+ }
35
+ function chapterText(project, host, index) {
36
+ const result = readChapter(project, index, { host });
37
+ if (!result.ok || !result.value) throw new Problems(result.diagnostics);
38
+ return result.value;
39
+ }
40
+ function paragraphCue(text, name, line) {
41
+ const p = paragraphAt(text, line);
42
+ if (p !== void 0) return p + 1;
43
+ const starts = text.paragraphs.flatMap((q) => q.place ? [String(q.place.line)] : []);
44
+ const list = starts.length > 1 ? `${starts.slice(0, -1).join(", ")} and ${starts.at(-1) ?? ""}` : starts.join("");
45
+ throw wrongArgument(`line ${String(line)} of ${name} is in no paragraph; the paragraphs start at lines ${list}`);
46
+ }
47
+ function texts(project, host) {
48
+ const reads = project.chapters.map((_, i) => readChapter(project, i + 1, { host }));
49
+ const problems = reads.flatMap((r) => r.ok && r.value ? [] : r.diagnostics);
50
+ if (problems.length) throw new Problems(problems);
51
+ return reads.flatMap((r) => r.value ? [r.value] : []);
52
+ }
53
+ function scriptView(project, host) {
54
+ return scriptMarkdown(project.title, texts(project, host));
55
+ }
56
+ function openMoves(text) {
57
+ return text.paragraphs.flatMap((p) => p.moves).filter((m) => !m.done);
58
+ }
59
+ function openCount(chapters, indexes) {
60
+ return chapters.filter((_, i) => indexes.includes(i + 1)).reduce((sum, t) => sum + openMoves(t).length, 0);
61
+ }
62
+
63
+ // ../aula-project/src/check.ts
64
+ import { checkChapter, readChapter as readChapter2 } from "@beff/aula";
65
+ import { chapterNames } from "@beff/aula/run";
66
+ import { check as rules } from "@beff/aula/text";
67
+ async function clock(narrator, chapters) {
68
+ const narrations = [];
69
+ for (const cues of chapters) {
70
+ const timings = [];
71
+ for (const cue of cues) timings.push(await narrator.time(cue.text, cue.speed));
72
+ narrations.push(timeChapter(cues, timings));
73
+ }
74
+ return narrations;
75
+ }
76
+ function narrationAt(narrations, index) {
77
+ const narration = narrations[index];
78
+ if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
79
+ return narration;
80
+ }
81
+ var EMPTY = { heading: "", metaphor: "", paragraphs: [] };
82
+ function checkProject(project, host, only) {
83
+ const reads = project.chapters.map((_, i) => readChapter2(project, i + 1, { host }));
84
+ const unloaded = /* @__PURE__ */ new Map();
85
+ reads.forEach((r, i) => {
86
+ if (r.value === void 0) unloaded.set(i + 1, r.diagnostics);
87
+ });
88
+ const all = reads.map((r) => r.value ?? EMPTY);
89
+ const own = /* @__PURE__ */ new Map();
90
+ reads.forEach((r, i) => {
91
+ if (r.value !== void 0) own.set(i + 1, [...r.diagnostics, ...rules(r.value)]);
92
+ });
93
+ const targets = (only ?? chapterNames(project).map((_, i) => i)).filter((i) => !unloaded.has(i));
94
+ const inScope = (index) => only === null || only.includes(index);
95
+ if (![...own].some(([index, d]) => inScope(index) && d.some(isError))) {
96
+ for (const index of targets) {
97
+ const run = checkChapter(project, index, { host });
98
+ const text = all[index - 1];
99
+ own.set(index, [...run.diagnostics, ...index === 0 || text === void 0 ? [] : rules(text)]);
100
+ }
101
+ }
102
+ const byChapter = [...unloaded, ...[...own].toSorted(([a], [b]) => a - b)];
103
+ const reported = byChapter.flatMap(([index, d]) => inScope(index) ? d : []);
104
+ const elsewhere = byChapter.flatMap(([index, d]) => inScope(index) ? [] : d);
105
+ const errors = reported.filter(isError).length;
106
+ const otherErrors = elsewhere.filter(isError).length;
107
+ return {
108
+ findings: reported,
109
+ others: { errors: otherErrors, warnings: elsewhere.length - otherErrors },
110
+ errors,
111
+ warnings: reported.length - errors,
112
+ open: openCount(all, targets),
113
+ texts: all
114
+ };
115
+ }
116
+ function chapterIndexes(project, only) {
117
+ const names = chapterNames(project);
118
+ return only.length === 0 ? null : only.map((name) => chapterIndex(names, name));
119
+ }
120
+
121
+ // ../aula-project/src/export.ts
122
+ function exportCheck(project, host) {
123
+ const checked = checkProject(project, host, null);
124
+ const open = checked.texts.flatMap(
125
+ (t) => openMoves(t).map(
126
+ (m) => error(`show: the move "${m.note}" has no animation yet`, {
127
+ location: m.place,
128
+ hint: "give the show its move, show`note``25%`((s) => { \u2026 }), or make it a hold, show`note``25%`(() => {})"
129
+ })
130
+ )
131
+ );
132
+ return { ...checked, findings: [...checked.findings, ...open], errors: checked.errors + open.length };
133
+ }
134
+ function clipPlan(narrations, fps) {
135
+ const starts = [0];
136
+ for (const narration of narrations) starts.push((starts.at(-1) ?? 0) + narration.endFrame / narration.sampleRate);
137
+ const firsts = starts.map((seconds) => Math.round(seconds * fps));
138
+ const clips = narrations.map((_, index) => {
139
+ const first = firsts[index] ?? 0;
140
+ return { from: first / fps - (starts[index] ?? 0), frames: (firsts[index + 1] ?? first) - first };
141
+ });
142
+ return { clips, seconds: starts.at(-1) ?? 0 };
143
+ }
144
+
145
+ // ../aula-project/src/preview.ts
146
+ import { chapterNames as chapterNames2, FPS } from "@beff/aula/run";
147
+
148
+ // ../aula-project/src/stills.ts
149
+ import { moveFrames } from "@beff/aula/text";
150
+ function stillsOf(narration, text, frames) {
151
+ if (text === null) {
152
+ return [{ name: "title", cue: 0, place: null, note: "title card", frame: Math.floor(0.6 * frames) }];
153
+ }
154
+ const paragraphs = moveFrames(narration, text);
155
+ const moves = paragraphs.flatMap(
156
+ (p, k) => Array.from(p.moves, (start, i) => ({ start, cue: k + 1, move: text.paragraphs[k]?.moves[i] }))
157
+ );
158
+ return moves.flatMap(({ start, cue, move }, i) => {
159
+ if (move === void 0) return [];
160
+ const next = moves[i + 1]?.start ?? frames;
161
+ const name = `L${String(move.place.line).padStart(4, "0")}`;
162
+ return [{ name, cue, place: move.place, note: move.note, frame: Math.max(start, next - 1) }];
163
+ });
164
+ }
165
+ function paragraphWindow(narration, text, cue, frames) {
166
+ const paragraphs = moveFrames(narration, text);
167
+ const start = paragraphs[cue - 1]?.start;
168
+ if (start === void 0) throw new Error(`paragraph ${String(cue)} is not narrated`);
169
+ return [start, paragraphs[cue]?.start ?? frames];
170
+ }
171
+
172
+ // ../aula-project/src/preview.ts
173
+ function previewTargets(project, given) {
174
+ const names = chapterNames2(project);
175
+ if (given.length === 0) return names.map((name, index) => ({ index, name, line: null }));
176
+ return given.map((target) => {
177
+ const m = /^(.*):([0-9]+)$/.exec(target);
178
+ const index = chapterIndex(names, m?.[1] ?? target);
179
+ if (index === 0 && m !== null) throw wrongArgument("the title card has no lines: give a chapter name with :<line>");
180
+ return { index, name: names[index] ?? target, line: m?.[2] === void 0 ? null : Number(m[2]) };
181
+ });
182
+ }
183
+ var targetChapters = (targets, given) => given.length === 0 ? null : [...new Set(targets.map((t) => t.index))];
184
+ function previewJobs(targets, chapters) {
185
+ return targets.map((t) => {
186
+ const base = t.line === null ? t.name : `${t.name}-L${String(t.line)}`;
187
+ const text = t.index === 0 ? null : chapters[t.index - 1];
188
+ if (text === void 0) throw new Error(`no text of chapter ${t.name}`);
189
+ const cue = text === null || t.line === null ? null : paragraphCue(text, t.name, t.line);
190
+ return { ...t, base, text, cue };
191
+ });
192
+ }
193
+ function pictureStills(narration, job, frames) {
194
+ const { text, cue } = job;
195
+ const window = text === null || cue === null ? [0, frames] : paragraphWindow(narration, text, cue, frames);
196
+ const stills = stillsOf(narration, text, frames).filter((s) => cue === null || s.cue === cue);
197
+ return { window, stills };
198
+ }
199
+ function pictureGroups(window, stills) {
200
+ const [from, to] = window;
201
+ const motion = [];
202
+ for (let k = Math.ceil(from * 2 / FPS); Math.floor(k * FPS / 2) < to; k++) {
203
+ motion.push({ name: `t${(k / 2).toFixed(1).padStart(5, "0")}s`, frame: Math.floor(k * FPS / 2) });
204
+ }
205
+ return [
206
+ { folder: "stills", cols: 3, rows: 3, tiles: stills.map((s) => ({ name: s.name, frame: s.frame })) },
207
+ { folder: "motion", cols: 4, rows: 4, tiles: motion }
208
+ ];
209
+ }
210
+ function movesMarkdown(stills) {
211
+ return stills.map((still) => {
212
+ const at = still.place ? placeText(still.place) : "title card";
213
+ return `- ${at}, ${(still.frame / FPS).toFixed(1)} s: ${still.note} (stills/${still.name}.png)
214
+ `;
215
+ }).join("");
216
+ }
217
+
218
+ // ../aula-project/src/timeline.ts
219
+ import { renderChapter } from "@beff/aula";
220
+ import { chapterNames as chapterNames3 } from "@beff/aula/run";
221
+ import { narrationScript, timeline as timelineOf } from "@beff/aula/text";
222
+ async function timelineView(project, host, narrator, only) {
223
+ const names = chapterNames3(project);
224
+ const indexes = only.length === 0 ? project.chapters.map((_, i) => i + 1) : only.map((name) => chapterIndex(names, name));
225
+ if (indexes.includes(0)) throw wrongArgument("the title card has no timeline: give a chapter name");
226
+ const n = await clock(narrator, narrationScript(project.title, texts(project, host)));
227
+ let out = header(project);
228
+ for (const index of indexes) {
229
+ const text = chapterText(project, host, index);
230
+ const run = renderChapter(project, index, { host, narration: narrationAt(n, index), lint: true });
231
+ if (!run.ok || run.value === void 0) throw new Problems(run.diagnostics);
232
+ out += `
233
+ ## ${names[index] ?? ""}
234
+ Metaphor: ${text.metaphor}
235
+ `;
236
+ for (const line of timelineOf(run.value.narration, text)) out += `${line}
237
+ `;
238
+ }
239
+ return out;
240
+ }
241
+
242
+ // ../aula-project/src/workspace.ts
243
+ import * as Engine from "@beff/aula";
244
+ import { diagnosticOf, importUserModule, loadEngine } from "@beff/aula/run";
245
+ import {
246
+ narrationScript as narrationScript2
247
+ } from "@beff/aula/text";
248
+
249
+ // src/problems.ts
250
+ async function printDiagnostics(capabilities, root, diagnostics, print = (text) => capabilities.log.out(text)) {
251
+ await loadEngine2();
252
+ for (const d of diagnostics) print(renderDiagnostic(await withSource(capabilities, root, d)));
253
+ }
254
+
255
+ export {
256
+ scriptView,
257
+ clock,
258
+ narrationAt,
259
+ checkProject,
260
+ chapterIndexes,
261
+ exportCheck,
262
+ clipPlan,
263
+ previewTargets,
264
+ targetChapters,
265
+ previewJobs,
266
+ pictureStills,
267
+ pictureGroups,
268
+ movesMarkdown,
269
+ timelineView,
270
+ printDiagnostics
271
+ };