import Timeline from '../Timeline'; import { Animator } from './Animator'; import Clip from './Clip'; import { AnimationEasing } from './easing'; type NumberArray = { [key: number]: number; readonly length: number; }; type InterpolatableType = string | number | NumberArray | NumberArray[]; export declare function cloneValue(value: InterpolatableType): number | any[]; type ValueType = 0 | 1 | 2 | 3 | 4 | 5 | 6; type Keyframe = { time: number; value: unknown; percent: number; rawValue: unknown; easingFunc?: (percent: number) => number; additiveValue?: unknown; }; declare class Track { keyframes: Keyframe[]; propName: string; valType: ValueType; discrete: boolean; _invalid: boolean; private _finished?; private _needsSort; private _additiveTrack?; private _additiveValue; /** * Last frame */ private _lastFr; /** * Percent of last frame. */ private _lastFrP; constructor(propName: string); isFinished(): boolean | undefined; setFinished(): void; needsAnimate(): boolean; getAdditiveTrack(): Track | undefined; addKeyframe(time: number, rawValue: unknown, easing?: AnimationEasing): Keyframe; prepare(maxTime: number, additiveTrack?: Track): void; step(target: any, percent: number): void; private _addToTarget; } type DoneCallback = () => void; type AbortCallback = () => void; export type OnframeCallback = (target: T, percent: number) => void; export type AnimationPropGetter = (target: T, key: string) => InterpolatableType; export type AnimationPropSetter = (target: T, key: string, value: InterpolatableType) => void; export default class ProceduralKeyframeAnimator implements Animator { timeline?: Timeline; targetName?: string; scope?: string; __fromStateTransition?: string; private _tracks; private _trackKeys; private _target; private _loop?; private _delay; private _maxTime; /** * If force run regardless of empty tracks when duration is set. */ private _force?; /** * If animator is paused * @default false */ private _paused?; private _started; /** * If allow discrete animation * @default false */ private _allowDiscrete?; private _additiveAnimators?; private _doneCbs; private _onframeCbs; private _abortedCbs; private _clip?; constructor(target: T, loop?: boolean, allowDiscreteAnimation?: boolean, // If doing discrete animation on the values can't be interpolated additiveTo?: ProceduralKeyframeAnimator[]); getMaxTime(): number; getDelay(): number; getLoop(): boolean | undefined; getTarget(): T; /** * Target can be changed during animation * For example if style is changed during state change. * We need to change target to the new style object. */ changeTarget(target: T): void; /** * Set Animation keyframe * @param time time of keyframe in ms * @param props key-value props of keyframe. * @param easing */ when(time: number, props: Record, easing?: AnimationEasing): this; whenWithKeys(time: number, props: Record, propNames: string[], easing?: AnimationEasing): this; pause(): void; resume(): void; isPaused(): boolean; /** * Set duration of animator. * Will run this duration regardless the track max time or if trackes exits. * @param duration * @returns */ duration(duration: number): this; private _doneCallback; private _abortedCallback; private _setTracksFinished; private _getAdditiveTrack; /** * Start the animation * @param easing * @return */ start(easing?: AnimationEasing): this | undefined; /** * Stop animation * @param {boolean} forwardToLast If move to last frame before stop */ stop(forwardToLast?: boolean): void; /** * Set when animation delay starts * @param time 单位ms */ delay(time: number): this; /** * 添加动画每一帧的回调函数 * @param callback */ during(cb?: OnframeCallback): this; /** * Add callback for animation end * @param cb */ done(cb?: DoneCallback): this; aborted(cb?: AbortCallback): this; getClip(): Clip | undefined; getTrack(propName: string): Track; getTracks(): Track[]; /** * Return true if animator is not available anymore. */ stopTracks(propNames: string[], forwardToLast?: boolean): boolean; } export type AnimatorTrack = Track; export {};