UNPKG

frame-duration

Version:

A lib for calculating the duration of frame dynamically, based on requestAnimationFrame, default is 1000 / 30. The actual duration will be calculated after 15 frames.

10 lines (8 loc) 772 B
/** * Bundle of frame-duration * Generated: 2020-05-01 * Version: 1.1.0 * License: MIT * Author: 2631541504@qq.com */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FrameDuration=t()}(this,function(){"use strict";var e="undefined"==typeof window?global||{}:window,u={times:1,duration:1e3/30,update:function(e){var t=Math.max(1e3/120,Math.min(1e3/30,e));this.times+=1,this.duration=(this.duration+t)/2},correct:function(){var o,r=0;return new Promise(function(i){!function n(){"function"==typeof e.requestAnimationFrame&&e.requestAnimationFrame(function(e){var t=e||(new Date).getTime();o&&u.update(t-o),o=t,++r<15?n():i(u.duration)})}()})}};return u.correct(),u});