22397b41dbe5333180c07d20dbc2d3dac3742e1e1cd2cbeb9fc3126d9a249b51

Source Code:

!function(){var t={VERSION:"2.3.5",Result:{SUCCEEDED:1,NOTRANSITION:2,CANCELLED:3,PENDING:4},Error:{INVALID_TRANSITION:100,PENDING_TRANSITION:200,INVALID_CALLBACK:300},WILDCARD:"*",ASYNC:"async",create:function(n,e){var r="string"==typeof n.initial?{state:n.initial}:n.initial,i=n.terminal||n.final,a=e||n.target||{},o=n.events||[],u=n.callbacks||{},f={},c={},s=function(n){var e=n.from instanceof Array?n.from:n.from?[n.from]:[t.WILDCARD];f[n.name]=f[n.name]||{};for(var r=0;r<e.length;r++)c[e[r]]=c[e[r]]||[],c[e[r]].push(n.name),f[n.name][e[r]]=n.to||e[r]};r&&(r.event=r.event||"startup",s({name:r.event,from:"none",to:r.state}));for(var l=0;l<o.length;l++)s(o[l]);for(var v in f)f.hasOwnProperty(v)&&(a[v]=t.buildEvent(v,f[v]));for(var v in u)u.hasOwnProperty(v)&&(a[v]=u[v]);return a.current="none",a.is=function(t){return t instanceof Array?t.indexOf(this.current)>=0:this.current===t},a.can=function(n){return!this.transition&&(f[n].hasOwnProperty(this.current)||f[n].hasOwnProperty(t.WILDCARD))},a.cannot=function(t){return!this.can(t)},a.transitions=function(){return c[this.current]},a.isFinished=function(){return this.is(i)},a.error=n.error||function(t,n,e,r,i,a,o){throw o||a},r&&!r.defer&&a[r.event](),a},doCallback:function(n,e,r,i,a,o){if(e)try{return e.apply(n,[r,i,a].concat(o))}catch(e){return n.error(r,i,a,o,t.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function",e)}},beforeAnyEvent:function(n,e,r,i,a){return t.doCallback(n,n.onbeforeevent,e,r,i,a)},afterAnyEvent:function(n,e,r,i,a){return t.doCallback(n,n.onafterevent||n.onevent,e,r,i,a)},leaveAnyState:function(n,e,r,i,a){return t.doCallback(n,n.onleavestate,e,r,i,a)},enterAnyState:function(n,e,r,i,a){return t.doCallback(n,n.onenterstate||n.onstate,e,r,i,a)},changeState:function(n,e,r,i,a){return t.doCallback(n,n.onchangestate,e,r,i,a)},beforeThisEvent:function(n,e,r,i,a){return t.doCallback(n,n["onbefore"+e],e,r,i,a)},afterThisEvent:function(n,e,r,i,a){return t.doCallback(n,n["onafter"+e]||n["on"+e],e,r,i,a)},leaveThisState:function(n,e,r,i,a){return t.doCallback(n,n["onleave"+r],e,r,i,a)},enterThisState:function(n,e,r,i,a){return t.doCallback(n,n["onenter"+i]||n["on"+i],e,r,i,a)},beforeEvent:function(n,e,r,i,a){if(!1===t.beforeThisEvent(n,e,r,i,a)||!1===t.beforeAnyEvent(n,e,r,i,a))return!1},afterEvent:function(n,e,r,i,a){t.afterThisEvent(n,e,r,i,a),t.afterAnyEvent(n,e,r,i,a)},leaveState:function(n,e,r,i,a){var o=t.leaveThisState(n,e,r,i,a),u=t.leaveAnyState(n,e,r,i,a);return!1!==o&&!1!==u&&(t.ASYNC===o||t.ASYNC===u?t.ASYNC:void 0)},enterState:function(n,e,r,i,a){t.enterThisState(n,e,r,i,a),t.enterAnyState(n,e,r,i,a)},buildEvent:function(n,e){return function(){var r=this.current,i=e[r]||e[t.WILDCARD]||r,a=Array.prototype.slice.call(arguments);if(this.transition)return this.error(n,r,i,a,t.Error.PENDING_TRANSITION,"event "+n+" inappropriate because previous transition did not complete");if(this.cannot(n))return this.error(n,r,i,a,t.Error.INVALID_TRANSITION,"event "+n+" inappropriate in current state "+this.current);if(!1===t.beforeEvent(this,n,r,i,a))return t.Result.CANCELLED;if(r===i)return t.afterEvent(this,n,r,i,a),t.Result.NOTRANSITION;var o=this;this.transition=function(){return o.transition=null,o.current=i,t.enterState(o,n,r,i,a),t.changeState(o,n,r,i,a),t.afterEvent(o,n,r,i,a),t.Result.SUCCEEDED},this.transition.cancel=function(){o.transition=null,t.afterEvent(o,n,r,i,a)};var u=t.leaveState(this,n,r,i,a);return!1===u?(this.transition=null,t.Result.CANCELLED):t.ASYNC===u?t.Result.PENDING:this.transition?this.transition():void 0}}};"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=t),exports.StateMachine=t),"function"==typeof define&&define.amd&&define(function(n){return t}),"undefined"!=typeof window&&(window.StateMachine=t),"undefined"!=typeof self&&(self.StateMachine=t)}();