Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metal-anim

Package Overview
Dependencies
Maintainers
12
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metal-anim - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

155

lib/Anim.js

@@ -7,2 +7,4 @@ 'use strict';

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 _metal = require('metal');

@@ -18,2 +20,5 @@

/**
* Anim class.
*/
var Anim = function () {

@@ -24,87 +29,95 @@ function Anim() {

/**
* Emulates animation or transition end event, the end event with longer
* duration will be used by the emulation. If they have the same value,
* transitionend will be emulated.
* @param {!Element} element
* @param {number=} opt_durationMs
* @return {!Object} Object containing `abort` function.
*/
Anim.emulateEnd = function emulateEnd(element, opt_durationMs) {
if (this.getComputedDurationMs(element, 'animation') > this.getComputedDurationMs(element, 'transition')) {
return this.emulateEnd_(element, 'animation', opt_durationMs);
} else {
return this.emulateEnd_(element, 'transition', opt_durationMs);
_createClass(Anim, null, [{
key: 'emulateEnd',
/**
* Emulates animation or transition end event, the end event with longer
* duration will be used by the emulation. If they have the same value,
* transitionend will be emulated.
* @param {!Element} element
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
value: function emulateEnd(element, optDurationMs) {
if (this.getComputedDurationMs(element, 'animation') > this.getComputedDurationMs(element, 'transition')) {
return this.emulateEnd_(element, 'animation', optDurationMs);
} else {
return this.emulateEnd_(element, 'transition', optDurationMs);
}
}
};
/**
* Emulates animation end event. If `opt_durationMs` not specified the value
* will read from computed style for animation-duration.
* @param {!Element} element
* @param {number=} opt_durationMs
* @return {!Object} Object containing `abort` function.
*/
/**
* Emulates animation end event. If `optDurationMs` not specified the value
* will read from computed style for animation-duration.
* @param {!Element} element
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
}, {
key: 'emulateAnimationEnd',
value: function emulateAnimationEnd(element, optDurationMs) {
return this.emulateEnd_(element, 'animation', optDurationMs);
}
Anim.emulateAnimationEnd = function emulateAnimationEnd(element, opt_durationMs) {
return this.emulateEnd_(element, 'animation', opt_durationMs);
};
/**
* Emulates transition end event. If `optDurationMs` not specified the
* value will read from computed style for transition-duration.
* @param {!Element} element
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
/**
* Emulates transition end event. If `opt_durationMs` not specified the
* value will read from computed style for transition-duration.
* @param {!Element} element
* @param {number=} opt_durationMs
* @return {!Object} Object containing `abort` function.
*/
}, {
key: 'emulateTransitionEnd',
value: function emulateTransitionEnd(element, optDurationMs) {
return this.emulateEnd_(element, 'transition', optDurationMs);
}
/**
* Emulates transition or animation end.
* @param {!Element} element
* @param {string} type
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
* @protected
*/
Anim.emulateTransitionEnd = function emulateTransitionEnd(element, opt_durationMs) {
this.emulateEnd_(element, 'transition', opt_durationMs);
};
}, {
key: 'emulateEnd_',
value: function emulateEnd_(element, type, optDurationMs) {
var duration = optDurationMs;
if (!_metal2.default.isDef(optDurationMs)) {
duration = this.getComputedDurationMs(element, type);
}
/**
* Emulates transition or animation end.
* @param {!Element} element
* @param {string} type
* @param {number=} opt_durationMs
* @return {!Object} Object containing `abort` function.
* @protected
*/
var delayed = setTimeout(function () {
_metalDom.dom.triggerEvent(element, _metalDom.features.checkAnimationEventName()[type]);
}, duration);
var abort = function abort() {
clearTimeout(delayed);
hoistedEvtHandler.removeListener();
};
var hoistedEvtHandler = _metalDom.dom.once(element, type + 'end', abort);
Anim.emulateEnd_ = function emulateEnd_(element, type, opt_durationMs) {
var duration = opt_durationMs;
if (!_metal2.default.isDef(opt_durationMs)) {
duration = this.getComputedDurationMs(element, type);
return {
abort: abort
};
}
var delayed = setTimeout(function () {
_metalDom.dom.triggerEvent(element, _metalDom.features.checkAnimationEventName()[type]);
}, duration);
/**
* Gets computed style duration for duration.
* @param {!Element} element
* @param {string} type
* @return {number} The computed duration in milliseconds.
*/
var abort = function abort() {
clearTimeout(delayed);
hoistedEvtHandler.removeListener();
};
var hoistedEvtHandler = _metalDom.dom.once(element, type + 'end', abort);
}, {
key: 'getComputedDurationMs',
value: function getComputedDurationMs(element, type) {
return (parseFloat(window.getComputedStyle(element, null).getPropertyValue(type + '-duration')) || 0) * 1000;
}
}]);
return {
abort: abort
};
};
/**
* Gets computed style duration for duration.
* @param {!Element} element
* @param {string} type
* @return {number} The computed duration in milliseconds.
*/
Anim.getComputedDurationMs = function getComputedDurationMs(element, type) {
return (parseFloat(window.getComputedStyle(element, null).getPropertyValue(type + '-duration')) || 0) * 1000;
};
return Anim;

@@ -111,0 +124,0 @@ }();

{
"name": "metal-anim",
"version": "2.0.0",
"version": "2.0.1",
"description": "Metal's animation utility",
"keywords": [
"metal"
],
"license": "BSD",
"repository": "metal/metal-anim",
"engines": {
"node": ">=0.12.0",
"npm": ">=3.0.0"
},
"jsnext:main": "src/Anim.js",
"main": "lib/Anim.js",
"files": [

@@ -18,20 +14,24 @@ "lib",

],
"main": "lib/Anim.js",
"jsnext:main": "src/Anim.js",
"repository": "metal/metal-anim",
"scripts": {
"compile": "babel --presets metal -d lib/ src/",
"prepublish": "npm run compile",
"test": "gulp test"
"build": "webpack",
"compile": "babel --presets env -d lib/ src/",
"prepublish": "npm run compile"
},
"keywords": [
"metal"
],
"dependencies": {
"metal": "^2.0.0",
"metal-dom": "^2.0.0"
"metal": "^2.16.6",
"metal-dom": "^2.16.6"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-preset-metal": "^4.0.0",
"gulp": "^3.8.11",
"gulp-metal": "^1.0.0"
}
"babel-preset-env": "^1.6.1",
"webpack": "^3.5.5"
},
"engines": {
"node": ">=0.12.0",
"npm": ">=3.0.0"
},
"gitHead": "282bfcb63137ce4b9982f91a7a10a7eb8f2ab15a"
}
'use strict';
import core from 'metal';
import { dom, features } from 'metal-dom';
import {dom, features} from 'metal-dom';
/**
* Anim class.
*/
class Anim {

@@ -12,10 +15,13 @@ /**

* @param {!Element} element
* @param {number=} opt_durationMs
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
static emulateEnd(element, opt_durationMs) {
if (this.getComputedDurationMs(element, 'animation') > this.getComputedDurationMs(element, 'transition')) {
return this.emulateEnd_(element, 'animation', opt_durationMs);
static emulateEnd(element, optDurationMs) {
if (
this.getComputedDurationMs(element, 'animation') >
this.getComputedDurationMs(element, 'transition')
) {
return this.emulateEnd_(element, 'animation', optDurationMs);
} else {
return this.emulateEnd_(element, 'transition', opt_durationMs);
return this.emulateEnd_(element, 'transition', optDurationMs);
}

@@ -25,21 +31,21 @@ }

/**
* Emulates animation end event. If `opt_durationMs` not specified the value
* Emulates animation end event. If `optDurationMs` not specified the value
* will read from computed style for animation-duration.
* @param {!Element} element
* @param {number=} opt_durationMs
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
static emulateAnimationEnd(element, opt_durationMs) {
return this.emulateEnd_(element, 'animation', opt_durationMs);
static emulateAnimationEnd(element, optDurationMs) {
return this.emulateEnd_(element, 'animation', optDurationMs);
}
/**
* Emulates transition end event. If `opt_durationMs` not specified the
* Emulates transition end event. If `optDurationMs` not specified the
* value will read from computed style for transition-duration.
* @param {!Element} element
* @param {number=} opt_durationMs
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
*/
static emulateTransitionEnd(element, opt_durationMs) {
this.emulateEnd_(element, 'transition', opt_durationMs);
static emulateTransitionEnd(element, optDurationMs) {
return this.emulateEnd_(element, 'transition', optDurationMs);
}

@@ -51,24 +57,24 @@

* @param {string} type
* @param {number=} opt_durationMs
* @param {number=} optDurationMs
* @return {!Object} Object containing `abort` function.
* @protected
*/
static emulateEnd_(element, type, opt_durationMs) {
var duration = opt_durationMs;
if (!core.isDef(opt_durationMs)) {
static emulateEnd_(element, type, optDurationMs) {
let duration = optDurationMs;
if (!core.isDef(optDurationMs)) {
duration = this.getComputedDurationMs(element, type);
}
var delayed = setTimeout(function() {
let delayed = setTimeout(function() {
dom.triggerEvent(element, features.checkAnimationEventName()[type]);
}, duration);
var abort = function() {
let abort = function() {
clearTimeout(delayed);
hoistedEvtHandler.removeListener();
};
var hoistedEvtHandler = dom.once(element, type + 'end', abort);
let hoistedEvtHandler = dom.once(element, type + 'end', abort);
return {
abort: abort
abort: abort,
};

@@ -84,3 +90,9 @@ }

static getComputedDurationMs(element, type) {
return (parseFloat(window.getComputedStyle(element, null).getPropertyValue(type + '-duration')) || 0) * 1000;
return (
(parseFloat(
window
.getComputedStyle(element, null)
.getPropertyValue(type + '-duration')
) || 0) * 1000
);
}

@@ -87,0 +99,0 @@ }

@@ -7,2 +7,21 @@ 'use strict';

describe('Anim', function() {
// Retry all tests in this suite up to 4 times,
// It only reports the final result as to whether
// the test passed at some point (after some number of tries),
// or failed (because all the tries failed).
// More information: https://mochajs.org/#retry-tests
// http://webdriver.io/guide/testrunner/retry.html
this.retries(4);
before(function() {
// Disables mobile devices tests for these tests due sauce tunnel inconsistency
let devices = ['iPhone', 'iPad', 'Android'];
let filtered = devices.filter(device => {
return window.navigator.userAgent.indexOf(device) !== -1;
});
if (filtered.length) {
this.skip();
}
});
beforeEach(function() {

@@ -20,3 +39,3 @@ this.element = document.createElement('div');

it('should emulate transitionend after transition-duration', function(done) {
var start = Date.now();
let start = Date.now();
Anim.emulateTransitionEnd(this.element);

@@ -30,3 +49,3 @@ dom.once(this.element, 'transitionend', function() {

it('should emulate animationend after animation-duration interval', function(done) {
var start = Date.now();
let start = Date.now();
Anim.emulateAnimationEnd(this.element);

@@ -40,3 +59,3 @@ dom.once(this.element, 'animationend', function() {

it('should emulate the longest duration when `emulateEnd` is used (transitionend)', function(done) {
var listener = sinon.stub();
let listener = sinon.stub();
dom.once(this.element, 'transitionend', listener);

@@ -55,3 +74,3 @@ dom.once(this.element, 'animationend', listener);

this.element.style.animationDuration = '0.3s';
var listener = sinon.stub();
let listener = sinon.stub();
dom.once(this.element, 'transitionend', listener);

@@ -67,12 +86,12 @@ dom.once(this.element, 'animationend', listener);

it('should not emulate transitionend if already fired', function(done) {
Anim.emulateTransitionEnd(this.element);
dom.triggerEvent(this.element, 'transitionend');
dom.on(this.element, 'transitionend', function() {
assert.fail();
});
setTimeout(function() {
done();
}, 350);
});
// it('should not emulate transitionend if already fired', function(done) {
// Anim.emulateTransitionEnd(this.element);
// dom.triggerEvent(this.element, 'transitionend');
// dom.on(this.element, 'transitionend', function() {
// assert.fail();
// });
// setTimeout(function() {
// done();
// }, 350);
// });

@@ -82,3 +101,5 @@ it('should not emulate end event for a specified duration', function(done) {

dom.on(this.element, 'animationend', function() {
assert.fail('Transition end event must be fired for the same duration');
assert.fail(
'Transition end event must be fired for the same duration'
);
});

@@ -85,0 +106,0 @@ dom.on(this.element, 'transitionend', function() {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc