Repository navigation
Expand file tree
/
Copy pathplugin.mjs
More file actions
80 lines (73 loc) · 1.94 KB
/
Copy pathplugin.mjs
File metadata and controls
80 lines (73 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* MyST plugin: manim-web
*
* Registers the `manim` directive. At build time it emits an anywidget node
* that carries the user's animation code and canvas options as model data.
* The browser-side widget (widget.mjs) picks those up and runs manim-web.
*
* Usage:
*
* :::{manim}
* :width: 800
* :height: 450
* :background-color: '#1e1e2e'
*
* const circle = new Circle({ color: RED, fillOpacity: 0.3 });
* scene.add(circle);
* await scene.play(new Create(circle));
* await scene.wait(1);
* await scene.play(new FadeOut(circle));
* :::
*/
const manimDirective = {
name: 'manim',
doc: `Embed an interactive manim-web animation.
Write only the animation body — \`scene\` and all manim-web exports
(shapes, animations, colors, rate-functions) are already in scope.`,
body: {
type: String,
required: true,
doc: 'Animation code. `scene` plus all manim-web exports are pre-imported.',
},
options: {
width: {
type: Number,
doc: 'Canvas width in pixels (default: 800).',
},
height: {
type: Number,
doc: 'Canvas height in pixels (default: 450).',
},
'background-color': {
type: String,
doc: "Background color as a CSS hex string, e.g. '#1e1e2e' (default: '#000000').",
},
scene: {
type: String,
doc: "Scene class to use: 'Scene' (default) or 'ThreeDScene' for 3D with orbit controls.",
},
},
run(data) {
const { body, options } = data;
return [
{
type: 'anywidget',
esm: './widget.mjs',
model: {
code: body,
width: options?.width ?? 800,
height: options?.height ?? 450,
backgroundColor: options?.['background-color'] ?? '#000000',
sceneType: options?.scene ?? 'Scene',
},
},
];
},
};
const plugin = {
name: 'manim-web',
author: 'myst-manim-extension',
license: 'MIT',
directives: [manimDirective],
};
export default plugin;