UNPKG

@lightningjs/renderer

Version:
35 lines 1.19 kB
export function easedProgressFn(p) { return this.from + (this.to - this.from) * this.easing(p); } export function linearProgressFn(p) { return this.from + (this.to - this.from) * p; } export function updateTransition(animationTime) { //calculate progress of transition let p = (animationTime - this.delay) / this.duration; if (p >= 1) { p = 1; return (this.current = this.to); } if (p < 0) { p = 0; return (this.current = this.from); } return (this.current = this.progressFn(p)); } export function createTransition(props) { const easing = props.easing; //cast props to Transition to add new properties and methods without creating a new object const transition = props; // Convert string values to numbers and add new properties transition.to = props.to; transition.from = props.from; transition.current = (props.from ?? props.to); transition.progress = 0; transition.easing = easing; transition.update = updateTransition; transition.progressFn = easing !== undefined ? easedProgressFn : linearProgressFn; return transition; } //# sourceMappingURL=Transition.js.map