calc-time.mjs 539 B

1234567891011121314151617181920
  1. /**
  2. * Given a absolute or relative time definition and current/prev time state of the sequence,
  3. * calculate an absolute time for the next keyframes.
  4. */
  5. function calcNextTime(current, next, prev, labels) {
  6. if (typeof next === "number") {
  7. return next;
  8. }
  9. else if (next.startsWith("-") || next.startsWith("+")) {
  10. return Math.max(0, current + parseFloat(next));
  11. }
  12. else if (next === "<") {
  13. return prev;
  14. }
  15. else {
  16. return labels.get(next) ?? current;
  17. }
  18. }
  19. export { calcNextTime };