@redwilly/anima 0.1.0 → 0.1.2

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/index.js +203 -57
  2. package/dist/index.d.ts +2086 -18
  3. package/dist/index.js +5343 -22
  4. package/package.json +5 -3
  5. package/dist/cli/SceneLoader.d.ts +0 -22
  6. package/dist/cli/SceneLoader.js +0 -47
  7. package/dist/cli/commands/export-frame.d.ts +0 -13
  8. package/dist/cli/commands/export-frame.js +0 -60
  9. package/dist/cli/commands/list-scenes.d.ts +0 -5
  10. package/dist/cli/commands/list-scenes.js +0 -22
  11. package/dist/cli/commands/preview.d.ts +0 -5
  12. package/dist/cli/commands/preview.js +0 -11
  13. package/dist/cli/commands/render.d.ts +0 -16
  14. package/dist/cli/commands/render.js +0 -76
  15. package/dist/cli/index.d.ts +0 -2
  16. package/dist/core/animations/Animation.d.ts +0 -41
  17. package/dist/core/animations/Animation.js +0 -76
  18. package/dist/core/animations/camera/Follow.d.ts +0 -70
  19. package/dist/core/animations/camera/Follow.js +0 -69
  20. package/dist/core/animations/camera/Shake.d.ts +0 -90
  21. package/dist/core/animations/camera/Shake.js +0 -87
  22. package/dist/core/animations/camera/index.d.ts +0 -2
  23. package/dist/core/animations/camera/index.js +0 -2
  24. package/dist/core/animations/categories/ExitAnimation.d.ts +0 -17
  25. package/dist/core/animations/categories/ExitAnimation.js +0 -15
  26. package/dist/core/animations/categories/IntroductoryAnimation.d.ts +0 -16
  27. package/dist/core/animations/categories/IntroductoryAnimation.js +0 -14
  28. package/dist/core/animations/categories/TransformativeAnimation.d.ts +0 -25
  29. package/dist/core/animations/categories/TransformativeAnimation.js +0 -25
  30. package/dist/core/animations/categories/index.d.ts +0 -3
  31. package/dist/core/animations/categories/index.js +0 -3
  32. package/dist/core/animations/composition/Parallel.d.ts +0 -37
  33. package/dist/core/animations/composition/Parallel.js +0 -79
  34. package/dist/core/animations/composition/Sequence.d.ts +0 -41
  35. package/dist/core/animations/composition/Sequence.js +0 -95
  36. package/dist/core/animations/composition/index.d.ts +0 -2
  37. package/dist/core/animations/composition/index.js +0 -3
  38. package/dist/core/animations/draw/Draw.d.ts +0 -30
  39. package/dist/core/animations/draw/Draw.js +0 -122
  40. package/dist/core/animations/draw/Unwrite.d.ts +0 -30
  41. package/dist/core/animations/draw/Unwrite.js +0 -120
  42. package/dist/core/animations/draw/Write.d.ts +0 -35
  43. package/dist/core/animations/draw/Write.js +0 -119
  44. package/dist/core/animations/draw/index.d.ts +0 -3
  45. package/dist/core/animations/draw/index.js +0 -3
  46. package/dist/core/animations/draw/partialPath.d.ts +0 -6
  47. package/dist/core/animations/draw/partialPath.js +0 -138
  48. package/dist/core/animations/easing/bounce.d.ts +0 -13
  49. package/dist/core/animations/easing/bounce.js +0 -37
  50. package/dist/core/animations/easing/index.d.ts +0 -7
  51. package/dist/core/animations/easing/index.js +0 -11
  52. package/dist/core/animations/easing/manim.d.ts +0 -46
  53. package/dist/core/animations/easing/manim.js +0 -102
  54. package/dist/core/animations/easing/registry.d.ts +0 -8
  55. package/dist/core/animations/easing/registry.js +0 -25
  56. package/dist/core/animations/easing/standard.d.ts +0 -113
  57. package/dist/core/animations/easing/standard.js +0 -151
  58. package/dist/core/animations/easing/types.d.ts +0 -6
  59. package/dist/core/animations/easing/types.js +0 -0
  60. package/dist/core/animations/fade/FadeIn.d.ts +0 -17
  61. package/dist/core/animations/fade/FadeIn.js +0 -22
  62. package/dist/core/animations/fade/FadeOut.d.ts +0 -17
  63. package/dist/core/animations/fade/FadeOut.js +0 -23
  64. package/dist/core/animations/fade/index.d.ts +0 -2
  65. package/dist/core/animations/fade/index.js +0 -2
  66. package/dist/core/animations/index.d.ts +0 -11
  67. package/dist/core/animations/index.js +0 -17
  68. package/dist/core/animations/keyframes/KeyframeAnimation.d.ts +0 -33
  69. package/dist/core/animations/keyframes/KeyframeAnimation.js +0 -40
  70. package/dist/core/animations/keyframes/KeyframeTrack.d.ts +0 -31
  71. package/dist/core/animations/keyframes/KeyframeTrack.js +0 -83
  72. package/dist/core/animations/keyframes/index.d.ts +0 -4
  73. package/dist/core/animations/keyframes/index.js +0 -5
  74. package/dist/core/animations/keyframes/types.d.ts +0 -25
  75. package/dist/core/animations/keyframes/types.js +0 -6
  76. package/dist/core/animations/morph/MorphTo.d.ts +0 -22
  77. package/dist/core/animations/morph/MorphTo.js +0 -42
  78. package/dist/core/animations/morph/index.d.ts +0 -1
  79. package/dist/core/animations/morph/index.js +0 -1
  80. package/dist/core/animations/transform/MoveTo.d.ts +0 -24
  81. package/dist/core/animations/transform/MoveTo.js +0 -38
  82. package/dist/core/animations/transform/Rotate.d.ts +0 -23
  83. package/dist/core/animations/transform/Rotate.js +0 -34
  84. package/dist/core/animations/transform/Scale.d.ts +0 -23
  85. package/dist/core/animations/transform/Scale.js +0 -35
  86. package/dist/core/animations/transform/index.d.ts +0 -3
  87. package/dist/core/animations/transform/index.js +0 -3
  88. package/dist/core/animations/types.d.ts +0 -52
  89. package/dist/core/animations/types.js +0 -6
  90. package/dist/core/camera/Camera.d.ts +0 -87
  91. package/dist/core/camera/Camera.js +0 -175
  92. package/dist/core/camera/CameraFrame.d.ts +0 -242
  93. package/dist/core/camera/CameraFrame.js +0 -322
  94. package/dist/core/camera/index.d.ts +0 -4
  95. package/dist/core/camera/index.js +0 -3
  96. package/dist/core/camera/types.d.ts +0 -17
  97. package/dist/core/camera/types.js +0 -1
  98. package/dist/core/errors/AnimationErrors.d.ts +0 -12
  99. package/dist/core/errors/AnimationErrors.js +0 -37
  100. package/dist/core/errors/index.d.ts +0 -1
  101. package/dist/core/errors/index.js +0 -1
  102. package/dist/core/math/Vector2/Vector2.d.ts +0 -23
  103. package/dist/core/math/Vector2/Vector2.js +0 -46
  104. package/dist/core/math/Vector2/index.d.ts +0 -1
  105. package/dist/core/math/Vector2/index.js +0 -1
  106. package/dist/core/math/bezier/BezierPath.d.ts +0 -38
  107. package/dist/core/math/bezier/BezierPath.js +0 -264
  108. package/dist/core/math/bezier/evaluators.d.ts +0 -9
  109. package/dist/core/math/bezier/evaluators.js +0 -36
  110. package/dist/core/math/bezier/index.d.ts +0 -8
  111. package/dist/core/math/bezier/index.js +0 -6
  112. package/dist/core/math/bezier/length.d.ts +0 -5
  113. package/dist/core/math/bezier/length.js +0 -27
  114. package/dist/core/math/bezier/morphing.d.ts +0 -16
  115. package/dist/core/math/bezier/morphing.js +0 -151
  116. package/dist/core/math/bezier/sampling.d.ts +0 -7
  117. package/dist/core/math/bezier/sampling.js +0 -153
  118. package/dist/core/math/bezier/split.d.ts +0 -19
  119. package/dist/core/math/bezier/split.js +0 -44
  120. package/dist/core/math/bezier/types.d.ts +0 -8
  121. package/dist/core/math/bezier/types.js +0 -0
  122. package/dist/core/math/color/Color.d.ts +0 -28
  123. package/dist/core/math/color/Color.js +0 -60
  124. package/dist/core/math/color/conversions.d.ts +0 -17
  125. package/dist/core/math/color/conversions.js +0 -100
  126. package/dist/core/math/color/index.d.ts +0 -2
  127. package/dist/core/math/color/index.js +0 -2
  128. package/dist/core/math/index.d.ts +0 -4
  129. package/dist/core/math/index.js +0 -5
  130. package/dist/core/math/matrix/Matrix3x3.d.ts +0 -23
  131. package/dist/core/math/matrix/Matrix3x3.js +0 -91
  132. package/dist/core/math/matrix/factories.d.ts +0 -12
  133. package/dist/core/math/matrix/factories.js +0 -44
  134. package/dist/core/math/matrix/index.d.ts +0 -2
  135. package/dist/core/math/matrix/index.js +0 -2
  136. package/dist/core/renderer/FrameRenderer.d.ts +0 -37
  137. package/dist/core/renderer/FrameRenderer.js +0 -75
  138. package/dist/core/renderer/ProgressReporter.d.ts +0 -19
  139. package/dist/core/renderer/ProgressReporter.js +0 -58
  140. package/dist/core/renderer/Renderer.d.ts +0 -36
  141. package/dist/core/renderer/Renderer.js +0 -102
  142. package/dist/core/renderer/drawMobject.d.ts +0 -8
  143. package/dist/core/renderer/drawMobject.js +0 -109
  144. package/dist/core/renderer/formats/index.d.ts +0 -3
  145. package/dist/core/renderer/formats/index.js +0 -3
  146. package/dist/core/renderer/formats/png.d.ts +0 -5
  147. package/dist/core/renderer/formats/png.js +0 -7
  148. package/dist/core/renderer/formats/sprite.d.ts +0 -6
  149. package/dist/core/renderer/formats/sprite.js +0 -24
  150. package/dist/core/renderer/formats/video.d.ts +0 -8
  151. package/dist/core/renderer/formats/video.js +0 -51
  152. package/dist/core/renderer/index.d.ts +0 -7
  153. package/dist/core/renderer/index.js +0 -9
  154. package/dist/core/renderer/types.d.ts +0 -87
  155. package/dist/core/renderer/types.js +0 -13
  156. package/dist/core/scene/Scene.d.ts +0 -104
  157. package/dist/core/scene/Scene.js +0 -225
  158. package/dist/core/scene/index.d.ts +0 -2
  159. package/dist/core/scene/index.js +0 -1
  160. package/dist/core/scene/types.d.ts +0 -23
  161. package/dist/core/scene/types.js +0 -0
  162. package/dist/core/serialization/animation.d.ts +0 -23
  163. package/dist/core/serialization/animation.js +0 -176
  164. package/dist/core/serialization/easingLookup.d.ts +0 -13
  165. package/dist/core/serialization/easingLookup.js +0 -65
  166. package/dist/core/serialization/index.d.ts +0 -23
  167. package/dist/core/serialization/index.js +0 -29
  168. package/dist/core/serialization/mobject.d.ts +0 -23
  169. package/dist/core/serialization/mobject.js +0 -248
  170. package/dist/core/serialization/prettyPrint.d.ts +0 -12
  171. package/dist/core/serialization/prettyPrint.js +0 -16
  172. package/dist/core/serialization/primitives.d.ts +0 -24
  173. package/dist/core/serialization/primitives.js +0 -98
  174. package/dist/core/serialization/registry.d.ts +0 -29
  175. package/dist/core/serialization/registry.js +0 -39
  176. package/dist/core/serialization/scene.d.ts +0 -28
  177. package/dist/core/serialization/scene.js +0 -114
  178. package/dist/core/serialization/types.d.ts +0 -152
  179. package/dist/core/serialization/types.js +0 -6
  180. package/dist/core/timeline/Timeline.d.ts +0 -70
  181. package/dist/core/timeline/Timeline.js +0 -144
  182. package/dist/core/timeline/index.d.ts +0 -5
  183. package/dist/core/timeline/index.js +0 -4
  184. package/dist/core/timeline/types.d.ts +0 -29
  185. package/dist/core/timeline/types.js +0 -0
  186. package/dist/mobjects/Mobject.d.ts +0 -98
  187. package/dist/mobjects/Mobject.js +0 -343
  188. package/dist/mobjects/VGroup/VGroup.d.ts +0 -51
  189. package/dist/mobjects/VGroup/VGroup.js +0 -142
  190. package/dist/mobjects/VGroup/index.d.ts +0 -3
  191. package/dist/mobjects/VGroup/index.js +0 -2
  192. package/dist/mobjects/VGroup/layout.d.ts +0 -20
  193. package/dist/mobjects/VGroup/layout.js +0 -139
  194. package/dist/mobjects/VMobject.d.ts +0 -106
  195. package/dist/mobjects/VMobject.js +0 -216
  196. package/dist/mobjects/geometry/Arc.d.ts +0 -8
  197. package/dist/mobjects/geometry/Arc.js +0 -46
  198. package/dist/mobjects/geometry/Arrow.d.ts +0 -7
  199. package/dist/mobjects/geometry/Arrow.js +0 -34
  200. package/dist/mobjects/geometry/Circle.d.ts +0 -4
  201. package/dist/mobjects/geometry/Circle.js +0 -10
  202. package/dist/mobjects/geometry/Line.d.ts +0 -8
  203. package/dist/mobjects/geometry/Line.js +0 -19
  204. package/dist/mobjects/geometry/Point.d.ts +0 -5
  205. package/dist/mobjects/geometry/Point.js +0 -11
  206. package/dist/mobjects/geometry/Polygon.d.ts +0 -7
  207. package/dist/mobjects/geometry/Polygon.js +0 -21
  208. package/dist/mobjects/geometry/Rectangle.d.ts +0 -6
  209. package/dist/mobjects/geometry/Rectangle.js +0 -18
  210. package/dist/mobjects/geometry/index.d.ts +0 -7
  211. package/dist/mobjects/geometry/index.js +0 -7
  212. package/dist/mobjects/graph/Graph.d.ts +0 -28
  213. package/dist/mobjects/graph/Graph.js +0 -119
  214. package/dist/mobjects/graph/GraphEdge.d.ts +0 -26
  215. package/dist/mobjects/graph/GraphEdge.js +0 -64
  216. package/dist/mobjects/graph/GraphNode.d.ts +0 -19
  217. package/dist/mobjects/graph/GraphNode.js +0 -63
  218. package/dist/mobjects/graph/index.d.ts +0 -5
  219. package/dist/mobjects/graph/index.js +0 -5
  220. package/dist/mobjects/graph/layouts/circular.d.ts +0 -8
  221. package/dist/mobjects/graph/layouts/circular.js +0 -23
  222. package/dist/mobjects/graph/layouts/forceDirected.d.ts +0 -9
  223. package/dist/mobjects/graph/layouts/forceDirected.js +0 -102
  224. package/dist/mobjects/graph/layouts/index.d.ts +0 -3
  225. package/dist/mobjects/graph/layouts/index.js +0 -3
  226. package/dist/mobjects/graph/layouts/tree.d.ts +0 -9
  227. package/dist/mobjects/graph/layouts/tree.js +0 -99
  228. package/dist/mobjects/graph/types.d.ts +0 -35
  229. package/dist/mobjects/graph/types.js +0 -0
  230. package/dist/mobjects/index.d.ts +0 -6
  231. package/dist/mobjects/index.js +0 -6
  232. package/dist/mobjects/text/Glyph.d.ts +0 -11
  233. package/dist/mobjects/text/Glyph.js +0 -72
  234. package/dist/mobjects/text/Text.d.ts +0 -19
  235. package/dist/mobjects/text/Text.js +0 -76
  236. package/dist/mobjects/text/index.d.ts +0 -4
  237. package/dist/mobjects/text/index.js +0 -3
  238. package/dist/mobjects/text/types.d.ts +0 -12
  239. package/dist/mobjects/text/types.js +0 -8
@@ -1,87 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { Follow } from './Follow';
2
- export { Shake } from './Shake';
@@ -1,2 +0,0 @@
1
- export { Follow } from './Follow';
2
- export { Shake } from './Shake';
@@ -1,17 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export { IntroductoryAnimation } from './IntroductoryAnimation';
2
- export { TransformativeAnimation } from './TransformativeAnimation';
3
- export { ExitAnimation } from './ExitAnimation';
@@ -1,3 +0,0 @@
1
- export { IntroductoryAnimation } from './IntroductoryAnimation';
2
- export { TransformativeAnimation } from './TransformativeAnimation';
3
- export { ExitAnimation } from './ExitAnimation';
@@ -1,37 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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
- }
@@ -1,95 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { Sequence } from './Sequence';
2
- export { Parallel } from './Parallel';
@@ -1,3 +0,0 @@
1
- // Animation composition containers
2
- export { Sequence } from './Sequence';
3
- export { Parallel } from './Parallel';
@@ -1,30 +0,0 @@
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
- }
@@ -1,122 +0,0 @@
1
- import { IntroductoryAnimation } from '../categories';
2
- import { getPartialPath } from './partialPath';
3
- /**
4
- * Checks if a VMobject is a VGroup (has getChildren method).
5
- * Uses duck-typing to avoid circular dependency with VGroup import.
6
- */
7
- function isVGroup(target) {
8
- return typeof target.getChildren === 'function';
9
- }
10
- /**
11
- * Animation that first draws the border progressively, then fills the shape.
12
- * The first 50% of the animation draws the stroke, the second 50% fades in the fill.
13
- *
14
- * Supports VGroup (including Text): animates each child's paths progressively.
15
- *
16
- * This is an introductory animation - it auto-registers the target with the scene.
17
- *
18
- * @example
19
- * const rect = new Rectangle(2, 1);
20
- * scene.play(new Draw(rect)); // Border draws, then fill fades in
21
- */
22
- export class Draw extends IntroductoryAnimation {
23
- isVGroup;
24
- /** For non-VGroup targets: original paths on the target itself. */
25
- originalPaths;
26
- originalFillOpacity;
27
- originalOpacity;
28
- /** For VGroup targets: original state of each child. */
29
- childStates;
30
- constructor(target) {
31
- super(target);
32
- this.isVGroup = isVGroup(target);
33
- this.originalOpacity = target.opacity;
34
- this.originalFillOpacity = target.getFillOpacity();
35
- if (this.isVGroup && isVGroup(target)) {
36
- // Store original state for each child
37
- this.originalPaths = [];
38
- this.childStates = [];
39
- for (const child of target.getChildren()) {
40
- this.childStates.push({
41
- child,
42
- originalPaths: child.paths.map((p) => p.clone()),
43
- originalOpacity: child.opacity,
44
- originalFillOpacity: child.getFillOpacity(),
45
- });
46
- }
47
- }
48
- else {
49
- // Store original paths on the target itself
50
- this.originalPaths = target.paths.map(p => p.clone());
51
- this.childStates = [];
52
- }
53
- }
54
- /** Interpolates stroke drawing (0-0.5) and then fill fade (0.5-1). */
55
- interpolate(progress) {
56
- if (this.isVGroup) {
57
- this.interpolateVGroup(progress);
58
- }
59
- else {
60
- this.interpolateVMobject(progress);
61
- }
62
- }
63
- /** Interpolates a single VMobject (non-VGroup). */
64
- interpolateVMobject(progress) {
65
- const targetOpacity = this.originalOpacity === 0 ? 1 : this.originalOpacity;
66
- if (progress <= 0) {
67
- this.target.paths = [];
68
- this.target.setOpacity(0);
69
- this.target.fill(this.target.getFillColor(), 0);
70
- return;
71
- }
72
- this.target.setOpacity(targetOpacity);
73
- if (progress < 0.5) {
74
- // First half: draw stroke progressively, no fill
75
- const strokeProgress = progress * 2;
76
- const partialPaths = [];
77
- for (const originalPath of this.originalPaths) {
78
- partialPaths.push(getPartialPath(originalPath, strokeProgress));
79
- }
80
- this.target.paths = partialPaths;
81
- this.target.fill(this.target.getFillColor(), 0);
82
- }
83
- else {
84
- // Second half: full stroke, fade in fill
85
- this.target.paths = this.originalPaths.map(p => p.clone());
86
- const fillProgress = (progress - 0.5) * 2;
87
- this.target.fill(this.target.getFillColor(), this.originalFillOpacity * fillProgress);
88
- }
89
- }
90
- /** Interpolates a VGroup by animating each child's paths. */
91
- interpolateVGroup(progress) {
92
- const targetOpacity = this.originalOpacity === 0 ? 1 : this.originalOpacity;
93
- this.target.setOpacity(progress <= 0 ? 0 : targetOpacity);
94
- for (const state of this.childStates) {
95
- const { child, originalPaths, originalOpacity, originalFillOpacity } = state;
96
- const childOpacity = originalOpacity === 0 ? 1 : originalOpacity;
97
- if (progress <= 0) {
98
- child.paths = [];
99
- child.setOpacity(0);
100
- child.fill(child.getFillColor(), 0);
101
- continue;
102
- }
103
- child.setOpacity(childOpacity);
104
- if (progress < 0.5) {
105
- // First half: draw stroke progressively, no fill
106
- const strokeProgress = progress * 2;
107
- const partialPaths = [];
108
- for (const originalPath of originalPaths) {
109
- partialPaths.push(getPartialPath(originalPath, strokeProgress));
110
- }
111
- child.paths = partialPaths;
112
- child.fill(child.getFillColor(), 0);
113
- }
114
- else {
115
- // Second half: full stroke, fade in fill
116
- child.paths = originalPaths.map(p => p.clone());
117
- const fillProgress = (progress - 0.5) * 2;
118
- child.fill(child.getFillColor(), originalFillOpacity * fillProgress);
119
- }
120
- }
121
- }
122
- }
@@ -1,30 +0,0 @@
1
- import { ExitAnimation } from '../categories';
2
- import { VMobject } from '../../../mobjects/VMobject';
3
- /**
4
- * Animation that progressively removes a VMobject by erasing the path.
5
- * Reverse of Write animation - at progress 0, full object is visible;
6
- * at progress 1, nothing is visible.
7
- *
8
- * Supports VGroup (including Text): animates each child's paths progressively.
9
- *
10
- * This is an exit animation - the target must already be in the scene.
11
- *
12
- * @example
13
- * scene.play(new Write(text));
14
- * scene.play(new Unwrite(text)); // Text is erased progressively
15
- */
16
- export declare class Unwrite<T extends VMobject = VMobject> extends ExitAnimation<T> {
17
- private readonly isVGroup;
18
- /** For non-VGroup targets: original paths on the target itself. */
19
- private readonly originalPaths;
20
- private readonly originalOpacity;
21
- private readonly originalFillOpacity;
22
- /** For VGroup targets: original state of each child. */
23
- private readonly childStates;
24
- constructor(target: T);
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
- }