@redwilly/anima 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 (239) hide show
  1. package/dist/cli/SceneLoader.d.ts +22 -0
  2. package/dist/cli/SceneLoader.js +47 -0
  3. package/dist/cli/commands/export-frame.d.ts +13 -0
  4. package/dist/cli/commands/export-frame.js +60 -0
  5. package/dist/cli/commands/list-scenes.d.ts +5 -0
  6. package/dist/cli/commands/list-scenes.js +22 -0
  7. package/dist/cli/commands/preview.d.ts +5 -0
  8. package/dist/cli/commands/preview.js +11 -0
  9. package/dist/cli/commands/render.d.ts +16 -0
  10. package/dist/cli/commands/render.js +76 -0
  11. package/dist/cli/index.d.ts +2 -0
  12. package/dist/cli/index.js +63 -0
  13. package/dist/core/animations/Animation.d.ts +41 -0
  14. package/dist/core/animations/Animation.js +76 -0
  15. package/dist/core/animations/camera/Follow.d.ts +70 -0
  16. package/dist/core/animations/camera/Follow.js +69 -0
  17. package/dist/core/animations/camera/Shake.d.ts +90 -0
  18. package/dist/core/animations/camera/Shake.js +87 -0
  19. package/dist/core/animations/camera/index.d.ts +2 -0
  20. package/dist/core/animations/camera/index.js +2 -0
  21. package/dist/core/animations/categories/ExitAnimation.d.ts +17 -0
  22. package/dist/core/animations/categories/ExitAnimation.js +15 -0
  23. package/dist/core/animations/categories/IntroductoryAnimation.d.ts +16 -0
  24. package/dist/core/animations/categories/IntroductoryAnimation.js +14 -0
  25. package/dist/core/animations/categories/TransformativeAnimation.d.ts +25 -0
  26. package/dist/core/animations/categories/TransformativeAnimation.js +25 -0
  27. package/dist/core/animations/categories/index.d.ts +3 -0
  28. package/dist/core/animations/categories/index.js +3 -0
  29. package/dist/core/animations/composition/Parallel.d.ts +37 -0
  30. package/dist/core/animations/composition/Parallel.js +79 -0
  31. package/dist/core/animations/composition/Sequence.d.ts +41 -0
  32. package/dist/core/animations/composition/Sequence.js +95 -0
  33. package/dist/core/animations/composition/index.d.ts +2 -0
  34. package/dist/core/animations/composition/index.js +3 -0
  35. package/dist/core/animations/draw/Draw.d.ts +30 -0
  36. package/dist/core/animations/draw/Draw.js +122 -0
  37. package/dist/core/animations/draw/Unwrite.d.ts +30 -0
  38. package/dist/core/animations/draw/Unwrite.js +120 -0
  39. package/dist/core/animations/draw/Write.d.ts +35 -0
  40. package/dist/core/animations/draw/Write.js +119 -0
  41. package/dist/core/animations/draw/index.d.ts +3 -0
  42. package/dist/core/animations/draw/index.js +3 -0
  43. package/dist/core/animations/draw/partialPath.d.ts +6 -0
  44. package/dist/core/animations/draw/partialPath.js +138 -0
  45. package/dist/core/animations/easing/bounce.d.ts +13 -0
  46. package/dist/core/animations/easing/bounce.js +37 -0
  47. package/dist/core/animations/easing/index.d.ts +7 -0
  48. package/dist/core/animations/easing/index.js +11 -0
  49. package/dist/core/animations/easing/manim.d.ts +46 -0
  50. package/dist/core/animations/easing/manim.js +102 -0
  51. package/dist/core/animations/easing/registry.d.ts +8 -0
  52. package/dist/core/animations/easing/registry.js +25 -0
  53. package/dist/core/animations/easing/standard.d.ts +113 -0
  54. package/dist/core/animations/easing/standard.js +151 -0
  55. package/dist/core/animations/easing/types.d.ts +6 -0
  56. package/dist/core/animations/easing/types.js +0 -0
  57. package/dist/core/animations/fade/FadeIn.d.ts +17 -0
  58. package/dist/core/animations/fade/FadeIn.js +22 -0
  59. package/dist/core/animations/fade/FadeOut.d.ts +17 -0
  60. package/dist/core/animations/fade/FadeOut.js +23 -0
  61. package/dist/core/animations/fade/index.d.ts +2 -0
  62. package/dist/core/animations/fade/index.js +2 -0
  63. package/dist/core/animations/index.d.ts +11 -0
  64. package/dist/core/animations/index.js +17 -0
  65. package/dist/core/animations/keyframes/KeyframeAnimation.d.ts +33 -0
  66. package/dist/core/animations/keyframes/KeyframeAnimation.js +40 -0
  67. package/dist/core/animations/keyframes/KeyframeTrack.d.ts +31 -0
  68. package/dist/core/animations/keyframes/KeyframeTrack.js +83 -0
  69. package/dist/core/animations/keyframes/index.d.ts +4 -0
  70. package/dist/core/animations/keyframes/index.js +5 -0
  71. package/dist/core/animations/keyframes/types.d.ts +25 -0
  72. package/dist/core/animations/keyframes/types.js +6 -0
  73. package/dist/core/animations/morph/MorphTo.d.ts +22 -0
  74. package/dist/core/animations/morph/MorphTo.js +42 -0
  75. package/dist/core/animations/morph/index.d.ts +1 -0
  76. package/dist/core/animations/morph/index.js +1 -0
  77. package/dist/core/animations/transform/MoveTo.d.ts +24 -0
  78. package/dist/core/animations/transform/MoveTo.js +38 -0
  79. package/dist/core/animations/transform/Rotate.d.ts +23 -0
  80. package/dist/core/animations/transform/Rotate.js +34 -0
  81. package/dist/core/animations/transform/Scale.d.ts +23 -0
  82. package/dist/core/animations/transform/Scale.js +35 -0
  83. package/dist/core/animations/transform/index.d.ts +3 -0
  84. package/dist/core/animations/transform/index.js +3 -0
  85. package/dist/core/animations/types.d.ts +52 -0
  86. package/dist/core/animations/types.js +6 -0
  87. package/dist/core/camera/Camera.d.ts +87 -0
  88. package/dist/core/camera/Camera.js +175 -0
  89. package/dist/core/camera/CameraFrame.d.ts +242 -0
  90. package/dist/core/camera/CameraFrame.js +322 -0
  91. package/dist/core/camera/index.d.ts +4 -0
  92. package/dist/core/camera/index.js +3 -0
  93. package/dist/core/camera/types.d.ts +17 -0
  94. package/dist/core/camera/types.js +1 -0
  95. package/dist/core/errors/AnimationErrors.d.ts +12 -0
  96. package/dist/core/errors/AnimationErrors.js +37 -0
  97. package/dist/core/errors/index.d.ts +1 -0
  98. package/dist/core/errors/index.js +1 -0
  99. package/dist/core/math/Vector2/Vector2.d.ts +23 -0
  100. package/dist/core/math/Vector2/Vector2.js +46 -0
  101. package/dist/core/math/Vector2/index.d.ts +1 -0
  102. package/dist/core/math/Vector2/index.js +1 -0
  103. package/dist/core/math/bezier/BezierPath.d.ts +38 -0
  104. package/dist/core/math/bezier/BezierPath.js +264 -0
  105. package/dist/core/math/bezier/evaluators.d.ts +9 -0
  106. package/dist/core/math/bezier/evaluators.js +36 -0
  107. package/dist/core/math/bezier/index.d.ts +8 -0
  108. package/dist/core/math/bezier/index.js +6 -0
  109. package/dist/core/math/bezier/length.d.ts +5 -0
  110. package/dist/core/math/bezier/length.js +27 -0
  111. package/dist/core/math/bezier/morphing.d.ts +16 -0
  112. package/dist/core/math/bezier/morphing.js +151 -0
  113. package/dist/core/math/bezier/sampling.d.ts +7 -0
  114. package/dist/core/math/bezier/sampling.js +153 -0
  115. package/dist/core/math/bezier/split.d.ts +19 -0
  116. package/dist/core/math/bezier/split.js +44 -0
  117. package/dist/core/math/bezier/types.d.ts +8 -0
  118. package/dist/core/math/bezier/types.js +0 -0
  119. package/dist/core/math/color/Color.d.ts +28 -0
  120. package/dist/core/math/color/Color.js +60 -0
  121. package/dist/core/math/color/conversions.d.ts +17 -0
  122. package/dist/core/math/color/conversions.js +100 -0
  123. package/dist/core/math/color/index.d.ts +2 -0
  124. package/dist/core/math/color/index.js +2 -0
  125. package/dist/core/math/index.d.ts +4 -0
  126. package/dist/core/math/index.js +5 -0
  127. package/dist/core/math/matrix/Matrix3x3.d.ts +23 -0
  128. package/dist/core/math/matrix/Matrix3x3.js +91 -0
  129. package/dist/core/math/matrix/factories.d.ts +12 -0
  130. package/dist/core/math/matrix/factories.js +44 -0
  131. package/dist/core/math/matrix/index.d.ts +2 -0
  132. package/dist/core/math/matrix/index.js +2 -0
  133. package/dist/core/renderer/FrameRenderer.d.ts +37 -0
  134. package/dist/core/renderer/FrameRenderer.js +75 -0
  135. package/dist/core/renderer/ProgressReporter.d.ts +19 -0
  136. package/dist/core/renderer/ProgressReporter.js +58 -0
  137. package/dist/core/renderer/Renderer.d.ts +36 -0
  138. package/dist/core/renderer/Renderer.js +102 -0
  139. package/dist/core/renderer/drawMobject.d.ts +8 -0
  140. package/dist/core/renderer/drawMobject.js +109 -0
  141. package/dist/core/renderer/formats/index.d.ts +3 -0
  142. package/dist/core/renderer/formats/index.js +3 -0
  143. package/dist/core/renderer/formats/png.d.ts +5 -0
  144. package/dist/core/renderer/formats/png.js +7 -0
  145. package/dist/core/renderer/formats/sprite.d.ts +6 -0
  146. package/dist/core/renderer/formats/sprite.js +24 -0
  147. package/dist/core/renderer/formats/video.d.ts +8 -0
  148. package/dist/core/renderer/formats/video.js +51 -0
  149. package/dist/core/renderer/index.d.ts +7 -0
  150. package/dist/core/renderer/index.js +9 -0
  151. package/dist/core/renderer/types.d.ts +87 -0
  152. package/dist/core/renderer/types.js +13 -0
  153. package/dist/core/scene/Scene.d.ts +104 -0
  154. package/dist/core/scene/Scene.js +225 -0
  155. package/dist/core/scene/index.d.ts +2 -0
  156. package/dist/core/scene/index.js +1 -0
  157. package/dist/core/scene/types.d.ts +23 -0
  158. package/dist/core/scene/types.js +0 -0
  159. package/dist/core/serialization/animation.d.ts +23 -0
  160. package/dist/core/serialization/animation.js +176 -0
  161. package/dist/core/serialization/easingLookup.d.ts +13 -0
  162. package/dist/core/serialization/easingLookup.js +65 -0
  163. package/dist/core/serialization/index.d.ts +23 -0
  164. package/dist/core/serialization/index.js +29 -0
  165. package/dist/core/serialization/mobject.d.ts +23 -0
  166. package/dist/core/serialization/mobject.js +248 -0
  167. package/dist/core/serialization/prettyPrint.d.ts +12 -0
  168. package/dist/core/serialization/prettyPrint.js +16 -0
  169. package/dist/core/serialization/primitives.d.ts +24 -0
  170. package/dist/core/serialization/primitives.js +98 -0
  171. package/dist/core/serialization/registry.d.ts +29 -0
  172. package/dist/core/serialization/registry.js +39 -0
  173. package/dist/core/serialization/scene.d.ts +28 -0
  174. package/dist/core/serialization/scene.js +114 -0
  175. package/dist/core/serialization/types.d.ts +152 -0
  176. package/dist/core/serialization/types.js +6 -0
  177. package/dist/core/timeline/Timeline.d.ts +70 -0
  178. package/dist/core/timeline/Timeline.js +144 -0
  179. package/dist/core/timeline/index.d.ts +5 -0
  180. package/dist/core/timeline/index.js +4 -0
  181. package/dist/core/timeline/types.d.ts +29 -0
  182. package/dist/core/timeline/types.js +0 -0
  183. package/dist/index.d.ts +18 -0
  184. package/dist/index.js +22 -0
  185. package/dist/mobjects/Mobject.d.ts +98 -0
  186. package/dist/mobjects/Mobject.js +343 -0
  187. package/dist/mobjects/VGroup/VGroup.d.ts +51 -0
  188. package/dist/mobjects/VGroup/VGroup.js +142 -0
  189. package/dist/mobjects/VGroup/index.d.ts +3 -0
  190. package/dist/mobjects/VGroup/index.js +2 -0
  191. package/dist/mobjects/VGroup/layout.d.ts +20 -0
  192. package/dist/mobjects/VGroup/layout.js +139 -0
  193. package/dist/mobjects/VMobject.d.ts +106 -0
  194. package/dist/mobjects/VMobject.js +216 -0
  195. package/dist/mobjects/geometry/Arc.d.ts +8 -0
  196. package/dist/mobjects/geometry/Arc.js +46 -0
  197. package/dist/mobjects/geometry/Arrow.d.ts +7 -0
  198. package/dist/mobjects/geometry/Arrow.js +34 -0
  199. package/dist/mobjects/geometry/Circle.d.ts +4 -0
  200. package/dist/mobjects/geometry/Circle.js +10 -0
  201. package/dist/mobjects/geometry/Line.d.ts +8 -0
  202. package/dist/mobjects/geometry/Line.js +19 -0
  203. package/dist/mobjects/geometry/Point.d.ts +5 -0
  204. package/dist/mobjects/geometry/Point.js +11 -0
  205. package/dist/mobjects/geometry/Polygon.d.ts +7 -0
  206. package/dist/mobjects/geometry/Polygon.js +21 -0
  207. package/dist/mobjects/geometry/Rectangle.d.ts +6 -0
  208. package/dist/mobjects/geometry/Rectangle.js +18 -0
  209. package/dist/mobjects/geometry/index.d.ts +7 -0
  210. package/dist/mobjects/geometry/index.js +7 -0
  211. package/dist/mobjects/graph/Graph.d.ts +28 -0
  212. package/dist/mobjects/graph/Graph.js +119 -0
  213. package/dist/mobjects/graph/GraphEdge.d.ts +26 -0
  214. package/dist/mobjects/graph/GraphEdge.js +64 -0
  215. package/dist/mobjects/graph/GraphNode.d.ts +19 -0
  216. package/dist/mobjects/graph/GraphNode.js +63 -0
  217. package/dist/mobjects/graph/index.d.ts +5 -0
  218. package/dist/mobjects/graph/index.js +5 -0
  219. package/dist/mobjects/graph/layouts/circular.d.ts +8 -0
  220. package/dist/mobjects/graph/layouts/circular.js +23 -0
  221. package/dist/mobjects/graph/layouts/forceDirected.d.ts +9 -0
  222. package/dist/mobjects/graph/layouts/forceDirected.js +102 -0
  223. package/dist/mobjects/graph/layouts/index.d.ts +3 -0
  224. package/dist/mobjects/graph/layouts/index.js +3 -0
  225. package/dist/mobjects/graph/layouts/tree.d.ts +9 -0
  226. package/dist/mobjects/graph/layouts/tree.js +99 -0
  227. package/dist/mobjects/graph/types.d.ts +35 -0
  228. package/dist/mobjects/graph/types.js +0 -0
  229. package/dist/mobjects/index.d.ts +6 -0
  230. package/dist/mobjects/index.js +6 -0
  231. package/dist/mobjects/text/Glyph.d.ts +11 -0
  232. package/dist/mobjects/text/Glyph.js +72 -0
  233. package/dist/mobjects/text/Text.d.ts +19 -0
  234. package/dist/mobjects/text/Text.js +76 -0
  235. package/dist/mobjects/text/index.d.ts +4 -0
  236. package/dist/mobjects/text/index.js +3 -0
  237. package/dist/mobjects/text/types.d.ts +12 -0
  238. package/dist/mobjects/text/types.js +8 -0
  239. package/package.json +51 -0
@@ -0,0 +1,90 @@
1
+ import { TransformativeAnimation } from '../categories';
2
+ import { CameraFrame } from '../../camera/CameraFrame';
3
+ /**
4
+ * Configuration options for the Shake animation.
5
+ */
6
+ interface ShakeConfig {
7
+ /**
8
+ * Maximum displacement distance in world units.
9
+ * Higher values create more violent shaking.
10
+ * @default 0.2
11
+ */
12
+ intensity?: number;
13
+ /**
14
+ * Number of oscillations per second.
15
+ * Higher values create faster, more frantic shaking.
16
+ * @default 10
17
+ */
18
+ frequency?: number;
19
+ /**
20
+ * Controls how quickly the shake diminishes over time.
21
+ * - 0 = no decay (constant intensity throughout)
22
+ * - 1 = linear decay
23
+ * - Higher values = faster decay (shake fades quickly)
24
+ * @default 1
25
+ */
26
+ decay?: number;
27
+ }
28
+ /**
29
+ * Camera shake effect animation.
30
+ * Creates procedural displacement using layered sine waves to simulate
31
+ * impacts, explosions, or earthquakes.
32
+ *
33
+ * The shake automatically returns to the original position when complete.
34
+ *
35
+ * @example
36
+ * // Basic shake effect
37
+ * this.play(new Shake(this.frame).duration(0.5));
38
+ *
39
+ * @example
40
+ * // Intense explosion shake with quick decay
41
+ * this.play(new Shake(this.frame, {
42
+ * intensity: 0.5,
43
+ * frequency: 20,
44
+ * decay: 2
45
+ * }).duration(0.3));
46
+ *
47
+ * @example
48
+ * // Subtle earthquake with slow decay
49
+ * this.play(new Shake(this.frame, {
50
+ * intensity: 0.1,
51
+ * frequency: 5,
52
+ * decay: 0.5
53
+ * }).duration(3));
54
+ */
55
+ export declare class Shake extends TransformativeAnimation<CameraFrame> {
56
+ private originalPosition;
57
+ private readonly intensity;
58
+ private readonly frequency;
59
+ private readonly decay;
60
+ private readonly seedX;
61
+ private readonly seedY;
62
+ /**
63
+ * Creates a new Shake animation.
64
+ *
65
+ * @param frame - The CameraFrame to shake
66
+ * @param config - Configuration options for intensity, frequency, and decay
67
+ *
68
+ * @example
69
+ * const shake = new Shake(scene.frame, { intensity: 0.3 });
70
+ * this.play(shake.duration(0.5));
71
+ */
72
+ constructor(frame: CameraFrame, config?: ShakeConfig);
73
+ /**
74
+ * Captures the original position before shake begins.
75
+ */
76
+ protected captureStartState(): void;
77
+ /**
78
+ * Applies procedural shake displacement each frame.
79
+ * @param progress - Animation progress (0 to 1)
80
+ */
81
+ interpolate(progress: number): void;
82
+ /**
83
+ * Generates pseudo-random noise using layered sine waves.
84
+ * @param t - Time value
85
+ * @param seed - Random seed for variation
86
+ * @returns Noise value between -1 and 1
87
+ */
88
+ private noise;
89
+ }
90
+ export {};
@@ -0,0 +1,87 @@
1
+ import { TransformativeAnimation } from '../categories';
2
+ /**
3
+ * Camera shake effect animation.
4
+ * Creates procedural displacement using layered sine waves to simulate
5
+ * impacts, explosions, or earthquakes.
6
+ *
7
+ * The shake automatically returns to the original position when complete.
8
+ *
9
+ * @example
10
+ * // Basic shake effect
11
+ * this.play(new Shake(this.frame).duration(0.5));
12
+ *
13
+ * @example
14
+ * // Intense explosion shake with quick decay
15
+ * this.play(new Shake(this.frame, {
16
+ * intensity: 0.5,
17
+ * frequency: 20,
18
+ * decay: 2
19
+ * }).duration(0.3));
20
+ *
21
+ * @example
22
+ * // Subtle earthquake with slow decay
23
+ * this.play(new Shake(this.frame, {
24
+ * intensity: 0.1,
25
+ * frequency: 5,
26
+ * decay: 0.5
27
+ * }).duration(3));
28
+ */
29
+ export class Shake extends TransformativeAnimation {
30
+ originalPosition;
31
+ intensity;
32
+ frequency;
33
+ decay;
34
+ seedX;
35
+ seedY;
36
+ /**
37
+ * Creates a new Shake animation.
38
+ *
39
+ * @param frame - The CameraFrame to shake
40
+ * @param config - Configuration options for intensity, frequency, and decay
41
+ *
42
+ * @example
43
+ * const shake = new Shake(scene.frame, { intensity: 0.3 });
44
+ * this.play(shake.duration(0.5));
45
+ */
46
+ constructor(frame, config = {}) {
47
+ super(frame);
48
+ this.intensity = config.intensity ?? 0.2;
49
+ this.frequency = config.frequency ?? 10;
50
+ this.decay = config.decay ?? 1;
51
+ this.seedX = Math.random() * 1000;
52
+ this.seedY = Math.random() * 1000;
53
+ }
54
+ /**
55
+ * Captures the original position before shake begins.
56
+ */
57
+ captureStartState() {
58
+ this.originalPosition = this.target.position;
59
+ }
60
+ /**
61
+ * Applies procedural shake displacement each frame.
62
+ * @param progress - Animation progress (0 to 1)
63
+ */
64
+ interpolate(progress) {
65
+ this.ensureInitialized();
66
+ if (progress >= 1) {
67
+ this.target.pos(this.originalPosition.x, this.originalPosition.y);
68
+ return;
69
+ }
70
+ const decayFactor = 1 - Math.pow(progress, this.decay);
71
+ const time = progress * this.durationSeconds * this.frequency;
72
+ const offsetX = this.noise(time, this.seedX) * this.intensity * decayFactor;
73
+ const offsetY = this.noise(time, this.seedY) * this.intensity * decayFactor;
74
+ this.target.pos(this.originalPosition.x + offsetX, this.originalPosition.y + offsetY);
75
+ }
76
+ /**
77
+ * Generates pseudo-random noise using layered sine waves.
78
+ * @param t - Time value
79
+ * @param seed - Random seed for variation
80
+ * @returns Noise value between -1 and 1
81
+ */
82
+ noise(t, seed) {
83
+ return Math.sin(t * 2 + seed) * 0.5 +
84
+ Math.sin(t * 3.7 + seed * 1.3) * 0.3 +
85
+ Math.sin(t * 7.1 + seed * 0.7) * 0.2;
86
+ }
87
+ }
@@ -0,0 +1,2 @@
1
+ export { Follow } from './Follow';
2
+ export { Shake } from './Shake';
@@ -0,0 +1,2 @@
1
+ export { Follow } from './Follow';
2
+ export { Shake } from './Shake';
@@ -0,0 +1,17 @@
1
+ import { Animation } from '../Animation';
2
+ import type { AnimationLifecycle } from '../types';
3
+ import type { Mobject } from '../../../mobjects/Mobject';
4
+ /**
5
+ * Abstract base class for animations that exit/remove an object from the scene.
6
+ *
7
+ * Exit animations:
8
+ * - Require the target to already be registered with the scene
9
+ * - Throw an error if the target is not in the scene
10
+ * - Typically animate opacity or scale to 0
11
+ * - May optionally auto-remove the target from the scene after completion
12
+ *
13
+ * Examples: FadeOut, ShrinkToCenter, Uncreate
14
+ */
15
+ export declare abstract class ExitAnimation<T extends Mobject = Mobject> extends Animation<T> {
16
+ readonly lifecycle: AnimationLifecycle;
17
+ }
@@ -0,0 +1,15 @@
1
+ import { Animation } from '../Animation';
2
+ /**
3
+ * Abstract base class for animations that exit/remove an object from the scene.
4
+ *
5
+ * Exit animations:
6
+ * - Require the target to already be registered with the scene
7
+ * - Throw an error if the target is not in the scene
8
+ * - Typically animate opacity or scale to 0
9
+ * - May optionally auto-remove the target from the scene after completion
10
+ *
11
+ * Examples: FadeOut, ShrinkToCenter, Uncreate
12
+ */
13
+ export class ExitAnimation extends Animation {
14
+ lifecycle = 'exit';
15
+ }
@@ -0,0 +1,16 @@
1
+ import { Animation } from '../Animation';
2
+ import type { AnimationLifecycle } from '../types';
3
+ import type { Mobject } from '../../../mobjects/Mobject';
4
+ /**
5
+ * Abstract base class for animations that introduce an object to the scene.
6
+ *
7
+ * Introductory animations:
8
+ * - Automatically register the target with the scene if not already present
9
+ * - Do not require the target to be in the scene beforehand
10
+ * - Typically animate opacity or drawing from 0 to visible
11
+ *
12
+ * Examples: FadeIn, Write, Draw, GrowFromCenter, SpinIn
13
+ */
14
+ export declare abstract class IntroductoryAnimation<T extends Mobject = Mobject> extends Animation<T> {
15
+ readonly lifecycle: AnimationLifecycle;
16
+ }
@@ -0,0 +1,14 @@
1
+ import { Animation } from '../Animation';
2
+ /**
3
+ * Abstract base class for animations that introduce an object to the scene.
4
+ *
5
+ * Introductory animations:
6
+ * - Automatically register the target with the scene if not already present
7
+ * - Do not require the target to be in the scene beforehand
8
+ * - Typically animate opacity or drawing from 0 to visible
9
+ *
10
+ * Examples: FadeIn, Write, Draw, GrowFromCenter, SpinIn
11
+ */
12
+ export class IntroductoryAnimation extends Animation {
13
+ lifecycle = 'introductory';
14
+ }
@@ -0,0 +1,25 @@
1
+ import { Animation } from '../Animation';
2
+ import type { AnimationLifecycle } from '../types';
3
+ import type { Mobject } from '../../../mobjects/Mobject';
4
+ /**
5
+ * Abstract base class for animations that transform an existing scene object.
6
+ *
7
+ * Transformative animations:
8
+ * - Require the target to already be registered with the scene
9
+ * - Throw an error if the target is not in the scene
10
+ * - Operate on objects that are already visible or have been introduced
11
+ * - Use lazy initialization to capture start state when animation becomes active
12
+ *
13
+ * Examples: MoveTo, Rotate, Scale, MorphTo, Transform
14
+ */
15
+ export declare abstract class TransformativeAnimation<T extends Mobject = Mobject> extends Animation<T> {
16
+ readonly lifecycle: AnimationLifecycle;
17
+ protected initialized: boolean;
18
+ /**
19
+ * Captures the start state from the target.
20
+ * Called once when the animation first becomes active.
21
+ */
22
+ protected abstract captureStartState(): void;
23
+ ensureInitialized(): void;
24
+ reset(): void;
25
+ }
@@ -0,0 +1,25 @@
1
+ import { Animation } from '../Animation';
2
+ /**
3
+ * Abstract base class for animations that transform an existing scene object.
4
+ *
5
+ * Transformative animations:
6
+ * - Require the target to already be registered with the scene
7
+ * - Throw an error if the target is not in the scene
8
+ * - Operate on objects that are already visible or have been introduced
9
+ * - Use lazy initialization to capture start state when animation becomes active
10
+ *
11
+ * Examples: MoveTo, Rotate, Scale, MorphTo, Transform
12
+ */
13
+ export class TransformativeAnimation extends Animation {
14
+ lifecycle = 'transformative';
15
+ initialized = false;
16
+ ensureInitialized() {
17
+ if (!this.initialized) {
18
+ this.captureStartState();
19
+ this.initialized = true;
20
+ }
21
+ }
22
+ reset() {
23
+ this.initialized = false;
24
+ }
25
+ }
@@ -0,0 +1,3 @@
1
+ export { IntroductoryAnimation } from './IntroductoryAnimation';
2
+ export { TransformativeAnimation } from './TransformativeAnimation';
3
+ export { ExitAnimation } from './ExitAnimation';
@@ -0,0 +1,3 @@
1
+ export { IntroductoryAnimation } from './IntroductoryAnimation';
2
+ export { TransformativeAnimation } from './TransformativeAnimation';
3
+ export { ExitAnimation } from './ExitAnimation';
@@ -0,0 +1,37 @@
1
+ import { Mobject } from '../../../mobjects/Mobject';
2
+ import { Animation } from '../Animation';
3
+ import type { AnimationLifecycle } from '../types';
4
+ /**
5
+ * Executes animations in parallel, all starting at the same time.
6
+ * Total duration equals the maximum of all child animation durations.
7
+ *
8
+ * This is a composition animation - its lifecycle is determined by its children.
9
+ * By default, uses 'transformative' lifecycle if children are mixed.
10
+ *
11
+ * All children are initialized together before any interpolation begins,
12
+ * ensuring they all capture state at the same moment.
13
+ */
14
+ export declare class Parallel extends Animation<Mobject> {
15
+ private readonly children;
16
+ private readonly maxChildDuration;
17
+ /**
18
+ * The lifecycle of Parallel is 'introductory' only if ALL children are introductory.
19
+ * Otherwise, it defaults to 'transformative'.
20
+ */
21
+ readonly lifecycle: AnimationLifecycle;
22
+ constructor(animations: Animation[]);
23
+ getDuration(): number;
24
+ getChildren(): readonly Animation[];
25
+ /**
26
+ * Ensures all children are initialized together.
27
+ * This captures start state for all parallel animations at the same moment.
28
+ */
29
+ ensureInitialized(): void;
30
+ reset(): void;
31
+ /**
32
+ * Interpolates all child animations at the given progress.
33
+ * Each child's progress is scaled based on its duration relative to the container.
34
+ */
35
+ interpolate(progress: number): void;
36
+ update(progress: number): void;
37
+ }
@@ -0,0 +1,79 @@
1
+ import { Mobject } from '../../../mobjects/Mobject';
2
+ import { Animation } from '../Animation';
3
+ /**
4
+ * Executes animations in parallel, all starting at the same time.
5
+ * Total duration equals the maximum of all child animation durations.
6
+ *
7
+ * This is a composition animation - its lifecycle is determined by its children.
8
+ * By default, uses 'transformative' lifecycle if children are mixed.
9
+ *
10
+ * All children are initialized together before any interpolation begins,
11
+ * ensuring they all capture state at the same moment.
12
+ */
13
+ export class Parallel extends Animation {
14
+ children;
15
+ maxChildDuration;
16
+ /**
17
+ * The lifecycle of Parallel is 'introductory' only if ALL children are introductory.
18
+ * Otherwise, it defaults to 'transformative'.
19
+ */
20
+ lifecycle;
21
+ constructor(animations) {
22
+ super(new Mobject());
23
+ this.children = animations;
24
+ this.maxChildDuration = animations.reduce((max, a) => Math.max(max, a.getDuration()), 0);
25
+ this.durationSeconds = this.maxChildDuration;
26
+ // Lifecycle is introductory only if ALL children are introductory
27
+ this.lifecycle = animations.every(a => a.lifecycle === 'introductory')
28
+ ? 'introductory'
29
+ : 'transformative';
30
+ }
31
+ getDuration() {
32
+ return this.durationSeconds;
33
+ }
34
+ getChildren() {
35
+ return this.children;
36
+ }
37
+ /**
38
+ * Ensures all children are initialized together.
39
+ * This captures start state for all parallel animations at the same moment.
40
+ */
41
+ ensureInitialized() {
42
+ for (const child of this.children) {
43
+ child.ensureInitialized();
44
+ }
45
+ }
46
+ reset() {
47
+ for (const child of this.children) {
48
+ child.reset();
49
+ }
50
+ }
51
+ /**
52
+ * Interpolates all child animations at the given progress.
53
+ * Each child's progress is scaled based on its duration relative to the container.
54
+ */
55
+ interpolate(progress) {
56
+ if (this.children.length === 0 || this.maxChildDuration === 0) {
57
+ return;
58
+ }
59
+ const globalTime = progress * this.maxChildDuration;
60
+ for (const child of this.children) {
61
+ const childDuration = child.getDuration();
62
+ if (childDuration === 0) {
63
+ child.update(1);
64
+ continue;
65
+ }
66
+ // Calculate local progress for this child
67
+ const localProgress = Math.min(1, globalTime / childDuration);
68
+ child.update(localProgress);
69
+ }
70
+ }
71
+ update(progress) {
72
+ // Pre-initialize ALL children before ANY interpolation
73
+ // This ensures parallel animations capture state at the same moment
74
+ this.ensureInitialized();
75
+ const clampedProgress = Math.max(0, Math.min(1, progress));
76
+ // Composition animations should not apply easing to their children
77
+ this.interpolate(clampedProgress);
78
+ }
79
+ }
@@ -0,0 +1,41 @@
1
+ import { Mobject } from '../../../mobjects/Mobject';
2
+ import { Animation } from '../Animation';
3
+ import type { AnimationLifecycle } from '../types';
4
+ /**
5
+ * Executes animations in sequence, one after another.
6
+ * Total duration equals the sum of all child animation durations.
7
+ *
8
+ * This is a composition animation - its lifecycle is determined by its children.
9
+ * Only the first child is initialized when the sequence starts; subsequent
10
+ * children are initialized when they become active.
11
+ */
12
+ export declare class Sequence extends Animation<Mobject> {
13
+ private readonly children;
14
+ private readonly childDurations;
15
+ private readonly totalChildDuration;
16
+ /**
17
+ * The lifecycle of Sequence is determined by its FIRST child animation.
18
+ * If the first animation is introductory, it will register the target,
19
+ * allowing subsequent transformative animations to work.
20
+ */
21
+ readonly lifecycle: AnimationLifecycle;
22
+ constructor(animations: Animation[]);
23
+ getDuration(): number;
24
+ getChildren(): readonly Animation[];
25
+ /**
26
+ * Initializes only the first child.
27
+ * Later children are initialized when they become active in interpolate().
28
+ */
29
+ ensureInitialized(): void;
30
+ reset(): void;
31
+ /**
32
+ * Interpolates the sequence at the given progress.
33
+ * Maps global progress to the correct child animation.
34
+ *
35
+ * IMPORTANT: We only update children that have started or completed.
36
+ * Children that haven't started yet are NOT updated to avoid
37
+ * premature initialization with incorrect state.
38
+ */
39
+ interpolate(progress: number): void;
40
+ update(progress: number): void;
41
+ }
@@ -0,0 +1,95 @@
1
+ import { Mobject } from '../../../mobjects/Mobject';
2
+ import { Animation } from '../Animation';
3
+ /**
4
+ * Executes animations in sequence, one after another.
5
+ * Total duration equals the sum of all child animation durations.
6
+ *
7
+ * This is a composition animation - its lifecycle is determined by its children.
8
+ * Only the first child is initialized when the sequence starts; subsequent
9
+ * children are initialized when they become active.
10
+ */
11
+ export class Sequence extends Animation {
12
+ children;
13
+ childDurations;
14
+ totalChildDuration;
15
+ /**
16
+ * The lifecycle of Sequence is determined by its FIRST child animation.
17
+ * If the first animation is introductory, it will register the target,
18
+ * allowing subsequent transformative animations to work.
19
+ */
20
+ lifecycle;
21
+ constructor(animations) {
22
+ super(new Mobject());
23
+ this.children = animations;
24
+ this.childDurations = animations.map((a) => a.getDuration());
25
+ this.totalChildDuration = this.childDurations.reduce((sum, d) => sum + d, 0);
26
+ this.durationSeconds = this.totalChildDuration;
27
+ // Lifecycle is determined by FIRST animation in the sequence
28
+ // If first is introductory, it registers the target for subsequent animations
29
+ const first = animations[0];
30
+ this.lifecycle = first?.lifecycle === 'introductory' ? 'introductory' : 'transformative';
31
+ }
32
+ getDuration() {
33
+ return this.durationSeconds;
34
+ }
35
+ getChildren() {
36
+ return this.children;
37
+ }
38
+ /**
39
+ * Initializes only the first child.
40
+ * Later children are initialized when they become active in interpolate().
41
+ */
42
+ ensureInitialized() {
43
+ if (this.children.length > 0) {
44
+ this.children[0].ensureInitialized();
45
+ }
46
+ }
47
+ reset() {
48
+ for (const child of this.children) {
49
+ child.reset();
50
+ }
51
+ }
52
+ /**
53
+ * Interpolates the sequence at the given progress.
54
+ * Maps global progress to the correct child animation.
55
+ *
56
+ * IMPORTANT: We only update children that have started or completed.
57
+ * Children that haven't started yet are NOT updated to avoid
58
+ * premature initialization with incorrect state.
59
+ */
60
+ interpolate(progress) {
61
+ if (this.children.length === 0 || this.totalChildDuration === 0) {
62
+ return;
63
+ }
64
+ const globalTime = progress * this.totalChildDuration;
65
+ let accumulatedTime = 0;
66
+ for (let i = 0; i < this.children.length; i++) {
67
+ const child = this.children[i];
68
+ const childDuration = this.childDurations[i];
69
+ if (child === undefined || childDuration === undefined) {
70
+ continue;
71
+ }
72
+ const childStart = accumulatedTime;
73
+ const childEnd = accumulatedTime + childDuration;
74
+ if (globalTime < childStart) {
75
+ // Before this child starts - DO NOT UPDATE
76
+ // Updating would prematurely initialize with wrong state
77
+ }
78
+ else if (globalTime >= childEnd) {
79
+ // This child is complete
80
+ child.update(1);
81
+ }
82
+ else {
83
+ // This child is active
84
+ const localProgress = (globalTime - childStart) / childDuration;
85
+ child.update(localProgress);
86
+ }
87
+ accumulatedTime = childEnd;
88
+ }
89
+ }
90
+ update(progress) {
91
+ const clampedProgress = Math.max(0, Math.min(1, progress));
92
+ // Composition animations should not apply easing to their children
93
+ this.interpolate(clampedProgress);
94
+ }
95
+ }
@@ -0,0 +1,2 @@
1
+ export { Sequence } from './Sequence';
2
+ export { Parallel } from './Parallel';
@@ -0,0 +1,3 @@
1
+ // Animation composition containers
2
+ export { Sequence } from './Sequence';
3
+ export { Parallel } from './Parallel';
@@ -0,0 +1,30 @@
1
+ import { IntroductoryAnimation } from '../categories';
2
+ import { VMobject } from '../../../mobjects/VMobject';
3
+ /**
4
+ * Animation that first draws the border progressively, then fills the shape.
5
+ * The first 50% of the animation draws the stroke, the second 50% fades in the fill.
6
+ *
7
+ * Supports VGroup (including Text): animates each child's paths progressively.
8
+ *
9
+ * This is an introductory animation - it auto-registers the target with the scene.
10
+ *
11
+ * @example
12
+ * const rect = new Rectangle(2, 1);
13
+ * scene.play(new Draw(rect)); // Border draws, then fill fades in
14
+ */
15
+ export declare class Draw<T extends VMobject = VMobject> extends IntroductoryAnimation<T> {
16
+ private readonly isVGroup;
17
+ /** For non-VGroup targets: original paths on the target itself. */
18
+ private readonly originalPaths;
19
+ private readonly originalFillOpacity;
20
+ private readonly originalOpacity;
21
+ /** For VGroup targets: original state of each child. */
22
+ private readonly childStates;
23
+ constructor(target: T);
24
+ /** Interpolates stroke drawing (0-0.5) and then fill fade (0.5-1). */
25
+ interpolate(progress: number): void;
26
+ /** Interpolates a single VMobject (non-VGroup). */
27
+ private interpolateVMobject;
28
+ /** Interpolates a VGroup by animating each child's paths. */
29
+ private interpolateVGroup;
30
+ }