!function(t,n,e){n[t]=n[t]||e(),"undefined"!=typeofmodule&&module.exports?module.exports=n[t]:"function"==typeofdefine&&define.amd&&define(function(){returnn[t]})}("Promise","undefined"!=typeofglobal?global:this,function(){"use strict";functiont(t,n){l.add(t,n),h||(h=y(l.drain))}functionn(t){varn,e=typeoft;returnnull==t||"object"!=e&&"function"!=e||(n=t.then),"function"==typeofn?n:!1}functione(){for(vart=0;t<this.chain.length;t++)o(this,1===this.state?this.chain[t].success:this.chain[t].failure,this.chain[t]);this.chain.length=0}functiono(t,e,o){varr,i;try{e===!1?o.reject(t.msg):(r=e===!0?t.msg:e.call(void0,t.msg),r===o.promise?o.reject(TypeError("Promise-chain cycle")):(i=n(r))?i.call(r,o.resolve,o.reject):o.resolve(r))}catch(c){o.reject(c)}}functionr(o){varc,u,a=this;if(!a.triggered){a.triggered=!0,a.def&&(a=a.def);try{(c=n(o))?(u=newf(a),c.call(o,function(){r.apply(u,arguments)},function(){i.apply(u,arguments)})):(a.msg=o,a.state=1,a.chain.length>0&&t(e,a))}catch(s){i.call(u||newf(a),s)}}}functioni(n){varo=this;o.triggered||(o.triggered=!0,o.def&&(o=o.def),o.msg=n,o.state=2,o.chain.length>0&&t(e,o))}functionc(t,n,e,o){for(varr=0;r<n.length;r++)!function(r){t.resolve(n[r]).then(function(t){e(r,t)},o)}(r)}functionf(t){this.def=t,this.triggered=!1}functionu(t){this.promise=t,this.state=0,this.triggered=!1,this.chain=[],this.msg=void0}functiona(n){if("function"!=typeofn)throwTypeError("Not a function");if(0!==this.__NPO__)throwTypeError("Not a promise");this.__NPO__=1;varo=newu(this);this.then=function(n,r){vari={success:"function"==typeofn?n:!0,failure:"function"==typeofr?r:!1};returni.promise=newthis.constructor(function(t,n){if("function"!=typeoft||"function"!=typeofn)throwTypeError("Not a function");i.resolve=t,i.reject=n}),o.chain.push(i),0!==o.state&&t(e,o),i.promise},this["catch"]=function(t){returnthis.then(void0,t)};try{n.call(void0,function(t){r.call(o,t)},function(t){i.call(o,t)})}catch(c){i.call(o,c)}}vars,h,l,p=Object.prototype.toString,y="undefined"!=typeofsetImmediate?function(t){returnsetImmediate(t)}:setTimeout;try{Object.defineProperty({},"x",{}),s=function(t,n,e,o){returnObject.defineProperty(t,n,{value:e,writable:!0,configurable:o!==!1})}}catch(d){s=function(t,n,e){returnt[n]=e,t}}l=function(){functiont(t,n){this.fn=t,this.self=n,this.next=void0}varn,e,o;return{add:function(r,i){o=newt(r,i),e?e.next=o:n=o,e=o,o=void0},drain:function(){vart=n;for(n=e=h=void0;t;)t.fn.call(t.self),t=t.next}}}();varg=s({},"constructor",a,!1);try{s(a,"prototype",g,!1)}catch(d){a.prototype=g}returns(g,"__NPO__",0,!1),s(a,"resolve",function(t){varn=this;returnt&&"object"==typeoft&&1===t.__NPO__?t:newn(function(n,e){if("function"!=typeofn||"function"!=typeofe)throwTypeError("Not a function");n(t)})}),s(a,"reject",function(t){returnnewthis(function(n,e){if("function"!=typeofn||"function"!=typeofe)throwTypeError("Not a function");e(t)})}),s(a,"all",function(t){varn=this;return"[object Array]"!=p.call(t)?n.reject(TypeError("Not an array")):0===t.length?n.resolve([]):newn(function(e,o){if("function"!=typeofe||"function"!=typeofo)throwTypeError("Not a function");varr=t.length,i=Array(r),f=0;c(n,t,function(t,n){i[t]=n,++f===r&&e(i)},o)})}),s(a,"race",function(t){varn=this;return"[object Array]"!=p.call(t)?n.reject(TypeError("Not an array")):newn(function(e,o){if("function"!=typeofe||"function"!=typeofo)throwTypeError("Not a function");c(n,t,function(t,n){e(n)},o)})}),a});