Comparing version 0.26.0 to 0.26.3
@@ -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&&(t.outputs===NO_OUTPUT||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||{},y=m.message,_=m.info;if(d)return t;if(s.push({name:r,message:y,info:_}),n.error(p),n.error([r,y].join(": ")),n.debug("Supporting error data:",_),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_event_enum(t){var e=t.reduce?t.slice():Array.prototype.slice.call(arguments);return e.push(INIT_EVENT),e.reduce(function(t,e){return t[e]=e,t},{})}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 build_state_enum(t){var e={history:{}};return e.NOK=INIT_STATE,function t(n){keys(n).forEach(function(r){var a=n[r];e[r]=r,"object"===_typeof(a)&&t(a)})}(t),e}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 normalizeFsmDef(t){return Object.assign({},t,{transitions:normalizeTransitions(t)})}function create_state_machine(t,e){return createStateMachine(t,e)}function createStateMachine(t,e){var n=t.states,r=t.events,a=t.initialExtendedState,i=t.updateState,o=e||{},s=o.debug,c=o.devTool,u=(o.displayName,s&&s.checkContracts||void 0),l=s&&s.console||emptyConsole,f=c&&c.tracer||emptyTracer,d=function(t){throw new KinglyError(t,l,f)};if(u){var T=fsmContractChecker(t,e,u).failingContracts;try{T.length>0&&d({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:e,failingContracts:T},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return f({type:MACHINE_CREATION_ERROR_MSG,trace:{info:t.errors,message:t.message,machineState:{cs:INIT_STATE,es:y,hs:g}}}),t}}build_event_enum(r);var p=normalizeTransitions(t),m=build_nested_state_structure(n),y=a,_=computeHistoryMaps(n),h=_.stateList,v=_.stateAncestors,g=initHistoryDataStructure(h),S={},E={},O=m.is_group_state,N=m.hash_states;function b(){return N[INIT_STATE].current_state_name}function A(t,e){var n;n=assert(isEventStruct,[t]),u&&n&&d(n);var r=destructureEvent(t),a=r.eventName,i=r.eventData,o=b();return l.debug("send event",t),e&&a===INIT_EVENT&&o!==INIT_STATE?(f({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:o,es:y,hs:g}}}),l.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){l.log("found event handler!"),l.info("WHEN EVENT ",e,n);var o=i(r,n,a),c=o.stop,u=o.outputs;s&&!c&&l.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var d=arrayizeOutput(u),T=t[INIT_STATE].current_state_name;if(E[T]&&T!==a){var p=S[T]?INIT_EVENT:AUTO_EVENT;f({type:INTERNAL_INPUT_MSG,trace:{info:{eventName:p,eventData:n},event:_defineProperty({},p,n),machineState:{cs:b(),es:r,hs:g}}});var m=A(_defineProperty({},p,n),!1);return f({type:INTERNAL_OUTPUTS_MSG,trace:{outputs:m,machineState:{cs:b(),es:r,hs:g}}}),[].concat(d).concat(m)}return d}return l.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!")),null}(m.hash_states,a,i,y)}p.forEach(function(t){var n=t.from,r=t.to,a=t.action,o=t.event,c=t.guards;c||(c=[{predicate:void 0,to:r,action:a}]),o===INIT_EVENT&&(S[n]=!0);var u=N[n];o||(o=AUTO_EVENT,E[n]=!0),O[n]&&S[n]&&(E[n]=!0),u[o]=c.reduce(function(t,r,a){var c=r.action||ACTION_IDENTITY,u=c.name||c.displayName||"",T=function(t,e){var r=function(r,T,p){n=p||n;var m=t.predicate||alwaysTrue,_=m.name||m.displayName||"<anonymous>",h=t.to,E=function(e,r,i){try{return m(e,r,i)}catch(s){d({when:"Executing predicate function ".concat(_),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:e,event:o,event_data:r,settings:i,guard:t,from:n,to:h,index:a},message:["Error occurred while processing event ".concat(o," with target state ").concat(h),s.message].join("\n"),stack:s.stack})}}(r,T,e);if("boolean"!=typeof E&&d({when:"Executing predicate function ".concat(_),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:o,guard:t,from:n,to:h,index:a,shouldTransitionBeTaken:E},message:"Guard index ".concat(a," with name ").concat(_," did not return a boolean!")}),E){l.info("IN STATE ",n),t.predicate?(f({type:DEBUG_MSG,trace:{message:"The guard ".concat(_," is fulfilled"),info:{eventData:T,from:n,action:u,to:h},machineState:{cs:p,es:r,hs:g}}}),l.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(f({type:DEBUG_MSG,trace:{message:"Evaluating transition with no guards",info:{eventData:T,from:n,action:u,to:h},machineState:{cs:p,es:y,hs:g}}}),l.info("CASE: unguarded transition")),l.info("THEN : we execute the action "+u);var O=function(e,r,i){try{return c(e,r,i)}catch(r){d({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:e,event:o,event_data:T,settings:i,guard:t,from:n,to:h,index:a,action:c},message:r.message,stack:r.stack})}}(r,T,e);isActions(O)||d({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:y,event:o,event_data:T,settings:e,guard:t,from:n,to:h,index:a,action:c,actionResult:O},message:"Action factory returned a value that does not have the expected shape!"});var A=O.updates,I=O.outputs;!function(t,e,n){var r=n[t].name;g=updateHistory(g,v,r),l.info("left state",wrap(t))}(n,0,N),y=function(t,e){var n=i.name||i.displayName||"";try{return i(t,e)}catch(r){d({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,A);var C=function(t,e,n){var r;if(isHistoryControlState(t)){var a=t.deep?DEEP:t.shallow?SHALLOW:void 0,i=t[a];s&&l&&!S[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=g[a][i]||i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t].name}return n[INIT_STATE].current_state_name=r,f({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:b(),es:y,hs:g}}}),s&&l.info("AND TRANSITION TO STATE",r),r}(h,0,N);return l.info("ENTERING NEXT STATE: ",C),l.info("with extended state: ",y),{stop:!0,outputs:I}}return f({type:DEBUG_MSG,trace:{message:t.predicate?"The guard ".concat(_," is not fulfilled!"):"Evaluated and skipped transition",info:{eventData:T,settings:e,guard:t,from:n,to:h,index:a,action:u},machineState:{cs:p,es:y,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{f({type:INIT_INPUT_MSG,trace:{info:{eventName:INIT_EVENT,eventData:a},event:_defineProperty({},INIT_EVENT,a),machineState:{cs:b(),es:y,hs:g}}}),A(_defineProperty({},INIT_EVENT,a),!0)}catch(n){return f({type:MACHINE_CREATION_ERROR_MSG,trace:{message:n.message,info:{fsmDef:t,settings:e,error:n},machineState:{cs:INIT_STATE,es:y,hs:g}}}),n}return function(t){try{var e=destructureEvent(t),n=e.eventName,r=e.eventData,a=b();f({type:INPUT_MSG,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:y,hs:g}}});var i=A(t,!0);return s&&l.info("OUTPUTS:",i),f({type:OUTPUTS_MSG,trace:{outputs:i,machineState:{cs:b(),es:y,hs:g}}}),i}catch(t){return t instanceof KinglyError?(f({type:ERROR_MSG,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:b(),es:y,hs:g}}}),t):(f({type:ERROR_MSG,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:b(),es:y,hs:g}}}),l.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 makeNamedActionsFactory(t){return Object.keys(t).reduce(function(e,n){var r=t[n];return r.displayName=n,e[n]=r,e},{})}function mergeOutputsFn(t){return t.reduce(function(t,e){return t.concat(e)},[])}function decorateWithEntryActions(t,e,n){if(!e)return t;var r=t.transitions,a=t.states,i=t.initialExtendedState,o=t.initialControlState,s=t.events,c=t.updateState,u=t.settings,l=getFsmStateList(a),f=Object.keys(e).every(function(t){return null!=l[t]}),d=n||mergeOutputsFn;if(f)return{initialExtendedState:i,initialControlState:o,states:a,events:s,transitions:mapOverTransitionsActions(function(t,n,r,a){var i=n.to,o=e[i];return o?decorateWithExitAction(t,o,d,c):t},r),updateState:c,settings:u};throw"decorateWithEntryActions : found control states for which entry actions are defined, and yet do not exist in the state machine!"}function decorateWithExitAction(t,e,n,r){var a=function(a,i,o){var s=o.debug,c=tryCatchMachineFn(ENTRY_ACTION_FACTORY_DESC,e,["extendedState","eventData","settings"]),u=t(a,i,o),l=u.updates,f=tryCatchMachineFn(UPDATE_STATE_FN_DESC,r,["extendedState, updates"])(a,l);handleFnExecError({debug:s,console:console},{updateStateFn:r,extendedState:a,actionUpdate:l},f,alwaysTrue,notifyAndRethrow,noop);var d=f,T=c(d,i,o);if(!handleFnExecError({debug:s,console:console},{action:e,extendedState:d,eventData:i,settings:o},T,isActions,notifyAndRethrow,throwIfInvalidEntryActionResult))return{updates:[].concat(l,T.updates),outputs:n([u.outputs,T.outputs])}};return a.displayName="Entry_Action_After_".concat(getFunctionName(t)),a}function traceFSM(t,e){var n=e.initialExtendedState,r=e.initialControlState,a=e.events,i=e.states,o=e.transitions,s=e.updateState;return{initialExtendedState:n,initialControlState:r,events:a,states:i,updateState:s,transitions:mapOverTransitionsActions(function(t,e,n,r){return function(a,i,o){var c=e.from,u=e.event,l=e.to,f=e.predicate,d=tryCatchMachineFn(ACTION_FACTORY_DESC,t,["extendedState","eventData","settings"])(a,i,o),T=d.outputs,p=d.updates;return{updates:p,outputs:[{outputs:T,updates:p,extendedState:a,newExtendedState:tryCatchMachineFn(UPDATE_STATE_FN_DESC,s,["extendedState, updates"])(a,p||[]),controlState:c,event:{eventLabel:u,eventData:i},settings:o,targetControlState:l,predicate:f,actionFactory:t,guardIndex:n,transitionIndex:r}]}}},o)}}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,build_state_enum,normalizeTransitions,normalizeFsmDef,create_state_machine,createStateMachine,makeWebComponentFromFsm,makeNamedActionsFactory,mergeOutputsFn,decorateWithEntryActions,traceFSM,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){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_event_enum(t){var e=t.reduce?t.slice():Array.prototype.slice.call(arguments);return e.push(INIT_EVENT),e.reduce(function(t,e){return t[e]=e,t},{})}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,a=t.initialExtendedState,i=t.updateState,o=e||{},s=o.debug,c=o.devTool,u=(o.displayName,s&&s.checkContracts||void 0),l=s&&s.console||emptyConsole,f=c&&c.tracer||emptyTracer,d=function(t){throw new KinglyError(t,l,f)};if(u){var T=fsmContractChecker(t,e,u).failingContracts;try{T.length>0&&d({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:e,failingContracts:T},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return f({type:MACHINE_CREATION_ERROR_MSG,trace:{info:t.errors,message:t.message,machineState:{cs:INIT_STATE,es:_,hs:v}}}),t}}build_event_enum(r);var p=normalizeTransitions(t),m=build_nested_state_structure(n),_=a,y=computeHistoryMaps(n),h=y.stateList,g=y.stateAncestors,v=initHistoryDataStructure(h),S={},E={},O=m.is_group_state,N=m.hash_states;function b(){return N[INIT_STATE].current_state_name}function I(t,e){var n;n=assert(isEventStruct,[t]),u&&n&&d(n);var r=destructureEvent(t),a=r.eventName,i=r.eventData,o=b();return l.debug("send event",t),e&&a===INIT_EVENT&&o!==INIT_STATE?(f({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:o,es:_,hs:v}}}),l.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){l.log("found event handler!"),l.info("WHEN EVENT ",e,n);var o=i(r,n,a),c=o.stop,u=o.outputs;s&&!c&&l.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var d=arrayizeOutput(u),T=t[INIT_STATE].current_state_name;if(E[T]&&T!==a){var p=S[T]?INIT_EVENT:AUTO_EVENT;f({type:INTERNAL_INPUT_MSG,trace:{info:{eventName:p,eventData:n},event:_defineProperty({},p,n),machineState:{cs:b(),es:r,hs:v}}});var m=I(_defineProperty({},p,n),!1);return f({type:INTERNAL_OUTPUTS_MSG,trace:{outputs:m,machineState:{cs:b(),es:r,hs:v}}}),[].concat(d).concat(m)}return d}return l.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!")),null}(m.hash_states,a,i,_)}p.forEach(function(t){var n=t.from,r=t.to,a=t.action,o=t.event,c=t.guards;c||(c=[{predicate:void 0,to:r,action:a}]),o===INIT_EVENT&&(S[n]=!0);var u=N[n];o||(o=AUTO_EVENT,E[n]=!0),O[n]&&S[n]&&(E[n]=!0),u[o]=c.reduce(function(t,r,a){var c=r.action||ACTION_IDENTITY,u=c.name||c.displayName||"",T=function(t,e){var r=function(r,T,p){n=p||n;var m=t.predicate||alwaysTrue,y=m.name||m.displayName||"<anonymous>",h=t.to,E=function(e,r,i){try{return m(e,r,i)}catch(s){d({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > shouldTransitionBeTaken",info:{extendedState:e,event:o,event_data:r,settings:i,guard:t,from:n,to:h,index:a},message:["Error occurred while processing event ".concat(o," with target state ").concat(h),s.message].join("\n"),stack:s.stack})}}(r,T,e);if("boolean"!=typeof E&&d({when:"Executing predicate function ".concat(y),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:o,guard:t,from:n,to:h,index:a,shouldTransitionBeTaken:E},message:"Guard index ".concat(a," with name ").concat(y," did not return a boolean!")}),E){l.info("IN STATE ",n),t.predicate?(f({type:DEBUG_MSG,trace:{message:"The guard ".concat(y," is fulfilled"),info:{eventData:T,from:n,action:u,to:h},machineState:{cs:p,es:r,hs:v}}}),l.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(f({type:DEBUG_MSG,trace:{message:"Evaluating transition with no guards",info:{eventData:T,from:n,action:u,to:h},machineState:{cs:p,es:_,hs:v}}}),l.info("CASE: unguarded transition")),l.info("THEN : we execute the action "+u);var O=function(e,r,i){try{return c(e,r,i)}catch(r){d({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:e,event:o,event_data:T,settings:i,guard:t,from:n,to:h,index:a,action:c},message:r.message,stack:r.stack})}}(r,T,e);isActions(O)||d({when:"Executing action factory ".concat(u),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:_,event:o,event_data:T,settings:e,guard:t,from:n,to:h,index:a,action:c,actionResult:O},message:"Action factory returned a value that does not have the expected shape!"});var I=O.updates,A=O.outputs;!function(t,e,n){var r=n[t].name;v=updateHistory(v,g,r),l.info("left state",wrap(t))}(n,0,N),_=function(t,e){var n=i.name||i.displayName||"";try{return i(t,e)}catch(r){d({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];s&&l&&!S[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=v[a][i]||i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t].name}return n[INIT_STATE].current_state_name=r,f({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:b(),es:_,hs:v}}}),s&&l.info("AND TRANSITION TO STATE",r),r}(h,0,N);return l.info("ENTERING NEXT STATE: ",R),l.info("with extended state: ",_),{stop:!0,outputs:A}}return f({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:h,index:a,action:u},machineState:{cs:p,es:_,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{f({type:INIT_INPUT_MSG,trace:{info:{eventName:INIT_EVENT,eventData:a},event:_defineProperty({},INIT_EVENT,a),machineState:{cs:b(),es:_,hs:v}}}),I(_defineProperty({},INIT_EVENT,a),!0)}catch(n){return f({type:MACHINE_CREATION_ERROR_MSG,trace:{message:n.message,info:{fsmDef:t,settings:e,error:n},machineState:{cs:INIT_STATE,es:_,hs:v}}}),n}return function(t){try{var e=destructureEvent(t),n=e.eventName,r=e.eventData,a=b();f({type:INPUT_MSG,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:_,hs:v}}});var i=I(t,!0);return s&&l.info("OUTPUTS:",i),f({type:OUTPUTS_MSG,trace:{outputs:i,machineState:{cs:b(),es:_,hs:v}}}),i}catch(t){return t instanceof KinglyError?(f({type:ERROR_MSG,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:b(),es:_,hs:v}}}),t):(f({type:ERROR_MSG,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:b(),es:_,hs:v}}}),l.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}; | ||
//# 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.")},F=function(t,e){return"".concat(k(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},R="action factory",I="(decorating) entry action",x="update state function",D="predicate",P="CONTRACTS_EVAL",L="OUTPUTS_MSG",H="INPUT_MSG",U="WARN_MSG",B="MACHINE_CREATION_ERROR_MSG",G="ERROR_MSG",V="INTERNAL_INPUT_MSG",W="INTERNAL_OUTPUTS_MSG",Y="DEBUG_MSG",J="INIT_INPUT_MSG";const K=[0],X="PRE_ORDER";function z(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function q(t,e){return Object.assign({},t,e)}function $(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 Q(t,e){t.set(e,q(t.get(e),{isVisited:!0}))}function Z(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()):z(l);let h="function"==typeof i?new(i()):z(i),m=p;for(o([e],h),d.set(e,{isAdded:!0,isVisited:!1,path:K});!c(h);){const t=s(h),e=u(d,t);o(e,h),$(d,t,e),m=f(m,d,t),Q(d,t)}return d.clear(),m}function tt(t,e,n){const{getChildren:r}=t;return Z({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 et(t,e,n){const{getChildren:r}=t;return Z({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 nt(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 Z({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 rt={isLeafLabel:function(t){return 0===rt.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 at(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:tt,PRE_ORDER:et,POST_ORDER:nt}[r]||et)(rt,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(K)?t:i(t,e,n)}},n)}const it={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 ot=function(){},st={log:ot,warn:ot,info:ot,debug:ot,error:ot,trace:ot},ct=ot;function ut(t){return"function"==typeof t}function ft(t){return t&&"string"==typeof t||Ht(t)}function lt(t){return void 0===t||"string"==typeof t}function dt(t){return t&&"function"==typeof t}function pt(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 ht(t){return["-",t,"-"].join("")}function mt(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function vt(t){return Object.keys(t)}function gt(t){return t.to.startsWith(y)}function yt(t){return t.event===T}function bt(t){return function(e){return e.from===t}}function Tt(t){return function(e){return St(t,e.to)}}function St(t,e){return e.substring(y.length)===t}function Et(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 Ot(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(y.length),".").concat(g)}function _t(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 wt(t){return t.replace(/_/g," ")}function At(t){var e=rt.getLabel;return at({strategy:X,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function Nt(t){var e=rt.getLabel,n=rt.isLeafLabel;return at({strategy:X,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=rt.getLabel;return at({strategy:X,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 Ct(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Ht(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function kt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Ht(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function Mt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return Ht(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function Ft(t){return Pt(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(Ht(a)){var o=Bt(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(Ht(i)){var s=Bt(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function Rt(t){return Pt(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=rt.getLabel,n=rt.getChildren;return at({strategy:X,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 xt(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var e=rt.getLabel,n=at({strategy:X,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 Dt(t,e){return Pt(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)}function Pt(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 Lt(t){return t===_?_:Array.isArray(t)?t:[t]}function Ht(t){return"object"===e(t)&&(j in t||N in t)}function Ut(t){return t[j]?j:N}function Bt(t){return t[Ut(t)]}function Gt(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 Vt(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function Wt(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 Yt(t){return t.find(function(t){return t.from===b&&t.event===T})}function Jt(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 Kt(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return Jt(e,function(r,a){var i=new Error(r),o=Xt(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})}function Xt(t){return t.name||t.displayName||"anonymous"}function zt(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 qt(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function $t(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 Qt(t,e){t.debug;throw qt(t.console,e),e}function Zt(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,c=Xt(a),u=new Error(M(c,I));throw u.info={fnName:Xt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},qt(r,u),u}function te(t){return t&&"updates"in t&&"outputs"in t&&(t.outputs===_||Array.isArray(t.outputs))}function ee(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 ne(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}var re=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 ae(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&ft(e)&<(n)&&ft(a)&&dt(i)}function ie(t){var e=t.to,n=t.predicate,r=t.action;return e&&ft(e)&&ut(n)&&dt(r)}function oe(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&ft(e)&<(n)&&r.every(ie)}var se={injected:function(t,e){return{statesType:Nt(t.states),initTransition:Yt(t.transitions),statesTransitionsMap:Ct(t.transitions),stateEventTransitionsMaps:kt(t.transitions),eventTransitionsMaps:Mt(t.transitions),ancestorMap:It(t.states),statesPath:jt(t.states),historyStatesMap:Ft(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!ae(t)&&!oe(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=rt.getLabel,r=at({strategy:X,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&&(ae(r)||oe(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 Ht(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 Ht(n)&&!a[Bt(n)]?t.concat(i):t},e):Ht(s)&&!a[Bt(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 ce=function(t,e,n){return function(t,e){var n=e&&e.debug&&e.debug.console||st,r=e&&e.debug&&e.debug.trace||ot,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({},P,f)),f}}(n,e)(t,e)};function ue(){return!0}function fe(t){var e=t.initialControlState,n=t.transitions,r=Yt(n);return e?n.concat([{from:b,event:T,to:e,action:w}]):r?n:void 0}function le(t,n){var r=t.states,i=t.events,o=t.initialExtendedState,s=t.updateState,c=n||{},u=c.debug,f=c.devTool,l=(c.displayName,u&&u.checkContracts||void 0),d=u&&u.console||st,p=f&&f.tracer||ct,h=function(t){throw new re(t,d,p)};if(l){var m=ce(t,n,l).failingContracts;try{m.length>0&&h({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:n,failingContracts:m},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return p({type:B,trace:{info:t.errors,message:t.message,machineState:{cs:b,es:y,hs:C}}}),t}}!function(t){var e=t.reduce?t.slice():Array.prototype.slice.call(arguments);e.push(T),e.reduce(function(t,e){return t[e]=e,t},{})}(i);var v=fe(t),g=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){vt(i).forEach(function(s){var c=i[s];if(r[s]=new o,r[s].name=s,r[s].parent_name=pt(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),y=o,O=xt(r),_=O.stateList,A=O.stateAncestors,C=Gt(_),k={},M={},F=g.is_group_state,R=g.hash_states;function I(){return R[b].current_state_name}function x(t,e){var n;n=zt(ee,[t]),l&&n&&h(n);var r=ne(t),i=r.eventName,o=r.eventData,s=I();return d.debug("send event",t),e&&i===T&&s!==b?(p({type:U,trace:{info:{eventName:i,eventData:o},message:"The external event INIT_EVENT can only be sent when starting the machine!",machineState:{cs:s,es:y,hs:C}}}),d.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){d.log("found event handler!"),d.info("WHEN EVENT ",e,n);var s=o(r,n,i),c=s.stop,f=s.outputs;u&&!c&&d.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var l=Lt(f),h=t[b].current_state_name;if(M[h]&&h!==i){var m=k[h]?T:S;p({type:V,trace:{info:{eventName:m,eventData:n},event:a({},m,n),machineState:{cs:I(),es:r,hs:C}}});var v=x(a({},m,n),!1);return p({type:W,trace:{outputs:v,machineState:{cs:I(),es:r,hs:C}}}),[].concat(l).concat(v)}return l}return d.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!")),null}(g.hash_states,i,o,y)}v.forEach(function(t){var e=t.from,r=t.to,a=t.action,i=t.event,o=t.guards;o||(o=[{predicate:void 0,to:r,action:a}]),i===T&&(k[e]=!0);var c=R[e];i||(i=S,M[e]=!0),F[e]&&k[e]&&(M[e]=!0),c[i]=o.reduce(function(t,r,a){var o=r.action||w,c=o.name||o.displayName||"",f=function(t,n){var r=function(r,f,l){e=l||e;var m=t.predicate||ue,v=m.name||m.displayName||"<anonymous>",g=t.to,T=function(n,r,o){try{return m(n,r,o)}catch(s){h({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:g,index:a},message:["Error occurred while processing event ".concat(i," with target state ").concat(g),s.message].join("\n"),stack:s.stack})}}(r,f,n);if("boolean"!=typeof T&&h({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:i,guard:t,from:e,to:g,index:a,shouldTransitionBeTaken:T},message:"Guard index ".concat(a," with name ").concat(v," did not return a boolean!")}),T){d.info("IN STATE ",e),t.predicate?(p({type:Y,trace:{message:"The guard ".concat(v," is fulfilled"),info:{eventData:f,from:e,action:c,to:g},machineState:{cs:l,es:r,hs:C}}}),d.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(p({type:Y,trace:{message:"Evaluating transition with no guards",info:{eventData:f,from:e,action:c,to:g},machineState:{cs:l,es:y,hs:C}}}),d.info("CASE: unguarded transition")),d.info("THEN : we execute the action "+c);var S=function(n,r,s){try{return o(n,r,s)}catch(r){h({when:"Executing action factory ".concat(c),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:n,event:i,event_data:f,settings:s,guard:t,from:e,to:g,index:a,action:o},message:r.message,stack:r.stack})}}(r,f,n);te(S)||h({when:"Executing action factory ".concat(c),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:y,event:i,event_data:f,settings:n,guard:t,from:e,to:g,index:a,action:o,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;C=Wt(C,A,r),d.info("left state",ht(t))}(e,0,R),y=function(t,e){var n=s.name||s.displayName||"";try{return s(t,e)}catch(r){h({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,E);var _=function(t,e,n){var r;if(Ht(t)){var a=t.deep?j:t.shallow?N:void 0,i=t[a];u&&d&&!k[i]&&d.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=C[a][i]||i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t].name}return n[b].current_state_name=r,p({type:Y,trace:{message:Ht(t)?"Entering history state for ".concat(t[t.deep?j:t.shallow?N:void 0]):"Entering state ".concat(t),machineState:{cs:I(),es:y,hs:C}}}),u&&d.info("AND TRANSITION TO STATE",r),r}(g,0,R);return d.info("ENTERING NEXT STATE: ",_),d.info("with extended state: ",y),{stop:!0,outputs:O}}return p({type:Y,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:g,index:a,action:c},machineState:{cs:l,es:y,hs:C}}}),{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{p({type:J,trace:{info:{eventName:T,eventData:o},event:a({},T,o),machineState:{cs:I(),es:y,hs:C}}}),x(a({},T,o),!0)}catch(e){return p({type:B,trace:{message:e.message,info:{fsmDef:t,settings:n,error:e},machineState:{cs:b,es:y,hs:C}}}),e}return function(t){try{var e=ne(t),n=e.eventName,r=e.eventData,a=I();p({type:H,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:y,hs:C}}});var i=x(t,!0);return u&&d.info("OUTPUTS:",i),p({type:L,trace:{outputs:i,machineState:{cs:I(),es:y,hs:C}}}),i}catch(t){return t instanceof re?(p({type:G,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:I(),es:y,hs:C}}}),t):(p({type:G,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:I(),es:y,hs:C}}}),d.error("yyield > unexpected error!",t),t)}}}function de(t){return t.reduce(function(t,e){return t.concat(e)},[])}function pe(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(wt(t),'" as ').concat(t," <<NoContent>>")}t.fsmContracts=se,t.build_state_enum=function(t){var n={history:{}};return n.NOK=b,function t(r){vt(r).forEach(function(a){var i=r[a];n[a]=a,"object"===e(i)&&t(i)})}(t),n},t.normalizeTransitions=fe,t.normalizeFsmDef=function(t){return Object.assign({},t,{transitions:fe(t)})},t.create_state_machine=function(t,e){return le(t,e)},t.createStateMachine=le,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.makeNamedActionsFactory=function(t){return Object.keys(t).reduce(function(e,n){var r=t[n];return r.displayName=n,e[n]=r,e},{})},t.mergeOutputsFn=de,t.decorateWithEntryActions=function(t,e,n){if(!e)return t;var r=t.transitions,a=t.states,i=t.initialExtendedState,o=t.initialControlState,s=t.events,c=t.updateState,u=t.settings,f=At(a),l=Object.keys(e).every(function(t){return null!=f[t]}),d=n||de;if(l)return{initialExtendedState:i,initialControlState:o,states:a,events:s,transitions:Dt(function(t,n,r,a){var i=n.to,o=e[i];return o?function(t,e,n,r){var a=function(a,i,o){var s=o.debug,c=Kt(I,e,["extendedState","eventData","settings"]),u=t(a,i,o),f=u.updates,l=Kt(x,r,["extendedState, updates"]),d=l(a,f);$t({debug:s,console:console},{updateStateFn:r,extendedState:a,actionUpdate:f},d,ue,Qt,ot);var p=d,h=c(p,i,o),m=$t({debug:s,console:console},{action:e,extendedState:p,eventData:i,settings:o},h,te,Qt,Zt);if(!m)return{updates:[].concat(f,h.updates),outputs:n([u.outputs,h.outputs])}};return a.displayName="Entry_Action_After_".concat(Xt(t)),a}(t,o,d,c):t},r),updateState:c,settings:u};throw"decorateWithEntryActions : found control states for which entry actions are defined, and yet do not exist in the state machine!"},t.traceFSM=function(t,e){var n=e.initialExtendedState,r=e.initialControlState,a=e.events,i=e.states,o=e.transitions,s=e.updateState;return{initialExtendedState:n,initialControlState:r,events:a,states:i,updateState:s,transitions:Dt(function(t,e,n,r){return function(a,i,o){var c=e.from,u=e.event,f=e.to,l=e.predicate,d=Kt(R,t,["extendedState","eventData","settings"])(a,i,o),p=d.outputs,h=d.updates;return{updates:h,outputs:[{outputs:p,updates:h,extendedState:a,newExtendedState:Kt(x,s,["extendedState, updates"])(a,h||[]),controlState:c,event:{eventLabel:u,eventData:i},settings:o,targetControlState:f,predicate:l,actionFactory:t,guardIndex:n,transitionIndex:r}]}}},o)}},t.makeHistoryStates=function(t){var e=Object.keys(At(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=rt.getChildren,o=rt.getLabel,s=function(t){return t.join(h)},c=nt(rt,{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(pe(t,"")," {"),e.join("\n"),function(t,e){var n=e.reduce(function(e,n){var r=_t(n);return r.filter(gt).filter(Tt(t)).reduce(function(t,e){return t[Ot(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(pe(t,g))}).join("\n")}(t,n),function(t,e){return e.reduce(function(e,n){var r=_t(n);return r.filter(yt).filter(bt(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(Et("",r,a))),t},e)},[]).join("\n")}(t,n),"}",function(t,e){var n=function(t,e){return e.map(function(e){var n=_t(e);return n.filter(bt(t)).filter(gt).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,m,Ot({from:e,to:a}),v,Et(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=_t(e);return n.filter(bt(t)).filter(function(t){return!yt(t)}).filter(function(t){return!gt(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,Et(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],mt(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=rt.getLabel,i=rt.getChildren,o=it.constructTree,s=function(t){return t.join(h)},c=nt(rt,{seed:function(){return Map},visit:function(t,e,n){var a=e.get(n).path,c=r(n),u=Object.keys(c)[0],f=mt(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=F,t.ACTION_FACTORY_DESC=R,t.ENTRY_ACTION_FACTORY_DESC=I,t.UPDATE_STATE_FN_DESC=x,t.PREDICATE_DESC=D,t.COMMAND_RENDER="render",t.CONTRACTS_EVAL=P,t.OUTPUTS_MSG=L,t.INPUT_MSG=H,t.WARN_MSG=U,t.MACHINE_CREATION_ERROR_MSG=B,t.ERROR_MSG=G,t.INTERNAL_INPUT_MSG=V,t.INTERNAL_OUTPUTS_MSG=W,t.DEBUG_MSG=Y,t.INIT_INPUT_MSG=J,t.noop=ot,t.emptyConsole=st,t.emptyTracer=ct,t.isBoolean=function(t){return"boolean"==typeof t},t.isFunction=ut,t.isControlState=ft,t.isEvent=lt,t.isActionFactory=dt,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=pt,t.wrap=ht,t.times=mt,t.always=function(t){return t},t.keys=vt,t.merge=function(t,e){return Object.assign({},t,e)},t.is_history_transition=gt,t.is_entry_transition=yt,t.is_from_control_state=bt,t.is_to_history_control_state_of=Tt,t.is_history_control_state_of=St,t.format_transition_label=Et,t.format_history_transition_state_name=Ot,t.get_all_transitions=_t,t.getDisplayName=wt,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=At,t.getStatesType=Nt,t.getStatesPath=jt,t.getStatesTransitionsMap=Ct,t.getStateEventTransitionsMaps=kt,t.getEventTransitionsMaps=Mt,t.getHistoryStatesMap=Ft,t.getTargetStatesMap=Rt,t.getAncestorMap=It,t.computeHistoryMaps=xt,t.mapOverTransitionsActions=Dt,t.reduceTransitions=Pt,t.everyTransition=function(t,e){return Pt(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=Lt,t.isHistoryControlState=Ht,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=Ut,t.getHistoryUnderlyingState=Bt,t.isHistoryStateEdge=function(t){return void 0!==t.history},t.initHistoryDataStructure=Gt,t.isCompoundState=Vt,t.isAtomicState=function(t,e){return!Vt(t,e)},t.updateHistory=Wt,t.computeHistoryState=function(t,e,n,r){var a=xt(t),i=a.stateList,o=a.stateAncestors,s=Gt(i);return(s=e.reduce(function(t,e){return Wt(t,o,e)},s))[n][r]},t.findInitTransition=Yt,t.tryCatch=Jt,t.tryCatchMachineFn=Kt,t.getFunctionName=Xt,t.assert=zt,t.notifyThrows=qt,t.handleFnExecError=$t,t.notifyAndRethrow=Qt,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=Xt(a),u=new Error(M(c,R));throw u.info={fnName:Xt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},qt(r,u),u},t.throwIfInvalidGuardResult=function(t,e,n){t.debug;var r=t.console,a=Xt(n.predicate),i=new Error(F(a,D));throw i.info={predicateName:a,params:n,returned:e},qt(r,i),i},t.throwIfInvalidEntryActionResult=Zt,t.isActions=te,t.isEventStruct=ee,t.isError=function(t){return t instanceof Error},t.destructureEvent=ne,t.formatUndefinedInJSON=function(t){return JSON.stringify(t,function(t,e){return void 0===e?"undefined":e})},t.KinglyError=re,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={},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,o=t.initialExtendedState,s=t.updateState,c=n||{},u=c.debug,f=c.devTool,l=(c.displayName,u&&u.checkContracts||void 0),d=u&&u.console||ot,p=f&&f.tracer||st,h=function(t){throw new $t(t,d,p)};if(l){var m=ne(t,n,l).failingContracts;try{m.length>0&&h({when:"Attempting to create a Kingly machine",location:"createStateMachine",info:{fsmDef:t,settings:n,failingContracts:m},message:"I found that one or more Kingly contracts are violated!"})}catch(t){return p({type:U,trace:{info:t.errors,message:t.message,machineState:{cs:b,es:y,hs:C}}}),t}}!function(t){var e=t.reduce?t.slice():Array.prototype.slice.call(arguments);e.push(T),e.reduce(function(t,e){return t[e]=e,t},{})}(i);var v=ae(t),g=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),y=o,O=Ft(r),_=O.stateList,A=O.stateAncestors,C=Ut(_),k={},M={},R=g.is_group_state,I=g.hash_states;function F(){return I[b].current_state_name}function x(t,e){var n;n=Jt(qt,[t]),l&&n&&h(n);var r=zt(t),i=r.eventName,o=r.eventData,s=F();return d.debug("send event",t),e&&i===T&&s!==b?(p({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:y,hs:C}}}),d.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){d.log("found event handler!"),d.info("WHEN EVENT ",e,n);var s=o(r,n,i),c=s.stop,f=s.outputs;u&&!c&&d.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var l=Dt(f),h=t[b].current_state_name;if(M[h]&&h!==i){var m=k[h]?T:S;p({type:G,trace:{info:{eventName:m,eventData:n},event:a({},m,n),machineState:{cs:F(),es:r,hs:C}}});var v=x(a({},m,n),!1);return p({type:V,trace:{outputs:v,machineState:{cs:F(),es:r,hs:C}}}),[].concat(l).concat(v)}return l}return d.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!")),null}(g.hash_states,i,o,y)}v.forEach(function(t){var e=t.from,r=t.to,a=t.action,i=t.event,o=t.guards;o||(o=[{predicate:void 0,to:r,action:a}]),i===T&&(k[e]=!0);var c=I[e];i||(i=S,M[e]=!0),R[e]&&k[e]&&(M[e]=!0),c[i]=o.reduce(function(t,r,a){var o=r.action||w,c=o.name||o.displayName||"",f=function(t,n){var r=function(r,f,l){e=l||e;var m=t.predicate||re,v=m.name||m.displayName||"<anonymous>",g=t.to,T=function(n,r,o){try{return m(n,r,o)}catch(s){h({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:g,index:a},message:["Error occurred while processing event ".concat(i," with target state ").concat(g),s.message].join("\n"),stack:s.stack})}}(r,f,n);if("boolean"!=typeof T&&h({when:"Executing predicate function ".concat(v),location:"createStateMachine > event handler > condition_checking_fn > throwIfInvalidGuardResult",info:{event:i,guard:t,from:e,to:g,index:a,shouldTransitionBeTaken:T},message:"Guard index ".concat(a," with name ").concat(v," did not return a boolean!")}),T){d.info("IN STATE ",e),t.predicate?(p({type:W,trace:{message:"The guard ".concat(v," is fulfilled"),info:{eventData:f,from:e,action:c,to:g},machineState:{cs:l,es:r,hs:C}}}),d.info("CASE: guard ".concat(m.name," for transition is fulfilled"))):(p({type:W,trace:{message:"Evaluating transition with no guards",info:{eventData:f,from:e,action:c,to:g},machineState:{cs:l,es:y,hs:C}}}),d.info("CASE: unguarded transition")),d.info("THEN : we execute the action "+c);var S=function(n,r,s){try{return o(n,r,s)}catch(r){h({when:"Executing action factory ".concat(c),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:n,event:i,event_data:f,settings:s,guard:t,from:e,to:g,index:a,action:o},message:r.message,stack:r.stack})}}(r,f,n);Xt(S)||h({when:"Executing action factory ".concat(c),location:"createStateMachine > event handler > condition_checking_fn",info:{extendedState:y,event:i,event_data:f,settings:n,guard:t,from:e,to:g,index:a,action:o,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;C=Gt(C,A,r),d.info("left state",pt(t))}(e,0,I),y=function(t,e){var n=s.name||s.displayName||"";try{return s(t,e)}catch(r){h({when:"Executing updateState function ".concat(n),location:"createStateMachine > wrappedUpdateState",info:{extendedState:t,updates:e},message:r.message,stack:r.stack})}}(r,E);var _=function(t,e,n){var r;if(Pt(t)){var a=t.deep?j:t.shallow?N:void 0,i=t[a];u&&d&&!k[i]&&d.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=C[a][i]||i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t].name}return n[b].current_state_name=r,p({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:F(),es:y,hs:C}}}),u&&d.info("AND TRANSITION TO STATE",r),r}(g,0,I);return d.info("ENTERING NEXT STATE: ",_),d.info("with extended state: ",y),{stop:!0,outputs:O}}return p({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:g,index:a,action:c},machineState:{cs:l,es:y,hs:C}}}),{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{p({type:Y,trace:{info:{eventName:T,eventData:o},event:a({},T,o),machineState:{cs:F(),es:y,hs:C}}}),x(a({},T,o),!0)}catch(e){return p({type:U,trace:{message:e.message,info:{fsmDef:t,settings:n,error:e},machineState:{cs:b,es:y,hs:C}}}),e}return function(t){try{var e=zt(t),n=e.eventName,r=e.eventData,a=F();p({type:L,trace:{info:{eventName:n,eventData:r},machineState:{cs:a,es:y,hs:C}}});var i=x(t,!0);return u&&d.info("OUTPUTS:",i),p({type:P,trace:{outputs:i,machineState:{cs:F(),es:y,hs:C}}}),i}catch(t){return t instanceof $t?(p({type:B,trace:{error:t,message:"An error ocurred while running an input through the machine!",machineState:{cs:F(),es:y,hs:C}}}),t):(p({type:B,trace:{error:t,message:"An unknown error ocurred while running an input through the machine!",machineState:{cs:F(),es:y,hs:C}}}),d.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})}); | ||
//# sourceMappingURL=kingly.umd.min.js.map |
{ | ||
"name": "kingly", | ||
"sideEffects": false, | ||
"version": "0.26.0", | ||
"version": "0.26.3", | ||
"description": "Extended Hierarchical State Transducer library", | ||
@@ -86,4 +86,3 @@ "repository": { | ||
"dependencies": { | ||
"fp-rosetree": "^0.6.2", | ||
"yed2kingly": "^0.1.0" | ||
"fp-rosetree": "^0.6.2" | ||
}, | ||
@@ -90,0 +89,0 @@ "browserslist": [ |
@@ -14,2 +14,3 @@ |Modelize your interface | Encode the graph | Run the generated machine! | | ||
- [Examples](#examples) | ||
- [Tooling](#tooling) | ||
- [Motivation](#motivation) | ||
@@ -51,2 +52,18 @@ - [Install](#install) | ||
# Tooling | ||
Kingly has been used to implement large applications such as [Conduit](https://github.com/gothinkster/realworld), a simplified [Medium](https://medium.com/)'s clone. On such a large machine, the process has been significantly smoothed by using the free professional graph editor [yEd](https://www.yworks.com/products/yed) to produce the machine graphs. | ||
In summary, Kingly has the following tools available: | ||
- yEd graph editor ([documentation](https://brucou.github.io/documentation/v1/tooling/graph_editing.html)) | ||
- yEd graphs are saved as `.graphml` files | ||
- yEd2kingly converter ([documentation](https://brucou.github.io/documentation/v1/tooling/graph_editing.html#yed2Kingly)) | ||
- the converter enables the conversion of `.graphml` files to Kingly state machines | ||
- compiler ([documentation](https://brucou.github.io/documentation/v1/tooling/compiling.html)) | ||
- the compiler compiles a `.graphml` file into small, plain, zero-dependency JavaScript which implements the logic expressed in the graph | ||
- devtool ([devtool](https://brucou.github.io/documentation/v1/tooling/devtool.html)) | ||
- traces a Kingly machine computation. The devtool is of invaluable help while testing and debugging. | ||
 | ||
## Trivial counter application | ||
@@ -121,11 +138,11 @@ | State Machine | Demo |UI library | ||
- support for both interactive and reactive programming | ||
- parallel and sequential composability of transducers | ||
- parallel and sequential composability of state machines | ||
As a result of this, the following choices were made: | ||
- **functional interface**: the transducer is just a function. As such, the transducer is a black-box, and only its injected outputs can be observed | ||
- **complete encapsulation** of the state of the transducer | ||
- **functional interface**: the Kingly state machine is just a function. As such, the machine is a black-box, and only its outputs can be observed | ||
- **complete encapsulation** of the state of the machine | ||
- **no effects** performed by the machine | ||
- no exit and entry actions, or activities as in other state machine formalisms | ||
- there is no loss of generality as both entry and exit actions can be implemented with our state transducer. There is simply no syntactic support for it in the core API. This can however be provided through standard functional programming patterns (higher-order functions, etc.) | ||
- there is no loss of generality as both entry and exit actions can be implemented with our state machine. There is simply no syntactic support for it in the core API. This can however be provided through standard functional programming patterns (higher-order functions, etc.) | ||
- every computation performed is synchronous (asynchrony is an effect) | ||
@@ -135,3 +152,3 @@ - action factories return the **updates** to the extended state to avoid any | ||
which in turn allows him to use any formalism to represent state - for instance `immutable.js`) | ||
- no restriction is made on output of transducers, but inputs must follow some conventions (if a | ||
- no restriction is made on output of state machines, but inputs must follow some conventions (if a | ||
machine's output match those conventions, two such machines can be sequentially composed | ||
@@ -143,3 +160,3 @@ - parallel composition naturally occurs by feeding two state machines the same input(s)) | ||
Concretely, our state transducer will be created by the factory function `createStateMachine`, which returns a state transducer which: | ||
Concretely, our state machine will be created by the factory function `createStateMachine`, which returns a state machine which: | ||
@@ -150,8 +167,8 @@ - immediately positions itself in its configured initial state (as defined by its initial control | ||
Let us insist again on the fact that the state transducer is not, in general, a pure function of | ||
its inputs. However, a given output of the transducer depends exclusively on the sequence of inputs | ||
it has received so far ([causality property](https://en.wikipedia.org/wiki/Causal_system)). This means that it is possible to associate to a state transducer another function which takes a sequence of inputs into a sequence of outputs, in a way that **that** function is pure. This is what enables simple and automated testing. | ||
Let us insist again on the fact that the state machine is not, in general, a pure function of | ||
its inputs. However, a given output of the machine depends exclusively on the sequence of inputs | ||
it has received so far ([causality property](https://en.wikipedia.org/wiki/Causal_system)). This means that it is possible to associate to a state machine another function which takes a sequence of inputs into a sequence of outputs, in a way that **that** function is pure. This is what enables simple and automated testing. | ||
# Visualization tools | ||
We have included two helpers for visualization of the state transducer: | ||
We have included two helpers for visualization of the state machine: | ||
@@ -164,3 +181,3 @@ - conversion to plantUML: `toPlantUml :: FSM_Def -> PlantUml` | ||
Automated visualization works well with simple graphs, but seems to encounter trouble to generate optimally satisfying complex graphs. The Dagre layout seems to be a least worse option. I believe the best option for visualization is to use professional specialized tooling such as `yed`. In a future version, we will provide a conversion to `yed` graph format to facilitate such workflow. The [`yed`](https://www.yworks.com/products/yed) orthogonal and flowchart layout seem to give pretty good results. | ||
Automated visualization works well with simple graphs, but seems to encounter trouble to generate optimally satisfying complex graphs. The Dagre layout seems to be a least worse option. I believe the best option for visualization is to use professional specialized tooling such as `yed`. In a future version, we will provide a conversion to `yed` graph format to facilitate such workflow. The [`yed`](https://www.yworks.com/products/yed)'s orthogonal and flowchart layout seem to give pretty good results. | ||
@@ -186,7 +203,4 @@ # Credits | ||
- [x] add support for [yEd](https://www.yworks.com/products/yed) (professional graph editor) | ||
- [ ] dev tool | ||
- [ ] compiler | ||
## Roadmap v1.X: consolidate | ||
- [ ] support for live, interactive debugging | ||
- [x] [dev tool](https://github.com/brucou/yed2Kingly) (including documentation) | ||
- [x] [compiler](https://github.com/brucou/slim) (including documentation) | ||
- [ ] decide definitively on tricky semantic cases | ||
@@ -198,5 +212,9 @@ - transitionning to history states when there is no history | ||
## Roadmap v1.Y: testing | ||
## Roadmap v1.X: consolidate | ||
- [ ] support for live, interactive debugging | ||
- render time machine | ||
- [ ] add cloning API | ||
- [ ] add reset API | ||
## Roadmap v1.Y: testing | ||
- [ ] finalize, document and release testing API | ||
@@ -203,0 +221,0 @@ - [ ] turn the test generation into an iterator(ES6 generator): this allows it to be composed with transducers and manipulate the test cases one by one as soon as they are produced. Will be useful for both example-based and property-based testing. When the generators runs through thousands of test cases, we often have to wait a long time before seeing any result, which is pretty damageable when a failure is located toward the ends of the generated input sequences. |
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
1
271
1271435
6888
- Removedyed2kingly@^0.1.0
- Removedcommander@5.1.0(transitive)
- Removedfast-xml-parser@3.21.1(transitive)
- Removedfs@0.0.1-security(transitive)
- Removedkingly@0.24.1(transitive)
- Removedprettier@2.8.8(transitive)
- Removedramda@0.27.2(transitive)
- Removedstrnum@1.1.1(transitive)
- Removedyed2kingly@0.1.0(transitive)