var t,n;t=this,n=function(t){"use strict";
/*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */function n(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),a=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return a}var e;t.InterpreterStatus=void 0,(e=t.InterpreterStatus||(t.InterpreterStatus={}))[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped";var r={type:"xstate.init"};function i(t){return void 0===t?[]:[].concat(t)}function o(t,n){return"string"==typeof(t="string"==typeof t&&n&&n[t]?n[t]:t)?{type:t}:"function"==typeof t?{type:t.name,exec:t}:t}function a(t){return function(n){return t===n}}function u(t){return"string"==typeof t?{type:t}:t}function c(t,n){return{value:t,context:n,actions:[],changed:!1,matches:a(t)}}function s(t,n,e){var r=n,i=!1;return[t.filter((function(t){if("xstate.assign"===t.type){i=!0;var n=Object.assign({},r);return"function"==typeof t.assignment?n=t.assignment(r,e):Object.keys(t.assignment).forEach((function(i){n[i]="function"==typeof t.assignment[i]?t.assignment[i](r,e):t.assignment[i]})),r=n,!1}return!0})),r,i]}var f=function(t,n){return t.actions.forEach((function(e){var r=e.exec;return r&&r(t.context,n)}))};t.assign=function(t){return{type:"xstate.assign",assignment:t}},t.createMachine=function(t,e){void 0===e&&(e={});var f=n(s(i(t.states[t.initial].entry).map((function(t){return o(t,e.actions)})),t.context,r),2),l=f[0],p=f[1],v={config:t,_options:e,initialState:{value:t.initial,actions:l,context:p,matches:a(t.initial)},transition:function(e,r){var f,l,p="string"==typeof e?{value:e,context:t.context}:e,y=p.value,d=p.context,g=u(r),x=t.states[y];if(x.on){var S=i(x.on[g.type]);try{for(var h=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(S),m=h.next();!m.done;m=h.next()){var b=m.value;if(void 0===b)return c(y,d);var I="string"==typeof b?{target:b}:b,j=I.target,w=I.actions,_=void 0===w?[]:w,E=I.cond,O=void 0===E?function(){return!0}:E,R=void 0===j,M=null!=j?j:y,N=t.states[M];if(O(d,g)){var T=n(s((R?i(_):[].concat(x.exit,_,N.entry).filter((function(t){return t}))).map((function(t){return o(t,v._options.actions)})),d,g),3),k=T[0],F=T[1],P=T[2],X=null!=j?j:y;return{value:X,context:F,actions:k,changed:j!==y||k.length>0||P,matches:a(X)}}}}catch(t){f={error:t}}finally{try{m&&!m.done&&(l=h.return)&&l.call(h)}finally{if(f)throw f.error}}}return c(y,d)}};return v},t.interpret=function(n){var e=n.initialState,i=t.InterpreterStatus.NotStarted,o=new Set,c={_machine:n,send:function(r){i===t.InterpreterStatus.Running&&(e=n.transition(e,r),f(e,u(r)),o.forEach((function(t){return t(e)})))},subscribe:function(t){return o.add(t),t(e),{unsubscribe:function(){return o.delete(t)}}},start:function(o){if(o){var u="object"==typeof o?o:{context:n.config.context,value:o};e={value:u.value,actions:[],context:u.context,matches:a(u.value)}}else e=n.initialState;return i=t.InterpreterStatus.Running,f(e,r),c},stop:function(){return i=t.InterpreterStatus.Stopped,o.clear(),c},get state(){return e},get status(){return i}};return c},Object.defineProperty(t,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).XStateFSM={});
