calc-duration.mjs 533 B

1234567891011121314151617
  1. /**
  2. * Implement a practical max duration for keyframe generation
  3. * to prevent infinite loops
  4. */
  5. const maxGeneratorDuration = 20000;
  6. function calcGeneratorDuration(generator) {
  7. let duration = 0;
  8. const timeStep = 50;
  9. let state = generator.next(duration);
  10. while (!state.done && duration < maxGeneratorDuration) {
  11. duration += timeStep;
  12. state = generator.next(duration);
  13. }
  14. return duration >= maxGeneratorDuration ? Infinity : duration;
  15. }
  16. export { calcGeneratorDuration, maxGeneratorDuration };