@beff/aula-cli 0.6.1 → 0.7.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 (52) hide show
  1. package/dist/src/{chunk-XYBGXFIM.js → chunk-HLRTXRAC.js} +63 -42
  2. package/dist/src/{chunk-6CZECZIX.js → chunk-JWAUET3S.js} +374 -15
  3. package/dist/src/{chunk-6LC3WXJ7.js → chunk-PLBRKNMD.js} +20 -5
  4. package/dist/src/{chunk-3MPFI4UE.js → chunk-RRS3SD7K.js} +41 -18
  5. package/dist/src/chunk-STW7EAFL.js +127 -0
  6. package/dist/src/chunk-THQ5Y74K.js +64 -0
  7. package/dist/src/{chunk-32AJJP3R.js → chunk-UKSA5OFC.js} +1 -1
  8. package/dist/src/{chunk-ZASMFCUL.js → chunk-WY3AMP6M.js} +5 -4
  9. package/dist/src/cli.js +23 -13
  10. package/dist/src/{commands-KNPNJHDC.js → commands-NDTPHXGF.js} +8 -8
  11. package/dist/src/problems-CQXPY4G5.js +14 -0
  12. package/dist/src/project-ICPIW4MO.js +12 -0
  13. package/dist/src/{run-V3U7HCKB.js → run-IBCNVZ4J.js} +8 -8
  14. package/dist/src/{server-KTS6ORJM.js → server-QQ2V343V.js} +84 -27
  15. package/dist/src/{site-VW2NSQV5.js → site-XYQKQZLZ.js} +33 -65
  16. package/dist/web/app/assets/{72474bf9 → 7ca1e7de}/aula-method.js +1 -1
  17. package/dist/web/app/assets/{72474bf9 → 7ca1e7de}/aula.js +1 -1
  18. package/dist/web/app/assets/7ca1e7de/build-worker.js +2 -0
  19. package/dist/web/app/assets/7ca1e7de/index.js +52 -0
  20. package/dist/web/app/assets/__vite-browser-external-CZjgZoe-.js +1 -0
  21. package/dist/web/app/assets/{aula-voice-worker-DxzRCbJL.js → aula-voice-worker-CjeRSu86.js} +10 -10
  22. package/dist/web/app/assets/{aula.core5-BdGr7QcG.wasm → aula.core5-DVDCNzCV.wasm} +0 -0
  23. package/dist/web/app/assets/{72474bf9/build-worker.js → browser-sNTR4ahh.js} +4 -5
  24. package/dist/web/app/assets/esbuild-D6hmBtXM.js +1 -0
  25. package/dist/web/{site/assets/index-Dcly6eU3.css → app/assets/index-CFRTa3wf.css} +1 -1
  26. package/dist/web/app/assets/protocol-CVAj9kTL.js +15 -0
  27. package/dist/web/app/assets/{src-Cz8PghaR.js → src-uzFdGdZX.js} +2 -3
  28. package/dist/web/app/index.html +28 -4
  29. package/dist/web/site/assets/{9db97082 → 8f69161f}/aula-method.js +1 -1
  30. package/dist/web/site/assets/{9db97082 → 8f69161f}/aula.js +1 -1
  31. package/dist/web/site/assets/8f69161f/build-worker.js +2 -0
  32. package/dist/web/site/assets/8f69161f/index.js +52 -0
  33. package/dist/web/site/assets/__vite-browser-external-lWmWnTMm.js +1 -0
  34. package/dist/web/site/assets/{aula-voice-worker-CzRFydP2.js → aula-voice-worker-Sm-si1oe.js} +10 -12
  35. package/dist/web/site/assets/{aula.core5-BdGr7QcG.wasm → aula.core5-DVDCNzCV.wasm} +0 -0
  36. package/dist/web/site/assets/{9db97082/build-worker.js → browser-sNTR4ahh.js} +4 -5
  37. package/dist/web/site/assets/esbuild-CW5RQptO.js +1 -0
  38. package/dist/web/{app/assets/index-DtOukfzG.css → site/assets/index-CFRTa3wf.css} +1 -1
  39. package/dist/web/site/assets/protocol-47nVPHKy.js +15 -0
  40. package/dist/web/site/assets/{src-71sAnADq.js → src-DWVrqSqZ.js} +2 -3
  41. package/dist/web/site/index.html +28 -4
  42. package/package.json +2 -2
  43. package/dist/src/chunk-KQJVAXSC.js +0 -369
  44. package/dist/src/chunk-NAMV5OAS.js +0 -77
  45. package/dist/src/problems-P6M3366O.js +0 -14
  46. package/dist/src/project-BZL5K5BR.js +0 -12
  47. package/dist/web/app/assets/72474bf9/index.js +0 -53
  48. package/dist/web/app/assets/__vite-browser-external-CS_r4ncq.js +0 -1
  49. package/dist/web/app/assets/protocol-DqAun5Af.js +0 -15
  50. package/dist/web/site/assets/9db97082/index.js +0 -53
  51. package/dist/web/site/assets/__vite-browser-external-CTYaiPUZ.js +0 -1
  52. package/dist/web/site/assets/protocol-DPaQDdsV.js +0 -15
@@ -2,13 +2,13 @@ import {
2
2
  timeChapter
3
3
  } from "./chunk-S74JLCZK.js";
4
4
  import {
5
+ LIST_MODULE,
5
6
  Problems,
6
- bundle,
7
7
  error,
8
8
  isError,
9
- projectModules,
9
+ linkBundle,
10
10
  wrongArgument
11
- } from "./chunk-3MPFI4UE.js";
11
+ } from "./chunk-RRS3SD7K.js";
12
12
 
13
13
  // ../aula-project/src/chapters.ts
14
14
  import { readChapter } from "@beff/aula";
@@ -60,18 +60,39 @@ function openCount(chapters, indexes) {
60
60
  // ../aula-project/src/check.ts
61
61
  import { checkChapter, checkLexicon, checkTitle, readChapter as readChapter2 } from "@beff/aula";
62
62
  import { chapterNames } from "@beff/aula/run";
63
- import { check as rules } from "@beff/aula/text";
64
- async function clock(narrator, chapters) {
65
- const narrations = [];
66
- for (const cues of chapters) {
63
+ import { check as rules, phonemize } from "@beff/aula/text";
64
+ var hasSpokenSound = (spoken) => Array.from(phonemize(spoken)).some((c) => new RegExp("\\p{L}", "u").test(c) && c !== "\u02C8" && c !== "\u02CC");
65
+ function cueLocation(place) {
66
+ if (place === void 0) return void 0;
67
+ const colon = place.lastIndexOf(":");
68
+ const line = Number(place.slice(colon + 1));
69
+ return colon > 0 && Number.isInteger(line) ? { file: place.slice(0, colon), line, col: 0 } : void 0;
70
+ }
71
+ async function clock(narrator, chapters, only = null, names = []) {
72
+ const narrations = /* @__PURE__ */ new Map();
73
+ for (const [index, cues] of chapters.entries()) {
74
+ if (only !== null && !only.includes(index)) continue;
67
75
  const timings = [];
68
- for (const cue of cues) timings.push(await narrator.time(cue.words));
69
- narrations.push(timeChapter(cues, timings));
76
+ for (const cue of cues) {
77
+ const spoken = cue.words.join(" ");
78
+ if (!cue.words.length || !hasSpokenSound(spoken)) {
79
+ const chapter = names[index] ?? `chapter ${String(index)}`;
80
+ const location = cueLocation(cue.place);
81
+ throw new Problems([
82
+ error(`cannot narrate ${cue.kind} in ${chapter}: ${JSON.stringify(cue.text)} has no spoken words`, {
83
+ ...location === void 0 ? {} : { location },
84
+ hint: `give the ${cue.kind} words that the narrator can say`
85
+ })
86
+ ]);
87
+ }
88
+ timings.push(await narrator.time(cue.words));
89
+ }
90
+ narrations.set(index, timeChapter(cues, timings));
70
91
  }
71
92
  return narrations;
72
93
  }
73
94
  function narrationAt(narrations, index) {
74
- const narration = narrations[index];
95
+ const narration = narrations.get(index);
75
96
  if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
76
97
  return narration;
77
98
  }
@@ -298,17 +319,24 @@ function movesMarkdown(stills) {
298
319
  }
299
320
 
300
321
  // ../aula-project/src/timeline.ts
301
- import { renderChapter } from "@beff/aula";
322
+ import { readChapter as readChapter3, renderChapter } from "@beff/aula";
302
323
  import { chapterNames as chapterNames3 } from "@beff/aula/run";
303
324
  import { narrationScript, timeline as timelineOf } from "@beff/aula/text";
325
+ var EMPTY2 = { heading: "", headingSpoken: "", metaphor: "", paragraphs: [] };
304
326
  async function timelineView(project, host, narrator, only) {
305
327
  const names = chapterNames3(project);
306
328
  const indexes = only.length === 0 ? project.chapters.map((_, i) => i + 1) : only.map((name) => chapterIndex(names, name));
307
329
  if (indexes.includes(0)) throw wrongArgument("the title card has no timeline: give a chapter name");
308
- const n = await clock(narrator, narrationScript(project, texts(project, host)));
330
+ const loaded = /* @__PURE__ */ new Map();
331
+ for (const index of indexes) loaded.set(index, chapterText(project, host, index));
332
+ const all = project.chapters.map((_, i) => {
333
+ const index = i + 1;
334
+ return loaded.get(index) ?? readChapter3(project, index, { host }).value ?? EMPTY2;
335
+ });
336
+ const n = await clock(narrator, narrationScript(project, all), indexes, names);
309
337
  let out = header(project);
310
338
  for (const index of indexes) {
311
- const text = chapterText(project, host, index);
339
+ const text = loaded.get(index) ?? chapterText(project, host, index);
312
340
  const run = renderChapter(project, index, { host, narration: narrationAt(n, index), lint: true });
313
341
  if (!run.ok || run.value === void 0) throw new Problems(run.diagnostics);
314
342
  out += `
@@ -334,44 +362,37 @@ var workspaceHost = (frames, media) => ({
334
362
  ...media ? { media } : {}
335
363
  });
336
364
  var propertyOf = (value, key) => typeof value === "object" && value !== null ? Reflect.get(value, key) : void 0;
337
- var LIST = "aula-projects.ts";
338
- async function loadProjects(files, host, modules, esbuild, player) {
339
- const root = await files.name();
340
- const listed = await projectModules(files, root);
341
- if (listed._tag === "Left") return listed;
342
- const found = listed.right.map((project) => project.module);
343
- if (found.length === 0) {
344
- throw new Error("no project here: open a folder that has index.ts, or whose subfolders have index.ts");
345
- }
346
- const list = [
347
- ...found.map((module, i) => `import p${String(i)} from ${JSON.stringify(`./${module}`)};`),
348
- `export default [${found.map((_, i) => `p${String(i)}`).join(", ")}];`
349
- ].join("\n");
350
- const tree = {
351
- read: (path) => path === LIST ? Promise.resolve(list) : files.read(path),
352
- list: (folder) => files.list(folder)
353
- };
354
- const [bundled] = await Promise.all([bundle(esbuild, tree, LIST, player), loadEngine()]);
355
- if (bundled._tag === "Left") return bundled;
356
- const loaded = await importUserModule(() => modules.load(bundled.right));
357
- if (loaded._tag === "Left") return { _tag: "Left", left: [diagnosticOf(loaded.left, LIST, host)] };
365
+ async function loadBuiltProjects(bundled, host, modules, player, engineLoaded) {
366
+ await loadEngine();
367
+ engineLoaded?.();
368
+ const code = linkBundle(bundled.code, player);
369
+ const loaded = await importUserModule(() => modules.load({ code, map: bundled.map }));
370
+ if (loaded._tag === "Left") return { _tag: "Left", left: [diagnosticOf(loaded.left, LIST_MODULE, host)] };
358
371
  const exported = propertyOf(loaded.right.exports, "default");
359
- if (!Array.isArray(exported)) throw new Error(`${LIST} has no list of projects`);
372
+ if (!Array.isArray(exported)) throw new Error(`${LIST_MODULE} has no list of projects`);
360
373
  const out = exported.map((definition, i) => {
374
+ const project = bundled.projects[i];
361
375
  if (!Engine.isProjectDefinition(definition)) {
362
376
  throw new Error(
363
- `the default export of ${found[i] ?? ""} is not made by defineProject: write \`export default defineProject({ title, theme, chapters: [ \u2026 ] })\``
377
+ `the default export of ${project?.module ?? ""} is not made by defineProject: write \`export default defineProject({ title, theme, chapters: [ \u2026 ] })\``
364
378
  );
365
379
  }
366
- const { name, section } = listed.right[i] ?? { name: "" };
367
- return localProject(name, section, definition, host);
380
+ return localProject(
381
+ project?.name ?? "",
382
+ folderOfModule(project?.module ?? "index.ts"),
383
+ project?.section,
384
+ definition,
385
+ host
386
+ );
368
387
  });
369
388
  return { _tag: "Right", right: out };
370
389
  }
371
- function localProject(name, section, definition, host) {
390
+ var folderOfModule = (module) => module.slice(0, Math.max(0, module.lastIndexOf("/")));
391
+ function localProject(name, folder, section, definition, host) {
372
392
  const count = definition.chapters.length + 1;
373
393
  return {
374
394
  name,
395
+ folder,
375
396
  ...section === void 0 ? {} : { section },
376
397
  title: definition.title,
377
398
  chapters: count,
@@ -386,8 +407,8 @@ function localProject(name, section, definition, host) {
386
407
  const script = narrationScript2(definition, chapters);
387
408
  return { _tag: "Right", right: { script } };
388
409
  },
389
- walk: () => {
390
- for (const i of definition.chapters.keys()) Engine.checkChapter(definition, i + 1, { host });
410
+ walk: (index) => {
411
+ if (index > 0) Engine.checkChapter(definition, index, { host });
391
412
  },
392
413
  render: (index, narration) => {
393
414
  const run = Engine.renderChapter(definition, index, { host, narration });
@@ -431,5 +452,5 @@ export {
431
452
  movesMarkdown,
432
453
  timelineView,
433
454
  workspaceHost,
434
- loadProjects
455
+ loadBuiltProjects
435
456
  };
@@ -1,8 +1,66 @@
1
1
  import {
2
+ VIDEO,
3
+ assemble,
4
+ ffmpeg,
5
+ hasAudio
6
+ } from "./chunk-BLKXJGEO.js";
7
+ import {
8
+ printDiagnostics
9
+ } from "./chunk-UKSA5OFC.js";
10
+ import {
11
+ chapterIndexes,
12
+ checkProject,
13
+ clipPlan,
14
+ clock,
15
+ exportCheck,
16
+ movesMarkdown,
17
+ narrationAt,
18
+ noteLine,
19
+ notesLine,
20
+ overlayPlan,
21
+ pictureGroups,
22
+ pictureStills,
23
+ previewJobs,
24
+ previewTargets,
25
+ scriptView,
26
+ targetChapters,
27
+ timelineView,
28
+ wordNotes
29
+ } from "./chunk-HLRTXRAC.js";
30
+ import {
31
+ createNodeBundler
32
+ } from "./chunk-THQ5Y74K.js";
33
+ import {
34
+ narrateScript,
35
+ scriptAudio,
36
+ wav
37
+ } from "./chunk-S74JLCZK.js";
38
+ import {
39
+ host
40
+ } from "./chunk-WY3AMP6M.js";
41
+ import {
42
+ folderOf,
43
+ nameOf
44
+ } from "./chunk-STW7EAFL.js";
45
+ import {
46
+ ObjectRuntype,
47
+ OptionalFieldRuntype,
48
+ PROVIDED,
2
49
  Parsers,
3
50
  Problems,
4
- bundle
5
- } from "./chunk-3MPFI4UE.js";
51
+ RefRuntype,
52
+ TypeofRuntype,
53
+ buildParsers,
54
+ bundle,
55
+ isError,
56
+ wrongArgument
57
+ } from "./chunk-RRS3SD7K.js";
58
+
59
+ // src/commands.ts
60
+ import path2 from "node:path";
61
+ import { m, renderChapter } from "@beff/aula";
62
+ import { chapterNames } from "@beff/aula/run";
63
+ import { narrationScript } from "@beff/aula/text";
6
64
 
7
65
  // ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs
8
66
  import { createRequire } from "module";
@@ -139,7 +197,7 @@ var hMap = (function(cd, mb, r) {
139
197
  var sv = i2 << 4 | cd[i2];
140
198
  var r_1 = mb - cd[i2];
141
199
  var v = le[cd[i2] - 1]++ << r_1;
142
- for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
200
+ for (var m2 = v | (1 << r_1) - 1; v <= m2; ++v) {
143
201
  co[rev[v] >> rvb] = sv;
144
202
  }
145
203
  }
@@ -688,7 +746,7 @@ function zipSync(data, opts) {
688
746
  var _a2 = r[fn], file = _a2[0], p = _a2[1];
689
747
  var compression = p.level == 0 ? 0 : 8;
690
748
  var f = strToU8(fn), s = f.length;
691
- var com = p.comment, m = com && strToU8(com), ms = m && m.length;
749
+ var com = p.comment, m2 = com && strToU8(com), ms = m2 && m2.length;
692
750
  var exl = exfl(p.extra);
693
751
  if (s > 65535)
694
752
  err(11);
@@ -700,8 +758,8 @@ function zipSync(data, opts) {
700
758
  crc: c.d(),
701
759
  c: d,
702
760
  f,
703
- m,
704
- u: s != fn.length || m && com.length != ms,
761
+ m: m2,
762
+ u: s != fn.length || m2 && com.length != ms,
705
763
  o,
706
764
  compression
707
765
  }));
@@ -721,7 +779,6 @@ function zipSync(data, opts) {
721
779
  }
722
780
 
723
781
  // ../aula-bundle/src/zip.ts
724
- var PROVIDED = ["@beff/aula", "@beff/aula-method"];
725
782
  async function workspacePackage(tree, file, project) {
726
783
  for (let folder = parent(file); folder !== "."; folder = parent(folder)) {
727
784
  const text = await tree.read(`${folder}/package.json`);
@@ -737,9 +794,9 @@ function parent(file) {
737
794
  return at < 0 ? "." : at === 0 ? "/" : file.slice(0, at);
738
795
  }
739
796
  var installedPackage = (file) => /^(.*node_modules\/(?:@[^/]+\/)?[^/]+)\//.exec(file)?.[1] ?? null;
740
- async function packageFiles(esbuild, tree, folder) {
797
+ async function packageFiles(bundler, tree, folder) {
741
798
  const imports = Object.fromEntries(PROVIDED.map((name) => [name, name]));
742
- const bundled = await bundle(esbuild, tree, `${folder}/index.ts`, imports);
799
+ const bundled = await bundle(bundler, tree, `${folder}/index.ts`, imports);
743
800
  if (bundled._tag === "Left") return bundled;
744
801
  const files = /* @__PURE__ */ new Map();
745
802
  for (const file of bundled.right.inputs) {
@@ -765,6 +822,53 @@ function zipBytes(entries) {
765
822
  return zipSync(sorted, { mtime: "2000-01-01T12:00:00Z" });
766
823
  }
767
824
 
825
+ // src/narrate.ts
826
+ function narrate(capabilities, chapters) {
827
+ return narrateScript(
828
+ (words) => capabilities.narrator.speak(words),
829
+ chapters,
830
+ (spoken, count, cue) => {
831
+ capabilities.log.out(`[${String(spoken)}/${String(count)}] Narrating: ${cue.text.slice(0, 70)}`);
832
+ }
833
+ );
834
+ }
835
+
836
+ // generated/parser.js
837
+ var RequiredStringFormats = [];
838
+ var RequiredNumberFormats = [];
839
+ var namedRuntypes = {};
840
+ var stringFormatters = {};
841
+ var numberFormatters = {};
842
+ var direct_hoist_0 = new RefRuntype(void 0, "TokensLine", namedRuntypes);
843
+ var direct_hoist_1 = new TypeofRuntype(void 0, "string");
844
+ var direct_hoist_2 = new ObjectRuntype({
845
+ "description": "One input line of `aula tokens`: a text, and an optional id that the output line repeats."
846
+ }, {
847
+ "id": new OptionalFieldRuntype(direct_hoist_1),
848
+ "text": direct_hoist_1
849
+ }, []);
850
+ Object.assign(namedRuntypes, {
851
+ "TokensLine": direct_hoist_2
852
+ });
853
+ var buildParsersInput = {
854
+ "TokensLine": direct_hoist_0
855
+ };
856
+ var parser_default = {
857
+ buildParsers: (args) => buildParsers(
858
+ {
859
+ parsers: buildParsersInput,
860
+ stringFormatters,
861
+ numberFormatters,
862
+ requiredStringFormats: RequiredStringFormats,
863
+ requiredNumberFormats: RequiredNumberFormats
864
+ },
865
+ args
866
+ )
867
+ };
868
+
869
+ // src/parsers.ts
870
+ var Parsers2 = parser_default.buildParsers();
871
+
768
872
  // src/project-zip.ts
769
873
  import path from "node:path";
770
874
  function diskTree(capabilities, root) {
@@ -786,9 +890,9 @@ function diskTree(capabilities, root) {
786
890
  }
787
891
  };
788
892
  }
789
- async function projectFiles(capabilities, esbuild, root, folder) {
893
+ async function projectFiles(capabilities, bundler, root, folder) {
790
894
  const tree = diskTree(capabilities, root);
791
- const found = await packageFiles(esbuild, tree, folder);
895
+ const found = await packageFiles(bundler, tree, folder);
792
896
  if (found._tag === "Left") throw new Problems(found.left);
793
897
  const files = found.right;
794
898
  for (const name of await capabilities.fs.readdir(path.join(root, folder), { recursive: true })) {
@@ -799,9 +903,264 @@ async function projectFiles(capabilities, esbuild, root, folder) {
799
903
  return files;
800
904
  }
801
905
 
906
+ // src/commands.ts
907
+ async function withHeavy(capabilities, f) {
908
+ const release = await capabilities.locks.heavy();
909
+ try {
910
+ return await f();
911
+ } finally {
912
+ await release();
913
+ }
914
+ }
915
+ async function withWork(capabilities, f) {
916
+ const work = await capabilities.fs.mkdtemp(path2.join(capabilities.env.temp, "aula-"));
917
+ try {
918
+ return await f(work);
919
+ } finally {
920
+ await capabilities.fs.rm(work, { recursive: true, force: true });
921
+ }
922
+ }
923
+ async function parallel(items, limit, task) {
924
+ let next = 0;
925
+ const worker = async () => {
926
+ for (let item = items[next++]; item !== void 0; item = items[next++]) await task(item);
927
+ };
928
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
929
+ }
930
+ async function drawChapter(capabilities, root, project, index, narration, lottie) {
931
+ const built = renderChapter(project, index, { host: host(capabilities, root), narration });
932
+ if (!built.ok || built.value === void 0) {
933
+ return { ok: false, findings: built.diagnostics, frames: 0, waits: [], embeds: [], narration };
934
+ }
935
+ await capabilities.fs.writeFile(lottie, built.value.lottie, "utf8");
936
+ const { frames, waits, embeds } = built.value;
937
+ return { ok: true, findings: built.diagnostics, frames, waits, embeds, narration: built.value.narration };
938
+ }
939
+ async function placedClips(capabilities, folder, overlays) {
940
+ return Promise.all(
941
+ overlays.map(async (o) => {
942
+ const file = path2.join(folder, o.path);
943
+ const picture = o.image === void 0 ? void 0 : path2.join(folder, o.image);
944
+ const video = o.kind === "video";
945
+ return {
946
+ file,
947
+ picture,
948
+ seen: video || picture !== void 0,
949
+ heard: !video || await hasAudio(capabilities, file),
950
+ at: o.at,
951
+ seconds: o.seconds
952
+ };
953
+ })
954
+ );
955
+ }
956
+ var inFolder = (folder, groups) => groups.map((group) => ({
957
+ ...group,
958
+ tiles: group.tiles.map((tile) => {
959
+ const { embed } = tile;
960
+ if (embed?.picture === void 0) return tile;
961
+ return { ...tile, embed: { ...embed, picture: path2.join(folder, embed.picture) } };
962
+ })
963
+ }));
964
+ var rowLine = (project, r) => `${nameOf(project)}: ${String(r.errors)} errors, ${String(r.warnings)} warnings, ${String(r.open)} open moves`;
965
+ async function printChecked(capabilities, root, project, checked) {
966
+ await printDiagnostics(capabilities, root, checked.findings);
967
+ printCounts(capabilities, project, checked);
968
+ }
969
+ function printCounts(capabilities, project, checked) {
970
+ const { errors, warnings } = checked.others;
971
+ if (errors + warnings > 0)
972
+ capabilities.log.out(`other chapters: ${String(errors)} errors, ${String(warnings)} warnings`);
973
+ capabilities.log.out(rowLine(project, checked));
974
+ }
975
+ async function check(capabilities, root, project, only, json = false) {
976
+ const chapters = chapterIndexes(project, only);
977
+ const checked = checkProject(project, host(capabilities, root), chapters);
978
+ const notes = wordNotes(narrationScript(project, checked.texts), chapters);
979
+ if (json) {
980
+ const { findings, others, errors, warnings, open } = checked;
981
+ const result = { name: nameOf(project), errors, warnings, openMoves: open, others, findings, notes };
982
+ capabilities.log.out(JSON.stringify(result, null, 2));
983
+ return errors === 0;
984
+ }
985
+ await printDiagnostics(capabilities, root, checked.findings);
986
+ for (const note of notes) capabilities.log.out(noteLine(note));
987
+ if (notes.length > 0) capabilities.log.out(notesLine(notes));
988
+ printCounts(capabilities, project, checked);
989
+ return checked.errors === 0;
990
+ }
991
+ async function script(capabilities, root, project) {
992
+ capabilities.log.write(scriptView(project, host(capabilities, root)));
993
+ return true;
994
+ }
995
+ async function timeline(capabilities, root, project, only) {
996
+ capabilities.log.write(await timelineView(project, host(capabilities, root), capabilities.narrator, only));
997
+ return true;
998
+ }
999
+ async function preview(capabilities, root, project, folder, given) {
1000
+ const targets = previewTargets(project, given);
1001
+ const only = targetChapters(targets, given);
1002
+ const checked = checkProject(project, host(capabilities, root), only);
1003
+ await printChecked(capabilities, root, project, checked);
1004
+ if (checked.errors > 0) return false;
1005
+ const all = checked.texts;
1006
+ const jobs = previewJobs(targets, all).map((job) => ({
1007
+ ...job,
1008
+ out: path2.join(folder, job.base),
1009
+ written: []
1010
+ }));
1011
+ return withWork(capabilities, async (work) => {
1012
+ const stopped = [];
1013
+ const waits = [];
1014
+ await withHeavy(capabilities, async () => {
1015
+ const n = await clock(capabilities.narrator, narrationScript(project, all), only, chapterNames(project));
1016
+ for (const job of jobs) await capabilities.fs.rm(job.out, { recursive: true, force: true });
1017
+ await parallel(jobs, capabilities.env.parallelism, async (job) => {
1018
+ const lottie = path2.join(work, `${job.base}.json`);
1019
+ const drawn = await drawChapter(capabilities, root, project, job.index, narrationAt(n, job.index), lottie);
1020
+ if (!drawn.ok) {
1021
+ stopped.push(...drawn.findings);
1022
+ return;
1023
+ }
1024
+ waits.push(...drawn.findings.filter((d) => !isError(d)));
1025
+ const { out } = job;
1026
+ const { window, stills } = pictureStills(drawn.narration, job, drawn.frames, drawn.embeds);
1027
+ const groups = inFolder(folderOf(project), pictureGroups(window, stills));
1028
+ const sheets = await capabilities.render.pictures({ lottie, out, groups });
1029
+ await capabilities.fs.mkdir(out, { recursive: true });
1030
+ await capabilities.fs.writeFile(path2.join(out, "moves.md"), movesMarkdown(stills));
1031
+ job.written.push(path2.join(out, "moves.md"), ...sheets);
1032
+ });
1033
+ });
1034
+ if (stopped.length) {
1035
+ await printDiagnostics(capabilities, root, stopped);
1036
+ return false;
1037
+ }
1038
+ await printDiagnostics(capabilities, root, waits);
1039
+ for (const line of jobs.flatMap((job) => job.written)) capabilities.log.out(line);
1040
+ return true;
1041
+ });
1042
+ }
1043
+ async function exportVideo(capabilities, root, project, file) {
1044
+ if (!file.endsWith(".mp4")) throw wrongArgument(`the video path must end in .mp4: ${file}`);
1045
+ const names = chapterNames(project);
1046
+ const checked = exportCheck(project, host(capabilities, root));
1047
+ await printChecked(capabilities, root, project, checked);
1048
+ if (checked.errors > 0) {
1049
+ capabilities.log.out(`export ${nameOf(project)}: stopped at check: fix the errors above`);
1050
+ return false;
1051
+ }
1052
+ await ffmpeg(capabilities, ["-version"]);
1053
+ return withWork(capabilities, async (work) => {
1054
+ const audio = path2.join(work, "narration.wav");
1055
+ const cues = narrationScript(project, checked.texts);
1056
+ const narrated = await withHeavy(capabilities, () => narrate(capabilities, cues));
1057
+ const lotties = names.map((name) => path2.join(work, `${name}.json`));
1058
+ const drawn = [];
1059
+ const problems = [];
1060
+ let done = 0;
1061
+ await withHeavy(
1062
+ capabilities,
1063
+ () => parallel(
1064
+ names.map((_, index) => index),
1065
+ capabilities.env.parallelism,
1066
+ async (index) => {
1067
+ const narration = narrated[index]?.narration;
1068
+ if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
1069
+ const chapter = await drawChapter(capabilities, root, project, index, narration, lotties[index] ?? "");
1070
+ drawn[index] = chapter;
1071
+ if (!chapter.ok) problems.push(...chapter.findings);
1072
+ done += 1;
1073
+ capabilities.log.out(
1074
+ `[${String(done)}/${String(names.length)}] ${names[index] ?? ""}: ${chapter.ok ? "drawn" : "FAILED"}`
1075
+ );
1076
+ }
1077
+ )
1078
+ );
1079
+ if (problems.length) {
1080
+ await printDiagnostics(capabilities, root, problems);
1081
+ return false;
1082
+ }
1083
+ const { samples, sampleRate } = scriptAudio(
1084
+ narrated,
1085
+ drawn.map((d) => d.waits)
1086
+ );
1087
+ await capabilities.fs.writeFile(audio, wav(samples, sampleRate));
1088
+ capabilities.log.out(`Narrated ${(samples.length / sampleRate / 60).toFixed(1)} minutes`);
1089
+ const plan = clipPlan(
1090
+ drawn.map((d) => d.narration),
1091
+ VIDEO.fps
1092
+ );
1093
+ const clips = names.map((name) => path2.join(work, `${name}.mp4`));
1094
+ await withHeavy(
1095
+ capabilities,
1096
+ () => parallel(
1097
+ names.map((_, index) => index),
1098
+ capabilities.env.parallelism,
1099
+ async (index) => {
1100
+ const clip = plan.clips[index] ?? { from: 0, frames: 0 };
1101
+ await capabilities.render.clip({ lottie: lotties[index] ?? "", out: clips[index] ?? "", ...clip });
1102
+ }
1103
+ )
1104
+ );
1105
+ await capabilities.fs.mkdir(path2.dirname(file), { recursive: true });
1106
+ const placed = await placedClips(
1107
+ capabilities,
1108
+ folderOf(project),
1109
+ overlayPlan(
1110
+ drawn.map((d) => d.narration),
1111
+ drawn.map((d) => d.embeds)
1112
+ )
1113
+ );
1114
+ const background = (project.theme ?? m.theme).background;
1115
+ await assemble(capabilities, { work, clips, audio, seconds: plan.seconds, out: file, placed, background });
1116
+ capabilities.log.out(file);
1117
+ return true;
1118
+ });
1119
+ }
1120
+ async function bundle2(capabilities, project, file) {
1121
+ if (!file.endsWith(".zip")) throw new Error(`the zip path must end in .zip: ${file}`);
1122
+ const home = folderOf(project);
1123
+ const root = path2.parse(home).root;
1124
+ const folder = path2.relative(root, home).split(path2.sep).join("/");
1125
+ const bundler = createNodeBundler();
1126
+ let files;
1127
+ try {
1128
+ files = await projectFiles(capabilities, bundler, root, folder);
1129
+ } finally {
1130
+ await bundler.stop();
1131
+ }
1132
+ const entries = /* @__PURE__ */ new Map();
1133
+ for (const [at, from] of files)
1134
+ entries.set(at, new Uint8Array(await capabilities.fs.readFile(path2.join(root, from))));
1135
+ const zip = zipBytes(entries);
1136
+ await capabilities.fs.mkdir(path2.dirname(file), { recursive: true });
1137
+ await capabilities.fs.writeFile(file, zip);
1138
+ capabilities.log.out(`${file}: ${String(files.size)} files, ${String(Math.ceil(zip.length / 1024))} kB`);
1139
+ return true;
1140
+ }
1141
+ async function tokens(capabilities, tokensOf, lines) {
1142
+ let number = 0;
1143
+ for await (const line of lines) {
1144
+ number += 1;
1145
+ if (!line.trim()) continue;
1146
+ const parsed = Parsers2.TokensLine.safeParse(JSON.parse(line));
1147
+ if (!parsed.success) throw wrongArgument(`stdin line ${String(number)}: expected {"id"?: string, "text": string}`);
1148
+ const { id, text } = parsed.data;
1149
+ capabilities.log.out(JSON.stringify({ ...id === void 0 ? {} : { id }, batches: await tokensOf(text) }));
1150
+ }
1151
+ return true;
1152
+ }
1153
+ function tokensArgs(positional) {
1154
+ if (positional.length > 0) throw wrongArgument("aula tokens takes no arguments", "run `aula help` for the usage");
1155
+ }
1156
+
802
1157
  export {
803
- packageFiles,
804
- zipBytes,
805
- diskTree,
806
- projectFiles
1158
+ check,
1159
+ script,
1160
+ timeline,
1161
+ preview,
1162
+ exportVideo,
1163
+ bundle2 as bundle,
1164
+ tokens,
1165
+ tokensArgs
807
1166
  };
@@ -151,10 +151,15 @@ async function tokenBatches(vocab, phonemize2, text) {
151
151
  var STRESS = "\u02C8\u02CC";
152
152
  var isSound = (phoneme) => new RegExp("\\p{L}", "u").test(phoneme) && !STRESS.includes(phoneme);
153
153
  async function timesOfWords(phonemize2, words, timings) {
154
- const spoken = timings.filter((timing) => isSound(timing.phoneme));
155
- if (!spoken.length) throw new Error("the model gave no phoneme timings");
156
154
  const read = [];
157
155
  for (const word of words) read.push(Array.from(await phonemize2(word)).filter(isSound));
156
+ const spoken = timings.filter((timing) => isSound(timing.phoneme));
157
+ if (!spoken.length) {
158
+ const text = JSON.stringify(words.join(" "));
159
+ throw new Error(
160
+ read.some((w) => w.length > 0) ? `the narrator gave no phoneme timings for ${text}` : `Nothing to say: ${text} has no spoken sounds`
161
+ );
162
+ }
158
163
  return alignWords(words, spoken, read);
159
164
  }
160
165
 
@@ -319,12 +324,22 @@ async function layout(parts, words, audio) {
319
324
  const text = words.join(" ");
320
325
  const batches = await batchesOf(parts.phonemize, text, MAX_TOKENS);
321
326
  if (!batches.length) throw new Error(`Nothing to say: ${JSON.stringify(text)} has no phonemes`);
327
+ const tokenized = batches.map((batch) => {
328
+ const { ids, known } = tokenize(KOKORO_VOCAB, batch);
329
+ if (!ids.length) {
330
+ throw new Error(
331
+ `No phonemes of ${JSON.stringify(text)} (${JSON.stringify(batch)}) are in the model's token table`
332
+ );
333
+ }
334
+ return { batch, ids, known };
335
+ });
336
+ if (!tokenized.some(({ known }) => known.some(isSound))) {
337
+ throw new Error(`Nothing to say: ${JSON.stringify(text)} has no spoken sounds`);
338
+ }
322
339
  const pieces = [];
323
340
  const timings = [];
324
341
  let offset = 0;
325
- for (const [index, batch] of batches.entries()) {
326
- const { ids, known } = tokenize(KOKORO_VOCAB, batch);
327
- if (!ids.length) throw new Error(`No phonemes of ${JSON.stringify(batch)} are in the model's token table`);
342
+ for (const [index, { batch, ids, known }] of tokenized.entries()) {
328
343
  const padded = [0, ...ids, 0];
329
344
  const spoken = audio ? parts.model.speak(padded, VOICE) : { audio: null, durations: parts.model.durations(padded, VOICE) };
330
345
  const edges = [0];