import {Ticker} from '@/util/promise.js'; export default function delta(object, properties) { const deltas = {}; for (const key in properties) { const property = properties[key]; const delta = { duration: Infinity, elapsed: 0, ...property, }; deltas[key] = delta; } let stop; const promise = new Ticker( (resolve) => { stop = resolve; }, (elapsed, resolve) => { for (const key in deltas) { deltas[key].elapsed += elapsed; if (deltas[key].elapsed >= deltas[key].duration) { object[key] += deltas[key].delta * (deltas[key].duration - deltas[key].elapsed); resolve(); return; } object[key] += deltas[key].delta * elapsed; } }, ); return {stop, deltas, promise}; }