import type { AnimationOptions , AnimationType } from "./Animations" ; import { ANIMATIONS } from "./Animations" ; import type { AnimationObject , Animationable } from "kittik-animation-basic" ; export class AnimationBuilder < T extends AnimationType , O extends AnimationOptions < T > > implements AnimationObject < T , O > { public type : T ; public options : O ; public constructor ( type ) { this . type = type ; this . options = { } as unknown as O ; } public static start < T extends AnimationType , O extends AnimationOptions < T > > ( type ) { return new this ( type ) ; } public withType ( type ) { this . type = type ; return this ; } public withOptions ( options ) { this . options = { ... this . options , ... options } ; return this ; } public withDuration ( duration ) { this . options . duration = duration ; return this ; } public withEasing ( easing ) { this . options . easing = easing ; return this ; } public end ( ) { const ctr = ANIMATIONS . get ( this . type ) ; if ( typeof ctr === "undefined" ) { throw new Error ( `You tried to build an animation with the type "${ this . type }". ` + "But the animation of this type is not implemented or you made a typo." ) ; } return ctr . fromObject < T , O , Animationable > ( this ) ; } }