animation-js
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "animation-js", | ||
"description": "project description", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
132
src/index.js
'use strict'; | ||
import {Bezier} from 'amfe-cubicbezier'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
const FPS = 60; | ||
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _amfeCubicbezier = require('amfe-cubicbezier'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var FPS = 60; | ||
var INTERVAL = 1000 / FPS; | ||
@@ -16,17 +24,6 @@ | ||
var requestAnimationFrame = | ||
window.requestAnimationFrame || | ||
window.msRequestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
window.mozRequestAnimationFrame || | ||
setTimeoutFrame; | ||
var requestAnimationFrame = window.requestAnimationFrame || window.msRequestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || setTimeoutFrame; | ||
var cancelAnimationFrame = window.cancelAnimationFrame || window.msCancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || clearTimeoutFrame; | ||
var cancelAnimationFrame = | ||
window.cancelAnimationFrame || | ||
window.msCancelAnimationFrame || | ||
window.webkitCancelAnimationFrame || | ||
window.mozCancelAnimationFrame || | ||
clearTimeoutFrame; | ||
if (requestAnimationFrame === setTimeoutFrame || cancelAnimationFrame === clearTimeoutFrame) { | ||
@@ -39,3 +36,3 @@ requestAnimationFrame = setTimeoutFrame; | ||
var deferred = {}; | ||
var promise = new Promise((resolve, reject) => { | ||
var promise = new Promise(function (resolve, reject) { | ||
deferred.resolve = resolve; | ||
@@ -50,4 +47,4 @@ deferred.reject = reject; | ||
var _promise = promise; | ||
['then', 'catch'].forEach((method) => { | ||
context[method] = function() { | ||
['then', 'catch'].forEach(function (method) { | ||
context[method] = function () { | ||
return promise[method].apply(_promise, arguments); | ||
@@ -59,3 +56,2 @@ }; | ||
function getFrameQueue(duration, frames) { | ||
@@ -71,3 +67,5 @@ if (typeof frames === 'function') { | ||
var frameQueue = []; | ||
var frameKeys = Object.keys(frames).map(i => parseInt(i)); | ||
var frameKeys = Object.keys(frames).map(function (i) { | ||
return parseInt(i); | ||
}); | ||
@@ -95,13 +93,13 @@ for (var i = 0; i < frameCount; i++) { | ||
if (typeof timingFunction === 'string' || timingFunction instanceof Array) { | ||
if (Bezier) { | ||
if (_amfeCubicbezier.Bezier) { | ||
//console.error('require amfe-cubicbezier'); | ||
} else { | ||
if (typeof timingFunction === 'string') { | ||
if (Bezier[timingFunction]) { | ||
bezier = Bezier[timingFunction]; | ||
if (typeof timingFunction === 'string') { | ||
if (_amfeCubicbezier.Bezier[timingFunction]) { | ||
bezier = _amfeCubicbezier.Bezier[timingFunction]; | ||
} | ||
} else if (timingFunction instanceof Array && timingFunction.length === 4) { | ||
bezier = _amfeCubicbezier.Bezier.apply(_amfeCubicbezier.Bezier, timingFunction); | ||
} | ||
} else if (timingFunction instanceof Array && timingFunction.length === 4){ | ||
bezier = Bezier.apply(Bezier, timingFunction); | ||
} | ||
} | ||
} else if (typeof timingFunction === 'function') { | ||
@@ -122,3 +120,3 @@ bezier = timingFunction; | ||
var tick; | ||
var isCancel =false; | ||
var isCancel = false; | ||
@@ -132,3 +130,3 @@ /** | ||
*/ | ||
this.request = function() { | ||
this.request = function () { | ||
isCancel = false; | ||
@@ -140,3 +138,3 @@ var args = arguments; | ||
tick = requestAnimationFrame(() => { | ||
tick = requestAnimationFrame(function () { | ||
if (isCancel) { | ||
@@ -158,3 +156,3 @@ return; | ||
*/ | ||
this.cancel = function() { | ||
this.cancel = function () { | ||
if (tick) { | ||
@@ -176,3 +174,3 @@ isCancel = true; | ||
*/ | ||
this.clone = function() { | ||
this.clone = function () { | ||
return new Frame(fun); | ||
@@ -182,5 +180,4 @@ }; | ||
var animation = function () { | ||
export default class animation { | ||
/** | ||
@@ -197,3 +194,6 @@ * 初始化一个动画实例 | ||
*/ | ||
constructor(duration, timingFunction, frames) { | ||
function animation(duration, timingFunction, frames) { | ||
_classCallCheck(this, animation); | ||
var defer; | ||
@@ -217,3 +217,3 @@ var frameQueue = getFrameQueue(duration, frames); | ||
*/ | ||
this.play = function() { | ||
this.play = function () { | ||
if (isPlaying) { | ||
@@ -233,20 +233,18 @@ return; | ||
currentFrame | ||
.request(percent.toFixed(10), timingFunction(percent).toFixed(10)) | ||
.then(() => { | ||
if (!isPlaying){ | ||
return; | ||
} | ||
currentFrame.request(percent.toFixed(10), timingFunction(percent).toFixed(10)).then(function () { | ||
if (!isPlaying) { | ||
return; | ||
} | ||
if (frameIndex === frameQueue.length - 1) { | ||
isPlaying = false; | ||
defer && defer.resolve('FINISH'); | ||
defer = null; | ||
} else { | ||
frameIndex++; | ||
request(); | ||
} | ||
}, () => { | ||
// CANCEL | ||
}); | ||
if (frameIndex === frameQueue.length - 1) { | ||
isPlaying = false; | ||
defer && defer.resolve('FINISH'); | ||
defer = null; | ||
} else { | ||
frameIndex++; | ||
request(); | ||
} | ||
}, function () { | ||
// CANCEL | ||
}); | ||
} | ||
@@ -265,3 +263,3 @@ | ||
*/ | ||
this.stop = function() { | ||
this.stop = function () { | ||
if (!isPlaying) { | ||
@@ -283,10 +281,20 @@ return; | ||
*/ | ||
frame (fun){ | ||
return new Frame(fun); | ||
} | ||
requestFrame (fun) { | ||
var frame = new Frame(fun); | ||
return frame.request(); | ||
} | ||
} | ||
_createClass(animation, [{ | ||
key: 'frame', | ||
value: function frame(fun) { | ||
return new Frame(fun); | ||
} | ||
}, { | ||
key: 'requestFrame', | ||
value: function requestFrame(fun) { | ||
var frame = new Frame(fun); | ||
return frame.request(); | ||
} | ||
}]); | ||
return animation; | ||
}(); | ||
exports.default = animation; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
1
11551
3
240