@beff/aula 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +9 -1
  2. package/dist/animations.d.ts +634 -0
  3. package/dist/animations.js +1793 -0
  4. package/dist/braces.d.ts +84 -0
  5. package/dist/braces.js +253 -0
  6. package/dist/card.d.ts +17 -0
  7. package/dist/card.js +90 -0
  8. package/dist/colors-palette.d.ts +2242 -0
  9. package/dist/colors-palette.js +2241 -0
  10. package/dist/colors.d.ts +120 -0
  11. package/dist/colors.js +403 -0
  12. package/dist/curves.d.ts +10 -0
  13. package/dist/curves.js +128 -0
  14. package/dist/engine.d.ts +1595 -0
  15. package/dist/engine.js +3364 -0
  16. package/dist/errors.d.ts +19 -0
  17. package/dist/errors.js +25 -0
  18. package/dist/generated/aula.conditional-suspending-3-i32-to-void.wasm +0 -0
  19. package/dist/generated/aula.core.wasm +0 -0
  20. package/dist/generated/aula.core2.wasm +0 -0
  21. package/dist/generated/aula.core3.wasm +0 -0
  22. package/dist/generated/aula.core4.wasm +0 -0
  23. package/dist/generated/aula.core5.wasm +0 -0
  24. package/dist/generated/aula.core6.wasm +0 -0
  25. package/dist/generated/aula.core7.wasm +0 -0
  26. package/dist/generated/aula.core8.wasm +0 -0
  27. package/dist/generated/aula.d.ts +80 -0
  28. package/dist/generated/aula.js +54639 -0
  29. package/dist/generated/interfaces/aula-engine-engine.d.ts +983 -0
  30. package/dist/generated/interfaces/aula-engine-host.d.ts +10 -0
  31. package/dist/generated/interfaces/aula-engine-tts.d.ts +43 -0
  32. package/dist/generated/interfaces/aula-engine-types.d.ts +60 -0
  33. package/dist/geometry.d.ts +551 -0
  34. package/dist/geometry.js +1821 -0
  35. package/dist/graph.d.ts +117 -0
  36. package/dist/graph.js +526 -0
  37. package/dist/graphing.d.ts +597 -0
  38. package/dist/graphing.js +1504 -0
  39. package/dist/host.d.ts +19 -0
  40. package/dist/host.js +85 -0
  41. package/dist/index.d.ts +5 -0
  42. package/dist/index.js +11 -0
  43. package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
  44. package/dist/licenses/espeak-ng-COPYING.txt +674 -0
  45. package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
  46. package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
  47. package/dist/load.d.ts +16 -0
  48. package/dist/load.js +69 -0
  49. package/dist/logo.d.ts +30 -0
  50. package/dist/logo.js +186 -0
  51. package/dist/manim.d.ts +22 -0
  52. package/dist/manim.js +19 -0
  53. package/dist/mobjects.d.ts +127 -0
  54. package/dist/mobjects.js +316 -0
  55. package/dist/pointcloud.d.ts +144 -0
  56. package/dist/pointcloud.js +400 -0
  57. package/dist/rates.d.ts +19 -0
  58. package/dist/rates.js +54 -0
  59. package/dist/run.d.ts +82 -0
  60. package/dist/run.js +245 -0
  61. package/dist/tables.d.ts +179 -0
  62. package/dist/tables.js +403 -0
  63. package/dist/tex.d.ts +8 -0
  64. package/dist/tex.js +257 -0
  65. package/dist/text-layouts.d.ts +64 -0
  66. package/dist/text-layouts.js +225 -0
  67. package/dist/text.d.ts +35 -0
  68. package/dist/text.js +52 -0
  69. package/dist/theme.d.ts +25 -0
  70. package/dist/theme.js +12 -0
  71. package/dist/user-code.d.ts +5 -0
  72. package/dist/user-code.js +20 -0
  73. package/dist/utils.d.ts +152 -0
  74. package/dist/utils.js +517 -0
  75. package/dist/vector-field.d.ts +132 -0
  76. package/dist/vector-field.js +361 -0
  77. package/package.json +46 -5
@@ -0,0 +1,127 @@
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 {};
@@ -0,0 +1,316 @@
1
+ // Manim CE's groups, points, frames, trackers and debug helpers that the engine draws with its
2
+ // own shapes: Group, VDict, VectorizedPoint, CurvesAsSubmobjects, ScreenRectangle,
3
+ // FullScreenRectangle, ComplexValueTracker, Variable, printFamily and indexLabels.
4
+ import { Animation, BLACK, DecimalNumber, FRAME_HEIGHT, Integer, MathTex, Mobject, ORIGIN, RIGHT, LEFT, Polyline, Tex, VGroup, ValueTracker, raw, wrong, } from "./engine.js";
5
+ import { AnimationGroup } from "./animations.js";
6
+ import { Rectangle } from "./geometry.js";
7
+ import { engine } from "./load.js";
8
+ /** Manim's `Group`: any mobjects as one. aula draws every mobject as vectors, so it is a VGroup. */
9
+ export function Group(...mobjects) {
10
+ return VGroup(...mobjects);
11
+ }
12
+ function entriesOf(m) {
13
+ return Symbol.iterator in m ? [...m] : Object.entries(m);
14
+ }
15
+ /** True for a Mobject or an array of them (not VDict entries). */
16
+ function isMobjects(v) {
17
+ return v instanceof Mobject || (Array.isArray(v) && v.every((x) => x instanceof Mobject));
18
+ }
19
+ /** A VGroup whose submobjects have keys: Manim's `VDict`. `get(key)` is Manim's `vdict[key]`. */
20
+ export class VDictMobject extends Mobject {
21
+ /** The submobject of each key (Manim `submob_dict`). */
22
+ submobDict = new Map();
23
+ showKeys = false;
24
+ /** Adds each entry (Manim `add`); a Mobject is added as a plain submobject. */
25
+ add(...mappingOrIterable) {
26
+ for (const item of mappingOrIterable) {
27
+ if (isMobjects(item))
28
+ super.add(item);
29
+ else
30
+ for (const [key, value] of entriesOf(item))
31
+ this.addKeyValuePair(key, value);
32
+ }
33
+ return this;
34
+ }
35
+ /** Removes the submobject of `key` (Manim `remove(key)`). A key that is not there is an error. */
36
+ remove(...key) {
37
+ for (const k of key) {
38
+ if (typeof k !== "string" && typeof k !== "number") {
39
+ super.remove(k);
40
+ continue;
41
+ }
42
+ const value = this.submobDict.get(k);
43
+ if (value === undefined)
44
+ wrong("VDict.remove", `the key ${JSON.stringify(k)} is not in the VDict`);
45
+ super.remove(value);
46
+ this.submobDict.delete(k);
47
+ }
48
+ return this;
49
+ }
50
+ /** The submobject of `key`, or undefined (Manim `vdict[key]`). */
51
+ get(key) {
52
+ return this.submobDict.get(key);
53
+ }
54
+ /** `set(key, value)` replaces the submobject of `key` (Manim `vdict[key] = value`).
55
+ * `set(attributes)` is `Mobject.set`. */
56
+ set(keyOrAttributes, value) {
57
+ if (typeof keyOrAttributes === "object")
58
+ return super.set(keyOrAttributes);
59
+ if (value === undefined)
60
+ return wrong("VDict.set", "give the value of the key");
61
+ if (this.submobDict.has(keyOrAttributes))
62
+ this.remove(keyOrAttributes);
63
+ return this.addKeyValuePair(keyOrAttributes, value);
64
+ }
65
+ has(key) {
66
+ return this.submobDict.has(key);
67
+ }
68
+ /** The values (Manim `get_all_submobjects`). */
69
+ getAllSubmobjects() {
70
+ return [...this.submobDict.values()];
71
+ }
72
+ /** Adds `value` with `key`. With `showKeys`, a `Tex` of the key goes to its left. */
73
+ addKeyValuePair(key, value) {
74
+ if (this.showKeys)
75
+ value.add(Tex(String(key)).nextTo(value, LEFT));
76
+ this.submobDict.set(key, value);
77
+ super.add(value);
78
+ return this;
79
+ }
80
+ copy() {
81
+ const c = new VDictMobject(raw(this).copy());
82
+ c.showKeys = this.showKeys;
83
+ const children = c.submobjects;
84
+ [...this.submobDict.keys()].forEach((k, i) => {
85
+ const child = children[i];
86
+ if (child !== undefined)
87
+ c.submobDict.set(k, child);
88
+ });
89
+ return c;
90
+ }
91
+ }
92
+ /** Manim's `VDict(mappingOrIterable, { showKeys })`: `VDict({ a: square, b: circle })`. */
93
+ export function VDict(mappingOrIterable = {}, opts = {}) {
94
+ const d = new VDictMobject(engine.vGroup([]));
95
+ d.showKeys = opts.showKeys ?? false;
96
+ return d.add(mappingOrIterable);
97
+ }
98
+ /** One point with a small artificial size: Manim's `VectorizedPoint`. */
99
+ export class VectorizedPointMobject extends Mobject {
100
+ artificialWidth = 0.01;
101
+ artificialHeight = 0.01;
102
+ get width() {
103
+ return this.artificialWidth;
104
+ }
105
+ set width(value) {
106
+ this.scaleToFitWidth(value);
107
+ }
108
+ get height() {
109
+ return this.artificialHeight;
110
+ }
111
+ set height(value) {
112
+ this.scaleToFitHeight(value);
113
+ }
114
+ /** The point (Manim `get_location`). */
115
+ getLocation() {
116
+ return this.getPoints()[0] ?? this.getCenter();
117
+ }
118
+ /** Moves the point to `newLoc` (Manim `set_location`). */
119
+ setLocation(newLoc) {
120
+ return this.setPoints([newLoc]);
121
+ }
122
+ copy() {
123
+ const c = new VectorizedPointMobject(raw(this).copy());
124
+ c.artificialWidth = this.artificialWidth;
125
+ c.artificialHeight = this.artificialHeight;
126
+ return c;
127
+ }
128
+ }
129
+ /** An invisible point (Manim `VectorizedPoint`): black, no fill, no stroke. */
130
+ export function VectorizedPoint(location = ORIGIN, opts = {}) {
131
+ const { artificialWidth = 0.01, artificialHeight = 0.01, color = BLACK, fillOpacity = 0, strokeWidth = 0, ...style } = opts;
132
+ const p = new VectorizedPointMobject(raw(Polyline(location, location)));
133
+ p.artificialWidth = artificialWidth;
134
+ p.artificialHeight = artificialHeight;
135
+ p.setLocation(location).setColor(color);
136
+ p.setFill(style.fillColor ?? color, { opacity: fillOpacity });
137
+ p.setStroke(style.strokeColor ?? color, { width: strokeWidth, opacity: style.strokeOpacity ?? 1 });
138
+ return p;
139
+ }
140
+ /** Each curve of a path as a submobject: Manim's `CurvesAsSubmobjects`. */
141
+ export class CurvesAsSubmobjectsMobject extends Mobject {
142
+ /** The point at `alpha` of the total arc length of the curves (Manim `point_from_proportion`). */
143
+ pointFromProportion(alpha) {
144
+ if (alpha < 0 || alpha > 1)
145
+ wrong("pointFromProportion", `alpha ${String(alpha)} is not between 0 and 1`);
146
+ const parts = this.submobjects.filter((p) => p.hasPoints());
147
+ const last = parts.at(-1);
148
+ if (last === undefined)
149
+ return wrong("pointFromProportion", "the CurvesAsSubmobjects has no curves");
150
+ if (alpha === 1)
151
+ return last.getEnd();
152
+ const lengths = parts.map(arcLength);
153
+ const target = alpha * lengths.reduce((a, b) => a + b, 0);
154
+ let run = 0;
155
+ for (const [i, part] of parts.entries()) {
156
+ const l = lengths[i] ?? 0;
157
+ if (run + l >= target)
158
+ return part.pointFromProportion(l === 0 ? 0 : (target - run) / l);
159
+ run += l;
160
+ }
161
+ return last.getEnd();
162
+ }
163
+ copy() {
164
+ return new CurvesAsSubmobjectsMobject(raw(this).copy());
165
+ }
166
+ }
167
+ /** The arc length of the own path, from 32 samples of each curve. */
168
+ function arcLength(m) {
169
+ let total = 0;
170
+ for (const [a, h1, h2, b] of m.getCubicBezierTuples()) {
171
+ let prev = a;
172
+ for (let i = 1; i <= 32; i++) {
173
+ const t = i / 32;
174
+ const u = 1 - t;
175
+ const p = [
176
+ u * u * u * a[0] + 3 * u * u * t * h1[0] + 3 * u * t * t * h2[0] + t * t * t * b[0],
177
+ u * u * u * a[1] + 3 * u * u * t * h1[1] + 3 * u * t * t * h2[1] + t * t * t * b[1],
178
+ ];
179
+ total += Math.hypot(p[0] - prev[0], p[1] - prev[1]);
180
+ prev = p;
181
+ }
182
+ }
183
+ return total;
184
+ }
185
+ /** One submobject for each cubic curve of `vmobject`, in its style (Manim `CurvesAsSubmobjects`). */
186
+ export function CurvesAsSubmobjects(vmobject) {
187
+ const group = new CurvesAsSubmobjectsMobject(engine.vGroup([]));
188
+ for (const tuple of vmobject.getCubicBezierTuples()) {
189
+ const part = Polyline(tuple[0], tuple[3]).setPoints(tuple);
190
+ part.setFill(vmobject.getFillColor(), { opacity: vmobject.getFillOpacity() });
191
+ part.setStroke(vmobject.getStrokeColor(), {
192
+ width: vmobject.getStrokeWidth(),
193
+ opacity: vmobject.getStrokeOpacity(),
194
+ });
195
+ group.add(part);
196
+ }
197
+ return group;
198
+ }
199
+ /** A rectangle with the shape of the screen: Manim's `ScreenRectangle`. */
200
+ export class ScreenRectangleMobject extends Mobject {
201
+ /** The width over the height; setting it stretches the width. */
202
+ get aspectRatio() {
203
+ return this.width / this.height;
204
+ }
205
+ set aspectRatio(value) {
206
+ this.stretchToFitWidth(value * this.height);
207
+ }
208
+ copy() {
209
+ return new ScreenRectangleMobject(raw(this).copy());
210
+ }
211
+ }
212
+ /** Manim's `ScreenRectangle({ aspectRatio, height })`: 16:9 and 4 high by default. */
213
+ export function ScreenRectangle(opts = {}) {
214
+ const { aspectRatio = 16 / 9, height = 4, ...style } = opts;
215
+ return new ScreenRectangleMobject(raw(Rectangle({ width: aspectRatio * height, height, ...style })));
216
+ }
217
+ /** A ScreenRectangle as high as the frame: Manim's `FullScreenRectangle`. */
218
+ export function FullScreenRectangle(opts = {}) {
219
+ const r = ScreenRectangle(opts);
220
+ r.height = FRAME_HEIGHT;
221
+ return r;
222
+ }
223
+ /** A complex number that animations change (Manim `ComplexValueTracker`), as `[re, im]`. */
224
+ export class ComplexValueTrackerObject {
225
+ #re;
226
+ #im;
227
+ constructor(value) {
228
+ const [re, im] = typeof value === "number" ? [value, 0] : value;
229
+ this.#re = ValueTracker(re);
230
+ this.#im = ValueTracker(im);
231
+ }
232
+ getValue() {
233
+ return [this.#re.getValue(), this.#im.getValue()];
234
+ }
235
+ setValue(value) {
236
+ const [re, im] = typeof value === "number" ? [value, 0] : value;
237
+ this.#re.setValue(re);
238
+ this.#im.setValue(im);
239
+ return this;
240
+ }
241
+ incrementValue(dValue) {
242
+ const [re, im] = typeof dValue === "number" ? [dValue, 0] : dValue;
243
+ const [a, b] = this.getValue();
244
+ return this.setValue([a + re, b + im]);
245
+ }
246
+ /** `tracker.animate.setValue(z)` and `incrementValue(dz)`, or with the animation options first. */
247
+ get animate() {
248
+ let options = {};
249
+ const both = (re, im) => AnimationGroup(re, im, options);
250
+ const methods = {
251
+ setValue: (value) => {
252
+ const [re, im] = typeof value === "number" ? [value, 0] : value;
253
+ return both(this.#re.animate.setValue(re), this.#im.animate.setValue(im));
254
+ },
255
+ incrementValue: (d) => {
256
+ const [re, im] = typeof d === "number" ? [d, 0] : d;
257
+ return both(this.#re.animate.incrementValue(re), this.#im.animate.incrementValue(im));
258
+ },
259
+ };
260
+ const call = (opts) => {
261
+ options = opts;
262
+ return methods;
263
+ };
264
+ return Object.assign(call, methods);
265
+ }
266
+ }
267
+ /** Manim's `ComplexValueTracker(value)`, with `[re, im]` for a complex number. */
268
+ export function ComplexValueTracker(value = 0) {
269
+ return new ComplexValueTrackerObject(value);
270
+ }
271
+ /** A label, `=` and a number that follows a tracker: Manim's `Variable`. */
272
+ export class VariableMobject extends Mobject {
273
+ /** The label with its `=` (Manim `label`). */
274
+ label;
275
+ /** The number (Manim `value`). */
276
+ value;
277
+ /** The tracker that the number follows (Manim `tracker`). */
278
+ tracker;
279
+ constructor(handle, label, value, tracker) {
280
+ super(handle);
281
+ this.label = label;
282
+ this.value = value;
283
+ this.tracker = tracker;
284
+ }
285
+ }
286
+ /** Manim's `Variable(var, label, { varType, numDecimalPlaces })`: a string label is a `MathTex`.
287
+ * Change `variable.tracker` to change the number. */
288
+ export function Variable(variable, label, opts = {}) {
289
+ const { varType = DecimalNumber, numDecimalPlaces = 2 } = opts;
290
+ const labelMob = typeof label === "string" ? MathTex(label) : label;
291
+ labelMob.add(MathTex("=").nextTo(labelMob, RIGHT));
292
+ const tracker = ValueTracker(variable);
293
+ const value = varType === Integer ? Integer(tracker.getValue()) : DecimalNumber(tracker.getValue(), { numDecimalPlaces });
294
+ value.addUpdater((v) => v.setValue(tracker.getValue())).nextTo(labelMob, RIGHT);
295
+ return new VariableMobject(engine.vGroup([raw(labelMob), raw(value)]), labelMob, value, tracker);
296
+ }
297
+ /** The tree of `mobject`, one line for each node, indented by depth (Manim `print_family`).
298
+ * aula returns the text: print it with `console.log`. */
299
+ export function printFamily(mobject, nTabs = 0) {
300
+ const name = mobject.constructor.name;
301
+ const own = `${"\t".repeat(nTabs)} ${name} ${String(mobject.id())}`;
302
+ return [own, ...mobject.submobjects.map((s) => printFamily(s, nTabs + 1))].join("\n");
303
+ }
304
+ /** An `Integer` on each submobject, with its index (Manim `index_labels`). Each label is a
305
+ * VGroup of an outline in `backgroundStrokeColor` and the Integer. */
306
+ export function indexLabels(mobject, opts = {}) {
307
+ const { labelHeight = 0.15, backgroundStrokeWidth = 5, backgroundStrokeColor = BLACK, ...rest } = opts;
308
+ const labels = mobject.submobjects.map((submob, n) => {
309
+ const label = Integer(n, rest);
310
+ label.height = labelHeight;
311
+ label.moveTo(submob);
312
+ const outline = label.copy().setStroke(backgroundStrokeColor, { width: backgroundStrokeWidth });
313
+ return VGroup(outline, label);
314
+ });
315
+ return VGroup(labels);
316
+ }
@@ -0,0 +1,144 @@
1
+ import { type Color, type Point as EnginePoint, Mobject } from "./engine.ts";
2
+ import { type ParsableManimColor } from "./colors.ts";
3
+ /** A point: `[x, y]`. `m.Point(location)` is also Manim's one-point cloud. */
4
+ export type Point = EnginePoint;
5
+ /** `[r, g, b, a]`, each from 0 to 1. */
6
+ type Rgba = [number, number, number, number];
7
+ /** A cloud of points: Manim's `PMobject`. Its submobjects are the colour runs of its own
8
+ * points (the nodes of the squares), then the clouds that `add` gives it. */
9
+ export declare class PMobjectMobject extends Mobject {
10
+ #private;
11
+ /** The colour of new points (Manim `color`). */
12
+ color: Color;
13
+ copy(): PMobjectMobject;
14
+ /** Gives `to`, a copy of the node, the settings of this cloud. */
15
+ protected copyCloud<T extends PMobjectMobject>(to: T): T;
16
+ /** Removes the own points (Manim `reset_points`). */
17
+ resetPoints(): this;
18
+ /** The names of the arrays of a point cloud (Manim `get_array_attrs`). */
19
+ getArrayAttrs(): string[];
20
+ /** Adds points, in `color` with opacity `alpha`, or one `[r, g, b, a]` each (Manim `add_points`). */
21
+ addPoints(points: readonly Point[], opts?: {
22
+ rgbas?: readonly (readonly number[])[];
23
+ color?: ParsableManimColor;
24
+ alpha?: number;
25
+ }): this;
26
+ /** Gives every point `color` (Manim `set_color`); with `family` (true) also the sub-clouds. */
27
+ setColor(color?: ParsableManimColor, opts?: {
28
+ alpha?: number;
29
+ family?: boolean;
30
+ }): this;
31
+ /** The size of a point, in pixels of a 1080-pixel-high frame. */
32
+ getStrokeWidth(): number;
33
+ /** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
34
+ * sub-clouds. */
35
+ setStrokeWidth(width: number, family?: boolean): this;
36
+ /** Spreads `colors` over the points in order (Manim `set_color_by_gradient`). */
37
+ setColorByGradient(...colors: ParsableManimColor[]): this;
38
+ /** Colours the points from `innerColor` at `center` to `outerColor` at `radius` (Manim
39
+ * `set_colors_by_radial_gradient`). */
40
+ setColorsByRadialGradient(opts?: {
41
+ center?: Point;
42
+ radius?: number;
43
+ innerColor?: ParsableManimColor;
44
+ outerColor?: ParsableManimColor;
45
+ }): this;
46
+ /** Takes the colours of the points of `mobject`, in order (Manim `match_colors`). */
47
+ matchColors(mobject: Mobject): this;
48
+ /** Removes the points where `condition` is true (Manim `filter_out`). */
49
+ filterOut(condition: (p: Point) => boolean): this;
50
+ /** Keeps every `factor`-th point (Manim `thin_out`). */
51
+ thinOut(factor?: number): this;
52
+ /** Orders the points by `f` (Manim `sort_points`; by x by default). */
53
+ sortPoints(f?: (p: Point) => number): this;
54
+ /** Moves the colours `alpha` of the way to `color` (Manim `fade_to`). */
55
+ fadeTo(color: ParsableManimColor, alpha: number, opts?: {
56
+ family?: boolean;
57
+ }): this;
58
+ /** The colours of the points of the cloud and its sub-clouds (Manim `get_all_rgbas`). */
59
+ getAllRgbas(): Rgba[];
60
+ /** Takes the points of the sub-clouds as its own, and removes the sub-clouds (Manim
61
+ * `ingest_submobjects`). */
62
+ ingestSubmobjects(): this;
63
+ /** The colour of the first point (Manim `get_color`). */
64
+ getColor(): Color;
65
+ /** The point at `alpha` of the list of points (Manim `point_from_proportion`). */
66
+ pointFromProportion(alpha: number): Point;
67
+ /** `m.PMobject` (Manim `get_mobject_type_class`). */
68
+ getMobjectTypeClass(): typeof PMobject;
69
+ /** Repeats points until the cloud has as many as `largerMobject` (Manim
70
+ * `align_points_with_larger`). */
71
+ alignPointsWithLarger(largerMobject: Mobject): this;
72
+ /** A one-point cloud at `center` (Manim `get_point_mobject`). */
73
+ getPointMobject(center?: Point): PointMobject;
74
+ /** Takes colours and point size `alpha` of the way from `mobject1` to `mobject2` (Manim
75
+ * `interpolate_color`). */
76
+ interpolateColor(mobject1: Mobject, mobject2: Mobject, alpha: number): this;
77
+ /** Becomes the points of `mobject` from proportion `a` to `b` (Manim
78
+ * `pointwise_become_partial`). */
79
+ pointwiseBecomePartial(mobject: Mobject, a: number, b: number): this;
80
+ }
81
+ /** The options of a point cloud (Manim's keyword arguments). */
82
+ export interface PMobjectOptions {
83
+ /** The size of a point, in pixels of a 1080-pixel-high frame (default 4). */
84
+ strokeWidth?: number;
85
+ /** The colour of new points (default white). */
86
+ color?: ParsableManimColor;
87
+ }
88
+ /** An empty point cloud (Manim `PMobject`): add points with `addPoints`. */
89
+ export declare function PMobject(opts?: PMobjectOptions): PMobjectMobject;
90
+ /** A point cloud of lines (Manim `Mobject1D`): `addLine` puts `density` points on each unit. */
91
+ export declare class Mobject1DMobject extends PMobjectMobject {
92
+ density: number;
93
+ get epsilon(): number;
94
+ copy(): Mobject1DMobject;
95
+ /** Adds the points of the line from `start` to `end`, `density` on each unit (Manim `add_line`). */
96
+ addLine(start: Point, end: Point, color?: ParsableManimColor): this;
97
+ }
98
+ /** `Mobject1D({ density })` (Manim; default density 10). */
99
+ export declare function Mobject1D(opts?: PMobjectOptions & {
100
+ density?: number;
101
+ }): Mobject1DMobject;
102
+ /** A point cloud of areas (Manim `Mobject2D`). */
103
+ export declare class Mobject2DMobject extends PMobjectMobject {
104
+ density: number;
105
+ copy(): Mobject2DMobject;
106
+ get epsilon(): number;
107
+ }
108
+ /** `Mobject2D({ density })` (Manim; default density 25). */
109
+ export declare function Mobject2D(opts?: PMobjectOptions & {
110
+ density?: number;
111
+ }): Mobject2DMobject;
112
+ /** Point clouds as one (Manim `PGroup`): `PGroup(cloud1, cloud2, opts)`. */
113
+ export declare function PGroup(...args: (PMobjectMobject | PMobjectOptions)[]): PMobjectMobject;
114
+ /** A disc of points (Manim `PointCloudDot`): rings every `1 / density` up to `radius`. */
115
+ export declare class PointCloudDotMobject extends Mobject1DMobject {
116
+ #private;
117
+ radius: number;
118
+ copy(): PointCloudDotMobject;
119
+ /** Makes the points again (Manim `init_points`). */
120
+ initPoints(): this;
121
+ /** Adds the rings of points about the centre (Manim `generate_points`). */
122
+ generatePoints(): this;
123
+ /** The centre for `generatePoints`. */
124
+ setGenerationCenter(center: Point): this;
125
+ }
126
+ /** `PointCloudDot({ center, radius, strokeWidth, density, color })` (Manim; defaults
127
+ * `ORIGIN`, 2, 2, 10 and `PURE_YELLOW`). */
128
+ export declare function PointCloudDot(opts?: PMobjectOptions & {
129
+ center?: Point;
130
+ radius?: number;
131
+ density?: number;
132
+ }): PointCloudDotMobject;
133
+ /** A cloud of one point (Manim `Point`). */
134
+ export declare class PointMobject extends PMobjectMobject {
135
+ location: Point;
136
+ copy(): PointMobject;
137
+ /** Makes the point again (Manim `init_points`). */
138
+ initPoints(): this;
139
+ /** Adds the point at `location` (Manim `generate_points`). */
140
+ generatePoints(): this;
141
+ }
142
+ /** `Point(location, { color })` (Manim; defaults `ORIGIN` and `BLACK`). */
143
+ export declare function Point(location?: Point, opts?: PMobjectOptions): PointMobject;
144
+ export {};