xstate 5.0.0-beta.43 → 5.0.0-beta.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -3
  3. package/actions/dist/xstate-actions.development.esm.js +2 -3
  4. package/actions/dist/xstate-actions.esm.js +2 -3
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +6 -6
  8. package/actors/dist/xstate-actors.development.cjs.js +6 -6
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +3 -7
  14. package/dist/declarations/src/actions/spawn.d.ts +11 -16
  15. package/dist/declarations/src/guards.d.ts +2 -2
  16. package/dist/declarations/src/index.d.ts +1 -1
  17. package/dist/declarations/src/spawn.d.ts +9 -13
  18. package/dist/declarations/src/stateUtils.d.ts +4 -4
  19. package/dist/declarations/src/types.d.ts +15 -16
  20. package/dist/declarations/src/utils.d.ts +1 -3
  21. package/dist/{raise-e0fe5c2d.cjs.js → raise-348cc74e.development.esm.js} +946 -68
  22. package/dist/{raise-f4ad5a87.development.esm.js → raise-5854eaca.esm.js} +860 -49
  23. package/dist/{raise-23dea0d7.development.cjs.js → raise-ed700d14.development.cjs.js} +922 -36
  24. package/dist/{raise-8dc8e1aa.esm.js → raise-fb6f017b.cjs.js} +907 -2
  25. package/dist/{send-0174c155.development.cjs.js → send-00466e37.development.cjs.js} +11 -12
  26. package/dist/{send-87bbaaab.cjs.js → send-53e5693c.cjs.js} +11 -12
  27. package/dist/{send-5d129d95.development.esm.js → send-a0193bdb.development.esm.js} +2 -3
  28. package/dist/{send-84e2e742.esm.js → send-b7b4befa.esm.js} +2 -3
  29. package/dist/xstate.cjs.js +25 -25
  30. package/dist/xstate.cjs.mjs +1 -0
  31. package/dist/xstate.development.cjs.js +25 -25
  32. package/dist/xstate.development.cjs.mjs +1 -0
  33. package/dist/xstate.development.esm.js +4 -6
  34. package/dist/xstate.esm.js +4 -6
  35. package/dist/xstate.umd.min.js +1 -1
  36. package/dist/xstate.umd.min.js.map +1 -1
  37. package/guards/dist/xstate-guards.cjs.js +1 -2
  38. package/guards/dist/xstate-guards.development.cjs.js +1 -2
  39. package/guards/dist/xstate-guards.development.esm.js +1 -2
  40. package/guards/dist/xstate-guards.esm.js +1 -2
  41. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/interpreter-36d5556e.cjs.js +0 -887
  44. package/dist/interpreter-4e8e2a0d.development.cjs.js +0 -898
  45. package/dist/interpreter-63c80754.esm.js +0 -857
  46. package/dist/interpreter-80eb3bec.development.esm.js +0 -868
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const n=".",s="",i="",o="xstate.init",r="xstate.error",a="xstate.stop";function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function f(t){return{type:o,input:t}}function h(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=h();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function g(t,e){const n=m(t),s=m(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&g(n[t],s[t])))}function v(t){try{return k(t)?t:t.toString().split(n)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function m(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(k(t))return _(t);if("string"!=typeof t)return t;return _(v(t))}function _(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function x(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function b(t){return[].concat(...t)}function S(t){return k(t)?t:[t]}function w(t){return void 0===t?[]:S(t)}function $(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function T(t){if(void 0!==t&&t!==s)return w(t)}function E(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function O(t,e){return`${t}[${e}]`}function j(t,e){if(e.startsWith("xstate#")){const[,n]=e.match(/\[(\d+)\]$/),s=t.getStateNodeById(e.slice(7,-(n.length+2))).config.invoke;return(Array.isArray(s)?s[n]:s).src}return t.implementations.actors[e]}const M=1;let N=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const A={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class P{constructor(t,n){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=N.NotStarted,this._parent=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...A,...n},{clock:i,logger:o,parent:r,id:a,systemId:c,inspect:u}=s;this.system=r?.system??function(t){const e=new Map,n=new Map,s=new WeakMap,i=new Set,o={_bookId:()=>"x:"+y++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const n={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:n}),e._send(n)}};return o}(this),u&&!r&&this.system.inspect(E(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState(n?.state),c&&"active"===this._state.status&&(this._systemId=c,this.system._set(c,this))}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,e){let n;for(this._state=t;n=this._deferred.shift();)n();for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,i=this._state.output,{type:`xstate.done.actor.${s}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,u(this.id,this._state.error))}var s,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=E(t,e,n);if(this._processingStatus!==N.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this._processingStatus===N.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=N.Running;const t=f(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(u(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(u(this.id,t))}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===N.Stopped?this:(this.mailbox.clear(),this._processingStatus===N.NotStarted?(this._processingStatus=N.Stopped,this):(this.mailbox.enqueue({type:a}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){p(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_stopProcedure(){if(this._processingStatus!==N.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=N.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==N.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:n,delay:s}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),s);n&&(this.delayedEventsMap[n]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:M,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[l](){return this}getSnapshot(){return this._state}}function R(t,e){return new P(t,e)}const D=R,J=new WeakMap;function V(t,e,n){let s=J.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},J.set(t,s)),s[e]}function C(t,e,n,s,{sendId:i}){return[e,"function"==typeof i?i(n,s):i]}function B(t,e){t.self.cancel(e)}function z(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=B,e}function W(t,e,n,s,{id:i,systemId:o,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?j(e.machine,r):r,f="function"==typeof i?i(n):i;let h;return u&&(h=R(u,{id:f,src:r,parent:t?.self,systemId:o,input:"function"==typeof a?a({context:e.context,event:n.event,self:t?.self}):a}),c&&h.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${i}`,snapshot:e})},error:()=>{}})),[Ut(e,{children:{...e.children,[f]:h}}),{id:i,actorRef:h}]}function U(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n._processingStatus!==N.Stopped)try{n.start?.()}catch(n){return void t.self.send(u(e,n))}}))}function q(...[t,{id:e,systemId:n,input:s,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawn",o.id=e,o.systemId=n,o.src=t,o.input=s,o.syncSnapshot=i,o.resolve=W,o.execute=U,o}function G(t,e,n,s,{actorRef:i}){const o="function"==typeof i?i(n,s):i,r="string"==typeof o?e.children[o]:o;let a=e.children;return r&&(a={...a},delete a[r.id]),[Ut(e,{children:a}),r]}function Q(t,e){e&&(t.system._unregister(e),e._processingStatus===N.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function F(t){function e(t,e){}return e.type="xstate.stop",e.actorRef=t,e.resolve=G,e.execute=Q,e}function X(t,e,{stateValue:n}){if("string"==typeof n&&at(n)){const e=t.machine.getStateNodeById(n);return t.configuration.some((t=>t===e))}return t.matches(n)}function H(t,{context:e,event:n},{guards:s}){return!Y(s[0],e,n,t)}function K(t,{context:e,event:n},{guards:s}){return s.every((s=>Y(s,e,n,t)))}function L(t,{context:e,event:n},{guards:s}){return s.some((s=>Y(s,e,n,t)))}function Y(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return Y(r,e,n,s);const a={context:e,event:n},c=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:n}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(s,a,r)}const Z=t=>"atomic"===t.type||"final"===t.type;function tt(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function et(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function nt(t){const e=new Set(t),n=new Set(t),s=it(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of tt(t))if("history"!==e.type&&!n.has(e)){const t=dt(e);for(const e of t)n.add(e)}}else dt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function st(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(Z(t))return t.key}const s={};for(const t of n)s[t.key]=st(t,e);return s}function it(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function ot(t,e){return st(t,it(nt(e)))}function rt(t,e){return"compound"===e.type?tt(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?tt(e).every((e=>rt(t,e))):"final"===e.type}const at=t=>"#"===t[0];function ct(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const i=e[n],o="string"==typeof i?{target:i}:i,r=isNaN(+n)?n:+n,a=((e,n)=>{const s=(o="function"==typeof e?`${t.id}:delay[${n}]`:e,r=t.id,{type:`xstate.after(${o})${r?`#${r}`:""}`}),i=s.type;var o,r;return t.entry.push(te(s,{id:i,delay:e})),t.exit.push(z(i)),i})(r,s);return w(o).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:n}=e;return{...ut(t,e.event,e),delay:n}}))}function ut(t,e,s){const i=T(s.target),o=s.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(at(e))return t.machine.getStateNodeById(e);const s=e[0]===n;if(s&&!t.parent)return yt(t,e.slice(1));const i=s?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return yt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,i),a={...s,actions:w(s.actions),guard:s.guard,target:r,source:t,reenter:o,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ft(t){const e=T(t.config.target);return e?{target:e.map((e=>"string"==typeof e?yt(t.parent,e):e))}:t.parent.initial}function ht(t){return"history"===t.type}function dt(t){const e=pt(t);for(const n of e)for(const s of et(n,t))e.add(s);return e}function pt(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of tt(n))t(e)}(t),e}function lt(t,e){if(at(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function yt(t,e){if("string"==typeof e&&at(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=v(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=lt(s,t)}return s}function gt(t,e){if("string"==typeof e)return[t,t.states[e]];const n=Object.keys(e),s=n.map((e=>lt(t,e))).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce(((n,s)=>{const i=lt(t,s);if(!i)return n;const o=gt(i,e[s]);return n.concat(o)}),[]))}function vt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=lt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=vt(lt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=vt(lt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function mt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function _t(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function xt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function bt(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(xt($t([i],e,n),$t([r],e,n))){if(!_t(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function St(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ht(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of St(ft(s),e))n.add(t);else n.add(s);return[...n]}function wt(t,e){const n=St(t,e);if(!n)return;if(!t.reenter&&n.every((e=>e===t.source||_t(e,t.source))))return t.source;const s=function(t){const[e,...n]=t;for(const t of et(e,void 0))if(n.every((e=>_t(e,t))))return t}(n.concat(t.source));return s||(t.reenter?void 0:t.source.machine.root)}function $t(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=wt(i,n);i.reenter&&i.source===t&&s.add(t);for(const n of e)_t(n,t)&&s.add(n)}return[...s]}function kt(t,e,n,s,i,o){if(!t.length)return e;const r=new Set(e.configuration);let a=e.historyValue;const u=bt(t,r,a);let f=e;i||([f,a]=function(t,e,n,s,i,o,r){let a=t;const c=$t(s,i,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of mt(t)){let n;n="deep"===e.history?e=>Z(e)&&_t(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(i).filter(n)}for(const t of c)a=Mt(a,e,n,[...t.exit,...t.invoke.map((t=>F(t.id)))],r),i.delete(t);return[a,u||o]}(f,s,n,u,r,a,o)),f=Mt(f,s,n,u.flatMap((t=>t.actions)),o),f=function(t,e,n,s,i,o,r,a){let u=t;const f=new Set,h=new Set;(function(t,e,n,s){for(const i of t){const t=wt(i,e);for(const o of i.target||[])ht(o)||i.source===o&&i.source===t&&!i.reenter||(s.add(o),n.add(o)),Tt(o,e,n,s);const o=St(i,e);for(const r of o){const o=et(r,t);"parallel"===t?.type&&o.push(t),Et(s,e,n,o,!i.source.parent&&i.reenter?void 0:t)}}})(s,r,h,f),a&&h.add(t.machine.root);const d=new Set;for(const t of[...f].sort(((t,e)=>t.order-e.order))){i.add(t);const s=[];s.push(...t.entry);for(const e of t.invoke)s.push(q(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(h.has(t)){const e=t.initial.actions;s.push(...e)}if(u=Mt(u,e,n,s,o,t.invoke.map((t=>t.id))),"final"===t.type){const s=t.parent;let r="parallel"===s?.type?s:s?.parent,a=r||t;for("compound"===s?.type&&o.push(c(s.id,t.output?$(t.output,u.context,e,n.self):void 0));"parallel"===r?.type&&!d.has(r)&&rt(i,r);)d.add(r),o.push(c(r.id)),a=r,r=r.parent;if(r)continue;u=Ut(u,{status:"done",output:It(u,e,n,u.machine.root,a)})}}return u}(f,s,n,u,r,o,a,i);const h=[...r];"done"===f.status&&(f=Mt(f,s,n,h.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(e.configuration,r)?f:Ut(f,{configuration:h,historyValue:a})}catch(t){throw t}}function It(t,e,n,s,i){if(!s.output)return;const o=c(i.id,i.output&&i.parent?$(i.output,t.context,e,n.self):void 0);return $(s.output,t.context,o,n.self)}function Tt(t,e,n,s){if(ht(t))if(e[t.id]){const i=e[t.id];for(const t of i)s.add(t),Tt(t,e,n,s);for(const o of i)Ot(o,t.parent,s,e,n)}else{const i=ft(t);for(const o of i.target)s.add(o),i===t.parent?.initial&&n.add(t.parent),Tt(o,e,n,s);for(const o of i.target)Ot(o,t,s,e,n)}else if("compound"===t.type){const[i]=t.initial.target;ht(i)||(s.add(i),n.add(i)),Tt(i,e,n,s),Ot(i,t,s,e,n)}else if("parallel"===t.type)for(const i of tt(t).filter((t=>!ht(t))))[...s].some((t=>_t(t,i)))||(ht(i)||(s.add(i),n.add(i)),Tt(i,e,n,s))}function Et(t,e,n,s,i){for(const o of s)if(i&&!_t(o,i)||t.add(o),"parallel"===o.type)for(const s of tt(o).filter((t=>!ht(t))))[...t].some((t=>_t(t,s)))||(t.add(s),Tt(s,e,n,t))}function Ot(t,e,n,s,i){Et(n,s,i,et(t,e))}function jt(t,e,n,s,i,o){const{machine:r}=t;let a=t;for(const t of s){const s="function"==typeof t,c=s?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:n?.self,system:n?.system},f=s||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in c)){n?.self._processingStatus===N.Running?c(u,f):n?.defer((()=>{c(u,f)}));continue}const h=c,[d,p,l]=h.resolve(n,a,u,f,c,i);a=d,"retryResolve"in h&&o?.push([h,p]),"execute"in h&&(n?.self._processingStatus===N.Running?h.execute(n,p):n?.defer(h.execute.bind(null,n,p))),l&&(a=jt(a,e,n,l,i,o))}return a}function Mt(t,e,n,s,i,o){const r=o?[]:void 0,a=jt(t,e,n,s,{internalQueue:i,deferredActorIds:o},r);return r?.forEach((([t,e])=>{t.retryResolve(n,a,e)})),a}function Nt(t,e,n,s=[]){let i=t;const r=[];if(e.type===a)return i=Ut(At(i,e,n),{status:"stopped"}),r.push(i),{state:i,microstates:r};let c=e;if(c.type!==o){i=kt(Pt(c,i),t,n,c,!1,s),r.push(i)}let u=!0;for(;"active"===i.status;){let t=u?Rt(i,c):[];const e=t.length?i:void 0;if(!t.length){if(!s.length)break;c=s.shift(),t=Pt(c,i)}i=kt(t,i,n,c,!1,s),u=i!==e,r.push(i)}return"active"!==i.status&&At(i,c,n),{state:i,microstates:r}}function At(t,e,n){return Mt(t,e,n,Object.values(t.children).map((t=>F(t))),[])}function Pt(t,e){return e.machine.getTransitionData(e,t)}function Rt(t,e){const n=new Set,s=t.configuration.filter(Z);for(const i of s)t:for(const s of[i].concat(et(i,void 0)))if(s.always)for(const i of s.always)if(void 0===i.guard||Y(i.guard,t.context,e,t)){n.add(i);break t}return bt(Array.from(n),new Set(t.configuration),t.historyValue)}const Dt=function(t){return g(t,this.value)},Jt=function(t){return this.tags.has(t)},Vt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Ct=function(){const{configuration:t,tags:e,machine:n,nextEvents:s,toJSON:i,can:o,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Bt=function(){return V(this,"nextEvents",(()=>[...new Set(b([...this.configuration.map((t=>t.ownEvents))]))]))},zt=function(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Wt(t,e){const n={status:t.status,output:t.output,error:t.error,machine:e,context:t.context,configuration:t.configuration,value:ot(e.root,t.configuration),tags:new Set(b(t.configuration.map((t=>t.tags)))),children:t.children,historyValue:t.historyValue||{},matches:Dt,hasTag:Jt,can:Vt,toJSON:Ct};return Object.defineProperties(n,{nextEvents:{get:Bt,configurable:!0,enumerable:!0},meta:{get:zt,configurable:!0,enumerable:!0}}),n}function Ut(t,e={}){return Wt({...t,...e},t.machine)}function qt(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:M,id:s.id};else{const i=qt(s);i!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=i)}}return e??t}function Gt(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof o){const u=j(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=R(u,{id:r.id,parent:t.self,input:"function"==typeof c?c({context:n,event:s,self:t.self}):c,src:o,systemId:a});return i[f.id]=f,r.syncSnapshot&&f.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${f.id}`,snapshot:e})},error:()=>{}}),f}{const e=R(o,{id:r.id,parent:t.self,input:r.input,src:o,systemId:a});return r.syncSnapshot&&e.subscribe({next:n=>{"active"===n.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:n,id:e.id})},error:()=>{}}),e}})(o,r);return i[a.id]=a,t.defer((()=>{if(a._processingStatus!==N.Stopped)try{a.start?.()}catch(e){return void t.self.send(u(a.id,e))}})),a}}function Qt(t,e,n,s,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:n.event,spawn:Gt(t,e,n.event,o),self:t?.self,system:t?.system};let a={};if("function"==typeof i)a=i(r,s);else for(const t of Object.keys(i)){const e=i[t];a[t]="function"==typeof e?e(r,s):e}return[Ut(e,{context:Object.assign({},e.context,a),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function Ft(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Qt,e}function Xt(t,e,n,s,{branches:i}){const o=i.find((t=>!t.guard||Y(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,w(o)]}function Ht(t,e,n,s,{value:i,label:o}){return[e,{value:"function"==typeof i?i(n,s):i,label:o}]}function Kt({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Lt(t,e,n,s,{get:i}){return[e,void 0,w(i({context:n.context,event:n.event}))]}function Yt(t,e,n,s,{event:i,id:o,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const u="function"==typeof i?i(n,s):i;let f;if("string"==typeof r){const t=c&&c[r];f="function"==typeof t?t(n,s):t}else f="function"==typeof r?r(n,s):r;return"number"!=typeof f&&a.push(u),[e,{event:u,id:o,delay:f}]}function Zt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function te(t,e){function n(t,e){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Yt,n.execute=Zt,n}let ee=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ne(t,e,n,s,{to:i,event:o,id:r,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const f="function"==typeof o?o(n,s):o;let h;if("string"==typeof a){const t=u&&u[a];h="function"==typeof t?t(n,s):t}else h="function"==typeof a?a(n,s):a;const d="function"==typeof i?i(n,s):i;let p;if("string"==typeof d){if(p=d===ee.Parent?t?.self._parent:d===ee.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t?.self;return[e,{to:p,event:f,id:r,delay:h}]}function se(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function ie(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:n,event:s}=e;t?.system._relay(t.self,n,s.type===r?u(t.self.id,s.data):s)})):t.self.delaySend(e)}function oe(t,e,n){function s(t,e){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=ne,s.retryResolve=se,s.execute=ie,s}function re(t,e){return oe(ee.Parent,t,e)}function ae(t,e){return{config:t,transition:(e,n,s)=>({...e,context:t(e.context,n,s)}),getInitialState:(t,n)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:n}):e}),getPersistedState:t=>t,restoreState:t=>t}}const ce="$$xstate.resolve",ue="$$xstate.reject";const fe=ae((t=>{}),void 0);const he={},de=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class pe{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(n),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?x(this.config.states,((t,e)=>new pe(t,{_parent:this,_key:e,_machine:this.machine}))):he,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=w(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===i)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,I(s).map((e=>ut(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,I(t.config.onDone).map((e=>ut(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,I(n.onDone).map((e=>ut(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,I(n.onError).map((e=>ut(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,I(n.onSnapshot).map((e=>ut(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>ut(this,i,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(de),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(de),eventType:null})}:void 0,history:this.history,states:x(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(de)}))),entry:this.entry.map(de),exit:this.exit.map(de),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return V(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,i=t.id||O(this.id,e),o="string"==typeof n?n:`xstate#${O(this.id,e)}`;return{...t,src:o,id:i,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return V(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return V(this,"delayedTransitions",(()=>ct(this)))}get initial(){return V(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type,s=[];let i;const o=V(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||Y(o,a,e,t)}catch(t){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get events(){return V(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class le{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreState=this.restoreState.bind(this),this.start=this.start.bind(this),this.root=new pe(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new le(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=(n=this.root,s=t.value,ot(n,[...nt(gt(n,s))]));var n,s;const i=nt(gt(this.root,e));return Wt({configuration:[...i],context:t.context||{},children:{},status:rt(i,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,n){if(function(t){return t.type.startsWith("xstate.error.actor")}(e)&&!t.nextEvents.some((t=>t===e.type)))return Ut(t,{status:"error",error:e.data});const{state:s}=Nt(t,e,n);return s}microstep(t,e,n){return Nt(t,e,n).microstates}getTransitionData(t,e){return vt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:s}=this.config,i=Wt({context:"function"!=typeof s&&s?s:{},configuration:[this.root],children:{},status:"active"},this);if("function"==typeof s){const o=({spawn:t,event:e})=>s({spawn:t,input:e.input});return Mt(i,e,t,[Ft(o)],n)}return i}getInitialState(t,e){const n=f(e),s=[],i=this.getPreInitialState(t,n,s),o=kt([{target:[...pt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,n,!0,s),{state:r}=Nt(o,n,t,s);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(n),s=e.slice(1),i=at(e[0])?e[0].slice(1):e[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return yt(o,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t,e){return function(t,e){const{configuration:n,tags:s,machine:i,children:o,context:r,can:a,hasTag:c,matches:u,toJSON:f,nextEvents:h,...d}=t,p={};for(const t in o){const n=o[t];p[t]={state:n.getPersistedState(e),src:n.src,systemId:n._systemId}}return{...d,context:qt(r),children:p}}(t,e)}restoreState(t,e){const n={},s=t.children;Object.keys(s).forEach((t=>{const i=s[t],o=i.state,r=i.src,a="string"==typeof r?j(this,r):r;if(!a)return;const c=a.restoreState?.(o,e),u=R(a,{id:t,parent:e?.self,state:c,src:r,systemId:i.systemId});n[t]=u}));const i=Wt({...t,children:n,configuration:Array.from(nt(gt(this.root,t.value)))},this);let o=new Set;return function t(e,n){if(!o.has(e)){o.add(e);for(let s in e){const i=e[s];if(i&&"object"==typeof i){if("xstate$$type"in i&&i.xstate$$type===M){e[s]=n[i.id];continue}t(i,n)}}}}(i.context,n),i}}const ye={timeout:1/0};t.Actor=P,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=ee,t.StateMachine=le,t.StateNode=pe,t.and=function(t){function e(t,e){return!1}return e.check=K,e.guards=t,e},t.assign=Ft,t.cancel=z,t.choose=function(t){function e(t,e){}return e.type="xstate.choose",e.branches=t,e.resolve=Xt,e},t.createActor=R,t.createEmptyActor=function(){return R(fe)},t.createMachine=function(t,e){return new le(t,e)},t.escalate=function(t,e){return re((e=>({type:r,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return oe(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e,system:n})=>{n._relay(e,e,{type:"xstate.create"})},transition:(e,n,{self:s,system:i})=>{if("xstate.create"===n.type){const n=t=>{"stopped"!==e.status&&s._parent&&i._relay(s,s._parent,t)},o=t=>{e._receivers.add(t)};return e._dispose=t({input:e.input,system:i,self:s,sendBack:n,receive:o}),e}return n.type===a?("function"==typeof(e={...e,status:"stopped",error:void 0})._dispose&&e._dispose(),e):(e._receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:e,...n})=>n,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case n:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent&&o._relay(i,i._parent,t)},error:t=>{o._relay(i,i,{type:e,data:t})},complete:()=>{o._relay(i,i,{type:n})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:r,defer:c,system:u})=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,context:i.data};case n:return{...t,status:"error",error:i.data,input:void 0,_subscription:void 0};case s:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i._subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{r._relay(o,o,{type:e,data:t})},error:t=>{r._relay(o,o,{type:n,data:t})},complete:()=>{r._relay(o,o,{type:s})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ce:{const n=e.data;return{...t,status:"done",output:n,input:void 0}}case ue:return{...t,status:"error",error:e.data,input:void 0};case a:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:ce,data:t})}),(t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:ue,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=ae,t.getStateNodes=gt,t.interpret=D,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t,e){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=Ht,n.execute=Kt,n},t.matchesState=g,t.not=function(t){function e(t,e){return!1}return e.check=H,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=L,e.guards=t,e},t.pathToStateValue=_,t.pure=function(t){function e(t,e){}return e.type="xstate.pure",e.get=t,e.resolve=Lt,e},t.raise=te,t.sendParent=re,t.sendTo=oe,t.spawn=q,t.stateIn=function(t){function e(t,e){return!1}return e.check=X,e.stateValue=t,e},t.stop=F,t.toObserver=E,t.waitFor=function(t,e,n){const s={...ye,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const n=".",s="",i="",o="xstate.init",r="xstate.error",a="xstate.stop";function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function f(t){return{type:o,input:t}}function h(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=h();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function g(t,e){const n=m(t),s=m(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&g(n[t],s[t])))}function v(t){try{return k(t)?t:t.split(n)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function m(t){if(Dt(t))return t.value;if("string"!=typeof t)return t;return _(v(t))}function _(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function x(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function b(t){return[].concat(...t)}function S(t){return k(t)?t:[t]}function w(t){return void 0===t?[]:S(t)}function $(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function T(t){if(void 0!==t&&t!==s)return w(t)}function E(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function O(t,e){return`${t}[${e}]`}function j(t,e){if(e.startsWith("xstate#")){const[,n]=e.match(/\[(\d+)\]$/),s=t.getStateNodeById(e.slice(7,-(n.length+2))).config.invoke;return(Array.isArray(s)?s[n]:s).src}return t.implementations.actors[e]}const M=1;let N=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const A={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class P{constructor(t,n){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=N.NotStarted,this._parent=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...A,...n},{clock:i,logger:o,parent:r,id:a,systemId:c,inspect:u}=s;this.system=r?.system??function(t){const e=new Map,n=new Map,s=new WeakMap,i=new Set,o={_bookId:()=>"x:"+y++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const n={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:n}),e._send(n)}};return o}(this),u&&!r&&this.system.inspect(E(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this._systemId=c,this.system._set(c,this)),this._initState(n?.state),c&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,e){let n;for(this._state=t;n=this._deferred.shift();)n();for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,i=this._state.output,{type:`xstate.done.actor.${s}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,u(this.id,this._state.error))}var s,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=E(t,e,n);if(this._processingStatus!==N.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this._processingStatus===N.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=N.Running;const t=f(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(u(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(u(this.id,t))}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===N.Stopped?this:(this.mailbox.clear(),this._processingStatus===N.NotStarted?(this._processingStatus=N.Stopped,this):(this.mailbox.enqueue({type:a}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){p(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_stopProcedure(){if(this._processingStatus!==N.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=N.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==N.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:n,delay:s}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),s);n&&(this.delayedEventsMap[n]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:M,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[l](){return this}getSnapshot(){return this._state}}function R(t,e){return new P(t,e)}const D=R,J=new WeakMap;function V(t,e,n){let s=J.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},J.set(t,s)),s[e]}function C(t,e,n,s,{sendId:i}){return[e,"function"==typeof i?i(n,s):i]}function B(t,e){t.self.cancel(e)}function z(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=B,e}function W(t,e,n,s,{id:i,systemId:o,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?j(e.machine,r):r,f="function"==typeof i?i(n):i;let h;return u&&(h=R(u,{id:f,src:r,parent:t?.self,systemId:o,input:"function"==typeof a?a({context:e.context,event:n.event,self:t?.self}):a}),c&&h.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${i}`,snapshot:e})},error:()=>{}})),[qt(e,{children:{...e.children,[f]:h}}),{id:i,actorRef:h}]}function U(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n._processingStatus!==N.Stopped)try{n.start?.()}catch(n){return void t.self.send(u(e,n))}}))}function q(...[t,{id:e,systemId:n,input:s,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawn",o.id=e,o.systemId=n,o.src=t,o.input=s,o.syncSnapshot=i,o.resolve=W,o.execute=U,o}function G(t,e,n,s,{actorRef:i}){const o="function"==typeof i?i(n,s):i,r="string"==typeof o?e.children[o]:o;let a=e.children;return r&&(a={...a},delete a[r.id]),[qt(e,{children:a}),r]}function Q(t,e){e&&(t.system._unregister(e),e._processingStatus===N.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function F(t){function e(t,e){}return e.type="xstate.stop",e.actorRef=t,e.resolve=G,e.execute=Q,e}function X(t,e,{stateValue:n}){if("string"==typeof n&&at(n)){const e=t.machine.getStateNodeById(n);return t.configuration.some((t=>t===e))}return t.matches(n)}function H(t,{context:e,event:n},{guards:s}){return!Y(s[0],e,n,t)}function K(t,{context:e,event:n},{guards:s}){return s.every((s=>Y(s,e,n,t)))}function L(t,{context:e,event:n},{guards:s}){return s.some((s=>Y(s,e,n,t)))}function Y(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return Y(r,e,n,s);const a={context:e,event:n},c=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:n}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(s,a,r)}const Z=t=>"atomic"===t.type||"final"===t.type;function tt(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function et(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function nt(t){const e=new Set(t),n=new Set(t),s=it(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of tt(t))if("history"!==e.type&&!n.has(e)){const t=dt(e);for(const e of t)n.add(e)}}else dt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function st(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(Z(t))return t.key}const s={};for(const t of n)s[t.key]=st(t,e);return s}function it(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function ot(t,e){return st(t,it(nt(e)))}function rt(t,e){return"compound"===e.type?tt(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?tt(e).every((e=>rt(t,e))):"final"===e.type}const at=t=>"#"===t[0];function ct(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const i=e[n],o="string"==typeof i?{target:i}:i,r=isNaN(+n)?n:+n,a=((e,n)=>{const s=(o="function"==typeof e?`${t.id}:delay[${n}]`:e,r=t.id,{type:`xstate.after(${o})${r?`#${r}`:""}`}),i=s.type;var o,r;return t.entry.push(ee(s,{id:i,delay:e})),t.exit.push(z(i)),i})(r,s);return w(o).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:n}=e;return{...ut(t,e.event,e),delay:n}}))}function ut(t,e,s){const i=T(s.target),o=s.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(at(e))return t.machine.getStateNodeById(e);const s=e[0]===n;if(s&&!t.parent)return yt(t,e.slice(1));const i=s?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return yt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,i),a={...s,actions:w(s.actions),guard:s.guard,target:r,source:t,reenter:o,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ft(t){const e=T(t.config.target);return e?{target:e.map((e=>"string"==typeof e?yt(t.parent,e):e))}:t.parent.initial}function ht(t){return"history"===t.type}function dt(t){const e=pt(t);for(const n of e)for(const s of et(n,t))e.add(s);return e}function pt(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of tt(n))t(e)}(t),e}function lt(t,e){if(at(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function yt(t,e){if("string"==typeof e&&at(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=v(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=lt(s,t)}return s}function gt(t,e){if("string"==typeof e)return[t,t.states[e]];const n=Object.keys(e),s=n.map((e=>lt(t,e))).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce(((n,s)=>{const i=lt(t,s);if(!i)return n;const o=gt(i,e[s]);return n.concat(o)}),[]))}function vt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=lt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=vt(lt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=vt(lt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function mt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function _t(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function xt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function bt(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(xt($t([i],e,n),$t([r],e,n))){if(!_t(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function St(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ht(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of St(ft(s),e))n.add(t);else n.add(s);return[...n]}function wt(t,e){const n=St(t,e);if(!n)return;if(!t.reenter&&n.every((e=>e===t.source||_t(e,t.source))))return t.source;const s=function(t){const[e,...n]=t;for(const t of et(e,void 0))if(n.every((e=>_t(e,t))))return t}(n.concat(t.source));return s||(t.reenter?void 0:t.source.machine.root)}function $t(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=wt(i,n);i.reenter&&i.source===t&&s.add(t);for(const n of e)_t(n,t)&&s.add(n)}return[...s]}function kt(t,e,n,s,i,o){if(!t.length)return e;const r=new Set(e.configuration);let a=e.historyValue;const u=bt(t,r,a);let f=e;i||([f,a]=function(t,e,n,s,i,o,r){let a=t;const c=$t(s,i,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of mt(t)){let n;n="deep"===e.history?e=>Z(e)&&_t(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(i).filter(n)}for(const t of c)a=Mt(a,e,n,[...t.exit,...t.invoke.map((t=>F(t.id)))],r),i.delete(t);return[a,u||o]}(f,s,n,u,r,a,o)),f=Mt(f,s,n,u.flatMap((t=>t.actions)),o),f=function(t,e,n,s,i,o,r,a){let u=t;const f=new Set,h=new Set;(function(t,e,n,s){for(const i of t){const t=wt(i,e);for(const o of i.target||[])ht(o)||i.source===o&&i.source===t&&!i.reenter||(s.add(o),n.add(o)),Tt(o,e,n,s);const o=St(i,e);for(const r of o){const o=et(r,t);"parallel"===t?.type&&o.push(t),Et(s,e,n,o,!i.source.parent&&i.reenter?void 0:t)}}})(s,r,h,f),a&&h.add(t.machine.root);const d=new Set;for(const t of[...f].sort(((t,e)=>t.order-e.order))){i.add(t);const s=[];s.push(...t.entry);for(const e of t.invoke)s.push(q(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(h.has(t)){const e=t.initial.actions;s.push(...e)}if(u=Mt(u,e,n,s,o,t.invoke.map((t=>t.id))),"final"===t.type){const s=t.parent;let r="parallel"===s?.type?s:s?.parent,a=r||t;for("compound"===s?.type&&o.push(c(s.id,t.output?$(t.output,u.context,e,n.self):void 0));"parallel"===r?.type&&!d.has(r)&&rt(i,r);)d.add(r),o.push(c(r.id)),a=r,r=r.parent;if(r)continue;u=qt(u,{status:"done",output:It(u,e,n,u.machine.root,a)})}}return u}(f,s,n,u,r,o,a,i);const h=[...r];"done"===f.status&&(f=Mt(f,s,n,h.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(e.configuration,r)?f:qt(f,{configuration:h,historyValue:a})}catch(t){throw t}}function It(t,e,n,s,i){if(!s.output)return;const o=c(i.id,i.output&&i.parent?$(i.output,t.context,e,n.self):void 0);return $(s.output,t.context,o,n.self)}function Tt(t,e,n,s){if(ht(t))if(e[t.id]){const i=e[t.id];for(const t of i)s.add(t),Tt(t,e,n,s);for(const o of i)Ot(o,t.parent,s,e,n)}else{const i=ft(t);for(const o of i.target)s.add(o),i===t.parent?.initial&&n.add(t.parent),Tt(o,e,n,s);for(const o of i.target)Ot(o,t,s,e,n)}else if("compound"===t.type){const[i]=t.initial.target;ht(i)||(s.add(i),n.add(i)),Tt(i,e,n,s),Ot(i,t,s,e,n)}else if("parallel"===t.type)for(const i of tt(t).filter((t=>!ht(t))))[...s].some((t=>_t(t,i)))||(ht(i)||(s.add(i),n.add(i)),Tt(i,e,n,s))}function Et(t,e,n,s,i){for(const o of s)if(i&&!_t(o,i)||t.add(o),"parallel"===o.type)for(const s of tt(o).filter((t=>!ht(t))))[...t].some((t=>_t(t,s)))||(t.add(s),Tt(s,e,n,t))}function Ot(t,e,n,s,i){Et(n,s,i,et(t,e))}function jt(t,e,n,s,i,o){const{machine:r}=t;let a=t;for(const t of s){const s="function"==typeof t,c=s?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:n?.self,system:n?.system},f=s||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in c)){n?.self._processingStatus===N.Running?c(u,f):n?.defer((()=>{c(u,f)}));continue}const h=c,[d,p,l]=h.resolve(n,a,u,f,c,i);a=d,"retryResolve"in h&&o?.push([h,p]),"execute"in h&&(n?.self._processingStatus===N.Running?h.execute(n,p):n?.defer(h.execute.bind(null,n,p))),l&&(a=jt(a,e,n,l,i,o))}return a}function Mt(t,e,n,s,i,o){const r=o?[]:void 0,a=jt(t,e,n,s,{internalQueue:i,deferredActorIds:o},r);return r?.forEach((([t,e])=>{t.retryResolve(n,a,e)})),a}function Nt(t,e,n,s=[]){let i=t;const r=[];if(e.type===a)return i=qt(At(i,e,n),{status:"stopped"}),r.push(i),{state:i,microstates:r};let c=e;if(c.type!==o){i=kt(Pt(c,i),t,n,c,!1,s),r.push(i)}let u=!0;for(;"active"===i.status;){let t=u?Rt(i,c):[];const e=t.length?i:void 0;if(!t.length){if(!s.length)break;c=s.shift(),t=Pt(c,i)}i=kt(t,i,n,c,!1,s),u=i!==e,r.push(i)}return"active"!==i.status&&At(i,c,n),{state:i,microstates:r}}function At(t,e,n){return Mt(t,e,n,Object.values(t.children).map((t=>F(t))),[])}function Pt(t,e){return e.machine.getTransitionData(e,t)}function Rt(t,e){const n=new Set,s=t.configuration.filter(Z);for(const i of s)t:for(const s of[i].concat(et(i,void 0)))if(s.always)for(const i of s.always)if(void 0===i.guard||Y(i.guard,t.context,e,t)){n.add(i);break t}return bt(Array.from(n),new Set(t.configuration),t.historyValue)}function Dt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Jt=function(t){return g(t,this.value)},Vt=function(t){return this.tags.has(t)},Ct=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Bt=function(){const{configuration:t,tags:e,machine:n,nextEvents:s,toJSON:i,can:o,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},zt=function(){return V(this,"nextEvents",(()=>[...new Set(b([...this.configuration.map((t=>t.ownEvents))]))]))},Wt=function(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Ut(t,e){const n={status:t.status,output:t.output,error:t.error,machine:e,context:t.context,configuration:t.configuration,value:ot(e.root,t.configuration),tags:new Set(b(t.configuration.map((t=>t.tags)))),children:t.children,historyValue:t.historyValue||{},matches:Jt,hasTag:Vt,can:Ct,toJSON:Bt};return Object.defineProperties(n,{nextEvents:{get:zt,configurable:!0,enumerable:!0},meta:{get:Wt,configurable:!0,enumerable:!0}}),n}function qt(t,e={}){return Ut({...t,...e},t.machine)}function Gt(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:M,id:s.id};else{const i=Gt(s);i!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=i)}}return e??t}function Qt(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof o){const u=j(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=R(u,{id:r.id,parent:t.self,input:"function"==typeof c?c({context:n,event:s,self:t.self}):c,src:o,systemId:a});return i[f.id]=f,r.syncSnapshot&&f.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${f.id}`,snapshot:e})},error:()=>{}}),f}{const e=R(o,{id:r.id,parent:t.self,input:r.input,src:o,systemId:a});return r.syncSnapshot&&e.subscribe({next:n=>{"active"===n.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:n,id:e.id})},error:()=>{}}),e}})(o,r);return i[a.id]=a,t.defer((()=>{if(a._processingStatus!==N.Stopped)try{a.start?.()}catch(e){return void t.self.send(u(a.id,e))}})),a}}function Ft(t,e,n,s,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:n.event,spawn:Qt(t,e,n.event,o),self:t?.self,system:t?.system};let a={};if("function"==typeof i)a=i(r,s);else for(const t of Object.keys(i)){const e=i[t];a[t]="function"==typeof e?e(r,s):e}return[qt(e,{context:Object.assign({},e.context,a),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function Xt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ft,e}function Ht(t,e,n,s,{branches:i}){const o=i.find((t=>!t.guard||Y(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,w(o)]}function Kt(t,e,n,s,{value:i,label:o}){return[e,{value:"function"==typeof i?i(n,s):i,label:o}]}function Lt({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Yt(t,e,n,s,{get:i}){return[e,void 0,w(i({context:n.context,event:n.event}))]}function Zt(t,e,n,s,{event:i,id:o,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const u="function"==typeof i?i(n,s):i;let f;if("string"==typeof r){const t=c&&c[r];f="function"==typeof t?t(n,s):t}else f="function"==typeof r?r(n,s):r;return"number"!=typeof f&&a.push(u),[e,{event:u,id:o,delay:f}]}function te(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function ee(t,e){function n(t,e){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Zt,n.execute=te,n}let ne=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function se(t,e,n,s,{to:i,event:o,id:r,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const f="function"==typeof o?o(n,s):o;let h;if("string"==typeof a){const t=u&&u[a];h="function"==typeof t?t(n,s):t}else h="function"==typeof a?a(n,s):a;const d="function"==typeof i?i(n,s):i;let p;if("string"==typeof d){if(p=d===ne.Parent?t?.self._parent:d===ne.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t?.self;return[e,{to:p,event:f,id:r,delay:h}]}function ie(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function oe(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:n,event:s}=e;t?.system._relay(t.self,n,s.type===r?u(t.self.id,s.data):s)})):t.self.delaySend(e)}function re(t,e,n){function s(t,e){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=se,s.retryResolve=ie,s.execute=oe,s}function ae(t,e){return re(ne.Parent,t,e)}function ce(t,e){return{config:t,transition:(e,n,s)=>({...e,context:t(e.context,n,s)}),getInitialState:(t,n)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:n}):e}),getPersistedState:t=>t,restoreState:t=>t}}const ue="$$xstate.resolve",fe="$$xstate.reject";const he=ce((t=>{}),void 0);const de={},pe=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class le{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(n),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?x(this.config.states,((t,e)=>new le(t,{_parent:this,_key:e,_machine:this.machine}))):de,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=w(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===i)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,I(s).map((e=>ut(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,I(t.config.onDone).map((e=>ut(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,I(n.onDone).map((e=>ut(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,I(n.onError).map((e=>ut(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,I(n.onSnapshot).map((e=>ut(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>ut(this,i,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(pe),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(pe),eventType:null})}:void 0,history:this.history,states:x(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(pe)}))),entry:this.entry.map(pe),exit:this.exit.map(pe),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return V(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,i=t.id||O(this.id,e),o="string"==typeof n?n:`xstate#${O(this.id,e)}`;return{...t,src:o,id:i,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return V(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return V(this,"delayedTransitions",(()=>ct(this)))}get initial(){return V(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type,s=[];let i;const o=V(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||Y(o,a,e,t)}catch(t){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get events(){return V(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class ye{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreState=this.restoreState.bind(this),this.start=this.start.bind(this),this.root=new le(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new ye(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=(n=this.root,s=t.value,ot(n,[...nt(gt(n,s))]));var n,s;const i=nt(gt(this.root,e));return Ut({configuration:[...i],context:t.context||{},children:{},status:rt(i,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,n){if(function(t){return t.type.startsWith("xstate.error.actor")}(e)&&!t.nextEvents.some((t=>t===e.type)))return qt(t,{status:"error",error:e.data});const{state:s}=Nt(t,e,n);return s}microstep(t,e,n){return Nt(t,e,n).microstates}getTransitionData(t,e){return vt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:s}=this.config,i=Ut({context:"function"!=typeof s&&s?s:{},configuration:[this.root],children:{},status:"active"},this);if("function"==typeof s){const o=({spawn:t,event:e})=>s({spawn:t,input:e.input});return Mt(i,e,t,[Xt(o)],n)}return i}getInitialState(t,e){const n=f(e),s=[],i=this.getPreInitialState(t,n,s),o=kt([{target:[...pt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,n,!0,s),{state:r}=Nt(o,n,t,s);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(n),s=e.slice(1),i=at(e[0])?e[0].slice(1):e[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return yt(o,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t,e){return function(t,e){const{configuration:n,tags:s,machine:i,children:o,context:r,can:a,hasTag:c,matches:u,toJSON:f,nextEvents:h,...d}=t,p={};for(const t in o){const n=o[t];p[t]={state:n.getPersistedState(e),src:n.src,systemId:n._systemId}}return{...d,context:Gt(r),children:p}}(t,e)}restoreState(t,e){const n={},s=t.children;Object.keys(s).forEach((t=>{const i=s[t],o=i.state,r=i.src,a="string"==typeof r?j(this,r):r;if(!a)return;const c=a.restoreState?.(o,e),u=R(a,{id:t,parent:e?.self,state:c,src:r,systemId:i.systemId});n[t]=u}));const i=Ut({...t,children:n,configuration:Array.from(nt(gt(this.root,t.value)))},this);let o=new Set;return function t(e,n){if(!o.has(e)){o.add(e);for(let s in e){const i=e[s];if(i&&"object"==typeof i){if("xstate$$type"in i&&i.xstate$$type===M){e[s]=n[i.id];continue}t(i,n)}}}}(i.context,n),i}}const ge={timeout:1/0};t.Actor=P,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=ne,t.StateMachine=ye,t.StateNode=le,t.and=function(t){function e(t,e){return!1}return e.check=K,e.guards=t,e},t.assign=Xt,t.cancel=z,t.choose=function(t){function e(t,e){}return e.type="xstate.choose",e.branches=t,e.resolve=Ht,e},t.createActor=R,t.createEmptyActor=function(){return R(he)},t.createMachine=function(t,e){return new ye(t,e)},t.escalate=function(t,e){return ae((e=>({type:r,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return re(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e,system:n})=>{n._relay(e,e,{type:"xstate.create"})},transition:(e,n,{self:s,system:i})=>{if("xstate.create"===n.type){const n=t=>{"stopped"!==e.status&&s._parent&&i._relay(s,s._parent,t)},o=t=>{e._receivers.add(t)};return e._dispose=t({input:e.input,system:i,self:s,sendBack:n,receive:o}),e}return n.type===a?("function"==typeof(e={...e,status:"stopped",error:void 0})._dispose&&e._dispose(),e):(e._receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:e,...n})=>n,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case n:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent&&o._relay(i,i._parent,t)},error:t=>{o._relay(i,i,{type:e,data:t})},complete:()=>{o._relay(i,i,{type:n})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:r,defer:c,system:u})=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,context:i.data};case n:return{...t,status:"error",error:i.data,input:void 0,_subscription:void 0};case s:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i._subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{r._relay(o,o,{type:e,data:t})},error:t=>{r._relay(o,o,{type:n,data:t})},complete:()=>{r._relay(o,o,{type:s})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ue:{const n=e.data;return{...t,status:"done",output:n,input:void 0}}case fe:return{...t,status:"error",error:e.data,input:void 0};case a:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:ue,data:t})}),(t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:fe,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=ce,t.getStateNodes=gt,t.interpret=D,t.isMachineSnapshot=Dt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t,e){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=Kt,n.execute=Lt,n},t.matchesState=g,t.not=function(t){function e(t,e){return!1}return e.check=H,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=L,e.guards=t,e},t.pathToStateValue=_,t.pure=function(t){function e(t,e){}return e.type="xstate.pure",e.get=t,e.resolve=Yt,e},t.raise=ee,t.sendParent=ae,t.sendTo=re,t.spawn=q,t.stateIn=function(t){function e(t,e){return!1}return e.check=X,e.stateValue=t,e},t.stop=F,t.toObserver=E,t.waitFor=function(t,e,n){const s={...ge,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate.umd.min.js.map