@beff/aula 0.1.1 → 0.3.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/dist/engine.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Animation as RawAnimation, Mobject as RawMobject, Rate as RawRate, Chapter as RawChapter, Narration, NarrationWait, Screen } from "./generated/interfaces/aula-engine-engine.js";
1
+ import type { Animation as RawAnimation, Mobject as RawMobject, Rate as RawRate, Chapter as RawChapter, Narration, NarrationWait, Screen, LexiconEntry, SayPart } from "./generated/interfaces/aula-engine-engine.js";
2
2
  import type { Color, Diagnostic, Location, Point, ChapterText as RawChapterText, ParagraphText as RawParagraphText } from "./generated/interfaces/aula-engine-types.js";
3
+ import type { Lexicon } from "./lexicon.ts";
3
4
  import type { Theme } from "./theme.ts";
4
5
  import { type CapStyleType, type Complex, type LineJointType } from "./utils.ts";
5
6
  export type { Instant, Screen, Shown } from "./generated/interfaces/aula-engine-engine.js";
@@ -1306,7 +1307,7 @@ type RowData = {
1306
1307
  } | {
1307
1308
  readonly kind: "say";
1308
1309
  readonly call: Call;
1309
- readonly text: string;
1310
+ readonly parts: readonly SayPart[];
1310
1311
  } | {
1311
1312
  readonly kind: "show";
1312
1313
  readonly call: Call;
@@ -1332,8 +1333,9 @@ export interface Untimed {
1332
1333
  }
1333
1334
  /** The fields of `defineChapter`: one chapter of a project. */
1334
1335
  export interface ChapterFields {
1335
- /** The `##` heading, spoken first. */
1336
- heading: string;
1336
+ /** The `##` heading, spoken first: a plain string (the usual form), or a ``say`…` `` when a word
1337
+ * needs `pronounce`. The cards show the written text, and the narrator speaks the reading. */
1338
+ heading: string | SayRow;
1337
1339
  /** The one recurring picture that the chapter is built on. */
1338
1340
  metaphor: string;
1339
1341
  /** Makes the objects of the chapter and returns its rows in time order. aula calls it for
@@ -1341,7 +1343,13 @@ export interface ChapterFields {
1341
1343
  rows: () => Row[];
1342
1344
  }
1343
1345
  /** What `defineChapter` returns. */
1344
- export interface ChapterDefinition extends Readonly<ChapterFields> {
1346
+ export interface ChapterDefinition extends Readonly<Omit<ChapterFields, "heading">> {
1347
+ /** The heading as written: the cards, the chapter names and `aula script` show it. */
1348
+ readonly heading: string;
1349
+ /** The parts of the heading's `say`: a plain string is one part with no reading. */
1350
+ readonly headingParts: readonly SayPart[];
1351
+ /** The call of the heading's `say` (its line), or the defineChapter call for a plain string. */
1352
+ readonly headingCall: Error;
1345
1353
  /** The defineChapter call: its second frame is the chapter file (`definedAt` in
1346
1354
  * `@beff/aula/run`). */
1347
1355
  readonly call: Error;
@@ -1352,8 +1360,10 @@ export declare function defineChapter(fields: ChapterFields): ChapterDefinition;
1352
1360
  declare const PROJECT: unique symbol;
1353
1361
  /** The fields of `defineProject`: one project. */
1354
1362
  export interface ProjectFields {
1355
- /** The project title: the title card (chapter 0). The name of the project is its folder name. */
1356
- title: string;
1363
+ /** The project title: the title card (chapter 0). The name of the project is its folder name.
1364
+ * A plain string (the usual form), or a ``say`…` `` when a word needs `pronounce`. The title card
1365
+ * shows the written text, and the narrator speaks the reading. */
1366
+ title: string | SayRow;
1357
1367
  /** The storyboard header: recurring objects, symbols and colour rules. */
1358
1368
  storyboard?: string;
1359
1369
  /** The colours and text sizes of the chrome (title card, chapter cards, docked heading) and
@@ -1364,9 +1374,22 @@ export interface ProjectFields {
1364
1374
  card?: Card;
1365
1375
  /** The chapters, in order: the default exports of their chapter modules. */
1366
1376
  chapters: readonly ChapterDefinition[];
1377
+ /** The words that have one reading in all of the video: each key is a written word, and each
1378
+ * value is the reading that the narrator speaks at each use of the word in a `say`, in the
1379
+ * title and in a heading (the reading of `pronounce`). The match is the whole word, with marks around it and a
1380
+ * possessive `'s`, in the same case; a key that starts with a lowercase letter also matches
1381
+ * the word with a capital first letter. `pronounce` comes first, and aula's own lexicon and
1382
+ * misaki come after it. The default is no word. */
1383
+ lexicon?: Lexicon;
1367
1384
  }
1368
1385
  /** What `defineProject` returns. */
1369
- export interface ProjectDefinition extends Required<Omit<ProjectFields, "card" | "theme">> {
1386
+ export interface ProjectDefinition extends Required<Omit<ProjectFields, "card" | "theme" | "title">> {
1387
+ /** The title as written: the title card, the list of videos and `aula script` show it. */
1388
+ readonly title: string;
1389
+ /** The parts of the title's `say`: a plain string is one part with no reading. */
1390
+ readonly titleParts: readonly SayPart[];
1391
+ /** The call of the title's `say` (its line), or the defineProject call for a plain string. */
1392
+ readonly titleCall: Error;
1370
1393
  /** The theme that the project gives, if any. */
1371
1394
  readonly theme?: Theme;
1372
1395
  /** The card that the project gives, if any. */
@@ -1376,8 +1399,8 @@ export interface ProjectDefinition extends Required<Omit<ProjectFields, "card" |
1376
1399
  * `@beff/aula/run`). */
1377
1400
  readonly call: Error;
1378
1401
  }
1379
- /** `export default defineProject({ title, storyboard, theme, chapters })`: one project, in the
1380
- * `index.ts` of its folder. Makes no engine call. */
1402
+ /** `export default defineProject({ title, storyboard, theme, lexicon, chapters })`: one project,
1403
+ * in the `index.ts` of its folder. Makes no engine call. */
1381
1404
  export declare function defineProject(fields: ProjectFields): ProjectDefinition;
1382
1405
  /** True for a value that defineProject made. */
1383
1406
  export declare function isProjectDefinition(v: unknown): v is ProjectDefinition;
@@ -1385,11 +1408,46 @@ export declare function isProjectDefinition(v: unknown): v is ProjectDefinition;
1385
1408
  * under the paragraph. `check` is for kits: aula calls it one time, after the chapter is drawn,
1386
1409
  * and reports its findings. */
1387
1410
  export declare function paragraph(notes?: Notes, check?: Check): Row;
1388
- /** The text of a row tag (`name` is the tag): one template with no `${…}`, no invalid escape
1389
- * and no line break. Throws a AulaError at the row. A kit's own row tag calls it. */
1390
- export declare function tagText(name: string, strings: TemplateStringsArray): string;
1391
- /** ``say`text` ``: the next words of the narration. */
1392
- export declare function say(strings: TemplateStringsArray): Row;
1411
+ declare const PRONOUNCE: unique symbol;
1412
+ /** How the narrator reads the word of `pronounce`: `{ say: "…" }` is plain text, which goes
1413
+ * through the normal front end (aula's lexicon, then misaki), and `{ phonemes: "…" }` is
1414
+ * phonemes of Kokoro's token table (misaki's symbols, as `aula tokens` shows them). */
1415
+ export type Reading = {
1416
+ readonly say: string;
1417
+ } | {
1418
+ readonly phonemes: string;
1419
+ };
1420
+ /** What `pronounce` returns: one written word and its reading. Only a `say` takes it: a `say` row,
1421
+ * or a `say` that is the `title` of `defineProject` or the `heading` of `defineChapter`. */
1422
+ export interface Pronounce {
1423
+ readonly [PRONOUNCE]: true;
1424
+ readonly written: string;
1425
+ readonly reading: Reading;
1426
+ }
1427
+ /** ``say`The file is 4 ${pronounce("GB", { say: "gigabytes" })}.` ``: one word that the
1428
+ * screen, the word times and `aula script` show as `written`, and that the narrator reads as
1429
+ * `reading`. The written part is one word, and its word time covers all of the reading. Use it
1430
+ * only for a word whose reading changes with the context. It goes in a `say`: a row, the
1431
+ * `title` of `defineProject` or the `heading` of `defineChapter`. `aula check` gives an error when the
1432
+ * written part is not one word, or when a phoneme is not in Kokoro's token table. */
1433
+ export declare function pronounce(written: string, reading: Reading): Pronounce;
1434
+ /** The text of a row tag (`name` is the tag), as written: one template with no invalid escape
1435
+ * and no line break. A `${…}` can only be the value of `pronounce`, and its written word is in
1436
+ * the text. Throws a AulaError at the row. A kit's own row tag calls it with the values of its
1437
+ * template. */
1438
+ export declare function tagText(name: string, strings: TemplateStringsArray, ...values: readonly unknown[]): string;
1439
+ declare const SAY: unique symbol;
1440
+ /** What ``say`…` `` returns: a row of the narration, or the `title` of `defineProject` or the
1441
+ * `heading` of `defineChapter`. */
1442
+ export interface SayRow extends Row {
1443
+ readonly [SAY]: true;
1444
+ }
1445
+ /** ``say`text` ``: the next words of the narration. A `${…}` can only be
1446
+ * `pronounce(written, reading)`: ``say`The file is 4 ${pronounce("GB", { say: "gigabytes" })}.` ``.
1447
+ * The written text is on the screen where aula shows the text (the cards, for a title or a
1448
+ * heading), in the word times and in `aula script`, and the narrator speaks the reading. A
1449
+ * `say` is a row, the `title` of `defineProject` or the `heading` of `defineChapter`. */
1450
+ export declare function say(strings: TemplateStringsArray, ...words: readonly Pronounce[]): SayRow;
1393
1451
  /** ``show`note``timing` ``: a move. The note says what changes on screen. The timing, a
1394
1452
  * second template right after the note, gives the length of the move: ``25%`` is a share of the
1395
1453
  * `say` above it (0 < N <= 100) and scales with the narration, and ``3s`` is seconds (N > 0).
@@ -1513,6 +1571,8 @@ export interface ChapterSlot {
1513
1571
  file: string;
1514
1572
  /** The frames of an error (`Host.frames`). */
1515
1573
  frames(error: Error): readonly StackFrame[];
1574
+ /** The project lexicon in the engine's form. */
1575
+ lexicon: readonly LexiconEntry[];
1516
1576
  }
1517
1577
  /** Reads a chapter: calls `rows` and no move. It gives the text and the text problems; the
1518
1578
  * paragraph checks run only in `drawRows`. A chapter error is thrown (a AulaError, a WIT
@@ -1529,7 +1589,7 @@ export declare function checkRows(chapter: ChapterDefinition, theme: Theme, card
1529
1589
  diagnostics: Diagnostic[];
1530
1590
  };
1531
1591
  /** Checks chapter 0: the card of the project `title`, with no clock. */
1532
- export declare function checkTitle(title: string, theme: Theme, card: Card, count: number): {
1592
+ export declare function checkTitleCard(title: string, theme: Theme, card: Card, count: number): {
1533
1593
  diagnostics: Diagnostic[];
1534
1594
  };
1535
1595
  /** How a chapter is drawn against a narration. */
package/dist/engine.js CHANGED
@@ -2912,13 +2912,39 @@ const ROW = Symbol("aula.row");
2912
2912
  /** `export default defineChapter({ heading, metaphor, rows: () => [ … ] })`: one chapter.
2913
2913
  * Makes no engine call. */
2914
2914
  export function defineChapter(fields) {
2915
- return { ...fields, call: new Error("defineChapter") };
2915
+ const call = new Error("defineChapter");
2916
+ const heading = spokenField("defineChapter", "heading", fields.heading, call);
2917
+ return { ...fields, heading: heading.text, headingParts: heading.parts, headingCall: heading.call, call };
2918
+ }
2919
+ /** The written text, the parts and the call of a `title` or a `heading` (`field`): a plain
2920
+ * string (one part with no reading, at `call`), or a `say` (its parts, at its own call). Any
2921
+ * other value is a fault. */
2922
+ function spokenField(name, field, value, call) {
2923
+ if (typeof value === "string")
2924
+ return { text: value, parts: [{ text: value }], call };
2925
+ if (!isSay(value)) {
2926
+ fault(`${name}: the ${field} must be a string or a say`, `${field}: "text" or ${field}: say\`text \${pronounce("word", { say: "words" })}\``);
2927
+ }
2928
+ const data = value[ROW];
2929
+ const parts = data.kind === "say" ? data.parts : [];
2930
+ return { text: parts.map((p) => p.text).join(""), parts, call: data.call };
2916
2931
  }
2917
2932
  const PROJECT = Symbol("aula.project");
2918
- /** `export default defineProject({ title, storyboard, theme, chapters })`: one project, in the
2919
- * `index.ts` of its folder. Makes no engine call. */
2933
+ /** `export default defineProject({ title, storyboard, theme, lexicon, chapters })`: one project,
2934
+ * in the `index.ts` of its folder. Makes no engine call. */
2920
2935
  export function defineProject(fields) {
2921
- return { [PROJECT]: true, storyboard: "", ...fields, call: new Error("defineProject") };
2936
+ const call = new Error("defineProject");
2937
+ const title = spokenField("defineProject", "title", fields.title, call);
2938
+ return {
2939
+ [PROJECT]: true,
2940
+ storyboard: "",
2941
+ lexicon: {},
2942
+ ...fields,
2943
+ title: title.text,
2944
+ titleParts: title.parts,
2945
+ titleCall: title.call,
2946
+ call,
2947
+ };
2922
2948
  }
2923
2949
  /** True for a value that defineProject made. */
2924
2950
  export function isProjectDefinition(v) {
@@ -2938,25 +2964,81 @@ function row(name, data) {
2938
2964
  export function paragraph(notes = {}, check) {
2939
2965
  return row("paragraph", (call) => ({ kind: "paragraph", call, notes, check }));
2940
2966
  }
2941
- /** The text of a row tag (`name` is the tag): one template with no `${…}`, no invalid escape
2942
- * and no line break. Throws a AulaError at the row. A kit's own row tag calls it. */
2943
- export function tagText(name, strings) {
2944
- if (strings.length !== 1) {
2967
+ const PRONOUNCE = Symbol("aula.pronounce");
2968
+ /** ``say`The file is 4 ${pronounce("GB", { say: "gigabytes" })}.` ``: one word that the
2969
+ * screen, the word times and `aula script` show as `written`, and that the narrator reads as
2970
+ * `reading`. The written part is one word, and its word time covers all of the reading. Use it
2971
+ * only for a word whose reading changes with the context. It goes in a `say`: a row, the
2972
+ * `title` of `defineProject` or the `heading` of `defineChapter`. `aula check` gives an error when the
2973
+ * written part is not one word, or when a phoneme is not in Kokoro's token table. */
2974
+ export function pronounce(written, reading) {
2975
+ const usage = 'pronounce("word", { say: "words" }) or pronounce("word", { phonemes: "fˈQnimz" })';
2976
+ if (typeof written !== "string")
2977
+ fault("pronounce: the written word must be a string", usage);
2978
+ const r = reading;
2979
+ const one = typeof r === "object" &&
2980
+ r !== null &&
2981
+ Object.keys(r).length === 1 &&
2982
+ (("say" in r && typeof r.say === "string") || ("phonemes" in r && typeof r.phonemes === "string"));
2983
+ if (!one)
2984
+ fault("pronounce: give the reading as { say: string } or { phonemes: string }", usage);
2985
+ return { [PRONOUNCE]: true, written, reading };
2986
+ }
2987
+ /** True for a value that `pronounce` made. */
2988
+ function isPronounce(v) {
2989
+ return typeof v === "object" && v !== null && PRONOUNCE in v;
2990
+ }
2991
+ /** The parts of a row tag's text: each piece of the template, and the written word and the
2992
+ * reading of each `pronounce` between them. Every other `${…}` is an error. */
2993
+ function tagParts(name, strings, values) {
2994
+ if (strings.length !== values.length + 1) {
2945
2995
  fault(`${name}: write the text as it is, with no \${…}`, "the text in the source is the text that is spoken");
2946
2996
  }
2947
- const text = strings[0];
2948
- if (text === undefined) {
2949
- fault(`${name}: the text has an invalid escape`, "escape only a backtick, a backslash and ${ with a backslash");
2950
- }
2951
- if (/[\r\n]/.test(text)) {
2952
- fault(`${name}: write the text on one line`, "a row's text stays on the line of its call");
2953
- }
2954
- return text;
2955
- }
2956
- /** ``say`text` ``: the next words of the narration. */
2957
- export function say(strings) {
2958
- const text = tagText("say", strings);
2959
- return row("say", (call) => ({ kind: "say", call, text }));
2997
+ const parts = [];
2998
+ strings.forEach((text, i) => {
2999
+ if (text === undefined) {
3000
+ fault(`${name}: the text has an invalid escape`, "escape only a backtick, a backslash and ${ with a backslash");
3001
+ }
3002
+ if (/[\r\n]/.test(text)) {
3003
+ fault(`${name}: write the text on one line`, "a row's text stays on the line of its call");
3004
+ }
3005
+ if (text !== "")
3006
+ parts.push({ text });
3007
+ if (i === values.length)
3008
+ return;
3009
+ const value = values[i];
3010
+ if (!isPronounce(value)) {
3011
+ fault(`${name}: write the text as it is; a \${…} can only be pronounce(written, reading)`, "the text in the source is the text that is spoken");
3012
+ }
3013
+ const reading = "say" in value.reading
3014
+ ? { tag: "words", val: value.reading.say }
3015
+ : { tag: "phonemes", val: value.reading.phonemes };
3016
+ parts.push({ text: value.written, reading });
3017
+ });
3018
+ return parts;
3019
+ }
3020
+ /** The text of a row tag (`name` is the tag), as written: one template with no invalid escape
3021
+ * and no line break. A `${…}` can only be the value of `pronounce`, and its written word is in
3022
+ * the text. Throws a AulaError at the row. A kit's own row tag calls it with the values of its
3023
+ * template. */
3024
+ export function tagText(name, strings, ...values) {
3025
+ return tagParts(name, strings, values)
3026
+ .map((p) => p.text)
3027
+ .join("");
3028
+ }
3029
+ const SAY = Symbol("aula.say");
3030
+ /** True for a value that `say` made. */
3031
+ function isSay(v) {
3032
+ return typeof v === "object" && v !== null && SAY in v;
3033
+ }
3034
+ /** ``say`text` ``: the next words of the narration. A `${…}` can only be
3035
+ * `pronounce(written, reading)`: ``say`The file is 4 ${pronounce("GB", { say: "gigabytes" })}.` ``.
3036
+ * The written text is on the screen where aula shows the text (the cards, for a title or a
3037
+ * heading), in the word times and in `aula script`, and the narrator speaks the reading. A
3038
+ * `say` is a row, the `title` of `defineProject` or the `heading` of `defineChapter`. */
3039
+ export function say(strings, ...words) {
3040
+ const parts = tagParts("say", strings, words);
3041
+ return { ...row("say", (call) => ({ kind: "say", call, parts })), [SAY]: true };
2960
3042
  }
2961
3043
  /** ``show`note``timing` ``: a move. The note says what changes on screen. The timing, a
2962
3044
  * second template right after the note, gives the length of the move: ``25%`` is a share of the
@@ -3178,7 +3260,8 @@ function noteList(notes) {
3178
3260
  }
3179
3261
  /** Gives the rows to the engine in order; with a scene, it runs each move after its `show`. */
3180
3262
  function write(handle, chapter, rows, slot, scene, card) {
3181
- handle.header(placeIn(chapter.call, slot), chapter.heading, chapter.metaphor);
3263
+ handle.lexicon([...slot.lexicon]);
3264
+ handle.header(placeIn(chapter.headingCall, slot), [...chapter.headingParts], chapter.metaphor);
3182
3265
  card?.();
3183
3266
  for (const r of rows) {
3184
3267
  const at = placeIn(r.call, slot);
@@ -3186,7 +3269,7 @@ function write(handle, chapter, rows, slot, scene, card) {
3186
3269
  handle.paragraph(at, noteList(r.notes));
3187
3270
  }
3188
3271
  else if (r.kind === "say") {
3189
- handle.say(at, r.text);
3272
+ handle.say(at, [...r.parts]);
3190
3273
  }
3191
3274
  else if (r.move === undefined) {
3192
3275
  handle.open(at, r.note, r.timing);
@@ -3297,10 +3380,10 @@ export function checkRows(chapter, theme, card, slot, exists) {
3297
3380
  };
3298
3381
  }
3299
3382
  /** Checks chapter 0: the card of the project `title`, with no clock. */
3300
- export function checkTitle(title, theme, card, count) {
3383
+ export function checkTitleCard(title, theme, card, count) {
3301
3384
  freshSeed();
3302
3385
  const handle = engine.Chapter.orderPass(0, count + 1);
3303
- const slot = { number: 0, count, source: "", file: "", frames: () => [] };
3386
+ const slot = { number: 0, count, source: "", file: "", frames: () => [], lexicon: [] };
3304
3387
  const scene = playCard(handle, slot, { file: "", line: 0, col: 0 }, card, { title, chapter: 0, count, theme });
3305
3388
  handle.finish();
3306
3389
  return { diagnostics: [...handle.report(), ...scene.warnings] };
@@ -3336,7 +3419,7 @@ export function drawTitle(title, theme, card, drawing) {
3336
3419
  freshSeed();
3337
3420
  const handle = engine.Chapter.render(drawing.narration, theme.background, 0, drawing.count, drawing.name, drawing.lint);
3338
3421
  const count = drawing.count - 1;
3339
- const slot = { number: 0, count, source: "", file: "", frames: () => [] };
3422
+ const slot = { number: 0, count, source: "", file: "", frames: () => [], lexicon: [] };
3340
3423
  playCard(handle, slot, { file: "", line: 0, col: 0 }, card, { title, chapter: 0, count, theme });
3341
3424
  return finished(handle);
3342
3425
  }
@@ -3344,7 +3427,7 @@ export function drawTitle(title, theme, card, drawing) {
3344
3427
  * second, on a black background. There is no project, no narration and no heading. */
3345
3428
  export function renderScene(draw) {
3346
3429
  const handle = engine.Chapter.scene();
3347
- const slot = { number: 0, count: 1, source: "scene", file: "scene", frames: () => [] };
3430
+ const slot = { number: 0, count: 1, source: "scene", file: "scene", frames: () => [], lexicon: [] };
3348
3431
  draw(new Scene(handle, slot));
3349
3432
  handle.finish();
3350
3433
  const trace = JSON.parse(handle.trace());
Binary file
Binary file
Binary file