(function(n,h){"object"===typeof exports&&"undefined"!==typeof module?h():"function"===typeof define&&define.amd?define(h):h()})(this,function(){function n(a){var b=this.constructor;return this.then(function(c){return b.resolve(a()).then(function(){return c})},function(c){return b.resolve(a()).then(function(){return b.reject(c)})})}function h(){}function x(a,b){return function(){a.apply(b,arguments)}}function d(a){if(!(this instanceof d))throw new TypeError("Promises must be constructed via new");
if("function"!==typeof a)throw new TypeError("not a function");this._state=0;this._handled=!1;this._value=void 0;this._deferreds=[];t(a,this)}function u(a,b){for(;3===a._state;)a=a._value;0===a._state?a._deferreds.push(b):(a._handled=!0,d._immediateFn(function(){var c=1===a._state?b.onFulfilled:b.onRejected;if(null===c)(1===a._state?p:k)(b.promise,a._value);else{try{var e=c(a._value)}catch(f){k(b.promise,f);return}p(b.promise,e)}}))}function p(a,b){try{if(b===a)throw new TypeError("A promise cannot be resolved with itself.");
if(b&&("object"===typeof b||"function"===typeof b)){var c=b.then;if(b instanceof d){a._state=3;a._value=b;q(a);return}if("function"===typeof c){t(x(c,b),a);return}}a._state=1;a._value=b;q(a)}catch(e){k(a,e)}}function k(a,b){a._state=2;a._value=b;q(a)}function q(a){2===a._state&&0===a._deferreds.length&&d._immediateFn(function(){a._handled||d._unhandledRejectionFn(a._value)});for(var b=0,c=a._deferreds.length;b<c;b++)u(a,a._deferreds[b]);a._deferreds=null}function y(a,b,c){this.onFulfilled="function"===
typeof a?a:null;this.onRejected="function"===typeof b?b:null;this.promise=c}function t(a,b){var c=!1;try{a(function(e){c||(c=!0,p(b,e))},function(e){c||(c=!0,k(b,e))})}catch(e){c||(c=!0,k(b,e))}}var z=setTimeout;d.prototype["catch"]=function(a){return this.then(null,a)};d.prototype.then=function(a,b){var c=new this.constructor(h);u(this,new y(a,b,c));return c};d.prototype["finally"]=n;d.all=function(a){return new d(function(b,c){function e(v,g){try{if(g&&("object"===typeof g||"function"===typeof g)){var w=
g.then;if("function"===typeof w){w.call(g,function(r){e(v,r)},c);return}}f[v]=g;0===--A&&b(f)}catch(r){c(r)}}if(!a||"undefined"===typeof a.length)return c(new TypeError("Promise.all accepts an array"));var f=Array.prototype.slice.call(a);if(0===f.length)return b([]);for(var A=f.length,l=0;l<f.length;l++)e(l,f[l])})};d.resolve=function(a){return a&&"object"===typeof a&&a.constructor===d?a:new d(function(b){b(a)})};d.reject=function(a){return new d(function(b,c){c(a)})};d.race=function(a){return new d(function(b,
c){if(!a||"undefined"===typeof a.length)return c(new TypeError("Promise.race accepts an array"));for(var e=0,f=a.length;e<f;e++)d.resolve(a[e]).then(b,c)})};d._immediateFn="function"===typeof setImmediate&&function(a){setImmediate(a)}||function(a){z(a,0)};d._unhandledRejectionFn=function(a){"undefined"!==typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",a)};var m=function(){if("undefined"!==typeof self)return self;if("undefined"!==typeof window)return window;if("undefined"!==
typeof global)return global;throw Error("unable to locate global object");}();"function"!==typeof m.Promise?m.Promise=d:m.Promise.prototype["finally"]||(m.Promise.prototype["finally"]=n)});
