/
githubmirror
/
anime
Обзор
Документация
Войти
/
githubmirror
/
anime
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/utils/time.js
60 строк
2 KB
Julian Garnier
4.5.0
22 июн 2026, 17:32
22 июн 2026, 17:32
34f4179
Код
Авторство
О чём код?
import { noop, } from '../core/consts.js'; import { globals, } from '../core/globals.js'; import { isFnc, isUnd, } from '../core/helpers.js'; import { Timer, } from '../timer/timer.js'; /** * @import { * Callback, * Tickable, * } from '../types/index.js' */ /** * @param {Callback<Timer>} [callback] * @return {Timer} */ export const sync = (callback = noop) => { return new Timer({ duration: 1 * globals.timeScale, onComplete: callback }, null, 0).resume(); } /** * @template {Tickable | ((...args: any[]) => void) | void} T * @param {(...args: any[]) => T} constructor * @return {(...args: any[]) => T extends void ? () => void : T} */ export const keepTime = constructor => { /** @type {Tickable} */ let tracked; return /** @type {(...args: any[]) => T extends void ? () => void : T} */(/** @type {*} */((...args) => { let currentIteration, currentIterationProgress, reversed, alternate, startTime; if (tracked) { currentIteration = tracked.currentIteration; currentIterationProgress = tracked.iterationProgress; reversed = tracked.reversed; alternate = tracked._alternate; startTime = tracked._startTime; tracked.revert(); } const cleanup = constructor(...args); if (cleanup && !isFnc(cleanup) && cleanup.revert) tracked = cleanup; if (!isUnd(currentIterationProgress)) { /** @type {Tickable} */(tracked).currentIteration = currentIteration; /** @type {Tickable} */(tracked).iterationProgress = (alternate ? !(currentIteration % 2) ? reversed : !reversed : reversed) ? 1 - currentIterationProgress : currentIterationProgress; /** @type {Tickable} */(tracked)._startTime = startTime; } return cleanup || noop; })); }