@beff/aula-cli 0.4.3 → 0.5.0

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 (53) hide show
  1. package/dist/src/aula-render.core.wasm +0 -0
  2. package/dist/src/{chunk-7KT36JRP.js → chunk-2NMVSQG4.js} +83 -93
  3. package/dist/src/{chunk-46KT47TH.js → chunk-5VYKT646.js} +1 -1
  4. package/dist/src/chunk-A5QHTZKT.js +6 -0
  5. package/dist/src/{chunk-CIFP475T.js → chunk-DQ2NGXNI.js} +6 -321
  6. package/dist/src/chunk-EQ3DVZV5.js +15 -0
  7. package/dist/src/chunk-IKKANHTF.js +94 -0
  8. package/dist/src/chunk-JDXHKYLZ.js +369 -0
  9. package/dist/src/chunk-JVCECTG2.js +77 -0
  10. package/dist/src/{chunk-BT3Z5CJI.js → chunk-YBHISJLN.js} +70 -31
  11. package/dist/src/cli.js +12 -7
  12. package/dist/src/{commands-QCUCX2GF.js → commands-34YCDSR5.js} +8 -5
  13. package/dist/src/{problems-7BVC64RO.js → problems-U4QXN6RO.js} +4 -2
  14. package/dist/src/project-WS7P5VIH.js +12 -0
  15. package/dist/src/render-child.js +284 -9
  16. package/dist/src/{run-5WC5WRZ2.js → run-7PM6EPND.js} +45 -9
  17. package/dist/src/{server-GK3EWFX3.js → server-YQYW4FT4.js} +6 -5
  18. package/dist/src/site-SVNNSF72.js +139 -0
  19. package/dist/web/app/assets/{ebd381c3 → 9733ee91}/aula-method.js +1 -1
  20. package/dist/web/app/assets/9733ee91/aula.js +1 -0
  21. package/dist/web/app/assets/{ebd381c3 → 9733ee91}/build-worker.js +2 -2
  22. package/dist/web/app/assets/9733ee91/index.js +52 -0
  23. package/dist/web/app/assets/__vite-browser-external-B57JSoUh.js +1 -0
  24. package/dist/web/app/assets/aula-voice-worker-CjOTYyla.js +52 -0
  25. package/dist/web/app/assets/{aula.core5-Bnq4-bLp.wasm → aula.core5-CfWXNps1.wasm} +0 -0
  26. package/dist/web/app/assets/{index-C_rGCAZR.css → index-BXxc0ZmT.css} +1 -1
  27. package/dist/web/app/assets/protocol-CylXac4E.js +15 -0
  28. package/dist/web/app/assets/src-CkCfHCj6.js +25 -0
  29. package/dist/web/app/index.html +4 -4
  30. package/dist/web/site/assets/64cc3acd/aula-method.js +1 -0
  31. package/dist/web/site/assets/64cc3acd/aula.js +1 -0
  32. package/dist/web/site/assets/64cc3acd/build-worker.js +696 -0
  33. package/dist/web/site/assets/64cc3acd/index.js +52 -0
  34. package/dist/web/site/assets/__vite-browser-external-BtQTJ51O.js +1 -0
  35. package/dist/web/site/assets/__vite-browser-external-uE9Q5hLF.js +1 -0
  36. package/dist/web/site/assets/aula-voice-worker-CbfByYTT.js +54 -0
  37. package/dist/web/site/assets/aula.core-BtiPQSZi.wasm +0 -0
  38. package/dist/web/site/assets/aula.core5-CfWXNps1.wasm +0 -0
  39. package/dist/web/site/assets/esbuild-BaXVPFT2.wasm +0 -0
  40. package/dist/web/site/assets/index-Dn5gqwRn.css +2 -0
  41. package/dist/web/site/assets/protocol-C4jhAcOf.js +15 -0
  42. package/dist/web/site/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
  43. package/dist/web/site/assets/src-BlEGe8aL.js +25 -0
  44. package/dist/web/site/index.html +39 -0
  45. package/package.json +2 -2
  46. package/dist/src/chunk-GFCJYE75.js +0 -42
  47. package/dist/src/project-NWT5MDQI.js +0 -11
  48. package/dist/web/app/assets/__vite-browser-external-BVodma7T.js +0 -1
  49. package/dist/web/app/assets/aula-voice-worker-D9iPLcHQ.js +0 -52
  50. package/dist/web/app/assets/ebd381c3/aula.js +0 -1
  51. package/dist/web/app/assets/ebd381c3/index.js +0 -52
  52. package/dist/web/app/assets/protocol-B46WpNW5.js +0 -15
  53. package/dist/web/app/assets/src-nkkXaLup.js +0 -25
@@ -0,0 +1,94 @@
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
+ async function hasAudio(capabilities, file) {
23
+ const { stderr } = await run(capabilities, "ffmpeg", ["-i", file]);
24
+ return /Stream #\S+: Audio:/.test(stderr);
25
+ }
26
+ var ffmpegColor = (color) => /^#[0-9a-fA-F]{6}$/.test(color) ? color : "black";
27
+ function overlayArgs(placed, background) {
28
+ const { width, height, fps } = VIDEO;
29
+ const fit = [
30
+ `fps=${String(fps)}`,
31
+ `scale=${String(width)}:${String(height)}:force_original_aspect_ratio=decrease`,
32
+ `pad=${String(width)}:${String(height)}:(ow-iw)/2:(oh-ih)/2:color=${ffmpegColor(background)}`,
33
+ "setsar=1"
34
+ ].join(",");
35
+ const inputs = [];
36
+ const graph = [];
37
+ const sounds = [];
38
+ let count = 2;
39
+ let video = "0:v";
40
+ placed.forEach((clip, i) => {
41
+ const at = clip.at.toFixed(3);
42
+ const end = (clip.at + clip.seconds).toFixed(3);
43
+ const length = clip.seconds.toFixed(3);
44
+ const main = count++;
45
+ inputs.push("-t", length, "-i", clip.file);
46
+ let picture = main;
47
+ if (clip.picture !== void 0) {
48
+ picture = count++;
49
+ inputs.push("-loop", "1", "-framerate", String(fps), "-t", length, "-i", clip.picture);
50
+ }
51
+ if (clip.seen) {
52
+ graph.push(
53
+ `[${String(picture)}:v]${fit},setpts=PTS-STARTPTS+${at}/TB[o${String(i)}]`,
54
+ `[${video}][o${String(i)}]overlay=eof_action=repeat:enable='between(t,${at},${end})'[v${String(i)}]`
55
+ );
56
+ video = `v${String(i)}`;
57
+ }
58
+ if (clip.heard) {
59
+ const ms = String(Math.round(clip.at * 1e3));
60
+ graph.push(`[${String(main)}:a]aresample=24000,aformat=channel_layouts=mono,adelay=${ms}:all=1[a${String(i)}]`);
61
+ sounds.push(`[a${String(i)}]`);
62
+ }
63
+ });
64
+ if (sounds.length > 0) {
65
+ graph.push(`[1:a]${sounds.join("")}amix=inputs=${String(sounds.length + 1)}:duration=first:normalize=0[mix]`);
66
+ }
67
+ const maps = [video === "0:v" ? "0:v:0" : `[${video}]`, sounds.length === 0 ? "1:a:0" : "[mix]"];
68
+ return [...inputs, "-filter_complex", graph.join(";"), "-map", maps[0] ?? "", "-map", maps[1] ?? ""];
69
+ }
70
+ var signed = (x) => `${x >= 0 ? "+" : ""}${x.toFixed(2)}`;
71
+ async function assemble(capabilities, options) {
72
+ const concat = path.join(options.work, "concat.txt");
73
+ await capabilities.fs.writeFile(concat, options.clips.map((v) => `file '${v}'
74
+ `).join(""));
75
+ const join = ["-f", "concat", "-safe", "0", "-i", concat, "-i", options.audio];
76
+ const placed = options.placed ?? [];
77
+ const mapped = placed.length === 0 ? ["-map", "0:v:0", "-map", "1:a:0"] : overlayArgs(placed, options.background ?? "black");
78
+ const video = placed.length === 0 ? ["-c:v", "copy"] : ["-c:v", "libx264", "-preset", "medium", "-crf", "18", "-pix_fmt", "yuv420p"];
79
+ const codecs = [...video, "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart"];
80
+ await ffmpeg(capabilities, [...join, ...mapped, ...codecs, options.out]);
81
+ const length = await duration(capabilities, options.out);
82
+ const diff = length - options.seconds;
83
+ capabilities.log.out(`video ${length.toFixed(2)}s narration ${options.seconds.toFixed(2)}s diff ${signed(diff)}s`);
84
+ if (Math.abs(diff) > 1 / VIDEO.fps) {
85
+ throw new Error(`Out of sync: video and narration differ by more than one frame (${options.out})`);
86
+ }
87
+ }
88
+
89
+ export {
90
+ VIDEO,
91
+ ffmpeg,
92
+ hasAudio,
93
+ assemble
94
+ };
@@ -0,0 +1,369 @@
1
+ import {
2
+ projectFiles,
3
+ zipBytes
4
+ } from "./chunk-DQ2NGXNI.js";
5
+ import {
6
+ VIDEO,
7
+ assemble,
8
+ ffmpeg,
9
+ hasAudio
10
+ } from "./chunk-IKKANHTF.js";
11
+ import {
12
+ printDiagnostics
13
+ } from "./chunk-EQ3DVZV5.js";
14
+ import {
15
+ chapterIndexes,
16
+ checkProject,
17
+ clipPlan,
18
+ clock,
19
+ exportCheck,
20
+ movesMarkdown,
21
+ narrationAt,
22
+ noteLine,
23
+ notesLine,
24
+ overlayPlan,
25
+ pictureGroups,
26
+ pictureStills,
27
+ previewJobs,
28
+ previewTargets,
29
+ scriptView,
30
+ targetChapters,
31
+ timelineView,
32
+ wordNotes
33
+ } from "./chunk-YBHISJLN.js";
34
+ import {
35
+ narrateScript,
36
+ scriptAudio,
37
+ wav
38
+ } from "./chunk-S74JLCZK.js";
39
+ import {
40
+ host
41
+ } from "./chunk-5VYKT646.js";
42
+ import {
43
+ folderOf,
44
+ nameOf
45
+ } from "./chunk-JVCECTG2.js";
46
+ import {
47
+ ObjectRuntype,
48
+ OptionalFieldRuntype,
49
+ RefRuntype,
50
+ TypeofRuntype,
51
+ buildParsers,
52
+ isError,
53
+ wrongArgument
54
+ } from "./chunk-2NMVSQG4.js";
55
+
56
+ // src/commands.ts
57
+ import path from "node:path";
58
+ import { m, renderChapter } from "@beff/aula";
59
+ import { chapterNames } from "@beff/aula/run";
60
+ import { narrationScript } from "@beff/aula/text";
61
+
62
+ // src/narrate.ts
63
+ function narrate(capabilities, chapters) {
64
+ return narrateScript(
65
+ (words) => capabilities.narrator.speak(words),
66
+ chapters,
67
+ (spoken, count, cue) => {
68
+ capabilities.log.out(`[${String(spoken)}/${String(count)}] Narrating: ${cue.text.slice(0, 70)}`);
69
+ }
70
+ );
71
+ }
72
+
73
+ // generated/parser.js
74
+ var RequiredStringFormats = [];
75
+ var RequiredNumberFormats = [];
76
+ var namedRuntypes = {};
77
+ var stringFormatters = {};
78
+ var numberFormatters = {};
79
+ var direct_hoist_0 = new RefRuntype(void 0, "TokensLine", namedRuntypes);
80
+ var direct_hoist_1 = new TypeofRuntype(void 0, "string");
81
+ var direct_hoist_2 = new ObjectRuntype({
82
+ "description": "One input line of `aula tokens`: a text, and an optional id that the output line repeats."
83
+ }, {
84
+ "id": new OptionalFieldRuntype(direct_hoist_1),
85
+ "text": direct_hoist_1
86
+ }, []);
87
+ Object.assign(namedRuntypes, {
88
+ "TokensLine": direct_hoist_2
89
+ });
90
+ var buildParsersInput = {
91
+ "TokensLine": direct_hoist_0
92
+ };
93
+ var parser_default = {
94
+ buildParsers: (args) => buildParsers(
95
+ {
96
+ parsers: buildParsersInput,
97
+ stringFormatters,
98
+ numberFormatters,
99
+ requiredStringFormats: RequiredStringFormats,
100
+ requiredNumberFormats: RequiredNumberFormats
101
+ },
102
+ args
103
+ )
104
+ };
105
+
106
+ // src/parsers.ts
107
+ var Parsers = parser_default.buildParsers();
108
+
109
+ // src/commands.ts
110
+ async function withHeavy(capabilities, f) {
111
+ const release = await capabilities.locks.heavy();
112
+ try {
113
+ return await f();
114
+ } finally {
115
+ await release();
116
+ }
117
+ }
118
+ async function withWork(capabilities, f) {
119
+ const work = await capabilities.fs.mkdtemp(path.join(capabilities.env.temp, "aula-"));
120
+ try {
121
+ return await f(work);
122
+ } finally {
123
+ await capabilities.fs.rm(work, { recursive: true, force: true });
124
+ }
125
+ }
126
+ async function parallel(items, limit, task) {
127
+ let next = 0;
128
+ const worker = async () => {
129
+ for (let item = items[next++]; item !== void 0; item = items[next++]) await task(item);
130
+ };
131
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
132
+ }
133
+ async function drawChapter(capabilities, root, project, index, narration, lottie) {
134
+ const built = renderChapter(project, index, { host: host(capabilities, root), narration });
135
+ if (!built.ok || built.value === void 0) {
136
+ return { ok: false, findings: built.diagnostics, frames: 0, waits: [], embeds: [], narration };
137
+ }
138
+ await capabilities.fs.writeFile(lottie, built.value.lottie, "utf8");
139
+ const { frames, waits, embeds } = built.value;
140
+ return { ok: true, findings: built.diagnostics, frames, waits, embeds, narration: built.value.narration };
141
+ }
142
+ async function placedClips(capabilities, folder, overlays) {
143
+ return Promise.all(
144
+ overlays.map(async (o) => {
145
+ const file = path.join(folder, o.path);
146
+ const picture = o.image === void 0 ? void 0 : path.join(folder, o.image);
147
+ const video = o.kind === "video";
148
+ return {
149
+ file,
150
+ picture,
151
+ seen: video || picture !== void 0,
152
+ heard: !video || await hasAudio(capabilities, file),
153
+ at: o.at,
154
+ seconds: o.seconds
155
+ };
156
+ })
157
+ );
158
+ }
159
+ var inFolder = (folder, groups) => groups.map((group) => ({
160
+ ...group,
161
+ tiles: group.tiles.map((tile) => {
162
+ const { embed } = tile;
163
+ if (embed?.picture === void 0) return tile;
164
+ return { ...tile, embed: { ...embed, picture: path.join(folder, embed.picture) } };
165
+ })
166
+ }));
167
+ var rowLine = (project, r) => `${nameOf(project)}: ${String(r.errors)} errors, ${String(r.warnings)} warnings, ${String(r.open)} open moves`;
168
+ async function printChecked(capabilities, root, project, checked) {
169
+ await printDiagnostics(capabilities, root, checked.findings);
170
+ printCounts(capabilities, project, checked);
171
+ }
172
+ function printCounts(capabilities, project, checked) {
173
+ const { errors, warnings } = checked.others;
174
+ if (errors + warnings > 0)
175
+ capabilities.log.out(`other chapters: ${String(errors)} errors, ${String(warnings)} warnings`);
176
+ capabilities.log.out(rowLine(project, checked));
177
+ }
178
+ async function check(capabilities, root, project, only, json = false) {
179
+ const chapters = chapterIndexes(project, only);
180
+ const checked = checkProject(project, host(capabilities, root), chapters);
181
+ const notes = wordNotes(narrationScript(project, checked.texts), chapters);
182
+ if (json) {
183
+ const { findings, others, errors, warnings, open } = checked;
184
+ const result = { name: nameOf(project), errors, warnings, openMoves: open, others, findings, notes };
185
+ capabilities.log.out(JSON.stringify(result, null, 2));
186
+ return errors === 0;
187
+ }
188
+ await printDiagnostics(capabilities, root, checked.findings);
189
+ for (const note of notes) capabilities.log.out(noteLine(note));
190
+ if (notes.length > 0) capabilities.log.out(notesLine(notes));
191
+ printCounts(capabilities, project, checked);
192
+ return checked.errors === 0;
193
+ }
194
+ async function script(capabilities, root, project) {
195
+ capabilities.log.write(scriptView(project, host(capabilities, root)));
196
+ return true;
197
+ }
198
+ async function timeline(capabilities, root, project, only) {
199
+ capabilities.log.write(await timelineView(project, host(capabilities, root), capabilities.narrator, only));
200
+ return true;
201
+ }
202
+ async function preview(capabilities, root, project, folder, given) {
203
+ const targets = previewTargets(project, given);
204
+ const checked = checkProject(project, host(capabilities, root), targetChapters(targets, given));
205
+ await printChecked(capabilities, root, project, checked);
206
+ if (checked.errors > 0) return false;
207
+ const all = checked.texts;
208
+ const n = await clock(capabilities.narrator, narrationScript(project, all));
209
+ const jobs = previewJobs(targets, all).map((job) => ({
210
+ ...job,
211
+ out: path.join(folder, job.base),
212
+ written: []
213
+ }));
214
+ return withWork(capabilities, async (work) => {
215
+ for (const job of jobs) await capabilities.fs.rm(job.out, { recursive: true, force: true });
216
+ const stopped = [];
217
+ const waits = [];
218
+ await withHeavy(
219
+ capabilities,
220
+ () => parallel(jobs, capabilities.env.parallelism, async (job) => {
221
+ const lottie = path.join(work, `${job.base}.json`);
222
+ const drawn = await drawChapter(capabilities, root, project, job.index, narrationAt(n, job.index), lottie);
223
+ if (!drawn.ok) {
224
+ stopped.push(...drawn.findings);
225
+ return;
226
+ }
227
+ waits.push(...drawn.findings.filter((d) => !isError(d)));
228
+ const { out } = job;
229
+ const { window, stills } = pictureStills(drawn.narration, job, drawn.frames, drawn.embeds);
230
+ const groups = inFolder(folderOf(project), pictureGroups(window, stills));
231
+ const sheets = await capabilities.render.pictures({ lottie, out, groups });
232
+ await capabilities.fs.mkdir(out, { recursive: true });
233
+ await capabilities.fs.writeFile(path.join(out, "moves.md"), movesMarkdown(stills));
234
+ job.written.push(path.join(out, "moves.md"), ...sheets);
235
+ })
236
+ );
237
+ if (stopped.length) {
238
+ await printDiagnostics(capabilities, root, stopped);
239
+ return false;
240
+ }
241
+ await printDiagnostics(capabilities, root, waits);
242
+ for (const line of jobs.flatMap((job) => job.written)) capabilities.log.out(line);
243
+ return true;
244
+ });
245
+ }
246
+ async function exportVideo(capabilities, root, project, file) {
247
+ if (!file.endsWith(".mp4")) throw wrongArgument(`the video path must end in .mp4: ${file}`);
248
+ const names = chapterNames(project);
249
+ const checked = exportCheck(project, host(capabilities, root));
250
+ await printChecked(capabilities, root, project, checked);
251
+ if (checked.errors > 0) {
252
+ capabilities.log.out(`export ${nameOf(project)}: stopped at check: fix the errors above`);
253
+ return false;
254
+ }
255
+ await ffmpeg(capabilities, ["-version"]);
256
+ return withWork(capabilities, async (work) => {
257
+ const audio = path.join(work, "narration.wav");
258
+ const cues = narrationScript(project, checked.texts);
259
+ const narrated = await withHeavy(capabilities, () => narrate(capabilities, cues));
260
+ const lotties = names.map((name) => path.join(work, `${name}.json`));
261
+ const drawn = [];
262
+ const problems = [];
263
+ let done = 0;
264
+ await withHeavy(
265
+ capabilities,
266
+ () => parallel(
267
+ names.map((_, index) => index),
268
+ capabilities.env.parallelism,
269
+ async (index) => {
270
+ const narration = narrated[index]?.narration;
271
+ if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
272
+ const chapter = await drawChapter(capabilities, root, project, index, narration, lotties[index] ?? "");
273
+ drawn[index] = chapter;
274
+ if (!chapter.ok) problems.push(...chapter.findings);
275
+ done += 1;
276
+ capabilities.log.out(
277
+ `[${String(done)}/${String(names.length)}] ${names[index] ?? ""}: ${chapter.ok ? "drawn" : "FAILED"}`
278
+ );
279
+ }
280
+ )
281
+ );
282
+ if (problems.length) {
283
+ await printDiagnostics(capabilities, root, problems);
284
+ return false;
285
+ }
286
+ const { samples, sampleRate } = scriptAudio(
287
+ narrated,
288
+ drawn.map((d) => d.waits)
289
+ );
290
+ await capabilities.fs.writeFile(audio, wav(samples, sampleRate));
291
+ capabilities.log.out(`Narrated ${(samples.length / sampleRate / 60).toFixed(1)} minutes`);
292
+ const plan = clipPlan(
293
+ drawn.map((d) => d.narration),
294
+ VIDEO.fps
295
+ );
296
+ const clips = names.map((name) => path.join(work, `${name}.mp4`));
297
+ await withHeavy(
298
+ capabilities,
299
+ () => parallel(
300
+ names.map((_, index) => index),
301
+ capabilities.env.parallelism,
302
+ async (index) => {
303
+ const clip = plan.clips[index] ?? { from: 0, frames: 0 };
304
+ await capabilities.render.clip({ lottie: lotties[index] ?? "", out: clips[index] ?? "", ...clip });
305
+ }
306
+ )
307
+ );
308
+ await capabilities.fs.mkdir(path.dirname(file), { recursive: true });
309
+ const placed = await placedClips(
310
+ capabilities,
311
+ folderOf(project),
312
+ overlayPlan(
313
+ drawn.map((d) => d.narration),
314
+ drawn.map((d) => d.embeds)
315
+ )
316
+ );
317
+ const background = (project.theme ?? m.theme).background;
318
+ await assemble(capabilities, { work, clips, audio, seconds: plan.seconds, out: file, placed, background });
319
+ capabilities.log.out(file);
320
+ return true;
321
+ });
322
+ }
323
+ async function bundle(capabilities, project, file) {
324
+ if (!file.endsWith(".zip")) throw new Error(`the zip path must end in .zip: ${file}`);
325
+ const home = folderOf(project);
326
+ const root = path.parse(home).root;
327
+ const folder = path.relative(root, home).split(path.sep).join("/");
328
+ const esbuild = await import("esbuild-wasm");
329
+ let files;
330
+ try {
331
+ files = await projectFiles(capabilities, esbuild, root, folder);
332
+ } finally {
333
+ await esbuild.stop();
334
+ }
335
+ const entries = /* @__PURE__ */ new Map();
336
+ for (const [at, from] of files)
337
+ entries.set(at, new Uint8Array(await capabilities.fs.readFile(path.join(root, from))));
338
+ const zip = zipBytes(entries);
339
+ await capabilities.fs.mkdir(path.dirname(file), { recursive: true });
340
+ await capabilities.fs.writeFile(file, zip);
341
+ capabilities.log.out(`${file}: ${String(files.size)} files, ${String(Math.ceil(zip.length / 1024))} kB`);
342
+ return true;
343
+ }
344
+ async function tokens(capabilities, tokensOf, lines) {
345
+ let number = 0;
346
+ for await (const line of lines) {
347
+ number += 1;
348
+ if (!line.trim()) continue;
349
+ const parsed = Parsers.TokensLine.safeParse(JSON.parse(line));
350
+ if (!parsed.success) throw wrongArgument(`stdin line ${String(number)}: expected {"id"?: string, "text": string}`);
351
+ const { id, text } = parsed.data;
352
+ capabilities.log.out(JSON.stringify({ ...id === void 0 ? {} : { id }, batches: await tokensOf(text) }));
353
+ }
354
+ return true;
355
+ }
356
+ function tokensArgs(positional) {
357
+ if (positional.length > 0) throw wrongArgument("aula tokens takes no arguments", "run `aula help` for the usage");
358
+ }
359
+
360
+ export {
361
+ check,
362
+ script,
363
+ timeline,
364
+ preview,
365
+ exportVideo,
366
+ bundle,
367
+ tokens,
368
+ tokensArgs
369
+ };
@@ -0,0 +1,77 @@
1
+ import {
2
+ Problems,
3
+ error,
4
+ projectName,
5
+ wrongArgument
6
+ } from "./chunk-2NMVSQG4.js";
7
+
8
+ // ../aula-project/src/node.ts
9
+ import path from "node:path";
10
+ import { pathToFileURL } from "node:url";
11
+ import { isProjectDefinition } from "@beff/aula";
12
+ import { definedAt, loadEngine, v8Frames } from "@beff/aula/run";
13
+ var PROJECT_MODULE = "index.ts";
14
+ var GLUE = [
15
+ `${path.dirname(new URL(import.meta.resolve("@beff/aula")).pathname)}/`,
16
+ new URL(import.meta.url).pathname
17
+ ];
18
+ function host(capabilities, root, glue = []) {
19
+ const all = [...GLUE, ...glue];
20
+ return {
21
+ frames: v8Frames,
22
+ name: (file) => file.startsWith("/") && !file.includes("/node_modules/") && !all.some((g) => file.startsWith(g)) ? path.relative(root, file) : void 0,
23
+ exists: (file) => capabilities.fs.existsSync(path.resolve(root, file)),
24
+ media: (file) => {
25
+ const full = path.resolve(root, file);
26
+ const stat = capabilities.fs.statSync(full, { throwIfNoEntry: false });
27
+ if (stat === void 0 || !stat.isFile()) return void 0;
28
+ let bytes;
29
+ return { size: stat.size, read: () => bytes ??= capabilities.fs.readFileSync(full) };
30
+ }
31
+ };
32
+ }
33
+ function propertyOf(e, key) {
34
+ return typeof e === "object" && e !== null ? Reflect.get(e, key) : void 0;
35
+ }
36
+ async function loadProject(capabilities, load, root, folder) {
37
+ const file = path.join(folder, PROJECT_MODULE);
38
+ if (!capabilities.fs.existsSync(file)) {
39
+ throw wrongArgument(
40
+ `${path.relative(root, folder) || "."} has no ${PROJECT_MODULE}`,
41
+ `give the project folder: the folder with ${PROJECT_MODULE}`
42
+ );
43
+ }
44
+ await loadEngine();
45
+ const module = await load(pathToFileURL(file).href);
46
+ const exported = propertyOf(module, "default");
47
+ if (!isProjectDefinition(exported)) {
48
+ const rel = path.relative(root, file);
49
+ throw new Problems([
50
+ error(`the default export of ${rel} is not made by defineProject`, {
51
+ location: { file: rel, line: 1, col: 0 },
52
+ hint: "write `export default defineProject({ title, theme, chapters: [ \u2026 ] })`"
53
+ })
54
+ ]);
55
+ }
56
+ return exported;
57
+ }
58
+ var folderOf = (project) => path.dirname(definedAt(project).file);
59
+ var nameOf = (project) => projectName(path.basename(folderOf(project)));
60
+ async function withSource(capabilities, root, d) {
61
+ if (d.source !== void 0 || d.location === void 0) return d;
62
+ const file = path.resolve(root, d.location.file);
63
+ if (!capabilities.fs.existsSync(file)) return d;
64
+ const text = await capabilities.fs.readFile(file, "utf8");
65
+ const lines = text.split("\n");
66
+ if (lines.at(-1) === "") lines.pop();
67
+ const line = lines[d.location.line - 1];
68
+ return line === void 0 || d.location.line < 1 ? d : { ...d, source: line.replace(/\r$/, "") };
69
+ }
70
+
71
+ export {
72
+ host,
73
+ loadProject,
74
+ folderOf,
75
+ nameOf,
76
+ withSource
77
+ };