Comparing version 0.28.3 to 0.28.4
@@ -1,2 +0,2 @@ | ||
function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _createClass(t,e,n){return e&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),t}function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){_defineProperty(t,e,n[e])})}return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function _construct(t,e,n){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var a=new(Function.bind.apply(t,r));return n&&_setPrototypeOf(a,n.prototype),a}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(n,t)})(t)}function _objectDestructuringEmpty(t){if(null==t)throw new TypeError("Cannot destructure undefined")}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _iterableToArrayLimit(t,e){var n=[],r=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){a=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(a)throw i}}return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",SEP=".",TRANSITION_SYMBOL="--\x3e",TRANSITION_LABEL_START_SYMBOL=":",HISTORY_STATE_NAME="H",HISTORY_PREFIX="history.",INIT_STATE="nok",INIT_EVENT="init",AUTO_EVENT="auto",STATE_PROTOTYPE_NAME="State",NO_STATE_UPDATE=[],NO_OUTPUT=[],ACTION_IDENTITY=function(){return{outputs:NO_OUTPUT,updates:NO_STATE_UPDATE}},history_symbol={},SHALLOW="shallow",DEEP="deep",WRONG_EVENT_FORMAT_ERROR="The machine received an event which does not have the proper format. Expecting an object whose unique key is the event name, and value is the event data.",FUNCTION_THREW_ERROR=function(t,e){return"Exception thrown when executing ".concat(e," ").concat(t||"")},INVALID_ACTION_FACTORY_EXECUTED=function(t,e){return"".concat(FUNCTION_THREW_ERROR(t,e),"\nThe ").concat(e," returned a value which is not an action.")},INVALID_PREDICATE_EXECUTED=function(t,e){return"".concat(FUNCTION_THREW_ERROR(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},ACTION_FACTORY_DESC="action factory",ENTRY_ACTION_FACTORY_DESC="(decorating) entry action",UPDATE_STATE_FN_DESC="update state function",PREDICATE_DESC="predicate",COMMAND_RENDER="render",CONTRACTS_EVAL="CONTRACTS_EVAL",OUTPUTS_MSG="OUTPUTS_MSG",INPUT_MSG="INPUT_MSG",WARN_MSG="WARN_MSG",MACHINE_CREATION_ERROR_MSG="MACHINE_CREATION_ERROR_MSG",ERROR_MSG="ERROR_MSG",INTERNAL_INPUT_MSG="INTERNAL_INPUT_MSG",INTERNAL_OUTPUTS_MSG="INTERNAL_OUTPUTS_MSG",DEBUG_MSG="DEBUG_MSG",INIT_INPUT_MSG="INIT_INPUT_MSG";const PATH_ROOT=[0],PRE_ORDER="PRE_ORDER";function clone(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function merge(t,e){return Object.assign({},t,e)}function updatePathInTraversalState(t,e,n){n.forEach((n,r)=>{const a=t.get(e),i=t.get(n),o=i&&i.path;t.set(n,merge(i,{isAdded:!0,isVisited:!1,path:o||a.path.concat(r)}))})}function updateVisitInTraversalState(t,e){t.set(e,merge(t.get(e),{isVisited:!0}))}function visitTree(t,e){const{store:n,lenses:r,traverse:a}=t,{empty:i,add:o,takeAndRemoveOne:s,isEmpty:c}=n,{getChildren:u}=r,{visit:l,seed:f}=a,d=new Map,T="function"==typeof f?new(f()):clone(f);let p="function"==typeof i?new(i()):clone(i),m=T;for(o([e],p),d.set(e,{isAdded:!0,isVisited:!1,path:PATH_ROOT});!c(p);){const t=s(p),e=u(d,t);o(e,p),updatePathInTraversalState(d,t,e),m=l(m,d,t),updateVisitInTraversalState(d,t)}return d.clear(),m}function breadthFirstTraverseTree(t,e,n){const{getChildren:r}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function preorderTraverseTree(t,e,n){const{getChildren:r}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function postOrderTraverseTree(t,e,n){const{getChildren:r}=t,{seed:a,visit:i}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===r(t,e).length)(t,e);return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>o(e,t)?[]:r(e,t).concat([e])},traverse:{seed:a,visit:(t,e,n)=>o(n,e)?i(t,e,n):t}},n)}function isLeafLabel(t){return 0===objectTreeLenses.getChildren(t).length}const objectTreeLenses={isLeafLabel:isLeafLabel,getLabel:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getLabel > unexpected object tree value";return t},getChildren:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getChildren > unexpected value";{let e=Object.values(t)[0];return e&&"object"==typeof e&&!Array.isArray(e)?Object.keys(e).map(t=>({[t]:e[t]})):[]}},constructTree:(t,e)=>{const n=t&&Object.keys(t)&&Object.keys(t)[0];return 0===e.length?t:{[n]:Object.assign.apply(null,e)}}};function traverseObj(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:breadthFirstTraverseTree,PRE_ORDER:preorderTraverseTree,POST_ORDER:postOrderTraverseTree}[r]||preorderTraverseTree)(objectTreeLenses,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(PATH_ROOT)?t:i(t,e,n)}},n)}const arrayTreeLenses={getLabel:t=>Array.isArray(t)?t[0]:t,getChildren:t=>Array.isArray(t)?t[1]:[],constructTree:(t,e)=>e&&Array.isArray(e)&&e.length>0?[t,e]:t};var noop=function(){},emptyConsole={log:noop,warn:noop,info:noop,debug:noop,error:noop,trace:noop},emptyTracer=noop;function isBoolean(t){return"boolean"==typeof t}function isFunction(t){return"function"==typeof t}function isControlState(t){return t&&"string"==typeof t||isHistoryControlState(t)}function isEvent(t){return void 0===t||"string"==typeof t}function isActionFactory(t){return t&&"function"==typeof t}function make_states(t){return t.reduce(function(t,e){return t[e]="",t},{})}function make_events(t){return t}function get_fn_name(t){return/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}\s*$/.exec(t.toString())[1]}function wrap(t){return["-",t,"-"].join("")}function times$1(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function always(t){return t}function keys(t){return Object.keys(t)}function merge$1(t,e){return Object.assign({},t,e)}function is_history_transition(t){return t.to.startsWith(HISTORY_PREFIX)}function is_entry_transition(t){return t.event===INIT_EVENT}function is_from_control_state(t){return function(e){return e.from===t}}function is_to_history_control_state_of(t){return function(e){return is_history_control_state_of(t,e.to)}}function is_history_control_state_of(t,e){return e.substring(HISTORY_PREFIX.length)===t}function format_transition_label(t,e,n){var r=t||"";return e&&n?"".concat(r," [").concat(e.name,"] / ").concat(n.name):e?"".concat(r," [").concat(e.name,"]}"):n?"".concat(r," / ").concat(n.name):"".concat(r)}function format_history_transition_state_name(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(HISTORY_PREFIX.length),".").concat(HISTORY_STATE_NAME)}function get_all_transitions(t){var e=t.from,n=t.event,r=t.guards;return r?r.map(function(t){var r=t.predicate,a=t.to,i=t.action;return{from:e,event:n,predicate:r,to:a,action:i}}):[t]}function getDisplayName(t){return t.replace(/_/g," ")}function mergeModelUpdates(t){return function(e,n,r){return{updates:t.reduce(function(t,a){var i=a(e,n,r).updates;return i?t.concat(i):t},[]),outputs:NO_OUTPUT}}}function chainModelUpdates(t){return function(e,n,r){var a=r.updateState;return{updates:t.reduce(function(t,e){var i=t.extendedState,o=t.updates,s=e(i,n,r).updates;return{extendedState:a(i,o),updates:s}},{extendedState:e,updates:[]}).updates||[],outputs:NO_OUTPUT}}}function mergeActionFactories(t,e){return function(n,r,a){var i,o=e.map(function(t){return t(n,r,a)}),s=o.map(function(t){return t.updates||[]}),c=o.map(function(t){return t.outputs||{}});return{updates:(i=[]).concat.apply(i,_toConsumableArray(s)),outputs:t(c)}}}function identity(t,e,n){return{updates:[],outputs:NO_OUTPUT}}function lastOf(t){return t[t.length-1]}function formatActionName(t,e,n,r,a){var i=a?a.name:"",o=i?"[".concat(i,"]"):"",s=t?t.name:"identity";return"".concat(s||"unnamed action",":").concat(e,"-").concat(n,"->").concat(r," ").concat(o)}function getFsmStateList(t){var e=objectTreeLenses.getLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function getStatesType(t){var e=objectTreeLenses.getLabel,n=objectTreeLenses.isLeafLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(i)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function getStatesPath(t){var e=objectTreeLenses.getLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,n,r){var a=n.get(r).path.join("."),i=e(r);return t[Object.keys(i)[0]]=a,t}},t)}function getStatesTransitionsMap(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function getStateEventTransitionsMaps(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function getEventTransitionsMaps(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function getHistoryStatesMap(t){return reduceTransitions(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(isHistoryControlState(a)){var o=getHistoryUnderlyingState(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(isHistoryControlState(i)){var s=getHistoryUnderlyingState(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function getTargetStatesMap(t){return reduceTransitions(function(t,e,n,r){var a=e.to;return t.set(a,(t.get(a)||[]).concat([e])),t},new Map,t)||{}}function getAncestorMap(t){var e=objectTreeLenses.getLabel,n=objectTreeLenses.getChildren;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(a).map(function(t){return Object.keys(e(t))[0]}).forEach(function(e){t[e]=t[e]||[],t[e]=t[e].concat(o)}),t}},t)}function computeHistoryMaps(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var e=objectTreeLenses.getLabel,n=traverseObj({strategy:PRE_ORDER,seed:{stateList:[],stateAncestors:{}},visit:function(t,n,r){var a=e(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=n.get(r).path;n.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)n.set(JSON.stringify(s),INIT_STATE);else{var c=n.get(JSON.stringify(s));t.stateAncestors[i]=[c];var u=o.reduce(function(t,e){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=n.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[i]=u}return t}},t);return{stateList:n.stateList,stateAncestors:n.stateAncestors}}function mapOverTransitionsActions(t,e){return reduceTransitions(function(e,n,r,a){var i=n.from,o=n.event,s=n.to,c=n.action,u=n.predicate,l=t(c,n,r,a);return l.displayName=l.displayName||c&&(c.name||c.displayName||formatActionName(c,i,o,s,u)),void 0===u?e.push({from:i,event:o,to:s,action:l}):0===r?e.push({from:i,event:o,guards:[{to:s,predicate:u,action:l}]}):e[e.length-1].guards.push({to:s,predicate:u,action:l}),e},[],e)}function reduceTransitions(t,e,n){return n.reduce(function(e,n,r){var a=n.from,i=n.event,o=n.to,s=n.gen,c=n.action,u=n.guards;return u||(u=s?[{to:o,action:c,gen:s,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce(function(e,n,o){var s=n.to,c=n.action,u=n.gen,l=n.predicate;return t(e,u?{from:a,event:i,to:s,action:c,predicate:l,gen:u}:{from:a,event:i,to:s,action:c,predicate:l},o,r)},e)},e)}function everyTransition(t,e){return reduceTransitions(function(e,n){return e&&t(n)},!0,[e])}function computeTimesCircledOn(t,e){return t.reduce(function(t,n){return n===e?t+1:t},0)}function isInitState(t){return t===INIT_STATE}function isInitEvent(t){return t===INIT_EVENT}function isEventless(t){return void 0===t}function arrayizeOutput(t){return t===NO_OUTPUT?NO_OUTPUT:Array.isArray(t)?t:[t]}function isHistoryControlState(t){return"object"===_typeof(t)&&(DEEP in t||SHALLOW in t)}function getHistoryParentState(t){return t[SHALLOW]||t[DEEP]}function isShallowHistory(t){return t[SHALLOW]}function isDeepHistory(t){return t[DEEP]}function getHistoryType(t){return t[DEEP]?DEEP:SHALLOW}function getHistoryUnderlyingState(t){return t[getHistoryType(t)]}function isHistoryStateEdge(t){return void 0!==t.history}function initHistoryDataStructure(t){var e,n=function(){return t.reduce(function(t,e){return t[e]="",t},{})};return _defineProperty(e={},DEEP,n()),_defineProperty(e,SHALLOW,n()),e}function isCompoundState(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function isAtomicState(t,e){return!isCompoundState(t,e)}function updateHistory(t,e,n){return n===INIT_STATE?t:((e[n]||[]).reduce(function(e,r){return t[DEEP][r]=n,t[SHALLOW][r]=e,r},n),t)}function computeHistoryState(t,e,n,r){var a=computeHistoryMaps(t),i=a.stateList,o=a.stateAncestors,s=initHistoryDataStructure(i);return(s=e.reduce(function(t,e){return updateHistory(t,o,e)},s))[n][r]}function findInitTransition(t){return t.find(function(t){return t.from===INIT_STATE&&t.event===INIT_EVENT})}function tryCatch(t,e){return function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];try{return t.apply(t,r)}catch(t){return e(t,r)}}}function tryCatchMachineFn(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return tryCatch(e,function(r,a){var i=new Error(r),o=getFunctionName(e),s=FUNCTION_THREW_ERROR(o,t);i.probableCause=r.probableCause?[r.probableCause,s].join("\n"):s;var c={fnName:o,params:n.reduce(function(t,e,n){return t[e]=a[n],t},{})};return i.info=r.info?[].concat([r.info]).concat([c]):c,i})}function getFunctionName(t){return t.name||t.displayName||"anonymous"}function assert(t,e){var n=t.name||t.name.displayName||"",r=t.apply(null,e);return!0===r?void 0:_objectSpread({},r,{when:"Checking contract",message:[r.message,"failed contract ".concat(n)].join("\n"),info:r.info})}function notifyThrows(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function handleFnExecError(t,e,n,r,a,i){var o=t.debug,s=t.console;return o&&n instanceof Error?(a({debug:o,console:s},n,e),!0):!(!o||r(n))&&(i({debug:o,console:s},n,e),!0)}function notifyAndRethrow(t,e){t.debug;throw notifyThrows(t.console,e),e}function throwIfInvalidActionResult(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=getFunctionName(a),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},notifyThrows(r,u),u}function throwIfInvalidGuardResult(t,e,n){t.debug;var r=t.console,a=getFunctionName(n.predicate),i=new Error(INVALID_PREDICATE_EXECUTED(a,PREDICATE_DESC));throw i.info={predicateName:a,params:n,returned:e},notifyThrows(r,i),i}function throwIfInvalidEntryActionResult(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=getFunctionName(a),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ENTRY_ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},notifyThrows(r,u),u}function isActions(t){return t&&"updates"in t&&"outputs"in t&&Array.isArray(t.outputs)}function isEventStruct(t){var e;return t&&"object"===_typeof(t)?Object.keys(t).length>1?(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:e=!0:(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"not an object!"},e}function isError(t){return t instanceof Error}function destructureEvent(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}function formatUndefinedInJSON(t){return JSON.stringify(t,function(t,e){return void 0===e?"undefined":e})}var KinglyError=function(t){function e(t,n,r){var a;_classCallCheck(this,e),(a=_possibleConstructorReturn(this,_getPrototypeOf(e).call(this,t&&t.message||""))).name="KinglyError",a.stack=t&&t.stack||a.stack,a.errors=t;var i=t||{},o=i.when,s=i.location,c=i.info,u=i.message,l=["At ".concat(s,": ").concat(o," => ").concat(u),c?"See extra info in console":""].join("\n");return n&&n.error(l),c&&n&&n.info(c),a}return _inherits(e,_wrapNativeSuper(Error)),e}(),noDuplicatedStates={name:"noDuplicatedStates",shouldThrow:!1,predicate:function(t,e){var n=objectTreeLenses.getLabel,r=traverseObj({strategy:PRE_ORDER,seed:{duplicatedStates:[],statesHashMap:{}},visit:function(t,e,r){var a=t.duplicatedStates,i=t.statesHashMap,o=n(r),s=Object.keys(o)[0];return s in i?{duplicatedStates:a.concat(s),statesHashMap:i}:{duplicatedStates:a,statesHashMap:(i[s]="",i)}}},t.states).duplicatedStates;return{isFulfilled:0===r.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:r}}}}},noReservedStates={name:"noReservedStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:-1===Object.keys(r).indexOf(INIT_STATE),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[INIT_STATE],statesType:r}}}}},atLeastOneState={name:"atLeastOneState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:Object.keys(r).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:r}}}}},isInitialControlStateDeclared={name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:function(t,e,n){n.initTransition;var r=n.statesType,a=t.initialControlState,i=(t.transitions,Object.keys(r));return a?{isFulfilled:i.indexOf(a)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:a,declaredStates:i}}}:{isFulfilled:!0,blame:void 0}}},eventsAreStrings={name:"eventsAreStrings",shouldThrow:!1,predicate:function(t,e){return{isFulfilled:t.events.every(function(t){return"string"==typeof t}),blame:{message:"Events must be an array of strings!",info:{events:t.events}}}}},validInitialConfig={name:"validInitialConfig",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState;return r&&a?{isFulfilled:!1,blame:{message:"Invalid machine configuration : defining an initial control state and an initial transition at the same time may lead to ambiguity and is forbidden!",info:{initialControlState:a,initTransition:r}}}:r||a?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Invalid machine configuration : you must define EITHER an initial control state OR an initial transition! Else in which state is the machine supposed to start?",info:{initialControlState:a,initTransition:r}}}}},validInitialTransition={name:"validInitialTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState,i=t.transitions.reduce(function(t,e){return e.from===INIT_STATE&&t.push(e),t},[]);return{isFulfilled:a&&!r||!a&&r&&1===i.length&&r.event===INIT_EVENT&&(isInconditionalTransition(r)||areCconditionalTransitions(r)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:r,initTransitions:i,initialControlState:a}}}}},initEventOnlyInCompoundStates={name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=(n.statesPath,Object.keys(a).filter(function(t){return!a[t]}).map(function(t){return _defineProperty({},t,r[t]&&r[t][INIT_EVENT])}).filter(function(t){return Object.values(t)[0]}));return{isFulfilled:0===i.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:i}}}}},validInitialTransitionForCompoundState={name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=n.statesPath,o=Object.keys(a).filter(function(t){return a[t]}),s=o.map(function(t){return r[t]&&r[t][INIT_EVENT]}),c=s.every(Boolean);if(!c)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:o.map(function(t){return _defineProperty({},t,!(!r[t]||!r[t][INIT_EVENT]))})}}};var u=c&&s.every(function(t){var e=t.guards,n=t.to;return e?e.map(function(t){return t.to}).every(function(t){return"string"==typeof t}):"string"==typeof n});return u?u&&s.every(function(t){var e=t.from,n=t.guards,r=t.to;return n?n.map(function(t){return t.to}).every(function(t){return e!==t&&i[t]&&i[t].startsWith(i[e])}):e!==r&&i[r]&&i[r].startsWith(i[e])})?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have a target state which is strictly below the compound state in the state hierarchy! ",info:{states:t.states,statesPath:i,entryTransitions:s}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have the associated target control states which are not a history pseudo-state. Cf. log",info:{entryTransitions:s}}}}},validEventLessTransitions={name:"validEventLessTransitions",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=(n.statesPath,Object.keys(a).map(function(t){return _defineProperty({},t,r[t]&&"".concat(void 0)in r[t]&&1!==Object.keys(r[t]).length)}).filter(function(t){return void 0!==Object.values(t)[0]&&Object.values(t)[0]}));return{isFulfilled:0===i.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:i}}}}},allStateTransitionsOnOneSingleRow={name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=Object.keys(r).reduce(function(t,e){var n=Object.keys(r[e]).filter(function(t){return r[e][t].length>1});return n.length>0&&(t[e]=n),t},{});return{isFulfilled:0===Object.keys(a).length,blame:{message:"Found at least one control state and one event for which the associated transition are not condensated under a unique row! Cf. log",info:{statesTransitionsInfo:a}}}}},noConflictingTransitionsWithAncestorState={name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:function(t,e,n){n.stateEventTransitionsMaps;var r=n.eventTransitionsMaps,a=n.ancestorMap,i=Object.keys(r).filter(function(t){return t!==INIT_EVENT&&void 0!==t}).reduce(function(t,e){var n=Object.keys(r[e]),i=n.filter(function(t){return t!==INIT_STATE}).map(function(t){return a[t]&&_defineProperty({},t,a[t].find(function(t){return n.indexOf(t)>-1}))}).filter(function(t){return t&&Object.values(t).filter(Boolean).length>0});return i.length>0&&(t[e]=i),t},{});return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found two conflicting transitions! A -ev-> X, and B -ev-> Y leads to ambiguity if A < B or B < A. Cf. log",info:{eventTransitionsInfo:i}}}}},isHistoryStatesTargetStates={name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:function(t,e,n){_objectDestructuringEmpty(n);var r=t.transitions.reduce(function(t,e){return isHistoryControlState(e.from)?t.concat(e):t},[]);return{isFulfilled:0===Object.keys(r).length,blame:{message:"Found a history pseudo state configured as the origin control state for a transition. History pseudo states should only be target control states. Cf. log",info:{wrongHistoryStates:r}}}}},isHistoryStatesCompoundStates={name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.statesType,i=Object.keys(r).map(function(t){return t===INIT_STATE?[]:Object.keys(r[t]).reduce(function(e,n){var i=r[t][n][0],o=i.guards,s=i.to;return o?o.reduce(function(t,e){var n=e.to;return isHistoryControlState(n)&&!a[getHistoryUnderlyingState(n)]?t.concat(i):t},e):isHistoryControlState(s)&&!a[getHistoryUnderlyingState(s)]?e.concat(i):e},[])}).reduce(function(t,e){return t.concat(e)},[]);return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found a history pseudo state connected to an atomic state! History pseudo states only refer to compound states. Cf. log",info:{wrongHistoryStates:i,states:t.states}}}}},isHistoryStatesExisting={name:"isHistoryStatesExisting",shouldThrow:!1,predicate:function(t,e,n){var r=n.historyStatesMap,a=n.statesType,i=Array.from(r.entries()).map(function(t){var e=_slicedToArray(t,2),n=e[0],r=e[1];return!(n in a)&&{historyState:n,flatTransitions:r}}).filter(Boolean),o=Object.keys(i).length;return{isFulfilled:0===o,blame:{message:"Found ".concat(o," history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition."),info:{invalidTransitions:i,states:t.states}}}}};function isInconditionalTransition(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&isControlState(e)&&isEvent(n)&&isControlState(a)&&isActionFactory(i)}function isValidGuard(t){var e=t.to,n=t.predicate,r=t.action;return e&&isControlState(e)&&isFunction(n)&&isActionFactory(r)}function areCconditionalTransitions(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&isControlState(e)&&isEvent(n)&&r.every(isValidGuard)}var isValidFsmDef={name:"isValidFsmDef",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=t.states,a=t.events,i=(t.initialExtendedState,n&&Array.isArray(n)),o=r&&"object"===_typeof(r),s=a&&Array.isArray(a);return i?o?s?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:a}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:r}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:n}}}}},haveTransitionsValidTypes={name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=n.map(function(t,e){return!isInconditionalTransition(t)&&!areCconditionalTransitions(t)&&{transition:t,index:e}}).filter(Boolean),a=Object.keys(r).length;return{isFulfilled:0===a,blame:{message:"Found ".concat(a," transitions with invalid format! Check logs for more details."),info:{wrongTransitions:r,transitions:n}}}}},areEventsDeclared={name:"areEventsDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.eventTransitionsMaps,a=Object.keys(r),i=t.events,o=i.map(function(t){return-1===a.indexOf(t)&&t}).filter(Boolean),s=a.map(function(t){return-1===i.indexOf(t)&&t}).filter(Boolean).filter(function(t){return t!==INIT_EVENT&&"undefined"!==t});return{isFulfilled:0===o.length&&0===s.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:o,eventsNotDeclaredButTriggeringTransitions:s}}}}},areStatesDeclared={name:"areStatesDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.targetStatesMap,i=n.statesType,o=Object.keys(r),s=Array.from(a.keys()).filter(function(t){return"object"!==_typeof(t)}),c=Object.keys([o,s].reduce(function(t,e){return e.forEach(function(e){return t[e]=!0}),t},{})),u=Object.keys(i),l=u.map(function(t){return-1===c.indexOf(t)&&t}).filter(Boolean),f=c.map(function(t){return t!==INIT_STATE&&-1===u.indexOf(t)&&t}).filter(Boolean);return{isFulfilled:0===l.length&&0===f.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:l,statesNotDeclaredButTriggeringTransitions:f}}}}},isValidSettings={name:"isValidSettings",shouldThrow:!1,predicate:function(t){return{isFulfilled:!0,blame:void 0}}},isInitialStateOriginState={name:"isInitialStateOriginState",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap;return Array.from(r.keys()).indexOf(INIT_STATE)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(r.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}}},isValidSelfTransition={name:"isValidSelfTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap,a=n.statesType,i=Array.from(r.keys()).map(function(t){return r.get(t).map(function(e){var n=e.from,r=e.event;if(t in a&&!a[t]&&n&&n===t&&!r)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(function(t){return t.length>0});return{isFulfilled:0===i.length,blame:{message:"Found at least one eventless self-transition involving an atomic state! This is forbidden to avoid infinity loop! Cf. log",info:{wrongSelfTransitions:i}}}}},fsmContracts={injected:function(t,e){return{statesType:getStatesType(t.states),initTransition:findInitTransition(t.transitions),statesTransitionsMap:getStatesTransitionsMap(t.transitions),stateEventTransitionsMaps:getStateEventTransitionsMaps(t.transitions),eventTransitionsMaps:getEventTransitionsMaps(t.transitions),ancestorMap:getAncestorMap(t.states),statesPath:getStatesPath(t.states),historyStatesMap:getHistoryStatesMap(t.transitions),targetStatesMap:getTargetStatesMap(t.transitions)}},description:"FSM structure",contracts:[isValidFsmDef,isValidSettings,isInitialControlStateDeclared,isInitialStateOriginState,eventsAreStrings,haveTransitionsValidTypes,noDuplicatedStates,noReservedStates,atLeastOneState,areEventsDeclared,areStatesDeclared,validInitialConfig,validInitialTransition,initEventOnlyInCompoundStates,validInitialTransitionForCompoundState,validEventLessTransitions,isValidSelfTransition,allStateTransitionsOnOneSingleRow,noConflictingTransitionsWithAncestorState,isHistoryStatesExisting,isHistoryStatesTargetStates,isHistoryStatesCompoundStates]};function makeContractHandler(t,e){var n=e&&e.debug&&e.debug.console||emptyConsole,r=e&&e.debug&&e.debug.trace||noop,a=t.description;return function(){for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];var s=[],c=t.injected.apply(null,i),u={isFulfilled:t.contracts.reduce(function(t,e){var r=e.name,o=e.predicate,u=e.shouldThrow,l=i.concat(c),f=o.apply(null,l),d=f.isFulfilled,T=f.blame,p="".concat(a," FAILS ").concat(r,"!"),m=T||{},_=m.message,y=m.info;if(d)return t;if(s.push({name:r,message:_,info:y}),n.error(p),n.error([r,_].join(": ")),n.debug("Supporting error data:",y),u)throw new Error([p,"check console for information!"].join("\n"));return!1},!0),failingContracts:s};return r(_defineProperty({},CONTRACTS_EVAL,u)),u}}var fsmContractChecker=function(t,e,n){return makeContractHandler(n,e)(t,e)};function alwaysTrue(){return!0}function build_nested_state_structure(t){var e="State",n={},r={};function a(){}return t={nok:t},a.prototype={current_state_name:INIT_STATE},n[INIT_STATE]=new a,n[STATE_PROTOTYPE_NAME]=new a,function t(a,i){keys(a).forEach(function(o){var s=a[o];if(n[o]=new i,n[o].name=o,n[o].parent_name=get_fn_name(i),n[o].root_name=e,"object"===_typeof(s)){r[o]=!0;var c=function(){};c.displayName=o,c.prototype=n[o],t(s,c)}})}(t,a),{hash_states:n,is_group_state:r}}function normalizeTransitions(t){var e=t.initialControlState,n=t.transitions,r=findInitTransition(n);return e?n.concat([{from:INIT_STATE,event:INIT_EVENT,to:e,action:ACTION_IDENTITY}]):r?n:void 0}function create_state_machine(t,e){return createStateMachine(t,e)}function createStateMachine(t,e){var n=t.states,r=(t.events,t.initialExtendedState),a=t.updateState,i=e||{},o=i.debug,s=i.devTool,c=(i.displayName,o&&o.checkContracts||void 0),u=o&&o.console||emptyConsole,l=s&&s.tracer||emptyTracer,f=function(t){throw new KinglyError(t,u,l)};if(c){var d=fsmContractChecker(t,e,c).failingContracts;try{d.length>0&&f({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:e,failingContracts:d},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return l({type:MACHINE_CREATION_ERROR_MSG,trace:{info:t.errors,message:t.message,machineState:{cs:INIT_STATE,es:m,hs:g}}}),t}}var T=normalizeTransitions(t),p=build_nested_state_structure(n),m=r,_=computeHistoryMaps(n),y=_.stateList,h=_.stateAncestors,g=initHistoryDataStructure(y),v={},S={},E=p.is_group_state,O=p.hash_states;function N(){return O[INIT_STATE].current_state_name}function b(t,e){var n;n=assert(isEventStruct,[t]),c&&n&&f(n);var r=destructureEvent(t),a=r.eventName,i=r.eventData,s=N();return u.debug("send event",t),e&&a===INIT_EVENT&&s!==INIT_STATE?(l({type:WARN_MSG,trace:{info:{eventName:a,eventData:i},message:"The external event INIT_EVENT can only be sent when starting the machine!",machineState:{cs:s,es:m,hs:g}}}),u.warn("The external event INIT_EVENT can only be sent when starting the machine!"),null):function(t,e,n,r){var a=t[INIT_STATE].current_state_name,i=t[a][e];if(i){u.log("found event handler!"),u.info("WHEN EVENT ",e,n);var s=i(r,n,a),c=s.stop,f=s.outputs;o&&!c&&u.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var d=arrayizeOutput(f),T=t[INIT_STATE].current_state_name;if(S[T]&&T!==a){var p=v[T]?INIT_EVENT:AUTO_EVENT;l({type:INTERNAL_INPUT_MSG,trace:{info:{eventName:p,eventData:n},event:_defineProperty({},p,n),machineState:{cs:N(),es:r,hs:g}}});var m=b(_defineProperty({},p,n),!1);return l({type:INTERNAL_OUTPUTS_MSG,trace:{outputs:m,machineState:{cs:N(),es:r,hs:g}}}),[].concat(d).concat(m)}return d}return u.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!")),l({type:WARN_MSG,trace:{info:{received:_defineProperty({},e,n)},message:"There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!"),machineState:{cs:a,es:r,hs:g}}}),null}(p.hash_states,a,i,m)}T.forEach(function(t){var n=t.from,r=t.to,i=t.action,s=t.event,c=t.guards;c||(c=[{predicate:void 0,to:r,action:i}]),s===INIT_EVENT&&(v[n]=!0);var d=O[n];s||(s=AUTO_EVENT,S[n]=!0),E[n]&&v[n]&&(S[n]=!0),d[s]=c.reduce(function(t,r,i){var c=r.action||ACTION_IDENTITY,d=c.name||c.displayName||"",T=function(t,e){var r=function(r,T,p){n=p||n;var _=t.predicate||alwaysTrue,y=_.name||_.displayName||"<anonymous>",S=t.to,E=function(e,r,a){try{return _(e,r,a)}catch(o){f({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:e,event:s,event_data:r,settings:a,guard:t,from:n,to:S,index:i},message:["Error occurred while processing event ".concat(s," with target state ").concat(S),o.message].join("\n"),stack:o.stack})}}(r,T,e);if("boolean"!=typeof E&&f({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:s,guard:t,from:n,to:S,index:i,shouldTransitionBeTaken:E},message:"Guard index ".concat(i," with name ").concat(y," did not return a boolean!")}),E){u.info("IN STATE ",n),t.predicate?(l({type:DEBUG_MSG,trace:{message:"The guard ".concat(y," is fulfilled"),info:{eventData:T,from:n,action:d,to:S},machineState:{cs:p,es:r,hs:g}}}),u.info("CASE: guard ".concat(_.name," for transition is fulfilled"))):(l({type:DEBUG_MSG,trace:{message:"Evaluating transition with no guards",info:{eventData:T,from:n,action:d,to:S},machineState:{cs:p,es:m,hs:g}}}),u.info("CASE: unguarded transition")),u.info("THEN : we execute the action "+d);var b=function(e,r,a){try{return c(e,r,a)}catch(r){f({when:"Executing action factory ".concat(d),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:e,event:s,event_data:T,settings:a,guard:t,from:n,to:S,index:i,action:c},message:r.message,stack:r.stack})}}(r,T,e);isActions(b)||f({when:"Executing action factory ".concat(d),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:m,event:s,event_data:T,settings:e,guard:t,from:n,to:S,index:i,action:c,actionResult:b},message:"Action factory returned a value that does not have the expected shape!"});var I=b.updates,A=b.outputs;!function(t,e,n){var r=n[t].name;g=updateHistory(g,h,r),u.info("left state",wrap(t))}(n,0,O),m=function(t,e){var n=a.name||a.displayName||"";try{return a(t,e)}catch(r){f({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,I);var R=function(t,e,n){var r;if(isHistoryControlState(t)){var a=t.deep?DEEP:t.shallow?SHALLOW:void 0,i=t[a];o&&u&&!v[i]&&u.error("Configured a history state which does not relate to a compound state! The behaviour of the machine is thus unspecified. Please review your machine configuration"),n[r=g[a][i]||i]}else t?r=n[t].name:f("enter_state : unknown case! Not a state name, and not a history state to enter!");return n[INIT_STATE].current_state_name=r,l({type:DEBUG_MSG,trace:{message:isHistoryControlState(t)?"Entering history state for ".concat(t[t.deep?DEEP:t.shallow?SHALLOW:void 0]):"Entering state ".concat(t),machineState:{cs:N(),es:m,hs:g}}}),o&&u.info("AND TRANSITION TO STATE",r),r}(S,0,O);return u.info("ENTERING NEXT STATE: ",R),u.info("with extended state: ",m),{stop:!0,outputs:A}}return l({type:DEBUG_MSG,trace:{message:t.predicate?"The guard ".concat(y," is not fulfilled!"):"Evaluated and skipped transition",info:{eventData:T,settings:e,guard:t,from:n,to:S,index:i,action:d},machineState:{cs:p,es:m,hs:g}}}),{stop:!1,outputs:null}};return r.displayName=n+"",r}(r,e);return function(e,n,r){var a=t(e,n,r);return a.stop?a:T(e,n,r)}},function(){return{stop:!1,outputs:null}})});try{l({type:INIT_INPUT_MSG,trace:{info:{eventName:INIT_EVENT,eventData:r},event:_defineProperty({},INIT_EVENT,r),machineState:{cs:N(),es:m,hs:g}}}),b(_defineProperty({},INIT_EVENT,r),!0)}catch(n){return l({type:MACHINE_CREATION_ERROR_MSG,trace:{message:n.message,info:{fsmDef:t,settings:e,error:n},machineState:{cs:INIT_STATE,es:m,hs:g}}}),n}return function(t){try{var e=destructureEvent(t),n=e.eventName,r=e.eventData,a=N();l({type:INPUT_MSG,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:m,hs:g}}});var i=b(t,!0);return o&&u.info("OUTPUTS:",i),l({type:OUTPUTS_MSG,trace:{outputs:i,machineState:{cs:N(),es:m,hs:g}}}),i}catch(t){if(t instanceof KinglyError)return l({type:ERROR_MSG,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:N(),es:m,hs:g}}}),t;throw l({type:ERROR_MSG,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:N(),es:m,hs:g}}}),u.error("yyield > unexpected error!",t),t}}}function makeWebComponentFromFsm(t){var e=t.name,n=t.eventHandler,r=t.fsm,a=t.commandHandlers,i=t.effectHandlers,o=t.options,s=function(t){function s(){var t;if(_classCallCheck(this,s),e.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";var c=_assertThisInitialized(t=_possibleConstructorReturn(this,_getPrototypeOf(s).call(this)));t.eventSubject=n,t.options=Object.assign({},o);var u=t.options.NO_ACTION||null;return t.eventSubject.subscribe({next:function(e){var n=r(e);n!==u&&n.forEach(function(e){if(e!==u){var n=e.command,r=e.params;a[n](t.eventSubject.next,r,i,c)}})}}),t}return _inherits(s,_wrapNativeSuper(HTMLElement)),_createClass(s,[{key:"connectedCallback",value:function(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}},{key:"disconnectedCallback",value:function(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}},{key:"attributeChangedCallback",value:function(t,e,n){this.constructor(),this.connectedCallback()}}],[{key:"observedAttributes",get:function(){return[]}}]),s}();return customElements.define(e,s)}function mergeOutputsFn(t){return t.reduce(function(t,e){return t.concat(e)},[])}function makeHistoryStates(t){var e=Object.keys(getFsmStateList(t));return function(t,n){var r;if(!e.includes(n))throw"makeHistoryStates: the state for which a history state must be constructed is not a configured state for the state machine under implementation!!";return _defineProperty(r={},t,n),_defineProperty(r,"type",history_symbol),r}}function historyState(t,e){return _defineProperty({},t,e)}function generateStatePlantUmlHeader(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(getDisplayName(t),'" as ').concat(t," <<NoContent>>")}function toPlantUml(t,e){var n=t.states,r=t.transitions,a=objectTreeLenses.getChildren,i=objectTreeLenses.getLabel,o=function(t){return t.join(SEP)},s=postOrderTraverseTree(objectTreeLenses,{seed:function(){return Map},visit:function(t,e,n){var s=e.get(n).path,c=i(n),u=stateToPlantUML(Object.keys(c)[0],times$1(function(e){return t.get(o(s.concat(e)))},function(t,e){return a(t,e).length}(n,e)),r);return t.set(o(s),u),t}},_defineProperty({},INIT_STATE,n)),c=s.get("0");return s.clear(),c}function stateToPlantUML(t,e,n){return["".concat(generateStatePlantUmlHeader(t,"")," {"),e.join("\n"),format_history_states(t,n),format_entry_transitions(t,n),"}",translate_transitions(t,n)].filter(function(t){return"\n"!==t&&""!==t}).join("\n")}function format_history_states(t,e){var n=e.reduce(function(e,n){return get_all_transitions(n).filter(is_history_transition).filter(is_to_history_control_state_of(t)).reduce(function(t,e){return t[format_history_transition_state_name(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(generateStatePlantUmlHeader(t,HISTORY_STATE_NAME))}).join("\n")}function translate_transitions(t,e){return[format_history_transitions(t,e),format_standard_transitions(t,e)].filter(Boolean).join("\n")}function format_standard_transitions(t,e){return t===INIT_STATE?"":e.map(function(e){return get_all_transitions(e).filter(is_from_control_state(t)).filter(function(t){return!is_entry_transition(t)}).filter(function(t){return!is_history_transition(t)}).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,TRANSITION_SYMBOL,a,TRANSITION_LABEL_START_SYMBOL,format_transition_label(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}function format_entry_transitions(t,e){return e.reduce(function(e,n){return get_all_transitions(n).filter(is_entry_transition).filter(is_from_control_state(t)).reduce(function(t,e){e.from;var n=e.to,r=e.predicate,a=e.action;return t.push("[*] ".concat(TRANSITION_SYMBOL," ").concat(n," ").concat(TRANSITION_LABEL_START_SYMBOL," ").concat(format_transition_label("",r,a))),t},e)},[]).join("\n")}function format_history_transitions(t,e){return e.map(function(e){return get_all_transitions(e).filter(is_from_control_state(t)).filter(is_history_transition).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,TRANSITION_SYMBOL,format_history_transition_state_name({from:e,to:a}),TRANSITION_LABEL_START_SYMBOL,format_transition_label(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}function toDagreVisualizerFormat(t){var e=t.states,n=t.transitions,r=objectTreeLenses.getLabel,a=objectTreeLenses.getChildren,i=arrayTreeLenses.constructTree,o=function(t){return t.join(SEP)},s=postOrderTraverseTree(objectTreeLenses,{seed:function(){return Map},visit:function(t,e,n){var s=e.get(n).path,c=r(n),u=Object.keys(c)[0],l=times$1(function(e){return t.get(o(s.concat(e)))},function(t,e){return a(t,e).length}(n,e));return t.set(o(s),i(u,l)),t}},_defineProperty({},INIT_STATE,e)).get("0"),c=n.map(function(t){var e=t.from,n=t.to,r=t.event,a=t.guards,i=t.action;return a?{from:e,event:r,guards:a.map(function(t){var e=t.predicate,n=t.to,r=t.action;return{predicate:e.name,to:n,action:r.name}})}:{from:e,to:n,event:r,action:i.name||"no action name?"}});return JSON.stringify({states:s,transitions:c})}export{fsmContracts,normalizeTransitions,create_state_machine,createStateMachine,makeWebComponentFromFsm,mergeOutputsFn,makeHistoryStates,historyState,toPlantUml,toDagreVisualizerFormat,CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE,SEP,TRANSITION_SYMBOL,TRANSITION_LABEL_START_SYMBOL,HISTORY_STATE_NAME,HISTORY_PREFIX,INIT_STATE,INIT_EVENT,AUTO_EVENT,STATE_PROTOTYPE_NAME,NO_STATE_UPDATE,NO_OUTPUT,ACTION_IDENTITY,history_symbol,SHALLOW,DEEP,WRONG_EVENT_FORMAT_ERROR,FUNCTION_THREW_ERROR,INVALID_ACTION_FACTORY_EXECUTED,INVALID_PREDICATE_EXECUTED,ACTION_FACTORY_DESC,ENTRY_ACTION_FACTORY_DESC,UPDATE_STATE_FN_DESC,PREDICATE_DESC,COMMAND_RENDER,CONTRACTS_EVAL,OUTPUTS_MSG,INPUT_MSG,WARN_MSG,MACHINE_CREATION_ERROR_MSG,ERROR_MSG,INTERNAL_INPUT_MSG,INTERNAL_OUTPUTS_MSG,DEBUG_MSG,INIT_INPUT_MSG,noop,emptyConsole,emptyTracer,isBoolean,isFunction,isControlState,isEvent,isActionFactory,make_states,make_events,get_fn_name,wrap,times$1 as times,always,keys,merge$1 as merge,is_history_transition,is_entry_transition,is_from_control_state,is_to_history_control_state_of,is_history_control_state_of,format_transition_label,format_history_transition_state_name,get_all_transitions,getDisplayName,mergeModelUpdates,chainModelUpdates,mergeActionFactories,identity,lastOf,getFsmStateList,getStatesType,getStatesPath,getStatesTransitionsMap,getStateEventTransitionsMaps,getEventTransitionsMaps,getHistoryStatesMap,getTargetStatesMap,getAncestorMap,computeHistoryMaps,mapOverTransitionsActions,reduceTransitions,everyTransition,computeTimesCircledOn,isInitState,isInitEvent,isEventless,arrayizeOutput,isHistoryControlState,getHistoryParentState,isShallowHistory,isDeepHistory,getHistoryType,getHistoryUnderlyingState,isHistoryStateEdge,initHistoryDataStructure,isCompoundState,isAtomicState,updateHistory,computeHistoryState,findInitTransition,tryCatch,tryCatchMachineFn,getFunctionName,assert,notifyThrows,handleFnExecError,notifyAndRethrow,throwIfInvalidActionResult,throwIfInvalidGuardResult,throwIfInvalidEntryActionResult,isActions,isEventStruct,isError,destructureEvent,formatUndefinedInJSON,KinglyError}; | ||
function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _createClass(t,e,n){return e&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),t}function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){_defineProperty(t,e,n[e])})}return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function _construct(t,e,n){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var a=new(Function.bind.apply(t,r));return n&&_setPrototypeOf(a,n.prototype),a}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(n,t)})(t)}function _objectDestructuringEmpty(t){if(null==t)throw new TypeError("Cannot destructure undefined")}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _iterableToArrayLimit(t,e){var n=[],r=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){a=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(a)throw i}}return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",SEP=".",TRANSITION_SYMBOL="--\x3e",TRANSITION_LABEL_START_SYMBOL=":",HISTORY_STATE_NAME="H",HISTORY_PREFIX="history.",INIT_STATE="nok",INIT_EVENT="init",AUTO_EVENT="auto",STATE_PROTOTYPE_NAME="State",NO_STATE_UPDATE=[],NO_OUTPUT=[],ACTION_IDENTITY=function(){return{outputs:NO_OUTPUT,updates:NO_STATE_UPDATE}},history_symbol={},SHALLOW="shallow",DEEP="deep",WRONG_EVENT_FORMAT_ERROR="The machine received an event which does not have the proper format. Expecting an object whose unique key is the event name, and value is the event data.",FUNCTION_THREW_ERROR=function(t,e){return"Exception thrown when executing ".concat(e," ").concat(t||"")},INVALID_ACTION_FACTORY_EXECUTED=function(t,e){return"".concat(FUNCTION_THREW_ERROR(t,e),"\nThe ").concat(e," returned a value which is not an action.")},INVALID_PREDICATE_EXECUTED=function(t,e){return"".concat(FUNCTION_THREW_ERROR(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},ACTION_FACTORY_DESC="action factory",ENTRY_ACTION_FACTORY_DESC="(decorating) entry action",UPDATE_STATE_FN_DESC="update state function",PREDICATE_DESC="predicate",COMMAND_RENDER="render",CONTRACTS_EVAL="CONTRACTS_EVAL",OUTPUTS_MSG="OUTPUTS_MSG",INPUT_MSG="INPUT_MSG",WARN_MSG="WARN_MSG",MACHINE_CREATION_ERROR_MSG="MACHINE_CREATION_ERROR_MSG",ERROR_MSG="ERROR_MSG",INTERNAL_INPUT_MSG="INTERNAL_INPUT_MSG",INTERNAL_OUTPUTS_MSG="INTERNAL_OUTPUTS_MSG",DEBUG_MSG="DEBUG_MSG",INIT_INPUT_MSG="INIT_INPUT_MSG";const PATH_ROOT=[0],PRE_ORDER="PRE_ORDER";function clone(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function merge(t,e){return Object.assign({},t,e)}function updatePathInTraversalState(t,e,n){n.forEach((n,r)=>{const a=t.get(e),i=t.get(n),o=i&&i.path;t.set(n,merge(i,{isAdded:!0,isVisited:!1,path:o||a.path.concat(r)}))})}function updateVisitInTraversalState(t,e){t.set(e,merge(t.get(e),{isVisited:!0}))}function visitTree(t,e){const{store:n,lenses:r,traverse:a}=t,{empty:i,add:o,takeAndRemoveOne:s,isEmpty:c}=n,{getChildren:u}=r,{visit:l,seed:f}=a,d=new Map,T="function"==typeof f?new(f()):clone(f);let p="function"==typeof i?new(i()):clone(i),m=T;for(o([e],p),d.set(e,{isAdded:!0,isVisited:!1,path:PATH_ROOT});!c(p);){const t=s(p),e=u(d,t);o(e,p),updatePathInTraversalState(d,t,e),m=l(m,d,t),updateVisitInTraversalState(d,t)}return d.clear(),m}function breadthFirstTraverseTree(t,e,n){const{getChildren:r}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function preorderTraverseTree(t,e,n){const{getChildren:r}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function postOrderTraverseTree(t,e,n){const{getChildren:r}=t,{seed:a,visit:i}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===r(t,e).length)(t,e);return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>o(e,t)?[]:r(e,t).concat([e])},traverse:{seed:a,visit:(t,e,n)=>o(n,e)?i(t,e,n):t}},n)}function isLeafLabel(t){return 0===objectTreeLenses.getChildren(t).length}const objectTreeLenses={isLeafLabel:isLeafLabel,getLabel:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getLabel > unexpected object tree value";return t},getChildren:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getChildren > unexpected value";{let e=Object.values(t)[0];return e&&"object"==typeof e&&!Array.isArray(e)?Object.keys(e).map(t=>({[t]:e[t]})):[]}},constructTree:(t,e)=>{const n=t&&Object.keys(t)&&Object.keys(t)[0];return 0===e.length?t:{[n]:Object.assign.apply(null,e)}}};function traverseObj(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:breadthFirstTraverseTree,PRE_ORDER:preorderTraverseTree,POST_ORDER:postOrderTraverseTree}[r]||preorderTraverseTree)(objectTreeLenses,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(PATH_ROOT)?t:i(t,e,n)}},n)}const arrayTreeLenses={getLabel:t=>Array.isArray(t)?t[0]:t,getChildren:t=>Array.isArray(t)?t[1]:[],constructTree:(t,e)=>e&&Array.isArray(e)&&e.length>0?[t,e]:t};var noop=function(){},emptyConsole={log:noop,warn:noop,info:noop,debug:noop,error:noop,trace:noop},emptyTracer=noop;function isBoolean(t){return"boolean"==typeof t}function isFunction(t){return"function"==typeof t}function isControlState(t){return t&&"string"==typeof t||isHistoryControlState(t)}function isEvent(t){return void 0===t||"string"==typeof t}function isActionFactory(t){return t&&"function"==typeof t}function make_states(t){return t.reduce(function(t,e){return t[e]="",t},{})}function make_events(t){return t}function get_fn_name(t){return/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}\s*$/.exec(t.toString())[1]}function wrap(t){return["-",t,"-"].join("")}function times$1(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function always(t){return t}function keys(t){return Object.keys(t)}function merge$1(t,e){return Object.assign({},t,e)}function is_history_transition(t){return t.to.startsWith(HISTORY_PREFIX)}function is_entry_transition(t){return t.event===INIT_EVENT}function is_from_control_state(t){return function(e){return e.from===t}}function is_to_history_control_state_of(t){return function(e){return is_history_control_state_of(t,e.to)}}function is_history_control_state_of(t,e){return e.substring(HISTORY_PREFIX.length)===t}function format_transition_label(t,e,n){var r=t||"";return e&&n?"".concat(r," [").concat(e.name,"] / ").concat(n.name):e?"".concat(r," [").concat(e.name,"]}"):n?"".concat(r," / ").concat(n.name):"".concat(r)}function format_history_transition_state_name(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(HISTORY_PREFIX.length),".").concat(HISTORY_STATE_NAME)}function get_all_transitions(t){var e=t.from,n=t.event,r=t.guards;return r?r.map(function(t){var r=t.predicate,a=t.to,i=t.action;return{from:e,event:n,predicate:r,to:a,action:i}}):[t]}function getDisplayName(t){return t.replace(/_/g," ")}function mergeModelUpdates(t){return function(e,n,r){return{updates:t.reduce(function(t,a){var i=a(e,n,r).updates;return i?t.concat(i):t},[]),outputs:NO_OUTPUT}}}function chainModelUpdates(t){return function(e,n,r){var a=r.updateState;return{updates:t.reduce(function(t,e){var i=t.extendedState,o=t.updates,s=e(i,n,r).updates;return{extendedState:a(i,o),updates:s}},{extendedState:e,updates:[]}).updates||[],outputs:NO_OUTPUT}}}function mergeActionFactories(t,e){return function(n,r,a){var i,o=e.map(function(t){return t(n,r,a)}),s=o.map(function(t){return t.updates||[]}),c=o.map(function(t){return t.outputs||{}});return{updates:(i=[]).concat.apply(i,_toConsumableArray(s)),outputs:t(c)}}}function identity(t,e,n){return{updates:[],outputs:NO_OUTPUT}}function lastOf(t){return t[t.length-1]}function formatActionName(t,e,n,r,a){var i=a?a.name:"",o=i?"[".concat(i,"]"):"",s=t?t.name:"identity";return"".concat(s||"unnamed action",":").concat(e,"-").concat(n,"->").concat(r," ").concat(o)}function getFsmStateList(t){var e=objectTreeLenses.getLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function getStatesType(t){var e=objectTreeLenses.getLabel,n=objectTreeLenses.isLeafLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(i)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function getStatesPath(t){var e=objectTreeLenses.getLabel;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,n,r){var a=n.get(r).path.join("."),i=e(r);return t[Object.keys(i)[0]]=a,t}},t)}function getStatesTransitionsMap(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function getStateEventTransitionsMaps(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function getEventTransitionsMaps(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return isHistoryControlState(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function getHistoryStatesMap(t){return reduceTransitions(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(isHistoryControlState(a)){var o=getHistoryUnderlyingState(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(isHistoryControlState(i)){var s=getHistoryUnderlyingState(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function getTargetStatesMap(t){return reduceTransitions(function(t,e,n,r){var a=e.to;return t.set(a,(t.get(a)||[]).concat([e])),t},new Map,t)||{}}function getAncestorMap(t){var e=objectTreeLenses.getLabel,n=objectTreeLenses.getChildren;return traverseObj({strategy:PRE_ORDER,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(a).map(function(t){return Object.keys(e(t))[0]}).forEach(function(e){t[e]=t[e]||[],t[e]=t[e].concat(o)}),t}},t)}function computeHistoryMaps(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var e=objectTreeLenses.getLabel,n=traverseObj({strategy:PRE_ORDER,seed:{stateList:[],stateAncestors:{}},visit:function(t,n,r){var a=e(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=n.get(r).path;n.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)n.set(JSON.stringify(s),INIT_STATE);else{var c=n.get(JSON.stringify(s));t.stateAncestors[i]=[c];var u=o.reduce(function(t,e){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=n.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[i]=u}return t}},t);return{stateList:n.stateList,stateAncestors:n.stateAncestors}}function mapOverTransitionsActions(t,e){return reduceTransitions(function(e,n,r,a){var i=n.from,o=n.event,s=n.to,c=n.action,u=n.predicate,l=t(c,n,r,a);return l.displayName=l.displayName||c&&(c.name||c.displayName||formatActionName(c,i,o,s,u)),void 0===u?e.push({from:i,event:o,to:s,action:l}):0===r?e.push({from:i,event:o,guards:[{to:s,predicate:u,action:l}]}):e[e.length-1].guards.push({to:s,predicate:u,action:l}),e},[],e)}function reduceTransitions(t,e,n){return n.reduce(function(e,n,r){var a=n.from,i=n.event,o=n.to,s=n.gen,c=n.action,u=n.guards;return u||(u=s?[{to:o,action:c,gen:s,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce(function(e,n,o){var s=n.to,c=n.action,u=n.gen,l=n.predicate;return t(e,u?{from:a,event:i,to:s,action:c,predicate:l,gen:u}:{from:a,event:i,to:s,action:c,predicate:l},o,r)},e)},e)}function everyTransition(t,e){return reduceTransitions(function(e,n){return e&&t(n)},!0,[e])}function computeTimesCircledOn(t,e){return t.reduce(function(t,n){return n===e?t+1:t},0)}function isInitState(t){return t===INIT_STATE}function isInitEvent(t){return t===INIT_EVENT}function isEventless(t){return void 0===t}function arrayizeOutput(t){return t===NO_OUTPUT?NO_OUTPUT:Array.isArray(t)?t:[t]}function isHistoryControlState(t){return"object"===_typeof(t)&&(DEEP in t||SHALLOW in t)}function getHistoryParentState(t){return t[SHALLOW]||t[DEEP]}function isShallowHistory(t){return t[SHALLOW]}function isDeepHistory(t){return t[DEEP]}function getHistoryType(t){return t[DEEP]?DEEP:SHALLOW}function getHistoryUnderlyingState(t){return t[getHistoryType(t)]}function isHistoryStateEdge(t){return void 0!==t.history}function initHistoryDataStructure(t){var e,n=function(){return t.reduce(function(t,e){return t[e]="",t},{})};return _defineProperty(e={},DEEP,n()),_defineProperty(e,SHALLOW,n()),e}function isCompoundState(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function isAtomicState(t,e){return!isCompoundState(t,e)}function updateHistory(t,e,n){var r,a=(_defineProperty(r={},DEEP,Object.assign({},t[DEEP])),_defineProperty(r,SHALLOW,Object.assign({},t[SHALLOW])),r);return n===INIT_STATE?a:((e[n]||[]).reduce(function(t,e){return a[DEEP][e]=n,a[SHALLOW][e]=t,e},n),a)}function computeHistoryState(t,e,n,r){var a=computeHistoryMaps(t),i=a.stateList,o=a.stateAncestors,s=initHistoryDataStructure(i);return(s=e.reduce(function(t,e){return updateHistory(t,o,e)},s))[n][r]}function findInitTransition(t){return t.find(function(t){return t.from===INIT_STATE&&t.event===INIT_EVENT})}function tryCatch(t,e){return function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];try{return t.apply(t,r)}catch(t){return e(t,r)}}}function tryCatchMachineFn(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return tryCatch(e,function(r,a){var i=new Error(r),o=getFunctionName(e),s=FUNCTION_THREW_ERROR(o,t);i.probableCause=r.probableCause?[r.probableCause,s].join("\n"):s;var c={fnName:o,params:n.reduce(function(t,e,n){return t[e]=a[n],t},{})};return i.info=r.info?[].concat([r.info]).concat([c]):c,i})}function getFunctionName(t){return t.name||t.displayName||"anonymous"}function assert(t,e){var n=t.name||t.name.displayName||"",r=t.apply(null,e);return!0===r?void 0:_objectSpread({},r,{when:"Checking contract",message:[r.message,"failed contract ".concat(n)].join("\n"),info:r.info})}function notifyThrows(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function handleFnExecError(t,e,n,r,a,i){var o=t.debug,s=t.console;return o&&n instanceof Error?(a({debug:o,console:s},n,e),!0):!(!o||r(n))&&(i({debug:o,console:s},n,e),!0)}function notifyAndRethrow(t,e){t.debug;throw notifyThrows(t.console,e),e}function throwIfInvalidActionResult(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=getFunctionName(a),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},notifyThrows(r,u),u}function throwIfInvalidGuardResult(t,e,n){t.debug;var r=t.console,a=getFunctionName(n.predicate),i=new Error(INVALID_PREDICATE_EXECUTED(a,PREDICATE_DESC));throw i.info={predicateName:a,params:n,returned:e},notifyThrows(r,i),i}function throwIfInvalidEntryActionResult(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=getFunctionName(a),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ENTRY_ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},notifyThrows(r,u),u}function isActions(t){return t&&"updates"in t&&"outputs"in t&&Array.isArray(t.outputs)}function isEventStruct(t){var e;return t&&"object"===_typeof(t)?Object.keys(t).length>1?(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:e=!0:(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"not an object!"},e}function isError(t){return t instanceof Error}function destructureEvent(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}function formatUndefinedInJSON(t){return JSON.stringify(t,function(t,e){return void 0===e?"undefined":e})}var KinglyError=function(t){function e(t,n,r){var a;_classCallCheck(this,e),(a=_possibleConstructorReturn(this,_getPrototypeOf(e).call(this,t&&t.message||""))).name="KinglyError",a.stack=t&&t.stack||a.stack,a.errors=t;var i=t||{},o=i.when,s=i.location,c=i.info,u=i.message,l=["At ".concat(s,": ").concat(o," => ").concat(u),c?"See extra info in console":""].join("\n");return n&&n.error(l),c&&n&&n.info(c),a}return _inherits(e,_wrapNativeSuper(Error)),e}(),noDuplicatedStates={name:"noDuplicatedStates",shouldThrow:!1,predicate:function(t,e){var n=objectTreeLenses.getLabel,r=traverseObj({strategy:PRE_ORDER,seed:{duplicatedStates:[],statesHashMap:{}},visit:function(t,e,r){var a=t.duplicatedStates,i=t.statesHashMap,o=n(r),s=Object.keys(o)[0];return s in i?{duplicatedStates:a.concat(s),statesHashMap:i}:{duplicatedStates:a,statesHashMap:(i[s]="",i)}}},t.states).duplicatedStates;return{isFulfilled:0===r.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:r}}}}},noReservedStates={name:"noReservedStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:-1===Object.keys(r).indexOf(INIT_STATE),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[INIT_STATE],statesType:r}}}}},atLeastOneState={name:"atLeastOneState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:Object.keys(r).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:r}}}}},isInitialControlStateDeclared={name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:function(t,e,n){n.initTransition;var r=n.statesType,a=t.initialControlState,i=(t.transitions,Object.keys(r));return a?{isFulfilled:i.indexOf(a)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:a,declaredStates:i}}}:{isFulfilled:!0,blame:void 0}}},eventsAreStrings={name:"eventsAreStrings",shouldThrow:!1,predicate:function(t,e){return{isFulfilled:t.events.every(function(t){return"string"==typeof t}),blame:{message:"Events must be an array of strings!",info:{events:t.events}}}}},validInitialConfig={name:"validInitialConfig",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState;return r&&a?{isFulfilled:!1,blame:{message:"Invalid machine configuration : defining an initial control state and an initial transition at the same time may lead to ambiguity and is forbidden!",info:{initialControlState:a,initTransition:r}}}:r||a?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Invalid machine configuration : you must define EITHER an initial control state OR an initial transition! Else in which state is the machine supposed to start?",info:{initialControlState:a,initTransition:r}}}}},validInitialTransition={name:"validInitialTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState,i=t.transitions.reduce(function(t,e){return e.from===INIT_STATE&&t.push(e),t},[]);return{isFulfilled:a&&!r||!a&&r&&1===i.length&&r.event===INIT_EVENT&&(isInconditionalTransition(r)||areCconditionalTransitions(r)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:r,initTransitions:i,initialControlState:a}}}}},initEventOnlyInCompoundStates={name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=(n.statesPath,Object.keys(a).filter(function(t){return!a[t]}).map(function(t){return _defineProperty({},t,r[t]&&r[t][INIT_EVENT])}).filter(function(t){return Object.values(t)[0]}));return{isFulfilled:0===i.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:i}}}}},validInitialTransitionForCompoundState={name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=n.statesPath,o=Object.keys(a).filter(function(t){return a[t]}),s=o.map(function(t){return r[t]&&r[t][INIT_EVENT]}),c=s.every(Boolean);if(!c)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:o.map(function(t){return _defineProperty({},t,!(!r[t]||!r[t][INIT_EVENT]))})}}};var u=c&&s.every(function(t){var e=t.guards,n=t.to;return e?e.map(function(t){return t.to}).every(function(t){return"string"==typeof t}):"string"==typeof n});return u?u&&s.every(function(t){var e=t.from,n=t.guards,r=t.to;return n?n.map(function(t){return t.to}).every(function(t){return e!==t&&i[t]&&i[t].startsWith(i[e])}):e!==r&&i[r]&&i[r].startsWith(i[e])})?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have a target state which is strictly below the compound state in the state hierarchy! ",info:{states:t.states,statesPath:i,entryTransitions:s}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have the associated target control states which are not a history pseudo-state. Cf. log",info:{entryTransitions:s}}}}},validEventLessTransitions={name:"validEventLessTransitions",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,a=n.statesType,i=(n.statesPath,Object.keys(a).map(function(t){return _defineProperty({},t,r[t]&&"".concat(void 0)in r[t]&&1!==Object.keys(r[t]).length)}).filter(function(t){return void 0!==Object.values(t)[0]&&Object.values(t)[0]}));return{isFulfilled:0===i.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:i}}}}},allStateTransitionsOnOneSingleRow={name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=Object.keys(r).reduce(function(t,e){var n=Object.keys(r[e]).filter(function(t){return r[e][t].length>1});return n.length>0&&(t[e]=n),t},{});return{isFulfilled:0===Object.keys(a).length,blame:{message:"Found at least one control state and one event for which the associated transition are not condensated under a unique row! Cf. log",info:{statesTransitionsInfo:a}}}}},noConflictingTransitionsWithAncestorState={name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:function(t,e,n){n.stateEventTransitionsMaps;var r=n.eventTransitionsMaps,a=n.ancestorMap,i=Object.keys(r).filter(function(t){return t!==INIT_EVENT&&void 0!==t}).reduce(function(t,e){var n=Object.keys(r[e]),i=n.filter(function(t){return t!==INIT_STATE}).map(function(t){return a[t]&&_defineProperty({},t,a[t].find(function(t){return n.indexOf(t)>-1}))}).filter(function(t){return t&&Object.values(t).filter(Boolean).length>0});return i.length>0&&(t[e]=i),t},{});return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found two conflicting transitions! A -ev-> X, and B -ev-> Y leads to ambiguity if A < B or B < A. Cf. log",info:{eventTransitionsInfo:i}}}}},isHistoryStatesTargetStates={name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:function(t,e,n){_objectDestructuringEmpty(n);var r=t.transitions.reduce(function(t,e){return isHistoryControlState(e.from)?t.concat(e):t},[]);return{isFulfilled:0===Object.keys(r).length,blame:{message:"Found a history pseudo state configured as the origin control state for a transition. History pseudo states should only be target control states. Cf. log",info:{wrongHistoryStates:r}}}}},isHistoryStatesCompoundStates={name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.statesType,i=Object.keys(r).map(function(t){return t===INIT_STATE?[]:Object.keys(r[t]).reduce(function(e,n){var i=r[t][n][0],o=i.guards,s=i.to;return o?o.reduce(function(t,e){var n=e.to;return isHistoryControlState(n)&&!a[getHistoryUnderlyingState(n)]?t.concat(i):t},e):isHistoryControlState(s)&&!a[getHistoryUnderlyingState(s)]?e.concat(i):e},[])}).reduce(function(t,e){return t.concat(e)},[]);return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found a history pseudo state connected to an atomic state! History pseudo states only refer to compound states. Cf. log",info:{wrongHistoryStates:i,states:t.states}}}}},isHistoryStatesExisting={name:"isHistoryStatesExisting",shouldThrow:!1,predicate:function(t,e,n){var r=n.historyStatesMap,a=n.statesType,i=Array.from(r.entries()).map(function(t){var e=_slicedToArray(t,2),n=e[0],r=e[1];return!(n in a)&&{historyState:n,flatTransitions:r}}).filter(Boolean),o=Object.keys(i).length;return{isFulfilled:0===o,blame:{message:"Found ".concat(o," history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition."),info:{invalidTransitions:i,states:t.states}}}}};function isInconditionalTransition(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&isControlState(e)&&isEvent(n)&&isControlState(a)&&isActionFactory(i)}function isValidGuard(t){var e=t.to,n=t.predicate,r=t.action;return e&&isControlState(e)&&isFunction(n)&&isActionFactory(r)}function areCconditionalTransitions(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&isControlState(e)&&isEvent(n)&&r.every(isValidGuard)}var isValidFsmDef={name:"isValidFsmDef",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=t.states,a=t.events,i=(t.initialExtendedState,n&&Array.isArray(n)),o=r&&"object"===_typeof(r),s=a&&Array.isArray(a);return i?o?s?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:a}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:r}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:n}}}}},haveTransitionsValidTypes={name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=n.map(function(t,e){return!isInconditionalTransition(t)&&!areCconditionalTransitions(t)&&{transition:t,index:e}}).filter(Boolean),a=Object.keys(r).length;return{isFulfilled:0===a,blame:{message:"Found ".concat(a," transitions with invalid format! Check logs for more details."),info:{wrongTransitions:r,transitions:n}}}}},areEventsDeclared={name:"areEventsDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.eventTransitionsMaps,a=Object.keys(r),i=t.events,o=i.map(function(t){return-1===a.indexOf(t)&&t}).filter(Boolean),s=a.map(function(t){return-1===i.indexOf(t)&&t}).filter(Boolean).filter(function(t){return t!==INIT_EVENT&&"undefined"!==t});return{isFulfilled:0===o.length&&0===s.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:o,eventsNotDeclaredButTriggeringTransitions:s}}}}},areStatesDeclared={name:"areStatesDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.targetStatesMap,i=n.statesType,o=Object.keys(r),s=Array.from(a.keys()).filter(function(t){return"object"!==_typeof(t)}),c=Object.keys([o,s].reduce(function(t,e){return e.forEach(function(e){return t[e]=!0}),t},{})),u=Object.keys(i),l=u.map(function(t){return-1===c.indexOf(t)&&t}).filter(Boolean),f=c.map(function(t){return t!==INIT_STATE&&-1===u.indexOf(t)&&t}).filter(Boolean);return{isFulfilled:0===l.length&&0===f.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:l,statesNotDeclaredButTriggeringTransitions:f}}}}},isValidSettings={name:"isValidSettings",shouldThrow:!1,predicate:function(t){return{isFulfilled:!0,blame:void 0}}},isInitialStateOriginState={name:"isInitialStateOriginState",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap;return Array.from(r.keys()).indexOf(INIT_STATE)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(r.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}}},isValidSelfTransition={name:"isValidSelfTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap,a=n.statesType,i=Array.from(r.keys()).map(function(t){return r.get(t).map(function(e){var n=e.from,r=e.event;if(t in a&&!a[t]&&n&&n===t&&!r)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(function(t){return t.length>0});return{isFulfilled:0===i.length,blame:{message:"Found at least one eventless self-transition involving an atomic state! This is forbidden to avoid infinity loop! Cf. log",info:{wrongSelfTransitions:i}}}}},fsmContracts={injected:function(t,e){return{statesType:getStatesType(t.states),initTransition:findInitTransition(t.transitions),statesTransitionsMap:getStatesTransitionsMap(t.transitions),stateEventTransitionsMaps:getStateEventTransitionsMaps(t.transitions),eventTransitionsMaps:getEventTransitionsMaps(t.transitions),ancestorMap:getAncestorMap(t.states),statesPath:getStatesPath(t.states),historyStatesMap:getHistoryStatesMap(t.transitions),targetStatesMap:getTargetStatesMap(t.transitions)}},description:"FSM structure",contracts:[isValidFsmDef,isValidSettings,isInitialControlStateDeclared,isInitialStateOriginState,eventsAreStrings,haveTransitionsValidTypes,noDuplicatedStates,noReservedStates,atLeastOneState,areEventsDeclared,areStatesDeclared,validInitialConfig,validInitialTransition,initEventOnlyInCompoundStates,validInitialTransitionForCompoundState,validEventLessTransitions,isValidSelfTransition,allStateTransitionsOnOneSingleRow,noConflictingTransitionsWithAncestorState,isHistoryStatesExisting,isHistoryStatesTargetStates,isHistoryStatesCompoundStates]};function makeContractHandler(t,e){var n=e&&e.debug&&e.debug.console||emptyConsole,r=e&&e.debug&&e.debug.trace||noop,a=t.description;return function(){for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];var s=[],c=t.injected.apply(null,i),u={isFulfilled:t.contracts.reduce(function(t,e){var r=e.name,o=e.predicate,u=e.shouldThrow,l=i.concat(c),f=o.apply(null,l),d=f.isFulfilled,T=f.blame,p="".concat(a," FAILS ").concat(r,"!"),m=T||{},_=m.message,y=m.info;if(d)return t;if(s.push({name:r,message:_,info:y}),n.error(p),n.error([r,_].join(": ")),n.debug("Supporting error data:",y),u)throw new Error([p,"check console for information!"].join("\n"));return!1},!0),failingContracts:s};return r(_defineProperty({},CONTRACTS_EVAL,u)),u}}var fsmContractChecker=function(t,e,n){return makeContractHandler(n,e)(t,e)};function alwaysTrue(){return!0}function build_nested_state_structure(t){var e="State",n={},r={};function a(){}return t={nok:t},a.prototype={current_state_name:INIT_STATE},n[INIT_STATE]=new a,n[STATE_PROTOTYPE_NAME]=new a,function t(a,i){keys(a).forEach(function(o){var s=a[o];if(n[o]=new i,n[o].name=o,n[o].parent_name=get_fn_name(i),n[o].root_name=e,"object"===_typeof(s)){r[o]=!0;var c=function(){};c.displayName=o,c.prototype=n[o],t(s,c)}})}(t,a),{hash_states:n,is_group_state:r}}function normalizeTransitions(t){var e=t.initialControlState,n=t.transitions,r=findInitTransition(n);return e?n.concat([{from:INIT_STATE,event:INIT_EVENT,to:e,action:ACTION_IDENTITY}]):r?n:void 0}function createStateMachine(t,e){var n=createStateMachineAPIs(t,e);return n instanceof Error?n:n.withProtectedState}function createPureStateMachine(t,e){var n=createStateMachineAPIs(t,e);return n instanceof Error?n:n.withPureInterface}function createStateMachineAPIs(t,e){var n=t.states,r=(t.events,t.initialExtendedState),a=t.updateState,i=e||{},o=i.debug,s=i.devTool,c=(i.displayName,o&&o.checkContracts||void 0),u=o&&o.console||emptyConsole,l=s&&s.tracer||emptyTracer,f=function(t){throw new KinglyError(t,u,l)};if(c){var d=fsmContractChecker(t,e,c).failingContracts;try{d.length>0&&f({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:e,failingContracts:d},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return l({type:MACHINE_CREATION_ERROR_MSG,trace:{info:t.errors,message:t.message,machineState:{cs:void 0,es:r,hs:void 0}}}),t}}var T=normalizeTransitions(t),p=build_nested_state_structure(n),m=r,_=computeHistoryMaps(n),y=_.stateList,h=_.stateAncestors,v=initHistoryDataStructure(y),g={},S={},E=p.is_group_state,O=p.hash_states;function N(){return O[INIT_STATE].current_state_name}function b(t,e){var n;n=assert(isEventStruct,[t]),c&&n&&f(n);var r=destructureEvent(t),a=r.eventName,i=r.eventData,s=N();return u.debug("send event",t),e&&a===INIT_EVENT&&s!==INIT_STATE?(l({type:WARN_MSG,trace:{info:{eventName:a,eventData:i},message:"The external event INIT_EVENT can only be sent when starting the machine!",machineState:{cs:s,es:m,hs:v}}}),u.warn("The external event INIT_EVENT can only be sent when starting the machine!"),null):function(t,e,n,r){var a=t[INIT_STATE].current_state_name,i=t[a][e];if(i){u.log("found event handler!"),u.info("WHEN EVENT ",e,n);var s=i(r,n,a),c=s.stop,f=s.outputs;o&&!c&&u.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var d=arrayizeOutput(f),T=t[INIT_STATE].current_state_name;if(S[T]&&T!==a){var p=g[T]?INIT_EVENT:AUTO_EVENT;l({type:INTERNAL_INPUT_MSG,trace:{info:{eventName:p,eventData:n},event:_defineProperty({},p,n),machineState:{cs:N(),es:r,hs:v}}});var m=b(_defineProperty({},p,n),!1);return l({type:INTERNAL_OUTPUTS_MSG,trace:{outputs:m,machineState:{cs:N(),es:r,hs:v}}}),[].concat(d).concat(m)}return d}return u.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!")),l({type:WARN_MSG,trace:{info:{received:_defineProperty({},e,n)},message:"There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!"),machineState:{cs:a,es:r,hs:v}}}),null}(p.hash_states,a,i,m)}function I(){return l({type:INIT_INPUT_MSG,trace:{info:{eventName:INIT_EVENT,eventData:r},event:_defineProperty({},INIT_EVENT,r),machineState:{cs:N(),es:m,hs:v}}}),b(_defineProperty({},INIT_EVENT,r),!0)}T.forEach(function(t){var n=t.from,r=t.to,i=t.action,s=t.event,c=t.guards;c||(c=[{predicate:void 0,to:r,action:i}]),s===INIT_EVENT&&(g[n]=!0);var d=O[n];s||(s=AUTO_EVENT,S[n]=!0),E[n]&&g[n]&&(S[n]=!0),d[s]=c.reduce(function(t,r,i){var c=r.action||ACTION_IDENTITY,d=c.name||c.displayName||"",T=function(t,e){var r=function(r,T,p){n=p||n;var _=t.predicate||alwaysTrue,y=_.name||_.displayName||"<anonymous>",S=t.to,E=function(e,r,a){try{return _(e,r,a)}catch(o){f({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:e,event:s,event_data:r,settings:a,guard:t,from:n,to:S,index:i},message:["Error occurred while processing event ".concat(s," with target state ").concat(S),o.message].join("\n"),stack:o.stack})}}(r,T,e);if("boolean"!=typeof E&&f({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:s,guard:t,from:n,to:S,index:i,shouldTransitionBeTaken:E},message:"Guard index ".concat(i," with name ").concat(y," did not return a boolean!")}),E){u.info("IN STATE ",n),t.predicate?(l({type:DEBUG_MSG,trace:{message:"The guard ".concat(y," is fulfilled"),info:{eventData:T,from:n,action:d,to:S},machineState:{cs:p,es:r,hs:v}}}),u.info("CASE: guard ".concat(_.name," for transition is fulfilled"))):(l({type:DEBUG_MSG,trace:{message:"Evaluating transition with no guards",info:{eventData:T,from:n,action:d,to:S},machineState:{cs:p,es:m,hs:v}}}),u.info("CASE: unguarded transition")),u.info("THEN : we execute the action "+d);var b=function(e,r,a){try{return c(e,r,a)}catch(r){f({when:"Executing action factory ".concat(d),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:e,event:s,event_data:T,settings:a,guard:t,from:n,to:S,index:i,action:c},message:r.message,stack:r.stack})}}(r,T,e);isActions(b)||f({when:"Executing action factory ".concat(d),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:m,event:s,event_data:T,settings:e,guard:t,from:n,to:S,index:i,action:c,actionResult:b},message:"Action factory returned a value that does not have the expected shape!"});var I=b.updates,A=b.outputs;!function(t,e,n){var r=n[t].name;v=updateHistory(v,h,r),u.info("left state",wrap(t))}(n,0,O),m=function(t,e){var n=a.name||a.displayName||"";try{return a(t,e)}catch(r){f({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,I);var R=function(t,e,n){var r;if(isHistoryControlState(t)){var a=t.deep?DEEP:t.shallow?SHALLOW:void 0,i=t[a];o&&u&&!g[i]&&u.error("Configured a history state which does not relate to a compound state! The behaviour of the machine is thus unspecified. Please review your machine configuration"),n[r=v[a][i]||i]}else t?r=n[t].name:f("enter_state : unknown case! Not a state name, and not a history state to enter!");return n[INIT_STATE].current_state_name=r,l({type:DEBUG_MSG,trace:{message:isHistoryControlState(t)?"Entering history state for ".concat(t[t.deep?DEEP:t.shallow?SHALLOW:void 0]):"Entering state ".concat(t),machineState:{cs:N(),es:m,hs:v}}}),o&&u.info("AND TRANSITION TO STATE",r),r}(S,0,O);return u.info("ENTERING NEXT STATE: ",R),u.info("with extended state: ",m),{stop:!0,outputs:A}}return l({type:DEBUG_MSG,trace:{message:t.predicate?"The guard ".concat(y," is not fulfilled!"):"Evaluated and skipped transition",info:{eventData:T,settings:e,guard:t,from:n,to:S,index:i,action:d},machineState:{cs:p,es:m,hs:v}}}),{stop:!1,outputs:null}};return r.displayName=n+"",r}(r,e);return function(e,n,r){var a=t(e,n,r);return a.stop?a:T(e,n,r)}},function(){return{stop:!1,outputs:null}})});try{I()}catch(n){return l({type:MACHINE_CREATION_ERROR_MSG,trace:{message:n.message,info:{fsmDef:t,settings:e,error:n},machineState:{cs:INIT_STATE,es:m,hs:v}}}),n}var A={withProtectedState:function(t){try{var e=destructureEvent(t),n=e.eventName,r=e.eventData,a=N();l({type:INPUT_MSG,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:m,hs:v}}});var i=b(t,!0);return o&&u.info("OUTPUTS:",i),l({type:OUTPUTS_MSG,trace:{outputs:i,machineState:{cs:N(),es:m,hs:v}}}),i}catch(t){if(t instanceof KinglyError)return l({type:ERROR_MSG,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:N(),es:m,hs:v}}}),t;throw l({type:ERROR_MSG,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:N(),es:m,hs:v}}}),u.error("yyield > unexpected error!",t),t}},withPureInterface:function(t,e){if(void 0===e);else if(null==e)m=r,v=initHistoryDataStructure(y),O[INIT_STATE].current_state_name=INIT_STATE,I();else{var n=e.cs,a=e.hs,i=e.es;m=i,v=a,O[INIT_STATE].current_state_name=n}return{outputs:A.withProtectedState(t),fsmState:{cs:N(),hs:v,es:m}}}};return A}function makeWebComponentFromFsm(t){var e=t.name,n=t.eventHandler,r=t.fsm,a=t.commandHandlers,i=t.effectHandlers,o=t.options,s=function(t){function s(){var t;if(_classCallCheck(this,s),e.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";var c=_assertThisInitialized(t=_possibleConstructorReturn(this,_getPrototypeOf(s).call(this)));t.eventSubject=n,t.options=Object.assign({},o);var u=t.options.NO_ACTION||null;return t.eventSubject.subscribe({next:function(e){var n=r(e);n!==u&&n.forEach(function(e){if(e!==u){var n=e.command,r=e.params;a[n](t.eventSubject.next,r,i,c)}})}}),t}return _inherits(s,_wrapNativeSuper(HTMLElement)),_createClass(s,[{key:"connectedCallback",value:function(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}},{key:"disconnectedCallback",value:function(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}},{key:"attributeChangedCallback",value:function(t,e,n){this.constructor(),this.connectedCallback()}}],[{key:"observedAttributes",get:function(){return[]}}]),s}();return customElements.define(e,s)}function mergeOutputsFn(t){return t.reduce(function(t,e){return t.concat(e)},[])}function makeHistoryStates(t){var e=Object.keys(getFsmStateList(t));return function(t,n){var r;if(!e.includes(n))throw"makeHistoryStates: the state for which a history state must be constructed is not a configured state for the state machine under implementation!!";return _defineProperty(r={},t,n),_defineProperty(r,"type",history_symbol),r}}function historyState(t,e){return _defineProperty({},t,e)}function generateStatePlantUmlHeader(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(getDisplayName(t),'" as ').concat(t," <<NoContent>>")}function toPlantUml(t,e){var n=t.states,r=t.transitions,a=objectTreeLenses.getChildren,i=objectTreeLenses.getLabel,o=function(t){return t.join(SEP)},s=postOrderTraverseTree(objectTreeLenses,{seed:function(){return Map},visit:function(t,e,n){var s=e.get(n).path,c=i(n),u=stateToPlantUML(Object.keys(c)[0],times$1(function(e){return t.get(o(s.concat(e)))},function(t,e){return a(t,e).length}(n,e)),r);return t.set(o(s),u),t}},_defineProperty({},INIT_STATE,n)),c=s.get("0");return s.clear(),c}function stateToPlantUML(t,e,n){return["".concat(generateStatePlantUmlHeader(t,"")," {"),e.join("\n"),format_history_states(t,n),format_entry_transitions(t,n),"}",translate_transitions(t,n)].filter(function(t){return"\n"!==t&&""!==t}).join("\n")}function format_history_states(t,e){var n=e.reduce(function(e,n){return get_all_transitions(n).filter(is_history_transition).filter(is_to_history_control_state_of(t)).reduce(function(t,e){return t[format_history_transition_state_name(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(generateStatePlantUmlHeader(t,HISTORY_STATE_NAME))}).join("\n")}function translate_transitions(t,e){return[format_history_transitions(t,e),format_standard_transitions(t,e)].filter(Boolean).join("\n")}function format_standard_transitions(t,e){return t===INIT_STATE?"":e.map(function(e){return get_all_transitions(e).filter(is_from_control_state(t)).filter(function(t){return!is_entry_transition(t)}).filter(function(t){return!is_history_transition(t)}).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,TRANSITION_SYMBOL,a,TRANSITION_LABEL_START_SYMBOL,format_transition_label(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}function format_entry_transitions(t,e){return e.reduce(function(e,n){return get_all_transitions(n).filter(is_entry_transition).filter(is_from_control_state(t)).reduce(function(t,e){e.from;var n=e.to,r=e.predicate,a=e.action;return t.push("[*] ".concat(TRANSITION_SYMBOL," ").concat(n," ").concat(TRANSITION_LABEL_START_SYMBOL," ").concat(format_transition_label("",r,a))),t},e)},[]).join("\n")}function format_history_transitions(t,e){return e.map(function(e){return get_all_transitions(e).filter(is_from_control_state(t)).filter(is_history_transition).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,TRANSITION_SYMBOL,format_history_transition_state_name({from:e,to:a}),TRANSITION_LABEL_START_SYMBOL,format_transition_label(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}function toDagreVisualizerFormat(t){var e=t.states,n=t.transitions,r=objectTreeLenses.getLabel,a=objectTreeLenses.getChildren,i=arrayTreeLenses.constructTree,o=function(t){return t.join(SEP)},s=postOrderTraverseTree(objectTreeLenses,{seed:function(){return Map},visit:function(t,e,n){var s=e.get(n).path,c=r(n),u=Object.keys(c)[0],l=times$1(function(e){return t.get(o(s.concat(e)))},function(t,e){return a(t,e).length}(n,e));return t.set(o(s),i(u,l)),t}},_defineProperty({},INIT_STATE,e)).get("0"),c=n.map(function(t){var e=t.from,n=t.to,r=t.event,a=t.guards,i=t.action;return a?{from:e,event:r,guards:a.map(function(t){var e=t.predicate,n=t.to,r=t.action;return{predicate:e.name,to:n,action:r.name}})}:{from:e,to:n,event:r,action:i.name||"no action name?"}});return JSON.stringify({states:s,transitions:c})}export{fsmContracts,normalizeTransitions,createStateMachine,createPureStateMachine,createStateMachineAPIs,makeWebComponentFromFsm,mergeOutputsFn,makeHistoryStates,historyState,toPlantUml,toDagreVisualizerFormat,CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE,SEP,TRANSITION_SYMBOL,TRANSITION_LABEL_START_SYMBOL,HISTORY_STATE_NAME,HISTORY_PREFIX,INIT_STATE,INIT_EVENT,AUTO_EVENT,STATE_PROTOTYPE_NAME,NO_STATE_UPDATE,NO_OUTPUT,ACTION_IDENTITY,history_symbol,SHALLOW,DEEP,WRONG_EVENT_FORMAT_ERROR,FUNCTION_THREW_ERROR,INVALID_ACTION_FACTORY_EXECUTED,INVALID_PREDICATE_EXECUTED,ACTION_FACTORY_DESC,ENTRY_ACTION_FACTORY_DESC,UPDATE_STATE_FN_DESC,PREDICATE_DESC,COMMAND_RENDER,CONTRACTS_EVAL,OUTPUTS_MSG,INPUT_MSG,WARN_MSG,MACHINE_CREATION_ERROR_MSG,ERROR_MSG,INTERNAL_INPUT_MSG,INTERNAL_OUTPUTS_MSG,DEBUG_MSG,INIT_INPUT_MSG,noop,emptyConsole,emptyTracer,isBoolean,isFunction,isControlState,isEvent,isActionFactory,make_states,make_events,get_fn_name,wrap,times$1 as times,always,keys,merge$1 as merge,is_history_transition,is_entry_transition,is_from_control_state,is_to_history_control_state_of,is_history_control_state_of,format_transition_label,format_history_transition_state_name,get_all_transitions,getDisplayName,mergeModelUpdates,chainModelUpdates,mergeActionFactories,identity,lastOf,getFsmStateList,getStatesType,getStatesPath,getStatesTransitionsMap,getStateEventTransitionsMaps,getEventTransitionsMaps,getHistoryStatesMap,getTargetStatesMap,getAncestorMap,computeHistoryMaps,mapOverTransitionsActions,reduceTransitions,everyTransition,computeTimesCircledOn,isInitState,isInitEvent,isEventless,arrayizeOutput,isHistoryControlState,getHistoryParentState,isShallowHistory,isDeepHistory,getHistoryType,getHistoryUnderlyingState,isHistoryStateEdge,initHistoryDataStructure,isCompoundState,isAtomicState,updateHistory,computeHistoryState,findInitTransition,tryCatch,tryCatchMachineFn,getFunctionName,assert,notifyThrows,handleFnExecError,notifyAndRethrow,throwIfInvalidActionResult,throwIfInvalidGuardResult,throwIfInvalidEntryActionResult,isActions,isEventStruct,isError,destructureEvent,formatUndefinedInJSON,KinglyError}; | ||
//# sourceMappingURL=kingly.es.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Kingly={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t,e,n){return(c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var a=new(Function.bind.apply(t,r));return n&&s(a,n.prototype),a}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)})(t)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?f(t):e}function d(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){a=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(a)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var h=".",m="--\x3e",v=":",g="H",y="history.",b="nok",T="init",S="auto",E="State",O=[],_=[],w=function(){return{outputs:_,updates:O}},A={},N="shallow",j="deep",C="The machine received an event which does not have the proper format. Expecting an object whose unique key is the event name, and value is the event data.",k=function(t,e){return"Exception thrown when executing ".concat(e," ").concat(t||"")},M=function(t,e){return"".concat(k(t,e),"\nThe ").concat(e," returned a value which is not an action.")},R=function(t,e){return"".concat(k(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},I="action factory",F="(decorating) entry action",x="predicate",D="CONTRACTS_EVAL",P="OUTPUTS_MSG",L="INPUT_MSG",H="WARN_MSG",U="MACHINE_CREATION_ERROR_MSG",B="ERROR_MSG",G="INTERNAL_INPUT_MSG",V="INTERNAL_OUTPUTS_MSG",W="DEBUG_MSG",Y="INIT_INPUT_MSG";const J=[0],K="PRE_ORDER";function X(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function q(t,e){return Object.assign({},t,e)}function z(t,e,n){n.forEach((n,r)=>{const a=t.get(e),i=t.get(n),o=i&&i.path;t.set(n,q(i,{isAdded:!0,isVisited:!1,path:o||a.path.concat(r)}))})}function $(t,e){t.set(e,q(t.get(e),{isVisited:!0}))}function Q(t,e){const{store:n,lenses:r,traverse:a}=t,{empty:i,add:o,takeAndRemoveOne:s,isEmpty:c}=n,{getChildren:u}=r,{visit:f,seed:l}=a,d=new Map,p="function"==typeof l?new(l()):X(l);let h="function"==typeof i?new(i()):X(i),m=p;for(o([e],h),d.set(e,{isAdded:!0,isVisited:!1,path:J});!c(h);){const t=s(h),e=u(d,t);o(e,h),z(d,t,e),m=f(m,d,t),$(d,t)}return d.clear(),m}function Z(t,e,n){const{getChildren:r}=t;return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function tt(t,e,n){const{getChildren:r}=t;return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function et(t,e,n){const{getChildren:r}=t,{seed:a,visit:i}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===r(t,e).length)(t,e);return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>o(e,t)?[]:r(e,t).concat([e])},traverse:{seed:a,visit:(t,e,n)=>o(n,e)?i(t,e,n):t}},n)}const nt={isLeafLabel:function(t){return 0===nt.getChildren(t).length},getLabel:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getLabel > unexpected object tree value";return t},getChildren:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getChildren > unexpected value";{let e=Object.values(t)[0];return e&&"object"==typeof e&&!Array.isArray(e)?Object.keys(e).map(t=>({[t]:e[t]})):[]}},constructTree:(t,e)=>{const n=t&&Object.keys(t)&&Object.keys(t)[0];return 0===e.length?t:{[n]:Object.assign.apply(null,e)}}};function rt(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:Z,PRE_ORDER:tt,POST_ORDER:et}[r]||tt)(nt,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(J)?t:i(t,e,n)}},n)}const at={getLabel:t=>Array.isArray(t)?t[0]:t,getChildren:t=>Array.isArray(t)?t[1]:[],constructTree:(t,e)=>e&&Array.isArray(e)&&e.length>0?[t,e]:t};var it=function(){},ot={log:it,warn:it,info:it,debug:it,error:it,trace:it},st=it;function ct(t){return"function"==typeof t}function ut(t){return t&&"string"==typeof t||Pt(t)}function ft(t){return void 0===t||"string"==typeof t}function lt(t){return t&&"function"==typeof t}function dt(t){return/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}\s*$/.exec(t.toString())[1]}function pt(t){return["-",t,"-"].join("")}function ht(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function mt(t){return Object.keys(t)}function vt(t){return t.to.startsWith(y)}function gt(t){return t.event===T}function yt(t){return function(e){return e.from===t}}function bt(t){return function(e){return Tt(t,e.to)}}function Tt(t,e){return e.substring(y.length)===t}function St(t,e,n){var r=t||"";return e&&n?"".concat(r," [").concat(e.name,"] / ").concat(n.name):e?"".concat(r," [").concat(e.name,"]}"):n?"".concat(r," / ").concat(n.name):"".concat(r)}function Et(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(y.length),".").concat(g)}function Ot(t){var e=t.from,n=t.event,r=t.guards;return r?r.map(function(t){var r=t.predicate,a=t.to,i=t.action;return{from:e,event:n,predicate:r,to:a,action:i}}):[t]}function _t(t){return t.replace(/_/g," ")}function wt(t){var e=nt.getLabel;return rt({strategy:K,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function At(t){var e=nt.getLabel,n=nt.isLeafLabel;return rt({strategy:K,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(i)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function Nt(t){var e=nt.getLabel;return rt({strategy:K,seed:{},visit:function(t,n,r){var a=n.get(r).path.join("."),i=e(r);return t[Object.keys(i)[0]]=a,t}},t)}function jt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function Ct(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function kt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function Mt(t){return xt(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(Pt(a)){var o=Ht(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(Pt(i)){var s=Ht(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function Rt(t){return xt(function(t,e,n,r){var a=e.to;return t.set(a,(t.get(a)||[]).concat([e])),t},new Map,t)||{}}function It(t){var e=nt.getLabel,n=nt.getChildren;return rt({strategy:K,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(a).map(function(t){return Object.keys(e(t))[0]}).forEach(function(e){t[e]=t[e]||[],t[e]=t[e].concat(o)}),t}},t)}function Ft(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var e=nt.getLabel,n=rt({strategy:K,seed:{stateList:[],stateAncestors:{}},visit:function(t,n,r){var a=e(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=n.get(r).path;n.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)n.set(JSON.stringify(s),b);else{var c=n.get(JSON.stringify(s));t.stateAncestors[i]=[c];var u=o.reduce(function(t,e){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=n.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[i]=u}return t}},t);return{stateList:n.stateList,stateAncestors:n.stateAncestors}}function xt(t,e,n){return n.reduce(function(e,n,r){var a=n.from,i=n.event,o=n.to,s=n.gen,c=n.action,u=n.guards;return u||(u=s?[{to:o,action:c,gen:s,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce(function(e,n,o){var s=n.to,c=n.action,u=n.gen,f=n.predicate;return t(e,u?{from:a,event:i,to:s,action:c,predicate:f,gen:u}:{from:a,event:i,to:s,action:c,predicate:f},o,r)},e)},e)}function Dt(t){return t===_?_:Array.isArray(t)?t:[t]}function Pt(t){return"object"===e(t)&&(j in t||N in t)}function Lt(t){return t[j]?j:N}function Ht(t){return t[Lt(t)]}function Ut(t){var e,n=function(){return t.reduce(function(t,e){return t[e]="",t},{})};return a(e={},j,n()),a(e,N,n()),e}function Bt(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function Gt(t,e,n){return n===b?t:((e[n]||[]).reduce(function(e,r){return t[j][r]=n,t[N][r]=e,r},n),t)}function Vt(t){return t.find(function(t){return t.from===b&&t.event===T})}function Wt(t,e){return function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];try{return t.apply(t,r)}catch(t){return e(t,r)}}}function Yt(t){return t.name||t.displayName||"anonymous"}function Jt(t,e){var n=t.name||t.name.displayName||"",r=t.apply(null,e);return!0===r?void 0:function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){a(t,e,n[e])})}return t}({},r,{when:"Checking contract",message:[r.message,"failed contract ".concat(n)].join("\n"),info:r.info})}function Kt(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function Xt(t){return t&&"updates"in t&&"outputs"in t&&Array.isArray(t.outputs)}function qt(t){var n;return t&&"object"===e(t)?Object.keys(t).length>1?(n=new Error(C)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:n=!0:(n=new Error(C)).info={event:t,cause:"not an object!"},n}function zt(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}var $t=function(t){function e(t,r,a){var i;n(this,e),(i=l(this,o(e).call(this,t&&t.message||""))).name="KinglyError",i.stack=t&&t.stack||i.stack,i.errors=t;var s=t||{},c=s.when,u=s.location,f=s.info,d=s.message,p=["At ".concat(u,": ").concat(c," => ").concat(d),f?"See extra info in console":""].join("\n");return r&&r.error(p),f&&r&&r.info(f),i}return i(e,u(Error)),e}();function Qt(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&ut(e)&&ft(n)&&ut(a)&<(i)}function Zt(t){var e=t.to,n=t.predicate,r=t.action;return e&&ut(e)&&ct(n)&<(r)}function te(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&ut(e)&&ft(n)&&r.every(Zt)}var ee={injected:function(t,e){return{statesType:At(t.states),initTransition:Vt(t.transitions),statesTransitionsMap:jt(t.transitions),stateEventTransitionsMaps:Ct(t.transitions),eventTransitionsMaps:kt(t.transitions),ancestorMap:It(t.states),statesPath:Nt(t.states),historyStatesMap:Mt(t.transitions),targetStatesMap:Rt(t.transitions)}},description:"FSM structure",contracts:[{name:"isValidFsmDef",shouldThrow:!1,predicate:function(t,n){var r=t.transitions,a=t.states,i=t.events,o=(t.initialExtendedState,r&&Array.isArray(r)),s=a&&"object"===e(a),c=i&&Array.isArray(i);return o?s?c?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:i}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:a}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:r}}}}},{name:"isValidSettings",shouldThrow:!1,predicate:function(t){return{isFulfilled:!0,blame:void 0}}},{name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:function(t,e,n){n.initTransition;var r=n.statesType,a=t.initialControlState,i=(t.transitions,Object.keys(r));return a?{isFulfilled:i.indexOf(a)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:a,declaredStates:i}}}:{isFulfilled:!0,blame:void 0}}},{name:"isInitialStateOriginState",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap;return Array.from(r.keys()).indexOf(b)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(r.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}}},{name:"eventsAreStrings",shouldThrow:!1,predicate:function(t,e){return{isFulfilled:t.events.every(function(t){return"string"==typeof t}),blame:{message:"Events must be an array of strings!",info:{events:t.events}}}}},{name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=n.map(function(t,e){return!Qt(t)&&!te(t)&&{transition:t,index:e}}).filter(Boolean),a=Object.keys(r).length;return{isFulfilled:0===a,blame:{message:"Found ".concat(a," transitions with invalid format! Check logs for more details."),info:{wrongTransitions:r,transitions:n}}}}},{name:"noDuplicatedStates",shouldThrow:!1,predicate:function(t,e){var n=nt.getLabel,r=rt({strategy:K,seed:{duplicatedStates:[],statesHashMap:{}},visit:function(t,e,r){var a=t.duplicatedStates,i=t.statesHashMap,o=n(r),s=Object.keys(o)[0];return s in i?{duplicatedStates:a.concat(s),statesHashMap:i}:{duplicatedStates:a,statesHashMap:(i[s]="",i)}}},t.states).duplicatedStates;return{isFulfilled:0===r.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:r}}}}},{name:"noReservedStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:-1===Object.keys(r).indexOf(b),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[b],statesType:r}}}}},{name:"atLeastOneState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:Object.keys(r).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:r}}}}},{name:"areEventsDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.eventTransitionsMaps,a=Object.keys(r),i=t.events,o=i.map(function(t){return-1===a.indexOf(t)&&t}).filter(Boolean),s=a.map(function(t){return-1===i.indexOf(t)&&t}).filter(Boolean).filter(function(t){return t!==T&&"undefined"!==t});return{isFulfilled:0===o.length&&0===s.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:o,eventsNotDeclaredButTriggeringTransitions:s}}}}},{name:"areStatesDeclared",shouldThrow:!1,predicate:function(t,n,r){var a=r.stateEventTransitionsMaps,i=r.targetStatesMap,o=r.statesType,s=Object.keys(a),c=Array.from(i.keys()).filter(function(t){return"object"!==e(t)}),u=Object.keys([s,c].reduce(function(t,e){return e.forEach(function(e){return t[e]=!0}),t},{})),f=Object.keys(o),l=f.map(function(t){return-1===u.indexOf(t)&&t}).filter(Boolean),d=u.map(function(t){return t!==b&&-1===f.indexOf(t)&&t}).filter(Boolean);return{isFulfilled:0===l.length&&0===d.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:l,statesNotDeclaredButTriggeringTransitions:d}}}}},{name:"validInitialConfig",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState;return r&&a?{isFulfilled:!1,blame:{message:"Invalid machine configuration : defining an initial control state and an initial transition at the same time may lead to ambiguity and is forbidden!",info:{initialControlState:a,initTransition:r}}}:r||a?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Invalid machine configuration : you must define EITHER an initial control state OR an initial transition! Else in which state is the machine supposed to start?",info:{initialControlState:a,initTransition:r}}}}},{name:"validInitialTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState,i=t.transitions.reduce(function(t,e){return e.from===b&&t.push(e),t},[]);return{isFulfilled:a&&!r||!a&&r&&1===i.length&&r.event===T&&(Qt(r)||te(r)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:r,initTransitions:i,initialControlState:a}}}}},{name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).filter(function(t){return!i[t]}).map(function(t){return a({},t,r[t]&&r[t][T])}).filter(function(t){return Object.values(t)[0]}));return{isFulfilled:0===o.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:o}}}}},{name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=n.statesPath,s=Object.keys(i).filter(function(t){return i[t]}),c=s.map(function(t){return r[t]&&r[t][T]}),u=c.every(Boolean);if(!u)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:s.map(function(t){return a({},t,!(!r[t]||!r[t][T]))})}}};var f=u&&c.every(function(t){var e=t.guards,n=t.to;return e?e.map(function(t){return t.to}).every(function(t){return"string"==typeof t}):"string"==typeof n});return f?f&&c.every(function(t){var e=t.from,n=t.guards,r=t.to;return n?n.map(function(t){return t.to}).every(function(t){return e!==t&&o[t]&&o[t].startsWith(o[e])}):e!==r&&o[r]&&o[r].startsWith(o[e])})?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have a target state which is strictly below the compound state in the state hierarchy! ",info:{states:t.states,statesPath:o,entryTransitions:c}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have the associated target control states which are not a history pseudo-state. Cf. log",info:{entryTransitions:c}}}}},{name:"validEventLessTransitions",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).map(function(t){return a({},t,r[t]&&"".concat(void 0)in r[t]&&1!==Object.keys(r[t]).length)}).filter(function(t){return void 0!==Object.values(t)[0]&&Object.values(t)[0]}));return{isFulfilled:0===o.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:o}}}}},{name:"isValidSelfTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap,a=n.statesType,i=Array.from(r.keys()).map(function(t){return r.get(t).map(function(e){var n=e.from,r=e.event;if(t in a&&!a[t]&&n&&n===t&&!r)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(function(t){return t.length>0});return{isFulfilled:0===i.length,blame:{message:"Found at least one eventless self-transition involving an atomic state! This is forbidden to avoid infinity loop! Cf. log",info:{wrongSelfTransitions:i}}}}},{name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=Object.keys(r).reduce(function(t,e){var n=Object.keys(r[e]).filter(function(t){return r[e][t].length>1});return n.length>0&&(t[e]=n),t},{});return{isFulfilled:0===Object.keys(a).length,blame:{message:"Found at least one control state and one event for which the associated transition are not condensated under a unique row! Cf. log",info:{statesTransitionsInfo:a}}}}},{name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:function(t,e,n){n.stateEventTransitionsMaps;var r=n.eventTransitionsMaps,i=n.ancestorMap,o=Object.keys(r).filter(function(t){return t!==T&&void 0!==t}).reduce(function(t,e){var n=Object.keys(r[e]),o=n.filter(function(t){return t!==b}).map(function(t){return i[t]&&a({},t,i[t].find(function(t){return n.indexOf(t)>-1}))}).filter(function(t){return t&&Object.values(t).filter(Boolean).length>0});return o.length>0&&(t[e]=o),t},{});return{isFulfilled:0===Object.keys(o).length,blame:{message:"Found two conflicting transitions! A -ev-> X, and B -ev-> Y leads to ambiguity if A < B or B < A. Cf. log",info:{eventTransitionsInfo:o}}}}},{name:"isHistoryStatesExisting",shouldThrow:!1,predicate:function(t,e,n){var r=n.historyStatesMap,a=n.statesType,i=Array.from(r.entries()).map(function(t){var e=d(t,2),n=e[0],r=e[1];return!(n in a)&&{historyState:n,flatTransitions:r}}).filter(Boolean),o=Object.keys(i).length;return{isFulfilled:0===o,blame:{message:"Found ".concat(o," history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition."),info:{invalidTransitions:i,states:t.states}}}}},{name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:function(t,e,n){!function(t){if(null==t)throw new TypeError("Cannot destructure undefined")}(n);var r=t.transitions.reduce(function(t,e){return Pt(e.from)?t.concat(e):t},[]);return{isFulfilled:0===Object.keys(r).length,blame:{message:"Found a history pseudo state configured as the origin control state for a transition. History pseudo states should only be target control states. Cf. log",info:{wrongHistoryStates:r}}}}},{name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.statesType,i=Object.keys(r).map(function(t){return t===b?[]:Object.keys(r[t]).reduce(function(e,n){var i=r[t][n][0],o=i.guards,s=i.to;return o?o.reduce(function(t,e){var n=e.to;return Pt(n)&&!a[Ht(n)]?t.concat(i):t},e):Pt(s)&&!a[Ht(s)]?e.concat(i):e},[])}).reduce(function(t,e){return t.concat(e)},[]);return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found a history pseudo state connected to an atomic state! History pseudo states only refer to compound states. Cf. log",info:{wrongHistoryStates:i,states:t.states}}}}}]};var ne=function(t,e,n){return function(t,e){var n=e&&e.debug&&e.debug.console||ot,r=e&&e.debug&&e.debug.trace||it,i=t.description;return function(){for(var e=arguments.length,o=new Array(e),s=0;s<e;s++)o[s]=arguments[s];var c=[],u=t.injected.apply(null,o),f={isFulfilled:t.contracts.reduce(function(t,e){var r=e.name,a=e.predicate,s=e.shouldThrow,f=o.concat(u),l=a.apply(null,f),d=l.isFulfilled,p=l.blame,h="".concat(i," FAILS ").concat(r,"!"),m=p||{},v=m.message,g=m.info;if(d)return t;if(c.push({name:r,message:v,info:g}),n.error(h),n.error([r,v].join(": ")),n.debug("Supporting error data:",g),s)throw new Error([h,"check console for information!"].join("\n"));return!1},!0),failingContracts:c};return r(a({},D,f)),f}}(n,e)(t,e)};function re(){return!0}function ae(t){var e=t.initialControlState,n=t.transitions,r=Vt(n);return e?n.concat([{from:b,event:T,to:e,action:w}]):r?n:void 0}function ie(t,n){var r=t.states,i=(t.events,t.initialExtendedState),o=t.updateState,s=n||{},c=s.debug,u=s.devTool,f=(s.displayName,c&&c.checkContracts||void 0),l=c&&c.console||ot,d=u&&u.tracer||st,p=function(t){throw new $t(t,l,d)};if(f){var h=ne(t,n,f).failingContracts;try{h.length>0&&p({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:n,failingContracts:h},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return d({type:U,trace:{info:t.errors,message:t.message,machineState:{cs:b,es:g,hs:A}}}),t}}var m=ae(t),v=function(t){var n="State",r={},a={};function i(){}return t={nok:t},i.prototype={current_state_name:b},r[b]=new i,r[E]=new i,function t(i,o){mt(i).forEach(function(s){var c=i[s];if(r[s]=new o,r[s].name=s,r[s].parent_name=dt(o),r[s].root_name=n,"object"===e(c)){a[s]=!0;var u=function(){};u.displayName=s,u.prototype=r[s],t(c,u)}})}(t,i),{hash_states:r,is_group_state:a}}(r),g=i,y=Ft(r),O=y.stateList,_=y.stateAncestors,A=Ut(O),C={},k={},M=v.is_group_state,R=v.hash_states;function I(){return R[b].current_state_name}function F(t,e){var n;n=Jt(qt,[t]),f&&n&&p(n);var r=zt(t),i=r.eventName,o=r.eventData,s=I();return l.debug("send event",t),e&&i===T&&s!==b?(d({type:H,trace:{info:{eventName:i,eventData:o},message:"The external event INIT_EVENT can only be sent when starting the machine!",machineState:{cs:s,es:g,hs:A}}}),l.warn("The external event INIT_EVENT can only be sent when starting the machine!"),null):function(t,e,n,r){var i=t[b].current_state_name,o=t[i][e];if(o){l.log("found event handler!"),l.info("WHEN EVENT ",e,n);var s=o(r,n,i),u=s.stop,f=s.outputs;c&&!u&&l.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var p=Dt(f),h=t[b].current_state_name;if(k[h]&&h!==i){var m=C[h]?T:S;d({type:G,trace:{info:{eventName:m,eventData:n},event:a({},m,n),machineState:{cs:I(),es:r,hs:A}}});var v=F(a({},m,n),!1);return d({type:V,trace:{outputs:v,machineState:{cs:I(),es:r,hs:A}}}),[].concat(p).concat(v)}return p}return l.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!")),d({type:H,trace:{info:{received:a({},e,n)},message:"There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!"),machineState:{cs:i,es:r,hs:A}}}),null}(v.hash_states,i,o,g)}m.forEach(function(t){var e=t.from,r=t.to,a=t.action,i=t.event,s=t.guards;s||(s=[{predicate:void 0,to:r,action:a}]),i===T&&(C[e]=!0);var u=R[e];i||(i=S,k[e]=!0),M[e]&&C[e]&&(k[e]=!0),u[i]=s.reduce(function(t,r,a){var s=r.action||w,u=s.name||s.displayName||"",f=function(t,n){var r=function(r,f,h){e=h||e;var m=t.predicate||re,v=m.name||m.displayName||"<anonymous>",y=t.to,T=function(n,r,o){try{return m(n,r,o)}catch(s){p({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:n,event:i,event_data:r,settings:o,guard:t,from:e,to:y,index:a},message:["Error occurred while processing event ".concat(i," with target state ").concat(y),s.message].join("\n"),stack:s.stack})}}(r,f,n);if("boolean"!=typeof T&&p({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:i,guard:t,from:e,to:y,index:a,shouldTransitionBeTaken:T},message:"Guard index ".concat(a," with name ").concat(v," did not return a boolean!")}),T){l.info("IN STATE ",e),t.predicate?(d({type:W,trace:{message:"The guard ".concat(v," is fulfilled"),info:{eventData:f,from:e,action:u,to:y},machineState:{cs:h,es:r,hs:A}}}),l.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(d({type:W,trace:{message:"Evaluating transition with no guards",info:{eventData:f,from:e,action:u,to:y},machineState:{cs:h,es:g,hs:A}}}),l.info("CASE: unguarded transition")),l.info("THEN : we execute the action "+u);var S=function(n,r,o){try{return s(n,r,o)}catch(r){p({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:n,event:i,event_data:f,settings:o,guard:t,from:e,to:y,index:a,action:s},message:r.message,stack:r.stack})}}(r,f,n);Xt(S)||p({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:g,event:i,event_data:f,settings:n,guard:t,from:e,to:y,index:a,action:s,actionResult:S},message:"Action factory returned a value that does not have the expected shape!"});var E=S.updates,O=S.outputs;!function(t,e,n){var r=n[t].name;A=Gt(A,_,r),l.info("left state",pt(t))}(e,0,R),g=function(t,e){var n=o.name||o.displayName||"";try{return o(t,e)}catch(r){p({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,E);var w=function(t,e,n){var r;if(Pt(t)){var a=t.deep?j:t.shallow?N:void 0,i=t[a];c&&l&&!C[i]&&l.error("Configured a history state which does not relate to a compound state! The behaviour of the machine is thus unspecified. Please review your machine configuration"),n[r=A[a][i]||i]}else t?r=n[t].name:p("enter_state : unknown case! Not a state name, and not a history state to enter!");return n[b].current_state_name=r,d({type:W,trace:{message:Pt(t)?"Entering history state for ".concat(t[t.deep?j:t.shallow?N:void 0]):"Entering state ".concat(t),machineState:{cs:I(),es:g,hs:A}}}),c&&l.info("AND TRANSITION TO STATE",r),r}(y,0,R);return l.info("ENTERING NEXT STATE: ",w),l.info("with extended state: ",g),{stop:!0,outputs:O}}return d({type:W,trace:{message:t.predicate?"The guard ".concat(v," is not fulfilled!"):"Evaluated and skipped transition",info:{eventData:f,settings:n,guard:t,from:e,to:y,index:a,action:u},machineState:{cs:h,es:g,hs:A}}}),{stop:!1,outputs:null}};return r.displayName=e+"",r}(r,n);return function(e,n,r){var a=t(e,n,r);return a.stop?a:f(e,n,r)}},function(){return{stop:!1,outputs:null}})});try{d({type:Y,trace:{info:{eventName:T,eventData:i},event:a({},T,i),machineState:{cs:I(),es:g,hs:A}}}),F(a({},T,i),!0)}catch(e){return d({type:U,trace:{message:e.message,info:{fsmDef:t,settings:n,error:e},machineState:{cs:b,es:g,hs:A}}}),e}return function(t){try{var e=zt(t),n=e.eventName,r=e.eventData,a=I();d({type:L,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:g,hs:A}}});var i=F(t,!0);return c&&l.info("OUTPUTS:",i),d({type:P,trace:{outputs:i,machineState:{cs:I(),es:g,hs:A}}}),i}catch(t){if(t instanceof $t)return d({type:B,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:I(),es:g,hs:A}}}),t;throw d({type:B,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:I(),es:g,hs:A}}}),l.error("yyield > unexpected error!",t),t}}}function oe(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(_t(t),'" as ').concat(t," <<NoContent>>")}t.fsmContracts=ee,t.normalizeTransitions=ae,t.create_state_machine=function(t,e){return ie(t,e)},t.createStateMachine=ie,t.makeWebComponentFromFsm=function(t){var e=t.name,a=t.eventHandler,s=t.fsm,c=t.commandHandlers,d=t.effectHandlers,p=t.options,h=function(t){function h(){var t;if(n(this,h),e.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";var r=f(t=l(this,o(h).call(this)));t.eventSubject=a,t.options=Object.assign({},p);var i=t.options.NO_ACTION||null;return t.eventSubject.subscribe({next:function(e){var n=s(e);n!==i&&n.forEach(function(e){if(e!==i){var n=e.command,a=e.params;c[n](t.eventSubject.next,a,d,r)}})}}),t}var m,v,g;return i(h,u(HTMLElement)),m=h,g=[{key:"observedAttributes",get:function(){return[]}}],(v=[{key:"connectedCallback",value:function(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}},{key:"disconnectedCallback",value:function(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}},{key:"attributeChangedCallback",value:function(t,e,n){this.constructor(),this.connectedCallback()}}])&&r(m.prototype,v),g&&r(m,g),h}();return customElements.define(e,h)},t.mergeOutputsFn=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},t.makeHistoryStates=function(t){var e=Object.keys(wt(t));return function(t,n){var r;if(!e.includes(n))throw"makeHistoryStates: the state for which a history state must be constructed is not a configured state for the state machine under implementation!!";return a(r={},t,n),a(r,"type",A),r}},t.historyState=function(t,e){return a({},t,e)},t.toPlantUml=function(t,e){var n=t.states,r=t.transitions,i=nt.getChildren,o=nt.getLabel,s=function(t){return t.join(h)},c=et(nt,{seed:function(){return Map},visit:function(t,e,n){var a=e.get(n).path,c=o(n),u=function(t,e,n){return["".concat(oe(t,"")," {"),e.join("\n"),function(t,e){var n=e.reduce(function(e,n){var r=Ot(n);return r.filter(vt).filter(bt(t)).reduce(function(t,e){return t[Et(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(oe(t,g))}).join("\n")}(t,n),function(t,e){return e.reduce(function(e,n){var r=Ot(n);return r.filter(gt).filter(yt(t)).reduce(function(t,e){e.from;var n=e.to,r=e.predicate,a=e.action;return t.push("[*] ".concat(m," ").concat(n," ").concat(v," ").concat(St("",r,a))),t},e)},[]).join("\n")}(t,n),"}",function(t,e){var n=function(t,e){return e.map(function(e){var n=Ot(e);return n.filter(yt(t)).filter(vt).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,m,Et({from:e,to:a}),v,St(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}(t,e),r=function(t,e){return t===b?"":e.map(function(e){var n=Ot(e);return n.filter(yt(t)).filter(function(t){return!gt(t)}).filter(function(t){return!vt(t)}).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,m,a,v,St(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}(t,e);return[n,r].filter(Boolean).join("\n")}(t,n)].filter(function(t){return"\n"!==t&&""!==t}).join("\n")}(Object.keys(c)[0],ht(function(e){return t.get(s(a.concat(e)))},function(t,e){return i(t,e).length}(n,e)),r);return t.set(s(a),u),t}},a({},b,n)),u=c.get("0");return c.clear(),u},t.toDagreVisualizerFormat=function(t){var e=t.states,n=t.transitions,r=nt.getLabel,i=nt.getChildren,o=at.constructTree,s=function(t){return t.join(h)},c=et(nt,{seed:function(){return Map},visit:function(t,e,n){var a=e.get(n).path,c=r(n),u=Object.keys(c)[0],f=ht(function(e){return t.get(s(a.concat(e)))},function(t,e){return i(t,e).length}(n,e));return t.set(s(a),o(u,f)),t}},a({},b,e)).get("0"),u=n.map(function(t){var e=t.from,n=t.to,r=t.event,a=t.guards,i=t.action;return a?{from:e,event:r,guards:a.map(function(t){var e=t.predicate,n=t.to,r=t.action;return{predicate:e.name,to:n,action:r.name}})}:{from:e,to:n,event:r,action:i.name||"no action name?"}});return JSON.stringify({states:c,transitions:u})},t.CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",t.SEP=h,t.TRANSITION_SYMBOL=m,t.TRANSITION_LABEL_START_SYMBOL=v,t.HISTORY_STATE_NAME=g,t.HISTORY_PREFIX=y,t.INIT_STATE=b,t.INIT_EVENT=T,t.AUTO_EVENT=S,t.STATE_PROTOTYPE_NAME=E,t.NO_STATE_UPDATE=O,t.NO_OUTPUT=_,t.ACTION_IDENTITY=w,t.history_symbol=A,t.SHALLOW=N,t.DEEP=j,t.WRONG_EVENT_FORMAT_ERROR=C,t.FUNCTION_THREW_ERROR=k,t.INVALID_ACTION_FACTORY_EXECUTED=M,t.INVALID_PREDICATE_EXECUTED=R,t.ACTION_FACTORY_DESC=I,t.ENTRY_ACTION_FACTORY_DESC=F,t.UPDATE_STATE_FN_DESC="update state function",t.PREDICATE_DESC=x,t.COMMAND_RENDER="render",t.CONTRACTS_EVAL=D,t.OUTPUTS_MSG=P,t.INPUT_MSG=L,t.WARN_MSG=H,t.MACHINE_CREATION_ERROR_MSG=U,t.ERROR_MSG=B,t.INTERNAL_INPUT_MSG=G,t.INTERNAL_OUTPUTS_MSG=V,t.DEBUG_MSG=W,t.INIT_INPUT_MSG=Y,t.noop=it,t.emptyConsole=ot,t.emptyTracer=st,t.isBoolean=function(t){return"boolean"==typeof t},t.isFunction=ct,t.isControlState=ut,t.isEvent=ft,t.isActionFactory=lt,t.make_states=function(t){return t.reduce(function(t,e){return t[e]="",t},{})},t.make_events=function(t){return t},t.get_fn_name=dt,t.wrap=pt,t.times=ht,t.always=function(t){return t},t.keys=mt,t.merge=function(t,e){return Object.assign({},t,e)},t.is_history_transition=vt,t.is_entry_transition=gt,t.is_from_control_state=yt,t.is_to_history_control_state_of=bt,t.is_history_control_state_of=Tt,t.format_transition_label=St,t.format_history_transition_state_name=Et,t.get_all_transitions=Ot,t.getDisplayName=_t,t.mergeModelUpdates=function(t){return function(e,n,r){return{updates:t.reduce(function(t,a){var i=a(e,n,r).updates;return i?t.concat(i):t},[]),outputs:_}}},t.chainModelUpdates=function(t){return function(e,n,r){var a=r.updateState;return{updates:t.reduce(function(t,e){var i=t.extendedState,o=t.updates,s=e(i,n,r).updates;return{extendedState:a(i,o),updates:s}},{extendedState:e,updates:[]}).updates||[],outputs:_}}},t.mergeActionFactories=function(t,e){return function(n,r,a){var i,o=e.map(function(t){return t(n,r,a)}),s=o.map(function(t){return t.updates||[]}),c=o.map(function(t){return t.outputs||{}});return{updates:(i=[]).concat.apply(i,p(s)),outputs:t(c)}}},t.identity=function(t,e,n){return{updates:[],outputs:_}},t.lastOf=function(t){return t[t.length-1]},t.getFsmStateList=wt,t.getStatesType=At,t.getStatesPath=Nt,t.getStatesTransitionsMap=jt,t.getStateEventTransitionsMaps=Ct,t.getEventTransitionsMaps=kt,t.getHistoryStatesMap=Mt,t.getTargetStatesMap=Rt,t.getAncestorMap=It,t.computeHistoryMaps=Ft,t.mapOverTransitionsActions=function(t,e){return xt(function(e,n,r,a){var i=n.from,o=n.event,s=n.to,c=n.action,u=n.predicate,f=t(c,n,r,a);return f.displayName=f.displayName||c&&(c.name||c.displayName||function(t,e,n,r,a){var i=a?a.name:"",o=i?"[".concat(i,"]"):"",s=t?t.name:"identity";return"".concat(s||"unnamed action",":").concat(e,"-").concat(n,"->").concat(r," ").concat(o)}(c,i,o,s,u)),void 0===u?e.push({from:i,event:o,to:s,action:f}):0===r?e.push({from:i,event:o,guards:[{to:s,predicate:u,action:f}]}):e[e.length-1].guards.push({to:s,predicate:u,action:f}),e},[],e)},t.reduceTransitions=xt,t.everyTransition=function(t,e){return xt(function(e,n){return e&&t(n)},!0,[e])},t.computeTimesCircledOn=function(t,e){return t.reduce(function(t,n){return n===e?t+1:t},0)},t.isInitState=function(t){return t===b},t.isInitEvent=function(t){return t===T},t.isEventless=function(t){return void 0===t},t.arrayizeOutput=Dt,t.isHistoryControlState=Pt,t.getHistoryParentState=function(t){return t[N]||t[j]},t.isShallowHistory=function(t){return t[N]},t.isDeepHistory=function(t){return t[j]},t.getHistoryType=Lt,t.getHistoryUnderlyingState=Ht,t.isHistoryStateEdge=function(t){return void 0!==t.history},t.initHistoryDataStructure=Ut,t.isCompoundState=Bt,t.isAtomicState=function(t,e){return!Bt(t,e)},t.updateHistory=Gt,t.computeHistoryState=function(t,e,n,r){var a=Ft(t),i=a.stateList,o=a.stateAncestors,s=Ut(i);return(s=e.reduce(function(t,e){return Gt(t,o,e)},s))[n][r]},t.findInitTransition=Vt,t.tryCatch=Wt,t.tryCatchMachineFn=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return Wt(e,function(r,a){var i=new Error(r),o=Yt(e),s=k(o,t);i.probableCause=r.probableCause?[r.probableCause,s].join("\n"):s;var c={fnName:o,params:n.reduce(function(t,e,n){return t[e]=a[n],t},{})};return i.info=r.info?[].concat([r.info]).concat([c]):c,i})},t.getFunctionName=Yt,t.assert=Jt,t.notifyThrows=Kt,t.handleFnExecError=function(t,e,n,r,a,i){var o=t.debug,s=t.console;return o&&n instanceof Error?(a({debug:o,console:s},n,e),!0):!(!o||r(n)||(i({debug:o,console:s},n,e),0))},t.notifyAndRethrow=function(t,e){throw t.debug,Kt(t.console,e),e},t.throwIfInvalidActionResult=function(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=Yt(a),u=new Error(M(c,I));throw u.info={fnName:Yt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Kt(r,u),u},t.throwIfInvalidGuardResult=function(t,e,n){t.debug;var r=t.console,a=Yt(n.predicate),i=new Error(R(a,x));throw i.info={predicateName:a,params:n,returned:e},Kt(r,i),i},t.throwIfInvalidEntryActionResult=function(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=Yt(a),u=new Error(M(c,F));throw u.info={fnName:Yt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Kt(r,u),u},t.isActions=Xt,t.isEventStruct=qt,t.isError=function(t){return t instanceof Error},t.destructureEvent=zt,t.formatUndefinedInJSON=function(t){return JSON.stringify(t,function(t,e){return void 0===e?"undefined":e})},t.KinglyError=$t,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Kingly={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t,e,n){return(c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var a=new(Function.bind.apply(t,r));return n&&s(a,n.prototype),a}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)})(t)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?f(t):e}function d(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,a=!1,i=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){a=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(a)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var h=".",m="--\x3e",v=":",g="H",y="history.",b="nok",T="init",S="auto",E="State",O=[],_=[],w=function(){return{outputs:_,updates:O}},A={},j="shallow",N="deep",C="The machine received an event which does not have the proper format. Expecting an object whose unique key is the event name, and value is the event data.",k=function(t,e){return"Exception thrown when executing ".concat(e," ").concat(t||"")},M=function(t,e){return"".concat(k(t,e),"\nThe ").concat(e," returned a value which is not an action.")},I=function(t,e){return"".concat(k(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},R="action factory",F="(decorating) entry action",x="predicate",D="CONTRACTS_EVAL",P="OUTPUTS_MSG",L="INPUT_MSG",H="WARN_MSG",U="MACHINE_CREATION_ERROR_MSG",B="ERROR_MSG",G="INTERNAL_INPUT_MSG",V="INTERNAL_OUTPUTS_MSG",W="DEBUG_MSG",Y="INIT_INPUT_MSG";const J=[0],K="PRE_ORDER";function X(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function q(t,e){return Object.assign({},t,e)}function z(t,e,n){n.forEach((n,r)=>{const a=t.get(e),i=t.get(n),o=i&&i.path;t.set(n,q(i,{isAdded:!0,isVisited:!1,path:o||a.path.concat(r)}))})}function $(t,e){t.set(e,q(t.get(e),{isVisited:!0}))}function Q(t,e){const{store:n,lenses:r,traverse:a}=t,{empty:i,add:o,takeAndRemoveOne:s,isEmpty:c}=n,{getChildren:u}=r,{visit:f,seed:l}=a,d=new Map,p="function"==typeof l?new(l()):X(l);let h="function"==typeof i?new(i()):X(i),m=p;for(o([e],h),d.set(e,{isAdded:!0,isVisited:!1,path:J});!c(h);){const t=s(h),e=u(d,t);o(e,h),z(d,t,e),m=f(m,d,t),$(d,t)}return d.clear(),m}function Z(t,e,n){const{getChildren:r}=t;return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function tt(t,e,n){const{getChildren:r}=t;return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>r(e)},traverse:e},n)}function et(t,e,n){const{getChildren:r}=t,{seed:a,visit:i}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===r(t,e).length)(t,e);return Q({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>o(e,t)?[]:r(e,t).concat([e])},traverse:{seed:a,visit:(t,e,n)=>o(n,e)?i(t,e,n):t}},n)}const nt={isLeafLabel:function(t){return 0===nt.getChildren(t).length},getLabel:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getLabel > unexpected object tree value";return t},getChildren:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getChildren > unexpected value";{let e=Object.values(t)[0];return e&&"object"==typeof e&&!Array.isArray(e)?Object.keys(e).map(t=>({[t]:e[t]})):[]}},constructTree:(t,e)=>{const n=t&&Object.keys(t)&&Object.keys(t)[0];return 0===e.length?t:{[n]:Object.assign.apply(null,e)}}};function rt(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:Z,PRE_ORDER:tt,POST_ORDER:et}[r]||tt)(nt,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(J)?t:i(t,e,n)}},n)}const at={getLabel:t=>Array.isArray(t)?t[0]:t,getChildren:t=>Array.isArray(t)?t[1]:[],constructTree:(t,e)=>e&&Array.isArray(e)&&e.length>0?[t,e]:t};var it=function(){},ot={log:it,warn:it,info:it,debug:it,error:it,trace:it},st=it;function ct(t){return"function"==typeof t}function ut(t){return t&&"string"==typeof t||Pt(t)}function ft(t){return void 0===t||"string"==typeof t}function lt(t){return t&&"function"==typeof t}function dt(t){return/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}\s*$/.exec(t.toString())[1]}function pt(t){return["-",t,"-"].join("")}function ht(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function mt(t){return Object.keys(t)}function vt(t){return t.to.startsWith(y)}function gt(t){return t.event===T}function yt(t){return function(e){return e.from===t}}function bt(t){return function(e){return Tt(t,e.to)}}function Tt(t,e){return e.substring(y.length)===t}function St(t,e,n){var r=t||"";return e&&n?"".concat(r," [").concat(e.name,"] / ").concat(n.name):e?"".concat(r," [").concat(e.name,"]}"):n?"".concat(r," / ").concat(n.name):"".concat(r)}function Et(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(y.length),".").concat(g)}function Ot(t){var e=t.from,n=t.event,r=t.guards;return r?r.map(function(t){var r=t.predicate,a=t.to,i=t.action;return{from:e,event:n,predicate:r,to:a,action:i}}):[t]}function _t(t){return t.replace(/_/g," ")}function wt(t){var e=nt.getLabel;return rt({strategy:K,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function At(t){var e=nt.getLabel,n=nt.isLeafLabel;return rt({strategy:K,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(i)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function jt(t){var e=nt.getLabel;return rt({strategy:K,seed:{},visit:function(t,n,r){var a=n.get(r).path.join("."),i=e(r);return t[Object.keys(i)[0]]=a,t}},t)}function Nt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function Ct(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function kt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Pt(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function Mt(t){return xt(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(Pt(a)){var o=Ht(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(Pt(i)){var s=Ht(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function It(t){return xt(function(t,e,n,r){var a=e.to;return t.set(a,(t.get(a)||[]).concat([e])),t},new Map,t)||{}}function Rt(t){var e=nt.getLabel,n=nt.getChildren;return rt({strategy:K,seed:{},visit:function(t,r,a){var i=e(a),o=Object.keys(i)[0];return n(a).map(function(t){return Object.keys(e(t))[0]}).forEach(function(e){t[e]=t[e]||[],t[e]=t[e].concat(o)}),t}},t)}function Ft(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var e=nt.getLabel,n=rt({strategy:K,seed:{stateList:[],stateAncestors:{}},visit:function(t,n,r){var a=e(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=n.get(r).path;n.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)n.set(JSON.stringify(s),b);else{var c=n.get(JSON.stringify(s));t.stateAncestors[i]=[c];var u=o.reduce(function(t,e){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=n.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[i]=u}return t}},t);return{stateList:n.stateList,stateAncestors:n.stateAncestors}}function xt(t,e,n){return n.reduce(function(e,n,r){var a=n.from,i=n.event,o=n.to,s=n.gen,c=n.action,u=n.guards;return u||(u=s?[{to:o,action:c,gen:s,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce(function(e,n,o){var s=n.to,c=n.action,u=n.gen,f=n.predicate;return t(e,u?{from:a,event:i,to:s,action:c,predicate:f,gen:u}:{from:a,event:i,to:s,action:c,predicate:f},o,r)},e)},e)}function Dt(t){return t===_?_:Array.isArray(t)?t:[t]}function Pt(t){return"object"===e(t)&&(N in t||j in t)}function Lt(t){return t[N]?N:j}function Ht(t){return t[Lt(t)]}function Ut(t){var e,n=function(){return t.reduce(function(t,e){return t[e]="",t},{})};return a(e={},N,n()),a(e,j,n()),e}function Bt(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function Gt(t,e,n){var r,i=(a(r={},N,Object.assign({},t[N])),a(r,j,Object.assign({},t[j])),r);return n===b?i:((e[n]||[]).reduce(function(t,e){return i[N][e]=n,i[j][e]=t,e},n),i)}function Vt(t){return t.find(function(t){return t.from===b&&t.event===T})}function Wt(t,e){return function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];try{return t.apply(t,r)}catch(t){return e(t,r)}}}function Yt(t){return t.name||t.displayName||"anonymous"}function Jt(t,e){var n=t.name||t.name.displayName||"",r=t.apply(null,e);return!0===r?void 0:function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){a(t,e,n[e])})}return t}({},r,{when:"Checking contract",message:[r.message,"failed contract ".concat(n)].join("\n"),info:r.info})}function Kt(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function Xt(t){return t&&"updates"in t&&"outputs"in t&&Array.isArray(t.outputs)}function qt(t){var n;return t&&"object"===e(t)?Object.keys(t).length>1?(n=new Error(C)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:n=!0:(n=new Error(C)).info={event:t,cause:"not an object!"},n}function zt(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}var $t=function(t){function e(t,r,a){var i;n(this,e),(i=l(this,o(e).call(this,t&&t.message||""))).name="KinglyError",i.stack=t&&t.stack||i.stack,i.errors=t;var s=t||{},c=s.when,u=s.location,f=s.info,d=s.message,p=["At ".concat(u,": ").concat(c," => ").concat(d),f?"See extra info in console":""].join("\n");return r&&r.error(p),f&&r&&r.info(f),i}return i(e,u(Error)),e}();function Qt(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&ut(e)&&ft(n)&&ut(a)&<(i)}function Zt(t){var e=t.to,n=t.predicate,r=t.action;return e&&ut(e)&&ct(n)&<(r)}function te(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&ut(e)&&ft(n)&&r.every(Zt)}var ee={injected:function(t,e){return{statesType:At(t.states),initTransition:Vt(t.transitions),statesTransitionsMap:Nt(t.transitions),stateEventTransitionsMaps:Ct(t.transitions),eventTransitionsMaps:kt(t.transitions),ancestorMap:Rt(t.states),statesPath:jt(t.states),historyStatesMap:Mt(t.transitions),targetStatesMap:It(t.transitions)}},description:"FSM structure",contracts:[{name:"isValidFsmDef",shouldThrow:!1,predicate:function(t,n){var r=t.transitions,a=t.states,i=t.events,o=(t.initialExtendedState,r&&Array.isArray(r)),s=a&&"object"===e(a),c=i&&Array.isArray(i);return o?s?c?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:i}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:a}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:r}}}}},{name:"isValidSettings",shouldThrow:!1,predicate:function(t){return{isFulfilled:!0,blame:void 0}}},{name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:function(t,e,n){n.initTransition;var r=n.statesType,a=t.initialControlState,i=(t.transitions,Object.keys(r));return a?{isFulfilled:i.indexOf(a)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:a,declaredStates:i}}}:{isFulfilled:!0,blame:void 0}}},{name:"isInitialStateOriginState",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap;return Array.from(r.keys()).indexOf(b)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(r.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}}},{name:"eventsAreStrings",shouldThrow:!1,predicate:function(t,e){return{isFulfilled:t.events.every(function(t){return"string"==typeof t}),blame:{message:"Events must be an array of strings!",info:{events:t.events}}}}},{name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:function(t,e){var n=t.transitions,r=n.map(function(t,e){return!Qt(t)&&!te(t)&&{transition:t,index:e}}).filter(Boolean),a=Object.keys(r).length;return{isFulfilled:0===a,blame:{message:"Found ".concat(a," transitions with invalid format! Check logs for more details."),info:{wrongTransitions:r,transitions:n}}}}},{name:"noDuplicatedStates",shouldThrow:!1,predicate:function(t,e){var n=nt.getLabel,r=rt({strategy:K,seed:{duplicatedStates:[],statesHashMap:{}},visit:function(t,e,r){var a=t.duplicatedStates,i=t.statesHashMap,o=n(r),s=Object.keys(o)[0];return s in i?{duplicatedStates:a.concat(s),statesHashMap:i}:{duplicatedStates:a,statesHashMap:(i[s]="",i)}}},t.states).duplicatedStates;return{isFulfilled:0===r.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:r}}}}},{name:"noReservedStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:-1===Object.keys(r).indexOf(b),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[b],statesType:r}}}}},{name:"atLeastOneState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesType;return{isFulfilled:Object.keys(r).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:r}}}}},{name:"areEventsDeclared",shouldThrow:!1,predicate:function(t,e,n){var r=n.eventTransitionsMaps,a=Object.keys(r),i=t.events,o=i.map(function(t){return-1===a.indexOf(t)&&t}).filter(Boolean),s=a.map(function(t){return-1===i.indexOf(t)&&t}).filter(Boolean).filter(function(t){return t!==T&&"undefined"!==t});return{isFulfilled:0===o.length&&0===s.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:o,eventsNotDeclaredButTriggeringTransitions:s}}}}},{name:"areStatesDeclared",shouldThrow:!1,predicate:function(t,n,r){var a=r.stateEventTransitionsMaps,i=r.targetStatesMap,o=r.statesType,s=Object.keys(a),c=Array.from(i.keys()).filter(function(t){return"object"!==e(t)}),u=Object.keys([s,c].reduce(function(t,e){return e.forEach(function(e){return t[e]=!0}),t},{})),f=Object.keys(o),l=f.map(function(t){return-1===u.indexOf(t)&&t}).filter(Boolean),d=u.map(function(t){return t!==b&&-1===f.indexOf(t)&&t}).filter(Boolean);return{isFulfilled:0===l.length&&0===d.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:l,statesNotDeclaredButTriggeringTransitions:d}}}}},{name:"validInitialConfig",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState;return r&&a?{isFulfilled:!1,blame:{message:"Invalid machine configuration : defining an initial control state and an initial transition at the same time may lead to ambiguity and is forbidden!",info:{initialControlState:a,initTransition:r}}}:r||a?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Invalid machine configuration : you must define EITHER an initial control state OR an initial transition! Else in which state is the machine supposed to start?",info:{initialControlState:a,initTransition:r}}}}},{name:"validInitialTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.initTransition,a=t.initialControlState,i=t.transitions.reduce(function(t,e){return e.from===b&&t.push(e),t},[]);return{isFulfilled:a&&!r||!a&&r&&1===i.length&&r.event===T&&(Qt(r)||te(r)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:r,initTransitions:i,initialControlState:a}}}}},{name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).filter(function(t){return!i[t]}).map(function(t){return a({},t,r[t]&&r[t][T])}).filter(function(t){return Object.values(t)[0]}));return{isFulfilled:0===o.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:o}}}}},{name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=n.statesPath,s=Object.keys(i).filter(function(t){return i[t]}),c=s.map(function(t){return r[t]&&r[t][T]}),u=c.every(Boolean);if(!u)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:s.map(function(t){return a({},t,!(!r[t]||!r[t][T]))})}}};var f=u&&c.every(function(t){var e=t.guards,n=t.to;return e?e.map(function(t){return t.to}).every(function(t){return"string"==typeof t}):"string"==typeof n});return f?f&&c.every(function(t){var e=t.from,n=t.guards,r=t.to;return n?n.map(function(t){return t.to}).every(function(t){return e!==t&&o[t]&&o[t].startsWith(o[e])}):e!==r&&o[r]&&o[r].startsWith(o[e])})?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have a target state which is strictly below the compound state in the state hierarchy! ",info:{states:t.states,statesPath:o,entryTransitions:c}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have the associated target control states which are not a history pseudo-state. Cf. log",info:{entryTransitions:c}}}}},{name:"validEventLessTransitions",shouldThrow:!1,predicate:function(t,e,n){var r=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).map(function(t){return a({},t,r[t]&&"".concat(void 0)in r[t]&&1!==Object.keys(r[t]).length)}).filter(function(t){return void 0!==Object.values(t)[0]&&Object.values(t)[0]}));return{isFulfilled:0===o.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:o}}}}},{name:"isValidSelfTransition",shouldThrow:!1,predicate:function(t,e,n){var r=n.targetStatesMap,a=n.statesType,i=Array.from(r.keys()).map(function(t){return r.get(t).map(function(e){var n=e.from,r=e.event;if(t in a&&!a[t]&&n&&n===t&&!r)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(function(t){return t.length>0});return{isFulfilled:0===i.length,blame:{message:"Found at least one eventless self-transition involving an atomic state! This is forbidden to avoid infinity loop! Cf. log",info:{wrongSelfTransitions:i}}}}},{name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=Object.keys(r).reduce(function(t,e){var n=Object.keys(r[e]).filter(function(t){return r[e][t].length>1});return n.length>0&&(t[e]=n),t},{});return{isFulfilled:0===Object.keys(a).length,blame:{message:"Found at least one control state and one event for which the associated transition are not condensated under a unique row! Cf. log",info:{statesTransitionsInfo:a}}}}},{name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:function(t,e,n){n.stateEventTransitionsMaps;var r=n.eventTransitionsMaps,i=n.ancestorMap,o=Object.keys(r).filter(function(t){return t!==T&&void 0!==t}).reduce(function(t,e){var n=Object.keys(r[e]),o=n.filter(function(t){return t!==b}).map(function(t){return i[t]&&a({},t,i[t].find(function(t){return n.indexOf(t)>-1}))}).filter(function(t){return t&&Object.values(t).filter(Boolean).length>0});return o.length>0&&(t[e]=o),t},{});return{isFulfilled:0===Object.keys(o).length,blame:{message:"Found two conflicting transitions! A -ev-> X, and B -ev-> Y leads to ambiguity if A < B or B < A. Cf. log",info:{eventTransitionsInfo:o}}}}},{name:"isHistoryStatesExisting",shouldThrow:!1,predicate:function(t,e,n){var r=n.historyStatesMap,a=n.statesType,i=Array.from(r.entries()).map(function(t){var e=d(t,2),n=e[0],r=e[1];return!(n in a)&&{historyState:n,flatTransitions:r}}).filter(Boolean),o=Object.keys(i).length;return{isFulfilled:0===o,blame:{message:"Found ".concat(o," history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition."),info:{invalidTransitions:i,states:t.states}}}}},{name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:function(t,e,n){!function(t){if(null==t)throw new TypeError("Cannot destructure undefined")}(n);var r=t.transitions.reduce(function(t,e){return Pt(e.from)?t.concat(e):t},[]);return{isFulfilled:0===Object.keys(r).length,blame:{message:"Found a history pseudo state configured as the origin control state for a transition. History pseudo states should only be target control states. Cf. log",info:{wrongHistoryStates:r}}}}},{name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:function(t,e,n){var r=n.stateEventTransitionsMaps,a=n.statesType,i=Object.keys(r).map(function(t){return t===b?[]:Object.keys(r[t]).reduce(function(e,n){var i=r[t][n][0],o=i.guards,s=i.to;return o?o.reduce(function(t,e){var n=e.to;return Pt(n)&&!a[Ht(n)]?t.concat(i):t},e):Pt(s)&&!a[Ht(s)]?e.concat(i):e},[])}).reduce(function(t,e){return t.concat(e)},[]);return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found a history pseudo state connected to an atomic state! History pseudo states only refer to compound states. Cf. log",info:{wrongHistoryStates:i,states:t.states}}}}}]};var ne=function(t,e,n){return function(t,e){var n=e&&e.debug&&e.debug.console||ot,r=e&&e.debug&&e.debug.trace||it,i=t.description;return function(){for(var e=arguments.length,o=new Array(e),s=0;s<e;s++)o[s]=arguments[s];var c=[],u=t.injected.apply(null,o),f={isFulfilled:t.contracts.reduce(function(t,e){var r=e.name,a=e.predicate,s=e.shouldThrow,f=o.concat(u),l=a.apply(null,f),d=l.isFulfilled,p=l.blame,h="".concat(i," FAILS ").concat(r,"!"),m=p||{},v=m.message,g=m.info;if(d)return t;if(c.push({name:r,message:v,info:g}),n.error(h),n.error([r,v].join(": ")),n.debug("Supporting error data:",g),s)throw new Error([h,"check console for information!"].join("\n"));return!1},!0),failingContracts:c};return r(a({},D,f)),f}}(n,e)(t,e)};function re(){return!0}function ae(t){var e=t.initialControlState,n=t.transitions,r=Vt(n);return e?n.concat([{from:b,event:T,to:e,action:w}]):r?n:void 0}function ie(t,n){var r=t.states,i=(t.events,t.initialExtendedState),o=t.updateState,s=n||{},c=s.debug,u=s.devTool,f=(s.displayName,c&&c.checkContracts||void 0),l=c&&c.console||ot,d=u&&u.tracer||st,p=function(t){throw new $t(t,l,d)};if(f){var h=ne(t,n,f).failingContracts;try{h.length>0&&p({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:n,failingContracts:h},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return d({type:U,trace:{info:t.errors,message:t.message,machineState:{cs:void 0,es:i,hs:void 0}}}),t}}var m=ae(t),v=function(t){var n="State",r={},a={};function i(){}return t={nok:t},i.prototype={current_state_name:b},r[b]=new i,r[E]=new i,function t(i,o){mt(i).forEach(function(s){var c=i[s];if(r[s]=new o,r[s].name=s,r[s].parent_name=dt(o),r[s].root_name=n,"object"===e(c)){a[s]=!0;var u=function(){};u.displayName=s,u.prototype=r[s],t(c,u)}})}(t,i),{hash_states:r,is_group_state:a}}(r),g=i,y=Ft(r),O=y.stateList,_=y.stateAncestors,A=Ut(O),C={},k={},M=v.is_group_state,I=v.hash_states;function R(){return I[b].current_state_name}function F(t,e){var n;n=Jt(qt,[t]),f&&n&&p(n);var r=zt(t),i=r.eventName,o=r.eventData,s=R();return l.debug("send event",t),e&&i===T&&s!==b?(d({type:H,trace:{info:{eventName:i,eventData:o},message:"The external event INIT_EVENT can only be sent when starting the machine!",machineState:{cs:s,es:g,hs:A}}}),l.warn("The external event INIT_EVENT can only be sent when starting the machine!"),null):function(t,e,n,r){var i=t[b].current_state_name,o=t[i][e];if(o){l.log("found event handler!"),l.info("WHEN EVENT ",e,n);var s=o(r,n,i),u=s.stop,f=s.outputs;c&&!u&&l.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var p=Dt(f),h=t[b].current_state_name;if(k[h]&&h!==i){var m=C[h]?T:S;d({type:G,trace:{info:{eventName:m,eventData:n},event:a({},m,n),machineState:{cs:R(),es:r,hs:A}}});var v=F(a({},m,n),!1);return d({type:V,trace:{outputs:v,machineState:{cs:R(),es:r,hs:A}}}),[].concat(p).concat(v)}return p}return l.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!")),d({type:H,trace:{info:{received:a({},e,n)},message:"There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!"),machineState:{cs:i,es:r,hs:A}}}),null}(v.hash_states,i,o,g)}function x(){return d({type:Y,trace:{info:{eventName:T,eventData:i},event:a({},T,i),machineState:{cs:R(),es:g,hs:A}}}),F(a({},T,i),!0)}m.forEach(function(t){var e=t.from,r=t.to,a=t.action,i=t.event,s=t.guards;s||(s=[{predicate:void 0,to:r,action:a}]),i===T&&(C[e]=!0);var u=I[e];i||(i=S,k[e]=!0),M[e]&&C[e]&&(k[e]=!0),u[i]=s.reduce(function(t,r,a){var s=r.action||w,u=s.name||s.displayName||"",f=function(t,n){var r=function(r,f,h){e=h||e;var m=t.predicate||re,v=m.name||m.displayName||"<anonymous>",y=t.to,T=function(n,r,o){try{return m(n,r,o)}catch(s){p({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:n,event:i,event_data:r,settings:o,guard:t,from:e,to:y,index:a},message:["Error occurred while processing event ".concat(i," with target state ").concat(y),s.message].join("\n"),stack:s.stack})}}(r,f,n);if("boolean"!=typeof T&&p({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:i,guard:t,from:e,to:y,index:a,shouldTransitionBeTaken:T},message:"Guard index ".concat(a," with name ").concat(v," did not return a boolean!")}),T){l.info("IN STATE ",e),t.predicate?(d({type:W,trace:{message:"The guard ".concat(v," is fulfilled"),info:{eventData:f,from:e,action:u,to:y},machineState:{cs:h,es:r,hs:A}}}),l.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(d({type:W,trace:{message:"Evaluating transition with no guards",info:{eventData:f,from:e,action:u,to:y},machineState:{cs:h,es:g,hs:A}}}),l.info("CASE: unguarded transition")),l.info("THEN : we execute the action "+u);var S=function(n,r,o){try{return s(n,r,o)}catch(r){p({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:n,event:i,event_data:f,settings:o,guard:t,from:e,to:y,index:a,action:s},message:r.message,stack:r.stack})}}(r,f,n);Xt(S)||p({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:g,event:i,event_data:f,settings:n,guard:t,from:e,to:y,index:a,action:s,actionResult:S},message:"Action factory returned a value that does not have the expected shape!"});var E=S.updates,O=S.outputs;!function(t,e,n){var r=n[t].name;A=Gt(A,_,r),l.info("left state",pt(t))}(e,0,I),g=function(t,e){var n=o.name||o.displayName||"";try{return o(t,e)}catch(r){p({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,E);var w=function(t,e,n){var r;if(Pt(t)){var a=t.deep?N:t.shallow?j:void 0,i=t[a];c&&l&&!C[i]&&l.error("Configured a history state which does not relate to a compound state! The behaviour of the machine is thus unspecified. Please review your machine configuration"),n[r=A[a][i]||i]}else t?r=n[t].name:p("enter_state : unknown case! Not a state name, and not a history state to enter!");return n[b].current_state_name=r,d({type:W,trace:{message:Pt(t)?"Entering history state for ".concat(t[t.deep?N:t.shallow?j:void 0]):"Entering state ".concat(t),machineState:{cs:R(),es:g,hs:A}}}),c&&l.info("AND TRANSITION TO STATE",r),r}(y,0,I);return l.info("ENTERING NEXT STATE: ",w),l.info("with extended state: ",g),{stop:!0,outputs:O}}return d({type:W,trace:{message:t.predicate?"The guard ".concat(v," is not fulfilled!"):"Evaluated and skipped transition",info:{eventData:f,settings:n,guard:t,from:e,to:y,index:a,action:u},machineState:{cs:h,es:g,hs:A}}}),{stop:!1,outputs:null}};return r.displayName=e+"",r}(r,n);return function(e,n,r){var a=t(e,n,r);return a.stop?a:f(e,n,r)}},function(){return{stop:!1,outputs:null}})});try{x()}catch(e){return d({type:U,trace:{message:e.message,info:{fsmDef:t,settings:n,error:e},machineState:{cs:b,es:g,hs:A}}}),e}var D={withProtectedState:function(t){try{var e=zt(t),n=e.eventName,r=e.eventData,a=R();d({type:L,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:g,hs:A}}});var i=F(t,!0);return c&&l.info("OUTPUTS:",i),d({type:P,trace:{outputs:i,machineState:{cs:R(),es:g,hs:A}}}),i}catch(t){if(t instanceof $t)return d({type:B,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:R(),es:g,hs:A}}}),t;throw d({type:B,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:R(),es:g,hs:A}}}),l.error("yyield > unexpected error!",t),t}},withPureInterface:function(t,e){if(void 0===e);else if(null==e)g=i,A=Ut(O),I[b].current_state_name=b,x();else{var n=e.cs,r=e.hs,a=e.es;g=a,A=r,I[b].current_state_name=n}return{outputs:D.withProtectedState(t),fsmState:{cs:R(),hs:A,es:g}}}};return D}function oe(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(_t(t),'" as ').concat(t," <<NoContent>>")}t.fsmContracts=ee,t.normalizeTransitions=ae,t.createStateMachine=function(t,e){var n=ie(t,e);return n instanceof Error?n:n.withProtectedState},t.createPureStateMachine=function(t,e){var n=ie(t,e);return n instanceof Error?n:n.withPureInterface},t.createStateMachineAPIs=ie,t.makeWebComponentFromFsm=function(t){var e=t.name,a=t.eventHandler,s=t.fsm,c=t.commandHandlers,d=t.effectHandlers,p=t.options,h=function(t){function h(){var t;if(n(this,h),e.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";var r=f(t=l(this,o(h).call(this)));t.eventSubject=a,t.options=Object.assign({},p);var i=t.options.NO_ACTION||null;return t.eventSubject.subscribe({next:function(e){var n=s(e);n!==i&&n.forEach(function(e){if(e!==i){var n=e.command,a=e.params;c[n](t.eventSubject.next,a,d,r)}})}}),t}var m,v,g;return i(h,u(HTMLElement)),m=h,g=[{key:"observedAttributes",get:function(){return[]}}],(v=[{key:"connectedCallback",value:function(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}},{key:"disconnectedCallback",value:function(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}},{key:"attributeChangedCallback",value:function(t,e,n){this.constructor(),this.connectedCallback()}}])&&r(m.prototype,v),g&&r(m,g),h}();return customElements.define(e,h)},t.mergeOutputsFn=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},t.makeHistoryStates=function(t){var e=Object.keys(wt(t));return function(t,n){var r;if(!e.includes(n))throw"makeHistoryStates: the state for which a history state must be constructed is not a configured state for the state machine under implementation!!";return a(r={},t,n),a(r,"type",A),r}},t.historyState=function(t,e){return a({},t,e)},t.toPlantUml=function(t,e){var n=t.states,r=t.transitions,i=nt.getChildren,o=nt.getLabel,s=function(t){return t.join(h)},c=et(nt,{seed:function(){return Map},visit:function(t,e,n){var a=e.get(n).path,c=o(n),u=function(t,e,n){return["".concat(oe(t,"")," {"),e.join("\n"),function(t,e){var n=e.reduce(function(e,n){var r=Ot(n);return r.filter(vt).filter(bt(t)).reduce(function(t,e){return t[Et(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(oe(t,g))}).join("\n")}(t,n),function(t,e){return e.reduce(function(e,n){var r=Ot(n);return r.filter(gt).filter(yt(t)).reduce(function(t,e){e.from;var n=e.to,r=e.predicate,a=e.action;return t.push("[*] ".concat(m," ").concat(n," ").concat(v," ").concat(St("",r,a))),t},e)},[]).join("\n")}(t,n),"}",function(t,e){var n=function(t,e){return e.map(function(e){var n=Ot(e);return n.filter(yt(t)).filter(vt).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,m,Et({from:e,to:a}),v,St(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}(t,e),r=function(t,e){return t===b?"":e.map(function(e){var n=Ot(e);return n.filter(yt(t)).filter(function(t){return!gt(t)}).filter(function(t){return!vt(t)}).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,m,a,v,St(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}(t,e);return[n,r].filter(Boolean).join("\n")}(t,n)].filter(function(t){return"\n"!==t&&""!==t}).join("\n")}(Object.keys(c)[0],ht(function(e){return t.get(s(a.concat(e)))},function(t,e){return i(t,e).length}(n,e)),r);return t.set(s(a),u),t}},a({},b,n)),u=c.get("0");return c.clear(),u},t.toDagreVisualizerFormat=function(t){var e=t.states,n=t.transitions,r=nt.getLabel,i=nt.getChildren,o=at.constructTree,s=function(t){return t.join(h)},c=et(nt,{seed:function(){return Map},visit:function(t,e,n){var a=e.get(n).path,c=r(n),u=Object.keys(c)[0],f=ht(function(e){return t.get(s(a.concat(e)))},function(t,e){return i(t,e).length}(n,e));return t.set(s(a),o(u,f)),t}},a({},b,e)).get("0"),u=n.map(function(t){var e=t.from,n=t.to,r=t.event,a=t.guards,i=t.action;return a?{from:e,event:r,guards:a.map(function(t){var e=t.predicate,n=t.to,r=t.action;return{predicate:e.name,to:n,action:r.name}})}:{from:e,to:n,event:r,action:i.name||"no action name?"}});return JSON.stringify({states:c,transitions:u})},t.CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",t.SEP=h,t.TRANSITION_SYMBOL=m,t.TRANSITION_LABEL_START_SYMBOL=v,t.HISTORY_STATE_NAME=g,t.HISTORY_PREFIX=y,t.INIT_STATE=b,t.INIT_EVENT=T,t.AUTO_EVENT=S,t.STATE_PROTOTYPE_NAME=E,t.NO_STATE_UPDATE=O,t.NO_OUTPUT=_,t.ACTION_IDENTITY=w,t.history_symbol=A,t.SHALLOW=j,t.DEEP=N,t.WRONG_EVENT_FORMAT_ERROR=C,t.FUNCTION_THREW_ERROR=k,t.INVALID_ACTION_FACTORY_EXECUTED=M,t.INVALID_PREDICATE_EXECUTED=I,t.ACTION_FACTORY_DESC=R,t.ENTRY_ACTION_FACTORY_DESC=F,t.UPDATE_STATE_FN_DESC="update state function",t.PREDICATE_DESC=x,t.COMMAND_RENDER="render",t.CONTRACTS_EVAL=D,t.OUTPUTS_MSG=P,t.INPUT_MSG=L,t.WARN_MSG=H,t.MACHINE_CREATION_ERROR_MSG=U,t.ERROR_MSG=B,t.INTERNAL_INPUT_MSG=G,t.INTERNAL_OUTPUTS_MSG=V,t.DEBUG_MSG=W,t.INIT_INPUT_MSG=Y,t.noop=it,t.emptyConsole=ot,t.emptyTracer=st,t.isBoolean=function(t){return"boolean"==typeof t},t.isFunction=ct,t.isControlState=ut,t.isEvent=ft,t.isActionFactory=lt,t.make_states=function(t){return t.reduce(function(t,e){return t[e]="",t},{})},t.make_events=function(t){return t},t.get_fn_name=dt,t.wrap=pt,t.times=ht,t.always=function(t){return t},t.keys=mt,t.merge=function(t,e){return Object.assign({},t,e)},t.is_history_transition=vt,t.is_entry_transition=gt,t.is_from_control_state=yt,t.is_to_history_control_state_of=bt,t.is_history_control_state_of=Tt,t.format_transition_label=St,t.format_history_transition_state_name=Et,t.get_all_transitions=Ot,t.getDisplayName=_t,t.mergeModelUpdates=function(t){return function(e,n,r){return{updates:t.reduce(function(t,a){var i=a(e,n,r).updates;return i?t.concat(i):t},[]),outputs:_}}},t.chainModelUpdates=function(t){return function(e,n,r){var a=r.updateState;return{updates:t.reduce(function(t,e){var i=t.extendedState,o=t.updates,s=e(i,n,r).updates;return{extendedState:a(i,o),updates:s}},{extendedState:e,updates:[]}).updates||[],outputs:_}}},t.mergeActionFactories=function(t,e){return function(n,r,a){var i,o=e.map(function(t){return t(n,r,a)}),s=o.map(function(t){return t.updates||[]}),c=o.map(function(t){return t.outputs||{}});return{updates:(i=[]).concat.apply(i,p(s)),outputs:t(c)}}},t.identity=function(t,e,n){return{updates:[],outputs:_}},t.lastOf=function(t){return t[t.length-1]},t.getFsmStateList=wt,t.getStatesType=At,t.getStatesPath=jt,t.getStatesTransitionsMap=Nt,t.getStateEventTransitionsMaps=Ct,t.getEventTransitionsMaps=kt,t.getHistoryStatesMap=Mt,t.getTargetStatesMap=It,t.getAncestorMap=Rt,t.computeHistoryMaps=Ft,t.mapOverTransitionsActions=function(t,e){return xt(function(e,n,r,a){var i=n.from,o=n.event,s=n.to,c=n.action,u=n.predicate,f=t(c,n,r,a);return f.displayName=f.displayName||c&&(c.name||c.displayName||function(t,e,n,r,a){var i=a?a.name:"",o=i?"[".concat(i,"]"):"",s=t?t.name:"identity";return"".concat(s||"unnamed action",":").concat(e,"-").concat(n,"->").concat(r," ").concat(o)}(c,i,o,s,u)),void 0===u?e.push({from:i,event:o,to:s,action:f}):0===r?e.push({from:i,event:o,guards:[{to:s,predicate:u,action:f}]}):e[e.length-1].guards.push({to:s,predicate:u,action:f}),e},[],e)},t.reduceTransitions=xt,t.everyTransition=function(t,e){return xt(function(e,n){return e&&t(n)},!0,[e])},t.computeTimesCircledOn=function(t,e){return t.reduce(function(t,n){return n===e?t+1:t},0)},t.isInitState=function(t){return t===b},t.isInitEvent=function(t){return t===T},t.isEventless=function(t){return void 0===t},t.arrayizeOutput=Dt,t.isHistoryControlState=Pt,t.getHistoryParentState=function(t){return t[j]||t[N]},t.isShallowHistory=function(t){return t[j]},t.isDeepHistory=function(t){return t[N]},t.getHistoryType=Lt,t.getHistoryUnderlyingState=Ht,t.isHistoryStateEdge=function(t){return void 0!==t.history},t.initHistoryDataStructure=Ut,t.isCompoundState=Bt,t.isAtomicState=function(t,e){return!Bt(t,e)},t.updateHistory=Gt,t.computeHistoryState=function(t,e,n,r){var a=Ft(t),i=a.stateList,o=a.stateAncestors,s=Ut(i);return(s=e.reduce(function(t,e){return Gt(t,o,e)},s))[n][r]},t.findInitTransition=Vt,t.tryCatch=Wt,t.tryCatchMachineFn=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return Wt(e,function(r,a){var i=new Error(r),o=Yt(e),s=k(o,t);i.probableCause=r.probableCause?[r.probableCause,s].join("\n"):s;var c={fnName:o,params:n.reduce(function(t,e,n){return t[e]=a[n],t},{})};return i.info=r.info?[].concat([r.info]).concat([c]):c,i})},t.getFunctionName=Yt,t.assert=Jt,t.notifyThrows=Kt,t.handleFnExecError=function(t,e,n,r,a,i){var o=t.debug,s=t.console;return o&&n instanceof Error?(a({debug:o,console:s},n,e),!0):!(!o||r(n)||(i({debug:o,console:s},n,e),0))},t.notifyAndRethrow=function(t,e){throw t.debug,Kt(t.console,e),e},t.throwIfInvalidActionResult=function(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=Yt(a),u=new Error(M(c,R));throw u.info={fnName:Yt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Kt(r,u),u},t.throwIfInvalidGuardResult=function(t,e,n){t.debug;var r=t.console,a=Yt(n.predicate),i=new Error(I(a,x));throw i.info={predicateName:a,params:n,returned:e},Kt(r,i),i},t.throwIfInvalidEntryActionResult=function(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=Yt(a),u=new Error(M(c,F));throw u.info={fnName:Yt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Kt(r,u),u},t.isActions=Xt,t.isEventStruct=qt,t.isError=function(t){return t instanceof Error},t.destructureEvent=zt,t.formatUndefinedInJSON=function(t){return JSON.stringify(t,function(t,e){return void 0===e?"undefined":e})},t.KinglyError=$t,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=kingly.umd.min.js.map |
{ | ||
"name": "kingly", | ||
"sideEffects": false, | ||
"version": "0.28.3", | ||
"description": "Extended Hierarchical State Transducer library", | ||
"version": "0.28.4", | ||
"description": "State machine library (Extended Hierarchical State Transducer)", | ||
"repository": { | ||
@@ -47,4 +47,2 @@ "type": "git", | ||
"devDependencies": { | ||
"courtesan":"latest", | ||
"kuker-emitters": "^6.7.4", | ||
"@babel/cli": "^7.4.4", | ||
@@ -56,2 +54,3 @@ "@babel/core": "^7.4.5", | ||
"browser-sync": "^2.18.8", | ||
"courtesan": "^0.4.0", | ||
"enzyme": "^3.7.0", | ||
@@ -64,3 +63,5 @@ "enzyme-adapter-react-16": "^1.7.0", | ||
"json-patch-es6": "^2.0.6", | ||
"kuker-emitters": "^6.7.4", | ||
"nodemon": "^1.9.2", | ||
"parcel": "^1.12.4", | ||
"parcel-bundler": "^1.10.3", | ||
@@ -67,0 +68,0 @@ "qunitjs": "^1.20.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1277654
6938
36