Skip to content

Commit 187609e

Browse files
committed
abstract away entirety of blob generation out of state management
1 parent 3065edc commit 187609e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

internal/animate/state.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import {TimingFunc, timingFunctions} from "./timing";
22
import {Point} from "../types";
33
import {prepare} from "./prepare";
44
import {interpolateBetween} from "./interpolate";
5-
import {BlobOptions} from "../../public/blobs";
65

76
export interface Keyframe {
87
delay?: number;
98
duration: number;
109
timingFunction?: keyof typeof timingFunctions;
11-
blobOptions: BlobOptions;
1210
}
1311

1412
export interface InternalKeyframe {
@@ -38,9 +36,9 @@ export interface RenderOutput {
3836
renderCache: RenderCache;
3937
}
4038

41-
export interface TransitionInput extends RenderInput {
42-
newFrames: Keyframe[];
43-
blobGenerator: <T extends Keyframe>(options: T) => Point[],
39+
export interface TransitionInput<T extends Keyframe> extends RenderInput {
40+
newFrames: T[];
41+
blobGenerator:(options: T) => Point[],
4442
}
4543

4644
export interface TransitionOutput {
@@ -126,7 +124,7 @@ export const renderFramesAt = (input: RenderInput): RenderOutput => {
126124
// TODO generate internal frames. Delayed frames can just copy the previous one.
127125
// TODO store current blob when interrupts happen to use as source.
128126
// TODO don't remove any frames.
129-
export const transitionFrames = (input: TransitionInput): TransitionOutput => {
127+
export const transitionFrames = <T extends Keyframe>(input: TransitionInput<T>): TransitionOutput => {
130128
const {renderCache, timestamp, newFrames} = input;
131129

132130
// Wipe animation when given no keyframes.

public/animate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CanvasOptions} from "./blobs";
1+
import {CanvasOptions, BlobOptions} from "./blobs";
22
import {Point} from "../internal/types";
33
import {renderPath2D} from "../internal/render/canvas";
44
import {genFromOptions} from "../internal/gen";
@@ -23,6 +23,7 @@ interface CallbackKeyframe extends Keyframe {
2323
}
2424

2525
export interface CanvasKeyframe extends CallbackKeyframe {
26+
blobOptions: BlobOptions;
2627
canvasOptions?: CanvasOptions;
2728
}
2829

@@ -79,7 +80,7 @@ export const canvasPath = (): CanvasAnimation => {
7980

8081
const transition: CanvasAnimation["transition"] = (...keyframes) => {
8182
const transitionTime = Date.now();
82-
const transitionOutput = transitionFrames({
83+
const transitionOutput = transitionFrames<CanvasKeyframe>({
8384
renderCache: renderCache,
8485
timestamp: transitionTime,
8586
currentFrames: internalFrames,

0 commit comments

Comments
 (0)