@lightningjs/renderer
Version:
Lightning 3 Renderer
63 lines • 2.09 kB
JavaScript
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2023 Comcast Cable Communications Management, LLC.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default class Transition {
data;
currentValue = null;
applyProgress = this.applyLinearProgress;
constructor(from, to, duration, delay, easing) {
this.data = [from, to, duration, delay, easing];
if (easing !== null) {
this.applyProgress = this.applyEasedProgress;
}
}
// This function only gets called if an easing function is provided
applyEasedProgress(from, to, p) {
return from + (to - from) * this.data[4](p);
}
// This function gets called if no easing function is provided (linear)
applyLinearProgress(from, to, p) {
return from + (to - from) * p;
}
update(animationTime) {
const [from, to, start, end] = this.data;
//calculate progress of transition
let p = (animationTime - start) / (end - start);
return this.currentValue = this.applyProgress(from, to, p);
}
//only settable property is 'from' will be used on start of animation
set from(value) {
this.data[0] = value;
}
get from() {
return this.data[0];
}
get to() {
return this.data[1];
}
get start() {
return this.data[2];
}
get end() {
return this.data[3];
}
get easing() {
return this.data[4];
}
}
//# sourceMappingURL=CoreTransition.js.map