@beff/aula-cli 0.0.1 → 0.1.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.
- package/README.md +11 -1
- package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
- package/dist/licenses/espeak-ng-COPYING.txt +674 -0
- package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
- package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
- package/dist/src/aula-render.core.wasm +0 -0
- package/dist/src/aula-voice-tts-ZXQ7XXHJ.js +14 -0
- package/dist/src/chunk-2XGNOG2U.js +28 -0
- package/dist/src/chunk-3IBMAZRS.js +21 -0
- package/dist/src/chunk-EYXQ2I7K.js +604 -0
- package/dist/src/chunk-GFCJYE75.js +42 -0
- package/dist/src/chunk-KLE5UOUB.js +57 -0
- package/dist/src/chunk-OMBYV6CK.js +1063 -0
- package/dist/src/chunk-PYRORQA5.js +88 -0
- package/dist/src/chunk-SDFXIMLW.js +1083 -0
- package/dist/src/chunk-UREQAEFC.js +491 -0
- package/dist/src/chunk-X3HJY34X.js +81 -0
- package/dist/src/cli.js +269 -0
- package/dist/src/commands-VDGWDVWT.js +28 -0
- package/dist/src/problems-OGUR4BLZ.js +12 -0
- package/dist/src/project-M63R4ENB.js +11 -0
- package/dist/src/render-child.js +3771 -0
- package/dist/src/run-CY72QGZJ.js +127 -0
- package/dist/src/server-ZG6K7Z7H.js +280 -0
- package/dist/web/app/assets/__vite-browser-external-Bbi05A7N.js +1 -0
- package/dist/web/app/assets/__vite-browser-external-BtQTJ51O.js +1 -0
- package/dist/web/app/assets/aula-method.js +1 -0
- package/dist/web/app/assets/aula-voice-worker-BL6WcrSe.js +52 -0
- package/dist/web/app/assets/aula.core-BtiPQSZi.wasm +0 -0
- package/dist/web/app/assets/aula.core5-BdGB-M10.wasm +0 -0
- package/dist/web/app/assets/aula.js +1 -0
- package/dist/web/app/assets/build-worker.js +697 -0
- package/dist/web/app/assets/esbuild-BaXVPFT2.wasm +0 -0
- package/dist/web/app/assets/index-BVQqteYG.js +53 -0
- package/dist/web/app/assets/index-CS60sOpp.css +2 -0
- package/dist/web/app/assets/protocol-Ds4jI5bY.js +15 -0
- package/dist/web/app/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
- package/dist/web/app/assets/src-BbJ5r410.js +25 -0
- package/dist/web/app/index.html +15 -0
- package/package.json +27 -5
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnyRuntype,
|
|
3
|
+
ArrayRuntype,
|
|
4
|
+
ObjectRuntype,
|
|
5
|
+
OptionalFieldRuntype,
|
|
6
|
+
RefRuntype,
|
|
7
|
+
TypeofRuntype,
|
|
8
|
+
buildParsers,
|
|
9
|
+
timeChapter
|
|
10
|
+
} from "./chunk-SDFXIMLW.js";
|
|
11
|
+
import {
|
|
12
|
+
Problems,
|
|
13
|
+
error,
|
|
14
|
+
isError,
|
|
15
|
+
withSource,
|
|
16
|
+
wrongArgument
|
|
17
|
+
} from "./chunk-PYRORQA5.js";
|
|
18
|
+
|
|
19
|
+
// src/problems.ts
|
|
20
|
+
import { loadEngine as loadEngine2 } from "@beff/aula/run";
|
|
21
|
+
import { renderDiagnostic } from "@beff/aula/text";
|
|
22
|
+
|
|
23
|
+
// ../aula-project/src/chapters.ts
|
|
24
|
+
import { readChapter } from "@beff/aula";
|
|
25
|
+
import { paragraphAt, scriptMarkdown } from "@beff/aula/text";
|
|
26
|
+
function chapterIndex(names, name) {
|
|
27
|
+
const at = names.indexOf(name);
|
|
28
|
+
if (at >= 0) return at;
|
|
29
|
+
throw wrongArgument(`No chapter '${name}': use one of [${names.join(", ")}]`);
|
|
30
|
+
}
|
|
31
|
+
function header(project) {
|
|
32
|
+
const body = project.storyboard.trim();
|
|
33
|
+
return body === "" ? `# ${project.title}
|
|
34
|
+
` : `# ${project.title}
|
|
35
|
+
|
|
36
|
+
${body}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
function placeText(place) {
|
|
40
|
+
return `${place.file}:${String(place.line)}`;
|
|
41
|
+
}
|
|
42
|
+
function chapterText(project, host, index) {
|
|
43
|
+
const result = readChapter(project, index, { host });
|
|
44
|
+
if (!result.ok || !result.value) throw new Problems(result.diagnostics);
|
|
45
|
+
return result.value;
|
|
46
|
+
}
|
|
47
|
+
function paragraphCue(text, name, line) {
|
|
48
|
+
const p = paragraphAt(text, line);
|
|
49
|
+
if (p !== void 0) return p + 1;
|
|
50
|
+
const starts = text.paragraphs.flatMap((q) => q.place ? [String(q.place.line)] : []);
|
|
51
|
+
const list = starts.length > 1 ? `${starts.slice(0, -1).join(", ")} and ${starts.at(-1) ?? ""}` : starts.join("");
|
|
52
|
+
throw wrongArgument(`line ${String(line)} of ${name} is in no paragraph; the paragraphs start at lines ${list}`);
|
|
53
|
+
}
|
|
54
|
+
function texts(project, host) {
|
|
55
|
+
const reads = project.chapters.map((_, i) => readChapter(project, i + 1, { host }));
|
|
56
|
+
const problems = reads.flatMap((r) => r.ok && r.value ? [] : r.diagnostics);
|
|
57
|
+
if (problems.length) throw new Problems(problems);
|
|
58
|
+
return reads.flatMap((r) => r.value ? [r.value] : []);
|
|
59
|
+
}
|
|
60
|
+
function scriptView(project, host) {
|
|
61
|
+
return scriptMarkdown(project.title, texts(project, host));
|
|
62
|
+
}
|
|
63
|
+
function openMoves(text) {
|
|
64
|
+
return text.paragraphs.flatMap((p) => p.moves).filter((m) => !m.done);
|
|
65
|
+
}
|
|
66
|
+
function openCount(chapters, indexes) {
|
|
67
|
+
return chapters.filter((_, i) => indexes.includes(i + 1)).reduce((sum, t) => sum + openMoves(t).length, 0);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ../aula-project/src/check.ts
|
|
71
|
+
import { checkChapter, readChapter as readChapter2 } from "@beff/aula";
|
|
72
|
+
import { chapterNames } from "@beff/aula/run";
|
|
73
|
+
import { check as rules } from "@beff/aula/text";
|
|
74
|
+
async function clock(narrator, chapters) {
|
|
75
|
+
const narrations = [];
|
|
76
|
+
for (const cues of chapters) {
|
|
77
|
+
const timings = [];
|
|
78
|
+
for (const cue of cues) timings.push(await narrator.time(cue.text, cue.speed));
|
|
79
|
+
narrations.push(timeChapter(cues, timings));
|
|
80
|
+
}
|
|
81
|
+
return narrations;
|
|
82
|
+
}
|
|
83
|
+
function narrationAt(narrations, index) {
|
|
84
|
+
const narration = narrations[index];
|
|
85
|
+
if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
|
|
86
|
+
return narration;
|
|
87
|
+
}
|
|
88
|
+
var EMPTY = { heading: "", metaphor: "", paragraphs: [] };
|
|
89
|
+
function checkProject(project, host, only) {
|
|
90
|
+
const reads = project.chapters.map((_, i) => readChapter2(project, i + 1, { host }));
|
|
91
|
+
const unloaded = /* @__PURE__ */ new Map();
|
|
92
|
+
reads.forEach((r, i) => {
|
|
93
|
+
if (r.value === void 0) unloaded.set(i + 1, r.diagnostics);
|
|
94
|
+
});
|
|
95
|
+
const all = reads.map((r) => r.value ?? EMPTY);
|
|
96
|
+
const own = /* @__PURE__ */ new Map();
|
|
97
|
+
reads.forEach((r, i) => {
|
|
98
|
+
if (r.value !== void 0) own.set(i + 1, [...r.diagnostics, ...rules(r.value)]);
|
|
99
|
+
});
|
|
100
|
+
const targets = (only ?? chapterNames(project).map((_, i) => i)).filter((i) => !unloaded.has(i));
|
|
101
|
+
const inScope = (index) => only === null || only.includes(index);
|
|
102
|
+
if (![...own].some(([index, d]) => inScope(index) && d.some(isError))) {
|
|
103
|
+
for (const index of targets) {
|
|
104
|
+
const run = checkChapter(project, index, { host });
|
|
105
|
+
const text = all[index - 1];
|
|
106
|
+
own.set(index, [...run.diagnostics, ...index === 0 || text === void 0 ? [] : rules(text)]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const byChapter = [...unloaded, ...[...own].toSorted(([a], [b]) => a - b)];
|
|
110
|
+
const reported = byChapter.flatMap(([index, d]) => inScope(index) ? d : []);
|
|
111
|
+
const elsewhere = byChapter.flatMap(([index, d]) => inScope(index) ? [] : d);
|
|
112
|
+
const errors = reported.filter(isError).length;
|
|
113
|
+
const otherErrors = elsewhere.filter(isError).length;
|
|
114
|
+
return {
|
|
115
|
+
findings: reported,
|
|
116
|
+
others: { errors: otherErrors, warnings: elsewhere.length - otherErrors },
|
|
117
|
+
errors,
|
|
118
|
+
warnings: reported.length - errors,
|
|
119
|
+
open: openCount(all, targets),
|
|
120
|
+
texts: all
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function chapterIndexes(project, only) {
|
|
124
|
+
const names = chapterNames(project);
|
|
125
|
+
return only.length === 0 ? null : only.map((name) => chapterIndex(names, name));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ../aula-project/src/export.ts
|
|
129
|
+
function exportCheck(project, host) {
|
|
130
|
+
const checked = checkProject(project, host, null);
|
|
131
|
+
const open = checked.texts.flatMap(
|
|
132
|
+
(t) => openMoves(t).map(
|
|
133
|
+
(m) => error(`show: the move "${m.note}" has no animation yet`, {
|
|
134
|
+
location: m.place,
|
|
135
|
+
hint: "give the show its move, show`note``25%`((s) => { \u2026 }), or make it a hold, show`note``25%`(() => {})"
|
|
136
|
+
})
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
return { ...checked, findings: [...checked.findings, ...open], errors: checked.errors + open.length };
|
|
140
|
+
}
|
|
141
|
+
function clipPlan(narrations, fps) {
|
|
142
|
+
const starts = [0];
|
|
143
|
+
for (const narration of narrations) starts.push((starts.at(-1) ?? 0) + narration.endFrame / narration.sampleRate);
|
|
144
|
+
const firsts = starts.map((seconds) => Math.round(seconds * fps));
|
|
145
|
+
const clips = narrations.map((_, index) => {
|
|
146
|
+
const first = firsts[index] ?? 0;
|
|
147
|
+
return { from: first / fps - (starts[index] ?? 0), frames: (firsts[index + 1] ?? first) - first };
|
|
148
|
+
});
|
|
149
|
+
return { clips, seconds: starts.at(-1) ?? 0 };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ../aula-project/src/preview.ts
|
|
153
|
+
import { chapterNames as chapterNames2, FPS } from "@beff/aula/run";
|
|
154
|
+
|
|
155
|
+
// ../aula-project/src/stills.ts
|
|
156
|
+
import { moveFrames } from "@beff/aula/text";
|
|
157
|
+
function stillsOf(narration, text, frames) {
|
|
158
|
+
if (text === null) {
|
|
159
|
+
return [{ name: "title", cue: 0, place: null, note: "title card", frame: Math.floor(0.6 * frames) }];
|
|
160
|
+
}
|
|
161
|
+
const paragraphs = moveFrames(narration, text);
|
|
162
|
+
const moves = paragraphs.flatMap(
|
|
163
|
+
(p, k) => Array.from(p.moves, (start, i) => ({ start, cue: k + 1, move: text.paragraphs[k]?.moves[i] }))
|
|
164
|
+
);
|
|
165
|
+
return moves.flatMap(({ start, cue, move }, i) => {
|
|
166
|
+
if (move === void 0) return [];
|
|
167
|
+
const next = moves[i + 1]?.start ?? frames;
|
|
168
|
+
const name = `L${String(move.place.line).padStart(4, "0")}`;
|
|
169
|
+
return [{ name, cue, place: move.place, note: move.note, frame: Math.max(start, next - 1) }];
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function paragraphWindow(narration, text, cue, frames) {
|
|
173
|
+
const paragraphs = moveFrames(narration, text);
|
|
174
|
+
const start = paragraphs[cue - 1]?.start;
|
|
175
|
+
if (start === void 0) throw new Error(`paragraph ${String(cue)} is not narrated`);
|
|
176
|
+
return [start, paragraphs[cue]?.start ?? frames];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ../aula-project/src/preview.ts
|
|
180
|
+
function previewTargets(project, given) {
|
|
181
|
+
const names = chapterNames2(project);
|
|
182
|
+
if (given.length === 0) return names.map((name, index) => ({ index, name, line: null }));
|
|
183
|
+
return given.map((target) => {
|
|
184
|
+
const m = /^(.*):([0-9]+)$/.exec(target);
|
|
185
|
+
const index = chapterIndex(names, m?.[1] ?? target);
|
|
186
|
+
if (index === 0 && m !== null) throw wrongArgument("the title card has no lines: give a chapter name with :<line>");
|
|
187
|
+
return { index, name: names[index] ?? target, line: m?.[2] === void 0 ? null : Number(m[2]) };
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
var targetChapters = (targets, given) => given.length === 0 ? null : [...new Set(targets.map((t) => t.index))];
|
|
191
|
+
function previewJobs(targets, chapters) {
|
|
192
|
+
return targets.map((t) => {
|
|
193
|
+
const base = t.line === null ? t.name : `${t.name}-L${String(t.line)}`;
|
|
194
|
+
const text = t.index === 0 ? null : chapters[t.index - 1];
|
|
195
|
+
if (text === void 0) throw new Error(`no text of chapter ${t.name}`);
|
|
196
|
+
const cue = text === null || t.line === null ? null : paragraphCue(text, t.name, t.line);
|
|
197
|
+
return { ...t, base, text, cue };
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function pictureStills(narration, job, frames) {
|
|
201
|
+
const { text, cue } = job;
|
|
202
|
+
const window = text === null || cue === null ? [0, frames] : paragraphWindow(narration, text, cue, frames);
|
|
203
|
+
const stills = stillsOf(narration, text, frames).filter((s) => cue === null || s.cue === cue);
|
|
204
|
+
return { window, stills };
|
|
205
|
+
}
|
|
206
|
+
function pictureGroups(window, stills) {
|
|
207
|
+
const [from, to] = window;
|
|
208
|
+
const motion = [];
|
|
209
|
+
for (let k = Math.ceil(from * 2 / FPS); Math.floor(k * FPS / 2) < to; k++) {
|
|
210
|
+
motion.push({ name: `t${(k / 2).toFixed(1).padStart(5, "0")}s`, frame: Math.floor(k * FPS / 2) });
|
|
211
|
+
}
|
|
212
|
+
return [
|
|
213
|
+
{ folder: "stills", cols: 3, rows: 3, tiles: stills.map((s) => ({ name: s.name, frame: s.frame })) },
|
|
214
|
+
{ folder: "motion", cols: 4, rows: 4, tiles: motion }
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
function movesMarkdown(stills) {
|
|
218
|
+
return stills.map((still) => {
|
|
219
|
+
const at = still.place ? placeText(still.place) : "title card";
|
|
220
|
+
return `- ${at}, ${(still.frame / FPS).toFixed(1)} s: ${still.note} (stills/${still.name}.png)
|
|
221
|
+
`;
|
|
222
|
+
}).join("");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ../aula-project/src/timeline.ts
|
|
226
|
+
import { renderChapter } from "@beff/aula";
|
|
227
|
+
import { chapterNames as chapterNames3 } from "@beff/aula/run";
|
|
228
|
+
import { narrationScript, timeline as timelineOf } from "@beff/aula/text";
|
|
229
|
+
async function timelineView(project, host, narrator, only) {
|
|
230
|
+
const names = chapterNames3(project);
|
|
231
|
+
const indexes = only.length === 0 ? project.chapters.map((_, i) => i + 1) : only.map((name) => chapterIndex(names, name));
|
|
232
|
+
if (indexes.includes(0)) throw wrongArgument("the title card has no timeline: give a chapter name");
|
|
233
|
+
const n = await clock(narrator, narrationScript(project.title, texts(project, host)));
|
|
234
|
+
let out = header(project);
|
|
235
|
+
for (const index of indexes) {
|
|
236
|
+
const text = chapterText(project, host, index);
|
|
237
|
+
const run = renderChapter(project, index, { host, narration: narrationAt(n, index), lint: true });
|
|
238
|
+
if (!run.ok || run.value === void 0) throw new Problems(run.diagnostics);
|
|
239
|
+
out += `
|
|
240
|
+
## ${names[index] ?? ""}
|
|
241
|
+
Metaphor: ${text.metaphor}
|
|
242
|
+
`;
|
|
243
|
+
for (const line of timelineOf(run.value.narration, text)) out += `${line}
|
|
244
|
+
`;
|
|
245
|
+
}
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ../aula-project/src/workspace.ts
|
|
250
|
+
import * as Engine from "@beff/aula";
|
|
251
|
+
import { diagnosticOf, importUserModule, loadEngine } from "@beff/aula/run";
|
|
252
|
+
import {
|
|
253
|
+
narrationScript as narrationScript2
|
|
254
|
+
} from "@beff/aula/text";
|
|
255
|
+
|
|
256
|
+
// ../aula-bundle/generated/parser.js
|
|
257
|
+
var RequiredStringFormats = [];
|
|
258
|
+
var RequiredNumberFormats = [];
|
|
259
|
+
var namedRuntypes = {};
|
|
260
|
+
var stringFormatters = {};
|
|
261
|
+
var numberFormatters = {};
|
|
262
|
+
var direct_hoist_0 = new RefRuntype(void 0, "PackageJson", namedRuntypes);
|
|
263
|
+
var direct_hoist_1 = new AnyRuntype(void 0);
|
|
264
|
+
var direct_hoist_2 = new TypeofRuntype(void 0, "string");
|
|
265
|
+
var direct_hoist_3 = new ArrayRuntype(void 0, direct_hoist_2);
|
|
266
|
+
var direct_hoist_4 = new ObjectRuntype({
|
|
267
|
+
"description": "The part of a package.json that aula reads: how a package names its module and its\nworkspace packages."
|
|
268
|
+
}, {
|
|
269
|
+
"exports": new OptionalFieldRuntype(direct_hoist_1),
|
|
270
|
+
"main": new OptionalFieldRuntype(direct_hoist_2),
|
|
271
|
+
"module": new OptionalFieldRuntype(direct_hoist_2),
|
|
272
|
+
"name": new OptionalFieldRuntype(direct_hoist_2),
|
|
273
|
+
"workspaces": new OptionalFieldRuntype(direct_hoist_3)
|
|
274
|
+
}, []);
|
|
275
|
+
Object.assign(namedRuntypes, {
|
|
276
|
+
"PackageJson": direct_hoist_4
|
|
277
|
+
});
|
|
278
|
+
var buildParsersInput = {
|
|
279
|
+
"PackageJson": direct_hoist_0
|
|
280
|
+
};
|
|
281
|
+
var parser_default = {
|
|
282
|
+
buildParsers: (args) => buildParsers(
|
|
283
|
+
{
|
|
284
|
+
parsers: buildParsersInput,
|
|
285
|
+
stringFormatters,
|
|
286
|
+
numberFormatters,
|
|
287
|
+
requiredStringFormats: RequiredStringFormats,
|
|
288
|
+
requiredNumberFormats: RequiredNumberFormats
|
|
289
|
+
},
|
|
290
|
+
args
|
|
291
|
+
)
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// ../aula-bundle/src/parsers.ts
|
|
295
|
+
var Parsers = parser_default.buildParsers();
|
|
296
|
+
|
|
297
|
+
// ../aula-bundle/src/index.ts
|
|
298
|
+
var SOURCE_PREFIX = "tree:";
|
|
299
|
+
function dirname(path) {
|
|
300
|
+
const at = path.lastIndexOf("/");
|
|
301
|
+
return at < 0 ? "" : path.slice(0, at);
|
|
302
|
+
}
|
|
303
|
+
function join(from, relative) {
|
|
304
|
+
const parts = from === "" ? [] : from.split("/");
|
|
305
|
+
for (const part of relative.split("/")) {
|
|
306
|
+
if (part === "" || part === ".") continue;
|
|
307
|
+
if (part === "..") {
|
|
308
|
+
if (!parts.length) return null;
|
|
309
|
+
parts.pop();
|
|
310
|
+
} else parts.push(part);
|
|
311
|
+
}
|
|
312
|
+
return parts.join("/");
|
|
313
|
+
}
|
|
314
|
+
var LOADERS = /* @__PURE__ */ new Map([
|
|
315
|
+
["ts", "ts"],
|
|
316
|
+
["mts", "ts"],
|
|
317
|
+
["js", "js"],
|
|
318
|
+
["mjs", "js"],
|
|
319
|
+
["json", "json"]
|
|
320
|
+
]);
|
|
321
|
+
var loaderOf = (path) => LOADERS.get(path.slice(path.lastIndexOf(".") + 1)) ?? "ts";
|
|
322
|
+
function treePlugin(tree, imports) {
|
|
323
|
+
return {
|
|
324
|
+
name: "aula-tree",
|
|
325
|
+
setup(build) {
|
|
326
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
327
|
+
const url = imports[args.path];
|
|
328
|
+
if (url !== void 0) return { path: url, external: true };
|
|
329
|
+
if (args.kind === "entry-point") return { path: join("", args.path) ?? args.path, namespace: "tree" };
|
|
330
|
+
if (!args.path.startsWith("./") && !args.path.startsWith("../")) {
|
|
331
|
+
const found = await resolvePackage(tree, args.path, args.importer);
|
|
332
|
+
if (found !== null) return { path: found, namespace: "tree" };
|
|
333
|
+
return {
|
|
334
|
+
errors: [{ text: `cannot find the package "${args.path}" in node_modules or the workspace packages` }]
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const path = join(dirname(args.importer), args.path);
|
|
338
|
+
if (path === null) return { errors: [{ text: `"${args.path}" is outside the folder you opened` }] };
|
|
339
|
+
for (const candidate of [path, `${path}.ts`, `${path}/index.ts`]) {
|
|
340
|
+
if (await tree.read(candidate) !== null) return { path: candidate, namespace: "tree" };
|
|
341
|
+
}
|
|
342
|
+
return { errors: [{ text: `cannot find "${args.path}" (${path})` }] };
|
|
343
|
+
});
|
|
344
|
+
build.onLoad({ filter: /.*/, namespace: "tree" }, async (args) => {
|
|
345
|
+
const contents = await tree.read(args.path);
|
|
346
|
+
if (contents === null) return { errors: [{ text: `cannot read ${args.path}` }] };
|
|
347
|
+
return { contents, loader: loaderOf(args.path) };
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function isMessage(value) {
|
|
353
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "text") === "string";
|
|
354
|
+
}
|
|
355
|
+
var diagnostic = ({ text, location: at }) => ({
|
|
356
|
+
severity: "error",
|
|
357
|
+
message: text,
|
|
358
|
+
...at ? { location: { file: at.file.replace(SOURCE_PREFIX, ""), line: at.line, col: at.column + 1 } } : {},
|
|
359
|
+
stack: [],
|
|
360
|
+
related: []
|
|
361
|
+
});
|
|
362
|
+
async function bundle(esbuild, tree, entry, imports) {
|
|
363
|
+
let result;
|
|
364
|
+
try {
|
|
365
|
+
result = await esbuild.build({
|
|
366
|
+
entryPoints: [entry],
|
|
367
|
+
bundle: true,
|
|
368
|
+
write: false,
|
|
369
|
+
format: "esm",
|
|
370
|
+
platform: "browser",
|
|
371
|
+
target: "es2024",
|
|
372
|
+
outfile: "bundle.js",
|
|
373
|
+
sourcemap: "both",
|
|
374
|
+
sourcesContent: false,
|
|
375
|
+
metafile: true,
|
|
376
|
+
logLevel: "silent",
|
|
377
|
+
plugins: [treePlugin(tree, imports)]
|
|
378
|
+
});
|
|
379
|
+
} catch (error2) {
|
|
380
|
+
const errors = typeof error2 === "object" && error2 !== null ? Reflect.get(error2, "errors") : void 0;
|
|
381
|
+
if (Array.isArray(errors) && errors.every(isMessage)) return { _tag: "Left", left: errors.map(diagnostic) };
|
|
382
|
+
throw error2;
|
|
383
|
+
}
|
|
384
|
+
const code = result.outputFiles.find((f) => f.path.endsWith(".js"))?.text;
|
|
385
|
+
const map = result.outputFiles.find((f) => f.path.endsWith(".js.map"))?.text;
|
|
386
|
+
if (code === void 0 || map === void 0) throw new Error("esbuild wrote no bundle");
|
|
387
|
+
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((input) => input.startsWith(SOURCE_PREFIX)).map((input) => input.slice(SOURCE_PREFIX.length));
|
|
388
|
+
return { _tag: "Right", right: { code, map, inputs } };
|
|
389
|
+
}
|
|
390
|
+
function exportTarget(exports, subpath) {
|
|
391
|
+
if (typeof exports === "string") return subpath === "." ? exports : null;
|
|
392
|
+
if (typeof exports !== "object" || exports === null) return null;
|
|
393
|
+
const keys = Object.keys(exports);
|
|
394
|
+
if (keys.some((key) => key.startsWith("."))) {
|
|
395
|
+
return subpath in exports ? exportTarget(Reflect.get(exports, subpath), ".") : null;
|
|
396
|
+
}
|
|
397
|
+
for (const key of ["browser", "import", "default"]) {
|
|
398
|
+
if (key in exports) return exportTarget(Reflect.get(exports, key), ".");
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
function packageOf(specifier) {
|
|
403
|
+
const parts = specifier.split("/");
|
|
404
|
+
const size = specifier.startsWith("@") ? 2 : 1;
|
|
405
|
+
const rest = parts.slice(size).join("/");
|
|
406
|
+
return { name: parts.slice(0, size).join("/"), subpath: rest === "" ? "." : `./${rest}` };
|
|
407
|
+
}
|
|
408
|
+
async function packageModule(tree, folder, subpath) {
|
|
409
|
+
const found = manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`));
|
|
410
|
+
if (!found) return null;
|
|
411
|
+
const target = exportTarget(found.exports, subpath) ?? (subpath === "." ? found.module ?? found.main ?? "index.js" : subpath);
|
|
412
|
+
return join(folder, target);
|
|
413
|
+
}
|
|
414
|
+
async function resolveBare(tree, specifier, importer) {
|
|
415
|
+
const { name, subpath } = packageOf(specifier);
|
|
416
|
+
for (let dir = dirname(importer); ; dir = dirname(dir)) {
|
|
417
|
+
const found = await packageModule(
|
|
418
|
+
tree,
|
|
419
|
+
dir === "" ? `node_modules/${name}` : `${dir}/node_modules/${name}`,
|
|
420
|
+
subpath
|
|
421
|
+
);
|
|
422
|
+
if (found !== null) return found;
|
|
423
|
+
if (dir === "") return null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function manifest(file, text) {
|
|
427
|
+
if (text === null) return null;
|
|
428
|
+
const parsed = Parsers.PackageJson.safeParse(JSON.parse(text));
|
|
429
|
+
return parsed.success ? parsed.data : null;
|
|
430
|
+
}
|
|
431
|
+
async function workspaceFolders(tree) {
|
|
432
|
+
const patterns = [];
|
|
433
|
+
const pnpm = await tree.read("pnpm-workspace.yaml");
|
|
434
|
+
if (pnpm !== null) {
|
|
435
|
+
let inside = false;
|
|
436
|
+
for (const line of pnpm.split("\n")) {
|
|
437
|
+
if (/^packages:\s*$/.test(line)) inside = true;
|
|
438
|
+
else if (/^\S/.test(line)) inside = false;
|
|
439
|
+
else if (inside) {
|
|
440
|
+
const item = /^\s*-\s*["']?([^"'#]+?)["']?\s*(#.*)?$/.exec(line)?.[1];
|
|
441
|
+
if (item !== void 0) patterns.push(item);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
patterns.push(...manifest("package.json", await tree.read("package.json"))?.workspaces ?? []);
|
|
446
|
+
const folders = [];
|
|
447
|
+
for (const pattern of patterns) {
|
|
448
|
+
const clean = pattern.replace(/^\.\//, "").replace(/\/$/, "");
|
|
449
|
+
if (clean.endsWith("/*")) {
|
|
450
|
+
const parent = clean.slice(0, -2);
|
|
451
|
+
folders.push(...(await tree.list(parent)).map((name) => `${parent}/${name}`));
|
|
452
|
+
} else if (!clean.includes("*")) folders.push(clean);
|
|
453
|
+
}
|
|
454
|
+
return folders;
|
|
455
|
+
}
|
|
456
|
+
async function resolvePackage(tree, specifier, importer) {
|
|
457
|
+
const installed = await resolveBare(tree, specifier, importer);
|
|
458
|
+
if (installed !== null) return installed;
|
|
459
|
+
const { name, subpath } = packageOf(specifier);
|
|
460
|
+
for (const folder of await workspaceFolders(tree)) {
|
|
461
|
+
if (manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`))?.name !== name) continue;
|
|
462
|
+
return packageModule(tree, folder, subpath);
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/problems.ts
|
|
468
|
+
async function printDiagnostics(capabilities, root, diagnostics, print = (text) => capabilities.log.out(text)) {
|
|
469
|
+
await loadEngine2();
|
|
470
|
+
for (const d of diagnostics) print(renderDiagnostic(await withSource(capabilities, root, d)));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export {
|
|
474
|
+
scriptView,
|
|
475
|
+
clock,
|
|
476
|
+
narrationAt,
|
|
477
|
+
checkProject,
|
|
478
|
+
chapterIndexes,
|
|
479
|
+
exportCheck,
|
|
480
|
+
clipPlan,
|
|
481
|
+
previewTargets,
|
|
482
|
+
targetChapters,
|
|
483
|
+
previewJobs,
|
|
484
|
+
pictureStills,
|
|
485
|
+
pictureGroups,
|
|
486
|
+
movesMarkdown,
|
|
487
|
+
timelineView,
|
|
488
|
+
Parsers,
|
|
489
|
+
bundle,
|
|
490
|
+
printDiagnostics
|
|
491
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AULA_VOICE_FILES,
|
|
3
|
+
AULA_VOICE_RELEASE,
|
|
4
|
+
AULA_VOICE_WEIGHTS,
|
|
5
|
+
KOKORO_VOCAB,
|
|
6
|
+
aulaVoiceNarrator,
|
|
7
|
+
aulaVoiceUrl,
|
|
8
|
+
britishPhonemizer,
|
|
9
|
+
studentWeightFile,
|
|
10
|
+
tokenBatches
|
|
11
|
+
} from "./chunk-EYXQ2I7K.js";
|
|
12
|
+
|
|
13
|
+
// ../aula-narration/src/node.ts
|
|
14
|
+
import { Buffer } from "node:buffer";
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { fault } from "@beff/aula/errors";
|
|
18
|
+
var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
19
|
+
async function download(capabilities, fetch, downloading, destination, url, hash) {
|
|
20
|
+
if (capabilities.fs.existsSync(destination)) {
|
|
21
|
+
const kept = new Uint8Array(await capabilities.fs.readFile(destination));
|
|
22
|
+
if (sha256(kept) === hash) return kept;
|
|
23
|
+
}
|
|
24
|
+
downloading(path.basename(destination));
|
|
25
|
+
const response = await fetch(url, { headers: { "User-Agent": "aula" } });
|
|
26
|
+
if (!response.ok) throw new Error(`Cannot download ${url}: HTTP ${String(response.status)}`);
|
|
27
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
28
|
+
const expected = Number(response.headers.get("Content-Length") ?? 0);
|
|
29
|
+
if (expected && bytes.byteLength !== expected) throw new Error(`Incomplete download of ${url}; run again to retry`);
|
|
30
|
+
if (sha256(bytes) !== hash) {
|
|
31
|
+
fault(`the download of ${url} has the wrong SHA-256`, "run the command again; if it fails again, report it");
|
|
32
|
+
}
|
|
33
|
+
await capabilities.fs.mkdir(path.dirname(destination), { recursive: true });
|
|
34
|
+
await capabilities.fs.writeFile(`${destination}.part`, bytes);
|
|
35
|
+
await capabilities.fs.rename(`${destination}.part`, destination);
|
|
36
|
+
return bytes;
|
|
37
|
+
}
|
|
38
|
+
var phonemize = britishPhonemizer(new Set(KOKORO_VOCAB.keys()));
|
|
39
|
+
function textTokens() {
|
|
40
|
+
return (text) => tokenBatches(KOKORO_VOCAB, phonemize, text);
|
|
41
|
+
}
|
|
42
|
+
var aulaVoiceFolder = (models) => path.join(models, "aula-voice", AULA_VOICE_RELEASE);
|
|
43
|
+
async function aulaVoiceWeightFile(capabilities, options) {
|
|
44
|
+
const { fetch, models, downloading } = options;
|
|
45
|
+
const folder = aulaVoiceFolder(models);
|
|
46
|
+
const destination = path.join(folder, AULA_VOICE_WEIGHTS.path);
|
|
47
|
+
if (capabilities.fs.existsSync(destination)) {
|
|
48
|
+
const kept = new Uint8Array(await capabilities.fs.readFile(destination));
|
|
49
|
+
if (sha256(kept) === AULA_VOICE_WEIGHTS.sha256) return kept;
|
|
50
|
+
}
|
|
51
|
+
const { model, config } = AULA_VOICE_FILES;
|
|
52
|
+
const raw = (file) => download(capabilities, fetch, downloading, path.join(folder, file.path), aulaVoiceUrl(file), file.sha256);
|
|
53
|
+
const avw = studentWeightFile(await raw(model), await raw(config));
|
|
54
|
+
if (sha256(avw) !== AULA_VOICE_WEIGHTS.sha256) {
|
|
55
|
+
fault("the weight file made from aula-voice's release has the wrong SHA-256", "report it");
|
|
56
|
+
}
|
|
57
|
+
await capabilities.fs.writeFile(`${destination}.part`, avw);
|
|
58
|
+
await capabilities.fs.rename(`${destination}.part`, destination);
|
|
59
|
+
return avw;
|
|
60
|
+
}
|
|
61
|
+
function createAulaVoice(capabilities, options) {
|
|
62
|
+
return aulaVoiceNarrator("wasm", async () => {
|
|
63
|
+
const { aulaVoiceModel } = await import("./aula-voice-tts-ZXQ7XXHJ.js");
|
|
64
|
+
return { model: await aulaVoiceModel(await aulaVoiceWeightFile(capabilities, options)), phonemize };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function speakAnswer(speech) {
|
|
68
|
+
const bytes = new Uint8Array(speech.samples.buffer, speech.samples.byteOffset, speech.samples.byteLength);
|
|
69
|
+
return { sample_rate: speech.sampleRate, samples: Buffer.from(bytes).toString("base64"), words: speech.words };
|
|
70
|
+
}
|
|
71
|
+
function timeAnswer(timing) {
|
|
72
|
+
return { sample_rate: timing.sampleRate, samples: timing.samples, words: timing.words };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
textTokens,
|
|
77
|
+
aulaVoiceWeightFile,
|
|
78
|
+
createAulaVoice,
|
|
79
|
+
speakAnswer,
|
|
80
|
+
timeAnswer
|
|
81
|
+
};
|