import { Tween } from '../tween'; import { TweenOptions } from '../opts'; import { TweenFromStep } from './tween-from-step'; import { TweenToStep } from './tween-to-step'; import { TweenWithStep } from './tween-with-step'; import { DeepPartial } from '../../deep-partial'; /** * Builds instances of Tween using an ordered process of steps, as an alternative to the constructor syntax. * @template T The type of the value to be tweened. */ export class TweenStepBuilder implements TweenFromStep, TweenToStep, TweenWithStep { private target?: T; private destination?: DeepPartial; public get(target: T): TweenToStep { this.target = target; return this; } /** * @param destination The value to interpolate towards. * @returns The next step in the building process, where the configuration of the Tween is provided. */ public to(destination: DeepPartial): TweenWithStep { this.destination = destination; return this; } /** * Complete the construction of the Tween, using the provided options. * @param options The options/configuration to provide to the Tween. * @returns The completed Tween. */ public with(options: TweenOptions): Tween { if (this.target == null || this.destination == null) { throw Error('Missing information required to create Tween.'); } return Tween.start(this.target, this.destination, options); } } export namespace TweenStepBuilder { export interface ToStep extends TweenToStep { }; export interface FromStep extends TweenFromStep {}; export interface WithStep extends TweenWithStep {}; }