@@ -16,6 +16,7 @@ export interface InternalKeyframe {
1616 timestamp : number ;
1717 timingFunction : TimingFunc ;
1818 initialPoints : Point [ ] ;
19+ transitionSourceFrameIndex : number | null ;
1920}
2021
2122export interface RenderCache {
@@ -26,7 +27,7 @@ export interface RenderCache {
2627}
2728
2829export interface RenderInput {
29- keyframes : InternalKeyframe [ ] ;
30+ currentFrames : InternalKeyframe [ ] ;
3031 timestamp : number ;
3132 cache : RenderCache ;
3233}
@@ -42,7 +43,7 @@ export interface TransitionInput extends RenderInput {
4243}
4344
4445export interface TransitionOutput {
45- frames : InternalKeyframe [ ] ;
46+ newFrames : InternalKeyframe [ ] ;
4647 cache : RenderCache ;
4748}
4849
@@ -61,25 +62,25 @@ export const removeStaleFrames = (
6162} ;
6263
6364export const renderFramesAt = ( input : RenderInput ) : RenderOutput => {
64- const { cache, keyframes } = input ;
65+ const { cache, currentFrames } = input ;
6566
66- if ( keyframes . length === 0 ) {
67+ if ( currentFrames . length === 0 ) {
6768 return { cache, lastFrameId : null , points : [ ] } ;
6869 }
6970
7071 // Animation freezes at the final shape if there are no more keyframes.
71- if ( keyframes . length === 1 ) {
72- const first = keyframes [ 0 ] ;
72+ if ( currentFrames . length === 1 ) {
73+ const first = currentFrames [ 0 ] ;
7374 return { cache, lastFrameId : first . id , points : first . initialPoints } ;
7475 }
7576
7677 // Find the start/end keyframes according to the timestamp.
77- let startKeyframe = keyframes [ 0 ] ;
78- let endKeyframe = keyframes [ 1 ] ;
79- for ( let i = 2 ; i < keyframes . length ; i ++ ) {
78+ let startKeyframe = currentFrames [ 0 ] ;
79+ let endKeyframe = currentFrames [ 1 ] ;
80+ for ( let i = 2 ; i < currentFrames . length ; i ++ ) {
8081 if ( endKeyframe . timestamp < input . timestamp ) break ;
81- startKeyframe = keyframes [ i - 1 ] ;
82- endKeyframe = keyframes [ i ] ;
82+ startKeyframe = currentFrames [ i - 1 ] ;
83+ endKeyframe = currentFrames [ i ] ;
8384 }
8485
8586 // Use and cache prepared points for current interpolation.
@@ -108,15 +109,22 @@ export const renderFramesAt = (input: RenderInput): RenderOutput => {
108109 cache,
109110 lastFrameId : startKeyframe . id ,
110111 points : interpolateBetween ( adjustedProgress , preparedStartPoints , preparedEndPoints ) ,
111- }
112+ } ;
112113} ;
113114
115+ // TODO render cache cleaner.
116+
114117// TODO generate internal frames. Delayed frames can just copy the previous one.
115118// TODO store current blob when interrupts happen to use as source.
116119// TODO don't remove any frames.
117120export const transitionFrames = ( input : TransitionInput ) : TransitionOutput => {
118121 const { cache, timestamp, newFrames} = input ;
119122
123+ // Wipe animation when given no keyframes.
124+ if ( input . newFrames . length === 0 ) {
125+ return { cache : input . cache , newFrames : [ ] } ;
126+ }
127+
120128 // Add current state as initial frame.
121129 const currentState = renderFramesAt ( input ) ;
122130 let internalFrames : InternalKeyframe [ ] = [
@@ -125,6 +133,7 @@ export const transitionFrames = (input: TransitionInput): TransitionOutput => {
125133 initialPoints : currentState . points ,
126134 timestamp : timestamp ,
127135 timingFunction : ( p ) => p ,
136+ transitionSourceFrameIndex : null ,
128137 } ,
129138 ] ;
130139
@@ -135,5 +144,5 @@ export const transitionFrames = (input: TransitionInput): TransitionOutput => {
135144 }
136145 }
137146
138- return { cache, frames : internalFrames } ;
147+ return { cache, newFrames : internalFrames } ;
139148} ;
0 commit comments