@beff/aula 0.1.0 → 0.2.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.
@@ -20,6 +20,14 @@ export function polygon(points: Array<Point>): Mobject;
20
20
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
21
21
  */
22
22
  export function polyline(points: Array<Point>): Mobject;
23
+ /**
24
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
25
+ */
26
+ export function pathBoolean(op: BooleanOp, shapes: Array<Array<Array<Point>>>): Array<Point>;
27
+ /**
28
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
29
+ */
30
+ export function pointSquares(points: Array<Point>, side: number): Mobject;
23
31
  /**
24
32
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
25
33
  */
@@ -132,6 +140,10 @@ export function fadeOutTo(m: Mobject, p: Point): Animation;
132
140
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
133
141
  */
134
142
  export function fadeTransform(a: Mobject, b: Mobject, stretch: boolean, dimToMatch: number): Animation;
143
+ /**
144
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
145
+ */
146
+ export function fadeTransformPieces(a: Mobject, b: Mobject, stretch: boolean, dimToMatch: number): Animation;
135
147
  export function create(m: Mobject): Animation;
136
148
  export function uncreate(m: Mobject): Animation;
137
149
  export function write(m: Mobject, reverse: boolean): Animation;
@@ -201,7 +213,7 @@ export function wait(): Animation;
201
213
  export function settle(anims: Array<Animation>): void;
202
214
  export function constants(): EngineConstants;
203
215
  export function scriptMarkdown(title: string, texts: Array<ChapterText>): string;
204
- export function narrationScript(title: string, texts: Array<ChapterText>): Array<Array<ScriptCue>>;
216
+ export function narrationScript(title: string, lexicon: Array<LexiconEntry>, texts: Array<ChapterText>): Array<Array<ScriptCue>>;
205
217
  /**
206
218
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
207
219
  */
@@ -216,7 +228,12 @@ export function fps(): number;
216
228
  /**
217
229
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
218
230
  */
219
- export function phonemize(text: string): string;
231
+ export function phonemize(text: string, lexicon: Array<LexiconEntry>): string;
232
+ export function checkLexicon(place: Location, entries: Array<LexiconEntry>): Array<Diagnostic>;
233
+ /**
234
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
235
+ */
236
+ export function misaki(text: string): string;
220
237
  export type Point = import('./aula-engine-types.js').Point;
221
238
  export type Color = import('./aula-engine-types.js').Color;
222
239
  export type Diagnostic = import('./aula-engine-types.js').Diagnostic;
@@ -406,6 +423,18 @@ export interface CodeSettings {
406
423
  fontSize: number,
407
424
  lineSpacing: number,
408
425
  }
426
+ /**
427
+ * # Variants
428
+ *
429
+ * ## `"union"`
430
+ *
431
+ * ## `"intersection"`
432
+ *
433
+ * ## `"difference"`
434
+ *
435
+ * ## `"exclusion"`
436
+ */
437
+ export type BooleanOp = "union" | "intersection" | "difference" | "exclusion";
409
438
  export interface NumberSettings {
410
439
  numDecimalPlaces: number,
411
440
  includeSign: boolean,
@@ -511,6 +540,23 @@ export interface NarrationWait {
511
540
  sample: number,
512
541
  samples: number,
513
542
  }
543
+ export type Pronunciation = PronunciationWords | PronunciationPhonemes;
544
+ export interface PronunciationWords {
545
+ tag: 'words',
546
+ val: string,
547
+ }
548
+ export interface PronunciationPhonemes {
549
+ tag: 'phonemes',
550
+ val: string,
551
+ }
552
+ export interface SayPart {
553
+ text: string,
554
+ reading?: Pronunciation,
555
+ }
556
+ export interface LexiconEntry {
557
+ word: string,
558
+ reading: Pronunciation,
559
+ }
514
560
  /**
515
561
  * # Variants
516
562
  *
@@ -523,6 +569,7 @@ export interface NarrationWait {
523
569
  export type CueKind = "title" | "heading" | "paragraph";
524
570
  export interface ScriptCue {
525
571
  text: string,
572
+ spoken: string,
526
573
  kind: CueKind,
527
574
  place?: string,
528
575
  leadIn: number,
@@ -620,12 +667,11 @@ export class Chapter implements Disposable {
620
667
  /**
621
668
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
622
669
  */
623
- static render(narration: Narration, background: Color, chapter: number, count: number, name: string, lint: boolean, text: ChapterText | undefined): Chapter;
670
+ static render(narration: Narration, background: Color, chapter: number, count: number, name: string, lint: boolean): Chapter;
624
671
  /**
625
672
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
626
673
  */
627
674
  static scene(): Chapter;
628
- narratedParagraphs(): number;
629
675
  /**
630
676
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
631
677
  */
@@ -637,7 +683,8 @@ export class Chapter implements Disposable {
637
683
  /**
638
684
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
639
685
  */
640
- say(place: Location, text: string): void;
686
+ say(place: Location, parts: Array<SayPart>): void;
687
+ lexicon(entries: Array<LexiconEntry>): void;
641
688
  /**
642
689
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
643
690
  */
@@ -38,6 +38,7 @@ export interface Note {
38
38
  export interface Say {
39
39
  place: Location,
40
40
  text: string,
41
+ spoken: string,
41
42
  }
42
43
  export interface Move {
43
44
  place: Location,
package/dist/geometry.js CHANGED
@@ -1361,305 +1361,39 @@ export function LabeledPolygram(...args) {
1361
1361
  l.moveTo(polylabel(groups, precision));
1362
1362
  return m.add(l);
1363
1363
  }
1364
- function lineCubic(a, b) {
1365
- return [a, lerp(a, b, 1 / 3), lerp(a, b, 2 / 3), b];
1366
- }
1367
- function reversed(c) {
1368
- return [c[3], c[2], c[1], c[0]];
1369
- }
1370
- /** The loops of the family of `m`, each closed with a straight piece as Skia closes a filled path. */
1371
- function loopsOf(m) {
1372
- const out = [];
1373
- const close = (loop) => {
1374
- const [first, last] = [loop[0], loop.at(-1)];
1375
- if (first === undefined || last === undefined)
1376
- return;
1377
- if (!same(last[3], first[0], 1e-6))
1378
- loop.push(lineCubic(last[3], first[0]));
1379
- out.push(loop);
1380
- };
1381
- for (const member of m.getFamily()) {
1382
- let loop = [];
1383
- for (const c of cubics(member.getPoints())) {
1384
- if (c.every((p) => same(p, c[0], 0)))
1385
- continue;
1386
- const last = loop.at(-1);
1387
- if (last !== undefined && !same(last[3], c[0], 1e-6)) {
1388
- close(loop);
1389
- loop = [];
1390
- }
1391
- loop.push(c);
1392
- }
1393
- close(loop);
1394
- }
1395
- return out;
1396
- }
1397
- /** The real roots of `a t² + b t + c`. */
1398
- function quadraticRoots(a, b, c) {
1399
- if (Math.abs(a) < 1e-12)
1400
- return Math.abs(b) < 1e-12 ? [] : [-c / b];
1401
- const d = b * b - 4 * a * c;
1402
- if (d < 0)
1403
- return [];
1404
- const s = Math.sqrt(d);
1405
- return [(-b - s) / (2 * a), (-b + s) / (2 * a)];
1406
- }
1407
- /** The parameter ranges of `c` where its `y` only rises or only falls. */
1408
- function yMonotonic(c) {
1409
- const [a, b, d] = [c[1][1] - c[0][1], c[2][1] - c[1][1], c[3][1] - c[2][1]];
1410
- const roots = quadraticRoots(a - 2 * b + d, 2 * (b - a), a).filter((t) => t > 0 && t < 1);
1411
- const ts = [0, ...roots.toSorted((x, y) => x - y), 1];
1412
- return ts.slice(1).map((t, i) => [ts[i] ?? 0, t]);
1413
- }
1414
- /** Non-zero inside test of `p` in the loops, as Skia and the renderer fill. */
1415
- function insideLoops(p, loops) {
1416
- let winding = 0;
1417
- for (const loop of loops)
1418
- for (const c of loop)
1419
- for (const [t0, t1] of yMonotonic(c)) {
1420
- const [y0, y1] = [cubicAt(c, t0)[1], cubicAt(c, t1)[1]];
1421
- if (y0 > p[1] === y1 > p[1])
1422
- continue;
1423
- let [lo, hi] = [t0, t1];
1424
- for (let i = 0; i < 60; i++) {
1425
- const mid = (lo + hi) / 2;
1426
- if (cubicAt(c, mid)[1] > p[1] === y0 > p[1])
1427
- lo = mid;
1428
- else
1429
- hi = mid;
1430
- }
1431
- if (cubicAt(c, (lo + hi) / 2)[0] > p[0])
1432
- winding += y1 > y0 ? 1 : -1;
1433
- }
1434
- return winding !== 0;
1435
- }
1436
- function bezierDerivative(c, t) {
1437
- const u = 1 - t;
1438
- const [a, b, d] = [sub(c[1], c[0]), sub(c[2], c[1]), sub(c[3], c[2])];
1439
- return add(add(mul(a, 3 * u * u), mul(b, 6 * u * t)), mul(d, 3 * t * t));
1440
- }
1441
- function flat(c) {
1442
- const v = sub(c[3], c[0]);
1443
- const n = norm(v);
1444
- const off = (q) => (n === 0 ? norm(sub(q, c[0])) : Math.abs(cross(v, sub(q, c[0]))) / n);
1445
- return Math.max(off(c[1]), off(c[2])) < 1e-9;
1446
- }
1447
- function boxesMeet(a, b) {
1448
- for (const k of [0, 1]) {
1449
- const [as, bs] = [a.map((p) => p[k]), b.map((p) => p[k])];
1450
- if (Math.min(...as) > Math.max(...bs) + 1e-9 || Math.min(...bs) > Math.max(...as) + 1e-9)
1451
- return false;
1452
- }
1453
- return true;
1454
- }
1455
- /** The crossings of two cubics: subdivision down to flat pieces, then Newton steps on the curves. */
1456
- function crossings(a, b) {
1457
- const rough = [];
1458
- const go = (pa, ta, pb, tb, depth) => {
1459
- if (!boxesMeet(pa, pb))
1460
- return;
1461
- const [fa, fb] = [flat(pa), flat(pb)];
1462
- if ((fa && fb) || depth > 48) {
1463
- const [r, s] = [sub(pa[3], pa[0]), sub(pb[3], pb[0])];
1464
- const den = cross(r, s);
1465
- if (Math.abs(den) <= 1e-12 * norm(r) * norm(s)) {
1466
- // Two straight curves on one line cut each other at the ends of their common part.
1467
- if (depth > 0 || Math.abs(cross(r, sub(pb[0], pa[0]))) > 1e-9 * norm(r))
1468
- return;
1469
- const on = (q, from, v) => dot(sub(q, from), v) / dot(v, v);
1470
- const commonEnds = [
1471
- { t: on(pb[0], pa[0], r), u: 0 },
1472
- { t: on(pb[3], pa[0], r), u: 1 },
1473
- { t: 0, u: on(pa[0], pb[0], s) },
1474
- { t: 1, u: on(pa[3], pb[0], s) },
1475
- ];
1476
- rough.push(...commonEnds.filter((h) => h.t >= 0 && h.t <= 1 && h.u >= 0 && h.u <= 1));
1477
- return;
1478
- }
1479
- const t = cross(sub(pb[0], pa[0]), s) / den;
1480
- const u = cross(sub(pb[0], pa[0]), r) / den;
1481
- if (t < -1e-9 || t > 1 + 1e-9 || u < -1e-9 || u > 1 + 1e-9)
1482
- return;
1483
- rough.push({ t: ta[0] + (ta[1] - ta[0]) * clip01(t), u: tb[0] + (tb[1] - tb[0]) * clip01(u) });
1484
- return;
1485
- }
1486
- const halves = (c, ts, isFlat) => {
1487
- if (isFlat)
1488
- return [[c, ts]];
1489
- const half = (ts[0] + ts[1]) / 2;
1490
- return [
1491
- [cubicPart(c, 0, 0.5), [ts[0], half]],
1492
- [cubicPart(c, 0.5, 1), [half, ts[1]]],
1493
- ];
1494
- };
1495
- for (const [ca, ra] of halves(pa, ta, fa))
1496
- for (const [cb, rb] of halves(pb, tb, fb))
1497
- go(ca, ra, cb, rb, depth + 1);
1498
- };
1499
- go(a, [0, 1], b, [0, 1], 0);
1500
- const hits = [];
1501
- for (let { t, u } of rough) {
1502
- for (let i = 0; i < 8; i++) {
1503
- const f = sub(cubicAt(a, t), cubicAt(b, u));
1504
- const [da, db] = [bezierDerivative(a, t), bezierDerivative(b, u)];
1505
- const det = -cross(da, db);
1506
- if (Math.abs(det) < 1e-14)
1507
- break;
1508
- const [nt, nu] = [clip01(t + cross(f, db) / det), clip01(u - cross(da, f) / det)];
1509
- if (norm(sub(cubicAt(a, nt), cubicAt(b, nu))) > norm(f))
1510
- break;
1511
- [t, u] = [nt, nu];
1512
- }
1513
- const p = lerp(cubicAt(a, t), cubicAt(b, u), 0.5);
1514
- if (!hits.some((h) => same(h.p, p, 1e-7)))
1515
- hits.push({ t, u, p });
1516
- }
1517
- return hits;
1518
- }
1519
- /** The pieces of `c` between its cuts; each cut point ends one piece and starts the next. */
1520
- function cutCubic(c, cuts) {
1521
- const inner = cuts.filter((k) => k.t > 1e-9 && k.t < 1 - 1e-9).toSorted((x, y) => x.t - y.t);
1522
- const stops = [{ t: 0, p: c[0] }];
1523
- for (const k of inner)
1524
- if (k.t - (stops.at(-1)?.t ?? 0) > 1e-9)
1525
- stops.push(k);
1526
- stops.push({ t: 1, p: c[3] });
1527
- return stops.slice(1).map((end, i) => {
1528
- const start = stops[i] ?? end;
1529
- const part = cubicPart(c, start.t, end.t);
1530
- return [start.p, part[1], part[2], end.p];
1531
- });
1532
- }
1533
- /** The curves of both shapes, cut where they cross. */
1534
- function cutAll(la, lb) {
1535
- const [ca, cb] = [la.flat(), lb.flat()];
1536
- const cutsA = ca.map(() => []);
1537
- const cutsB = cb.map(() => []);
1538
- ca.forEach((a, i) => {
1539
- cb.forEach((b, j) => {
1540
- for (const h of crossings(a, b)) {
1541
- cutsA[i]?.push({ t: h.t, p: h.p });
1542
- cutsB[j]?.push({ t: h.u, p: h.p });
1543
- }
1544
- });
1545
- });
1546
- return [ca.flatMap((c, i) => cutCubic(c, cutsA[i] ?? [])), cb.flatMap((c, i) => cutCubic(c, cutsB[i] ?? []))];
1547
- }
1548
- /** Where the curve heads at its start or end: the first handle that is not on the anchor. */
1549
- function heading(c, atEnd) {
1550
- const ds = atEnd
1551
- ? [sub(c[3], c[2]), sub(c[3], c[1]), sub(c[3], c[0])]
1552
- : [sub(c[1], c[0]), sub(c[2], c[0]), sub(c[3], c[0])];
1553
- return ds.find((d) => norm(d) > 1e-12) ?? [1, 0];
1554
- }
1555
- /** The turn from heading `into` to heading `out`, counter-clockwise positive. */
1556
- function turnAngle(into, out) {
1557
- return Math.atan2(cross(into, out), dot(into, out));
1558
- }
1559
- /** Two straight pieces in a row on one line become one, as Skia writes them. */
1560
- function mergeLines(loop) {
1561
- const inLine = (a, b) => isStraight(a) && isStraight(b) && Math.abs(cross(unit(sub(a[3], a[0])), unit(sub(b[3], b[0])))) < 1e-9;
1562
- const out = [];
1563
- for (const c of loop) {
1564
- const last = out.at(-1);
1565
- if (last !== undefined && inLine(last, c))
1566
- out[out.length - 1] = lineCubic(last[0], c[3]);
1567
- else
1568
- out.push(c);
1569
- }
1570
- const [first, last] = [out[0], out.at(-1)];
1571
- if (out.length > 2 && first !== undefined && last !== undefined && inLine(last, first))
1572
- return [lineCubic(last[0], first[3]), ...out.slice(1, -1)];
1573
- return out;
1574
- }
1575
- /** The kept pieces, each with the result on its left, joined into closed loops. At a point
1576
- * where loops touch, each loop takes the piece that turns most to the left, so the loops stay
1577
- * apart. The outer loops turn counter-clockwise and the holes clockwise, so the even-odd fill
1578
- * and the non-zero fill agree. */
1579
- function joinLoops(pieces) {
1580
- const used = new Set();
1581
- const found = [];
1582
- pieces.forEach((first, i) => {
1583
- if (used.has(i))
1584
- return;
1585
- used.add(i);
1586
- const loop = [first];
1587
- for (;;) {
1588
- const last = loop.at(-1) ?? first;
1589
- const into = heading(last, true);
1590
- let [best, bestTurn] = [-1, -Infinity];
1591
- pieces.forEach((c, k) => {
1592
- if (used.has(k) || !same(c[0], last[3], 1e-6))
1593
- return;
1594
- const t = turnAngle(into, heading(c, false));
1595
- if (t > bestTurn)
1596
- [best, bestTurn] = [k, t];
1597
- });
1598
- const closing = same(first[0], last[3], 1e-6);
1599
- if (closing && turnAngle(into, heading(first, false)) >= bestTurn) {
1600
- loop[loop.length - 1] = [last[0], last[1], last[2], first[0]];
1601
- break;
1602
- }
1603
- const next = pieces[best];
1604
- if (next === undefined)
1605
- break;
1606
- used.add(best);
1607
- loop.push([last[3], next[1], next[2], next[3]]);
1608
- }
1609
- found.push(mergeLines(loop));
1610
- });
1611
- return found.flat(2);
1612
- }
1613
- /** The boundary of the result, as Skia's path operations make it: the curves of `a` and `b`
1614
- * cut where they cross. A piece is kept when the result is on one side of it and not on the
1615
- * other, and it is turned so that the result is on its left. A piece that both shapes have
1616
- * is kept one time. */
1617
- function boolean(label, a, b, op) {
1618
- const [la, lb] = [loopsOf(a), loopsOf(b)];
1619
- if (la.length === 0 || lb.length === 0)
1620
- wrong(label, "each Mobject needs a closed path");
1621
- const [pa, pb] = cutAll(la, lb);
1622
- const kept = [];
1623
- for (const c of [...pa, ...pb]) {
1624
- const p = cubicAt(c, 0.5);
1625
- const left = mul(rotated(unit(bezierDerivative(c, 0.5)), PI / 2), 1e-6);
1626
- const inResult = (q) => op(insideLoops(q, la), insideLoops(q, lb));
1627
- const [onLeft, onRight] = [inResult(add(p, left)), inResult(sub(p, left))];
1628
- if (onLeft === onRight)
1629
- continue;
1630
- const piece = onLeft ? c : reversed(c);
1631
- const twin = (k) => same(k[0], piece[0], 1e-7) && same(k[3], piece[3], 1e-7) && same(cubicAt(k, 0.5), p, 1e-7);
1632
- if (!kept.some(twin))
1633
- kept.push(piece);
1634
- }
1635
- return joinLoops(kept);
1636
- }
1637
- function fold(label, ms, op, style) {
1364
+ // --- boolean operations ----------------------------------------------------------------
1365
+ /** Manim's boolean operations, in the engine: Skia's PathOps and skia-pathops' contour
1366
+ * directions and start points, so the points and their order are Manim's (a Transform from a
1367
+ * boolean shape moves as in Manim). Each shape gives the points of each member of its family. */
1368
+ function fold(label, ms, style) {
1638
1369
  if (ms.length < 2)
1639
1370
  wrong(label, `${label} needs at least 2 Mobjects`);
1640
- const [first, ...rest] = ms;
1641
- let acc = first ?? wrong(label, "no Mobject");
1642
- for (const m of rest)
1643
- acc = wrap(pathNode(boolean(label, acc, m, op)));
1644
- return styled(acc, style);
1371
+ const shapes = ms.map((m) => m
1372
+ .getFamily()
1373
+ .map((member) => member.getPoints())
1374
+ .filter((points) => points.length > 0));
1375
+ if (shapes.some((members) => members.length === 0))
1376
+ wrong(label, "each Mobject needs a path");
1377
+ const op = { Union: "union", Intersection: "intersection", Difference: "difference", Exclusion: "exclusion" }[label];
1378
+ return styled(wrap(pathNode(engine.pathBoolean(op, shapes))), style);
1645
1379
  }
1646
1380
  /** The area inside any of the mobjects (Manim `Union`): `Union(a, b, opts)`. */
1647
1381
  export function Union(...args) {
1648
1382
  const [ms, style] = split(args);
1649
- return fold("Union", ms, (inA, inB) => inA || inB, style ?? {});
1383
+ return fold("Union", ms, style ?? {});
1650
1384
  }
1651
1385
  /** The area inside all the mobjects (Manim `Intersection`). */
1652
1386
  export function Intersection(...args) {
1653
1387
  const [ms, style] = split(args);
1654
- return fold("Intersection", ms, (inA, inB) => inA && inB, style ?? {});
1388
+ return fold("Intersection", ms, style ?? {});
1655
1389
  }
1656
1390
  /** The area of `subject` outside `clip` (Manim `Difference`). */
1657
1391
  export function Difference(subject, clip, opts = {}) {
1658
- return fold("Difference", [subject, clip], (inA, inB) => inA && !inB, opts);
1392
+ return fold("Difference", [subject, clip], opts);
1659
1393
  }
1660
1394
  /** The area inside one of the two, not both (Manim `Exclusion`). */
1661
1395
  export function Exclusion(subject, clip, opts = {}) {
1662
- return fold("Exclusion", [subject, clip], (inA, inB) => inA !== inB, opts);
1396
+ return fold("Exclusion", [subject, clip], opts);
1663
1397
  }
1664
1398
  /** A curve: Manim's `ParametricFunction`. */
1665
1399
  export class ParametricFunctionMobject extends Mobject {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * as m from "./manim.ts";
2
- export { defineChapter, defineProject, isProjectDefinition, paragraph, say, show, tagText } from "./engine.ts";
3
- export { checkChapter, readChapter, renderChapter, renderScene } from "./run.ts";
4
- export type { Card, ChapterDefinition, ChapterFields, ChapterRun, CheckedChapter, CheckedParagraph, Check, Finding, Heading, Notes, OpenMove, Leaf, SceneRun, Untimed, ProjectDefinition, ProjectFields, Instant, Row, Screen, Shown, } from "./engine.ts";
2
+ export { defineChapter, defineProject, isProjectDefinition, paragraph, pronounce, say, show, tagText, } from "./engine.ts";
3
+ export { checkChapter, checkLexicon, readChapter, renderChapter, renderScene } from "./run.ts";
4
+ export type { Card, ChapterDefinition, ChapterFields, ChapterRun, CheckedChapter, CheckedParagraph, Check, Finding, Heading, Notes, OpenMove, Leaf, Pronounce, Reading, SceneRun, Untimed, ProjectDefinition, ProjectFields, Instant, Row, Screen, Shown, } from "./engine.ts";
5
5
  export type { ChapterResult, Host, ReadOptions, RenderOptions, StackFrame } from "./run.ts";
6
+ export type { Lexicon } from "./lexicon.ts";
package/dist/index.js CHANGED
@@ -7,5 +7,5 @@
7
7
  // readChapter, checkChapter and renderChapter run a chapter, as the CLI and the web app do.
8
8
  // renderScene runs a Manim construct, with no narration.
9
9
  export * as m from "./manim.js";
10
- export { defineChapter, defineProject, isProjectDefinition, paragraph, say, show, tagText } from "./engine.js";
11
- export { checkChapter, readChapter, renderChapter, renderScene } from "./run.js";
10
+ export { defineChapter, defineProject, isProjectDefinition, paragraph, pronounce, say, show, tagText, } from "./engine.js";
11
+ export { checkChapter, checkLexicon, readChapter, renderChapter, renderScene } from "./run.js";
@@ -0,0 +1,10 @@
1
+ import type { Reading } from "./engine.ts";
2
+ import type { LexiconEntry } from "./generated/interfaces/aula-engine-engine.js";
3
+ /** The project lexicon: each key is a written word, and each value is its reading, the same
4
+ * object that `pronounce` takes. A kit exports one, and a project spreads it into its own. */
5
+ export type Lexicon = Readonly<Record<string, Reading>>;
6
+ /** The entries of `lexicon` in the engine's form, in the order of the object. An entry whose
7
+ * reading has the wrong form is left out: `badReadings` gives its key. */
8
+ export declare function lexiconEntries(lexicon: Lexicon): LexiconEntry[];
9
+ /** The keys of `lexicon` whose reading is not `{ say: string }` or `{ phonemes: string }`. */
10
+ export declare function badReadings(lexicon: Lexicon): string[];
@@ -0,0 +1,23 @@
1
+ /** A reading in the engine's form, or undefined when it is not `{ say: string }` or
2
+ * `{ phonemes: string }` (a value from JavaScript with no types). */
3
+ function rawReading(reading) {
4
+ if (typeof reading !== "object" || reading === null || Object.keys(reading).length !== 1)
5
+ return undefined;
6
+ if ("say" in reading && typeof reading.say === "string")
7
+ return { tag: "words", val: reading.say };
8
+ if ("phonemes" in reading && typeof reading.phonemes === "string")
9
+ return { tag: "phonemes", val: reading.phonemes };
10
+ return undefined;
11
+ }
12
+ /** The entries of `lexicon` in the engine's form, in the order of the object. An entry whose
13
+ * reading has the wrong form is left out: `badReadings` gives its key. */
14
+ export function lexiconEntries(lexicon) {
15
+ return Object.entries(lexicon).flatMap(([word, reading]) => {
16
+ const raw = rawReading(reading);
17
+ return raw === undefined ? [] : [{ word, reading: raw }];
18
+ });
19
+ }
20
+ /** The keys of `lexicon` whose reading is not `{ say: string }` or `{ phonemes: string }`. */
21
+ export function badReadings(lexicon) {
22
+ return Object.entries(lexicon).flatMap(([word, reading]) => (rawReading(reading) === undefined ? [word] : []));
23
+ }
@@ -0,0 +1,35 @@
1
+ aula-core uses valo-pathops 0.27.0 (https://crates.io/crates/valo-pathops), MIT AND
2
+ BSD-3-Clause: a line-for-line Rust port of Skia's PathOps, for the boolean operations
3
+ (src/boolean.rs). src/boolean.rs also ports parts of skia-pathops 0.9.2
4
+ (https://github.com/fonttools/skia-pathops, BSD-3-Clause): winding_from_even_odd,
5
+ restore_starting_points and their helpers. Skia's license follows.
6
+
7
+ Copyright (c) 2011 Google Inc. All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are
11
+ met:
12
+
13
+ * Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ * Redistributions in binary form must reproduce the above copyright
17
+ notice, this list of conditions and the following disclaimer in
18
+ the documentation and/or other materials provided with the
19
+ distribution.
20
+
21
+ * Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived
23
+ from this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -28,7 +28,7 @@ export declare class PMobjectMobject extends Mobject {
28
28
  alpha?: number;
29
29
  family?: boolean;
30
30
  }): this;
31
- /** The size of a point, in pixels of a 1080-pixel-high frame. */
31
+ /** The size of a point, in pixels of the 854×480 frame. */
32
32
  getStrokeWidth(): number;
33
33
  /** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
34
34
  * sub-clouds. */
@@ -80,7 +80,7 @@ export declare class PMobjectMobject extends Mobject {
80
80
  }
81
81
  /** The options of a point cloud (Manim's keyword arguments). */
82
82
  export interface PMobjectOptions {
83
- /** The size of a point, in pixels of a 1080-pixel-high frame (default 4). */
83
+ /** The size of a point, in pixels of the 854×480 frame (default 4). */
84
84
  strokeWidth?: number;
85
85
  /** The colour of new points (default white). */
86
86
  color?: ParsableManimColor;
@@ -1,30 +1,14 @@
1
1
  // Manim CE's point clouds: PMobject, Mobject1D, Mobject2D, PGroup, PointCloudDot and Point.
2
- // Each point is a small filled square, `strokeWidth` pixels of the frame wide, as Manim's
3
- // camera draws it. The points of one colour run are the subpaths of one node, so
4
- // a cloud of thousands of points is a few nodes. The points and their colours are read back from
2
+ // Each point is a small filled square, `strokeWidth` pixels of the frame wide. The frame draws
3
+ // it as Manim's camera draws a point: a block of whole pixels (the engine's `point-squares`).
4
+ // The points of one colour run are the subpaths of one node, so a cloud of thousands of
5
+ // points is a few nodes. The points and their colours are read back from
5
6
  // the nodes, so every Mobject method and animation keeps them right.
6
- import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, Polyline, add, mul, norm, raw, sub, wrong, } from "./engine.js";
7
+ import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, add, mul, norm, raw, sub, wrong, wrap, } from "./engine.js";
7
8
  import { colorGradient, colorToRgba, rgbaToColor } from "./colors.js";
8
9
  import { engine } from "./load.js";
9
10
  /** Frame units of one pixel of the frame. */
10
11
  const PIXEL = FRAME_WIDTH / PIXEL_WIDTH;
11
- /** The square subpaths of `points` with side `side`, four lines each. */
12
- function squares(points, side) {
13
- const h = side / 2;
14
- return points.flatMap(([x, y]) => {
15
- const corners = [
16
- [x - h, y - h],
17
- [x + h, y - h],
18
- [x + h, y + h],
19
- [x - h, y + h],
20
- [x - h, y - h],
21
- ];
22
- return corners.slice(0, 4).flatMap((a, i) => {
23
- const b = corners[i + 1] ?? a;
24
- return [a, add(a, mul(sub(b, a), 1 / 3)), add(a, mul(sub(b, a), 2 / 3)), b];
25
- });
26
- });
27
- }
28
12
  /** The points of a node of squares (the centres of its square subpaths), and their side. */
29
13
  function squareCentres(node) {
30
14
  const p = node.getPoints();
@@ -90,7 +74,7 @@ export class PMobjectMobject extends Mobject {
90
74
  const a = rgbas[start] ?? [1, 1, 1, 1];
91
75
  if (i < points.length && sameRgba(a, rgbas[i] ?? a))
92
76
  continue;
93
- const run = Polyline(ORIGIN, ORIGIN).setPoints(squares(points.slice(start, i), side));
77
+ const run = wrap(engine.pointSquares(points.slice(start, i), side));
94
78
  run.setFill(rgbaToColor(a), { opacity: a[3] }).setStroke({ width: 0 });
95
79
  this.add(run);
96
80
  start = i;
@@ -127,7 +111,7 @@ export class PMobjectMobject extends Mobject {
127
111
  }
128
112
  return this;
129
113
  }
130
- /** The size of a point, in pixels of a 1080-pixel-high frame. */
114
+ /** The size of a point, in pixels of the 854×480 frame. */
131
115
  getStrokeWidth() {
132
116
  return this.#strokeWidth;
133
117
  }
package/dist/run.d.ts CHANGED
@@ -59,18 +59,23 @@ export interface ReadOptions {
59
59
  }
60
60
  /** Reads chapter `index` (from 1) of `project`: its text and its text problems, with no move
61
61
  * run. The paragraph checks run only when the chapter is checked (`checkChapter`). */
62
- export declare function readChapter(project: Pick<ProjectDefinition, "title" | "chapters">, index: number, options?: ReadOptions): ChapterResult<ChapterText>;
62
+ export declare function readChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon">, index: number, options?: ReadOptions): ChapterResult<ChapterText>;
63
63
  /** Checks chapter `index` (0 is the title card) of `project`, as `aula check` does: it runs
64
64
  * the moves in list order with no clock and no narration, and gives the text problems, the
65
65
  * engine's checks of the picture after each animation, the kit findings and the paragraph
66
66
  * checks. With sync by construction, no check depends on the length of a `say`. */
67
- export declare function checkChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options?: ReadOptions): ChapterResult<{
67
+ export declare function checkChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon" | "theme" | "card">, index: number, options?: ReadOptions): ChapterResult<{
68
68
  diagnostics: Diagnostic[];
69
69
  }>;
70
+ /** The problems of the project lexicon (`defineProject({ lexicon })`), at the `defineProject`
71
+ * call: a key that is not one word, a reading that is not `{ say: string }` or
72
+ * `{ phonemes: string }`, an empty `say` reading, and a phoneme that is not in Kokoro's token
73
+ * table. `aula check` gives them once for the project. A chapter leaves out an entry with a
74
+ * problem. */
75
+ export declare function checkLexicon(project: Pick<ProjectDefinition, "lexicon" | "call">, options?: ReadOptions): Diagnostic[];
70
76
  /** How aula draws a chapter against a narration. */
71
77
  export interface RenderOptions extends ReadOptions {
72
- /** The narration of this chapter. With fewer cues than the chapter's text (a prefix, as the
73
- * web app narrates a chapter while it plays), the chapter is drawn up to the narrated end. */
78
+ /** The narration of this chapter: a cue for its heading and for each paragraph. */
74
79
  narration: Narration;
75
80
  /** Draw no frames: only the clock (the waits and the narration on the clock of the
76
81
  * picture). */
@@ -79,4 +84,4 @@ export interface RenderOptions extends ReadOptions {
79
84
  /** Draws chapter `index` (0 is the title card) of `project` on its narration: its Lottie, its
80
85
  * length in frames, the waits of the narration and the warnings at the moves that the
81
86
  * narration waits for. */
82
- export declare function renderChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options: RenderOptions): ChapterResult<ChapterRun>;
87
+ export declare function renderChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon" | "theme" | "card">, index: number, options: RenderOptions): ChapterResult<ChapterRun>;