New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kingly

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kingly - npm Package Compare versions

Comparing version 0.19.3 to 0.20.0

dist/kingly.es.js

2

dist/kingly.es.min.js

@@ -1,2 +0,2 @@

const 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=null,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=(t,e)=>`Exception thrown when executing ${e} ${t||""}`,INVALID_ACTION_FACTORY_EXECUTED=(t,e)=>`${FUNCTION_THREW_ERROR(t,e)}\nThe ${e} returned a value which is not an action.`,INVALID_PREDICATE_EXECUTED=(t,e)=>`${FUNCTION_THREW_ERROR(t,e)}\nThe ${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",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,s)=>{const i=t.get(e),a=t.get(n),o=a&&a.path;t.set(n,merge(a,{isAdded:!0,isVisited:!1,path:o||i.path.concat(s)}))})}function updateVisitInTraversalState(t,e){t.set(e,merge(t.get(e),{isVisited:!0}))}function visitTree(t,e){const{store:n,lenses:s,traverse:i}=t,{empty:a,add:o,takeAndRemoveOne:r,isEmpty:c}=n,{getChildren:u}=s,{visit:l,seed:d}=i,f=new Map,T="function"==typeof d?new(d()):clone(d);let p="function"==typeof a?new(a()):clone(a),m=T;for(o([e],p),f.set(e,{isAdded:!0,isVisited:!1,path:PATH_ROOT});!c(p);){const t=r(p),e=u(f,t);o(e,p),updatePathInTraversalState(f,t,e),m=l(m,f,t),updateVisitInTraversalState(f,t)}return f.clear(),m}function breadthFirstTraverseTree(t,e,n){const{getChildren:s}=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)=>s(e)},traverse:e},n)}function preorderTraverseTree(t,e,n){const{getChildren:s}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>s(e)},traverse:e},n)}function postOrderTraverseTree(t,e,n){const{getChildren:s}=t,{seed:i,visit:a}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===s(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)?[]:s(e,t).concat([e])},traverse:{seed:i,visit:(t,e,n)=>o(n,e)?a(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:s,seed:i,visit:a}=t;return({BFS:breadthFirstTraverseTree,PRE_ORDER:preorderTraverseTree,POST_ORDER:postOrderTraverseTree}[s]||preorderTraverseTree)(objectTreeLenses,{seed:i,visit:function(t,e,n){const{path:s}=e.get(n);return JSON.stringify(s)===JSON.stringify(PATH_ROOT)?t:a(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},noop=()=>{},emptyConsole={log:noop,warn:noop,info:noop,debug:noop,error:noop,trace: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 t&&"string"==typeof t}function isActionFactory(t){return t&&"function"==typeof t}function make_states(t){return t.reduce((t,e)=>(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){const s=t||"";return e&&n?`${s} [${e.name}] / ${n.name}`:e?`${s} [${e.name}]}`:n?`${s} / ${n.name}`:`${s}`}function format_history_transition_state_name({from:t,to:e}){return`${t}.${e.substring(HISTORY_PREFIX.length)}.${HISTORY_STATE_NAME}`}function get_all_transitions(t){const{from:e,event:n,guards:s}=t;return s?s.map(({predicate:t,to:s,action:i})=>({from:e,event:n,predicate:t,to:s,action:i})):[t]}function getDisplayName(t){return t.replace(/_/g," ")}function mergeModelUpdates(t){return function(e,n,s){return{updates:t.reduce((t,i)=>{const a=i(e,n,s).updates;return a?t.concat(a):t},[]),outputs:NO_OUTPUT}}}function chainModelUpdates(t){return function(e,n,s){const{updateState:i}=s;return{updates:t.reduce((t,e)=>{const{extendedState:a,updates:o}=t,r=e(a,n,s).updates;return{extendedState:i(a,o),updates:r}},{extendedState:e,updates:[]}).updates||[],outputs:NO_OUTPUT}}}function mergeActionFactories(t,e){return function(n,s,i){const a=e.map(t=>t(n,s,i)),o=a.map(t=>t.updates||[]),r=a.map(t=>t.outputs||{});return{updates:[].concat(...o),outputs:t(r)}}}function identity(t,e,n){return{updates:[],outputs:NO_OUTPUT}}function lastOf(t){return t[t.length-1]}function formatActionName(t,e,n,s,i){const a=i?i.name:"",o=a?`[${a}]`:"",r=t?t.name:"identity";return`${r||"unnamed action"}:${e}-${n}->${s} ${o}`}function getFsmStateList(t){const{getLabel:e}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,n,s)=>{const i=e(s);return t[Object.keys(i)[0]]="",t}},t)}function getStatesType(t){const{getLabel:e,isLeafLabel:n}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,s,i)=>{const a=e(i),o=Object.keys(a)[0];return n(a)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function getStatesPath(t){const{getLabel:e}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,n,s)=>{const i=n.get(s).path.join("."),a=e(s);return t[Object.keys(a)[0]]=i,t}},t)}function getStatesTransitionsMap(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][s]=e,t)},{})||{}}function getStatesTransitionsMaps(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][s]=t[n][s]?t[n][s].concat(e):[e],t)},{})||{}}function getEventTransitionsMaps(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[s]=t[s]||{},t[s][n]=t[s][n]?t[s][n].concat(e):[e],t)},{})||{}}function getHistoryStatesMap(t){return reduceTransitions((t,e,n,s)=>{const{from:i,event:a,to:o,action:r,predicate:c,gen:u}=e;if(isHistoryControlState(i)){const n=getHistoryUnderlyingState(i);t.set(n,(t.get(n)||[]).concat([e]))}else if(isHistoryControlState(o)){const n=getHistoryUnderlyingState(o);t.set(n,(t.get(n)||[]).concat([e]))}return t},new Map,t)||{}}function getTargetStatesMap(t){return reduceTransitions((t,e,n,s)=>{const{to:i}=e;return t.set(i,(t.get(i)||[]).concat([e])),t},new Map,t)||{}}function getAncestorMap(t){const{getLabel:e,getChildren:n}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,s,i)=>{const a=e(i),o=Object.keys(a)[0];return n(i).map(t=>Object.keys(e(t))[0]).forEach(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?";const{getLabel:e,isLeafLabel:n}=objectTreeLenses,s={strategy:PRE_ORDER,seed:{stateList:[],stateAncestors:{[DEEP]:{},[SHALLOW]:{}}},visit:(t,n,s)=>{const i=e(s),a=Object.keys(i)[0];t.stateList=t.stateList.concat(a);const{path:o}=n.get(s);n.set(JSON.stringify(o),a);const r=o.slice(0,-1);if(1===r.length)n.set(JSON.stringify(r),INIT_STATE);else{const e=n.get(JSON.stringify(r));t.stateAncestors[SHALLOW][a]=[e];const{ancestors:s}=o.reduce((t,e)=>{const s=t.path.slice(0,-1);if(t.path=s,s.length>1){const e=n.get(JSON.stringify(s));t.ancestors=t.ancestors.concat(e)}return t},{ancestors:[],path:o});t.stateAncestors[DEEP][a]=s}return t}},{stateList:i,stateAncestors:a}=traverseObj(s,t);return{stateList:i,stateAncestors:a}}function mapOverTransitionsActions(t,e){return reduceTransitions(function(e,n,s,i){const{from:a,event:o,to:r,action:c,predicate:u}=n,l=t(c,n,s,i);return l.displayName=l.displayName||c&&(c.name||c.displayName||formatActionName(c,a,o,r,u)),void 0===u?e.push({from:a,event:o,to:r,action:l}):0===s?e.push({from:a,event:o,guards:[{to:r,predicate:u,action:l}]}):e[e.length-1].guards.push({to:r,predicate:u,action:l}),e},[],e)}function reduceTransitions(t,e,n){return n.reduce((e,n,s)=>{let{from:i,event:a,to:o,gen:r,action:c,guards:u}=n;return u||(u=r?[{to:o,action:c,gen:r,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce((e,n,o)=>{const{to:r,action:c,gen:u,predicate:l}=n;return t(e,u?{from:i,event:a,to:r,action:c,predicate:l,gen:u}:{from:i,event:a,to:r,action:c,predicate:l},o,s)},e)},e)}function everyTransition(t,e){return reduceTransitions((e,n)=>e&&t(n),!0,[e])}function computeTimesCircledOn(t,e){return t.reduce((t,n)=>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){const e=()=>t.reduce((t,e)=>(t[e]="",t),{});return{[DEEP]:e(),[SHALLOW]:e()}}function isCompoundState(t,e){const{statesAdjacencyList:n}=t;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:([SHALLOW,DEEP].forEach(s=>{(e[s][n]||[]).forEach(e=>{t[s][e]=n})}),t)}function computeHistoryState(t,e,n,s){const{stateList:i,stateAncestors:a}=computeHistoryMaps(t);let o=initHistoryDataStructure(i);return(o=e.reduce((t,e)=>updateHistory(t,a,e),o))[n][s]}function findInitTransition(t){return t.find(t=>t.from===INIT_STATE&&t.event===INIT_EVENT)}function tryCatch(t,e){return function(...n){try{return t.apply(t,n)}catch(t){return e(t,n)}}}function tryCatchMachineFn(t,e,n=[]){return tryCatch(e,(s,i)=>{const a=new Error(s),o=getFunctionName(e),r=FUNCTION_THREW_ERROR(o,t);a.probableCause=s.probableCause?[s.probableCause,r].join("\n"):r;const c={fnName:o,params:n.reduce((t,e,n)=>(t[e]=i[n],t),{})};return a.info=s.info?[].concat([s.info]).concat([c]):c,a})}function getFunctionName(t){return t.name||t.displayName||"anonymous"}function assert(t,e){const n=t.apply(null,e);if(!0!==n){const e=n.info;throw console.error(`ERROR: failed contract ${t.name||""}. ${e?"Error info:":""}`,n.info),n}}function notifyThrows(t,e){t.error(e),e.probableCause&&t.error(`Probable cause: ${e.probableCause}`),e.info&&t.error("ERROR: additional info",e.info)}function handleFnExecError(t,e,n,s,i,a){const{debug:o,console:r}=t;return o&&n instanceof Error?(i({debug:o,console:r},n,e),!0):!(!o||s(n))&&(a({debug:o,console:r},n,e),!0)}function notifyAndRethrow({debug:t,console:e},n){throw notifyThrows(e,n),n}function throwIfInvalidActionResult({debug:t,console:e},n,s){const{action:i,extendedState:a,eventData:o,settings:r}=s,c=getFunctionName(i),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(i),params:{updatedExtendedState:a,eventData:o,settings:r},returned:n},notifyThrows(e,u),u}function throwIfInvalidGuardResult({debug:t,console:e},n,s){const i=getFunctionName(s.predicate),a=new Error(INVALID_PREDICATE_EXECUTED(i,PREDICATE_DESC));throw a.info={predicateName:i,params:s,returned:n},notifyThrows(e,a),a}function throwIfInvalidEntryActionResult({debug:t,console:e},n,s){const{action:i,extendedState:a,eventData:o,settings:r}=s,c=getFunctionName(i),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ENTRY_ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(i),params:{updatedExtendedState:a,eventData:o,settings:r},returned:n},notifyThrows(e,u),u}function isActions(t){return t&&"updates"in t&&"outputs"in t&&(t.outputs===NO_OUTPUT||Array.isArray(t.outputs))&&Array.isArray(t.updates)}function isEventStruct(t){let 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}const noDuplicatedStates={name:"noDuplicatedStates",shouldThrow:!1,predicate:(t,e)=>{const{getLabel:n}=objectTreeLenses,s={strategy:PRE_ORDER,seed:{duplicatedStates:[],statesHashMap:{}},visit:(t,e,s)=>{const{duplicatedStates:i,statesHashMap:a}=t,o=n(s),r=Object.keys(o)[0];return r in a?{duplicatedStates:i.concat(r),statesHashMap:a}:{duplicatedStates:i,statesHashMap:(a[r]="",a)}}},{duplicatedStates:i}=traverseObj(s,t.states);return{isFulfilled:0===i.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:i}}}}},noReservedStates={name:"noReservedStates",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:-1===Object.keys(n).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:n}}})},atLeastOneState={name:"atLeastOneState",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:Object.keys(n).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:n}}})},isInitialControlStateDeclared={name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:(t,e,{initTransition:n,statesType:s})=>{const{initialControlState:i,transitions:a}=t,o=Object.keys(s);return i?{isFulfilled:o.indexOf(i)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:i,declaredStates:o}}}:{isFulfilled:!0,blame:void 0}}},eventsAreStrings={name:"eventsAreStrings",shouldThrow:!1,predicate:(t,e)=>({isFulfilled:t.events.every(t=>"string"==typeof t),blame:{message:"Events must be an array of strings!",info:{events:t.events}}})},validInitialConfig={name:"validInitialConfig",shouldThrow:!1,predicate:(t,e,{initTransition:n})=>{const{initialControlState:s}=t;return n&&s?{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:s,initTransition:n}}}:n||s?{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:s,initTransition:n}}}}},validInitialTransition={name:"validInitialTransition",shouldThrow:!1,predicate:(t,e,{initTransition:n})=>{const{initialControlState:s,transitions:i}=t,a=i.reduce((t,e)=>(e.from===INIT_STATE&&t.push(e),t),[]);return{isFulfilled:s&&!n||!s&&n&&1===a.length&&n.event===INIT_EVENT&&(isInconditionalTransition(n)||areCconditionalTransitions(n)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:n,initTransitions:a,initialControlState:s}}}}},initEventOnlyInCompoundStates={name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).filter(t=>!s[t]).map(t=>({[t]:n[t]&&n[t][INIT_EVENT]})).filter(t=>Object.values(t)[0]);return{isFulfilled:0===a.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:a}}}}},validInitialTransitionForCompoundState={name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).filter(t=>s[t]),o=a.map(t=>n[t]&&n[t][INIT_EVENT]),r=o.every(Boolean);if(!r)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:a.map(t=>({[t]:!(!n[t]||!n[t][INIT_EVENT])}))}}};const c=r&&o.every(t=>{const{guards:e,to:n}=t;return!e&&"string"==typeof n});return c?c&&o.every(t=>{const{from:e,to:n}=t;return e!==n&&i[n]&&i[n].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:o}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must be inconditional and the associated target control state cannot be a history pseudo-state. Cf. log",info:{entryTransitions:o}}}}},validEventLessTransitions={name:"validEventLessTransitions",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).map(t=>({[t]:n[t]&&"undefined"in n[t]&&1!==Object.keys(n[t]).length})).filter(t=>void 0!==Object.values(t)[0]&&Object.values(t)[0]);return{isFulfilled:0===a.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:a}}}}},allStateTransitionsOnOneSingleRow={name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n})=>{const s=Object.keys(n).reduce((t,e)=>{const s=Object.keys(n[e]).filter(t=>n[e][t].length>1);return s.length>0&&(t[e]=s),t},{});return{isFulfilled:0===Object.keys(s).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:s}}}}},noConflictingTransitionsWithAncestorState={name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,eventTransitionsMaps:s,ancestorMap:i})=>{const a=Object.keys(s).reduce((t,e)=>{const n=Object.keys(s[e]),a=n.filter(t=>t!==INIT_STATE).map(t=>i[t]&&{[t]:i[t].find(t=>n.indexOf(t)>-1)}).filter(t=>t&&Object.values(t).filter(Boolean).length>0);return a.length>0&&(t[e]=a),t},{});return{isFulfilled:0===Object.keys(a).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:a}}}}},isHistoryStatesTargetStates={name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:(t,e,{})=>{const n=t.transitions.reduce((t,e)=>isHistoryControlState(e.from)?t.concat(e):t,[]);return{isFulfilled:0===Object.keys(n).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:n}}}}},isHistoryStatesCompoundStates={name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,statesType:s})=>{const i=Object.keys(n).map(t=>{if(t===INIT_STATE)return[];return Object.keys(n[t]).reduce((e,i)=>{const a=n[t][i][0],{guards:o,to:r}=a;return o?o.reduce((t,e)=>{const{to:n}=e;return isHistoryControlState(n)&&!s[getHistoryUnderlyingState(n)]?t.concat(a):t},e):isHistoryControlState(r)&&!s[getHistoryUnderlyingState(r)]?e.concat(a):e},[])}).reduce((t,e)=>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:(t,e,{historyStatesMap:n,statesType:s})=>{const i=Array.from(n.entries()).map(([t,e])=>!(t in s)&&{historyState:t,flatTransitions:e}).filter(Boolean),a=Object.keys(i).length;return{isFulfilled:0===a,blame:{message:`Found ${a} 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){const{from:e,event:n,guards:s,to:i,action:a}=t;return void 0===s&&i&&isControlState(e)&&isEvent(n)&&isControlState(i)&&isActionFactory(a)}function isValidGuard(t){const{to:e,predicate:n,action:s}=t;return e&&isControlState(e)&&isFunction(n)&&isActionFactory(s)}function areCconditionalTransitions(t){const{from:e,event:n,guards:s,to:i}=t;return s&&Array.isArray(s)&&s.length>0&&!i&&isControlState(e)&&isEvent(n)&&s.every(isValidGuard)}const isValidFsmDef={name:"isValidFsmDef",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n,states:s,events:i,initialExtendedState:a}=t,o=n&&Array.isArray(n),r=s&&"object"==typeof s,c=i&&Array.isArray(i);return o?r?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:s}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:n}}}}},haveTransitionsValidTypes={name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n}=t,s=n.map((t,e)=>!isInconditionalTransition(t)&&!areCconditionalTransitions(t)&&{transition:t,index:e}).filter(Boolean),i=Object.keys(s).length;return{isFulfilled:0===i,blame:{message:`Found ${i} transitions with invalid format! Check logs for more details.`,info:{wrongTransitions:s,transitions:n}}}}},areEventsDeclared={name:"areEventsDeclared",shouldThrow:!1,predicate:(t,e,{eventTransitionsMaps:n})=>{const s=Object.keys(n),i=t.events,a=i.map(t=>-1===s.indexOf(t)&&t).filter(Boolean),o=s.map(t=>-1===i.indexOf(t)&&t).filter(Boolean).filter(t=>t!==INIT_EVENT);return{isFulfilled:0===a.length&&0===o.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:a,eventsNotDeclaredButTriggeringTransitions:o}}}}},areStatesDeclared={name:"areStatesDeclared",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,targetStatesMap:s,statesType:i})=>{const a=Object.keys(n),o=Array.from(s.keys()),r=Object.keys([a,o].reduce((t,e)=>(e.forEach(e=>t[e]=!0),t),{})),c=Object.keys(i),u=c.map(t=>-1===r.indexOf(t)&&t).filter(Boolean),l=r.map(t=>t!==INIT_STATE&&-1===c.indexOf(t)&&t).filter(Boolean);return{isFulfilled:0===u.length&&0===u.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:u,statesNotDeclaredButTriggeringTransitions:l}}}}},isValidSettings={name:"isValidSettings",shouldThrow:!1,predicate:t=>({isFulfilled:!0,blame:void 0})},isInitialStateOriginState={name:"isInitialStateOriginState",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n})=>Array.from(n.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(n.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}},isValidSelfTransition={name:"isValidSelfTransition",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n,statesType:s})=>{const i=Array.from(n.keys()).map(t=>{return n.get(t).map(e=>{const{from:n,event:i}=e;if(t in s&&!s[t]&&n&&n===t&&!i)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(t=>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={computed:(t,e)=>({statesType:getStatesType(t.states),initTransition:findInitTransition(t.transitions),statesTransitionsMap:getStatesTransitionsMap(t.transitions),statesTransitionsMaps:getStatesTransitionsMaps(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){const e=t.description;return function(...n){const s=[],i=t.computed.apply(null,n);return{isFulfilled:t.contracts.reduce((t,a)=>{const{name:o,predicate:r,shouldThrow:c}=a,u=n.concat(i),{isFulfilled:l,blame:d}=r.apply(null,u),f=`${e} FAILS ${o}!`,{message:T,info:p}=d||{};if(l)return t;if(s.push({name:o,message:T,info:p}),console.error(f),console.error([o,T].join(": ")),console.debug("Supporting error data:",p),c)throw new Error([f,"check console for information!"].join("\n"));return!1},!0),failingContracts:s}}}const fsmContractChecker=(t,e,n)=>makeContractHandler(n)(t,e),alwaysTrue=()=>!0;function build_event_enum(t){return(t=t.reduce?t:Array.prototype.slice.call(arguments)).push(INIT_EVENT),t.reduce(function(t,e){return t[e]=e,t},{})}function build_nested_state_structure(t){const e="State";let n={},s={};function i(){}return t={nok:t},i.prototype={current_state_name:INIT_STATE},n[INIT_STATE]=new i,n[STATE_PROTOTYPE_NAME]=new i,function t(i,a){keys(i).forEach(function(o){const r=i[o];if(n[o]=new a,n[o].name=o,n[o].parent_name=get_fn_name(a),n[o].root_name=e,"object"==typeof r){s[o]=!0;const e=function(){};e.displayName=o,e.prototype=n[o],t(r,e)}})}(t,i),{hash_states:n,is_group_state:s}}function build_state_enum(t){let e={history:{}};return e.NOK=INIT_STATE,function t(n){keys(n).forEach(function(s){const i=n[s];e[s]=s,"object"==typeof i&&t(i)})}(t),e}function normalizeTransitions(t){const{initialControlState:e,transitions:n}=t,s=findInitTransition(n);return e?n.concat([{from:INIT_STATE,event:INIT_EVENT,to:e,action:ACTION_IDENTITY}]):s?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){const{states:n,events:s,initialExtendedState:i,updateState:a}=t,{debug:o}=e||{},r=o&&o.checkContracts||void 0;let c=o&&o.console?o.console:emptyConsole;if(r){const{failingContracts:n}=fsmContractChecker(t,e,r);if(n.length>0)throw new Error("createStateMachine: called with wrong parameters! Cf. logs for failing contracts.")}const u=tryCatchMachineFn(UPDATE_STATE_FN_DESC,a,["extendedState, updates"]),l=build_event_enum(s),d=normalizeTransitions(t),f=build_nested_state_structure(n);let T=i;const{stateList:p,stateAncestors:m}=computeHistoryMaps(n);let h=initHistoryDataStructure(p),g={},y={};const _=f.is_group_state;let E=f.hash_states;function S(t,e){var n,s;c.debug("send event",t),n=isEventStruct,s=[t],r&&assert(n,s);const i=keys(t)[0],a=t[i],u=E[INIT_STATE].current_state_name;return e&&i===INIT_EVENT&&u!==INIT_STATE?(c.warn("The external event INIT_EVENT can only be sent when starting the machine!"),NO_OUTPUT):function(t,e,n,s){const i=t[INIT_STATE].current_state_name,a=t[i][e];if(a){c.log("found event handler!"),c.info("WHEN EVENT ",e);const{stop:r,outputs:u}=a(s,n,i);o&&!r&&c.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");const l=arrayizeOutput(u),d=t[INIT_STATE].current_state_name;if(y[d]&&d!==i){const t=g[d]?INIT_EVENT:AUTO_EVENT;return[].concat(l).concat(S({[t]:n},!1))}return l}return c.warn(`There is no transition associated to the event |${e}| in state |${i}|!`),NO_OUTPUT}(f.hash_states,i,a,T)}return d.forEach(function(t){let{from:n,to:s,action:i,event:r,guards:d}=t;d||(d=[{predicate:alwaysTrue,to:s,action:i}]),r===INIT_EVENT&&(g[n]=!0);let f=E[n];if(r&&!(r in l))throw`unknown event ${r} found in state machine definition!`;r||(r=AUTO_EVENT,y[n]=!0),_[n]&&g[n]&&(y[n]=!0),f[r]=d.reduce((t,s,i)=>{const r=s.action||ACTION_IDENTITY,l=r.name||r.displayName,d=function(t,e){let s="";const d=function(d,f,p){n=p||n;const y=t.predicate,_=y||alwaysTrue,S=!y||tryCatchMachineFn(PREDICATE_DESC,_,["extendedState","eventData","settings"])(d,f,e),O=t.to;if(s=_?"_checking_condition_"+i:"",handleFnExecError({debug:o,console:c},{predicate:t.predicate,extendedState:d,eventData:f,settings:e},S,isBoolean,notifyAndRethrow,throwIfInvalidGuardResult),S){c.info("IN STATE ",n),y&&c.info(`CASE: guard ${_.name} for transition is fulfilled`),!y&&c.info("CASE: unguarded transition"),c.info("THEN : we execute the action "+l);const t=tryCatchMachineFn(ACTION_FACTORY_DESC,r,["extendedState","eventData","settings"])(d,f,e);handleFnExecError({debug:o,console:c},{action:r,extendedState:d,eventData:f,settings:e},t,isActions,notifyAndRethrow,throwIfInvalidActionResult);const{updates:s,outputs:i}=t;!function(t,e,n){const s=n[t].name;h=updateHistory(h,m,s),c.info("left state",wrap(t))}(n,0,E);const p=u(d,s);handleFnExecError({debug:o,console:c},{updateStateFn:a,extendedState:d,updates:s},p,alwaysTrue,notifyAndRethrow,noop),T=p;const S=function(t,e,n){let s,i;if(isHistoryControlState(t)){const e=t.deep?DEEP:t.shallow?SHALLOW:void 0,a=t[e];o&&c&&!g[a]&&c.warn("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"),i=h[e][a]||a,s=n[i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";s=n[t],i=s.name}return n[INIT_STATE].current_state_name=i,o&&c.info("AND TRANSITION TO STATE",i),i}(O,0,E);return c.info("ENTERING NEXT STATE: ",S),isError(p)&&c.error("with error: ",p),isError(p)||c.info("with extended state: ",T),{stop:!0,outputs:i}}return{stop:!1,outputs:NO_OUTPUT}};return d.displayName=n+s,d}(s,e);return function(e,n,s){const i=t(e,n,s);return i.stop?i:d(e,n,s)}},function(){return{stop:!1,outputs:NO_OUTPUT}})}),S({[INIT_EVENT]:i},!0),function(t){return S(t,!0)}}function makeWebComponentFromFsm({name:t,eventHandler:e,fsm:n,commandHandlers:s,effectHandlers:i,options:a}){return customElements.define(t,class extends HTMLElement{constructor(){if(t.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";super();const o=this;this.eventSubject=e,this.options=Object.assign({},a);const r=this.options.NO_ACTION||NO_OUTPUT;this.eventSubject.subscribe({next:t=>{const e=n(t);e!==r&&e.forEach(t=>{if(t===r)return;const{command:e,params:n}=t;s[e](this.eventSubject.next,n,i,o)})}})}static get observedAttributes(){return[]}connectedCallback(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}disconnectedCallback(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}attributeChangedCallback(t,e,n){this.constructor(),this.connectedCallback()}})}function makeNamedActionsFactory(t){return Object.keys(t).reduce((e,n)=>{const s=t[n];return s.displayName=n,e[n]=s,e},{})}function mergeOutputsFn(t){return t.reduce((t,e)=>t.concat(e),[])}function decorateWithEntryActions(t,e,n){if(!e)return t;const{transitions:s,states:i,initialExtendedState:a,initialControlState:o,events:r,updateState:c,settings:u}=t,l=getFsmStateList(i),d=Object.keys(e).every(t=>null!=l[t]),f=n||mergeOutputsFn;if(d){return{initialExtendedState:a,initialControlState:o,states:i,events:r,transitions:mapOverTransitionsActions((t,n,s,i)=>{const{to:a}=n,o=e[a];return o?decorateWithExitAction(t,o,f,c):t},s),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,s){const i=function(i,a,o){const{debug:r}=o,c=tryCatchMachineFn(ENTRY_ACTION_FACTORY_DESC,e,["extendedState","eventData","settings"]),u=t(i,a,o),l=u.updates,d=tryCatchMachineFn(UPDATE_STATE_FN_DESC,s,["extendedState, updates"])(i,l);handleFnExecError({debug:r,console:console},{updateStateFn:s,extendedState:i,actionUpdate:l},d,alwaysTrue,notifyAndRethrow,noop);const f=d,T=c(f,a,o);if(!handleFnExecError({debug:r,console:console},{action:e,extendedState:f,eventData:a,settings:o},T,isActions,notifyAndRethrow,throwIfInvalidEntryActionResult))return{updates:[].concat(l,T.updates),outputs:n([u.outputs,T.outputs])}};return i.displayName=`Entry_Action_After_${getFunctionName(t)}`,i}function traceFSM(t,e){const{initialExtendedState:n,initialControlState:s,events:i,states:a,transitions:o,updateState:r}=e;return{initialExtendedState:n,initialControlState:s,events:i,states:a,updateState:r,transitions:mapOverTransitionsActions((t,e,n,s)=>(function(i,a,o){const{from:c,event:u,to:l,predicate:d}=e,f=tryCatchMachineFn(ACTION_FACTORY_DESC,t,["extendedState","eventData","settings"])(i,a,o),{outputs:T,updates:p}=f;return{updates:p,outputs:[{outputs:T,updates:p,extendedState:i,newExtendedState:tryCatchMachineFn(UPDATE_STATE_FN_DESC,r,["extendedState, updates"])(i,p||[]),controlState:c,event:{eventLabel:u,eventData:a},settings:o,targetControlState:l,predicate:d,actionFactory:t,guardIndex:n,transitionIndex:s}]}}),o)}}function makeHistoryStates(t){const e=Object.keys(getFsmStateList(t));return(t,n)=>{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{[t]:n,type:history_symbol}}}function historyState(t,e){return{[t]:e}}function generateStatePlantUmlHeader(t,e){return e?`state "${e}" as ${t} <<NoContent>>`:`state "${getDisplayName(t)}" as ${t} <<NoContent>>`}function toPlantUml(t,e){const{states:n,transitions:s}=t,{getChildren:i,constructTree:a,getLabel:o}=objectTreeLenses,r=t=>t.join(SEP),c=postOrderTraverseTree(objectTreeLenses,{seed:()=>Map,visit:(t,e,n)=>{const{path:a}=e.get(n),c=o(n),u=stateToPlantUML(Object.keys(c)[0],times$1(e=>t.get(r(a.concat(e))),((t,e)=>i(t,e).length)(n,e)),s);return t.set(r(a),u),t}},{[INIT_STATE]:n}),u=c.get("0");return c.clear(),u}function stateToPlantUML(t,e,n){return[`${generateStatePlantUmlHeader(t,"")} {`,e.join("\n"),format_history_states(t,n),format_entry_transitions(t,n),"}",translate_transitions(t,n)].filter(t=>"\n"!==t&&""!==t).join("\n")}function format_history_states(t,e){const n=e.reduce((e,n)=>{return get_all_transitions(n).filter(is_history_transition).filter(is_to_history_control_state_of(t)).reduce((t,e)=>(t[format_history_transition_state_name(e)]=void 0,t),e)},{});return Object.keys(n).map(t=>`${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(e=>{return get_all_transitions(e).filter(is_from_control_state(t)).filter(t=>!is_entry_transition(t)).filter(t=>!is_history_transition(t)).map(({from:t,event:e,predicate:n,to:s,action:i})=>[t,TRANSITION_SYMBOL,s,TRANSITION_LABEL_START_SYMBOL,format_transition_label(e,n,i)].join(" ")).join("\n")}).filter(Boolean).join("\n")}function format_entry_transitions(t,e){return e.reduce((e,n)=>{return get_all_transitions(n).filter(is_entry_transition).filter(is_from_control_state(t)).reduce((t,e)=>{const{from:n,to:s,predicate:i,action:a}=e;return t.push(`[*] ${TRANSITION_SYMBOL} ${s} ${TRANSITION_LABEL_START_SYMBOL} ${format_transition_label("",i,a)}`),t},e)},[]).join("\n")}function format_history_transitions(t,e){return e.map(e=>{return get_all_transitions(e).filter(is_from_control_state(t)).filter(is_history_transition).map(({from:t,event:e,predicate:n,to:s,action:i})=>[t,TRANSITION_SYMBOL,format_history_transition_state_name({from:t,to:s}),TRANSITION_LABEL_START_SYMBOL,format_transition_label(e,n,i)].join(" ")).join("\n")}).filter(Boolean).join("\n")}function toDagreVisualizerFormat(t){const{states:e,transitions:n}=t,{getLabel:s,getChildren:i}=objectTreeLenses,{constructTree:a}=arrayTreeLenses,o=t=>t.join(SEP),r=postOrderTraverseTree(objectTreeLenses,{seed:()=>Map,visit:(t,e,n)=>{const{path:r}=e.get(n),c=s(n),u=Object.keys(c)[0],l=times$1(e=>t.get(o(r.concat(e))),((t,e)=>i(t,e).length)(n,e));return t.set(o(r),a(u,l)),t}},{[INIT_STATE]:e}).get("0"),c=n.map(t=>{const{from:e,to:n,event:s,guards:i,action:a}=t;if(i){return{from:e,event:s,guards:i.map(t=>{const{predicate:e,to:n,action:s}=t;return{predicate:e.name,to:n,action:s.name}})}}return{from:e,to:n,event:s,action:a.name||"no action name?"}});return JSON.stringify({states:r,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,noop,emptyConsole,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,getStatesTransitionsMaps,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};
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 _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=null,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";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),y=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),y=l(y,d,t),updateVisitInTraversalState(d,t)}return d.clear(),y}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 emptyTrace,noop=function(){},emptyConsole={log:noop,warn:noop,info:noop,debug:noop,error:noop,trace: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 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 getStatesTransitionsMaps(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){var e;if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var n=objectTreeLenses.getLabel,r=traverseObj({strategy:PRE_ORDER,seed:{stateList:[],stateAncestors:(e={},_defineProperty(e,DEEP,{}),_defineProperty(e,SHALLOW,{}),e)},visit:function(t,e,r){var a=n(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=e.get(r).path;e.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)e.set(JSON.stringify(s),INIT_STATE);else{var c=e.get(JSON.stringify(s));t.stateAncestors[SHALLOW][i]=[c];var u=o.reduce(function(t,n){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=e.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[DEEP][i]=u}return t}},t);return{stateList:r.stateList,stateAncestors:r.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:([SHALLOW,DEEP].forEach(function(r){(e[r][n]||[]).forEach(function(e){t[r][e]=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.apply(null,e);if(!0!==n){var r=n.info;throw console.error("ERROR: failed contract ".concat(t.name||"",". ").concat(r?"Error info:":""),n.info),n}}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))&&Array.isArray(t.updates)}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]}}var 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&&"string"==typeof n});return u?u&&s.every(function(t){var e=t.from,n=t.to;return e!==n&&i[n]&&i[n].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 be inconditional and the associated target control state cannot be 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.statesTransitionsMaps,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.statesTransitionsMaps;var r=n.eventTransitionsMaps,a=n.ancestorMap,i=Object.keys(r).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.statesTransitionsMaps,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});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.statesTransitionsMaps,a=n.targetStatesMap,i=n.statesType,o=Object.keys(r),s=Array.from(a.keys()),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===l.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={computed:function(t,e){return{statesType:getStatesType(t.states),initTransition:findInitTransition(t.transitions),statesTransitionsMap:getStatesTransitionsMap(t.transitions),statesTransitionsMaps:getStatesTransitionsMaps(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.console||emptyConsole,r=e&&e.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.computed.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,"!"),y=T||{},m=y.message,_=y.info;if(d)return t;if(s.push({name:r,message:m,info:_}),n.error(p),n.error([r,m].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)},alwaysTrue=function(){return!0};function build_event_enum(t){return(t=t.reduce?t:Array.prototype.slice.call(arguments)).push(INIT_EVENT),t.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||{}).debug,s=o&&o.checkContracts||void 0,c=o&&o.console?o.console:emptyConsole;o&&o.trace&&o.trace;if(s&&fsmContractChecker(t,e,s).failingContracts.length>0)throw new Error("createStateMachine: called with wrong parameters! Cf. logs for failing contracts.");var u=tryCatchMachineFn(UPDATE_STATE_FN_DESC,i,["extendedState, updates"]),l=build_event_enum(r),f=normalizeTransitions(t),d=build_nested_state_structure(n),T=a,p=computeHistoryMaps(n),y=p.stateList,m=p.stateAncestors,_=initHistoryDataStructure(y),h={},v={},g=d.is_group_state,E=d.hash_states;function S(t,e){var n,r;c.debug("send event",t),n=isEventStruct,r=[t],s&&assert(n,r);var a=destructureEvent(t),i=a.eventName,u=a.eventData,l=E[INIT_STATE].current_state_name;return e&&i===INIT_EVENT&&l!==INIT_STATE?(c.warn("The external event INIT_EVENT can only be sent when starting the machine!"),NO_OUTPUT):function(t,e,n,r){var a=t[INIT_STATE].current_state_name,i=t[a][e];if(i){c.log("found event handler!"),c.info("WHEN EVENT ",e);var s=i(r,n,a),u=s.stop,l=s.outputs;o&&!u&&c.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var f=arrayizeOutput(l),d=t[INIT_STATE].current_state_name;if(v[d]&&d!==a){var T=h[d]?INIT_EVENT:AUTO_EVENT;return[].concat(f).concat(S(_defineProperty({},T,n),!1))}return f}return c.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(a,"|!")),NO_OUTPUT}(d.hash_states,i,u,T)}return f.forEach(function(t){var n=t.from,r=t.to,a=t.action,s=t.event,f=t.guards;f||(f=[{predicate:alwaysTrue,to:r,action:a}]),s===INIT_EVENT&&(h[n]=!0);var d=E[n];if(s&&!(s in l))throw"unknown event ".concat(s," found in state machine definition!");s||(s=AUTO_EVENT,v[n]=!0),g[n]&&h[n]&&(v[n]=!0),d[s]=f.reduce(function(t,r,a){var s=r.action||ACTION_IDENTITY,l=s.name||s.displayName,f=function(t,e){var r="",f=function(f,d,p){n=p||n;var y=t.predicate,v=y||alwaysTrue,g=!y||tryCatchMachineFn(PREDICATE_DESC,v,["extendedState","eventData","settings"])(f,d,e),S=t.to;if(r=v?"_checking_condition_"+a:"",handleFnExecError({debug:o,console:c},{predicate:t.predicate,extendedState:f,eventData:d,settings:e},g,isBoolean,notifyAndRethrow,throwIfInvalidGuardResult),g){c.info("IN STATE ",n),y&&c.info("CASE: guard ".concat(v.name," for transition is fulfilled")),!y&&c.info("CASE: unguarded transition"),c.info("THEN : we execute the action "+l);var O=tryCatchMachineFn(ACTION_FACTORY_DESC,s,["extendedState","eventData","settings"])(f,d,e);handleFnExecError({debug:o,console:c},{action:s,extendedState:f,eventData:d,settings:e},O,isActions,notifyAndRethrow,throwIfInvalidActionResult);var b=O.updates,A=O.outputs;!function(t,e,n){var r=n[t].name;_=updateHistory(_,m,r),c.info("left state",wrap(t))}(n,0,E);var N=u(f,b);handleFnExecError({debug:o,console:c},{updateStateFn:i,extendedState:f,updates:b},N,alwaysTrue,notifyAndRethrow,noop),T=N;var I=function(t,e,n){var r,a;if(isHistoryControlState(t)){var i=t.deep?DEEP:t.shallow?SHALLOW:void 0,s=t[i];o&&c&&!h[s]&&c.warn("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"),a=_[i][s]||s,r=n[a]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t],a=r.name}return n[INIT_STATE].current_state_name=a,o&&c.info("AND TRANSITION TO STATE",a),a}(S,0,E);return c.info("ENTERING NEXT STATE: ",I),isError(N)&&c.error("with error: ",N),isError(N)||c.info("with extended state: ",T),{stop:!0,outputs:A}}return{stop:!1,outputs:NO_OUTPUT}};return f.displayName=n+r,f}(r,e);return function(e,n,r){var a=t(e,n,r);return a.stop?a:f(e,n,r)}},function(){return{stop:!1,outputs:NO_OUTPUT}})}),S(_defineProperty({},INIT_EVENT,a),!0),function(t){return S(t,!0)}}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(_assertThisInitialized(t=_possibleConstructorReturn(this,_getPrototypeOf(s).call(this))));t.eventSubject=n,t.options=Object.assign({},o);var u=t.options.NO_ACTION||NO_OUTPUT;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,noop,emptyConsole,noop as emptyTrace,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,getStatesTransitionsMaps,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};
//# 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";const e=".",n="--\x3e",s=":",o="H",i="history.",a="nok",r="init",c="auto",u="State",l=[],d=null,f=function(){return{outputs:d,updates:l}},p={},m="shallow",h="deep",g="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.",y=(t,e)=>`Exception thrown when executing ${e} ${t||""}`,b=(t,e)=>`${y(t,e)}\nThe ${e} returned a value which is not an action.`,v=(t,e)=>`${y(t,e)}\nThe ${e} returned a value which is not a boolean.`,T="action factory",S="(decorating) entry action",E="update state function",O="predicate",w=[0],A="PRE_ORDER";function _(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function C(t,e){return Object.assign({},t,e)}function j(t,e,n){n.forEach((n,s)=>{const o=t.get(e),i=t.get(n),a=i&&i.path;t.set(n,C(i,{isAdded:!0,isVisited:!1,path:a||o.path.concat(s)}))})}function F(t,e){t.set(e,C(t.get(e),{isVisited:!0}))}function N(t,e){const{store:n,lenses:s,traverse:o}=t,{empty:i,add:a,takeAndRemoveOne:r,isEmpty:c}=n,{getChildren:u}=s,{visit:l,seed:d}=o,f=new Map,p="function"==typeof d?new(d()):_(d);let m="function"==typeof i?new(i()):_(i),h=p;for(a([e],m),f.set(e,{isAdded:!0,isVisited:!1,path:w});!c(m);){const t=r(m),e=u(f,t);a(e,m),j(f,t,e),h=l(h,f,t),F(f,t)}return f.clear(),h}function k(t,e,n){const{getChildren:s}=t;return N({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>s(e)},traverse:e},n)}function x(t,e,n){const{getChildren:s}=t;return N({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>s(e)},traverse:e},n)}function M(t,e,n){const{getChildren:s}=t,{seed:o,visit:i}=e,a=(t,e)=>e.get(t).isVisited||((t,e)=>0===s(t,e).length)(t,e);return N({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>a(e,t)?[]:s(e,t).concat([e])},traverse:{seed:o,visit:(t,e,n)=>a(n,e)?i(t,e,n):t}},n)}const I={isLeafLabel:function(t){return 0===I.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 R(t,e){const n={root:e},{strategy:s,seed:o,visit:i}=t;return({BFS:k,PRE_ORDER:x,POST_ORDER:M}[s]||x)(I,{seed:o,visit:function(t,e,n){const{path:s}=e.get(n);return JSON.stringify(s)===JSON.stringify(w)?t:i(t,e,n)}},n)}const D={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},$=()=>{},L={log:$,warn:$,info:$,debug:$,error:$,trace:$};function H(t){return"boolean"==typeof t}function P(t){return"function"==typeof t}function B(t){return t&&"string"==typeof t||gt(t)}function U(t){return t&&"string"==typeof t}function V(t){return t&&"function"==typeof t}function W(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 Y(t){return["-",t,"-"].join("")}function J(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function X(t){return Object.keys(t)}function z(t){return t.to.startsWith(i)}function q(t){return t.event===r}function G(t){return function(e){return e.from===t}}function K(t){return function(e){return Q(t,e.to)}}function Q(t,e){return e.substring(i.length)===t}function Z(t,e,n){const s=t||"";return e&&n?`${s} [${e.name}] / ${n.name}`:e?`${s} [${e.name}]}`:n?`${s} / ${n.name}`:`${s}`}function tt({from:t,to:e}){return`${t}.${e.substring(i.length)}.${o}`}function et(t){const{from:e,event:n,guards:s}=t;return s?s.map(({predicate:t,to:s,action:o})=>({from:e,event:n,predicate:t,to:s,action:o})):[t]}function nt(t){return t.replace(/_/g," ")}function st(t){const{getLabel:e}=I;return R({strategy:A,seed:{},visit:(t,n,s)=>{const o=e(s);return t[Object.keys(o)[0]]="",t}},t)}function ot(t){const{getLabel:e,isLeafLabel:n}=I;return R({strategy:A,seed:{},visit:(t,s,o)=>{const i=e(o),a=Object.keys(i)[0];return n(i)?(t[a]=!1,t):(t[a]=!0,t)}},t)}function it(t){const{getLabel:e}=I;return R({strategy:A,seed:{},visit:(t,n,s)=>{const o=n.get(s).path.join("."),i=e(s);return t[Object.keys(i)[0]]=o,t}},t)}function at(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return gt(n)?t:(t[n]=t[n]||{},t[n][s]=e,t)},{})||{}}function rt(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return gt(n)?t:(t[n]=t[n]||{},t[n][s]=t[n][s]?t[n][s].concat(e):[e],t)},{})||{}}function ct(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return gt(n)?t:(t[s]=t[s]||{},t[s][n]=t[s][n]?t[s][n].concat(e):[e],t)},{})||{}}function ut(t){return mt((t,e,n,s)=>{const{from:o,event:i,to:a,action:r,predicate:c,gen:u}=e;if(gt(o)){const n=bt(o);t.set(n,(t.get(n)||[]).concat([e]))}else if(gt(a)){const n=bt(a);t.set(n,(t.get(n)||[]).concat([e]))}return t},new Map,t)||{}}function lt(t){return mt((t,e,n,s)=>{const{to:o}=e;return t.set(o,(t.get(o)||[]).concat([e])),t},new Map,t)||{}}function dt(t){const{getLabel:e,getChildren:n}=I;return R({strategy:A,seed:{},visit:(t,s,o)=>{const i=e(o),a=Object.keys(i)[0];return n(o).map(t=>Object.keys(e(t))[0]).forEach(e=>{t[e]=t[e]||[],t[e]=t[e].concat(a)}),t}},t)}function ft(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";const{getLabel:e,isLeafLabel:n}=I,s={strategy:A,seed:{stateList:[],stateAncestors:{[h]:{},[m]:{}}},visit:(t,n,s)=>{const o=e(s),i=Object.keys(o)[0];t.stateList=t.stateList.concat(i);const{path:r}=n.get(s);n.set(JSON.stringify(r),i);const c=r.slice(0,-1);if(1===c.length)n.set(JSON.stringify(c),a);else{const e=n.get(JSON.stringify(c));t.stateAncestors[m][i]=[e];const{ancestors:s}=r.reduce((t,e)=>{const s=t.path.slice(0,-1);if(t.path=s,s.length>1){const e=n.get(JSON.stringify(s));t.ancestors=t.ancestors.concat(e)}return t},{ancestors:[],path:r});t.stateAncestors[h][i]=s}return t}},{stateList:o,stateAncestors:i}=R(s,t);return{stateList:o,stateAncestors:i}}function pt(t,e){return mt(function(e,n,s,o){const{from:i,event:a,to:r,action:c,predicate:u}=n,l=t(c,n,s,o);return l.displayName=l.displayName||c&&(c.name||c.displayName||function(t,e,n,s,o){const i=o?o.name:"",a=i?`[${i}]`:"",r=t?t.name:"identity";return`${r||"unnamed action"}:${e}-${n}->${s} ${a}`}(c,i,a,r,u)),void 0===u?e.push({from:i,event:a,to:r,action:l}):0===s?e.push({from:i,event:a,guards:[{to:r,predicate:u,action:l}]}):e[e.length-1].guards.push({to:r,predicate:u,action:l}),e},[],e)}function mt(t,e,n){return n.reduce((e,n,s)=>{let{from:o,event:i,to:a,gen:r,action:c,guards:u}=n;return u||(u=r?[{to:a,action:c,gen:r,predicate:void 0}]:[{to:a,action:c,predicate:void 0}]),u.reduce((e,n,a)=>{const{to:r,action:c,gen:u,predicate:l}=n;return t(e,u?{from:o,event:i,to:r,action:c,predicate:l,gen:u}:{from:o,event:i,to:r,action:c,predicate:l},a,s)},e)},e)}function ht(t){return t===d?d:Array.isArray(t)?t:[t]}function gt(t){return"object"==typeof t&&(h in t||m in t)}function yt(t){return t[h]?h:m}function bt(t){return t[yt(t)]}function vt(t){const e=()=>t.reduce((t,e)=>(t[e]="",t),{});return{[h]:e(),[m]:e()}}function Tt(t,e){const{statesAdjacencyList:n}=t;return n[e]&&0!==n[e].length}function St(t,e,n){return n===a?t:([m,h].forEach(s=>{(e[s][n]||[]).forEach(e=>{t[s][e]=n})}),t)}function Et(t){return t.find(t=>t.from===a&&t.event===r)}function Ot(t,e){return function(...n){try{return t.apply(t,n)}catch(t){return e(t,n)}}}function wt(t,e,n=[]){return Ot(e,(s,o)=>{const i=new Error(s),a=At(e),r=y(a,t);i.probableCause=s.probableCause?[s.probableCause,r].join("\n"):r;const c={fnName:a,params:n.reduce((t,e,n)=>(t[e]=o[n],t),{})};return i.info=s.info?[].concat([s.info]).concat([c]):c,i})}function At(t){return t.name||t.displayName||"anonymous"}function _t(t,e){const n=t.apply(null,e);if(!0!==n){const e=n.info;throw console.error(`ERROR: failed contract ${t.name||""}. ${e?"Error info:":""}`,n.info),n}}function Ct(t,e){t.error(e),e.probableCause&&t.error(`Probable cause: ${e.probableCause}`),e.info&&t.error("ERROR: additional info",e.info)}function jt(t,e,n,s,o,i){const{debug:a,console:r}=t;return a&&n instanceof Error?(o({debug:a,console:r},n,e),!0):!(!a||s(n))&&(i({debug:a,console:r},n,e),!0)}function Ft({debug:t,console:e},n){throw Ct(e,n),n}function Nt({debug:t,console:e},n,s){const{action:o,extendedState:i,eventData:a,settings:r}=s,c=At(o),u=new Error(b(c,T));throw u.info={fnName:At(o),params:{updatedExtendedState:i,eventData:a,settings:r},returned:n},Ct(e,u),u}function kt({debug:t,console:e},n,s){const o=At(s.predicate),i=new Error(v(o,O));throw i.info={predicateName:o,params:s,returned:n},Ct(e,i),i}function xt({debug:t,console:e},n,s){const{action:o,extendedState:i,eventData:a,settings:r}=s,c=At(o),u=new Error(b(c,S));throw u.info={fnName:At(o),params:{updatedExtendedState:i,eventData:a,settings:r},returned:n},Ct(e,u),u}function Mt(t){return t&&"updates"in t&&"outputs"in t&&(t.outputs===d||Array.isArray(t.outputs))&&Array.isArray(t.updates)}function It(t){let e;return t&&"object"==typeof t?Object.keys(t).length>1?(e=new Error(g)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:e=!0:(e=new Error(g)).info={event:t,cause:"not an object!"},e}function Rt(t){return t instanceof Error}function Dt(t){const{from:e,event:n,guards:s,to:o,action:i}=t;return void 0===s&&o&&B(e)&&U(n)&&B(o)&&V(i)}function $t(t){const{to:e,predicate:n,action:s}=t;return e&&B(e)&&P(n)&&V(s)}function Lt(t){const{from:e,event:n,guards:s,to:o}=t;return s&&Array.isArray(s)&&s.length>0&&!o&&B(e)&&U(n)&&s.every($t)}const Ht={computed:(t,e)=>({statesType:ot(t.states),initTransition:Et(t.transitions),statesTransitionsMap:at(t.transitions),statesTransitionsMaps:rt(t.transitions),eventTransitionsMaps:ct(t.transitions),ancestorMap:dt(t.states),statesPath:it(t.states),historyStatesMap:ut(t.transitions),targetStatesMap:lt(t.transitions)}),description:"FSM structure",contracts:[{name:"isValidFsmDef",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n,states:s,events:o,initialExtendedState:i}=t,a=n&&Array.isArray(n),r=s&&"object"==typeof s,c=o&&Array.isArray(o);return a?r?c?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:o}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:s}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:n}}}}},{name:"isValidSettings",shouldThrow:!1,predicate:t=>({isFulfilled:!0,blame:void 0})},{name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:(t,e,{initTransition:n,statesType:s})=>{const{initialControlState:o,transitions:i}=t,a=Object.keys(s);return o?{isFulfilled:a.indexOf(o)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:o,declaredStates:a}}}:{isFulfilled:!0,blame:void 0}}},{name:"isInitialStateOriginState",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n})=>Array.from(n.keys()).indexOf(a)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(n.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}},{name:"eventsAreStrings",shouldThrow:!1,predicate:(t,e)=>({isFulfilled:t.events.every(t=>"string"==typeof t),blame:{message:"Events must be an array of strings!",info:{events:t.events}}})},{name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n}=t,s=n.map((t,e)=>!Dt(t)&&!Lt(t)&&{transition:t,index:e}).filter(Boolean),o=Object.keys(s).length;return{isFulfilled:0===o,blame:{message:`Found ${o} transitions with invalid format! Check logs for more details.`,info:{wrongTransitions:s,transitions:n}}}}},{name:"noDuplicatedStates",shouldThrow:!1,predicate:(t,e)=>{const{getLabel:n}=I,s={strategy:A,seed:{duplicatedStates:[],statesHashMap:{}},visit:(t,e,s)=>{const{duplicatedStates:o,statesHashMap:i}=t,a=n(s),r=Object.keys(a)[0];return r in i?{duplicatedStates:o.concat(r),statesHashMap:i}:{duplicatedStates:o,statesHashMap:(i[r]="",i)}}},{duplicatedStates:o}=R(s,t.states);return{isFulfilled:0===o.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:o}}}}},{name:"noReservedStates",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:-1===Object.keys(n).indexOf(a),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[a],statesType:n}}})},{name:"atLeastOneState",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:Object.keys(n).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:n}}})},{name:"areEventsDeclared",shouldThrow:!1,predicate:(t,e,{eventTransitionsMaps:n})=>{const s=Object.keys(n),o=t.events,i=o.map(t=>-1===s.indexOf(t)&&t).filter(Boolean),a=s.map(t=>-1===o.indexOf(t)&&t).filter(Boolean).filter(t=>t!==r);return{isFulfilled:0===i.length&&0===a.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:i,eventsNotDeclaredButTriggeringTransitions:a}}}}},{name:"areStatesDeclared",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,targetStatesMap:s,statesType:o})=>{const i=Object.keys(n),r=Array.from(s.keys()),c=Object.keys([i,r].reduce((t,e)=>(e.forEach(e=>t[e]=!0),t),{})),u=Object.keys(o),l=u.map(t=>-1===c.indexOf(t)&&t).filter(Boolean),d=c.map(t=>t!==a&&-1===u.indexOf(t)&&t).filter(Boolean);return{isFulfilled:0===l.length&&0===l.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:(t,e,{initTransition:n})=>{const{initialControlState:s}=t;return n&&s?{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:s,initTransition:n}}}:n||s?{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:s,initTransition:n}}}}},{name:"validInitialTransition",shouldThrow:!1,predicate:(t,e,{initTransition:n})=>{const{initialControlState:s,transitions:o}=t,i=o.reduce((t,e)=>(e.from===a&&t.push(e),t),[]);return{isFulfilled:s&&!n||!s&&n&&1===i.length&&n.event===r&&(Dt(n)||Lt(n)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:n,initTransitions:i,initialControlState:s}}}}},{name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:o})=>{const i=Object.keys(s).filter(t=>!s[t]).map(t=>({[t]:n[t]&&n[t][r]})).filter(t=>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}}}}},{name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:o})=>{const i=Object.keys(s).filter(t=>s[t]),a=i.map(t=>n[t]&&n[t][r]),c=a.every(Boolean);if(!c)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:i.map(t=>({[t]:!(!n[t]||!n[t][r])}))}}};const u=c&&a.every(t=>{const{guards:e,to:n}=t;return!e&&"string"==typeof n});return u?u&&a.every(t=>{const{from:e,to:n}=t;return e!==n&&o[n]&&o[n].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:a}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must be inconditional and the associated target control state cannot be a history pseudo-state. Cf. log",info:{entryTransitions:a}}}}},{name:"validEventLessTransitions",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:o})=>{const i=Object.keys(s).map(t=>({[t]:n[t]&&"undefined"in n[t]&&1!==Object.keys(n[t]).length})).filter(t=>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}}}}},{name:"isValidSelfTransition",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n,statesType:s})=>{const o=Array.from(n.keys()).map(t=>{return n.get(t).map(e=>{const{from:n,event:o}=e;if(t in s&&!s[t]&&n&&n===t&&!o)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(t=>t.length>0);return{isFulfilled:0===o.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:o}}}}},{name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n})=>{const s=Object.keys(n).reduce((t,e)=>{const s=Object.keys(n[e]).filter(t=>n[e][t].length>1);return s.length>0&&(t[e]=s),t},{});return{isFulfilled:0===Object.keys(s).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:s}}}}},{name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,eventTransitionsMaps:s,ancestorMap:o})=>{const i=Object.keys(s).reduce((t,e)=>{const n=Object.keys(s[e]),i=n.filter(t=>t!==a).map(t=>o[t]&&{[t]:o[t].find(t=>n.indexOf(t)>-1)}).filter(t=>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}}}}},{name:"isHistoryStatesExisting",shouldThrow:!1,predicate:(t,e,{historyStatesMap:n,statesType:s})=>{const o=Array.from(n.entries()).map(([t,e])=>!(t in s)&&{historyState:t,flatTransitions:e}).filter(Boolean),i=Object.keys(o).length;return{isFulfilled:0===i,blame:{message:`Found ${i} history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition.`,info:{invalidTransitions:o,states:t.states}}}}},{name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:(t,e,{})=>{const n=t.transitions.reduce((t,e)=>gt(e.from)?t.concat(e):t,[]);return{isFulfilled:0===Object.keys(n).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:n}}}}},{name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,statesType:s})=>{const o=Object.keys(n).map(t=>{if(t===a)return[];return Object.keys(n[t]).reduce((e,o)=>{const i=n[t][o][0],{guards:a,to:r}=i;return a?a.reduce((t,e)=>{const{to:n}=e;return gt(n)&&!s[bt(n)]?t.concat(i):t},e):gt(r)&&!s[bt(r)]?e.concat(i):e},[])}).reduce((t,e)=>t.concat(e),[]);return{isFulfilled:0===Object.keys(o).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:o,states:t.states}}}}}]};const Pt=(t,e,n)=>(function(t){const e=t.description;return function(...n){const s=[],o=t.computed.apply(null,n);return{isFulfilled:t.contracts.reduce((t,i)=>{const{name:a,predicate:r,shouldThrow:c}=i,u=n.concat(o),{isFulfilled:l,blame:d}=r.apply(null,u),f=`${e} FAILS ${a}!`,{message:p,info:m}=d||{};if(l)return t;if(s.push({name:a,message:p,info:m}),console.error(f),console.error([a,p].join(": ")),console.debug("Supporting error data:",m),c)throw new Error([f,"check console for information!"].join("\n"));return!1},!0),failingContracts:s}}})(n)(t,e),Bt=()=>!0;function Ut(t){const{initialControlState:e,transitions:n}=t,s=Et(n);return e?n.concat([{from:a,event:r,to:e,action:f}]):s?n:void 0}function Vt(t,e){const{states:n,events:s,initialExtendedState:o,updateState:i}=t,{debug:l}=e||{},p=l&&l.checkContracts||void 0;let g=l&&l.console?l.console:L;if(p){const{failingContracts:n}=Pt(t,e,p);if(n.length>0)throw new Error("createStateMachine: called with wrong parameters! Cf. logs for failing contracts.")}const y=wt(E,i,["extendedState, updates"]),b=function(t){return(t=t.reduce?t:Array.prototype.slice.call(arguments)).push(r),t.reduce(function(t,e){return t[e]=e,t},{})}(s),v=Ut(t),S=function(t){const e="State";let n={},s={};function o(){}return t={nok:t},o.prototype={current_state_name:a},n[a]=new o,n[u]=new o,function t(o,i){X(o).forEach(function(a){const r=o[a];if(n[a]=new i,n[a].name=a,n[a].parent_name=W(i),n[a].root_name=e,"object"==typeof r){s[a]=!0;const e=function(){};e.displayName=a,e.prototype=n[a],t(r,e)}})}(t,o),{hash_states:n,is_group_state:s}}(n);let w=o;const{stateList:A,stateAncestors:_}=ft(n);let C=vt(A),j={},F={};const N=S.is_group_state;let k=S.hash_states;function x(t,e){var n,s;g.debug("send event",t),n=It,s=[t],p&&_t(n,s);const o=X(t)[0],i=t[o],u=k[a].current_state_name;return e&&o===r&&u!==a?(g.warn("The external event INIT_EVENT can only be sent when starting the machine!"),d):function(t,e,n,s){const o=t[a].current_state_name,i=t[o][e];if(i){g.log("found event handler!"),g.info("WHEN EVENT ",e);const{stop:u,outputs:d}=i(s,n,o);l&&!u&&g.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");const f=ht(d),p=t[a].current_state_name;if(F[p]&&p!==o){const t=j[p]?r:c;return[].concat(f).concat(x({[t]:n},!1))}return f}return g.warn(`There is no transition associated to the event |${e}| in state |${o}|!`),d}(S.hash_states,o,i,w)}return v.forEach(function(t){let{from:n,to:s,action:o,event:u,guards:p}=t;p||(p=[{predicate:Bt,to:s,action:o}]),u===r&&(j[n]=!0);let v=k[n];if(u&&!(u in b))throw`unknown event ${u} found in state machine definition!`;u||(u=c,F[n]=!0),N[n]&&j[n]&&(F[n]=!0),v[u]=p.reduce((t,s,o)=>{const r=s.action||f,c=r.name||r.displayName,u=function(t,e){let s="";const u=function(u,f,p){n=p||n;const b=t.predicate,v=b||Bt,S=!b||wt(O,v,["extendedState","eventData","settings"])(u,f,e),E=t.to;if(s=v?"_checking_condition_"+o:"",jt({debug:l,console:g},{predicate:t.predicate,extendedState:u,eventData:f,settings:e},S,H,Ft,kt),S){g.info("IN STATE ",n),b&&g.info(`CASE: guard ${v.name} for transition is fulfilled`),!b&&g.info("CASE: unguarded transition"),g.info("THEN : we execute the action "+c);const t=wt(T,r,["extendedState","eventData","settings"])(u,f,e);jt({debug:l,console:g},{action:r,extendedState:u,eventData:f,settings:e},t,Mt,Ft,Nt);const{updates:s,outputs:o}=t;!function(t,e,n){const s=n[t].name;C=St(C,_,s),g.info("left state",Y(t))}(n,0,k);const d=y(u,s);jt({debug:l,console:g},{updateStateFn:i,extendedState:u,updates:s},d,Bt,Ft,$),w=d;const p=function(t,e,n){let s,o;if(gt(t)){const e=t.deep?h:t.shallow?m:void 0,i=t[e];l&&g&&!j[i]&&g.warn("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"),o=C[e][i]||i,s=n[o]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";s=n[t],o=s.name}return n[a].current_state_name=o,l&&g.info("AND TRANSITION TO STATE",o),o}(E,0,k);return g.info("ENTERING NEXT STATE: ",p),Rt(d)&&g.error("with error: ",d),Rt(d)||g.info("with extended state: ",w),{stop:!0,outputs:o}}return{stop:!1,outputs:d}};return u.displayName=n+s,u}(s,e);return function(e,n,s){const o=t(e,n,s);return o.stop?o:u(e,n,s)}},function(){return{stop:!1,outputs:d}})}),x({[r]:o},!0),function(t){return x(t,!0)}}function Wt(t){return t.reduce((t,e)=>t.concat(e),[])}function Yt(t,e){return e?`state "${e}" as ${t} <<NoContent>>`:`state "${nt(t)}" as ${t} <<NoContent>>`}t.fsmContracts=Ht,t.build_state_enum=function(t){let e={history:{}};return e.NOK=a,function t(n){X(n).forEach(function(s){const o=n[s];e[s]=s,"object"==typeof o&&t(o)})}(t),e},t.normalizeTransitions=Ut,t.normalizeFsmDef=function(t){return Object.assign({},t,{transitions:Ut(t)})},t.create_state_machine=function(t,e){return Vt(t,e)},t.createStateMachine=Vt,t.makeWebComponentFromFsm=function({name:t,eventHandler:e,fsm:n,commandHandlers:s,effectHandlers:o,options:i}){return customElements.define(t,class extends HTMLElement{constructor(){if(t.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";super();const a=this;this.eventSubject=e,this.options=Object.assign({},i);const r=this.options.NO_ACTION||d;this.eventSubject.subscribe({next:t=>{const e=n(t);e!==r&&e.forEach(t=>{if(t===r)return;const{command:e,params:n}=t;s[e](this.eventSubject.next,n,o,a)})}})}static get observedAttributes(){return[]}connectedCallback(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}disconnectedCallback(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}attributeChangedCallback(t,e,n){this.constructor(),this.connectedCallback()}})},t.makeNamedActionsFactory=function(t){return Object.keys(t).reduce((e,n)=>{const s=t[n];return s.displayName=n,e[n]=s,e},{})},t.mergeOutputsFn=Wt,t.decorateWithEntryActions=function(t,e,n){if(!e)return t;const{transitions:s,states:o,initialExtendedState:i,initialControlState:a,events:r,updateState:c,settings:u}=t,l=st(o),d=Object.keys(e).every(t=>null!=l[t]),f=n||Wt;if(d)return{initialExtendedState:i,initialControlState:a,states:o,events:r,transitions:pt((t,n,s,o)=>{const{to:i}=n,a=e[i];return a?function(t,e,n,s){const o=function(o,i,a){const{debug:r}=a,c=wt(S,e,["extendedState","eventData","settings"]),u=t(o,i,a),l=u.updates,d=wt(E,s,["extendedState, updates"]),f=d(o,l);jt({debug:r,console:console},{updateStateFn:s,extendedState:o,actionUpdate:l},f,Bt,Ft,$);const p=f,m=c(p,i,a),h=jt({debug:r,console:console},{action:e,extendedState:p,eventData:i,settings:a},m,Mt,Ft,xt);if(!h)return{updates:[].concat(l,m.updates),outputs:n([u.outputs,m.outputs])}};return o.displayName=`Entry_Action_After_${At(t)}`,o}(t,a,f,c):t},s),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){const{initialExtendedState:n,initialControlState:s,events:o,states:i,transitions:a,updateState:r}=e;return{initialExtendedState:n,initialControlState:s,events:o,states:i,updateState:r,transitions:pt((t,e,n,s)=>(function(o,i,a){const{from:c,event:u,to:l,predicate:d}=e,f=wt(T,t,["extendedState","eventData","settings"])(o,i,a),{outputs:p,updates:m}=f;return{updates:m,outputs:[{outputs:p,updates:m,extendedState:o,newExtendedState:wt(E,r,["extendedState, updates"])(o,m||[]),controlState:c,event:{eventLabel:u,eventData:i},settings:a,targetControlState:l,predicate:d,actionFactory:t,guardIndex:n,transitionIndex:s}]}}),a)}},t.makeHistoryStates=function(t){const e=Object.keys(st(t));return(t,n)=>{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{[t]:n,type:p}}},t.historyState=function(t,e){return{[t]:e}},t.toPlantUml=function(t,i){const{states:r,transitions:c}=t,{getChildren:u,constructTree:l,getLabel:d}=I,f=t=>t.join(e),p=M(I,{seed:()=>Map,visit:(t,e,i)=>{const{path:r}=e.get(i),l=d(i),p=function(t,e,i){return[`${Yt(t,"")} {`,e.join("\n"),function(t,e){const n=e.reduce((e,n)=>{const s=et(n);return s.filter(z).filter(K(t)).reduce((t,e)=>(t[tt(e)]=void 0,t),e)},{});return Object.keys(n).map(t=>`${Yt(t,o)}`).join("\n")}(t,i),function(t,e){return e.reduce((e,o)=>{const i=et(o);return i.filter(q).filter(G(t)).reduce((t,e)=>{const{from:o,to:i,predicate:a,action:r}=e;return t.push(`[*] ${n} ${i} ${s} ${Z("",a,r)}`),t},e)},[]).join("\n")}(t,i),"}",function(t,e){const o=function(t,e){return e.map(e=>{const o=et(e);return o.filter(G(t)).filter(z).map(({from:t,event:e,predicate:o,to:i,action:a})=>[t,n,tt({from:t,to:i}),s,Z(e,o,a)].join(" ")).join("\n")}).filter(Boolean).join("\n")}(t,e),i=function(t,e){return t===a?"":e.map(e=>{const o=et(e);return o.filter(G(t)).filter(t=>!q(t)).filter(t=>!z(t)).map(({from:t,event:e,predicate:o,to:i,action:a})=>[t,n,i,s,Z(e,o,a)].join(" ")).join("\n")}).filter(Boolean).join("\n")}(t,e);return[o,i].filter(Boolean).join("\n")}(t,i)].filter(t=>"\n"!==t&&""!==t).join("\n")}(Object.keys(l)[0],J(e=>t.get(f(r.concat(e))),((t,e)=>u(t,e).length)(i,e)),c);return t.set(f(r),p),t}},{[a]:r}),m=p.get("0");return p.clear(),m},t.toDagreVisualizerFormat=function(t){const{states:n,transitions:s}=t,{getLabel:o,getChildren:i}=I,{constructTree:r}=D,c=t=>t.join(e),u=M(I,{seed:()=>Map,visit:(t,e,n)=>{const{path:s}=e.get(n),a=o(n),u=Object.keys(a)[0],l=J(e=>t.get(c(s.concat(e))),((t,e)=>i(t,e).length)(n,e));return t.set(c(s),r(u,l)),t}},{[a]:n}).get("0"),l=s.map(t=>{const{from:e,to:n,event:s,guards:o,action:i}=t;return o?{from:e,event:s,guards:o.map(t=>{const{predicate:e,to:n,action:s}=t;return{predicate:e.name,to:n,action:s.name}})}:{from:e,to:n,event:s,action:i.name||"no action name?"}});return JSON.stringify({states:u,transitions:l})},t.CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",t.SEP=e,t.TRANSITION_SYMBOL=n,t.TRANSITION_LABEL_START_SYMBOL=s,t.HISTORY_STATE_NAME=o,t.HISTORY_PREFIX=i,t.INIT_STATE=a,t.INIT_EVENT=r,t.AUTO_EVENT=c,t.STATE_PROTOTYPE_NAME=u,t.NO_STATE_UPDATE=l,t.NO_OUTPUT=d,t.ACTION_IDENTITY=f,t.history_symbol=p,t.SHALLOW=m,t.DEEP=h,t.WRONG_EVENT_FORMAT_ERROR=g,t.FUNCTION_THREW_ERROR=y,t.INVALID_ACTION_FACTORY_EXECUTED=b,t.INVALID_PREDICATE_EXECUTED=v,t.ACTION_FACTORY_DESC=T,t.ENTRY_ACTION_FACTORY_DESC=S,t.UPDATE_STATE_FN_DESC=E,t.PREDICATE_DESC=O,t.COMMAND_RENDER="render",t.noop=$,t.emptyConsole=L,t.isBoolean=H,t.isFunction=P,t.isControlState=B,t.isEvent=U,t.isActionFactory=V,t.make_states=function(t){return t.reduce((t,e)=>(t[e]="",t),{})},t.make_events=function(t){return t},t.get_fn_name=W,t.wrap=Y,t.times=J,t.always=function(t){return t},t.keys=X,t.merge=function(t,e){return Object.assign({},t,e)},t.is_history_transition=z,t.is_entry_transition=q,t.is_from_control_state=G,t.is_to_history_control_state_of=K,t.is_history_control_state_of=Q,t.format_transition_label=Z,t.format_history_transition_state_name=tt,t.get_all_transitions=et,t.getDisplayName=nt,t.mergeModelUpdates=function(t){return function(e,n,s){return{updates:t.reduce((t,o)=>{const i=o(e,n,s).updates;return i?t.concat(i):t},[]),outputs:d}}},t.chainModelUpdates=function(t){return function(e,n,s){const{updateState:o}=s;return{updates:t.reduce((t,e)=>{const{extendedState:i,updates:a}=t,r=e(i,n,s).updates;return{extendedState:o(i,a),updates:r}},{extendedState:e,updates:[]}).updates||[],outputs:d}}},t.mergeActionFactories=function(t,e){return function(n,s,o){const i=e.map(t=>t(n,s,o)),a=i.map(t=>t.updates||[]),r=i.map(t=>t.outputs||{});return{updates:[].concat(...a),outputs:t(r)}}},t.identity=function(t,e,n){return{updates:[],outputs:d}},t.lastOf=function(t){return t[t.length-1]},t.getFsmStateList=st,t.getStatesType=ot,t.getStatesPath=it,t.getStatesTransitionsMap=at,t.getStatesTransitionsMaps=rt,t.getEventTransitionsMaps=ct,t.getHistoryStatesMap=ut,t.getTargetStatesMap=lt,t.getAncestorMap=dt,t.computeHistoryMaps=ft,t.mapOverTransitionsActions=pt,t.reduceTransitions=mt,t.everyTransition=function(t,e){return mt((e,n)=>e&&t(n),!0,[e])},t.computeTimesCircledOn=function(t,e){return t.reduce((t,n)=>n===e?t+1:t,0)},t.isInitState=function(t){return t===a},t.isInitEvent=function(t){return t===r},t.isEventless=function(t){return void 0===t},t.arrayizeOutput=ht,t.isHistoryControlState=gt,t.getHistoryParentState=function(t){return t[m]||t[h]},t.isShallowHistory=function(t){return t[m]},t.isDeepHistory=function(t){return t[h]},t.getHistoryType=yt,t.getHistoryUnderlyingState=bt,t.isHistoryStateEdge=function(t){return void 0!==t.history},t.initHistoryDataStructure=vt,t.isCompoundState=Tt,t.isAtomicState=function(t,e){return!Tt(t,e)},t.updateHistory=St,t.computeHistoryState=function(t,e,n,s){const{stateList:o,stateAncestors:i}=ft(t);let a=vt(o);return(a=e.reduce((t,e)=>St(t,i,e),a))[n][s]},t.findInitTransition=Et,t.tryCatch=Ot,t.tryCatchMachineFn=wt,t.getFunctionName=At,t.assert=_t,t.notifyThrows=Ct,t.handleFnExecError=jt,t.notifyAndRethrow=Ft,t.throwIfInvalidActionResult=Nt,t.throwIfInvalidGuardResult=kt,t.throwIfInvalidEntryActionResult=xt,t.isActions=Mt,t.isEventStruct=It,t.isError=Rt,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){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 r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function o(t,e,n){return(o=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&&i(a,n.prototype),a}).apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return(s=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 o(t,arguments,a(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(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 f(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 l=".",d="--\x3e",p=":",v="H",m="history.",h="nok",y="init",g="auto",b="State",T=[],S=null,O=function(){return{outputs:S,updates:T}},E={},w="shallow",A="deep",_="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.",C=function(t,e){return"Exception thrown when executing ".concat(e," ").concat(t||"")},j=function(t,e){return"".concat(C(t,e),"\nThe ").concat(e," returned a value which is not an action.")},N=function(t,e){return"".concat(C(t,e),"\nThe ").concat(e," returned a value which is not a boolean.")},F="action factory",k="(decorating) entry action",x="update state function",R="predicate",M="CONTRACTS_EVAL";const I=[0],D="PRE_ORDER";function L(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function H(t,e){return Object.assign({},t,e)}function P(t,e,n){n.forEach((n,r)=>{const a=t.get(e),i=t.get(n),o=i&&i.path;t.set(n,H(i,{isAdded:!0,isVisited:!1,path:o||a.path.concat(r)}))})}function B(t,e){t.set(e,H(t.get(e),{isVisited:!0}))}function V(t,e){const{store:n,lenses:r,traverse:a}=t,{empty:i,add:o,takeAndRemoveOne:s,isEmpty:u}=n,{getChildren:c}=r,{visit:f,seed:l}=a,d=new Map,p="function"==typeof l?new(l()):L(l);let v="function"==typeof i?new(i()):L(i),m=p;for(o([e],v),d.set(e,{isAdded:!0,isVisited:!1,path:I});!u(v);){const t=s(v),e=c(d,t);o(e,v),P(d,t,e),m=f(m,d,t),B(d,t)}return d.clear(),m}function U(t,e,n){const{getChildren:r}=t;return V({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 W(t,e,n){const{getChildren:r}=t;return V({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 Y(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 V({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 J={isLeafLabel:function(t){return 0===J.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 X(t,e){const n={root:e},{strategy:r,seed:a,visit:i}=t;return({BFS:U,PRE_ORDER:W,POST_ORDER:Y}[r]||W)(J,{seed:a,visit:function(t,e,n){const{path:r}=e.get(n);return JSON.stringify(r)===JSON.stringify(I)?t:i(t,e,n)}},n)}const z={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 q=function(){},G={log:q,warn:q,info:q,debug:q,error:q,trace:q},K=q;function $(t){return"boolean"==typeof t}function Q(t){return"function"==typeof t}function Z(t){return t&&"string"==typeof t||jt(t)}function tt(t){return t&&"string"==typeof t}function et(t){return t&&"function"==typeof t}function nt(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 rt(t){return["-",t,"-"].join("")}function at(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function it(t){return Object.keys(t)}function ot(t){return t.to.startsWith(m)}function st(t){return t.event===y}function ut(t){return function(e){return e.from===t}}function ct(t){return function(e){return ft(t,e.to)}}function ft(t,e){return e.substring(m.length)===t}function lt(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 dt(t){var e=t.from,n=t.to;return"".concat(e,".").concat(n.substring(m.length),".").concat(v)}function pt(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 vt(t){return t.replace(/_/g," ")}function mt(t){var e=J.getLabel;return X({strategy:D,seed:{},visit:function(t,n,r){var a=e(r);return t[Object.keys(a)[0]]="",t}},t)}function ht(t){var e=J.getLabel,n=J.isLeafLabel;return X({strategy:D,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 yt(t){var e=J.getLabel;return X({strategy:D,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 gt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return jt(n)?t:(t[n]=t[n]||{},t[n][r]=e,t)},{})||{}}function bt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return jt(n)?t:(t[n]=t[n]||{},t[n][r]=t[n][r]?t[n][r].concat(e):[e],t)},{})||{}}function Tt(t){return t.reduce(function(t,e){var n=e.from,r=e.event;return jt(n)?t:(t[r]=t[r]||{},t[r][n]=t[r][n]?t[r][n].concat(e):[e],t)},{})||{}}function St(t){return _t(function(t,e,n,r){var a=e.from,i=(e.event,e.to);e.action,e.predicate,e.gen;if(jt(a)){var o=Ft(a);t.set(o,(t.get(o)||[]).concat([e]))}else if(jt(i)){var s=Ft(i);t.set(s,(t.get(s)||[]).concat([e]))}return t},new Map,t)||{}}function Ot(t){return _t(function(t,e,n,r){var a=e.to;return t.set(a,(t.get(a)||[]).concat([e])),t},new Map,t)||{}}function Et(t){var e=J.getLabel,n=J.getChildren;return X({strategy:D,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 wt(t){var e;if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";var n=J.getLabel,a=X({strategy:D,seed:{stateList:[],stateAncestors:(e={},r(e,A,{}),r(e,w,{}),e)},visit:function(t,e,r){var a=n(r),i=Object.keys(a)[0];t.stateList=t.stateList.concat(i);var o=e.get(r).path;e.set(JSON.stringify(o),i);var s=o.slice(0,-1);if(1===s.length)e.set(JSON.stringify(s),h);else{var u=e.get(JSON.stringify(s));t.stateAncestors[w][i]=[u];var c=o.reduce(function(t,n){var r=t.path.slice(0,-1);if(t.path=r,r.length>1){var a=e.get(JSON.stringify(r));t.ancestors=t.ancestors.concat(a)}return t},{ancestors:[],path:o}).ancestors;t.stateAncestors[A][i]=c}return t}},t);return{stateList:a.stateList,stateAncestors:a.stateAncestors}}function At(t,e){return _t(function(e,n,r,a){var i=n.from,o=n.event,s=n.to,u=n.action,c=n.predicate,f=t(u,n,r,a);return f.displayName=f.displayName||u&&(u.name||u.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)}(u,i,o,s,c)),void 0===c?e.push({from:i,event:o,to:s,action:f}):0===r?e.push({from:i,event:o,guards:[{to:s,predicate:c,action:f}]}):e[e.length-1].guards.push({to:s,predicate:c,action:f}),e},[],e)}function _t(t,e,n){return n.reduce(function(e,n,r){var a=n.from,i=n.event,o=n.to,s=n.gen,u=n.action,c=n.guards;return c||(c=s?[{to:o,action:u,gen:s,predicate:void 0}]:[{to:o,action:u,predicate:void 0}]),c.reduce(function(e,n,o){var s=n.to,u=n.action,c=n.gen,f=n.predicate;return t(e,c?{from:a,event:i,to:s,action:u,predicate:f,gen:c}:{from:a,event:i,to:s,action:u,predicate:f},o,r)},e)},e)}function Ct(t){return t===S?S:Array.isArray(t)?t:[t]}function jt(t){return"object"===e(t)&&(A in t||w in t)}function Nt(t){return t[A]?A:w}function Ft(t){return t[Nt(t)]}function kt(t){var e,n=function(){return t.reduce(function(t,e){return t[e]="",t},{})};return r(e={},A,n()),r(e,w,n()),e}function xt(t,e){var n=t.statesAdjacencyList;return n[e]&&0!==n[e].length}function Rt(t,e,n){return n===h?t:([w,A].forEach(function(r){(e[r][n]||[]).forEach(function(e){t[r][e]=n})}),t)}function Mt(t){return t.find(function(t){return t.from===h&&t.event===y})}function It(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 Dt(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return It(e,function(r,a){var i=new Error(r),o=Lt(e),s=C(o,t);i.probableCause=r.probableCause?[r.probableCause,s].join("\n"):s;var u={fnName:o,params:n.reduce(function(t,e,n){return t[e]=a[n],t},{})};return i.info=r.info?[].concat([r.info]).concat([u]):u,i})}function Lt(t){return t.name||t.displayName||"anonymous"}function Ht(t,e){var n=t.apply(null,e);if(!0!==n){var r=n.info;throw console.error("ERROR: failed contract ".concat(t.name||"",". ").concat(r?"Error info:":""),n.info),n}}function Pt(t,e){t.error(e),e.probableCause&&t.error("Probable cause: ".concat(e.probableCause)),e.info&&t.error("ERROR: additional info",e.info)}function Bt(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 Vt(t,e){t.debug;throw Pt(t.console,e),e}function Ut(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,u=Lt(a),c=new Error(j(u,F));throw c.info={fnName:Lt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Pt(r,c),c}function Wt(t,e,n){t.debug;var r=t.console,a=Lt(n.predicate),i=new Error(N(a,R));throw i.info={predicateName:a,params:n,returned:e},Pt(r,i),i}function Yt(t,e,n){t.debug;var r=t.console,a=n.action,i=n.extendedState,o=n.eventData,s=n.settings,u=Lt(a),c=new Error(j(u,k));throw c.info={fnName:Lt(a),params:{updatedExtendedState:i,eventData:o,settings:s},returned:e},Pt(r,c),c}function Jt(t){return t&&"updates"in t&&"outputs"in t&&(t.outputs===S||Array.isArray(t.outputs))&&Array.isArray(t.updates)}function Xt(t){var n;return t&&"object"===e(t)?Object.keys(t).length>1?(n=new Error(_)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:n=!0:(n=new Error(_)).info={event:t,cause:"not an object!"},n}function zt(t){return t instanceof Error}function qt(t){var e=Object.keys(t)[0];return{eventName:e,eventData:t[e]}}function Gt(t){var e=t.from,n=t.event,r=t.guards,a=t.to,i=t.action;return typeof r==="".concat(void 0)&&a&&Z(e)&&tt(n)&&Z(a)&&et(i)}function Kt(t){var e=t.to,n=t.predicate,r=t.action;return e&&Z(e)&&Q(n)&&et(r)}function $t(t){var e=t.from,n=t.event,r=t.guards,a=t.to;return r&&Array.isArray(r)&&r.length>0&&!a&&Z(e)&&tt(n)&&r.every(Kt)}var Qt={computed:function(t,e){return{statesType:ht(t.states),initTransition:Mt(t.transitions),statesTransitionsMap:gt(t.transitions),statesTransitionsMaps:bt(t.transitions),eventTransitionsMaps:Tt(t.transitions),ancestorMap:Et(t.states),statesPath:yt(t.states),historyStatesMap:St(t.transitions),targetStatesMap:Ot(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),u=i&&Array.isArray(i);return o?s?u?{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(h)>-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!Gt(t)&&!$t(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=J.getLabel,r=X({strategy:D,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(h),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[h],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!==y});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,e,n){var r=n.statesTransitionsMaps,a=n.targetStatesMap,i=n.statesType,o=Object.keys(r),s=Array.from(a.keys()),u=Object.keys([o,s].reduce(function(t,e){return e.forEach(function(e){return t[e]=!0}),t},{})),c=Object.keys(i),f=c.map(function(t){return-1===u.indexOf(t)&&t}).filter(Boolean),l=u.map(function(t){return t!==h&&-1===c.indexOf(t)&&t}).filter(Boolean);return{isFulfilled:0===f.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:f,statesNotDeclaredButTriggeringTransitions:l}}}}},{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===h&&t.push(e),t},[]);return{isFulfilled:a&&!r||!a&&r&&1===i.length&&r.event===y&&(Gt(r)||$t(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 a=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).filter(function(t){return!i[t]}).map(function(t){return r({},t,a[t]&&a[t][y])}).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 a=n.statesTransitionsMap,i=n.statesType,o=n.statesPath,s=Object.keys(i).filter(function(t){return i[t]}),u=s.map(function(t){return a[t]&&a[t][y]}),c=u.every(Boolean);if(!c)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:s.map(function(t){return r({},t,!(!a[t]||!a[t][y]))})}}};var f=c&&u.every(function(t){var e=t.guards,n=t.to;return!e&&"string"==typeof n});return f?f&&u.every(function(t){var e=t.from,n=t.to;return e!==n&&o[n]&&o[n].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:u}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must be inconditional and the associated target control state cannot be a history pseudo-state. Cf. log",info:{entryTransitions:u}}}}},{name:"validEventLessTransitions",shouldThrow:!1,predicate:function(t,e,n){var a=n.statesTransitionsMap,i=n.statesType,o=(n.statesPath,Object.keys(i).map(function(t){return r({},t,a[t]&&"".concat(void 0)in a[t]&&1!==Object.keys(a[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.statesTransitionsMaps,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.statesTransitionsMaps;var a=n.eventTransitionsMaps,i=n.ancestorMap,o=Object.keys(a).reduce(function(t,e){var n=Object.keys(a[e]),o=n.filter(function(t){return t!==h}).map(function(t){return i[t]&&r({},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=c(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 jt(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.statesTransitionsMaps,a=n.statesType,i=Object.keys(r).map(function(t){return t===h?[]: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 jt(n)&&!a[Ft(n)]?t.concat(i):t},e):jt(s)&&!a[Ft(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 Zt=function(t,e,n){return function(t,e){var n=e&&e.console||G,a=e&&e.trace||q,i=t.description;return function(){for(var e=arguments.length,o=new Array(e),s=0;s<e;s++)o[s]=arguments[s];var u=[],c=t.computed.apply(null,o),f={isFulfilled:t.contracts.reduce(function(t,e){var r=e.name,a=e.predicate,s=e.shouldThrow,f=o.concat(c),l=a.apply(null,f),d=l.isFulfilled,p=l.blame,v="".concat(i," FAILS ").concat(r,"!"),m=p||{},h=m.message,y=m.info;if(d)return t;if(u.push({name:r,message:h,info:y}),n.error(v),n.error([r,h].join(": ")),n.debug("Supporting error data:",y),s)throw new Error([v,"check console for information!"].join("\n"));return!1},!0),failingContracts:u};return a(r({},M,f)),f}}(n,e)(t,e)},te=function(){return!0};function ee(t){var e=t.initialControlState,n=t.transitions,r=Mt(n);return e?n.concat([{from:h,event:y,to:e,action:O}]):r?n:void 0}function ne(t,n){var a=t.states,i=t.events,o=t.initialExtendedState,s=t.updateState,u=(n||{}).debug,c=u&&u.checkContracts||void 0,f=u&&u.console?u.console:G;u&&u.trace&&u.trace;if(c&&Zt(t,n,c).failingContracts.length>0)throw new Error("createStateMachine: called with wrong parameters! Cf. logs for failing contracts.");var l=Dt(x,s,["extendedState, updates"]),d=function(t){return(t=t.reduce?t:Array.prototype.slice.call(arguments)).push(y),t.reduce(function(t,e){return t[e]=e,t},{})}(i),p=ee(t),v=function(t){var n="State",r={},a={};function i(){}return t={nok:t},i.prototype={current_state_name:h},r[h]=new i,r[b]=new i,function t(i,o){it(i).forEach(function(s){var u=i[s];if(r[s]=new o,r[s].name=s,r[s].parent_name=nt(o),r[s].root_name=n,"object"===e(u)){a[s]=!0;var c=function(){};c.displayName=s,c.prototype=r[s],t(u,c)}})}(t,i),{hash_states:r,is_group_state:a}}(a),m=o,T=wt(a),E=T.stateList,_=T.stateAncestors,C=kt(E),j={},N={},k=v.is_group_state,M=v.hash_states;function I(t,e){var n,a;f.debug("send event",t),n=Xt,a=[t],c&&Ht(n,a);var i=qt(t),o=i.eventName,s=i.eventData,l=M[h].current_state_name;return e&&o===y&&l!==h?(f.warn("The external event INIT_EVENT can only be sent when starting the machine!"),S):function(t,e,n,a){var i=t[h].current_state_name,o=t[i][e];if(o){f.log("found event handler!"),f.info("WHEN EVENT ",e);var s=o(a,n,i),c=s.stop,l=s.outputs;u&&!c&&f.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");var d=Ct(l),p=t[h].current_state_name;if(N[p]&&p!==i){var v=j[p]?y:g;return[].concat(d).concat(I(r({},v,n),!1))}return d}return f.warn("There is no transition associated to the event |".concat(e,"| in state |").concat(i,"|!")),S}(v.hash_states,o,s,m)}return p.forEach(function(t){var e=t.from,r=t.to,a=t.action,i=t.event,o=t.guards;o||(o=[{predicate:te,to:r,action:a}]),i===y&&(j[e]=!0);var c=M[e];if(i&&!(i in d))throw"unknown event ".concat(i," found in state machine definition!");i||(i=g,N[e]=!0),k[e]&&j[e]&&(N[e]=!0),c[i]=o.reduce(function(t,r,a){var i=r.action||O,o=i.name||i.displayName,c=function(t,n){var r="",c=function(c,d,p){e=p||e;var v=t.predicate,y=v||te,g=!v||Dt(R,y,["extendedState","eventData","settings"])(c,d,n),b=t.to;if(r=y?"_checking_condition_"+a:"",Bt({debug:u,console:f},{predicate:t.predicate,extendedState:c,eventData:d,settings:n},g,$,Vt,Wt),g){f.info("IN STATE ",e),v&&f.info("CASE: guard ".concat(y.name," for transition is fulfilled")),!v&&f.info("CASE: unguarded transition"),f.info("THEN : we execute the action "+o);var T=Dt(F,i,["extendedState","eventData","settings"])(c,d,n);Bt({debug:u,console:f},{action:i,extendedState:c,eventData:d,settings:n},T,Jt,Vt,Ut);var O=T.updates,E=T.outputs;!function(t,e,n){var r=n[t].name;C=Rt(C,_,r),f.info("left state",rt(t))}(e,0,M);var N=l(c,O);Bt({debug:u,console:f},{updateStateFn:s,extendedState:c,updates:O},N,te,Vt,q),m=N;var k=function(t,e,n){var r,a;if(jt(t)){var i=t.deep?A:t.shallow?w:void 0,o=t[i];u&&f&&!j[o]&&f.warn("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"),a=C[i][o]||o,r=n[a]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";r=n[t],a=r.name}return n[h].current_state_name=a,u&&f.info("AND TRANSITION TO STATE",a),a}(b,0,M);return f.info("ENTERING NEXT STATE: ",k),zt(N)&&f.error("with error: ",N),zt(N)||f.info("with extended state: ",m),{stop:!0,outputs:E}}return{stop:!1,outputs:S}};return c.displayName=e+r,c}(r,n);return function(e,n,r){var a=t(e,n,r);return a.stop?a:c(e,n,r)}},function(){return{stop:!1,outputs:S}})}),I(r({},y,o),!0),function(t){return I(t,!0)}}function re(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ae(t,e){return e?'state "'.concat(e,'" as ').concat(t," <<NoContent>>"):'state "'.concat(vt(t),'" as ').concat(t," <<NoContent>>")}t.fsmContracts=Qt,t.build_state_enum=function(t){var n={history:{}};return n.NOK=h,function t(r){it(r).forEach(function(a){var i=r[a];n[a]=a,"object"===e(i)&&t(i)})}(t),n},t.normalizeTransitions=ee,t.normalizeFsmDef=function(t){return Object.assign({},t,{transitions:ee(t)})},t.create_state_machine=function(t,e){return ne(t,e)},t.createStateMachine=ne,t.makeWebComponentFromFsm=function(t){var e=t.name,r=t.eventHandler,o=t.fsm,c=t.commandHandlers,f=t.effectHandlers,l=t.options,d=function(t){function d(){var t,n,i;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,d),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!";n=this,i=a(d).call(this),t=!i||"object"!=typeof i&&"function"!=typeof i?u(n):i;var s=u(u(t));t.eventSubject=r,t.options=Object.assign({},l);var p=t.options.NO_ACTION||S;return t.eventSubject.subscribe({next:function(e){var n=o(e);n!==p&&n.forEach(function(e){if(e!==p){var n=e.command,r=e.params;c[n](t.eventSubject.next,r,f,s)}})}}),t}var p,v,m;return function(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&&i(t,e)}(d,s(HTMLElement)),p=d,m=[{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()}}])&&n(p.prototype,v),m&&n(p,m),d}();return customElements.define(e,d)},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=re,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,u=t.updateState,c=t.settings,f=mt(a),l=Object.keys(e).every(function(t){return null!=f[t]}),d=n||re;if(l)return{initialExtendedState:i,initialControlState:o,states:a,events:s,transitions:At(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,u=Dt(k,e,["extendedState","eventData","settings"]),c=t(a,i,o),f=c.updates,l=Dt(x,r,["extendedState, updates"]),d=l(a,f);Bt({debug:s,console:console},{updateStateFn:r,extendedState:a,actionUpdate:f},d,te,Vt,q);var p=d,v=u(p,i,o),m=Bt({debug:s,console:console},{action:e,extendedState:p,eventData:i,settings:o},v,Jt,Vt,Yt);if(!m)return{updates:[].concat(f,v.updates),outputs:n([c.outputs,v.outputs])}};return a.displayName="Entry_Action_After_".concat(Lt(t)),a}(t,o,d,u):t},r),updateState:u,settings:c};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:At(function(t,e,n,r){return function(a,i,o){var u=e.from,c=e.event,f=e.to,l=e.predicate,d=Dt(F,t,["extendedState","eventData","settings"])(a,i,o),p=d.outputs,v=d.updates;return{updates:v,outputs:[{outputs:p,updates:v,extendedState:a,newExtendedState:Dt(x,s,["extendedState, updates"])(a,v||[]),controlState:u,event:{eventLabel:c,eventData:i},settings:o,targetControlState:f,predicate:l,actionFactory:t,guardIndex:n,transitionIndex:r}]}}},o)}},t.makeHistoryStates=function(t){var e=Object.keys(mt(t));return function(t,n){var a;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 r(a={},t,n),r(a,"type",E),a}},t.historyState=function(t,e){return r({},t,e)},t.toPlantUml=function(t,e){var n=t.states,a=t.transitions,i=J.getChildren,o=J.getLabel,s=function(t){return t.join(l)},u=Y(J,{seed:function(){return Map},visit:function(t,e,n){var r=e.get(n).path,u=o(n),c=function(t,e,n){return["".concat(ae(t,"")," {"),e.join("\n"),function(t,e){var n=e.reduce(function(e,n){var r=pt(n);return r.filter(ot).filter(ct(t)).reduce(function(t,e){return t[dt(e)]=void 0,t},e)},{});return Object.keys(n).map(function(t){return"".concat(ae(t,v))}).join("\n")}(t,n),function(t,e){return e.reduce(function(e,n){var r=pt(n);return r.filter(st).filter(ut(t)).reduce(function(t,e){e.from;var n=e.to,r=e.predicate,a=e.action;return t.push("[*] ".concat(d," ").concat(n," ").concat(p," ").concat(lt("",r,a))),t},e)},[]).join("\n")}(t,n),"}",function(t,e){var n=function(t,e){return e.map(function(e){var n=pt(e);return n.filter(ut(t)).filter(ot).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,d,dt({from:e,to:a}),p,lt(n,r,i)].join(" ")}).join("\n")}).filter(Boolean).join("\n")}(t,e),r=function(t,e){return t===h?"":e.map(function(e){var n=pt(e);return n.filter(ut(t)).filter(function(t){return!st(t)}).filter(function(t){return!ot(t)}).map(function(t){var e=t.from,n=t.event,r=t.predicate,a=t.to,i=t.action;return[e,d,a,p,lt(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(u)[0],at(function(e){return t.get(s(r.concat(e)))},function(t,e){return i(t,e).length}(n,e)),a);return t.set(s(r),c),t}},r({},h,n)),c=u.get("0");return u.clear(),c},t.toDagreVisualizerFormat=function(t){var e=t.states,n=t.transitions,a=J.getLabel,i=J.getChildren,o=z.constructTree,s=function(t){return t.join(l)},u=Y(J,{seed:function(){return Map},visit:function(t,e,n){var r=e.get(n).path,u=a(n),c=Object.keys(u)[0],f=at(function(e){return t.get(s(r.concat(e)))},function(t,e){return i(t,e).length}(n,e));return t.set(s(r),o(c,f)),t}},r({},h,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:u,transitions:c})},t.CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",t.SEP=l,t.TRANSITION_SYMBOL=d,t.TRANSITION_LABEL_START_SYMBOL=p,t.HISTORY_STATE_NAME=v,t.HISTORY_PREFIX=m,t.INIT_STATE=h,t.INIT_EVENT=y,t.AUTO_EVENT=g,t.STATE_PROTOTYPE_NAME=b,t.NO_STATE_UPDATE=T,t.NO_OUTPUT=S,t.ACTION_IDENTITY=O,t.history_symbol=E,t.SHALLOW=w,t.DEEP=A,t.WRONG_EVENT_FORMAT_ERROR=_,t.FUNCTION_THREW_ERROR=C,t.INVALID_ACTION_FACTORY_EXECUTED=j,t.INVALID_PREDICATE_EXECUTED=N,t.ACTION_FACTORY_DESC=F,t.ENTRY_ACTION_FACTORY_DESC=k,t.UPDATE_STATE_FN_DESC=x,t.PREDICATE_DESC=R,t.COMMAND_RENDER="render",t.CONTRACTS_EVAL=M,t.noop=q,t.emptyConsole=G,t.emptyTrace=K,t.isBoolean=$,t.isFunction=Q,t.isControlState=Z,t.isEvent=tt,t.isActionFactory=et,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=nt,t.wrap=rt,t.times=at,t.always=function(t){return t},t.keys=it,t.merge=function(t,e){return Object.assign({},t,e)},t.is_history_transition=ot,t.is_entry_transition=st,t.is_from_control_state=ut,t.is_to_history_control_state_of=ct,t.is_history_control_state_of=ft,t.format_transition_label=lt,t.format_history_transition_state_name=dt,t.get_all_transitions=pt,t.getDisplayName=vt,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:S}}},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:S}}},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||[]}),u=o.map(function(t){return t.outputs||{}});return{updates:(i=[]).concat.apply(i,f(s)),outputs:t(u)}}},t.identity=function(t,e,n){return{updates:[],outputs:S}},t.lastOf=function(t){return t[t.length-1]},t.getFsmStateList=mt,t.getStatesType=ht,t.getStatesPath=yt,t.getStatesTransitionsMap=gt,t.getStatesTransitionsMaps=bt,t.getEventTransitionsMaps=Tt,t.getHistoryStatesMap=St,t.getTargetStatesMap=Ot,t.getAncestorMap=Et,t.computeHistoryMaps=wt,t.mapOverTransitionsActions=At,t.reduceTransitions=_t,t.everyTransition=function(t,e){return _t(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===h},t.isInitEvent=function(t){return t===y},t.isEventless=function(t){return void 0===t},t.arrayizeOutput=Ct,t.isHistoryControlState=jt,t.getHistoryParentState=function(t){return t[w]||t[A]},t.isShallowHistory=function(t){return t[w]},t.isDeepHistory=function(t){return t[A]},t.getHistoryType=Nt,t.getHistoryUnderlyingState=Ft,t.isHistoryStateEdge=function(t){return void 0!==t.history},t.initHistoryDataStructure=kt,t.isCompoundState=xt,t.isAtomicState=function(t,e){return!xt(t,e)},t.updateHistory=Rt,t.computeHistoryState=function(t,e,n,r){var a=wt(t),i=a.stateList,o=a.stateAncestors,s=kt(i);return(s=e.reduce(function(t,e){return Rt(t,o,e)},s))[n][r]},t.findInitTransition=Mt,t.tryCatch=It,t.tryCatchMachineFn=Dt,t.getFunctionName=Lt,t.assert=Ht,t.notifyThrows=Pt,t.handleFnExecError=Bt,t.notifyAndRethrow=Vt,t.throwIfInvalidActionResult=Ut,t.throwIfInvalidGuardResult=Wt,t.throwIfInvalidEntryActionResult=Yt,t.isActions=Jt,t.isEventStruct=Xt,t.isError=zt,t.destructureEvent=qt,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=kingly.umd.min.js.map
{
"name": "kingly",
"sideEffects": false,
"version": "0.19.3",
"version": "0.20.0",
"description": "Extended Hierarchical State Transducer library",

@@ -25,2 +25,6 @@ "repository": {

],
"np": {
"yarn": false,
"contents": "dist"
},
"scripts": {

@@ -39,11 +43,6 @@ "prepublish": "npm run build",

"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.1",
"babel-plugin-transform-class-properties": "^6.9.1",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babelify": "^7.3.0",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"babel-preset-es2015-rollup": "^3.0.0",
"benchmark": "^2.1.2",

@@ -66,2 +65,3 @@ "browser-sync": "^2.18.8",

"rollup": "^0.63.4",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.1.3",

@@ -82,3 +82,7 @@ "rollup-plugin-node-builtins": "^2.1.2",

},
"browserslist": ["> 1%", "last 2 versions", "not ie <= 9"]
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 9"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc