123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import _typeof from 'babel-runtime/helpers/typeof';
- import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
- import _createClass from 'babel-runtime/helpers/createClass';
-
-
- import util from '../util';
- import internal from '../internal';
-
- var AnimatorFactory = function () {
-
-
-
- function AnimatorFactory(opts) {
- _classCallCheck(this, AnimatorFactory);
-
- this._animators = opts.animators;
- this._baseClass = opts.baseClass;
- this._baseClassName = opts.baseClassName || opts.baseClass.name;
- this._animation = opts.defaultAnimation || 'default';
- this._animationOptions = opts.defaultAnimationOptions || {};
-
- if (!this._animators[this._animation]) {
- util.throw('No such animation: ' + this._animation);
- }
- }
-
-
-
-
-
- _createClass(AnimatorFactory, [{
- key: 'setAnimationOptions',
-
-
-
-
- value: function setAnimationOptions(options) {
- this._animationOptions = options;
- }
-
-
-
-
- }, {
- key: 'newAnimator',
- value: function newAnimator() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var defaultAnimator = arguments[1];
-
-
- var animator = null;
-
- if (options.animation instanceof this._baseClass) {
- return options.animation;
- }
-
- var Animator = null;
-
- if (typeof options.animation === 'string') {
- Animator = this._animators[options.animation];
- }
-
- if (!Animator && defaultAnimator) {
- animator = defaultAnimator;
- } else {
- Animator = Animator || this._animators[this._animation];
-
- var animationOpts = util.extend({}, this._animationOptions, options.animationOptions || {}, internal.config.animationsDisabled ? { duration: 0, delay: 0 } : {});
-
- animator = new Animator(animationOpts);
-
- if (typeof animator === 'function') {
- animator = new animator(animationOpts);
- }
- }
-
- if (!(animator instanceof this._baseClass)) {
- util.throw('"animator" is not an instance of ' + this._baseClassName);
- }
-
- return animator;
- }
- }], [{
- key: 'parseAnimationOptionsString',
- value: function parseAnimationOptionsString(jsonString) {
- try {
- if (typeof jsonString === 'string') {
- var result = util.animationOptionsParse(jsonString);
- if ((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object' && result !== null) {
- return result;
- } else {
- console.error('"animation-options" attribute must be a JSON object string: ' + jsonString);
- }
- }
- return {};
- } catch (e) {
- console.error('"animation-options" attribute must be a JSON object string: ' + jsonString);
- return {};
- }
- }
- }]);
-
- return AnimatorFactory;
- }();
-
- export default AnimatorFactory;
|