Socket
Socket
Sign inDemoInstall

frame-duration

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

10

index.d.ts

@@ -1,11 +0,11 @@

declare class FrameDuration {
declare const FrameDuration: {
times: number
duration: number
constructor(defaultDuration?: number)
update(currDuration: number): void
/**
* @return { Promise<number> } actual duration
* */
correct(): Promise<number>
}
export default FrameDuration
/**
* Bundle of frame-duration
* Generated: 2020-05-01
* Version: 1.0.1
* Version: 1.1.0
* License: MIT

@@ -9,80 +9,41 @@ * Author: 2631541504@qq.com

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var root = typeof window === 'undefined' ? global || {} : window;
var FrameDuration = {
times: 1,
duration: 1000 / 30,
update: function update(currDuration) {
// frameDuration usually not less than 1000 / 30
// and not greater than 1000 / 120
var $currDuration = Math.max(1000 / 120, Math.min(1000 / 30, currDuration));
this.times += 1;
this.duration = (this.duration + $currDuration) / 2;
},
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var FrameDuration = /*#__PURE__*/function () {
function FrameDuration(defaultDuration) {
_classCallCheck(this, FrameDuration);
_defineProperty(this, "times", 1);
_defineProperty(this, "duration", void 0);
// @ts-ignore
this.duration = +defaultDuration || 1000 / 30;
/**
* @return { Promise<number> } actual duration
* */
correct: function correct() {
var i = 0;
var last;
var that = this;
return new Promise(function (res) {
(function init() {
requestAnimationFrame(function (now) {
var $now = now || new Date().getTime();
(function init() {
if (typeof root.requestAnimationFrame === 'function') {
root.requestAnimationFrame(function (now) {
var $now = now || new Date().getTime();
if (last) {
that.update($now - last);
if (last) {
FrameDuration.update($now - last);
}
last = $now;
if (++i < 15) init();else res(FrameDuration.duration);
});
}
last = $now;
if (++i < 60) init();
});
})();
})();
});
}
};
FrameDuration.correct();
_createClass(FrameDuration, [{
key: "update",
value: function update(currDuration) {
// frameDuration usually not less than 1000 / 30
var $currDuration = Math.min(1000 / 30, currDuration);
this.times += 1;
this.duration = (this.duration + $currDuration) / 2;
}
}]);
return FrameDuration;
}();
export default FrameDuration;
/**
* Bundle of frame-duration
* Generated: 2020-05-01
* Version: 1.0.1
* Version: 1.1.0
* License: MIT

@@ -9,2 +9,2 @@ * 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";function r(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}return function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),a(this,"times",1),a(this,"duration",void 0),this.duration=+e||1e3/30;var i,r=0,o=this;!function n(){requestAnimationFrame(function(e){var t=e||(new Date).getTime();i&&o.update(t-i),i=t,++r<60&&n()})}()}var e,n,i;return e=t,(n=[{key:"update",value:function(e){var t=Math.min(1e3/30,e);this.times+=1,this.duration=(this.duration+t)/2}}])&&r(e.prototype,n),i&&r(e,i),t}()});
!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});
{
"name": "frame-duration",
"version": "1.0.1",
"description": "A lib for calculating the duration of frame dynamically, default is 1000 / 30",
"version": "1.1.0",
"description": "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.",
"main": "./lib/umd/index.js",

@@ -6,0 +6,0 @@ "module": "./lib/es/index.js",

# frame-duration
[![NPM Version](http://img.shields.io/npm/v/frame-duration.svg?style=flat-square)](https://www.npmjs.com/package/frame-duration)
[![Download Month](http://img.shields.io/npm/dm/frame-duration.svg?style=flat-square)](https://www.npmjs.com/package/frame-duration)
![gzip with dependencies: 1kb](https://img.shields.io/badge/gzip--with--dependencies-1kb-brightgreen.svg "gzip with dependencies: 1kb")
![gzip with dependencies: 0.5kb](https://img.shields.io/badge/gzip--with--dependencies-0.5kb-brightgreen.svg "gzip with dependencies: 0.5kb")
![typescript](https://img.shields.io/badge/typescript-supported-blue.svg "typescript")

@@ -9,3 +9,3 @@

A lib for calculating the duration of frame dynamically, default is 1000 / 30
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.

@@ -42,6 +42,11 @@ ## repository

const defaultDuration = 1000 / 45
const frameDuration = new FrameDuration(defaultDuration)
console.log(FrameDuration.duration) // -> 33.33
console.log(frameDuration) // -> { duration: 16.66, times: 60, update: [function] }
// 设置默认帧间隔。只在应用最初的时候设置默认
FrameDuration.duration = 1000 / 60
// 打印动态计算之后的帧间隔
setTimeout(() => {
console.log(FrameDuration.duration) // -> 16.66
}, 1000)
```

@@ -48,0 +53,0 @@

# frame-duration
[![NPM Version](http://img.shields.io/npm/v/frame-duration.svg?style=flat-square)](https://www.npmjs.com/package/frame-duration)
[![Download Month](http://img.shields.io/npm/dm/frame-duration.svg?style=flat-square)](https://www.npmjs.com/package/frame-duration)
![gzip with dependencies: 1kb](https://img.shields.io/badge/gzip--with--dependencies-1kb-brightgreen.svg "gzip with dependencies: 1kb")
![gzip with dependencies: 0.5kb](https://img.shields.io/badge/gzip--with--dependencies-0.5kb-brightgreen.svg "gzip with dependencies: 0.5kb")
![typescript](https://img.shields.io/badge/typescript-supported-blue.svg "typescript")

@@ -9,3 +9,3 @@

A lib for calculating the duration of frame dynamically, default is 1000 / 30
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.

@@ -42,6 +42,11 @@ ## repository

const defaultDuration = 1000 / 45
const frameDuration = new FrameDuration(defaultDuration)
console.log(FrameDuration.duration) // -> 33.33
console.log(frameDuration) // -> { duration: 16.66, times: 60, update: [function] }
// Set default duration. Make sure that this only run at the start of app
FrameDuration.duration = 1000 / 60
// Duration after dynamic calculate
setTimeout(() => {
console.log(FrameDuration.duration) // -> 16.66
}, 1000)
```

@@ -48,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc