text: /**
   * @license
   * The MIT License (MIT)
   *
   * Copyright (c) Joel F Guillod <joel.guillod@gmail.com> (www.imed.ch)
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
  !function(t){"use strict";if("function"==typeof bootstrap)bootstrap("jsfsm",t);else if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=t}else{if("undefined"==typeof self)throw"This environment was not anticipated by imed-javascript-finite-state-machine. Please file a bug.";self.FSM=t()}}(function(){"use strict";function t(e,t){var n,r,i=this,o=this._transitions={},s=this._states={},a=this._fromStates={},c=e._,f=this._private=Object.assign({initial:"none"},c);this.debug=!1,f.justListen=!1!==f.justListen,this._listeners=[],this.e={},this.original=function(){return i},Object.freeze(this.original),Object.getOwnPropertyNames(e).forEach(function(t){n=e[t],"_"!=t&&(n.entry||n.exit||n.actions?(!(s[t]=n).exit||n.exit instanceof Array||(n.exit=[n.exit]),!n.entry||n.entry instanceof Array||(n.entry=[n.entry]),n.hasOwnProperty("actions")||(n.actions={})):(o[t]=n instanceof Array?n:[n],this.e[t]||(this.e[t]=u(this,t))))},this),Object.getOwnPropertyNames(o).forEach(function(e){o[e].forEach(function(t){!t.before||t.before instanceof Array||(t.before=[t.before]),!t.after||t.after instanceof Array||(t.after=[t.after]),!t.do||t.do instanceof Array||(t.do=[t.do]),!t.guard||t.guard instanceof Array||(t.guard=[t.guard]),!t.dont||t.dont instanceof Array||(t.dont=[t.dont]),t.from&&!s[t.from]&&(s[t.from]={}),t.to&&!s[t.to]&&(s[t.to]={}),r=t.from||"none",a[r]||(a[r]={}),a[r][e]=t,Object.freeze(t),Object.freeze(a[r][e]),Object.freeze(s[t.from]),Object.freeze(s[t.to])})},this),Object.freeze(o),Object.freeze(s),Object.freeze(a),Object.freeze(f),Object.freeze(this.e),this._pendingTransition=!1,this._lockKey=null,this._lifeCycle=[],y(this,f.initial),"function"==typeof t&&t.call(this,this)}function u(i,o){return function(t){for(var e=0,n=arguments.length,r=new Array(n);e<n;++e)r[e]=arguments[e];return i.trigger.apply(i,[o].concat(r))}}function y(t,e,n){if(t._addHistory(e,n),t._current=e,!t._states.hasOwnProperty(e))throw'unknown state "'+e+"'";t._actions=Object.assign({},t._states[e].actions)}function s(e,t,n,r){var i=n.guard;var o={step:"guard",event:t,from:n.from,to:n.to,options:n.options};return!i||i.every(function(t){return!t||t.apply(e,[o].concat(r))})}return Object.defineProperty(t.prototype,"actions",{get:function(){return this._actions}}),t.prototype.factory=function(t,e){var n=this,r=Object.getOwnPropertyNames(n.e),i=n._private.initial;function o(t,e){1===arguments.length&&"function"==typeof t&&(cb=t,t=null),this._debug=!1,this._pendingTransition=!1,this._listeners=[],this._lockKey=null,this._lifeCycle=[],this._initial="",this.reason=null,y(this,t||i),this.e={},r.forEach(function(t){this.e[t]=u(this,t)},this),Object.freeze(this.e),"function"==typeof e&&e.call(this,this)}return o.prototype=n,new o(t,e)},t.prototype.resetMachine=function(t){if(this.isLocked()&&!this.testLock(t))throw"Reseting machine is forbidden by a lock";if(this._pendingTransition)throw"Reseting machine is forbidden during a transition";y(this,this._private.initial)},t.prototype.engineVersion=function(){return"JFG's FSM engine v 0.8.1 Tue Feb 16 2016 13:02:36 GMT+0100 (CET)"},t.prototype.version=function(){return this._private.version||"unknown"},t.prototype.lock=function(){if(this.isLocked())throw"Machine is already locked";return this._lockKey=arguments[0]||{}},t.prototype.unlock=function(t){return this._lockKey&&t===this._lockKey&&(this._lockKey=null),null===this._lockKey},t.prototype.testLock=function(t){return t===this._lockKey},t.prototype.isLocked=function(){return null!==this._lockKey},t.prototype.status=function(){var t={engine:this.engineVersion(),version:this.version(),state:this._current,pending:this._pendingTransition};return this._private.namespace&&(t.namespace=this._private.namespace),t},t.prototype.current=function(){return this._current},t.prototype._addHistory=function(t,e){var n={date:new Date,to:t};this._current&&(n.from=this._current),e&&(n.event=e),Object.freeze(n),this._lifeCycle.push(n)},t.prototype.history=function(){return this._lifeCycle.concat()},t.prototype.on=function(t,e,n){var r=3,i=n;"function"==typeof e&&(i=e,e=this,r=2);for(var o=arguments.length,s=[];r<o;++r)s.push(arguments[r]);return function(t,e,n,r,i){var o={fn:r,scope:n};return 0<i.length&&(o.options=i),t._listeners.length+1===t._listeners.push({pattern:e,observer:o})}(this,t,e,i,s)},t.prototype.un=function(t,e,n){var r=n;return"function"==typeof e&&(r=e,e=this),function(t,r,i,o){var e=t._listeners.length;return t._listeners=t._listeners.filter(function(t){var e=t.observer.fn,n=t.observer.scope;return t.pattern!=r.toString()||i!==n||o!==e}),e>t._listeners.length}(this,t,e,r)},t.prototype.availActions=function(){return Object.getOwnPropertyNames(this.actions)},t.prototype.availEvents=function(e){for(var n=this._fromStates[this._current],r=this,t=1,i=arguments.length,o=t<i?new Array(i-t):[];t<i;++t)o[t-1]=arguments[t];return Object.getOwnPropertyNames(n).filter(function(t){return!0!==e||s(r,t,n[t],o)})},t.prototype.can=function(t,e){if(0===arguments.length)return!1;for(var n=2,r=arguments.length,i=n<r?new Array(r-n):[];n<r;++n)i[n-2]=arguments[n];return!0===e?s(this,t,this._fromStates[this._current][t],i):this._fromStates[this._current].hasOwnProperty(t)},t.prototype.is=function(t){return this._current===t},t.prototype._fsmListeners=function(t,f){var e,n=this,u=this._private.justListen,r=t.event,i=t.to,o=t.from,s=t.state,h=t.step+(s?"-"+s:(r?"-"+r:"")+(o?"-"+o:"")+(i?"-"+i:"")),a=n._listeners,p=Object.assign({},t);try{e=a.every(function(t){var e,n=t.pattern,r=t.observer,i=r.fn,o=r.scope,s=r.options,a=Object.freeze(Object.assign(s?{options:s}:{},p)),c=!0;return(n instanceof RegExp?n.test(h):n===h)&&(e=[a].concat(f),c=i.apply(o,e)),c||u})}finally{0}return e},t.prototype.recoverPendingTransition=function(){this._pendingTransition=!1},t.prototype.isInTransition=function(){return this._pendingTransition},t.prototype.t=t.prototype.trigger=function(t){var e=1;if(this.isLocked()){if(!this.testLock(arguments[1]))return!(this.reason="Trigger is forbidden by a lock");e=2}if(this._pendingTransition)return this.reason="Cannot trigger '"+arguments[e]+"' : previous transition is not completed",!1;this._pendingTransition=!0;for(var n=arguments.length,r=[];e<n;++e)r.push(arguments[e]);var i=function(s,t,a){var e=s._current,n=s._fromStates[e][t],r=!0,c=s._private.justListen;if(a=a||[],s.reason=null,!n)return s.reason="Cannot trigger '"+t+"' : undefined transition in current state '"+e+"'",!1;var i=n.to,f=n.options,o={event:t,from:e},u={state:e},h={state:i};i&&(o.to=i);function p(t,e,n){e.step=t;var r,i,o={};f&&(o.options=f);try{o=Object.freeze(Object.assign(o,e)),i=[o].concat(a),r=!n||n.every(function(t){return!t||t.apply(s,i)})}finally{0,c?s._fsmListeners(e,a):r=r&&s._fsmListeners(e,a)}return r}function l(){return p("dont",o,n.dont)}{}try{if(!0!==p("before",o,n.before))throw"before cancelled the transition";if(!0!==p("guard",o,n.guard))throw l(),"guard cancelled the transition";if(i){if(!0!==p("exit",u,s._states[e].exit))throw l(),"exit cancelled the transition";s._actions={}}p("do",o,n.do),i&&(y(s,i,t),p("entry",h,s._states[i].entry))}catch(t){0,s.reason=t,r=!1}finally{try{p("after",o,n.after)}catch(t){0,s.reason={error:t,step:"after"},r=!1}0}return r}(this,t,r);return this._pendingTransition=!1,i},Object.defineProperty(t.prototype,"debug",{set:function(t){this._debug=!!this.logger&&!!(t&&console&&console.log&&console.time&&console.timeEnd)},get:function(){return this._debug}}),t});