@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/media.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
// The files that an `embed` plays: what a file is and how long it is, read from its header.
|
|
2
|
-
// `probeMedia` is pure: the host gives the bytes of the file (`Host.media`), the same for the
|
|
3
|
-
// CLI and the web app. The length is the one in the header, so every command gets the same
|
|
4
|
-
// number. Not here: decoding. The export and the browser play the file.
|
|
5
|
-
/** The most bytes of one file of an `embed`. */
|
|
6
|
-
export const MAX_CLIP_BYTES = 50 * 1024 * 1024;
|
|
7
|
-
/** The formats that an `embed` plays, for the messages. */
|
|
8
|
-
export const MEDIA_FORMATS = "MP4 (H.264, AAC) or WebM (VP8 or VP9, Opus or Vorbis) video; WAV (PCM) or MP3 sound; PNG or JPEG picture";
|
|
9
|
-
const ascii = (bytes, at, length) => String.fromCharCode(...bytes.subarray(at, at + length));
|
|
10
|
-
const view = (bytes) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
11
|
-
const SIGNATURE_PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
12
|
-
/** The MB of `bytes`, for a message. */
|
|
13
|
-
const megabytes = (bytes) => (bytes / (1024 * 1024)).toFixed(1);
|
|
14
|
-
/** What the file `source` is, or why aula cannot play it (a problem that fits after the path of
|
|
15
|
-
* the file). The size is checked before the read. */
|
|
16
|
-
export function probeMedia(source) {
|
|
17
|
-
if (source.size > MAX_CLIP_BYTES) {
|
|
18
|
-
return `is ${megabytes(source.size)} MB, and the limit is ${megabytes(MAX_CLIP_BYTES)} MB`;
|
|
19
|
-
}
|
|
20
|
-
const bytes = source.read();
|
|
21
|
-
if (bytes.length >= 8 && SIGNATURE_PNG.every((b, i) => bytes[i] === b))
|
|
22
|
-
return { kind: "image", format: "png" };
|
|
23
|
-
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
|
|
24
|
-
return { kind: "image", format: "jpeg" };
|
|
25
|
-
}
|
|
26
|
-
if (bytes.length >= 12 && ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WAVE")
|
|
27
|
-
return probeWav(bytes);
|
|
28
|
-
if (bytes.length >= 12 && ascii(bytes, 4, 4) === "ftyp")
|
|
29
|
-
return probeMp4(bytes);
|
|
30
|
-
if (bytes.length >= 4 && bytes[0] === 0x1a && bytes[1] === 0x45 && bytes[2] === 0xdf && bytes[3] === 0xa3) {
|
|
31
|
-
return probeWebm(bytes);
|
|
32
|
-
}
|
|
33
|
-
const mp3 = probeMp3(bytes);
|
|
34
|
-
if (mp3 !== undefined)
|
|
35
|
-
return mp3;
|
|
36
|
-
return `has an unknown format: aula plays ${MEDIA_FORMATS}`;
|
|
37
|
-
}
|
|
38
|
-
/** A length in seconds that is a number above 0, or the problem of a header with no length. */
|
|
39
|
-
function lengthOf(seconds) {
|
|
40
|
-
return Number.isFinite(seconds) && seconds > 0 ? seconds : "has no length in its header";
|
|
41
|
-
}
|
|
42
|
-
// --- WAV ------------------------------------------------------------------------------------
|
|
43
|
-
function probeWav(bytes) {
|
|
44
|
-
const data = view(bytes);
|
|
45
|
-
let at = 12;
|
|
46
|
-
let byteRate = 0;
|
|
47
|
-
let format = -1;
|
|
48
|
-
while (at + 8 <= bytes.length) {
|
|
49
|
-
const id = ascii(bytes, at, 4);
|
|
50
|
-
const size = data.getUint32(at + 4, true);
|
|
51
|
-
const body = at + 8;
|
|
52
|
-
if (id === "fmt " && body + 16 <= bytes.length) {
|
|
53
|
-
format = data.getUint16(body, true);
|
|
54
|
-
// WAVE_FORMAT_EXTENSIBLE: the format is the first two bytes of its sub-format.
|
|
55
|
-
if (format === 0xfffe && size >= 26 && body + 26 <= bytes.length)
|
|
56
|
-
format = data.getUint16(body + 24, true);
|
|
57
|
-
byteRate = data.getUint32(body + 8, true);
|
|
58
|
-
}
|
|
59
|
-
else if (id === "data") {
|
|
60
|
-
if (format !== 1)
|
|
61
|
-
return `is a WAV file that is not PCM (format ${String(format)})`;
|
|
62
|
-
// A size that is 0 or past the end of the file (a stream) is the rest of the file.
|
|
63
|
-
const length = size === 0 || size > bytes.length - body ? bytes.length - body : size;
|
|
64
|
-
const seconds = lengthOf(byteRate > 0 ? length / byteRate : 0);
|
|
65
|
-
return typeof seconds === "string" ? seconds : { kind: "sound", format: "wav", seconds };
|
|
66
|
-
}
|
|
67
|
-
at = body + size + (size % 2);
|
|
68
|
-
}
|
|
69
|
-
return format === -1 ? "has a WAV header with no fmt chunk" : "has a WAV header with no data chunk";
|
|
70
|
-
}
|
|
71
|
-
// --- MP3 ------------------------------------------------------------------------------------
|
|
72
|
-
const MP3_BITRATES = {
|
|
73
|
-
// MPEG 1, layer III.
|
|
74
|
-
1: [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320],
|
|
75
|
-
// MPEG 2 and 2.5, layer III.
|
|
76
|
-
2: [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160],
|
|
77
|
-
};
|
|
78
|
-
const MP3_RATES = [44100, 48000, 32000];
|
|
79
|
-
/** The layer III frame header at `at`, or undefined. */
|
|
80
|
-
function mp3Frame(bytes, at) {
|
|
81
|
-
const [b0, b1, b2] = [bytes[at], bytes[at + 1], bytes[at + 2]];
|
|
82
|
-
if (b0 !== 0xff || b1 === undefined || b2 === undefined || (b1 & 0xe0) !== 0xe0)
|
|
83
|
-
return undefined;
|
|
84
|
-
const version = (b1 >> 3) & 3; // 0: 2.5, 2: 2, 3: 1
|
|
85
|
-
const layer = (b1 >> 1) & 3; // 1: III
|
|
86
|
-
if (version === 1 || layer !== 1)
|
|
87
|
-
return undefined;
|
|
88
|
-
const bitrateIndex = b2 >> 4;
|
|
89
|
-
const rateIndex = (b2 >> 2) & 3;
|
|
90
|
-
if (bitrateIndex === 0 || bitrateIndex === 15 || rateIndex === 3)
|
|
91
|
-
return undefined;
|
|
92
|
-
const mpeg1 = version === 3;
|
|
93
|
-
const bitrate = MP3_BITRATES[mpeg1 ? 1 : 2][bitrateIndex] ?? 0;
|
|
94
|
-
const rate = (MP3_RATES[rateIndex] ?? 0) / (version === 3 ? 1 : version === 2 ? 2 : 4);
|
|
95
|
-
const padding = (b2 >> 1) & 1;
|
|
96
|
-
const samples = mpeg1 ? 1152 : 576;
|
|
97
|
-
const length = Math.floor(((mpeg1 ? 144000 : 72000) * bitrate) / rate) + padding;
|
|
98
|
-
return length > 4 ? { length, samples, rate } : undefined;
|
|
99
|
-
}
|
|
100
|
-
/** An MP3 file (undefined when the bytes are not one): the sum of the samples of its frames. */
|
|
101
|
-
function probeMp3(bytes) {
|
|
102
|
-
let at = 0;
|
|
103
|
-
if (bytes.length >= 10 && ascii(bytes, 0, 3) === "ID3") {
|
|
104
|
-
const size = ((bytes[6] ?? 0) << 21) | ((bytes[7] ?? 0) << 14) | ((bytes[8] ?? 0) << 7) | (bytes[9] ?? 0);
|
|
105
|
-
at = 10 + size;
|
|
106
|
-
}
|
|
107
|
-
// The first frame must start at once (after the tag): a file with another format has no frames.
|
|
108
|
-
let first = mp3Frame(bytes, at);
|
|
109
|
-
for (let skip = 0; first === undefined && skip < 4096 && at < bytes.length; skip++)
|
|
110
|
-
first = mp3Frame(bytes, ++at);
|
|
111
|
-
if (first === undefined)
|
|
112
|
-
return undefined;
|
|
113
|
-
const firstAt = at;
|
|
114
|
-
const next = mp3Frame(bytes, at + first.length);
|
|
115
|
-
if (next === undefined && at + first.length < bytes.length - 128)
|
|
116
|
-
return undefined;
|
|
117
|
-
let samples = 0;
|
|
118
|
-
let frames = 0;
|
|
119
|
-
while (at < bytes.length) {
|
|
120
|
-
const frame = mp3Frame(bytes, at);
|
|
121
|
-
if (frame === undefined)
|
|
122
|
-
break;
|
|
123
|
-
if (at + frame.length > bytes.length + 1)
|
|
124
|
-
break;
|
|
125
|
-
frames += 1;
|
|
126
|
-
samples += frame.samples;
|
|
127
|
-
at += frame.length;
|
|
128
|
-
}
|
|
129
|
-
// A Xing or Info frame has no sound: it is the first frame, and it is not in the length.
|
|
130
|
-
const tag = /Xing|Info/.test(ascii(bytes, firstAt + 4, 40));
|
|
131
|
-
const seconds = lengthOf((samples - (tag && frames > 1 ? first.samples : 0)) / first.rate);
|
|
132
|
-
return typeof seconds === "string" ? seconds : { kind: "sound", format: "mp3", seconds };
|
|
133
|
-
}
|
|
134
|
-
/** The boxes of `bytes` from `from` to `to`. A box that does not fit stops the list. */
|
|
135
|
-
function boxes(bytes, from, to) {
|
|
136
|
-
const data = view(bytes);
|
|
137
|
-
const out = [];
|
|
138
|
-
let at = from;
|
|
139
|
-
while (at + 8 <= to) {
|
|
140
|
-
let size = data.getUint32(at, false);
|
|
141
|
-
const type = ascii(bytes, at + 4, 4);
|
|
142
|
-
let head = 8;
|
|
143
|
-
if (size === 1) {
|
|
144
|
-
if (at + 16 > to)
|
|
145
|
-
break;
|
|
146
|
-
size = Number(data.getBigUint64(at + 8, false));
|
|
147
|
-
head = 16;
|
|
148
|
-
}
|
|
149
|
-
else if (size === 0) {
|
|
150
|
-
size = to - at;
|
|
151
|
-
}
|
|
152
|
-
if (size < head || at + size > to)
|
|
153
|
-
break;
|
|
154
|
-
out.push({ type, start: at + head, end: at + size });
|
|
155
|
-
at += size;
|
|
156
|
-
}
|
|
157
|
-
return out;
|
|
158
|
-
}
|
|
159
|
-
const childOf = (bytes, box, type, skip = 0) => box === undefined ? undefined : boxes(bytes, box.start + skip, box.end).find((b) => b.type === type);
|
|
160
|
-
/** The codec of the AAC description of an `mp4a` entry (`esds`): its object type, or undefined. */
|
|
161
|
-
function aacObjectType(bytes, entry) {
|
|
162
|
-
// An audio sample entry has 28 bytes before its boxes.
|
|
163
|
-
const esds = childOf(bytes, entry, "esds", 28);
|
|
164
|
-
if (esds === undefined)
|
|
165
|
-
return undefined;
|
|
166
|
-
// version and flags (4), then descriptors: ES (tag 3), then DecoderConfig (tag 4).
|
|
167
|
-
let at = esds.start + 4;
|
|
168
|
-
const length = () => {
|
|
169
|
-
let size = 0;
|
|
170
|
-
for (let i = 0; i < 4 && at < esds.end; i++) {
|
|
171
|
-
const b = bytes[at++] ?? 0;
|
|
172
|
-
size = (size << 7) | (b & 0x7f);
|
|
173
|
-
if ((b & 0x80) === 0)
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
return size;
|
|
177
|
-
};
|
|
178
|
-
if (bytes[at++] !== 3)
|
|
179
|
-
return undefined;
|
|
180
|
-
length();
|
|
181
|
-
at += 2;
|
|
182
|
-
const flags = bytes[at++] ?? 0;
|
|
183
|
-
if (flags & 0x80)
|
|
184
|
-
at += 2;
|
|
185
|
-
if (flags & 0x40)
|
|
186
|
-
at += 1 + (bytes[at] ?? 0);
|
|
187
|
-
if (flags & 0x20)
|
|
188
|
-
at += 2;
|
|
189
|
-
if (bytes[at++] !== 4)
|
|
190
|
-
return undefined;
|
|
191
|
-
length();
|
|
192
|
-
return bytes[at];
|
|
193
|
-
}
|
|
194
|
-
function probeMp4(bytes) {
|
|
195
|
-
const data = view(bytes);
|
|
196
|
-
const moov = boxes(bytes, 0, bytes.length).find((b) => b.type === "moov");
|
|
197
|
-
if (moov === undefined)
|
|
198
|
-
return "has an MP4 header with no movie box (moov): it may be cut, or not ready for streaming";
|
|
199
|
-
const mvhd = childOf(bytes, moov, "mvhd");
|
|
200
|
-
let seconds = 0;
|
|
201
|
-
if (mvhd !== undefined) {
|
|
202
|
-
const version = bytes[mvhd.start] ?? 0;
|
|
203
|
-
const at = mvhd.start + 4 + (version === 1 ? 16 : 8);
|
|
204
|
-
if (at + (version === 1 ? 12 : 8) <= mvhd.end) {
|
|
205
|
-
const scale = data.getUint32(at, false);
|
|
206
|
-
const duration = version === 1 ? Number(data.getBigUint64(at + 4, false)) : data.getUint32(at + 4, false);
|
|
207
|
-
seconds = scale > 0 ? duration / scale : 0;
|
|
208
|
-
}
|
|
209
|
-
if (seconds === 0) {
|
|
210
|
-
// A fragmented file has its length in `mvex/mehd`.
|
|
211
|
-
const mehd = childOf(bytes, childOf(bytes, moov, "mvex"), "mehd");
|
|
212
|
-
if (mehd !== undefined && scaleOf(data, mvhd) > 0) {
|
|
213
|
-
const wide = (bytes[mehd.start] ?? 0) === 1;
|
|
214
|
-
const fragment = wide
|
|
215
|
-
? Number(data.getBigUint64(mehd.start + 4, false))
|
|
216
|
-
: data.getUint32(mehd.start + 4, false);
|
|
217
|
-
seconds = fragment / scaleOf(data, mvhd);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
let video;
|
|
222
|
-
let audio;
|
|
223
|
-
for (const trak of boxes(bytes, moov.start, moov.end).filter((b) => b.type === "trak")) {
|
|
224
|
-
const mdia = childOf(bytes, trak, "mdia");
|
|
225
|
-
const hdlr = childOf(bytes, mdia, "hdlr");
|
|
226
|
-
const handler = hdlr === undefined ? "" : ascii(bytes, hdlr.start + 8, 4);
|
|
227
|
-
const stsd = childOf(bytes, childOf(bytes, childOf(bytes, mdia, "minf"), "stbl"), "stsd");
|
|
228
|
-
// version and flags (4), the number of entries (4), then the first entry.
|
|
229
|
-
const entry = stsd === undefined ? undefined : boxes(bytes, stsd.start + 8, stsd.end)[0];
|
|
230
|
-
if (entry === undefined)
|
|
231
|
-
continue;
|
|
232
|
-
if (handler === "vide")
|
|
233
|
-
video ??= entry.type;
|
|
234
|
-
if (handler === "soun") {
|
|
235
|
-
audio ??= entry.type;
|
|
236
|
-
if (entry.type === "mp4a") {
|
|
237
|
-
const type = aacObjectType(bytes, entry);
|
|
238
|
-
if (type !== undefined && ![0x40, 0x66, 0x67, 0x68].includes(type)) {
|
|
239
|
-
audio = `mp4a with object type 0x${type.toString(16)}`;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (video === undefined)
|
|
245
|
-
return "has no video track: a sound is a WAV or MP3 file";
|
|
246
|
-
if (video !== "avc1" && video !== "avc3")
|
|
247
|
-
return `has the video codec ${video}, and aula plays H.264 (avc1) in MP4`;
|
|
248
|
-
if (audio !== undefined && audio !== "mp4a")
|
|
249
|
-
return `has the audio codec ${audio}, and aula plays AAC (mp4a) in MP4`;
|
|
250
|
-
const length = lengthOf(seconds);
|
|
251
|
-
return typeof length === "string" ? length : { kind: "video", format: "mp4", seconds: length };
|
|
252
|
-
}
|
|
253
|
-
const scaleOf = (data, mvhd) => data.getUint32(mvhd.start + 4 + (data.getUint8(mvhd.start) === 1 ? 16 : 8), false);
|
|
254
|
-
/** The element at `at`, or undefined at the end of the bytes or at a wrong id or size. */
|
|
255
|
-
function element(bytes, at) {
|
|
256
|
-
const first = bytes[at];
|
|
257
|
-
if (first === undefined || first === 0)
|
|
258
|
-
return undefined;
|
|
259
|
-
const idLength = Math.clz32(first) - 24 + 1;
|
|
260
|
-
if (idLength > 4 || at + idLength >= bytes.length)
|
|
261
|
-
return undefined;
|
|
262
|
-
let id = 0;
|
|
263
|
-
for (let i = 0; i < idLength; i++)
|
|
264
|
-
id = id * 256 + (bytes[at + i] ?? 0);
|
|
265
|
-
const sizeAt = at + idLength;
|
|
266
|
-
const sizeFirst = bytes[sizeAt];
|
|
267
|
-
if (sizeFirst === undefined || sizeFirst === 0)
|
|
268
|
-
return undefined;
|
|
269
|
-
const sizeLength = Math.clz32(sizeFirst) - 24 + 1;
|
|
270
|
-
if (sizeLength > 8 || sizeAt + sizeLength > bytes.length)
|
|
271
|
-
return undefined;
|
|
272
|
-
let size = sizeFirst & (0xff >> sizeLength);
|
|
273
|
-
let unknown = size === 0xff >> sizeLength;
|
|
274
|
-
for (let i = 1; i < sizeLength; i++) {
|
|
275
|
-
const b = bytes[sizeAt + i] ?? 0;
|
|
276
|
-
size = size * 256 + b;
|
|
277
|
-
if (b !== 0xff)
|
|
278
|
-
unknown = false;
|
|
279
|
-
}
|
|
280
|
-
const start = sizeAt + sizeLength;
|
|
281
|
-
return { id, start, end: unknown ? Infinity : start + size };
|
|
282
|
-
}
|
|
283
|
-
/** The children of the element body `[from, to)`, up to the first cluster. */
|
|
284
|
-
function children(bytes, from, to) {
|
|
285
|
-
const out = [];
|
|
286
|
-
let at = from;
|
|
287
|
-
while (at < to && at < bytes.length) {
|
|
288
|
-
const e = element(bytes, at);
|
|
289
|
-
if (e === undefined)
|
|
290
|
-
break;
|
|
291
|
-
out.push(e);
|
|
292
|
-
if (e.end === Infinity)
|
|
293
|
-
break;
|
|
294
|
-
at = e.end;
|
|
295
|
-
}
|
|
296
|
-
return out;
|
|
297
|
-
}
|
|
298
|
-
const WEBM = {
|
|
299
|
-
segment: 0x18538067,
|
|
300
|
-
info: 0x1549a966,
|
|
301
|
-
tracks: 0x1654ae6b,
|
|
302
|
-
entry: 0xae,
|
|
303
|
-
type: 0x83,
|
|
304
|
-
codec: 0x86,
|
|
305
|
-
scale: 0x2ad7b1,
|
|
306
|
-
duration: 0x4489,
|
|
307
|
-
docType: 0x4282,
|
|
308
|
-
header: 0x1a45dfa3,
|
|
309
|
-
};
|
|
310
|
-
function probeWebm(bytes) {
|
|
311
|
-
const data = view(bytes);
|
|
312
|
-
const top = children(bytes, 0, bytes.length);
|
|
313
|
-
const head = top.find((e) => e.id === WEBM.header);
|
|
314
|
-
const docType = head && children(bytes, head.start, head.end).find((e) => e.id === WEBM.docType);
|
|
315
|
-
if (docType === undefined || ascii(bytes, docType.start, docType.end - docType.start) !== "webm") {
|
|
316
|
-
return `has the EBML header of a file that is not WebM: aula plays ${MEDIA_FORMATS}`;
|
|
317
|
-
}
|
|
318
|
-
const segment = top.find((e) => e.id === WEBM.segment);
|
|
319
|
-
if (segment === undefined)
|
|
320
|
-
return "has no segment: a WebM file is cut";
|
|
321
|
-
const parts = children(bytes, segment.start, Math.min(segment.end, bytes.length));
|
|
322
|
-
const info = parts.find((e) => e.id === WEBM.info);
|
|
323
|
-
const tracks = parts.find((e) => e.id === WEBM.tracks);
|
|
324
|
-
if (info === undefined || tracks === undefined)
|
|
325
|
-
return "has no length in its header";
|
|
326
|
-
const fields = children(bytes, info.start, info.end);
|
|
327
|
-
const scale = fields.find((e) => e.id === WEBM.scale);
|
|
328
|
-
let timecode = 1_000_000;
|
|
329
|
-
if (scale !== undefined) {
|
|
330
|
-
timecode = 0;
|
|
331
|
-
for (let i = scale.start; i < scale.end; i++)
|
|
332
|
-
timecode = timecode * 256 + (bytes[i] ?? 0);
|
|
333
|
-
}
|
|
334
|
-
const long = fields.find((e) => e.id === WEBM.duration);
|
|
335
|
-
let seconds = 0;
|
|
336
|
-
if (long !== undefined) {
|
|
337
|
-
const size = long.end - long.start;
|
|
338
|
-
if (size === 4)
|
|
339
|
-
seconds = (data.getFloat32(long.start, false) * timecode) / 1e9;
|
|
340
|
-
if (size === 8)
|
|
341
|
-
seconds = (data.getFloat64(long.start, false) * timecode) / 1e9;
|
|
342
|
-
}
|
|
343
|
-
let video = false;
|
|
344
|
-
for (const entry of children(bytes, tracks.start, tracks.end).filter((e) => e.id === WEBM.entry)) {
|
|
345
|
-
const fieldsOf = children(bytes, entry.start, entry.end);
|
|
346
|
-
const type = fieldsOf.find((e) => e.id === WEBM.type);
|
|
347
|
-
const codec = fieldsOf.find((e) => e.id === WEBM.codec);
|
|
348
|
-
const name = codec === undefined ? "" : ascii(bytes, codec.start, codec.end - codec.start);
|
|
349
|
-
if (type !== undefined && bytes[type.start] === 1) {
|
|
350
|
-
video = true;
|
|
351
|
-
if (name !== "V_VP8" && name !== "V_VP9")
|
|
352
|
-
return `has the video codec ${name}, and aula plays VP8 or VP9 in WebM`;
|
|
353
|
-
}
|
|
354
|
-
else if (type !== undefined && bytes[type.start] === 2) {
|
|
355
|
-
if (name !== "A_OPUS" && name !== "A_VORBIS") {
|
|
356
|
-
return `has the audio codec ${name}, and aula plays Opus or Vorbis in WebM`;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (!video)
|
|
361
|
-
return "has no video track: a sound is a WAV or MP3 file";
|
|
362
|
-
const length = lengthOf(seconds);
|
|
363
|
-
return typeof length === "string" ? length : { kind: "video", format: "webm", seconds: length };
|
|
364
|
-
}
|
|
365
|
-
// --- paths ----------------------------------------------------------------------------------
|
|
366
|
-
/** The path `given` of a file of the project, from the folder `from` of the project (default: the
|
|
367
|
-
* project folder), as a path from the project folder with no `.` and no `..`, or the problem with
|
|
368
|
-
* it: a URL, an absolute path, or a path outside the project folder. */
|
|
369
|
-
export function projectPath(given, from = "") {
|
|
370
|
-
if (given.trim() === "")
|
|
371
|
-
return { problem: "has an empty path" };
|
|
372
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(given)) {
|
|
373
|
-
return { problem: `is a URL (${JSON.stringify(given)}): aula plays files of the project folder` };
|
|
374
|
-
}
|
|
375
|
-
if (given.startsWith("/") || given.includes("\\")) {
|
|
376
|
-
return { problem: `is not a path from the project folder with "/" (${JSON.stringify(given)})` };
|
|
377
|
-
}
|
|
378
|
-
const parts = from.split("/").filter((part) => part !== "");
|
|
379
|
-
for (const part of given.split("/")) {
|
|
380
|
-
if (part === "" || part === ".")
|
|
381
|
-
continue;
|
|
382
|
-
if (part === "..") {
|
|
383
|
-
if (parts.pop() === undefined)
|
|
384
|
-
return { problem: `is outside the project folder (${JSON.stringify(given)})` };
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
parts.push(part);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return parts.length === 0 ? { problem: "has an empty path" } : { path: parts.join("/") };
|
|
391
|
-
}
|
package/dist/mobjects.d.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { type AnimationOptions, type Color, type DecimalNumberMobject, type Mobjects, type MobjectAttributes, type Point, type StyleOptions, Animation, DecimalNumber, Integer, Mobject, ValueTracker } from "./engine.ts";
|
|
2
|
-
import type { Mobject as RawMobject } from "./generated/interfaces/aula-engine-engine.js";
|
|
3
|
-
/** Manim's `Group`: any mobjects as one. aula draws every mobject as vectors, so it is a VGroup. */
|
|
4
|
-
export declare function Group(...mobjects: Mobjects[]): Mobject;
|
|
5
|
-
/** A key of a VDict. */
|
|
6
|
-
export type VDictKey = string | number;
|
|
7
|
-
/** The entries of a VDict: an object, or `[key, mobject]` pairs. */
|
|
8
|
-
export type VDictEntries = Readonly<Record<string, Mobject>> | Iterable<readonly [VDictKey, Mobject]>;
|
|
9
|
-
/** A VGroup whose submobjects have keys: Manim's `VDict`. `get(key)` is Manim's `vdict[key]`. */
|
|
10
|
-
export declare class VDictMobject extends Mobject {
|
|
11
|
-
/** The submobject of each key (Manim `submob_dict`). */
|
|
12
|
-
readonly submobDict: Map<VDictKey, Mobject>;
|
|
13
|
-
showKeys: boolean;
|
|
14
|
-
/** Adds each entry (Manim `add`); a Mobject is added as a plain submobject. */
|
|
15
|
-
add(...mappingOrIterable: (Mobjects | VDictEntries)[]): this;
|
|
16
|
-
/** Removes the submobject of `key` (Manim `remove(key)`). A key that is not there is an error. */
|
|
17
|
-
remove(...key: (Mobjects | VDictKey)[]): this;
|
|
18
|
-
/** The submobject of `key`, or undefined (Manim `vdict[key]`). */
|
|
19
|
-
get(key: VDictKey): Mobject | undefined;
|
|
20
|
-
/** `set(key, value)` replaces the submobject of `key` (Manim `vdict[key] = value`).
|
|
21
|
-
* `set(attributes)` is `Mobject.set`. */
|
|
22
|
-
set(keyOrAttributes: VDictKey | MobjectAttributes, value?: Mobject): this;
|
|
23
|
-
has(key: VDictKey): boolean;
|
|
24
|
-
/** The values (Manim `get_all_submobjects`). */
|
|
25
|
-
getAllSubmobjects(): Mobject[];
|
|
26
|
-
/** Adds `value` with `key`. With `showKeys`, a `Tex` of the key goes to its left. */
|
|
27
|
-
addKeyValuePair(key: VDictKey, value: Mobject): this;
|
|
28
|
-
copy(): VDictMobject;
|
|
29
|
-
}
|
|
30
|
-
/** Manim's `VDict(mappingOrIterable, { showKeys })`: `VDict({ a: square, b: circle })`. */
|
|
31
|
-
export declare function VDict(mappingOrIterable?: VDictEntries, opts?: {
|
|
32
|
-
showKeys?: boolean;
|
|
33
|
-
}): VDictMobject;
|
|
34
|
-
/** One point with a small artificial size: Manim's `VectorizedPoint`. */
|
|
35
|
-
export declare class VectorizedPointMobject extends Mobject {
|
|
36
|
-
artificialWidth: number;
|
|
37
|
-
artificialHeight: number;
|
|
38
|
-
get width(): number;
|
|
39
|
-
set width(value: number);
|
|
40
|
-
get height(): number;
|
|
41
|
-
set height(value: number);
|
|
42
|
-
/** The point (Manim `get_location`). */
|
|
43
|
-
getLocation(): Point;
|
|
44
|
-
/** Moves the point to `newLoc` (Manim `set_location`). */
|
|
45
|
-
setLocation(newLoc: Point): this;
|
|
46
|
-
copy(): VectorizedPointMobject;
|
|
47
|
-
}
|
|
48
|
-
/** The options of VectorizedPoint (Manim's keyword arguments). */
|
|
49
|
-
export interface VectorizedPointOptions extends StyleOptions {
|
|
50
|
-
artificialWidth?: number;
|
|
51
|
-
artificialHeight?: number;
|
|
52
|
-
}
|
|
53
|
-
/** An invisible point (Manim `VectorizedPoint`): black, no fill, no stroke. */
|
|
54
|
-
export declare function VectorizedPoint(location?: Point, opts?: VectorizedPointOptions): VectorizedPointMobject;
|
|
55
|
-
/** Each curve of a path as a submobject: Manim's `CurvesAsSubmobjects`. */
|
|
56
|
-
export declare class CurvesAsSubmobjectsMobject extends Mobject {
|
|
57
|
-
/** The point at `alpha` of the total arc length of the curves (Manim `point_from_proportion`). */
|
|
58
|
-
pointFromProportion(alpha: number): Point;
|
|
59
|
-
copy(): CurvesAsSubmobjectsMobject;
|
|
60
|
-
}
|
|
61
|
-
/** One submobject for each cubic curve of `vmobject`, in its style (Manim `CurvesAsSubmobjects`). */
|
|
62
|
-
export declare function CurvesAsSubmobjects(vmobject: Mobject): CurvesAsSubmobjectsMobject;
|
|
63
|
-
/** A rectangle with the shape of the screen: Manim's `ScreenRectangle`. */
|
|
64
|
-
export declare class ScreenRectangleMobject extends Mobject {
|
|
65
|
-
/** The width over the height; setting it stretches the width. */
|
|
66
|
-
get aspectRatio(): number;
|
|
67
|
-
set aspectRatio(value: number);
|
|
68
|
-
copy(): ScreenRectangleMobject;
|
|
69
|
-
}
|
|
70
|
-
/** Manim's `ScreenRectangle({ aspectRatio, height })`: 16:9 and 4 high by default. */
|
|
71
|
-
export declare function ScreenRectangle(opts?: StyleOptions & {
|
|
72
|
-
aspectRatio?: number;
|
|
73
|
-
height?: number;
|
|
74
|
-
}): ScreenRectangleMobject;
|
|
75
|
-
/** A ScreenRectangle as high as the frame: Manim's `FullScreenRectangle`. */
|
|
76
|
-
export declare function FullScreenRectangle(opts?: StyleOptions & {
|
|
77
|
-
aspectRatio?: number;
|
|
78
|
-
}): ScreenRectangleMobject;
|
|
79
|
-
/** A complex number as `[re, im]`. */
|
|
80
|
-
export type ComplexValue = readonly [number, number];
|
|
81
|
-
/** A complex number that animations change (Manim `ComplexValueTracker`), as `[re, im]`. */
|
|
82
|
-
export declare class ComplexValueTrackerObject {
|
|
83
|
-
#private;
|
|
84
|
-
constructor(value: ComplexValue | number);
|
|
85
|
-
getValue(): [number, number];
|
|
86
|
-
setValue(value: ComplexValue | number): this;
|
|
87
|
-
incrementValue(dValue: ComplexValue | number): this;
|
|
88
|
-
/** `tracker.animate.setValue(z)` and `incrementValue(dz)`, or with the animation options first. */
|
|
89
|
-
get animate(): ComplexTrackerBuilder;
|
|
90
|
-
}
|
|
91
|
-
interface ComplexTrackerMethods {
|
|
92
|
-
setValue(value: ComplexValue | number): Animation;
|
|
93
|
-
incrementValue(dValue: ComplexValue | number): Animation;
|
|
94
|
-
}
|
|
95
|
-
/** `tracker.animate` of a ComplexValueTracker. */
|
|
96
|
-
export type ComplexTrackerBuilder = ComplexTrackerMethods & ((opts: AnimationOptions) => ComplexTrackerMethods);
|
|
97
|
-
/** Manim's `ComplexValueTracker(value)`, with `[re, im]` for a complex number. */
|
|
98
|
-
export declare function ComplexValueTracker(value?: ComplexValue | number): ComplexValueTrackerObject;
|
|
99
|
-
/** A label, `=` and a number that follows a tracker: Manim's `Variable`. */
|
|
100
|
-
export declare class VariableMobject extends Mobject {
|
|
101
|
-
/** The label with its `=` (Manim `label`). */
|
|
102
|
-
readonly label: Mobject;
|
|
103
|
-
/** The number (Manim `value`). */
|
|
104
|
-
readonly value: DecimalNumberMobject;
|
|
105
|
-
/** The tracker that the number follows (Manim `tracker`). */
|
|
106
|
-
readonly tracker: ValueTracker;
|
|
107
|
-
constructor(handle: RawMobject, label: Mobject, value: DecimalNumberMobject, tracker: ValueTracker);
|
|
108
|
-
}
|
|
109
|
-
/** Manim's `Variable(var, label, { varType, numDecimalPlaces })`: a string label is a `MathTex`.
|
|
110
|
-
* Change `variable.tracker` to change the number. */
|
|
111
|
-
export declare function Variable(variable: number, label: string | Mobject, opts?: {
|
|
112
|
-
varType?: typeof DecimalNumber | typeof Integer;
|
|
113
|
-
numDecimalPlaces?: number;
|
|
114
|
-
}): VariableMobject;
|
|
115
|
-
/** The tree of `mobject`, one line for each node, indented by depth (Manim `print_family`).
|
|
116
|
-
* aula returns the text: print it with `console.log`. */
|
|
117
|
-
export declare function printFamily(mobject: Mobject, nTabs?: number): string;
|
|
118
|
-
/** An `Integer` on each submobject, with its index (Manim `index_labels`). Each label is a
|
|
119
|
-
* VGroup of an outline in `backgroundStrokeColor` and the Integer. */
|
|
120
|
-
export declare function indexLabels(mobject: Mobject, opts?: {
|
|
121
|
-
labelHeight?: number;
|
|
122
|
-
backgroundStrokeWidth?: number;
|
|
123
|
-
backgroundStrokeColor?: Color;
|
|
124
|
-
color?: Color;
|
|
125
|
-
fontSize?: number;
|
|
126
|
-
}): Mobject;
|
|
127
|
-
export {};
|