-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
37 lines (30 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var assert = require('nanoassert')
var placeholder = {
cancel: noop,
finish: noop,
pause: noop,
play: noop,
reverse: noop,
finished: {
then: Promise.resolve // Animations can be chained with promises or property definitions
}
}
module.exports = animate
function animate (keyframes, timingProperties) {
assert.equal(typeof keyframes, 'object', 'nanoanimation: keyframes should be an array or an object')
assert.ok(typeof timingProperties === 'object' || typeof timingProperties === 'number', 'nanoanimation: timingProperties should be type object or number')
return function (element, _done) {
var done = _done || noop
assert.equal(typeof element, 'object', 'nanoanimation: element should be type object')
assert.equal(typeof done, 'function', 'nanoanimation: done should be type function')
if (typeof window === 'undefined' || !('AnimationEvent' in window)) {
done()
return placeholder
}
var animation = element.animate(keyframes, timingProperties)
animation.pause()
animation.onfinish = done
return animation
}
}
function noop () {}