@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.
- package/dist/cli/SceneLoader.d.ts +22 -0
- package/dist/cli/SceneLoader.js +47 -0
- package/dist/cli/commands/export-frame.d.ts +13 -0
- package/dist/cli/commands/export-frame.js +60 -0
- package/dist/cli/commands/list-scenes.d.ts +5 -0
- package/dist/cli/commands/list-scenes.js +22 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.js +11 -0
- package/dist/cli/commands/render.d.ts +16 -0
- package/dist/cli/commands/render.js +76 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +63 -0
- package/dist/core/animations/Animation.d.ts +41 -0
- package/dist/core/animations/Animation.js +76 -0
- package/dist/core/animations/camera/Follow.d.ts +70 -0
- package/dist/core/animations/camera/Follow.js +69 -0
- package/dist/core/animations/camera/Shake.d.ts +90 -0
- package/dist/core/animations/camera/Shake.js +87 -0
- package/dist/core/animations/camera/index.d.ts +2 -0
- package/dist/core/animations/camera/index.js +2 -0
- package/dist/core/animations/categories/ExitAnimation.d.ts +17 -0
- package/dist/core/animations/categories/ExitAnimation.js +15 -0
- package/dist/core/animations/categories/IntroductoryAnimation.d.ts +16 -0
- package/dist/core/animations/categories/IntroductoryAnimation.js +14 -0
- package/dist/core/animations/categories/TransformativeAnimation.d.ts +25 -0
- package/dist/core/animations/categories/TransformativeAnimation.js +25 -0
- package/dist/core/animations/categories/index.d.ts +3 -0
- package/dist/core/animations/categories/index.js +3 -0
- package/dist/core/animations/composition/Parallel.d.ts +37 -0
- package/dist/core/animations/composition/Parallel.js +79 -0
- package/dist/core/animations/composition/Sequence.d.ts +41 -0
- package/dist/core/animations/composition/Sequence.js +95 -0
- package/dist/core/animations/composition/index.d.ts +2 -0
- package/dist/core/animations/composition/index.js +3 -0
- package/dist/core/animations/draw/Draw.d.ts +30 -0
- package/dist/core/animations/draw/Draw.js +122 -0
- package/dist/core/animations/draw/Unwrite.d.ts +30 -0
- package/dist/core/animations/draw/Unwrite.js +120 -0
- package/dist/core/animations/draw/Write.d.ts +35 -0
- package/dist/core/animations/draw/Write.js +119 -0
- package/dist/core/animations/draw/index.d.ts +3 -0
- package/dist/core/animations/draw/index.js +3 -0
- package/dist/core/animations/draw/partialPath.d.ts +6 -0
- package/dist/core/animations/draw/partialPath.js +138 -0
- package/dist/core/animations/easing/bounce.d.ts +13 -0
- package/dist/core/animations/easing/bounce.js +37 -0
- package/dist/core/animations/easing/index.d.ts +7 -0
- package/dist/core/animations/easing/index.js +11 -0
- package/dist/core/animations/easing/manim.d.ts +46 -0
- package/dist/core/animations/easing/manim.js +102 -0
- package/dist/core/animations/easing/registry.d.ts +8 -0
- package/dist/core/animations/easing/registry.js +25 -0
- package/dist/core/animations/easing/standard.d.ts +113 -0
- package/dist/core/animations/easing/standard.js +151 -0
- package/dist/core/animations/easing/types.d.ts +6 -0
- package/dist/core/animations/easing/types.js +0 -0
- package/dist/core/animations/fade/FadeIn.d.ts +17 -0
- package/dist/core/animations/fade/FadeIn.js +22 -0
- package/dist/core/animations/fade/FadeOut.d.ts +17 -0
- package/dist/core/animations/fade/FadeOut.js +23 -0
- package/dist/core/animations/fade/index.d.ts +2 -0
- package/dist/core/animations/fade/index.js +2 -0
- package/dist/core/animations/index.d.ts +11 -0
- package/dist/core/animations/index.js +17 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.d.ts +33 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.js +40 -0
- package/dist/core/animations/keyframes/KeyframeTrack.d.ts +31 -0
- package/dist/core/animations/keyframes/KeyframeTrack.js +83 -0
- package/dist/core/animations/keyframes/index.d.ts +4 -0
- package/dist/core/animations/keyframes/index.js +5 -0
- package/dist/core/animations/keyframes/types.d.ts +25 -0
- package/dist/core/animations/keyframes/types.js +6 -0
- package/dist/core/animations/morph/MorphTo.d.ts +22 -0
- package/dist/core/animations/morph/MorphTo.js +42 -0
- package/dist/core/animations/morph/index.d.ts +1 -0
- package/dist/core/animations/morph/index.js +1 -0
- package/dist/core/animations/transform/MoveTo.d.ts +24 -0
- package/dist/core/animations/transform/MoveTo.js +38 -0
- package/dist/core/animations/transform/Rotate.d.ts +23 -0
- package/dist/core/animations/transform/Rotate.js +34 -0
- package/dist/core/animations/transform/Scale.d.ts +23 -0
- package/dist/core/animations/transform/Scale.js +35 -0
- package/dist/core/animations/transform/index.d.ts +3 -0
- package/dist/core/animations/transform/index.js +3 -0
- package/dist/core/animations/types.d.ts +52 -0
- package/dist/core/animations/types.js +6 -0
- package/dist/core/camera/Camera.d.ts +87 -0
- package/dist/core/camera/Camera.js +175 -0
- package/dist/core/camera/CameraFrame.d.ts +242 -0
- package/dist/core/camera/CameraFrame.js +322 -0
- package/dist/core/camera/index.d.ts +4 -0
- package/dist/core/camera/index.js +3 -0
- package/dist/core/camera/types.d.ts +17 -0
- package/dist/core/camera/types.js +1 -0
- package/dist/core/errors/AnimationErrors.d.ts +12 -0
- package/dist/core/errors/AnimationErrors.js +37 -0
- package/dist/core/errors/index.d.ts +1 -0
- package/dist/core/errors/index.js +1 -0
- package/dist/core/math/Vector2/Vector2.d.ts +23 -0
- package/dist/core/math/Vector2/Vector2.js +46 -0
- package/dist/core/math/Vector2/index.d.ts +1 -0
- package/dist/core/math/Vector2/index.js +1 -0
- package/dist/core/math/bezier/BezierPath.d.ts +38 -0
- package/dist/core/math/bezier/BezierPath.js +264 -0
- package/dist/core/math/bezier/evaluators.d.ts +9 -0
- package/dist/core/math/bezier/evaluators.js +36 -0
- package/dist/core/math/bezier/index.d.ts +8 -0
- package/dist/core/math/bezier/index.js +6 -0
- package/dist/core/math/bezier/length.d.ts +5 -0
- package/dist/core/math/bezier/length.js +27 -0
- package/dist/core/math/bezier/morphing.d.ts +16 -0
- package/dist/core/math/bezier/morphing.js +151 -0
- package/dist/core/math/bezier/sampling.d.ts +7 -0
- package/dist/core/math/bezier/sampling.js +153 -0
- package/dist/core/math/bezier/split.d.ts +19 -0
- package/dist/core/math/bezier/split.js +44 -0
- package/dist/core/math/bezier/types.d.ts +8 -0
- package/dist/core/math/bezier/types.js +0 -0
- package/dist/core/math/color/Color.d.ts +28 -0
- package/dist/core/math/color/Color.js +60 -0
- package/dist/core/math/color/conversions.d.ts +17 -0
- package/dist/core/math/color/conversions.js +100 -0
- package/dist/core/math/color/index.d.ts +2 -0
- package/dist/core/math/color/index.js +2 -0
- package/dist/core/math/index.d.ts +4 -0
- package/dist/core/math/index.js +5 -0
- package/dist/core/math/matrix/Matrix3x3.d.ts +23 -0
- package/dist/core/math/matrix/Matrix3x3.js +91 -0
- package/dist/core/math/matrix/factories.d.ts +12 -0
- package/dist/core/math/matrix/factories.js +44 -0
- package/dist/core/math/matrix/index.d.ts +2 -0
- package/dist/core/math/matrix/index.js +2 -0
- package/dist/core/renderer/FrameRenderer.d.ts +37 -0
- package/dist/core/renderer/FrameRenderer.js +75 -0
- package/dist/core/renderer/ProgressReporter.d.ts +19 -0
- package/dist/core/renderer/ProgressReporter.js +58 -0
- package/dist/core/renderer/Renderer.d.ts +36 -0
- package/dist/core/renderer/Renderer.js +102 -0
- package/dist/core/renderer/drawMobject.d.ts +8 -0
- package/dist/core/renderer/drawMobject.js +109 -0
- package/dist/core/renderer/formats/index.d.ts +3 -0
- package/dist/core/renderer/formats/index.js +3 -0
- package/dist/core/renderer/formats/png.d.ts +5 -0
- package/dist/core/renderer/formats/png.js +7 -0
- package/dist/core/renderer/formats/sprite.d.ts +6 -0
- package/dist/core/renderer/formats/sprite.js +24 -0
- package/dist/core/renderer/formats/video.d.ts +8 -0
- package/dist/core/renderer/formats/video.js +51 -0
- package/dist/core/renderer/index.d.ts +7 -0
- package/dist/core/renderer/index.js +9 -0
- package/dist/core/renderer/types.d.ts +87 -0
- package/dist/core/renderer/types.js +13 -0
- package/dist/core/scene/Scene.d.ts +104 -0
- package/dist/core/scene/Scene.js +225 -0
- package/dist/core/scene/index.d.ts +2 -0
- package/dist/core/scene/index.js +1 -0
- package/dist/core/scene/types.d.ts +23 -0
- package/dist/core/scene/types.js +0 -0
- package/dist/core/serialization/animation.d.ts +23 -0
- package/dist/core/serialization/animation.js +176 -0
- package/dist/core/serialization/easingLookup.d.ts +13 -0
- package/dist/core/serialization/easingLookup.js +65 -0
- package/dist/core/serialization/index.d.ts +23 -0
- package/dist/core/serialization/index.js +29 -0
- package/dist/core/serialization/mobject.d.ts +23 -0
- package/dist/core/serialization/mobject.js +248 -0
- package/dist/core/serialization/prettyPrint.d.ts +12 -0
- package/dist/core/serialization/prettyPrint.js +16 -0
- package/dist/core/serialization/primitives.d.ts +24 -0
- package/dist/core/serialization/primitives.js +98 -0
- package/dist/core/serialization/registry.d.ts +29 -0
- package/dist/core/serialization/registry.js +39 -0
- package/dist/core/serialization/scene.d.ts +28 -0
- package/dist/core/serialization/scene.js +114 -0
- package/dist/core/serialization/types.d.ts +152 -0
- package/dist/core/serialization/types.js +6 -0
- package/dist/core/timeline/Timeline.d.ts +70 -0
- package/dist/core/timeline/Timeline.js +144 -0
- package/dist/core/timeline/index.d.ts +5 -0
- package/dist/core/timeline/index.js +4 -0
- package/dist/core/timeline/types.d.ts +29 -0
- package/dist/core/timeline/types.js +0 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +22 -0
- package/dist/mobjects/Mobject.d.ts +98 -0
- package/dist/mobjects/Mobject.js +343 -0
- package/dist/mobjects/VGroup/VGroup.d.ts +51 -0
- package/dist/mobjects/VGroup/VGroup.js +142 -0
- package/dist/mobjects/VGroup/index.d.ts +3 -0
- package/dist/mobjects/VGroup/index.js +2 -0
- package/dist/mobjects/VGroup/layout.d.ts +20 -0
- package/dist/mobjects/VGroup/layout.js +139 -0
- package/dist/mobjects/VMobject.d.ts +106 -0
- package/dist/mobjects/VMobject.js +216 -0
- package/dist/mobjects/geometry/Arc.d.ts +8 -0
- package/dist/mobjects/geometry/Arc.js +46 -0
- package/dist/mobjects/geometry/Arrow.d.ts +7 -0
- package/dist/mobjects/geometry/Arrow.js +34 -0
- package/dist/mobjects/geometry/Circle.d.ts +4 -0
- package/dist/mobjects/geometry/Circle.js +10 -0
- package/dist/mobjects/geometry/Line.d.ts +8 -0
- package/dist/mobjects/geometry/Line.js +19 -0
- package/dist/mobjects/geometry/Point.d.ts +5 -0
- package/dist/mobjects/geometry/Point.js +11 -0
- package/dist/mobjects/geometry/Polygon.d.ts +7 -0
- package/dist/mobjects/geometry/Polygon.js +21 -0
- package/dist/mobjects/geometry/Rectangle.d.ts +6 -0
- package/dist/mobjects/geometry/Rectangle.js +18 -0
- package/dist/mobjects/geometry/index.d.ts +7 -0
- package/dist/mobjects/geometry/index.js +7 -0
- package/dist/mobjects/graph/Graph.d.ts +28 -0
- package/dist/mobjects/graph/Graph.js +119 -0
- package/dist/mobjects/graph/GraphEdge.d.ts +26 -0
- package/dist/mobjects/graph/GraphEdge.js +64 -0
- package/dist/mobjects/graph/GraphNode.d.ts +19 -0
- package/dist/mobjects/graph/GraphNode.js +63 -0
- package/dist/mobjects/graph/index.d.ts +5 -0
- package/dist/mobjects/graph/index.js +5 -0
- package/dist/mobjects/graph/layouts/circular.d.ts +8 -0
- package/dist/mobjects/graph/layouts/circular.js +23 -0
- package/dist/mobjects/graph/layouts/forceDirected.d.ts +9 -0
- package/dist/mobjects/graph/layouts/forceDirected.js +102 -0
- package/dist/mobjects/graph/layouts/index.d.ts +3 -0
- package/dist/mobjects/graph/layouts/index.js +3 -0
- package/dist/mobjects/graph/layouts/tree.d.ts +9 -0
- package/dist/mobjects/graph/layouts/tree.js +99 -0
- package/dist/mobjects/graph/types.d.ts +35 -0
- package/dist/mobjects/graph/types.js +0 -0
- package/dist/mobjects/index.d.ts +6 -0
- package/dist/mobjects/index.js +6 -0
- package/dist/mobjects/text/Glyph.d.ts +11 -0
- package/dist/mobjects/text/Glyph.js +72 -0
- package/dist/mobjects/text/Text.d.ts +19 -0
- package/dist/mobjects/text/Text.js +76 -0
- package/dist/mobjects/text/index.d.ts +4 -0
- package/dist/mobjects/text/index.js +3 -0
- package/dist/mobjects/text/types.d.ts +12 -0
- package/dist/mobjects/text/types.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization types and interfaces.
|
|
3
|
+
*
|
|
4
|
+
* All serialized types are plain JSON-compatible objects that represent
|
|
5
|
+
* the state of a component in a format that can be persisted or transmitted.
|
|
6
|
+
*/
|
|
7
|
+
import type { PathCommandType } from '../math/bezier/types';
|
|
8
|
+
/** Serialized 2D vector */
|
|
9
|
+
export interface SerializedVector2 {
|
|
10
|
+
readonly x: number;
|
|
11
|
+
readonly y: number;
|
|
12
|
+
}
|
|
13
|
+
/** Serialized RGBA color */
|
|
14
|
+
export interface SerializedColor {
|
|
15
|
+
readonly r: number;
|
|
16
|
+
readonly g: number;
|
|
17
|
+
readonly b: number;
|
|
18
|
+
readonly a: number;
|
|
19
|
+
}
|
|
20
|
+
/** Serialized 3x3 transformation matrix */
|
|
21
|
+
export interface SerializedMatrix3x3 {
|
|
22
|
+
readonly values: readonly number[];
|
|
23
|
+
}
|
|
24
|
+
/** Serialized Bezier path command */
|
|
25
|
+
export interface SerializedPathCommand {
|
|
26
|
+
readonly type: PathCommandType;
|
|
27
|
+
readonly end: SerializedVector2;
|
|
28
|
+
readonly control1?: SerializedVector2;
|
|
29
|
+
readonly control2?: SerializedVector2;
|
|
30
|
+
}
|
|
31
|
+
/** Serialized Bezier path composed of multiple commands */
|
|
32
|
+
export interface SerializedBezierPath {
|
|
33
|
+
readonly commands: readonly SerializedPathCommand[];
|
|
34
|
+
}
|
|
35
|
+
/** Type discriminator for polymorphic deserialization */
|
|
36
|
+
export type MobjectType = 'Mobject' | 'VMobject' | 'VGroup' | 'Circle' | 'Rectangle' | 'Line' | 'Arrow' | 'Arc' | 'Polygon' | 'Point' | 'Text' | 'Glyph' | 'Graph' | 'GraphNode' | 'GraphEdge' | string;
|
|
37
|
+
/** Base properties for all serialized Mobjects */
|
|
38
|
+
export interface SerializedMobject {
|
|
39
|
+
readonly type: MobjectType;
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly matrix: SerializedMatrix3x3;
|
|
42
|
+
readonly opacity: number;
|
|
43
|
+
}
|
|
44
|
+
/** Serialized properties for Vector Mobjects (VMobjects) */
|
|
45
|
+
export interface SerializedVMobject extends SerializedMobject {
|
|
46
|
+
readonly paths: readonly SerializedBezierPath[];
|
|
47
|
+
readonly strokeColor: SerializedColor;
|
|
48
|
+
readonly strokeWidth: number;
|
|
49
|
+
readonly fillColor: SerializedColor;
|
|
50
|
+
readonly fillOpacity: number;
|
|
51
|
+
}
|
|
52
|
+
export interface SerializedVGroup extends SerializedMobject {
|
|
53
|
+
readonly children: readonly SerializedMobject[];
|
|
54
|
+
}
|
|
55
|
+
export interface SerializedCircle extends SerializedVMobject {
|
|
56
|
+
readonly type: 'Circle';
|
|
57
|
+
readonly radius: number;
|
|
58
|
+
}
|
|
59
|
+
export interface SerializedRectangle extends SerializedVMobject {
|
|
60
|
+
readonly type: 'Rectangle';
|
|
61
|
+
readonly width: number;
|
|
62
|
+
readonly height: number;
|
|
63
|
+
}
|
|
64
|
+
export interface SerializedLine extends SerializedVMobject {
|
|
65
|
+
readonly type: 'Line';
|
|
66
|
+
readonly start: SerializedVector2;
|
|
67
|
+
readonly end: SerializedVector2;
|
|
68
|
+
}
|
|
69
|
+
export interface SerializedArc extends SerializedVMobject {
|
|
70
|
+
readonly type: 'Arc';
|
|
71
|
+
readonly radius: number;
|
|
72
|
+
readonly startAngle: number;
|
|
73
|
+
readonly endAngle: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SerializedPolygon extends SerializedVMobject {
|
|
76
|
+
readonly type: 'Polygon';
|
|
77
|
+
readonly vertices: readonly SerializedVector2[];
|
|
78
|
+
}
|
|
79
|
+
export interface SerializedPoint extends SerializedVMobject {
|
|
80
|
+
readonly type: 'Point';
|
|
81
|
+
readonly position: SerializedVector2;
|
|
82
|
+
}
|
|
83
|
+
export type AnimationType = 'FadeIn' | 'FadeOut' | 'MoveTo' | 'Rotate' | 'Scale' | 'MorphTo' | 'Create' | 'Draw' | 'Write' | 'Unwrite' | 'Sequence' | 'Parallel' | 'KeyframeAnimation' | string;
|
|
84
|
+
export interface SerializedAnimationConfig {
|
|
85
|
+
readonly durationSeconds: number;
|
|
86
|
+
readonly delaySeconds: number;
|
|
87
|
+
readonly easingName: string;
|
|
88
|
+
}
|
|
89
|
+
/** Base properties for all serialized animations */
|
|
90
|
+
export interface SerializedAnimation {
|
|
91
|
+
readonly type: AnimationType;
|
|
92
|
+
readonly targetId: string;
|
|
93
|
+
readonly config: SerializedAnimationConfig;
|
|
94
|
+
}
|
|
95
|
+
export interface SerializedMoveTo extends SerializedAnimation {
|
|
96
|
+
readonly type: 'MoveTo';
|
|
97
|
+
readonly destination: SerializedVector2;
|
|
98
|
+
}
|
|
99
|
+
export interface SerializedRotate extends SerializedAnimation {
|
|
100
|
+
readonly type: 'Rotate';
|
|
101
|
+
readonly angle: number;
|
|
102
|
+
}
|
|
103
|
+
export interface SerializedScale extends SerializedAnimation {
|
|
104
|
+
readonly type: 'Scale';
|
|
105
|
+
readonly factor: number;
|
|
106
|
+
}
|
|
107
|
+
export interface SerializedMorphTo extends SerializedAnimation {
|
|
108
|
+
readonly type: 'MorphTo';
|
|
109
|
+
readonly targetShapeId: string;
|
|
110
|
+
}
|
|
111
|
+
export interface SerializedSequence extends SerializedAnimation {
|
|
112
|
+
readonly type: 'Sequence';
|
|
113
|
+
readonly animations: readonly SerializedAnimation[];
|
|
114
|
+
}
|
|
115
|
+
export interface SerializedParallel extends SerializedAnimation {
|
|
116
|
+
readonly type: 'Parallel';
|
|
117
|
+
readonly animations: readonly SerializedAnimation[];
|
|
118
|
+
}
|
|
119
|
+
export interface SerializedScheduledAnimation {
|
|
120
|
+
readonly animation: SerializedAnimation;
|
|
121
|
+
readonly startTime: number;
|
|
122
|
+
}
|
|
123
|
+
/** Serialized timeline state including all scheduled animations */
|
|
124
|
+
export interface SerializedTimeline {
|
|
125
|
+
readonly loop: boolean;
|
|
126
|
+
readonly scheduled: readonly SerializedScheduledAnimation[];
|
|
127
|
+
}
|
|
128
|
+
export interface SerializedSceneConfig {
|
|
129
|
+
readonly width: number;
|
|
130
|
+
readonly height: number;
|
|
131
|
+
readonly backgroundColor: SerializedColor;
|
|
132
|
+
readonly frameRate: number;
|
|
133
|
+
}
|
|
134
|
+
/** Top-level serialized scene container */
|
|
135
|
+
export interface SerializedScene {
|
|
136
|
+
readonly version: string;
|
|
137
|
+
readonly config: SerializedSceneConfig;
|
|
138
|
+
readonly mobjects: readonly SerializedMobject[];
|
|
139
|
+
readonly timeline: SerializedTimeline;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Interface for custom serializers.
|
|
143
|
+
*
|
|
144
|
+
* Allows extending the serialization system to support user-defined Mobject types.
|
|
145
|
+
*/
|
|
146
|
+
export interface CustomSerializer<T> {
|
|
147
|
+
readonly typeName: string;
|
|
148
|
+
/** Serialize an instance to a plain object */
|
|
149
|
+
serialize(instance: T): SerializedMobject;
|
|
150
|
+
/** Restore an instance from a plain object */
|
|
151
|
+
deserialize(data: SerializedMobject): T;
|
|
152
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Animation } from '../animations/Animation';
|
|
2
|
+
import type { ScheduledAnimation, TimelineConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Timeline schedules and controls playback of animations.
|
|
5
|
+
* Animations can be scheduled at specific times and the timeline
|
|
6
|
+
* provides seek/state access for non-linear playback.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Timeline {
|
|
9
|
+
private readonly scheduled;
|
|
10
|
+
private readonly config;
|
|
11
|
+
private currentTime;
|
|
12
|
+
constructor(config?: TimelineConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Schedule an animation to start at a specific time.
|
|
15
|
+
* @param animation The animation to schedule
|
|
16
|
+
* @param startTime Start time in seconds (default: 0)
|
|
17
|
+
*/
|
|
18
|
+
schedule(animation: Animation, startTime?: number): this;
|
|
19
|
+
/**
|
|
20
|
+
* Schedule multiple animations to play in sequence.
|
|
21
|
+
* First animation starts at the given startTime, subsequent
|
|
22
|
+
* animations start after the previous one ends.
|
|
23
|
+
* @param animations Animations to schedule sequentially
|
|
24
|
+
* @param startTime Start time for the first animation (default: 0)
|
|
25
|
+
*/
|
|
26
|
+
scheduleSequence(animations: Animation[], startTime?: number): this;
|
|
27
|
+
/**
|
|
28
|
+
* Schedule multiple animations to play in parallel.
|
|
29
|
+
* All animations start at the same time.
|
|
30
|
+
* @param animations Animations to schedule in parallel
|
|
31
|
+
* @param startTime Start time for all animations (default: 0)
|
|
32
|
+
*/
|
|
33
|
+
scheduleParallel(animations: Animation[], startTime?: number): this;
|
|
34
|
+
/**
|
|
35
|
+
* Get all scheduled animations with resolved timing information.
|
|
36
|
+
*/
|
|
37
|
+
private getResolved;
|
|
38
|
+
/**
|
|
39
|
+
* Get total duration of the timeline.
|
|
40
|
+
* Returns the end time of the last animation to finish.
|
|
41
|
+
*/
|
|
42
|
+
getTotalDuration(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Seek to a specific time and update all animations.
|
|
45
|
+
* @param time Time in seconds to seek to
|
|
46
|
+
*/
|
|
47
|
+
seek(time: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get the timeline state at a specific time without modifying the
|
|
50
|
+
* current playhead position.
|
|
51
|
+
* @param time Time in seconds
|
|
52
|
+
*/
|
|
53
|
+
getStateAt(time: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current time of the timeline.
|
|
56
|
+
*/
|
|
57
|
+
getCurrentTime(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Get all scheduled animations.
|
|
60
|
+
*/
|
|
61
|
+
getScheduled(): readonly ScheduledAnimation[];
|
|
62
|
+
/**
|
|
63
|
+
* Check if timeline is configured to loop.
|
|
64
|
+
*/
|
|
65
|
+
isLooping(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Clear all scheduled animations.
|
|
68
|
+
*/
|
|
69
|
+
clear(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeline schedules and controls playback of animations.
|
|
3
|
+
* Animations can be scheduled at specific times and the timeline
|
|
4
|
+
* provides seek/state access for non-linear playback.
|
|
5
|
+
*/
|
|
6
|
+
export class Timeline {
|
|
7
|
+
scheduled = [];
|
|
8
|
+
config;
|
|
9
|
+
currentTime = 0;
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
this.config = {
|
|
12
|
+
loop: config.loop ?? false,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Schedule an animation to start at a specific time.
|
|
17
|
+
* @param animation The animation to schedule
|
|
18
|
+
* @param startTime Start time in seconds (default: 0)
|
|
19
|
+
*/
|
|
20
|
+
schedule(animation, startTime = 0) {
|
|
21
|
+
if (startTime < 0) {
|
|
22
|
+
throw new Error('Start time must be non-negative');
|
|
23
|
+
}
|
|
24
|
+
this.scheduled.push({ animation, startTime });
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Schedule multiple animations to play in sequence.
|
|
29
|
+
* First animation starts at the given startTime, subsequent
|
|
30
|
+
* animations start after the previous one ends.
|
|
31
|
+
* @param animations Animations to schedule sequentially
|
|
32
|
+
* @param startTime Start time for the first animation (default: 0)
|
|
33
|
+
*/
|
|
34
|
+
scheduleSequence(animations, startTime = 0) {
|
|
35
|
+
let currentStart = startTime;
|
|
36
|
+
for (const anim of animations) {
|
|
37
|
+
this.schedule(anim, currentStart);
|
|
38
|
+
currentStart += anim.getDuration() + anim.getDelay();
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Schedule multiple animations to play in parallel.
|
|
44
|
+
* All animations start at the same time.
|
|
45
|
+
* @param animations Animations to schedule in parallel
|
|
46
|
+
* @param startTime Start time for all animations (default: 0)
|
|
47
|
+
*/
|
|
48
|
+
scheduleParallel(animations, startTime = 0) {
|
|
49
|
+
for (const anim of animations) {
|
|
50
|
+
this.schedule(anim, startTime);
|
|
51
|
+
}
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get all scheduled animations with resolved timing information.
|
|
56
|
+
*/
|
|
57
|
+
getResolved() {
|
|
58
|
+
return this.scheduled.map((s) => {
|
|
59
|
+
const delay = s.animation.getDelay();
|
|
60
|
+
const duration = s.animation.getDuration();
|
|
61
|
+
const effectiveStartTime = s.startTime + delay;
|
|
62
|
+
return {
|
|
63
|
+
animation: s.animation,
|
|
64
|
+
effectiveStartTime,
|
|
65
|
+
duration,
|
|
66
|
+
endTime: effectiveStartTime + duration,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get total duration of the timeline.
|
|
72
|
+
* Returns the end time of the last animation to finish.
|
|
73
|
+
*/
|
|
74
|
+
getTotalDuration() {
|
|
75
|
+
const resolved = this.getResolved();
|
|
76
|
+
if (resolved.length === 0)
|
|
77
|
+
return 0;
|
|
78
|
+
return Math.max(...resolved.map((r) => r.endTime));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Seek to a specific time and update all animations.
|
|
82
|
+
* @param time Time in seconds to seek to
|
|
83
|
+
*/
|
|
84
|
+
seek(time) {
|
|
85
|
+
const clampedTime = Math.max(0, time);
|
|
86
|
+
this.currentTime = clampedTime;
|
|
87
|
+
const resolved = this.getResolved();
|
|
88
|
+
for (const r of resolved) {
|
|
89
|
+
const { animation, effectiveStartTime, duration, endTime } = r;
|
|
90
|
+
if (clampedTime < effectiveStartTime) {
|
|
91
|
+
// Before animation starts - do NOT update the animation.
|
|
92
|
+
// This prevents future animations from overwriting state
|
|
93
|
+
// that earlier animations have already set.
|
|
94
|
+
// The animation will be initialized when it first becomes active.
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
else if (clampedTime >= endTime) {
|
|
98
|
+
// Animation completed - set to final state
|
|
99
|
+
animation.update(1);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Animation is active - calculate progress
|
|
103
|
+
const elapsed = clampedTime - effectiveStartTime;
|
|
104
|
+
const progress = duration > 0 ? elapsed / duration : 1;
|
|
105
|
+
animation.update(progress);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the timeline state at a specific time without modifying the
|
|
111
|
+
* current playhead position.
|
|
112
|
+
* @param time Time in seconds
|
|
113
|
+
*/
|
|
114
|
+
getStateAt(time) {
|
|
115
|
+
const savedTime = this.currentTime;
|
|
116
|
+
this.seek(time);
|
|
117
|
+
this.currentTime = savedTime;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the current time of the timeline.
|
|
121
|
+
*/
|
|
122
|
+
getCurrentTime() {
|
|
123
|
+
return this.currentTime;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get all scheduled animations.
|
|
127
|
+
*/
|
|
128
|
+
getScheduled() {
|
|
129
|
+
return this.scheduled;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if timeline is configured to loop.
|
|
133
|
+
*/
|
|
134
|
+
isLooping() {
|
|
135
|
+
return this.config.loop;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Clear all scheduled animations.
|
|
139
|
+
*/
|
|
140
|
+
clear() {
|
|
141
|
+
this.scheduled.length = 0;
|
|
142
|
+
this.currentTime = 0;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Animation } from '../animations/Animation';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an animation scheduled at a specific time on the Timeline.
|
|
4
|
+
*/
|
|
5
|
+
export interface ScheduledAnimation {
|
|
6
|
+
/** The animation to play */
|
|
7
|
+
readonly animation: Animation;
|
|
8
|
+
/** Start time in seconds from timeline beginning */
|
|
9
|
+
readonly startTime: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for Timeline.
|
|
13
|
+
*/
|
|
14
|
+
export interface TimelineConfig {
|
|
15
|
+
/** Whether the timeline loops. Default: false */
|
|
16
|
+
readonly loop?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Internal representation of a scheduled animation with computed timing.
|
|
20
|
+
*/
|
|
21
|
+
export interface ResolvedScheduledAnimation {
|
|
22
|
+
readonly animation: Animation;
|
|
23
|
+
/** Effective start time including animation delay */
|
|
24
|
+
readonly effectiveStartTime: number;
|
|
25
|
+
/** Duration of the animation */
|
|
26
|
+
readonly duration: number;
|
|
27
|
+
/** End time = effectiveStartTime + duration */
|
|
28
|
+
readonly endTime: number;
|
|
29
|
+
}
|
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { Scene } from './core/scene';
|
|
2
|
+
export type { SceneConfig } from './core/scene';
|
|
3
|
+
export { Mobject, VMobject, VGroup } from './mobjects';
|
|
4
|
+
export { Camera, CameraFrame } from './core/camera';
|
|
5
|
+
export type { CameraConfig, ResolvedCameraConfig } from './core/camera';
|
|
6
|
+
export { Circle, Rectangle, Line, Arrow, Arc, Polygon, Point } from './mobjects/geometry';
|
|
7
|
+
export { Text, Glyph } from './mobjects/text';
|
|
8
|
+
export type { TextStyle } from './mobjects/text';
|
|
9
|
+
export { Graph, GraphNode, GraphEdge } from './mobjects/graph';
|
|
10
|
+
export type { GraphNodeId, NodeConfig, EdgeConfig, LayoutType, LayoutConfig } from './mobjects/graph';
|
|
11
|
+
export { Animation, FadeIn, FadeOut, MoveTo, Rotate, Scale, MorphTo, Draw, Write, Unwrite, Sequence, Parallel, KeyframeTrack, KeyframeAnimation, Follow, Shake } from './core/animations';
|
|
12
|
+
export type { AnimationConfig, Keyframe } from './core/animations';
|
|
13
|
+
export { Color, Vector2 } from './core/math';
|
|
14
|
+
export { serialize, deserialize } from './core/serialization';
|
|
15
|
+
export { Timeline } from './core/timeline';
|
|
16
|
+
export type { ScheduledAnimation, TimelineConfig } from './core/timeline';
|
|
17
|
+
export { Renderer, FrameRenderer, ProgressReporter, Resolution } from './core/renderer';
|
|
18
|
+
export * from './core/animations/easing';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Core Classes - Essential for all users
|
|
2
|
+
export { Scene } from './core/scene';
|
|
3
|
+
// Mobjects - Visual objects that can be animated
|
|
4
|
+
export { Mobject, VMobject, VGroup } from './mobjects';
|
|
5
|
+
// Camera
|
|
6
|
+
export { Camera, CameraFrame } from './core/camera';
|
|
7
|
+
// Geometric Primitives
|
|
8
|
+
export { Circle, Rectangle, Line, Arrow, Arc, Polygon, Point } from './mobjects/geometry';
|
|
9
|
+
// Text and Graph - Advanced visualization
|
|
10
|
+
export { Text, Glyph } from './mobjects/text';
|
|
11
|
+
export { Graph, GraphNode, GraphEdge } from './mobjects/graph';
|
|
12
|
+
// FluentAPI - Chainable animations (built into mobjects above)
|
|
13
|
+
// No exports needed - methods are available on mobject instances
|
|
14
|
+
// ProAPI - Explicit animation objects for advanced users
|
|
15
|
+
export { Animation, FadeIn, FadeOut, MoveTo, Rotate, Scale, MorphTo, Draw, Write, Unwrite, Sequence, Parallel, KeyframeTrack, KeyframeAnimation, Follow, Shake } from './core/animations';
|
|
16
|
+
export { Color, Vector2 } from './core/math';
|
|
17
|
+
// Serialization - For saving/loading animations
|
|
18
|
+
export { serialize, deserialize } from './core/serialization';
|
|
19
|
+
export { Timeline } from './core/timeline';
|
|
20
|
+
export { Renderer, FrameRenderer, ProgressReporter, Resolution } from './core/renderer';
|
|
21
|
+
// Easing Functions - Essential for animation control
|
|
22
|
+
export * from './core/animations/easing';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Matrix3x3 } from '../core/math/matrix/Matrix3x3';
|
|
2
|
+
import { Vector2 } from '../core/math/Vector2/Vector2';
|
|
3
|
+
import { Animation } from '../core/animations/Animation';
|
|
4
|
+
import type { EasingFunction } from '../core/animations/easing';
|
|
5
|
+
/**
|
|
6
|
+
* Manages a queue of animations for fluent chaining.
|
|
7
|
+
* This is an internal implementation detail of Mobject's fluent API.
|
|
8
|
+
*/
|
|
9
|
+
declare class AnimationQueue {
|
|
10
|
+
private readonly target;
|
|
11
|
+
private readonly queue;
|
|
12
|
+
constructor(target: Mobject);
|
|
13
|
+
enqueueAnimation(animation: Animation<Mobject>): void;
|
|
14
|
+
setLastDuration(seconds: number): void;
|
|
15
|
+
setLastEasing(easing: EasingFunction): void;
|
|
16
|
+
isEmpty(): boolean;
|
|
17
|
+
popLastAnimation(): Animation<Mobject> | null;
|
|
18
|
+
toAnimation(): Animation<Mobject>;
|
|
19
|
+
getTotalDuration(): number;
|
|
20
|
+
}
|
|
21
|
+
interface MobjectState {
|
|
22
|
+
position: Vector2;
|
|
23
|
+
scale: Vector2;
|
|
24
|
+
rotation: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base class for all mathematical objects.
|
|
28
|
+
* Manages position, rotation, scale, and opacity via a local transformation matrix.
|
|
29
|
+
* Includes fluent animation API for chainable animations.
|
|
30
|
+
*/
|
|
31
|
+
export declare class Mobject {
|
|
32
|
+
protected localMatrix: Matrix3x3;
|
|
33
|
+
protected opacityValue: number;
|
|
34
|
+
protected animQueue: AnimationQueue | null;
|
|
35
|
+
private savedStates;
|
|
36
|
+
parent: Mobject | null;
|
|
37
|
+
constructor();
|
|
38
|
+
protected getQueue(): AnimationQueue;
|
|
39
|
+
get matrix(): Matrix3x3;
|
|
40
|
+
getWorldMatrix(): Matrix3x3;
|
|
41
|
+
get position(): Vector2;
|
|
42
|
+
get rotation(): number;
|
|
43
|
+
get scale(): Vector2;
|
|
44
|
+
get opacity(): number;
|
|
45
|
+
pos(x: number, y: number): this;
|
|
46
|
+
show(): this;
|
|
47
|
+
hide(): this;
|
|
48
|
+
setOpacity(value: number): this;
|
|
49
|
+
setRotation(angle: number): this;
|
|
50
|
+
setScale(sx: number, sy: number): this;
|
|
51
|
+
applyMatrix(m: Matrix3x3): this;
|
|
52
|
+
saveState(): this;
|
|
53
|
+
getSavedState(): MobjectState | undefined;
|
|
54
|
+
clearSavedStates(): this;
|
|
55
|
+
/**
|
|
56
|
+
* Animates back to the last saved state.
|
|
57
|
+
* Pops the saved state from the stack.
|
|
58
|
+
* @throws Error if no state was previously saved
|
|
59
|
+
*/
|
|
60
|
+
restore(durationSeconds?: number): this & {
|
|
61
|
+
toAnimation(): Animation<Mobject>;
|
|
62
|
+
};
|
|
63
|
+
private createAnimation;
|
|
64
|
+
fadeIn(durationSeconds?: number): this & {
|
|
65
|
+
toAnimation(): Animation<Mobject>;
|
|
66
|
+
};
|
|
67
|
+
fadeOut(durationSeconds?: number): this & {
|
|
68
|
+
toAnimation(): Animation<Mobject>;
|
|
69
|
+
};
|
|
70
|
+
moveTo(x: number, y: number, durationSeconds?: number): this & {
|
|
71
|
+
toAnimation(): Animation<Mobject>;
|
|
72
|
+
};
|
|
73
|
+
rotate(angle: number, durationSeconds?: number): this & {
|
|
74
|
+
toAnimation(): Animation<Mobject>;
|
|
75
|
+
};
|
|
76
|
+
scaleTo(factor: number, durationSeconds?: number): this & {
|
|
77
|
+
toAnimation(): Animation<Mobject>;
|
|
78
|
+
};
|
|
79
|
+
scaleToXY(factorX: number, factorY: number, durationSeconds?: number): this & {
|
|
80
|
+
toAnimation(): Animation<Mobject>;
|
|
81
|
+
};
|
|
82
|
+
duration(seconds: number): this;
|
|
83
|
+
ease(easing: EasingFunction): this;
|
|
84
|
+
toAnimation(): Animation<Mobject>;
|
|
85
|
+
getQueuedDuration(): number;
|
|
86
|
+
hasQueuedAnimations(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Queues multiple animations to run in parallel (simultaneously).
|
|
89
|
+
* Automatically handles both Animation objects and mobject method calls.
|
|
90
|
+
* @example
|
|
91
|
+
* circle.fadeIn(1).parallel(
|
|
92
|
+
* circle.moveTo(100, 50),
|
|
93
|
+
* circle.rotate(Math.PI)
|
|
94
|
+
* ).fadeOut(1);
|
|
95
|
+
*/
|
|
96
|
+
parallel(...items: (Animation<Mobject> | Mobject)[]): this;
|
|
97
|
+
}
|
|
98
|
+
export {};
|