spiritjs
Version:
The animation toolkit for the web
190 lines (150 loc) • 6.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _list = require('../list/list');
var _list2 = _interopRequireDefault(_list);
var _transition = require('./transition');
var _transition2 = _interopRequireDefault(_transition);
var _utils = require('../utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* List of transitions.
*
* @fires Transitions#change:list
* @fires Transitions#add
* @fires Transitions#remove
*
* Bubble events from items
*
* @fires Transitions#change
* @fires Transitions#change:frame
* @fires Transitions#change:params
* @fires Transitions#change:ease
*
* @fires Transitions#change:param
* @fires Transitions#change:param:prop
* @fires Transitions#change:param:value
*
* @fires Transitions#add:param
* @fires Transitions#remove:param
*/
var Transitions = function (_List) {
_inherits(Transitions, _List);
/**
* Create transitions
*
* @param {Array} transitions
*/
function Transitions() {
var transitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
_classCallCheck(this, Transitions);
var _this = _possibleConstructorReturn(this, (Transitions.__proto__ || Object.getPrototypeOf(Transitions)).call(this, transitions, _transition2.default, [0]));
_this.duplicates = { prop: 'frame' };
_this.sortOn = 'frame';
_this.linkedList = true;
_this._mappings = [];
return _this;
}
/**
* Get a transition by frame
*
* @param {number} frame
*/
_createClass(Transitions, [{
key: 'get',
value: function get(frame) {
return this._list.find(function (tr) {
return tr.frame === frame;
});
}
/**
* Does have a transition with frame
*
* @param {number} frame
* @returns {boolean}
*/
}, {
key: 'haveFrame',
value: function haveFrame(frame) {
return this._list.filter(function (tr) {
return tr.frame === frame;
}).length > 0;
}
/**
* Get mappings for these transitions
*
* @returns {Array}
*/
}, {
key: 'add',
/**
* Apply mappings to child transition
*
* @param {*|Array} tr
* @returns {*}
*/
value: function add(tr) {
var _this2 = this;
var affected = _get(Transitions.prototype.__proto__ || Object.getPrototypeOf(Transitions.prototype), 'add', this).call(this, tr);
var exec = function exec(transition) {
transition.params.mappings = [].concat(_toConsumableArray(_this2.mappings));
};
Array.isArray(affected) ? affected.forEach(exec) : exec(affected);
return affected;
}
/**
* Remove mappings from transition on removal
*
* @param {*|Array} transition
*/
}, {
key: 'remove',
value: function remove(tr) {
var affected = _get(Transitions.prototype.__proto__ || Object.getPrototypeOf(Transitions.prototype), 'remove', this).call(this, tr);
var exec = function exec(transition) {
transition.params.mappings = [];
};
Array.isArray(affected) ? affected.forEach(exec) : exec(affected);
return affected;
}
/**
* Clean up transitions
*/
}, {
key: 'destroy',
value: function destroy() {
this.each(function (tr) {
return tr.destroy();
});
_utils.events.clearEvents(this, Transitions.Events);
}
}, {
key: 'mappings',
get: function get() {
return this._mappings;
}
/**
* Set mappings for these transitions
*
* @param {Array} mappings
*/
,
set: function set(mappings) {
this._mappings = mappings;
this.each(function (tr) {
tr.params.mappings = [].concat(_toConsumableArray(mappings));
});
}
}]);
return Transitions;
}(_list2.default);
Transitions.Events = ['change:list', 'add', 'remove', 'change', 'change:frame', 'change:params', 'change:ease', 'change:param', 'change:param:prop', 'change:param:value', 'add:param', 'remove:param'];
exports.default = Transitions;
module.exports = exports['default'];