@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,175 @@
1
+ import { Vector2 } from '../math/Vector2/Vector2';
2
+ import { Matrix3x3 } from '../math/matrix/Matrix3x3';
3
+ import { CameraFrame } from './CameraFrame';
4
+ import { MANIM_FRAME_HEIGHT } from './types';
5
+ /**
6
+ * Camera manages the view into the scene.
7
+ * Uses CameraFrame (a Mobject) to store transform state, enabling camera animations.
8
+ *
9
+ * The Camera provides both instant manipulation methods (panTo, zoomTo) and
10
+ * access to the CameraFrame for fluent animation APIs.
11
+ *
12
+ * @example
13
+ * // Instant camera manipulation
14
+ * camera.zoomTo(2);
15
+ * camera.panTo(new Vector2(5, 3));
16
+ *
17
+ * @example
18
+ * // Animated camera movement via frame
19
+ * this.play(this.frame.zoomIn(2).duration(1));
20
+ * this.play(this.frame.centerOn(circle).duration(0.5));
21
+ */
22
+ export class Camera {
23
+ config;
24
+ /** The CameraFrame that stores the camera's transform state. Use this for animations. */
25
+ frame;
26
+ /**
27
+ * Creates a new Camera with the specified viewport dimensions.
28
+ *
29
+ * @param config - Configuration options
30
+ * @param config.pixelWidth - Width of the viewport in pixels (default: 1920)
31
+ * @param config.pixelHeight - Height of the viewport in pixels (default: 1080)
32
+ */
33
+ constructor(config = {}) {
34
+ this.config = {
35
+ pixelWidth: config.pixelWidth ?? 1920,
36
+ pixelHeight: config.pixelHeight ?? 1080,
37
+ };
38
+ this.frame = new CameraFrame({
39
+ pixelWidth: this.config.pixelWidth,
40
+ pixelHeight: this.config.pixelHeight,
41
+ });
42
+ }
43
+ // ========== Frame Dimensions (Manim-compatible) ==========
44
+ get frameHeight() {
45
+ return MANIM_FRAME_HEIGHT;
46
+ }
47
+ get frameWidth() {
48
+ const aspectRatio = this.config.pixelWidth / this.config.pixelHeight;
49
+ return MANIM_FRAME_HEIGHT * aspectRatio;
50
+ }
51
+ get frameYRadius() {
52
+ return this.frameHeight / 2;
53
+ }
54
+ get frameXRadius() {
55
+ return this.frameWidth / 2;
56
+ }
57
+ // ========== Pixel Dimensions ==========
58
+ get pixelWidth() {
59
+ return this.config.pixelWidth;
60
+ }
61
+ get pixelHeight() {
62
+ return this.config.pixelHeight;
63
+ }
64
+ // ========== Camera Transform Properties (read from frame) ==========
65
+ get position() {
66
+ return this.frame.position;
67
+ }
68
+ get zoom() {
69
+ return 1 / this.frame.scale.x;
70
+ }
71
+ get rotation() {
72
+ return this.frame.rotation;
73
+ }
74
+ // ========== Pan Operations (proxy to frame) ==========
75
+ pan(delta) {
76
+ const current = this.frame.position;
77
+ this.frame.pos(current.x + delta.x, current.y + delta.y);
78
+ return this;
79
+ }
80
+ panTo(position) {
81
+ this.frame.pos(position.x, position.y);
82
+ return this;
83
+ }
84
+ // ========== Zoom Operations (proxy to frame) ==========
85
+ zoomTo(level) {
86
+ if (level <= 0) {
87
+ throw new Error('Zoom level must be positive');
88
+ }
89
+ const frameScale = 1 / level;
90
+ this.frame.setScale(frameScale, frameScale);
91
+ return this;
92
+ }
93
+ // ========== Rotation Operations (proxy to frame) ==========
94
+ rotateTo(angle) {
95
+ this.frame.setRotation(angle);
96
+ return this;
97
+ }
98
+ // ========== View Matrix ==========
99
+ getViewMatrix() {
100
+ const framePos = this.frame.position;
101
+ const frameScale = this.frame.scale;
102
+ const frameRotation = this.frame.rotation;
103
+ const zoomX = 1 / frameScale.x;
104
+ const zoomY = 1 / frameScale.y;
105
+ const translate = Matrix3x3.translation(-framePos.x, -framePos.y);
106
+ const rotate = Matrix3x3.rotation(-frameRotation);
107
+ const scale = Matrix3x3.scale(zoomX, zoomY);
108
+ return scale.multiply(rotate).multiply(translate);
109
+ }
110
+ // ========== Coordinate Transforms ==========
111
+ /**
112
+ * Transforms a world-space position to screen-space (pixel) coordinates.
113
+ *
114
+ * Screen coordinates have origin at top-left, with x increasing right
115
+ * and y increasing downward.
116
+ *
117
+ * @param pos - Position in world coordinates
118
+ * @returns Position in screen coordinates (pixels)
119
+ *
120
+ * @example
121
+ * const screenPos = camera.worldToScreen(circle.position);
122
+ * console.log(`Circle is at pixel (${screenPos.x}, ${screenPos.y})`);
123
+ */
124
+ worldToScreen(pos) {
125
+ const viewMatrix = this.getViewMatrix();
126
+ const transformed = viewMatrix.transformPoint(pos);
127
+ const screenX = (transformed.x + 1) * 0.5 * this.config.pixelWidth;
128
+ const screenY = (1 - transformed.y) * 0.5 * this.config.pixelHeight;
129
+ return new Vector2(screenX, screenY);
130
+ }
131
+ /**
132
+ * Transforms a screen-space (pixel) position to world coordinates.
133
+ * This is the inverse of worldToScreen.
134
+ *
135
+ * @param pos - Position in screen coordinates (pixels, origin at top-left)
136
+ * @returns Position in world coordinates
137
+ *
138
+ * @example
139
+ * // Convert a mouse click position to world coordinates
140
+ * const worldPos = camera.screenToWorld(new Vector2(mouseX, mouseY));
141
+ */
142
+ screenToWorld(pos) {
143
+ const ndcX = (pos.x / this.config.pixelWidth) * 2 - 1;
144
+ const ndcY = 1 - (pos.y / this.config.pixelHeight) * 2;
145
+ const viewMatrix = this.getViewMatrix();
146
+ const inverseView = viewMatrix.inverse();
147
+ return inverseView.transformPoint(new Vector2(ndcX, ndcY));
148
+ }
149
+ /**
150
+ * Checks if a world-space position is currently visible within the camera frame.
151
+ *
152
+ * @param pos - Position in world coordinates to check
153
+ * @returns True if the position is within the visible frame bounds
154
+ *
155
+ * @example
156
+ * if (camera.isInView(object.position)) {
157
+ * console.log('Object is visible');
158
+ * }
159
+ */
160
+ isInView(pos) {
161
+ const framePos = this.frame.position;
162
+ const halfWidth = this.frame.width / 2;
163
+ const halfHeight = this.frame.height / 2;
164
+ return (pos.x >= framePos.x - halfWidth &&
165
+ pos.x <= framePos.x + halfWidth &&
166
+ pos.y >= framePos.y - halfHeight &&
167
+ pos.y <= framePos.y + halfHeight);
168
+ }
169
+ reset() {
170
+ this.frame.pos(0, 0);
171
+ this.frame.setScale(1, 1);
172
+ this.frame.setRotation(0);
173
+ return this;
174
+ }
175
+ }
@@ -0,0 +1,242 @@
1
+ import { Mobject } from '../../mobjects/Mobject';
2
+ import { Parallel } from '../animations/composition';
3
+ import type { Animation } from '../animations/Animation';
4
+ /**
5
+ * Configuration options for CameraFrame.
6
+ */
7
+ interface CameraFrameConfig {
8
+ /** Width of the viewport in pixels. Defaults to 1920. */
9
+ pixelWidth?: number;
10
+ /** Height of the viewport in pixels. Defaults to 1080. */
11
+ pixelHeight?: number;
12
+ }
13
+ /**
14
+ * Camera bounds that limit how far the camera can pan.
15
+ */
16
+ interface Bounds {
17
+ minX: number;
18
+ maxX: number;
19
+ minY: number;
20
+ maxY: number;
21
+ }
22
+ /**
23
+ * CameraFrame represents the viewport window in world space.
24
+ * Extends Mobject (not VMobject - no visual representation).
25
+ * Its transform properties define what the camera shows:
26
+ * - scale(2) = zoom OUT (larger frame = see more)
27
+ * - scale(0.5) = zoom IN (smaller frame = see less)
28
+ *
29
+ * The CameraFrame is the primary way to control camera animations in Anima.
30
+ * Access it via `scene.frame` or `scene.camera.frame`.
31
+ *
32
+ * @example
33
+ * // Zoom in over 1 second
34
+ * this.play(this.frame.zoomIn(2).duration(1));
35
+ *
36
+ * @example
37
+ * // Pan to center on an object
38
+ * this.play(this.frame.centerOn(circle).duration(0.5));
39
+ *
40
+ * @example
41
+ * // Fit multiple objects in view
42
+ * this.play(this.frame.fitTo([obj1, obj2, obj3]).duration(1));
43
+ */
44
+ export declare class CameraFrame extends Mobject {
45
+ private readonly baseWidth;
46
+ private readonly baseHeight;
47
+ private bounds?;
48
+ /**
49
+ * Creates a new CameraFrame with the specified viewport dimensions.
50
+ *
51
+ * @param config - Configuration options
52
+ * @param config.pixelWidth - Width of the viewport in pixels (default: 1920)
53
+ * @param config.pixelHeight - Height of the viewport in pixels (default: 1080)
54
+ *
55
+ * @example
56
+ * const frame = new CameraFrame({ pixelWidth: 1920, pixelHeight: 1080 });
57
+ */
58
+ constructor(config?: CameraFrameConfig);
59
+ /**
60
+ * The current width of the frame in world units, accounting for scale.
61
+ * @returns The frame width multiplied by the current scale.x
62
+ */
63
+ get width(): number;
64
+ /**
65
+ * The current height of the frame in world units, accounting for scale.
66
+ * @returns The frame height multiplied by the current scale.y
67
+ */
68
+ get height(): number;
69
+ /**
70
+ * Sets the scale of the camera frame.
71
+ * Overrides Mobject.setScale to prevent zero or negative scales.
72
+ *
73
+ * @param sx - Scale factor for the x-axis (must be positive)
74
+ * @param sy - Scale factor for the y-axis (must be positive)
75
+ * @returns This CameraFrame for method chaining
76
+ * @throws Error if sx or sy is zero or negative
77
+ *
78
+ * @example
79
+ * frame.setScale(2, 2); // Zoom out 2x
80
+ * frame.setScale(0.5, 0.5); // Zoom in 2x
81
+ */
82
+ setScale(sx: number, sy: number): this;
83
+ /**
84
+ * Sets bounds that limit how far the camera can pan.
85
+ * When bounds are set, the camera position is clamped to stay within them,
86
+ * accounting for the frame size so edges don't go outside bounds.
87
+ *
88
+ * @param minX - Minimum x coordinate
89
+ * @param minY - Minimum y coordinate
90
+ * @param maxX - Maximum x coordinate
91
+ * @param maxY - Maximum y coordinate
92
+ * @returns This CameraFrame for method chaining
93
+ *
94
+ * @example
95
+ * // Limit camera to a 100x100 world area
96
+ * frame.setBounds(0, 0, 100, 100);
97
+ */
98
+ setBounds(minX: number, minY: number, maxX: number, maxY: number): this;
99
+ /**
100
+ * Removes any bounds restrictions on camera movement.
101
+ *
102
+ * @returns This CameraFrame for method chaining
103
+ *
104
+ * @example
105
+ * frame.clearBounds(); // Camera can now pan freely
106
+ */
107
+ clearBounds(): this;
108
+ /**
109
+ * Checks if the camera has bounds set.
110
+ *
111
+ * @returns True if bounds are set, false otherwise
112
+ */
113
+ hasBounds(): boolean;
114
+ /**
115
+ * Gets the current bounds configuration.
116
+ *
117
+ * @returns The bounds object or undefined if no bounds are set
118
+ */
119
+ getBounds(): Bounds | undefined;
120
+ /**
121
+ * Sets the position of the camera frame.
122
+ * Overrides Mobject.pos to clamp position within bounds if set.
123
+ *
124
+ * @param x - The x coordinate in world space
125
+ * @param y - The y coordinate in world space
126
+ * @returns This CameraFrame for method chaining
127
+ *
128
+ * @example
129
+ * frame.pos(5, 3); // Move camera center to (5, 3)
130
+ */
131
+ pos(x: number, y: number): this;
132
+ /**
133
+ * Smoothly zoom the camera in by the given factor.
134
+ * Internally scales the frame down, which makes objects appear larger.
135
+ *
136
+ * @param factor - Zoom multiplier. 2 = objects appear 2x larger (default: 2)
137
+ * @returns FluentAnimation that can be chained with .duration() and .ease()
138
+ * @throws Error if factor is zero or negative
139
+ *
140
+ * @example
141
+ * // Zoom in 2x over 1 second
142
+ * this.play(this.frame.zoomIn(2).duration(1));
143
+ *
144
+ * @example
145
+ * // Zoom in 3x with easing
146
+ * this.play(this.frame.zoomIn(3).duration(1.5).ease(easeInOutQuad));
147
+ */
148
+ zoomIn(factor?: number): this & {
149
+ toAnimation(): Animation<Mobject>;
150
+ };
151
+ /**
152
+ * Smoothly zoom the camera out by the given factor.
153
+ * Internally scales the frame up, which makes objects appear smaller.
154
+ *
155
+ * @param factor - Zoom multiplier. 2 = objects appear 2x smaller (default: 2)
156
+ * @returns FluentAnimation that can be chained with .duration() and .ease()
157
+ * @throws Error if factor is zero or negative
158
+ *
159
+ * @example
160
+ * // Zoom out 2x over 1 second
161
+ * this.play(this.frame.zoomOut(2).duration(1));
162
+ *
163
+ * @example
164
+ * // Zoom out to show more of the scene
165
+ * this.play(this.frame.zoomOut(4).duration(2).ease(easeOutCubic));
166
+ */
167
+ zoomOut(factor?: number): this & {
168
+ toAnimation(): Animation<Mobject>;
169
+ };
170
+ /**
171
+ * Move the camera to center on a target Mobject.
172
+ * The camera will smoothly pan so the target is at the center of the frame.
173
+ *
174
+ * @param target - The Mobject to center on
175
+ * @returns FluentAnimation that can be chained with .duration() and .ease()
176
+ * @throws Error if target is null or undefined
177
+ *
178
+ * @example
179
+ * // Center on a circle over 0.5 seconds
180
+ * this.play(this.frame.centerOn(circle).duration(0.5));
181
+ *
182
+ * @example
183
+ * // Pan to focus on different objects in sequence
184
+ * await this.play(this.frame.centerOn(obj1).duration(1));
185
+ * await this.play(this.frame.centerOn(obj2).duration(1));
186
+ */
187
+ centerOn(target: Mobject): this & {
188
+ toAnimation(): Animation<Mobject>;
189
+ };
190
+ /**
191
+ * Zoom in/out while keeping a specific world point fixed on screen.
192
+ * Like pinch-to-zoom behavior where the pinch point stays stationary.
193
+ *
194
+ * Uses the formula: C' = P * (1 - factor) + C * factor
195
+ * Where P = point, C = current center, factor = zoom factor.
196
+ *
197
+ * @param factor - Scale multiplier. Less than 1 for zoom in, greater than 1 for zoom out
198
+ * @param point - World coordinates to keep fixed on screen
199
+ * @returns Parallel animation combining move and scale
200
+ * @throws Error if factor is zero or negative
201
+ *
202
+ * @example
203
+ * // Zoom in 2x on a specific point
204
+ * this.play(frame.zoomToPoint(0.5, { x: 5, y: 5 }).duration(1));
205
+ *
206
+ * @example
207
+ * // Zoom out while keeping an object's position fixed
208
+ * this.play(frame.zoomToPoint(2, circle.position).duration(1));
209
+ */
210
+ zoomToPoint(factor: number, point: {
211
+ x: number;
212
+ y: number;
213
+ }): Parallel;
214
+ /**
215
+ * Automatically frame one or more objects with optional margin.
216
+ * Calculates the bounding box of all targets and animates the camera
217
+ * to show them all with the specified margin around them.
218
+ *
219
+ * @param targets - Single Mobject or array of Mobjects to frame
220
+ * @param margin - Padding around the objects in world units (default: 0.5)
221
+ * @returns FluentAnimation that can be chained with .duration() and .ease()
222
+ * @throws Error if targets array is empty
223
+ *
224
+ * @example
225
+ * // Fit a single object with default margin
226
+ * this.play(this.frame.fitTo(circle).duration(1));
227
+ *
228
+ * @example
229
+ * // Fit multiple objects with custom margin
230
+ * this.play(this.frame.fitTo([obj1, obj2, obj3], 1.0).duration(1.5));
231
+ *
232
+ * @example
233
+ * // Show all objects in the scene
234
+ * this.play(this.frame.fitTo(allObjects, 0).duration(2));
235
+ */
236
+ fitTo(targets: Mobject | Mobject[], margin?: number): this & {
237
+ toAnimation(): Animation<Mobject>;
238
+ };
239
+ private calculateBounds;
240
+ private hasGetBoundingBox;
241
+ }
242
+ export {};