@beff/aula 0.8.1 → 0.9.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/generated/aula.core5.wasm +0 -0
- package/dist/index.d.ts +7304 -6
- package/dist/index.js +14864 -11
- package/dist/index.js.map +1 -0
- package/package.json +8 -25
- package/dist/animations.d.ts +0 -635
- package/dist/animations.js +0 -1778
- package/dist/braces.d.ts +0 -84
- package/dist/braces.js +0 -253
- package/dist/card.d.ts +0 -17
- package/dist/card.js +0 -90
- package/dist/colors-palette.d.ts +0 -2242
- package/dist/colors-palette.js +0 -2241
- package/dist/colors.d.ts +0 -120
- package/dist/colors.js +0 -403
- package/dist/curves.d.ts +0 -10
- package/dist/curves.js +0 -128
- package/dist/engine.d.ts +0 -1705
- package/dist/engine.js +0 -3561
- package/dist/errors.d.ts +0 -19
- package/dist/errors.js +0 -25
- package/dist/geometry.d.ts +0 -551
- package/dist/geometry.js +0 -1555
- package/dist/graph.d.ts +0 -117
- package/dist/graph.js +0 -526
- package/dist/graphing.d.ts +0 -597
- package/dist/graphing.js +0 -1504
- package/dist/host.d.ts +0 -19
- package/dist/host.js +0 -85
- package/dist/lexicon.d.ts +0 -10
- package/dist/lexicon.js +0 -23
- package/dist/load.d.ts +0 -21
- package/dist/load.js +0 -109
- package/dist/logo.d.ts +0 -30
- package/dist/logo.js +0 -186
- package/dist/manim.d.ts +0 -22
- package/dist/manim.js +0 -19
- package/dist/media.d.ts +0 -34
- package/dist/media.js +0 -391
- package/dist/mobjects.d.ts +0 -127
- package/dist/mobjects.js +0 -316
- package/dist/picture.d.ts +0 -23
- package/dist/picture.js +0 -291
- package/dist/pointcloud.d.ts +0 -144
- package/dist/pointcloud.js +0 -384
- package/dist/rates.d.ts +0 -19
- package/dist/rates.js +0 -54
- package/dist/run.d.ts +0 -101
- package/dist/run.js +0 -323
- package/dist/tables.d.ts +0 -179
- package/dist/tables.js +0 -403
- package/dist/tex.d.ts +0 -8
- package/dist/tex.js +0 -257
- package/dist/text-layouts.d.ts +0 -64
- package/dist/text-layouts.js +0 -225
- package/dist/text.d.ts +0 -61
- package/dist/text.js +0 -78
- package/dist/theme.d.ts +0 -25
- package/dist/theme.js +0 -12
- package/dist/user-code.d.ts +0 -5
- package/dist/user-code.js +0 -20
- package/dist/utils.d.ts +0 -152
- package/dist/utils.js +0 -517
- package/dist/vector-field.d.ts +0 -132
- package/dist/vector-field.js +0 -361
package/dist/tables.js
DELETED
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
// Manim CE's tables and matrices: Table, MathTable, MobjectTable, IntegerTable, DecimalTable,
|
|
2
|
-
// Matrix, DecimalMatrix, IntegerMatrix, MobjectMatrix, matrixToTexString, matrixToMobject and
|
|
3
|
-
// getDetText.
|
|
4
|
-
import { BLACK, DR, DecimalNumber, Integer, LEFT, MED_SMALL_BUFF, MathTex, Mobject, ORIGIN, RIGHT, Tex, VGroup, raw, wrong, } from "./engine.js";
|
|
5
|
-
import { AnimationGroup, Create, FadeIn, Write } from "./animations.js";
|
|
6
|
-
import { BackgroundRectangle, Line, Polygon } from "./geometry.js";
|
|
7
|
-
import { engine } from "./load.js";
|
|
8
|
-
import { Paragraph } from "./text-layouts.js";
|
|
9
|
-
/** Manim's `PURE_YELLOW`, the default colour of a highlighted cell. */
|
|
10
|
-
const PURE_YELLOW = "#FFFF00";
|
|
11
|
-
/** Puts `rect` behind the other submobjects of `mob` (Manim `add_to_back`). */
|
|
12
|
-
function addToBack(mob, rect) {
|
|
13
|
-
const children = mob.submobjects;
|
|
14
|
-
mob.remove(...children);
|
|
15
|
-
mob.add(rect, ...children);
|
|
16
|
-
}
|
|
17
|
-
/** Manim's `add_background_rectangle`: a BackgroundRectangle behind `mob`. */
|
|
18
|
-
function addBackground(mob, color) {
|
|
19
|
-
addToBack(mob, BackgroundRectangle(mob, { color }));
|
|
20
|
-
}
|
|
21
|
-
/** `f(m)`, or 0 for a mobject with nothing to measure. */
|
|
22
|
-
const size = (m, f) => (m.hasPoints() || m.length > 0 ? f(m) : 0);
|
|
23
|
-
/** Manim's `arrange_in_grid` with a buff for each direction: each cell is as wide as its column
|
|
24
|
-
* and as high as its row; an entry goes to the `cellAlignment` of its cell. */
|
|
25
|
-
function grid(table, hBuff, vBuff, config) {
|
|
26
|
-
const rows = table.length;
|
|
27
|
-
const cols = table[0]?.length ?? 0;
|
|
28
|
-
const heights = Array.from({ length: rows }, (_, i) => config.rowHeights?.[i] ?? Math.max(0, ...(table[i] ?? []).map((m) => size(m, (x) => x.height))));
|
|
29
|
-
const widths = Array.from({ length: cols }, (_, j) => config.colWidths?.[j] ?? Math.max(0, ...table.map((r) => (r[j] === undefined ? 0 : size(r[j], (x) => x.width)))));
|
|
30
|
-
const rowLetter = { u: 1, c: 0, d: -1 };
|
|
31
|
-
const colLetter = { l: -1, c: 0, r: 1 };
|
|
32
|
-
const cell = config.cellAlignment ?? ORIGIN;
|
|
33
|
-
let y = 0;
|
|
34
|
-
table.forEach((row, i) => {
|
|
35
|
-
const h = heights[i] ?? 0;
|
|
36
|
-
let x = 0;
|
|
37
|
-
row.forEach((mob, j) => {
|
|
38
|
-
const w = widths[j] ?? 0;
|
|
39
|
-
const ax = colLetter[config.colAlignments?.[j] ?? ""] ?? cell[0];
|
|
40
|
-
const ay = rowLetter[config.rowAlignments?.[i] ?? ""] ?? cell[1];
|
|
41
|
-
const anchor = [x + w / 2 + (ax * w) / 2, y - h / 2 + (ay * h) / 2];
|
|
42
|
-
if (mob.hasPoints() || mob.length > 0)
|
|
43
|
-
mob.moveTo(anchor, { alignedEdge: [ax, ay] });
|
|
44
|
-
x += w + hBuff;
|
|
45
|
-
});
|
|
46
|
-
y -= h + vBuff;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/** A table: Manim's `Table`. Rows and columns count from 1, labels included. */
|
|
50
|
-
export class TableMobject extends Mobject {
|
|
51
|
-
hBuff;
|
|
52
|
-
vBuff;
|
|
53
|
-
#p;
|
|
54
|
-
constructor(handle, parts, hBuff, vBuff) {
|
|
55
|
-
super(handle);
|
|
56
|
-
this.#p = parts;
|
|
57
|
-
this.hBuff = hBuff;
|
|
58
|
-
this.vBuff = vBuff;
|
|
59
|
-
}
|
|
60
|
-
/** The entries, labels included (Manim `elements`). */
|
|
61
|
-
get elements() {
|
|
62
|
-
return this.#p.elements;
|
|
63
|
-
}
|
|
64
|
-
/** The grid of entries, labels included (Manim `mob_table`). */
|
|
65
|
-
get mobTable() {
|
|
66
|
-
return this.#p.mobTable;
|
|
67
|
-
}
|
|
68
|
-
getHorizontalLines() {
|
|
69
|
-
return this.#p.horizontalLines;
|
|
70
|
-
}
|
|
71
|
-
getVerticalLines() {
|
|
72
|
-
return this.#p.verticalLines;
|
|
73
|
-
}
|
|
74
|
-
/** One VGroup for each column. */
|
|
75
|
-
getColumns() {
|
|
76
|
-
const t = this.#p.mobTable;
|
|
77
|
-
return VGroup((t[0] ?? []).map((_, j) => VGroup(t.flatMap((row) => row[j] ?? []))));
|
|
78
|
-
}
|
|
79
|
-
/** One VGroup for each row. */
|
|
80
|
-
getRows() {
|
|
81
|
-
return VGroup(this.#p.mobTable.map((row) => VGroup(row)));
|
|
82
|
-
}
|
|
83
|
-
setColumnColors(...colors) {
|
|
84
|
-
this.getColumns().submobjects.forEach((c, i) => colors[i] !== undefined && c.setColor(colors[i]));
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
setRowColors(...colors) {
|
|
88
|
-
this.getRows().submobjects.forEach((r, i) => colors[i] !== undefined && r.setColor(colors[i]));
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
/** All the entries with the labels, or the entry at `pos` (`[row, column]`, from 1). */
|
|
92
|
-
getEntries(pos) {
|
|
93
|
-
if (pos === undefined)
|
|
94
|
-
return this.#p.elements;
|
|
95
|
-
const width = this.#p.mobTable[0]?.length ?? 0;
|
|
96
|
-
const noCorner = this.#p.rowLabels !== undefined && this.#p.colLabels !== undefined && this.#p.topLeftEntry === undefined;
|
|
97
|
-
const index = width * (pos[0] - 1) + pos[1] - (noCorner ? 2 : 1);
|
|
98
|
-
return this.#p.elements.submobjects[index] ?? wrong("getEntries", `the table has no entry at [${pos.join(", ")}]`);
|
|
99
|
-
}
|
|
100
|
-
/** The entries without the labels, or the one at `pos` (`[row, column]`, from 1). */
|
|
101
|
-
getEntriesWithoutLabels(pos) {
|
|
102
|
-
if (pos === undefined)
|
|
103
|
-
return this.#p.elementsWithoutLabels;
|
|
104
|
-
const index = this.#p.colDim * (pos[0] - 1) + pos[1] - 1;
|
|
105
|
-
const entry = this.#p.elementsWithoutLabels.submobjects[index];
|
|
106
|
-
return entry ?? wrong("getEntriesWithoutLabels", `the table has no entry at [${pos.join(", ")}]`);
|
|
107
|
-
}
|
|
108
|
-
getRowLabels() {
|
|
109
|
-
return VGroup(this.#p.rowLabels ?? []);
|
|
110
|
-
}
|
|
111
|
-
getColLabels() {
|
|
112
|
-
return VGroup(this.#p.colLabels ?? []);
|
|
113
|
-
}
|
|
114
|
-
/** The top-left entry, the column labels and the row labels. */
|
|
115
|
-
getLabels() {
|
|
116
|
-
const { topLeftEntry, colLabels = [], rowLabels = [] } = this.#p;
|
|
117
|
-
return VGroup(topLeftEntry ?? [], colLabels, rowLabels);
|
|
118
|
-
}
|
|
119
|
-
/** A BackgroundRectangle behind each entry. */
|
|
120
|
-
addBackgroundToEntries(color = BLACK) {
|
|
121
|
-
for (const mob of this.getEntries())
|
|
122
|
-
addBackground(mob, color);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
/** The rectangle of the cell at `pos` (`[row, column]`, from 1), with half the buffs around the
|
|
126
|
-
* entries, as a Polygon with the style options. */
|
|
127
|
-
getCell(pos = [1, 1], opts = {}) {
|
|
128
|
-
const row = this.getRows().submobjects[pos[0] - 1];
|
|
129
|
-
const col = this.getColumns().submobjects[pos[1] - 1];
|
|
130
|
-
if (row === undefined || col === undefined)
|
|
131
|
-
return wrong("getCell", `the table has no cell at [${pos.join(", ")}]`);
|
|
132
|
-
const [l, r] = [col.left() - this.hBuff / 2, col.right() + this.hBuff / 2];
|
|
133
|
-
const [t, b] = [row.top() + this.vBuff / 2, row.bottom() - this.vBuff / 2];
|
|
134
|
-
return Polygon([l, t], [r, t], [r, b], [l, b], opts);
|
|
135
|
-
}
|
|
136
|
-
/** A BackgroundRectangle on the cell at `pos`, in `color` (Manim's `PURE_YELLOW`). */
|
|
137
|
-
getHighlightedCell(pos = [1, 1], color = PURE_YELLOW, opts = {}) {
|
|
138
|
-
return BackgroundRectangle(this.getCell(pos), { color, ...opts });
|
|
139
|
-
}
|
|
140
|
-
/** Puts `getHighlightedCell(pos, color)` behind the table. */
|
|
141
|
-
addHighlightedCell(pos = [1, 1], color = PURE_YELLOW, opts = {}) {
|
|
142
|
-
const cell = this.getHighlightedCell(pos, color, opts);
|
|
143
|
-
addToBack(this, cell);
|
|
144
|
-
this.#p.backgrounds.set(this.getEntries(pos), cell);
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
/** Draws the lines, then the entries, the labels and the highlighted cells, one after the
|
|
148
|
-
* other by `lagRatio` (Manim `Table.create`). */
|
|
149
|
-
create(opts = {}) {
|
|
150
|
-
const { lagRatio = 1, lineAnimation = (m) => Create(m), labelAnimation = (m) => Write(m), elementAnimation = (m) => Create(m), entryAnimation = (m) => FadeIn(m), } = opts;
|
|
151
|
-
const animations = [
|
|
152
|
-
lineAnimation(VGroup(this.#p.verticalLines, this.#p.horizontalLines)),
|
|
153
|
-
elementAnimation(this.#p.elementsWithoutLabels),
|
|
154
|
-
];
|
|
155
|
-
const labels = this.getLabels();
|
|
156
|
-
if (labels.length > 0)
|
|
157
|
-
animations.push(labelAnimation(labels));
|
|
158
|
-
for (const entry of this.#p.elementsWithoutLabels) {
|
|
159
|
-
const bg = this.#p.backgrounds.get(entry);
|
|
160
|
-
if (bg !== undefined)
|
|
161
|
-
animations.push(entryAnimation(bg));
|
|
162
|
-
}
|
|
163
|
-
return AnimationGroup(...animations, { lagRatio });
|
|
164
|
-
}
|
|
165
|
-
/** Scales the table and its buffs. With `scaleStroke`, the stroke widths scale too. */
|
|
166
|
-
scale(scaleFactor, opts = {}) {
|
|
167
|
-
const { scaleStroke = false, ...rest } = opts;
|
|
168
|
-
this.hBuff *= scaleFactor;
|
|
169
|
-
this.vBuff *= scaleFactor;
|
|
170
|
-
super.scale(scaleFactor, rest);
|
|
171
|
-
if (scaleStroke)
|
|
172
|
-
for (const m of this.getFamily())
|
|
173
|
-
m.setStroke({ width: m.getStrokeWidth() * scaleFactor });
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
copy() {
|
|
177
|
-
return new TableMobject(raw(this).copy(), this.#p, this.hBuff, this.vBuff);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function entryText(make) {
|
|
181
|
-
return (i, c) => (i instanceof Mobject ? i : make(String(i), c));
|
|
182
|
-
}
|
|
183
|
-
/** Manim's `Table(table, opts)`: each entry becomes `elementToMobject(entry, elementToMobjectConfig)`
|
|
184
|
-
* (a `Paragraph` by default), in a grid with lines between the rows and the columns. */
|
|
185
|
-
export function Table(table, opts = {}) {
|
|
186
|
-
const { rowLabels, colLabels, topLeftEntry, vBuff = 0.8, hBuff = 1.3, includeOuterLines = false, includeInnerLines = true, addBackgroundRectanglesToEntries = false, entriesBackgroundColor = BLACK, includeBackgroundRectangle = false, backgroundRectangleColor = BLACK, elementToMobject = entryText((s, c) => Paragraph(s, c)), elementToMobjectConfig = {}, arrangeInGridConfig = {}, lineConfig = {}, } = opts;
|
|
187
|
-
const colDim = table[0]?.length ?? 0;
|
|
188
|
-
if (table.some((row) => row.length !== colDim))
|
|
189
|
-
wrong("Table", "not all rows of the table have the same length");
|
|
190
|
-
const mobTable = table.map((row) => row.map((item) => elementToMobject(item, elementToMobjectConfig)));
|
|
191
|
-
const elementsWithoutLabels = VGroup(mobTable.flat());
|
|
192
|
-
const rows = rowLabels === undefined || rowLabels.length === 0 ? undefined : rowLabels;
|
|
193
|
-
const cols = colLabels === undefined || colLabels.length === 0 ? undefined : colLabels;
|
|
194
|
-
if (rows !== undefined)
|
|
195
|
-
rows.forEach((label, k) => mobTable[k]?.unshift(label));
|
|
196
|
-
if (cols !== undefined)
|
|
197
|
-
mobTable.unshift(rows === undefined ? [...cols] : [topLeftEntry ?? VGroup(), ...cols]);
|
|
198
|
-
grid(mobTable, hBuff, vBuff, arrangeInGridConfig);
|
|
199
|
-
const all = mobTable.flat();
|
|
200
|
-
const elements = VGroup(all[0] !== undefined && !all[0].hasPoints() && all[0].length === 0 ? all.slice(1) : all);
|
|
201
|
-
const node = VGroup(elements);
|
|
202
|
-
node.center();
|
|
203
|
-
const rowsOf = () => mobTable.map((row) => VGroup(row));
|
|
204
|
-
const colsOf = () => (mobTable[0] ?? []).map((_, j) => VGroup(mobTable.flatMap((r) => r[j] ?? [])));
|
|
205
|
-
const [left, right] = [node.left() - hBuff / 2, node.right() + hBuff / 2];
|
|
206
|
-
const horizontal = [];
|
|
207
|
-
const rowGroups = rowsOf();
|
|
208
|
-
const hLine = (y) => Line([left, y], [right, y], lineConfig);
|
|
209
|
-
if (includeOuterLines) {
|
|
210
|
-
const [first, last] = [rowGroups[0], rowGroups.at(-1)];
|
|
211
|
-
if (first !== undefined && last !== undefined) {
|
|
212
|
-
horizontal.push(hLine(first.top() + vBuff / 2), hLine(last.bottom() - vBuff / 2));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (includeInnerLines) {
|
|
216
|
-
for (let k = 0; k + 1 < rowGroups.length; k++) {
|
|
217
|
-
const [a, b] = [rowGroups[k], rowGroups[k + 1]];
|
|
218
|
-
if (a !== undefined && b !== undefined)
|
|
219
|
-
horizontal.push(hLine(b.top() + (a.bottom() - b.top()) / 2));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const [top, bottom] = [node.top() + vBuff / 2, node.bottom() - vBuff / 2];
|
|
223
|
-
const vertical = [];
|
|
224
|
-
const colGroups = colsOf();
|
|
225
|
-
if (includeOuterLines) {
|
|
226
|
-
const [first, last] = [colGroups[0], colGroups.at(-1)];
|
|
227
|
-
if (first !== undefined && last !== undefined) {
|
|
228
|
-
const x0 = first.left() - hBuff / 2;
|
|
229
|
-
const x1 = last.right() + hBuff / 2;
|
|
230
|
-
vertical.push(Line([x0, top], [x0, bottom], lineConfig), Line([x1, top], [x1, bottom], lineConfig));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (includeInnerLines) {
|
|
234
|
-
for (let k = 0; k + 1 < colGroups.length; k++) {
|
|
235
|
-
const [a, b] = [colGroups[k], colGroups[k + 1]];
|
|
236
|
-
if (a !== undefined && b !== undefined) {
|
|
237
|
-
const x = b.left() + (a.right() - b.left()) / 2;
|
|
238
|
-
vertical.push(Line([x, bottom], [x, top], lineConfig));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const parts = {
|
|
243
|
-
mobTable,
|
|
244
|
-
elements,
|
|
245
|
-
elementsWithoutLabels,
|
|
246
|
-
rowLabels: rows,
|
|
247
|
-
colLabels: cols,
|
|
248
|
-
topLeftEntry,
|
|
249
|
-
colDim,
|
|
250
|
-
horizontalLines: VGroup(horizontal),
|
|
251
|
-
verticalLines: VGroup(vertical),
|
|
252
|
-
backgrounds: new Map(),
|
|
253
|
-
};
|
|
254
|
-
const t = new TableMobject(engine.vGroup([raw(elements), ...[...horizontal, ...vertical].map(raw)]), parts, hBuff, vBuff);
|
|
255
|
-
if (addBackgroundRectanglesToEntries)
|
|
256
|
-
t.addBackgroundToEntries(entriesBackgroundColor);
|
|
257
|
-
if (includeBackgroundRectangle)
|
|
258
|
-
addBackground(t, backgroundRectangleColor);
|
|
259
|
-
return t;
|
|
260
|
-
}
|
|
261
|
-
/** A Table of `MathTex` entries (Manim `MathTable`). */
|
|
262
|
-
export function MathTable(table, opts = {}) {
|
|
263
|
-
return Table(table, { elementToMobject: entryText((s, c) => MathTex(s, c)), ...opts });
|
|
264
|
-
}
|
|
265
|
-
/** A Table of mobjects as they are (Manim `MobjectTable`). */
|
|
266
|
-
export function MobjectTable(table, opts = {}) {
|
|
267
|
-
return Table(table, { elementToMobject: entryText((s) => Tex(s)), ...opts });
|
|
268
|
-
}
|
|
269
|
-
/** A Table of `Integer` entries (Manim `IntegerTable`). */
|
|
270
|
-
export function IntegerTable(table, opts = {}) {
|
|
271
|
-
return Table(table, { elementToMobject: numberEntry(Integer), ...opts });
|
|
272
|
-
}
|
|
273
|
-
/** A Table of `DecimalNumber` entries with one decimal place (Manim `DecimalTable`). */
|
|
274
|
-
export function DecimalTable(table, opts = {}) {
|
|
275
|
-
return Table(table, {
|
|
276
|
-
elementToMobject: numberEntry(DecimalNumber),
|
|
277
|
-
elementToMobjectConfig: { numDecimalPlaces: 1 },
|
|
278
|
-
...opts,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
function numberEntry(make) {
|
|
282
|
-
return (item, config) => (item instanceof Mobject ? item : make(Number(item), config));
|
|
283
|
-
}
|
|
284
|
-
/** A matrix: Manim's `Matrix`. Its submobjects are the entries (one VGroup) and the brackets. */
|
|
285
|
-
export class MatrixMobject extends Mobject {
|
|
286
|
-
#mobMatrix;
|
|
287
|
-
#elements;
|
|
288
|
-
#brackets;
|
|
289
|
-
constructor(handle, mobMatrix, elements, brackets) {
|
|
290
|
-
super(handle);
|
|
291
|
-
this.#mobMatrix = mobMatrix;
|
|
292
|
-
this.#elements = elements;
|
|
293
|
-
this.#brackets = brackets;
|
|
294
|
-
}
|
|
295
|
-
getColumns() {
|
|
296
|
-
const t = this.#mobMatrix;
|
|
297
|
-
return VGroup((t[0] ?? []).map((_, j) => VGroup(t.flatMap((row) => row[j] ?? []))));
|
|
298
|
-
}
|
|
299
|
-
getRows() {
|
|
300
|
-
return VGroup(this.#mobMatrix.map((row) => VGroup(row)));
|
|
301
|
-
}
|
|
302
|
-
setColumnColors(...colors) {
|
|
303
|
-
this.getColumns().submobjects.forEach((c, i) => colors[i] !== undefined && c.setColor(colors[i]));
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
setRowColors(...colors) {
|
|
307
|
-
this.getRows().submobjects.forEach((r, i) => colors[i] !== undefined && r.setColor(colors[i]));
|
|
308
|
-
return this;
|
|
309
|
-
}
|
|
310
|
-
/** A BackgroundRectangle behind each entry. */
|
|
311
|
-
addBackgroundToEntries() {
|
|
312
|
-
for (const mob of this.#elements)
|
|
313
|
-
addBackground(mob, BLACK);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
/** The entries as rows of mobjects (Manim `mob_matrix`). */
|
|
317
|
-
getMobMatrix() {
|
|
318
|
-
return this.#mobMatrix;
|
|
319
|
-
}
|
|
320
|
-
getEntries() {
|
|
321
|
-
return this.#elements;
|
|
322
|
-
}
|
|
323
|
-
/** The left and the right bracket. */
|
|
324
|
-
getBrackets() {
|
|
325
|
-
return this.#brackets;
|
|
326
|
-
}
|
|
327
|
-
copy() {
|
|
328
|
-
return new MatrixMobject(raw(this).copy(), this.#mobMatrix, this.#elements, this.#brackets);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/** Manim's `Matrix(matrix, opts)`: each entry is `elementToMobject(entry, elementToMobjectConfig)`
|
|
332
|
-
* (a `MathTex` by default), between brackets that `\\left` and `\\right` draw. */
|
|
333
|
-
export function Matrix(matrix, opts = {}) {
|
|
334
|
-
const { vBuff = 0.8, hBuff = 1.3, bracketHBuff = MED_SMALL_BUFF, bracketVBuff = MED_SMALL_BUFF, addBackgroundRectanglesToEntries = false, includeBackgroundRectangle = false, elementToMobject = entryText((s, c) => MathTex(s, c)), elementToMobjectConfig = {}, elementAlignmentCorner = DR, leftBracket = "[", rightBracket = "]", stretchBrackets = true, bracketConfig = {}, } = opts;
|
|
335
|
-
const mobMatrix = matrix.map((row, i) => row.map((item, j) => elementToMobject(item, elementToMobjectConfig).moveTo([j * hBuff, -i * vBuff], {
|
|
336
|
-
alignedEdge: elementAlignmentCorner,
|
|
337
|
-
})));
|
|
338
|
-
const elements = VGroup(mobMatrix.flat());
|
|
339
|
-
const height = elements.height;
|
|
340
|
-
const n = Math.floor(height / 0.5977) + 1;
|
|
341
|
-
const empty = `\\begin{array}{c}${"\\quad \\\\".repeat(n)}\\end{array}`;
|
|
342
|
-
const left = MathTex(`\\left${leftBracket}${empty}\\right.`, bracketConfig);
|
|
343
|
-
const right = MathTex(`\\left.${empty}\\right${rightBracket}`, bracketConfig);
|
|
344
|
-
const brackets = VGroup(left, right);
|
|
345
|
-
if (stretchBrackets)
|
|
346
|
-
brackets.stretchToFitHeight(height + 2 * bracketVBuff);
|
|
347
|
-
left.nextTo(elements, LEFT, { buff: bracketHBuff });
|
|
348
|
-
right.nextTo(elements, RIGHT, { buff: bracketHBuff });
|
|
349
|
-
const m = new MatrixMobject(engine.vGroup([raw(elements), raw(left), raw(right)]), mobMatrix, elements, brackets);
|
|
350
|
-
m.center();
|
|
351
|
-
if (addBackgroundRectanglesToEntries)
|
|
352
|
-
m.addBackgroundToEntries();
|
|
353
|
-
if (includeBackgroundRectangle)
|
|
354
|
-
addBackground(m, BLACK);
|
|
355
|
-
return m;
|
|
356
|
-
}
|
|
357
|
-
/** A Matrix of `DecimalNumber` entries with one decimal place (Manim `DecimalMatrix`). */
|
|
358
|
-
export function DecimalMatrix(matrix, opts = {}) {
|
|
359
|
-
return Matrix(matrix, {
|
|
360
|
-
elementToMobject: numberEntry(DecimalNumber),
|
|
361
|
-
elementToMobjectConfig: { numDecimalPlaces: 1 },
|
|
362
|
-
...opts,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
/** A Matrix of `Integer` entries (Manim `IntegerMatrix`). */
|
|
366
|
-
export function IntegerMatrix(matrix, opts = {}) {
|
|
367
|
-
return Matrix(matrix, { elementToMobject: numberEntry(Integer), ...opts });
|
|
368
|
-
}
|
|
369
|
-
/** A Matrix of mobjects as they are (Manim `MobjectMatrix`). */
|
|
370
|
-
export function MobjectMatrix(matrix, opts = {}) {
|
|
371
|
-
return Matrix(matrix, { elementToMobject: entryText((s) => Tex(s)), ...opts });
|
|
372
|
-
}
|
|
373
|
-
/** The LaTeX of a matrix (a list is one column) in brackets (Manim `matrix_to_tex_string`). */
|
|
374
|
-
export function matrixToTexString(matrix) {
|
|
375
|
-
const rows = matrix.map((row) => (Array.isArray(row) ? row : [row]));
|
|
376
|
-
const cols = rows[0]?.length ?? 0;
|
|
377
|
-
const body = rows.map((row) => row.map(String).join(" & ")).join(" \\\\ ");
|
|
378
|
-
return `\\left[ \\begin{array}{${"c".repeat(cols)}}${body}\\end{array} \\right]`;
|
|
379
|
-
}
|
|
380
|
-
/** `MathTex(matrixToTexString(matrix))` (Manim `matrix_to_mobject`). */
|
|
381
|
-
export function matrixToMobject(matrix) {
|
|
382
|
-
return MathTex(matrixToTexString(matrix));
|
|
383
|
-
}
|
|
384
|
-
/** `det(…)` around a Matrix, and `= determinant` with a determinant (Manim `get_det_text`). */
|
|
385
|
-
export function getDetText(matrix, opts = {}) {
|
|
386
|
-
const { determinant, backgroundRect = false, initialScaleFactor = 2 } = opts;
|
|
387
|
-
const parens = MathTex("(", ")").scale(initialScaleFactor);
|
|
388
|
-
parens.stretchToFitHeight(matrix.height);
|
|
389
|
-
const [l, r] = parens.submobjects;
|
|
390
|
-
if (l === undefined || r === undefined)
|
|
391
|
-
return wrong("getDetText", "the parentheses have no parts");
|
|
392
|
-
l.nextTo(matrix, LEFT, { buff: 0.1 });
|
|
393
|
-
r.nextTo(matrix, RIGHT, { buff: 0.1 });
|
|
394
|
-
const det = Tex("det").scale(initialScaleFactor).nextTo(l, LEFT, { buff: 0.1 });
|
|
395
|
-
if (backgroundRect)
|
|
396
|
-
addBackground(det, BLACK);
|
|
397
|
-
const text = VGroup(det, l, r);
|
|
398
|
-
if (determinant !== undefined) {
|
|
399
|
-
const eq = MathTex("=").nextTo(r, RIGHT, { buff: 0.1 });
|
|
400
|
-
text.add(eq, MathTex(String(determinant)).nextTo(eq, RIGHT, { buff: 0.2 }));
|
|
401
|
-
}
|
|
402
|
-
return text;
|
|
403
|
-
}
|
package/dist/tex.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Glyph } from "./generated/interfaces/aula-engine-engine.js";
|
|
2
|
-
export type { Glyph };
|
|
3
|
-
/** The function that draws formulas: its name starts each error. */
|
|
4
|
-
export type Formula = "MathTex" | "Tex";
|
|
5
|
-
/** The glyphs of each part of a formula of `name`, at `fontSize`, centred later by the engine.
|
|
6
|
-
* Tex reads the parts as text-mode LaTeX, MathTex as math. A formula that does not parse throws
|
|
7
|
-
* a AulaError that names the part. */
|
|
8
|
-
export declare function texGlyphs(name: Formula, parts: readonly string[], separator: string, fontSize: number): Glyph[][];
|
package/dist/tex.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// LaTeX to glyph paths for m.MathTex and m.Tex: MathJax (TeX input, SVG output, the lite DOM)
|
|
2
|
-
// runs in Node and in the browser with no TeX installation. Each part is wrapped in
|
|
3
|
-
// `\class{aula-<i>}{…}`, so each glyph path of the SVG knows its part. The engine (`engine.tex`)
|
|
4
|
-
// reads the path data; this file only walks the SVG tree and composes the transforms.
|
|
5
|
-
import { LiteElement } from "mathjax-full/js/adaptors/lite/Element.js";
|
|
6
|
-
import { liteAdaptor } from "mathjax-full/js/adaptors/liteAdaptor.js";
|
|
7
|
-
import { RegisterHTMLHandler } from "mathjax-full/js/handlers/html.js";
|
|
8
|
-
import { TeX } from "mathjax-full/js/input/tex.js";
|
|
9
|
-
import { mathjax } from "mathjax-full/js/mathjax.js";
|
|
10
|
-
import { SVG } from "mathjax-full/js/output/svg.js";
|
|
11
|
-
import { fault } from "./errors.js";
|
|
12
|
-
import { BaseConfiguration } from "mathjax-full/js/input/tex/base/BaseConfiguration.js";
|
|
13
|
-
import { AmsConfiguration } from "mathjax-full/js/input/tex/ams/AmsConfiguration.js";
|
|
14
|
-
import { BoldsymbolConfiguration } from "mathjax-full/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
|
|
15
|
-
import { BraketConfiguration } from "mathjax-full/js/input/tex/braket/BraketConfiguration.js";
|
|
16
|
-
import { CancelConfiguration } from "mathjax-full/js/input/tex/cancel/CancelConfiguration.js";
|
|
17
|
-
import { CasesConfiguration } from "mathjax-full/js/input/tex/cases/CasesConfiguration.js";
|
|
18
|
-
import { CenternotConfiguration } from "mathjax-full/js/input/tex/centernot/CenternotConfiguration.js";
|
|
19
|
-
import { ExtpfeilConfiguration } from "mathjax-full/js/input/tex/extpfeil/ExtpfeilConfiguration.js";
|
|
20
|
-
import { GensymbConfiguration } from "mathjax-full/js/input/tex/gensymb/GensymbConfiguration.js";
|
|
21
|
-
import { HtmlConfiguration } from "mathjax-full/js/input/tex/html/HtmlConfiguration.js";
|
|
22
|
-
import { MathtoolsConfiguration } from "mathjax-full/js/input/tex/mathtools/MathtoolsConfiguration.js";
|
|
23
|
-
import { MhchemConfiguration } from "mathjax-full/js/input/tex/mhchem/MhchemConfiguration.js";
|
|
24
|
-
import { NewcommandConfiguration } from "mathjax-full/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
25
|
-
import { PhysicsConfiguration } from "mathjax-full/js/input/tex/physics/PhysicsConfiguration.js";
|
|
26
|
-
import { TextMacrosConfiguration } from "mathjax-full/js/input/tex/textmacros/TextMacrosConfiguration.js";
|
|
27
|
-
import { UpgreekConfiguration } from "mathjax-full/js/input/tex/upgreek/UpgreekConfiguration.js";
|
|
28
|
-
/** The TeX packages that MathTex and Tex know (docs/agents/api.md lists them). */
|
|
29
|
-
const PACKAGES = [
|
|
30
|
-
BaseConfiguration,
|
|
31
|
-
AmsConfiguration,
|
|
32
|
-
BoldsymbolConfiguration,
|
|
33
|
-
BraketConfiguration,
|
|
34
|
-
CancelConfiguration,
|
|
35
|
-
CasesConfiguration,
|
|
36
|
-
CenternotConfiguration,
|
|
37
|
-
ExtpfeilConfiguration,
|
|
38
|
-
GensymbConfiguration,
|
|
39
|
-
HtmlConfiguration,
|
|
40
|
-
MathtoolsConfiguration,
|
|
41
|
-
MhchemConfiguration,
|
|
42
|
-
NewcommandConfiguration,
|
|
43
|
-
PhysicsConfiguration,
|
|
44
|
-
TextMacrosConfiguration,
|
|
45
|
-
UpgreekConfiguration,
|
|
46
|
-
].map((c) => c.name);
|
|
47
|
-
/** Throws the error of a formula that aula cannot draw, with the fix. */
|
|
48
|
-
function fail(name, message) {
|
|
49
|
-
return fault(`${name}: ${message}`, "each argument and each {{ }} group must be LaTeX that parses alone (MathJax with the TeX packages of docs/agents/api.md); colour parts with setColorByTex");
|
|
50
|
-
}
|
|
51
|
-
/** Manim: at font size 48 one em (10 TeX points) is half a unit. MathJax uses 1000 units per em. */
|
|
52
|
-
const UNITS_PER_EM_PER_SIZE = 1 / 96;
|
|
53
|
-
let converter;
|
|
54
|
-
/** The message of the first `merror` node under `node`: MathJax draws LaTeX that does not parse
|
|
55
|
-
* as an `merror` node with the message in `data-mjx-error`. */
|
|
56
|
-
function errorOf(node) {
|
|
57
|
-
if (!(node instanceof LiteElement))
|
|
58
|
-
return undefined;
|
|
59
|
-
const message = attribute(node, "data-mjx-error");
|
|
60
|
-
if (message !== undefined)
|
|
61
|
-
return message;
|
|
62
|
-
for (const child of node.children) {
|
|
63
|
-
const found = errorOf(child);
|
|
64
|
-
if (found !== undefined)
|
|
65
|
-
return found;
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
/** The root of the SVG of `latex`, or the message of MathJax when it does not parse. */
|
|
70
|
-
function parse(latex) {
|
|
71
|
-
if (converter === undefined) {
|
|
72
|
-
const adaptor = liteAdaptor();
|
|
73
|
-
RegisterHTMLHandler(adaptor);
|
|
74
|
-
const tex = new TeX({ packages: [...PACKAGES] });
|
|
75
|
-
const document = mathjax.document("", { InputJax: tex, OutputJax: new SVG({ fontCache: "none" }) });
|
|
76
|
-
converter = (s) => document.convert(s, { display: true });
|
|
77
|
-
}
|
|
78
|
-
const node = converter(latex);
|
|
79
|
-
if (!(node instanceof LiteElement))
|
|
80
|
-
return { _tag: "Left", left: "MathJax returned no SVG" };
|
|
81
|
-
const message = errorOf(node);
|
|
82
|
-
return message === undefined ? { _tag: "Right", right: node } : { _tag: "Left", left: message };
|
|
83
|
-
}
|
|
84
|
-
function compose(a, b) {
|
|
85
|
-
return [
|
|
86
|
-
a[0] * b[0] + a[2] * b[1],
|
|
87
|
-
a[1] * b[0] + a[3] * b[1],
|
|
88
|
-
a[0] * b[2] + a[2] * b[3],
|
|
89
|
-
a[1] * b[2] + a[3] * b[3],
|
|
90
|
-
a[0] * b[4] + a[2] * b[5] + a[4],
|
|
91
|
-
a[1] * b[4] + a[3] * b[5] + a[5],
|
|
92
|
-
];
|
|
93
|
-
}
|
|
94
|
-
function numbers(s) {
|
|
95
|
-
return s
|
|
96
|
-
.trim()
|
|
97
|
-
.split(/[\s,]+/)
|
|
98
|
-
.filter((x) => x !== "")
|
|
99
|
-
.map(Number);
|
|
100
|
-
}
|
|
101
|
-
/** The SVG `transform` attribute as one map (MathJax writes translate, scale and matrix). */
|
|
102
|
-
function transformOf(formula, text) {
|
|
103
|
-
let m = [1, 0, 0, 1, 0, 0];
|
|
104
|
-
for (const [, name, args] of text.matchAll(/(\w+)\s*\(([^)]*)\)/g)) {
|
|
105
|
-
const n = numbers(args ?? "");
|
|
106
|
-
const [x = 0, y] = n;
|
|
107
|
-
let step;
|
|
108
|
-
if (name === "translate")
|
|
109
|
-
step = [1, 0, 0, 1, x, y ?? 0];
|
|
110
|
-
else if (name === "scale")
|
|
111
|
-
step = [x, 0, 0, y ?? x, 0, 0];
|
|
112
|
-
else if (name === "matrix" && n.length === 6)
|
|
113
|
-
step = [x, n[1] ?? 0, n[2] ?? 0, n[3] ?? 0, n[4] ?? 0, n[5] ?? 0];
|
|
114
|
-
else if (name === "rotate") {
|
|
115
|
-
const a = (x * Math.PI) / 180;
|
|
116
|
-
step = [Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0];
|
|
117
|
-
}
|
|
118
|
-
else
|
|
119
|
-
fail(formula, `MathJax wrote a transform that aula cannot read: ${text}`);
|
|
120
|
-
m = compose(m, step);
|
|
121
|
-
}
|
|
122
|
-
return m;
|
|
123
|
-
}
|
|
124
|
-
function attribute(e, name) {
|
|
125
|
-
const v = e.attributes[name];
|
|
126
|
-
return typeof v === "string" ? v : typeof v === "number" ? String(v) : undefined;
|
|
127
|
-
}
|
|
128
|
-
function number(e, name) {
|
|
129
|
-
const v = Number(attribute(e, name) ?? 0);
|
|
130
|
-
return Number.isFinite(v) ? v : 0;
|
|
131
|
-
}
|
|
132
|
-
function rect(x, y, w, h) {
|
|
133
|
-
return `M${String(x)} ${String(y)}H${String(x + w)}V${String(y + h)}H${String(x)}Z`;
|
|
134
|
-
}
|
|
135
|
-
/** The glyphs of each part, in the order of the parts. */
|
|
136
|
-
function collect(name, root, count, m) {
|
|
137
|
-
const parts = Array.from({ length: count }, () => []);
|
|
138
|
-
let last = 0;
|
|
139
|
-
const glyph = (part, d, at) => {
|
|
140
|
-
const i = part ?? last;
|
|
141
|
-
last = i;
|
|
142
|
-
parts[i]?.push({ d, transform: at });
|
|
143
|
-
};
|
|
144
|
-
const walk = (node, outer, part, nested) => {
|
|
145
|
-
if (!(node instanceof LiteElement))
|
|
146
|
-
return;
|
|
147
|
-
const own = /\baula-(\d+)\b/.exec(attribute(node, "class") ?? "");
|
|
148
|
-
const p = own === null ? part : Number(own[1]);
|
|
149
|
-
const t = attribute(node, "transform");
|
|
150
|
-
let at = t === undefined ? outer : compose(outer, transformOf(name, t));
|
|
151
|
-
switch (node.kind) {
|
|
152
|
-
case "mjx-container":
|
|
153
|
-
case "g":
|
|
154
|
-
break;
|
|
155
|
-
case "svg": {
|
|
156
|
-
if (!nested)
|
|
157
|
-
break;
|
|
158
|
-
at = compose(at, [1, 0, 0, 1, number(node, "x"), number(node, "y")]);
|
|
159
|
-
const box = numbers(attribute(node, "viewBox") ?? "");
|
|
160
|
-
const [bx = 0, by = 0, bw = 0, bh = 0] = box;
|
|
161
|
-
const [w, h] = [number(node, "width"), number(node, "height")];
|
|
162
|
-
if (box.length === 4 && bw > 0 && bh > 0 && w > 0 && h > 0) {
|
|
163
|
-
at = compose(at, [w / bw, 0, 0, h / bh, -bx, -by]);
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case "path": {
|
|
168
|
-
// A space is a path with no data.
|
|
169
|
-
const d = attribute(node, "d") ?? "";
|
|
170
|
-
if (d.trim() !== "")
|
|
171
|
-
glyph(p, d, at);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
case "rect": {
|
|
175
|
-
const [x, y, w, h] = [number(node, "x"), number(node, "y"), number(node, "width"), number(node, "height")];
|
|
176
|
-
if (attribute(node, "fill") === "none") {
|
|
177
|
-
// A stroked frame (\boxed): the ring of its stroke, inner edge the other way round.
|
|
178
|
-
const s = number(node, "stroke-width") / 2;
|
|
179
|
-
const inner = `M${String(x + s)} ${String(y + s)}V${String(y + h - s)}H${String(x + w - s)}V${String(y + s)}Z`;
|
|
180
|
-
glyph(p, rect(x - s, y - s, w + 2 * s, h + 2 * s) + inner, at);
|
|
181
|
-
}
|
|
182
|
-
else
|
|
183
|
-
glyph(p, rect(x, y, w, h), at);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
case "line": {
|
|
187
|
-
// A stroked line (\cancel): a thin quadrilateral.
|
|
188
|
-
const [x1, y1, x2, y2] = [number(node, "x1"), number(node, "y1"), number(node, "x2"), number(node, "y2")];
|
|
189
|
-
const length = Math.hypot(x2 - x1, y2 - y1);
|
|
190
|
-
if (length === 0)
|
|
191
|
-
return;
|
|
192
|
-
const s = number(node, "stroke-width") / 2;
|
|
193
|
-
const [nx, ny] = [(-(y2 - y1) / length) * s, ((x2 - x1) / length) * s];
|
|
194
|
-
const q = [
|
|
195
|
-
[x1 + nx, y1 + ny],
|
|
196
|
-
[x2 + nx, y2 + ny],
|
|
197
|
-
[x2 - nx, y2 - ny],
|
|
198
|
-
[x1 - nx, y1 - ny],
|
|
199
|
-
];
|
|
200
|
-
glyph(p, `M${q.map(([a = 0, b = 0]) => `${String(a)} ${String(b)}`).join("L")}Z`, at);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
case "text": {
|
|
204
|
-
const text = node.children.map((c) => ("value" in c ? c.value : "")).join("");
|
|
205
|
-
fail(name, `the MathJax TeX font has no glyph for ${JSON.stringify(text)}`);
|
|
206
|
-
}
|
|
207
|
-
case "title":
|
|
208
|
-
case "desc":
|
|
209
|
-
case "defs":
|
|
210
|
-
return;
|
|
211
|
-
default:
|
|
212
|
-
fail(name, `MathJax drew a <${node.kind}>, which aula cannot draw`);
|
|
213
|
-
}
|
|
214
|
-
for (const child of node.children)
|
|
215
|
-
walk(child, at, p, nested || node.kind === "svg");
|
|
216
|
-
};
|
|
217
|
-
walk(root, m, undefined, false);
|
|
218
|
-
return parts;
|
|
219
|
-
}
|
|
220
|
-
/** Text-mode LaTeX (`Tex`) as math: the text between `$` signs stays math, the rest goes in
|
|
221
|
-
* `\text{…}`. */
|
|
222
|
-
function textMode(s) {
|
|
223
|
-
const pieces = s.split(/(?<!\\)\$/);
|
|
224
|
-
if (pieces.length % 2 === 0)
|
|
225
|
-
fail("Tex", `"${s}" has an odd number of $ signs`);
|
|
226
|
-
return pieces.map((piece, i) => (i % 2 === 1 ? `{${piece}}` : piece === "" ? "" : `\\text{${piece}}`)).join("");
|
|
227
|
-
}
|
|
228
|
-
function body(part, name) {
|
|
229
|
-
return name === "Tex" ? textMode(part) : part;
|
|
230
|
-
}
|
|
231
|
-
const cache = new Map();
|
|
232
|
-
/** The glyphs of each part of a formula of `name`, at `fontSize`, centred later by the engine.
|
|
233
|
-
* Tex reads the parts as text-mode LaTeX, MathTex as math. A formula that does not parse throws
|
|
234
|
-
* a AulaError that names the part. */
|
|
235
|
-
export function texGlyphs(name, parts, separator, fontSize) {
|
|
236
|
-
const key = JSON.stringify([name, parts, separator, fontSize]);
|
|
237
|
-
const known = cache.get(key);
|
|
238
|
-
if (known !== undefined)
|
|
239
|
-
return known;
|
|
240
|
-
const root = parse(parts.map((p, i) => `\\class{aula-${String(i)}}{${body(p, name)}}`).join(separator));
|
|
241
|
-
if (root._tag === "Left") {
|
|
242
|
-
// Name the part that does not parse alone, if one does not.
|
|
243
|
-
for (const [i, p] of parts.entries()) {
|
|
244
|
-
const alone = parse(body(p, name));
|
|
245
|
-
if (alone._tag === "Right")
|
|
246
|
-
continue;
|
|
247
|
-
const which = parts.length > 1 ? `part ${String(i)}, ` : "";
|
|
248
|
-
fail(name, `${which}"${p}", does not parse: ${alone.left}`);
|
|
249
|
-
}
|
|
250
|
-
fail(name, `"${parts.join(separator)}" does not parse: ${root.left}`);
|
|
251
|
-
}
|
|
252
|
-
const s = fontSize * UNITS_PER_EM_PER_SIZE * 0.001;
|
|
253
|
-
// MathJax's SVG is y down (its root group flips the font's y up): flip it back.
|
|
254
|
-
const glyphs = collect(name, root.right, parts.length, [s, 0, 0, -s, 0, 0]);
|
|
255
|
-
cache.set(key, glyphs);
|
|
256
|
-
return glyphs;
|
|
257
|
-
}
|