Socket
Socket
Sign inDemoInstall

xstate

Package Overview
Dependencies
Maintainers
3
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xstate - npm Package Compare versions

Comparing version 5.4.1 to 5.5.0

dist/declarations/src/getNextSnapshot.d.ts

4

actions/dist/xstate-actions.cjs.js

@@ -5,4 +5,4 @@ 'use strict';

var log = require('../../dist/log-2580e864.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-5c58eb8e.cjs.js');
var log = require('../../dist/log-742895c6.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-ad8bb7c2.cjs.js');
require('../../dev/dist/xstate-dev.cjs.js');

@@ -9,0 +9,0 @@

@@ -5,4 +5,4 @@ 'use strict';

var log = require('../../dist/log-18eb632d.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-3d3d6d51.development.cjs.js');
var log = require('../../dist/log-da322832.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-7af39710.development.cjs.js');
require('../../dev/dist/xstate-dev.development.cjs.js');

@@ -9,0 +9,0 @@

@@ -1,3 +0,3 @@

export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-11038f00.development.esm.js';
export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-057d17af.development.esm.js';
export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-285f62db.development.esm.js';
export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-8da27ebb.development.esm.js';
import '../../dev/dist/xstate-dev.development.esm.js';

@@ -1,3 +0,3 @@

export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-88b333eb.esm.js';
export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-3b380e4b.esm.js';
export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-22b3587f.esm.js';
export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-0e64ee6e.esm.js';
import '../../dev/dist/xstate-dev.esm.js';

@@ -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="undefined"!=typeof globalThis?globalThis:t||self).XStateActions={})}(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 s=".",n="xstate.error",o="xstate.stop";function i(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const r=t=>{const e=i();e&&e.register(t)};function c(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function a(t){setTimeout((()=>{throw t}))}const h="function"==typeof Symbol&&Symbol.observable||"@@observable";function u(t,e){return`${t.sessionId}.${e}`}let d=0;function p(t,e){const s=f(t),n=f(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&p(s[t],n[t])))}function l(t){return e=t,Array.isArray(e)?t:t.split(s);var e}function f(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;return function(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}(l(t))}function y(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function _(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}let v=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const g={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class m{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.observers=new Set,this.logger=void 0,this._processingStatus=v.NotStarted,this._parent=void 0,this._syncSnapshot=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 n={...g,...s},{clock:o,logger:i,parent:r,syncSnapshot:c,id:a,systemId:h,inspect:p}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},c=e.clock,a={schedule:(t,e,s,n,o=Math.random().toString(36).slice(2))=>{const i={source:t,target:e,event:s,delay:n,id:o,startedAt:Date.now()},a=u(t,o);h._snapshot._scheduledEvents[a]=i;const d=c.setTimeout((()=>{delete r[a],delete h._snapshot._scheduledEvents[a],h._relay(t,e,s)}),n);r[a]=d},cancel:(t,e)=>{const s=u(t,e),n=r[s];delete r[s],delete h._snapshot._scheduledEvents[s],c.clearTimeout(n)},cancelAll:t=>{for(const e in h._snapshot._scheduledEvents){const s=h._snapshot._scheduledEvents[e];s.source===t&&a.cancel(t,s.id)}}},h={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+d++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const e=o.get(t);void 0!==e&&(n.delete(e),o.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const s=n.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),o.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)},scheduler:a,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const t=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:n,event:o,delay:i,id:r}=t[e];a.schedule(s,n,o,i,r)}}};return h}(this,{clock:o}),p&&!r&&this.system.inspect(y(p)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=c,this.options=n,this.src=n.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}),h&&(this._systemId=h,this.system._set(h,this)),this._initState(s?.snapshot??s?.state),h&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=y(t,e,s);if(this._processingStatus!==v.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){a(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){a(t)}else a(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===v.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=v.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===o&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===v.Stopped?this:(this.mailbox.clear(),this._processingStatus===v.NotStarted?(this._processingStatus=v.Stopped,this):(this.mailbox.enqueue({type:o}),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){a(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,c(this.id,t))}_stopProcedure(){return this._processingStatus!==v.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=v.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==v.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:r)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[h](){return this}getSnapshot(){return this._snapshot}}function b(t,e){return new m(t,e)}function x(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function S(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function w(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=x,e.execute=S,e}function I(t,e,s,n,{id:o,systemId:i,src:r,input:c,syncSnapshot:a}){const h="string"==typeof r?_(e.machine,r):r,u="function"==typeof o?o(s):o;let d;return h&&(d=b(h,{id:u,src:r,parent:t?.self,syncSnapshot:a,systemId:i,input:"function"==typeof c?c({context:e.context,event:s.event,self:t?.self}):c})),[G(e,{children:{...e.children,[u]:d}}),{id:o,actorRef:d}]}function E(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==v.Stopped&&s.start()}))}function T(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=I,i.execute=E,i}function k(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let c=e.children;return r&&(c={...c},delete c[r.id]),[G(e,{children:c}),r]}function R(t,e){e&&(t.system._unregister(e),e._processingStatus===v.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function $(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=k,e.execute=R,e}const A=$;function j(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return j(r,e,s,n);const c={context:e,event:s},a=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const C=t=>"atomic"===t.type||"final"===t.type;function O(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function P(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function M(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(C(t))return t.key}const n={};for(const t of s)n[t.key]=M(t,e);return n}function N(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function q(t,e){const s=function(t){const e=new Set(t),s=N(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of O(t))if("history"!==s.type&&!e.has(s)){const t=D(s);for(const s of t)e.add(s)}}else D(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}(e);return M(t,N(s))}function D(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of O(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of P(s,t))e.add(n);return e}const J=function(t){return p(t,this.value)},V=function(t){return this.tags.has(t)},W=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},z=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}},B=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function G(t,e={}){return function(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:q(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:J,hasTag:V,can:W,getMeta:B,toJSON:z}}({...t,...e},t.machine)}function Q(t,{machine:e,context:s},n,o){return(i,r)=>{const c=((i,r={})=>{const{systemId:c,input:a}=r;if("string"==typeof i){const h=_(e,i);if(!h)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const u=b(h,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof a?a({context:s,event:n,self:t.self}):a,src:i,systemId:c});return o[u.id]=u,u}return b(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:c})})(i,r);return o[c.id]=c,t.defer((()=>{c._processingStatus!==v.Stopped&&c.start()})),c}}function U(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Q(t,e,s.event,i),self:t?.self,system:t?.system};let c={};if("function"==typeof o)c=o(r,n);else for(const t of Object.keys(o)){const e=o[t];c[t]="function"==typeof e?e(r,n):e}return[G(e,{context:Object.assign({},e.context,c),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function X(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=U,e}function F(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const h="function"==typeof o?o(s,n):o;let u;if("string"==typeof r){const t=a&&a[r];u="function"==typeof t?t(s,n):t}else u="function"==typeof r?r(s,n):r;return"number"!=typeof u&&c.push(h),[e,{event:h,id:i,delay:u}]}function H(t,e){const{event:s,delay:n,id:o}=e;"number"!=typeof n||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,s,n,o)}))}function K(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=F,s.execute=H,s}let L=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Y(t,e,s,n,{to:o,event:i,id:r,delay:c},a){const h=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const u="function"==typeof i?i(s,n):i;let d;if("string"==typeof c){const t=h&&h[c];d="function"==typeof t?t(s,n):t}else d="function"==typeof c?c(s,n):c;const p="function"==typeof o?o(s,n):o;let l;if("string"==typeof p){if(l=p===L.Parent?t?.self._parent:p===L.Internal?t?.self:p.startsWith("#_")?e.children[p.slice(2)]:a.deferredActorIds?.includes(p)?p:e.children[p],!l)throw new Error(`Unable to send event to actor '${p}' from machine '${e.machine.id}'.`)}else l=p||t?.self;return[e,{to:l,event:u,id:r,delay:d}]}function Z(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function tt(t,e){t.defer((()=>{const{to:s,event:o,delay:i,id:r}=e;"number"!=typeof i?t.system._relay(t.self,s,o.type===n?c(t.self.id,o.data):o):t.system.scheduler.schedule(t.self,s,o,i,r)}))}function et(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Y,n.retryResolve=Z,n.execute=tt,n}function st(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(X(...t))},r.cancel=(...t)=>{i.push(w(...t))},r.raise=(...t)=>{i.push(K(...t))},r.sendTo=(...t)=>{i.push(et(...t))},r.spawnChild=(...t)=>{i.push(T(...t))},r.stopChild=(...t)=>{i.push($(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>j(t,e.context,s.event,e),self:t.self,system:t.system}),[e,void 0,i]}function nt(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ot({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=X,t.cancel=w,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=st,e},t.forwardTo=function(t,e){return et(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=nt,s.execute=ot,s},t.raise=K,t.sendParent=function(t,e){return et(L.Parent,t,e)},t.sendTo=et,t.spawnChild=T,t.stop=A,t.stopChild=$,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="undefined"!=typeof globalThis?globalThis:t||self).XStateActions={})}(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 s=".",n="xstate.error",o="xstate.stop";function i(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const r=t=>{const e=i();e&&e.register(t)};function c(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function a(t){setTimeout((()=>{throw t}))}const h="function"==typeof Symbol&&Symbol.observable||"@@observable";function u(t,e){return`${t.sessionId}.${e}`}let d=0;function p(t,e){const s=f(t),n=f(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&p(s[t],n[t])))}function l(t){return e=t,Array.isArray(e)?t:t.split(s);var e}function f(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;return function(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}(l(t))}function y(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function _(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}let v=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const g={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class m{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.observers=new Set,this.logger=void 0,this._processingStatus=v.NotStarted,this._parent=void 0,this._syncSnapshot=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 n={...g,...s},{clock:o,logger:i,parent:r,syncSnapshot:c,id:a,systemId:h,inspect:p}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},c=e.clock,a={schedule:(t,e,s,n,o=Math.random().toString(36).slice(2))=>{const i={source:t,target:e,event:s,delay:n,id:o,startedAt:Date.now()},a=u(t,o);h._snapshot._scheduledEvents[a]=i;const d=c.setTimeout((()=>{delete r[a],delete h._snapshot._scheduledEvents[a],h._relay(t,e,s)}),n);r[a]=d},cancel:(t,e)=>{const s=u(t,e),n=r[s];delete r[s],delete h._snapshot._scheduledEvents[s],c.clearTimeout(n)},cancelAll:t=>{for(const e in h._snapshot._scheduledEvents){const s=h._snapshot._scheduledEvents[e];s.source===t&&a.cancel(t,s.id)}}},h={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+d++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const e=o.get(t);void 0!==e&&(n.delete(e),o.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const s=n.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),o.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)},scheduler:a,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const t=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:n,event:o,delay:i,id:r}=t[e];a.schedule(s,n,o,i,r)}}};return h}(this,{clock:o}),p&&!r&&this.system.inspect(y(p)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=c,this.options=n,this.src=n.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}),h&&(this._systemId=h,this.system._set(h,this)),this._initState(s?.snapshot??s?.state),h&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=y(t,e,s);if(this._processingStatus!==v.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){a(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){a(t)}else a(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===v.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=v.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===o&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===v.Stopped?this:(this.mailbox.clear(),this._processingStatus===v.NotStarted?(this._processingStatus=v.Stopped,this):(this.mailbox.enqueue({type:o}),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){a(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,c(this.id,t))}_stopProcedure(){return this._processingStatus!==v.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=v.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==v.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:r)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[h](){return this}getSnapshot(){return this._snapshot}}function b(t,e){return new m(t,e)}function x(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function S(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function w(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=x,e.execute=S,e}function I(t,e,s,n,{id:o,systemId:i,src:r,input:c,syncSnapshot:a}){const h="string"==typeof r?_(e.machine,r):r,u="function"==typeof o?o(s):o;let d;return h&&(d=b(h,{id:u,src:r,parent:t.self,syncSnapshot:a,systemId:i,input:"function"==typeof c?c({context:e.context,event:s.event,self:t.self}):c})),[G(e,{children:{...e.children,[u]:d}}),{id:o,actorRef:d}]}function E(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==v.Stopped&&s.start()}))}function T(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=I,i.execute=E,i}function k(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let c=e.children;return r&&(c={...c},delete c[r.id]),[G(e,{children:c}),r]}function R(t,e){e&&(t.system._unregister(e),e._processingStatus===v.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function $(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=k,e.execute=R,e}const A=$;function j(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return j(r,e,s,n);const c={context:e,event:s},a=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const C=t=>"atomic"===t.type||"final"===t.type;function O(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function P(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function M(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(C(t))return t.key}const n={};for(const t of s)n[t.key]=M(t,e);return n}function N(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function q(t,e){const s=function(t){const e=new Set(t),s=N(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of O(t))if("history"!==s.type&&!e.has(s)){const t=D(s);for(const s of t)e.add(s)}}else D(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}(e);return M(t,N(s))}function D(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of O(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of P(s,t))e.add(n);return e}const J=function(t){return p(t,this.value)},V=function(t){return this.tags.has(t)},W=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},z=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}},B=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function G(t,e={}){return function(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:q(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:J,hasTag:V,can:W,getMeta:B,toJSON:z}}({...t,...e},t.machine)}function Q(t,{machine:e,context:s},n,o){return(i,r)=>{const c=((i,r={})=>{const{systemId:c,input:a}=r;if("string"==typeof i){const h=_(e,i);if(!h)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const u=b(h,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof a?a({context:s,event:n,self:t.self}):a,src:i,systemId:c});return o[u.id]=u,u}return b(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:c})})(i,r);return o[c.id]=c,t.defer((()=>{c._processingStatus!==v.Stopped&&c.start()})),c}}function U(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Q(t,e,s.event,i),self:t.self,system:t.system};let c={};if("function"==typeof o)c=o(r,n);else for(const t of Object.keys(o)){const e=o[t];c[t]="function"==typeof e?e(r,n):e}return[G(e,{context:Object.assign({},e.context,c),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function X(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=U,e}function F(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const h="function"==typeof o?o(s,n):o;let u;if("string"==typeof r){const t=a&&a[r];u="function"==typeof t?t(s,n):t}else u="function"==typeof r?r(s,n):r;return"number"!=typeof u&&c.push(h),[e,{event:h,id:i,delay:u}]}function H(t,e){const{event:s,delay:n,id:o}=e;"number"!=typeof n||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,s,n,o)}))}function K(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=F,s.execute=H,s}let L=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Y(t,e,s,n,{to:o,event:i,id:r,delay:c},a){const h=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const u="function"==typeof i?i(s,n):i;let d;if("string"==typeof c){const t=h&&h[c];d="function"==typeof t?t(s,n):t}else d="function"==typeof c?c(s,n):c;const p="function"==typeof o?o(s,n):o;let l;if("string"==typeof p){if(l=p===L.Parent?t.self._parent:p===L.Internal?t.self:p.startsWith("#_")?e.children[p.slice(2)]:a.deferredActorIds?.includes(p)?p:e.children[p],!l)throw new Error(`Unable to send event to actor '${p}' from machine '${e.machine.id}'.`)}else l=p||t.self;return[e,{to:l,event:u,id:r,delay:d}]}function Z(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function tt(t,e){t.defer((()=>{const{to:s,event:o,delay:i,id:r}=e;"number"!=typeof i?t.system._relay(t.self,s,o.type===n?c(t.self.id,o.data):o):t.system.scheduler.schedule(t.self,s,o,i,r)}))}function et(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Y,n.retryResolve=Z,n.execute=tt,n}function st(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(X(...t))},r.cancel=(...t)=>{i.push(w(...t))},r.raise=(...t)=>{i.push(K(...t))},r.sendTo=(...t)=>{i.push(et(...t))},r.spawnChild=(...t)=>{i.push(T(...t))},r.stopChild=(...t)=>{i.push($(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>j(t,e.context,s.event,e),self:t.self,system:t.system}),[e,void 0,i]}function nt(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ot({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=X,t.cancel=w,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=st,e},t.forwardTo=function(t,e){return et(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=nt,s.execute=ot,s},t.raise=K,t.sendParent=function(t,e){return et(L.Parent,t,e)},t.sendTo=et,t.spawnChild=T,t.stop=A,t.stopChild=$,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=xstate-actions.umd.min.js.map

@@ -5,3 +5,3 @@ 'use strict';

var guards_dist_xstateGuards = require('../../dist/raise-5c58eb8e.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-ad8bb7c2.cjs.js');
require('../../dev/dist/xstate-dev.cjs.js');

@@ -8,0 +8,0 @@

@@ -5,3 +5,3 @@ 'use strict';

var guards_dist_xstateGuards = require('../../dist/raise-3d3d6d51.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-7af39710.development.cjs.js');
require('../../dev/dist/xstate-dev.development.cjs.js');

@@ -8,0 +8,0 @@

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

import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-057d17af.development.esm.js';
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-8da27ebb.development.esm.js';
import '../../dev/dist/xstate-dev.development.esm.js';

@@ -3,0 +3,0 @@

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

import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-3b380e4b.esm.js';
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-0e64ee6e.esm.js';
import '../../dev/dist/xstate-dev.esm.js';

@@ -3,0 +3,0 @@

@@ -13,5 +13,32 @@ import { Spawner } from "../spawn.js";

*
* @param assignment An object that represents the partial context to update.
* @param assignment An object that represents the partial context to update, or a
* function that returns an object that represents the partial context to update.
*
* @example
```ts
import { createMachine, assign } from 'xstate';
const countMachine = createMachine({
context: {
count: 0,
message: ''
},
on: {
inc: {
actions: assign({
count: ({ context }) => context.count + 1
})
},
updateMessage: {
actions: assign(({ context, event }) => {
return {
message: event.message.trim()
}
})
}
}
});
```
*/
export declare function assign<TContext extends MachineContext, TExpressionEvent extends AnyEventObject = AnyEventObject, // TODO: consider using a stricter `EventObject` here
TParams extends ParameterizedObject['params'] | undefined = ParameterizedObject['params'] | undefined, TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor>): AssignAction<TContext, TExpressionEvent, TParams, TEvent, TActor>;

@@ -7,9 +7,28 @@ import { EventObject, MachineContext, ActionArgs, ParameterizedObject } from "../types.js";

/**
* Cancels an in-flight `send(...)` action. A canceled sent action will not
* be executed, nor will its event be sent, unless it has already been sent
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The canceled `sendTo(...)` action
* will not send its event or execute, unless the `delay` has already elapsed before `cancel(...)` is called.
*
* @param sendId The `id` of the `send(...)` action to cancel.
* @param sendId The `id` of the `sendTo(...)` action to cancel.
*
* @example
```ts
import { createMachine, sendTo, cancel } from 'xstate';
const machine = createMachine({
// ...
on: {
sendEvent: {
actions: sendTo('some-actor', { type: 'someEvent' }, {
id: 'some-id',
delay: 1000
})
},
cancelEvent: {
actions: cancel('some-id')
}
}
});
```
*/
export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject>(sendId: ResolvableSendId<TContext, TExpressionEvent, TParams, TEvent>): CancelAction<TContext, TExpressionEvent, TParams, TEvent>;
export {};

@@ -31,3 +31,23 @@ import { Guard } from "../guards.js";

type CollectActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = ({ context, event, check, enqueue, self }: CollectActionsArg<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>) => void;
/**
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
*
* @example
```ts
import { createMachine, enqueueActions } from 'xstate';
const machine = createMachine({
entry: enqueueActions(({ enqueue, check }) => {
enqueue.assign({ count: 0 });
if (check('someGuard')) {
enqueue.assign({ count: 1 });
}
enqueue('someAction');
})
})
```
*/
export declare function enqueueActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string>(collect: CollectActions<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>): EnqueueActionsAction<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
export {};

@@ -25,5 +25,5 @@ import { ActionArgs, ActorRef, AnyActorRef, AnyEventObject, Cast, EventFrom, EventObject, InferEvent, MachineContext, NoInfer, ParameterizedObject, SendExpr, SendToActionOptions } from "../types.js";

/**
* Forwards (sends) an event to a specified service.
* Forwards (sends) an event to the `target` actor.
*
* @param target The target service to forward the event to.
* @param target The target actor to forward the event to.
* @param options Options to pass into the send action creator.

@@ -30,0 +30,0 @@ */

@@ -37,3 +37,2 @@ import { symbolObservable } from "./symbolObservable.js";

_parent?: ActorRef<any, any>;
_syncSnapshot?: boolean;
ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>;

@@ -40,0 +39,0 @@ private _actorScope;

@@ -18,4 +18,44 @@ import { StateMachine } from "./StateMachine.js";

} : never);
/**
* Creates a state machine (statechart) with the given configuration.
*
* The state machine represents the pure logic of a state machine actor.
*
* @param config The state machine configuration.
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
*
* @example
```ts
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
```
*/
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, 'matchesStates' extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
export {};

@@ -29,3 +29,59 @@ import type { EventObject, StateValue, MachineContext, ParameterizedObject, AnyMachineSnapshot, NoRequiredParams, NoInfer, WithDynamicParams, Identity, Elements } from "./types.js";

export declare function stateIn<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined>(stateValue: StateValue): GuardPredicate<TContext, TExpressionEvent, TParams, any>;
/**
* Higher-order guard that evaluates to `true` if the `guard` passed to it evaluates to `false`.
*
* @category Guards
* @example
```ts
import { setup, not } from 'xstate';
const machine = setup({
guards: {
someNamedGuard: () => false
}
}).createMachine({
on: {
someEvent: {
guard: not('someNamedGuard'),
actions: () => {
// will be executed if guard in `not(...)`
// evaluates to `false`
}
}
}
});
```
* @returns A guard
*/
export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg>(guard: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg>): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArg<NoInfer<TArg>>>;
/**
* Higher-order guard that evaluates to `true` if all `guards` passed to it
* evaluate to `true`.
*
* @category Guards
* @example
```ts
import { setup, and } from 'xstate';
const machine = setup({
guards: {
someNamedGuard: () => true
}
}).createMachine({
on: {
someEvent: {
guard: and([
({ context }) => context.value > 0,
'someNamedGuard'
]),
actions: () => {
// will be executed if all guards in `and(...)`
// evaluate to true
}
}
}
});
```
* @returns A guard action object
*/
export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [

@@ -36,2 +92,32 @@ ...{

]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<NoInfer<TArg>>>;
/**
* Higher-order guard that evaluates to `true` if any of the `guards` passed to it
* evaluate to `true`.
*
* @category Guards
* @example
```ts
import { setup, or } from 'xstate';
const machine = setup({
guards: {
someNamedGuard: () => true
}
}).createMachine({
on: {
someEvent: {
guard: or([
({ context }) => context.value > 0,
'someNamedGuard'
]),
actions: () => {
// will be executed if any of the guards in `or(...)`
// evaluate to true
}
}
}
});
```
* @returns A guard action object
*/
export declare function or<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [

@@ -38,0 +124,0 @@ ...{

@@ -12,2 +12,3 @@ export * from "./actions.js";

import { createMachine } from "./createMachine.js";
export { getNextSnapshot } from "./getNextSnapshot.js";
import { Actor, createActor, interpret, Interpreter } from "./createActor.js";

@@ -14,0 +15,0 @@ import { StateNode } from "./StateNode.js";

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

import { ActorRefFrom, AnyActorScope, AnyActorLogic, AnyActorRef, AnyEventObject, AnyMachineSnapshot, InputFrom, IsLiteralString, ProvidedActor, RequiredActorOptions, IsNotNever, ConditionalRequired } from "./types.js";
import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {

@@ -20,3 +20,3 @@ src: TSrc;

systemId?: string;
input?: unknown;
input?: TLogic extends string ? unknown : InputFrom<TLogic>;
syncSnapshot?: boolean;

@@ -23,0 +23,0 @@ }) => TLogic extends string ? AnyActorRef : ActorRefFrom<TLogic>;

@@ -9,5 +9,32 @@ import type { StateNode } from "./StateNode.js";

interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, _TUnusedButLeftForCompatReasons = never> {
/**
* The state machine that produced this state snapshot.
*/
machine: StateMachine<TContext, TEvent, TChildren, ProvidedActor, ParameterizedObject, ParameterizedObject, string, TStateValue, TTag, unknown, TOutput>;
/**
* The tags of the active state nodes that represent the current state value.
*/
tags: Set<string>;
/**
* The current state value.
*
* This represents the active state nodes in the state machine.
* - For atomic state nodes, it is a string.
* - For compound parent state nodes, it is an object where:
* - The key is the parent state node's key
* - The value is the current state value of the active child state node(s)
*
* @example
```ts
// single-level state node
snapshot.value; // => 'yellow'
// nested state nodes
snapshot.value; // => { red: 'wait' }
```
*/
value: TStateValue;
/**
* The current status of this snapshot.
*/
status: 'active' | 'done' | 'error' | 'stopped';

@@ -26,6 +53,6 @@ error: unknown;

/**
* Whether the current state value is a subset of the given parent state value.
* @param testValue
* Whether the current state value is a subset of the given partial state value.
* @param partialStateValue
*/
matches: (this: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, testValue: ToTestStateValue<TStateValue>) => boolean;
matches: (this: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, partialStateValue: ToTestStateValue<TStateValue>) => boolean;
/**

@@ -32,0 +59,0 @@ * Whether the current state nodes has a state node with the specified `tag`.

@@ -18,4 +18,2 @@ import { MachineSnapshot } from "./State.js";

implementations: MachineImplementationsSimplified<TContext, TEvent>;
__xstatenode: true;
idMap: Map<string, StateNode<TContext, TEvent>>;
root: StateNode<TContext, TEvent>;

@@ -82,4 +80,6 @@ id: string;

restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>;
/** @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons */
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
__TResolvedTypesMeta: TResolvedTypesMeta;
}

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

import { MachineSnapshot } from "./State.js";
import type { StateMachine } from "./StateMachine.js";

@@ -102,3 +101,2 @@ import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, InvokeDefinition, MachineContext, Mapper, StateNodeConfig, StateNodeDefinition, StateNodesConfig, TransitionDefinition, TransitionDefinitionMap, TODO, UnknownAction, ParameterizedObject, AnyStateMachine, ProvidedActor, NonReducibleUnknown, EventDescriptor } from "./types.js";

TODO>, options: StateNodeOptions<TContext, TEvent>);
_initialize(): void;
/**

@@ -108,3 +106,2 @@ * The well-structured state node definition.

get definition(): StateNodeDefinition<TContext, TEvent>;
toJSON(): StateNodeDefinition<TContext, TEvent>;
/**

@@ -120,3 +117,2 @@ * The logic invoked as actors by this state node.

get initial(): InitialTransitionDefinition<TContext, TEvent>;
next(snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): TransitionDefinition<TContext, TEvent>[] | undefined;
/**

@@ -123,0 +119,0 @@ * All the event types accepted by this state node and its descendants.

import { EventObject, IndexByType, IsNever, Prop, ParameterizedObject, ProvidedActor, OutputFrom, AnyActorLogic, IndexByProp } from "./types.js";
/**
* @deprecated
*/
export interface TypegenDisabled {
'@@xstate/typegen': false;
}
/**
* @deprecated
*/
export interface TypegenEnabled {
'@@xstate/typegen': true;
}
/**
* @deprecated
*/
export interface TypegenMeta extends TypegenEnabled {

@@ -80,2 +89,5 @@ /**

}
/**
* @deprecated
*/
export interface ResolvedTypegenMeta extends TypegenMeta {

@@ -90,2 +102,5 @@ resolved: TypegenMeta & {

}
/**
* @deprecated
*/
export type TypegenConstraint = TypegenEnabled | TypegenDisabled;

@@ -96,2 +111,5 @@ /**

export type AreAllImplementationsAssumedToBeProvided<_TResolvedTypesMeta, _TMissingImplementations> = true;
/**
* @deprecated
*/
interface AllImplementationsProvided {

@@ -120,2 +138,5 @@ missingImplementations: {

} : never;
/**
* @deprecated
*/
export interface ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string> {

@@ -122,0 +143,0 @@ '@@xstate/typegen': TTypesMeta['@@xstate/typegen'];

@@ -6,3 +6,3 @@ import type { MachineSnapshot } from "./State.js";

import { PromiseActorLogic } from "./actors/promise.js";
import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
import { Guard, UnknownGuard } from "./guards.js";
import type { Actor } from "./createActor.js";

@@ -387,18 +387,4 @@ import { Spawner } from "./spawn.js";

};
type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
[K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
type: K;
} ? TGuard : never>, TGuard>;
};
export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
guards: GuardMap<TContext, TEvent, TGuard>;
actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
actors: Record<string, AnyActorLogic | {
src: AnyActorLogic;
input: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
}>;
delays: DelayFunctionMap<TContext, TEvent, TAction>;
}
type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedEvents, K extends keyof TCausingLookup ? TCausingLookup[K] : TIndexedEvents[keyof TIndexedEvents]>, EventObject>;

@@ -593,5 +579,6 @@ type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {

/**
* Specifies the logger to be used for log(...) actions. Defaults to the native console.log method.
* Specifies the logger to be used for `log(...)` actions. Defaults to the native `console.log(...)` method.
*/
logger?: (...args: any[]) => void;
parent?: ActorRef<any, any>;
/**

@@ -602,9 +589,7 @@ * The custom `id` for referencing this service.

/**
* If `true`, states and events will be logged to Redux DevTools.
*
* Default: `false`
* @deprecated Use `inspect` instead.
*/
devTools?: boolean | DevToolsAdapter;
devTools?: never;
/**
* The system ID to register this actor under
* The system ID to register this actor under.
*/

@@ -635,3 +620,3 @@ systemId?: string;

/**
* The source definition.
* The source actor logic.
*/

@@ -728,8 +713,2 @@ src?: string | AnyActorLogic;

}
export interface InteropObservable<T> {
[Symbol.observable]: () => InteropSubscribable<T>;
}
export interface InteropSubscribable<T> {
subscribe(observer: Observer<T>): Subscription;
}
export interface Subscribable<T> extends InteropSubscribable<T> {

@@ -739,3 +718,4 @@ subscribe(observer: Observer<T>): Subscription;

}
export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? TEvent['type'] extends TNormalizedDescriptor ? TEvent : never : never : never;
type EventDescriptorMatches<TEventType extends string, TNormalizedDescriptor> = TEventType extends TNormalizedDescriptor ? true : false;
export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? true extends EventDescriptorMatches<TEvent['type'], TNormalizedDescriptor> ? TEvent : never : never : never;
export interface BaseActorRef<TEvent extends EventObject> {

@@ -742,0 +722,0 @@ send: (event: TEvent) => void;

@@ -6,4 +6,4 @@ 'use strict';

var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
var guards_dist_xstateGuards = require('./raise-5c58eb8e.cjs.js');
var log = require('./log-2580e864.cjs.js');
var guards_dist_xstateGuards = require('./raise-ad8bb7c2.cjs.js');
var log = require('./log-742895c6.cjs.js');
require('../dev/dist/xstate-dev.cjs.js');

@@ -211,2 +211,4 @@

}
/** @internal */
_initialize() {

@@ -263,2 +265,4 @@ this.transitions = guards_dist_xstateGuards.formatTransitions(this);

}
/** @internal */
toJSON() {

@@ -320,2 +324,4 @@ return this.definition;

}
/** @internal */
next(snapshot, event) {

@@ -396,3 +402,5 @@ const eventType = event.type;

this.implementations = void 0;
/** @internal */
this.__xstatenode = true;
/** @internal */
this.idMap = new Map();

@@ -403,3 +411,5 @@ this.root = void 0;

this.events = void 0;
/** @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons */
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
this.__TResolvedTypesMeta = void 0;

@@ -590,3 +600,3 @@ this.id = config.id || '(machine)';

id: actorId,
parent: _actorScope?.self,
parent: _actorScope.self,
syncSnapshot: actorData.syncSnapshot,

@@ -700,2 +710,42 @@ snapshot: childState,

// this is fine for most practical use cases anyway though
/**
* Creates a state machine (statechart) with the given configuration.
*
* The state machine represents the pure logic of a state machine actor.
*
* @param config The state machine configuration.
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
*
* @example
```ts
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
```
*/
function createMachine(config, implementations) {

@@ -705,2 +755,52 @@ return new StateMachine(config, implementations);

/** @internal */
function createInertActorScope(actorLogic) {
const self = guards_dist_xstateGuards.createActor(actorLogic);
const inertActorScope = {
self,
defer: () => {},
id: '',
logger: () => {},
sessionId: '',
stopChild: () => {},
system: self.system
};
return inertActorScope;
}
/**
* Determines the next snapshot for the given `actorLogic` based on
* the given `snapshot` and `event`.
*
* If the `snapshot` is `undefined`, the initial snapshot of the
* `actorLogic` is used.
*
* @example
```ts
import { getNextSnapshot } from 'xstate';
import { trafficLightMachine } from './trafficLightMachine.ts';
const nextSnapshot = getNextSnapshot(
trafficLightMachine, // actor logic
undefined, // snapshot (or initial state if undefined)
{ type: 'TIMER' }); // event object
console.log(nextSnapshot.value);
// => 'yellow'
const nextSnapshot2 = getNextSnapshot(
trafficLightMachine, // actor logic
nextSnapshot, // snapshot
{ type: 'TIMER' }); // event object
console.log(nextSnapshot2.value);
// =>'red'
```
*/
function getNextSnapshot(actorLogic, snapshot, event) {
const inertActorScope = createInertActorScope(actorLogic);
inertActorScope.self._snapshot = snapshot;
return actorLogic.transition(snapshot, event, inertActorScope);
}
// at the moment we allow extra actors - ones that are not specified by `children`

@@ -823,4 +923,5 @@ // this could be reconsidered in the future

exports.createMachine = createMachine;
exports.getNextSnapshot = getNextSnapshot;
exports.setup = setup;
exports.toPromise = toPromise;
exports.waitFor = waitFor;

@@ -6,4 +6,4 @@ 'use strict';

var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
var guards_dist_xstateGuards = require('./raise-3d3d6d51.development.cjs.js');
var log = require('./log-18eb632d.development.cjs.js');
var guards_dist_xstateGuards = require('./raise-7af39710.development.cjs.js');
var log = require('./log-da322832.development.cjs.js');
require('../dev/dist/xstate-dev.development.cjs.js');

@@ -211,2 +211,4 @@

}
/** @internal */
_initialize() {

@@ -263,2 +265,4 @@ this.transitions = guards_dist_xstateGuards.formatTransitions(this);

}
/** @internal */
toJSON() {

@@ -320,2 +324,4 @@ return this.definition;

}
/** @internal */
next(snapshot, event) {

@@ -396,3 +402,5 @@ const eventType = event.type;

this.implementations = void 0;
/** @internal */
this.__xstatenode = true;
/** @internal */
this.idMap = new Map();

@@ -403,3 +411,5 @@ this.root = void 0;

this.events = void 0;
/** @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons */
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
this.__TResolvedTypesMeta = void 0;

@@ -593,3 +603,3 @@ this.id = config.id || '(machine)';

id: actorId,
parent: _actorScope?.self,
parent: _actorScope.self,
syncSnapshot: actorData.syncSnapshot,

@@ -706,2 +716,42 @@ snapshot: childState,

// this is fine for most practical use cases anyway though
/**
* Creates a state machine (statechart) with the given configuration.
*
* The state machine represents the pure logic of a state machine actor.
*
* @param config The state machine configuration.
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
*
* @example
```ts
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
```
*/
function createMachine(config, implementations) {

@@ -711,2 +761,52 @@ return new StateMachine(config, implementations);

/** @internal */
function createInertActorScope(actorLogic) {
const self = guards_dist_xstateGuards.createActor(actorLogic);
const inertActorScope = {
self,
defer: () => {},
id: '',
logger: () => {},
sessionId: '',
stopChild: () => {},
system: self.system
};
return inertActorScope;
}
/**
* Determines the next snapshot for the given `actorLogic` based on
* the given `snapshot` and `event`.
*
* If the `snapshot` is `undefined`, the initial snapshot of the
* `actorLogic` is used.
*
* @example
```ts
import { getNextSnapshot } from 'xstate';
import { trafficLightMachine } from './trafficLightMachine.ts';
const nextSnapshot = getNextSnapshot(
trafficLightMachine, // actor logic
undefined, // snapshot (or initial state if undefined)
{ type: 'TIMER' }); // event object
console.log(nextSnapshot.value);
// => 'yellow'
const nextSnapshot2 = getNextSnapshot(
trafficLightMachine, // actor logic
nextSnapshot, // snapshot
{ type: 'TIMER' }); // event object
console.log(nextSnapshot2.value);
// =>'red'
```
*/
function getNextSnapshot(actorLogic, snapshot, event) {
const inertActorScope = createInertActorScope(actorLogic);
inertActorScope.self._snapshot = snapshot;
return actorLogic.transition(snapshot, event, inertActorScope);
}
// at the moment we allow extra actors - ones that are not specified by `children`

@@ -829,4 +929,5 @@ // this could be reconsidered in the future

exports.createMachine = createMachine;
exports.getNextSnapshot = getNextSnapshot;
exports.setup = setup;
exports.toPromise = toPromise;
exports.waitFor = waitFor;
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-057d17af.development.esm.js';
export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-057d17af.development.esm.js';
import { a as assign } from './log-11038f00.development.esm.js';
export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-11038f00.development.esm.js';
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-8da27ebb.development.esm.js';
export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-8da27ebb.development.esm.js';
import { a as assign } from './log-285f62db.development.esm.js';
export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-285f62db.development.esm.js';
import '../dev/dist/xstate-dev.development.esm.js';

@@ -208,2 +208,4 @@

}
/** @internal */
_initialize() {

@@ -260,2 +262,4 @@ this.transitions = formatTransitions(this);

}
/** @internal */
toJSON() {

@@ -317,2 +321,4 @@ return this.definition;

}
/** @internal */
next(snapshot, event) {

@@ -393,3 +399,5 @@ const eventType = event.type;

this.implementations = void 0;
/** @internal */
this.__xstatenode = true;
/** @internal */
this.idMap = new Map();

@@ -400,3 +408,5 @@ this.root = void 0;

this.events = void 0;
/** @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons */
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
this.__TResolvedTypesMeta = void 0;

@@ -590,3 +600,3 @@ this.id = config.id || '(machine)';

id: actorId,
parent: _actorScope?.self,
parent: _actorScope.self,
syncSnapshot: actorData.syncSnapshot,

@@ -703,2 +713,42 @@ snapshot: childState,

// this is fine for most practical use cases anyway though
/**
* Creates a state machine (statechart) with the given configuration.
*
* The state machine represents the pure logic of a state machine actor.
*
* @param config The state machine configuration.
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
*
* @example
```ts
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
```
*/
function createMachine(config, implementations) {

@@ -708,2 +758,52 @@ return new StateMachine(config, implementations);

/** @internal */
function createInertActorScope(actorLogic) {
const self = createActor(actorLogic);
const inertActorScope = {
self,
defer: () => {},
id: '',
logger: () => {},
sessionId: '',
stopChild: () => {},
system: self.system
};
return inertActorScope;
}
/**
* Determines the next snapshot for the given `actorLogic` based on
* the given `snapshot` and `event`.
*
* If the `snapshot` is `undefined`, the initial snapshot of the
* `actorLogic` is used.
*
* @example
```ts
import { getNextSnapshot } from 'xstate';
import { trafficLightMachine } from './trafficLightMachine.ts';
const nextSnapshot = getNextSnapshot(
trafficLightMachine, // actor logic
undefined, // snapshot (or initial state if undefined)
{ type: 'TIMER' }); // event object
console.log(nextSnapshot.value);
// => 'yellow'
const nextSnapshot2 = getNextSnapshot(
trafficLightMachine, // actor logic
nextSnapshot, // snapshot
{ type: 'TIMER' }); // event object
console.log(nextSnapshot2.value);
// =>'red'
```
*/
function getNextSnapshot(actorLogic, snapshot, event) {
const inertActorScope = createInertActorScope(actorLogic);
inertActorScope.self._snapshot = snapshot;
return actorLogic.transition(snapshot, event, inertActorScope);
}
// at the moment we allow extra actors - ones that are not specified by `children`

@@ -790,2 +890,2 @@ // this could be reconsidered in the future

export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, setup, toPromise, waitFor };
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getNextSnapshot, setup, toPromise, waitFor };
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-3b380e4b.esm.js';
export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-3b380e4b.esm.js';
import { a as assign } from './log-88b333eb.esm.js';
export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-88b333eb.esm.js';
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-0e64ee6e.esm.js';
export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-0e64ee6e.esm.js';
import { a as assign } from './log-22b3587f.esm.js';
export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-22b3587f.esm.js';
import '../dev/dist/xstate-dev.esm.js';

@@ -208,2 +208,4 @@

}
/** @internal */
_initialize() {

@@ -260,2 +262,4 @@ this.transitions = formatTransitions(this);

}
/** @internal */
toJSON() {

@@ -317,2 +321,4 @@ return this.definition;

}
/** @internal */
next(snapshot, event) {

@@ -393,3 +399,5 @@ const eventType = event.type;

this.implementations = void 0;
/** @internal */
this.__xstatenode = true;
/** @internal */
this.idMap = new Map();

@@ -400,3 +408,5 @@ this.root = void 0;

this.events = void 0;
/** @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons */
/**
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
**/
this.__TResolvedTypesMeta = void 0;

@@ -587,3 +597,3 @@ this.id = config.id || '(machine)';

id: actorId,
parent: _actorScope?.self,
parent: _actorScope.self,
syncSnapshot: actorData.syncSnapshot,

@@ -697,2 +707,42 @@ snapshot: childState,

// this is fine for most practical use cases anyway though
/**
* Creates a state machine (statechart) with the given configuration.
*
* The state machine represents the pure logic of a state machine actor.
*
* @param config The state machine configuration.
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
*
* @example
```ts
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
```
*/
function createMachine(config, implementations) {

@@ -702,2 +752,52 @@ return new StateMachine(config, implementations);

/** @internal */
function createInertActorScope(actorLogic) {
const self = createActor(actorLogic);
const inertActorScope = {
self,
defer: () => {},
id: '',
logger: () => {},
sessionId: '',
stopChild: () => {},
system: self.system
};
return inertActorScope;
}
/**
* Determines the next snapshot for the given `actorLogic` based on
* the given `snapshot` and `event`.
*
* If the `snapshot` is `undefined`, the initial snapshot of the
* `actorLogic` is used.
*
* @example
```ts
import { getNextSnapshot } from 'xstate';
import { trafficLightMachine } from './trafficLightMachine.ts';
const nextSnapshot = getNextSnapshot(
trafficLightMachine, // actor logic
undefined, // snapshot (or initial state if undefined)
{ type: 'TIMER' }); // event object
console.log(nextSnapshot.value);
// => 'yellow'
const nextSnapshot2 = getNextSnapshot(
trafficLightMachine, // actor logic
nextSnapshot, // snapshot
{ type: 'TIMER' }); // event object
console.log(nextSnapshot2.value);
// =>'red'
```
*/
function getNextSnapshot(actorLogic, snapshot, event) {
const inertActorScope = createInertActorScope(actorLogic);
inertActorScope.self._snapshot = snapshot;
return actorLogic.transition(snapshot, event, inertActorScope);
}
// at the moment we allow extra actors - ones that are not specified by `children`

@@ -784,2 +884,2 @@ // this could be reconsidered in the future

export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, setup, toPromise, waitFor };
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getNextSnapshot, setup, toPromise, waitFor };

@@ -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="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 s=".",n="",o="",i="xstate.init",r="xstate.error",a="xstate.stop";function c(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const u=t=>{const e=c();e&&e.register(t)};function h(t,e){return{type:`xstate.done.state.${t}`,output:e}}function d(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function f(t){return{type:i,input:t}}function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";function y(t,e){return`${t.sessionId}.${e}`}let g=0;function v(t,e){const s=_(t),n=_(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&v(s[t],n[t])))}function m(t){return I(t)?t:t.split(s)}function _(t){if(Rt(t))return t.value;if("string"!=typeof t)return t;return b(m(t))}function b(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function S(t,e){const s={},n=Object.keys(t);for(let o=0;o<n.length;o++){const i=n[o];s[i]=e(t[i],i,t,o)}return s}function x(t){return I(t)?t:[t]}function w(t){return void 0===t?[]:x(t)}function k(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function I(t){return Array.isArray(t)}function $(t){return x(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function E(t){if(void 0!==t&&t!==n)return w(t)}function T(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function O(t,e){return`${e}.${t}`}function j(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}const A=1;let M=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class P{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.observers=new Set,this.logger=void 0,this._processingStatus=M.NotStarted,this._parent=void 0,this._syncSnapshot=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 n={...N,...s},{clock:o,logger:i,parent:r,syncSnapshot:a,id:c,systemId:u,inspect:h}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},a=e.clock,c={schedule:(t,e,s,n,o=Math.random().toString(36).slice(2))=>{const i={source:t,target:e,event:s,delay:n,id:o,startedAt:Date.now()},c=y(t,o);u._snapshot._scheduledEvents[c]=i;const h=a.setTimeout((()=>{delete r[c],delete u._snapshot._scheduledEvents[c],u._relay(t,e,s)}),n);r[c]=h},cancel:(t,e)=>{const s=y(t,e),n=r[s];delete r[s],delete u._snapshot._scheduledEvents[s],a.clearTimeout(n)},cancelAll:t=>{for(const e in u._snapshot._scheduledEvents){const s=u._snapshot._scheduledEvents[e];s.source===t&&c.cancel(t,s.id)}}},u={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+g++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const e=o.get(t);void 0!==e&&(n.delete(e),o.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const s=n.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),o.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{u._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)},scheduler:c,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{const t=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:n,event:o,delay:i,id:r}=t[e];c.schedule(s,n,o,i,r)}}};return u}(this,{clock:o}),h&&!r&&this.system.inspect(T(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=a,this.options=n,this.src=n.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}),u&&(this._systemId=u,this.system._set(u,this)),this._initState(s?.snapshot??s?.state),u&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=T(t,e,s);if(this._processingStatus!==M.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){p(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){p(t)}else p(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===M.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=M.Running;const t=f(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===M.Stopped?this:(this.mailbox.clear(),this._processingStatus===M.NotStarted?(this._processingStatus=M.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()}_reportError(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,d(this.id,t))}_stopProcedure(){return this._processingStatus!==M.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=M.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==M.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:u)(this)}}toJSON(){return{xstate$$type:A,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[l](){return this}getSnapshot(){return this._snapshot}}function R(t,e){return new P(t,e)}const C=R;function D(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function J(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function V(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=D,e.execute=J,e}function B(t,e,s,n,{id:o,systemId:i,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?j(e.machine,r):r,h="function"==typeof o?o(s):o;let d;return u&&(d=R(u,{id:h,src:r,parent:t?.self,syncSnapshot:c,systemId:i,input:"function"==typeof a?a({context:e.context,event:s.event,self:t?.self}):a})),[zt(e,{children:{...e.children,[h]:d}}),{id:o,actorRef:d}]}function q(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==M.Stopped&&s.start()}))}function z(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=B,i.execute=q,i}function W(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let a=e.children;return r&&(a={...a},delete a[r.id]),[zt(e,{children:a}),r]}function U(t,e){e&&(t.system._unregister(e),e._processingStatus===M.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function Q(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=W,e.execute=U,e}const F=Q;function G(t,e,{stateValue:s}){if("string"==typeof s&&rt(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function X(t,{context:e,event:s},{guards:n}){return!L(n[0],e,s,t)}function H(t,{context:e,event:s},{guards:n}){return n.every((n=>L(n,e,s,t)))}function K(t,{context:e,event:s},{guards:n}){return n.some((n=>L(n,e,s,t)))}function L(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return L(r,e,s,n);const a={context:e,event:s},c=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(n,a,r)}const Y=t=>"atomic"===t.type||"final"===t.type;function Z(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function tt(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function et(t){const e=new Set(t),s=nt(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of Z(t))if("history"!==s.type&&!e.has(s)){const t=dt(s);for(const s of t)e.add(s)}}else dt(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}function st(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(Y(t))return t.key}const n={};for(const t of s)n[t.key]=st(t,e);return n}function nt(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function ot(t,e){return st(t,nt(et(e)))}function it(t,e){return"compound"===e.type?Z(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Z(e).every((e=>it(t,e))):"final"===e.type}const rt=t=>"#"===t[0];function at(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((s,n)=>{const o=e[s],i="string"==typeof o?{target:o}:o,r=Number.isNaN(+s)?s:+s,a=((e,s)=>{const n=(o=e,i=t.id,{type:`xstate.after.${o}.${i}`});var o,i;const r=n.type;return t.entry.push(Ht(n,{id:r,delay:e})),t.exit.push(V(r)),r})(r);return w(i).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...ct(t,e.event,e),delay:s}}))}function ct(t,e,n){const o=E(n.target),i=n.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(rt(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return lt(t,e.slice(1));const o=n?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 lt(t.parent,o)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,o),a={...n,actions:w(n.actions),guard:n.guard,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ut(t){const e=E(t.config.target);return e?{target:e.map((e=>"string"==typeof e?lt(t.parent,e):e))}:t.parent.initial}function ht(t){return"history"===t.type}function dt(t){const e=ft(t);for(const s of e)for(const n of tt(s,t))e.add(n);return e}function ft(t){const e=new Set;return function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)t(s.initial.target[0]);else if("parallel"===s.type)for(const e of Z(s))t(e)}(t),e}function pt(t,e){if(rt(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 s=t.states[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function lt(t,e){if("string"==typeof e&&rt(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=m(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=pt(n,t)}return n}function yt(t,e){if("string"==typeof e)return[t,t.states[e]];const s=Object.keys(e),n=s.map((e=>pt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const o=pt(t,n);if(!o)return s;const i=yt(o,e[n]);return s.concat(i)}),[]))}function gt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const o=pt(t,e).next(s,n);return o&&o.length?o:t.next(s,n)}(t,e,s,n):1===Object.keys(e).length?function(t,e,s,n){const o=Object.keys(e),i=gt(pt(t,o[0]),e[o[0]],s,n);return i&&i.length?i:t.next(s,n)}(t,e,s,n):function(t,e,s,n){const o=[];for(const i of Object.keys(e)){const r=e[i];if(!r)continue;const a=gt(pt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function mt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function _t(t,e){const s=new Set(t),n=new Set(e);for(const t of s)if(n.has(t))return!0;for(const t of n)if(s.has(t))return!0;return!1}function bt(t,e,s){const n=new Set;for(const o of t){let t=!1;const i=new Set;for(const r of n)if(_t(wt([o],e,s),wt([r],e,s))){if(!mt(o.source,r.source)){t=!0;break}i.add(r)}if(!t){for(const t of i)n.delete(t);n.add(o)}}return Array.from(n)}function St(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ht(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of St(ut(n),e))s.add(t);else s.add(n);return[...s]}function xt(t,e){const s=St(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||mt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of tt(e,void 0))if(s.every((e=>mt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function wt(t,e,s){const n=new Set;for(const o of t)if(o.target?.length){const t=xt(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)mt(s,t)&&n.add(s)}return[...n]}function kt(t,e,s,n,o,i){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const c=bt(t,r,a);let u=e;o||([u,a]=function(t,e,s,n,o,i,r){let a=t;const c=wt(n,o,i);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let s;s="deep"===e.history?e=>Y(e)&&mt(e,t):e=>e.parent===t,u??={...i},u[e.id]=Array.from(o).filter(s)}for(const t of c)a=jt(a,e,s,[...t.exit,...t.invoke.map((t=>Q(t.id)))],r),o.delete(t);return[a,u||i]}(u,n,s,c,r,a,i)),u=jt(u,n,s,c.flatMap((t=>t.actions)),i),u=function(t,e,s,n,o,i,r,a){let c=t;const u=new Set,d=new Set;(function(t,e,s,n){for(const o of t){const t=xt(o,e);for(const i of o.target||[])ht(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),$t(i,e,s,n);const i=St(o,e);for(const r of i){const i=tt(r,t);"parallel"===t?.type&&i.push(t),Et(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,d,u),a&&d.add(t.machine.root);const f=new Set;for(const t of[...u].sort(((t,e)=>t.order-e.order))){o.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(z(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(d.has(t)){const e=t.initial.actions;n.push(...e)}if(c=jt(c,e,s,n,i,t.invoke.map((t=>t.id))),"final"===t.type){const n=t.parent;let r="parallel"===n?.type?n:n?.parent,a=r||t;for("compound"===n?.type&&i.push(h(n.id,t.output?k(t.output,c.context,e,s.self):void 0));"parallel"===r?.type&&!f.has(r)&&it(o,r);)f.add(r),i.push(h(r.id)),a=r,r=r.parent;if(r)continue;c=zt(c,{status:"done",output:It(c,e,s,c.machine.root,a)})}}return c}(u,n,s,c,r,i,a,o);const d=[...r];"done"===u.status&&(u=jt(u,n,s,d.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),i));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0}(e._nodes,r)?u:zt(u,{_nodes:d,historyValue:a})}catch(t){throw t}}function It(t,e,s,n,o){if(!n.output)return;const i=h(o.id,o.output&&o.parent?k(o.output,t.context,e,s.self):void 0);return k(n.output,t.context,i,s.self)}function $t(t,e,s,n){if(ht(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),$t(t,e,s,n);for(const i of o)Tt(i,t.parent,n,e,s)}else{const o=ut(t);for(const i of o.target)n.add(i),o===t.parent?.initial&&s.add(t.parent),$t(i,e,s,n);for(const i of o.target)Tt(i,t.parent,n,e,s)}else if("compound"===t.type){const[o]=t.initial.target;ht(o)||(n.add(o),s.add(o)),$t(o,e,s,n),Tt(o,t,n,e,s)}else if("parallel"===t.type)for(const o of Z(t).filter((t=>!ht(t))))[...n].some((t=>mt(t,o)))||(ht(o)||(n.add(o),s.add(o)),$t(o,e,s,n))}function Et(t,e,s,n,o){for(const i of n)if(o&&!mt(i,o)||t.add(i),"parallel"===i.type)for(const n of Z(i).filter((t=>!ht(t))))[...t].some((t=>mt(t,n)))||(t.add(n),$t(n,e,s,t))}function Tt(t,e,s,n,o){Et(s,n,o,tt(t,e))}function Ot(t,e,s,n,o,i){const{machine:r}=t;let a=t;for(const t of n){const n="function"==typeof t,c=n?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:s?.self,system:s?.system},h=n||"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)){s?.self._processingStatus===M.Running?c(u,h):s?.defer((()=>{c(u,h)}));continue}const d=c,[f,p,l]=d.resolve(s,a,u,h,c,o);a=f,"retryResolve"in d&&i?.push([d,p]),"execute"in d&&(s?.self._processingStatus===M.Running?d.execute(s,p):s?.defer(d.execute.bind(null,s,p))),l&&(a=Ot(a,e,s,l,o,i))}return a}function jt(t,e,s,n,o,i){const r=i?[]:void 0,a=Ot(t,e,s,n,{internalQueue:o,deferredActorIds:i},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function At(t,e,s,n=[]){let o=t;const r=[];if(e.type===a)return o=zt(Mt(o,e,s),{status:"stopped"}),r.push(o),{snapshot:o,microstates:r};let c=e;if(c.type!==i){const e=c,i=function(t){return t.type.startsWith("xstate.error.actor")}(e),a=Nt(e,o);if(i&&!a.length)return o=zt(t,{status:"error",error:e.error}),r.push(o),{snapshot:o,microstates:r};o=kt(a,t,s,c,!1,n),r.push(o)}let u=!0;for(;"active"===o.status;){let t=u?Pt(o,c):[];const e=t.length?o:void 0;if(!t.length){if(!n.length)break;c=n.shift(),t=Nt(c,o)}o=kt(t,o,s,c,!1,n),u=o!==e,r.push(o)}return"active"!==o.status&&Mt(o,c,s),{snapshot:o,microstates:r}}function Mt(t,e,s){return jt(t,e,s,Object.values(t.children).map((t=>Q(t))),[])}function Nt(t,e){return e.machine.getTransitionData(e,t)}function Pt(t,e){const s=new Set,n=t._nodes.filter(Y);for(const o of n)t:for(const n of[o].concat(tt(o,void 0)))if(n.always)for(const o of n.always)if(void 0===o.guard||L(o.guard,t.context,e,t)){s.add(o);break t}return bt(Array.from(s),new Set(t._nodes),t.historyValue)}function Rt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Ct=function(t){return v(t,this.value)},Dt=function(t){return this.tags.has(t)},Jt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Vt=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Bt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function qt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:ot(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Ct,hasTag:Dt,can:Jt,getMeta:Bt,toJSON:Vt}}function zt(t,e={}){return qt({...t,...e},t.machine)}function Wt(t){let e;for(const s in t){const n=t[s];if(n&&"object"==typeof n)if("sessionId"in n&&"send"in n&&"ref"in n)e??=Array.isArray(t)?t.slice():{...t},e[s]={xstate$$type:A,id:n.id};else{const o=Wt(n);o!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=o)}}return e??t}function Ut(t,{machine:e,context:s},n,o){return(i,r)=>{const a=((i,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof i){const u=j(e,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const h=R(u,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof c?c({context:s,event:n,self:t.self}):c,src:i,systemId:a});return o[h.id]=h,h}return R(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:a})})(i,r);return o[a.id]=a,t.defer((()=>{a._processingStatus!==M.Stopped&&a.start()})),a}}function Qt(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Ut(t,e,s.event,i),self:t?.self,system:t?.system};let a={};if("function"==typeof o)a=o(r,n);else for(const t of Object.keys(o)){const e=o[t];a[t]="function"==typeof e?e(r,n):e}return[zt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Ft(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Qt,e}function Gt(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&a.push(u),[e,{event:u,id:i,delay:h}]}function Xt(t,e){const{event:s,delay:n,id:o}=e;"number"!=typeof n||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,s,n,o)}))}function Ht(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Gt,s.execute=Xt,s}let Kt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Lt(t,e,s,n,{to:o,event:i,id:r,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const h="function"==typeof i?i(s,n):i;let d;if("string"==typeof a){const t=u&&u[a];d="function"==typeof t?t(s,n):t}else d="function"==typeof a?a(s,n):a;const f="function"==typeof o?o(s,n):o;let p;if("string"==typeof f){if(p=f===Kt.Parent?t?.self._parent:f===Kt.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:c.deferredActorIds?.includes(f)?f:e.children[f],!p)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else p=f||t?.self;return[e,{to:p,event:h,id:r,delay:d}]}function Yt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Zt(t,e){t.defer((()=>{const{to:s,event:n,delay:o,id:i}=e;"number"!=typeof o?t.system._relay(t.self,s,n.type===r?d(t.self.id,n.data):n):t.system.scheduler.schedule(t.self,s,n,o,i)}))}function te(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Lt,n.retryResolve=Yt,n.execute=Zt,n}function ee(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Ft(...t))},r.cancel=(...t)=>{i.push(V(...t))},r.raise=(...t)=>{i.push(Ht(...t))},r.sendTo=(...t)=>{i.push(te(...t))},r.spawnChild=(...t)=>{i.push(z(...t))},r.stopChild=(...t)=>{i.push(Q(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>L(t,e.context,s.event,e),self:t.self,system:t.system}),[e,void 0,i]}function se(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ne({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function oe(t,e){return{config:t,transition:(e,s,n)=>({...e,context:t(e.context,s,n)}),getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const ie=new WeakMap;const re="xstate.observable.next",ae="xstate.observable.error",ce="xstate.observable.complete";const ue="xstate.promise.resolve",he="xstate.promise.reject";const de=oe((t=>{}),void 0);const fe=new WeakMap;function pe(t,e,s){let n=fe.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},fe.set(t,n)),n[e]}const le={},ye=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ge{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(s),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?S(this.config.states,((t,e)=>new ge(t,{_parent:this,_key:e,_machine:this.machine}))):le,"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 s of Object.keys(t.config.on)){if(s===o)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,$(n).map((e=>ct(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,$(t.config.onDone).map((e=>ct(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,$(s.onDone).map((e=>ct(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,$(s.onError).map((e=>ct(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,$(s.onSnapshot).map((e=>ct(t,n,e))))}}for(const s of t.after){let t=e.get(s.eventType);t||(t=[],e.set(s.eventType,t)),t.push(s)}return e}(this),this.config.always&&(this.always=$(this.config.always).map((t=>ct(this,o,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(ye),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ye),eventType:null})}:void 0,history:this.history,states:S(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ye)}))),entry:this.entry.map(ye),exit:this.exit.map(ye),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 pe(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??O(this.id,e),i="string"==typeof s?s:`xstate.invoke.${O(this.id,e)}`;return{...t,src:i,id:o,systemId:n,toJSON(){const{onDone:e,onError:s,...n}=t;return{...n,type:"xstate.invoke",src:i,id:o}}}}))))}get on(){return pe(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,s])=>(t[e]=t[e]||[],t[e].push(s),t)),{})))}get after(){return pe(this,"delayedTransitions",(()=>at(this)))}get initial(){return pe(this,"initial",(()=>function(t,e){const s="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!s&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const n={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${t.id}`,target:s?[`#${s.id}`]:[]})};return n}(this,this.config.initial)))}next(t,e){const s=e.type,n=[];let o;const i=pe(this,`candidates-${s}`,(()=>{return e=s,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let t=0;t<s.length;t++){const e=s[t],o=n[t];if("*"===e)return t===s.length-1;if(e!==o)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of i){const{guard:i}=r,a=t.context;let c=!1;try{c=!i||L(i,a,e,t)}catch(t){const e="string"==typeof i?i:"object"==typeof i?i.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(c){n.push(...r.actions),o=r;break}}return o?[o]:void 0}get events(){return pe(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const n=t[s];if(n.states)for(const t of n.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 ve{constructor(t,e){this.config=t,this.version=void 0,this.implementations=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.__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.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ge(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:s,actors:n,delays:o}=this.implementations;return new ve(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...o,...t.delays}})}resolveState(t){const e=(s=this.root,n=t.value,ot(s,[...et(yt(s,n))]));var s,n;const o=et(yt(this.root,e));return qt({_nodes:[...o],context:t.context||{},children:{},status:it(o,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return At(t,e,s).snapshot}microstep(t,e,s){return At(t,e,s).microstates}getTransitionData(t,e){return gt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=qt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return jt(o,e,t,[Ft((({spawn:t,event:e,self:s})=>n({spawn:t,input:e.input,self:s})))],s)}return o}getInitialSnapshot(t,e){const s=f(e),n=[],o=this.getPreInitialState(t,s,n),i=kt([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],o,t,s,!0,n),{snapshot:r}=At(i,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(s),n=e.slice(1),o=rt(e[0])?e[0].slice(1):e[0],i=this.idMap.get(o);if(!i)throw new Error(`Child state node '#${o}' does not exist on machine '${this.id}'`);return lt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:s,tags:n,machine:o,children:i,context:r,can:a,hasTag:c,matches:u,getMeta:h,toJSON:d,...f}=t,p={};for(const t in i){const s=i[t];p[t]={snapshot:s.getPersistedSnapshot(e),src:s.src,systemId:s._systemId,syncSnapshot:s._syncSnapshot}}return{...f,context:Wt(r),children:p}}(t,e)}restoreSnapshot(t,e){const s={},n=t.children;Object.keys(n).forEach((t=>{const o=n[t],i=o.snapshot,r=o.src,a="string"==typeof r?j(this,r):r;if(!a)return;const c=R(a,{id:t,parent:e?.self,syncSnapshot:o.syncSnapshot,snapshot:i,src:r,systemId:o.systemId});s[t]=c}));const o=qt({...t,children:s,_nodes:Array.from(et(yt(this.root,t.value)))},this);let i=new Set;return function t(e,s){if(!i.has(e)){i.add(e);for(let n in e){const o=e[n];if(o&&"object"==typeof o){if("xstate$$type"in o&&o.xstate$$type===A){e[n]=s[o.id];continue}t(o,s)}}}}(o.context,s),o}}const me={timeout:1/0};function _e(t,e){return new ve(t,e)}t.Actor=P,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0,this._flushing=!1,this._flushingInvalidated=!1}now(){return this._now}getId(){return this._id++}setTimeout(t,e){this._flushingInvalidated=this._flushing;const s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}clearTimeout(t){this._flushingInvalidated=this._flushing,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(){if(this._flushing)return void(this._flushingInvalidated=!0);this._flushing=!0;const t=[...this.timeouts].sort((([t,e],[s,n])=>{const o=e.start+e.timeout;return n.start+n.timeout>o?-1:1}));for(const[e,s]of t){if(this._flushingInvalidated)return this._flushingInvalidated=!1,this._flushing=!1,void this.flushTimeouts();this.now()-s.start>=s.timeout&&(this.timeouts.delete(e),s.fn.call(null))}this._flushing=!1}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=Kt,t.StateMachine=ve,t.StateNode=ge,t.__unsafe_getAllOwnEventDescriptors=function(t){return[...new Set([...t._nodes.flatMap((t=>t.ownEvents))])]},t.and=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.assertEvent=function(t,e){const s=w(e);if(!s.includes(t.type)){const e=1===s.length?`type "${s[0]}"`:`one of types "${s.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(t)} to have ${e}`)}},t.assign=Ft,t.cancel=V,t.createActor=R,t.createEmptyActor=function(){return R(de)},t.createMachine=_e,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ee,e},t.forwardTo=function(t,e){return te(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(e,s)=>{const{self:n,system:o}=s,i={receivers:void 0,dispose:void 0};ie.set(n,i),i.dispose=t({input:e.input,system:o,self:n,sendBack:t=>{"stopped"!==n.getSnapshot().status&&n._parent&&o._relay(n,n._parent,t)},receive:t=>{i.receivers??=new Set,i.receivers.add(t)}})},transition:(t,e,s)=>{const n=ie.get(s.self);return e.type===a?(t={...t,status:"stopped",error:void 0},n.dispose?.(),t):(n.receivers?.forEach((t=>t(e))),t)},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce: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}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,e,{self:s,id:n,defer:o,system:i})=>{if("active"!==t.status)return t;switch(e.type){case re:return{...t,context:e.data};case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce: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}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{n._relay(s,s,{type:re,data:t})},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot: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 s=e.data;return{...t,status:"done",output:s,input:void 0}}case he: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:s,system:n})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:n,self:s})).then((t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ue,data:t})}),(t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:he,data:t})}))},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=oe,t.getStateNodes=yt,t.interpret=C,t.isMachineSnapshot=Rt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=se,s.execute=ne,s},t.matchesState=v,t.not=function(t){function e(t,e){return!1}return e.check=X,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=K,e.guards=t,e},t.pathToStateValue=b,t.raise=Ht,t.sendParent=function(t,e){return te(Kt.Parent,t,e)},t.sendTo=te,t.setup=function({actors:t,actions:e,guards:s,delays:n}){return{createMachine:o=>_e(o,{actors:t,actions:e,guards:s,delays:n})}},t.spawnChild=z,t.stateIn=function(t){function e(t,e){return!1}return e.check=G,e.stateValue=t,e},t.stop=F,t.stopChild=Q,t.toObserver=T,t.toPromise=function(t){return new Promise(((e,s)=>{t.subscribe({complete:()=>{e(t.getSnapshot().output)},error:s})}))},t.waitFor=function(t,e,s){const n={...me,...s};return new Promise(((s,o)=>{let i=!1;const r=n.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),a=()=>{clearTimeout(r),i=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),s(t))}let u;c(t.getSnapshot()),i||(u=t.subscribe({next:c,error:t=>{a(),o(t)},complete:()=>{a(),o(new Error("Actor terminated without satisfying predicate"))}}),i&&u.unsubscribe())}))},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="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 s=".",n="",o="",i="xstate.init",r="xstate.error",a="xstate.stop";function c(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const u=t=>{const e=c();e&&e.register(t)};function h(t,e){return{type:`xstate.done.state.${t}`,output:e}}function d(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function f(t){return{type:i,input:t}}function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";function y(t,e){return`${t.sessionId}.${e}`}let g=0;function v(t,e){const s=_(t),n=_(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&v(s[t],n[t])))}function m(t){return I(t)?t:t.split(s)}function _(t){if(Rt(t))return t.value;if("string"!=typeof t)return t;return b(m(t))}function b(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function S(t,e){const s={},n=Object.keys(t);for(let o=0;o<n.length;o++){const i=n[o];s[i]=e(t[i],i,t,o)}return s}function x(t){return I(t)?t:[t]}function w(t){return void 0===t?[]:x(t)}function k(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function I(t){return Array.isArray(t)}function $(t){return x(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function E(t){if(void 0!==t&&t!==n)return w(t)}function T(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function O(t,e){return`${e}.${t}`}function j(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}const A=1;let M=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class P{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.observers=new Set,this.logger=void 0,this._processingStatus=M.NotStarted,this._parent=void 0,this._syncSnapshot=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 n={...N,...s},{clock:o,logger:i,parent:r,syncSnapshot:a,id:c,systemId:u,inspect:h}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},a=e.clock,c={schedule:(t,e,s,n,o=Math.random().toString(36).slice(2))=>{const i={source:t,target:e,event:s,delay:n,id:o,startedAt:Date.now()},c=y(t,o);u._snapshot._scheduledEvents[c]=i;const h=a.setTimeout((()=>{delete r[c],delete u._snapshot._scheduledEvents[c],u._relay(t,e,s)}),n);r[c]=h},cancel:(t,e)=>{const s=y(t,e),n=r[s];delete r[s],delete u._snapshot._scheduledEvents[s],a.clearTimeout(n)},cancelAll:t=>{for(const e in u._snapshot._scheduledEvents){const s=u._snapshot._scheduledEvents[e];s.source===t&&c.cancel(t,s.id)}}},u={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+g++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const e=o.get(t);void 0!==e&&(n.delete(e),o.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const s=n.get(t);if(s&&s!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),o.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{u._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)},scheduler:c,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{const t=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(const e in t){const{source:s,target:n,event:o,delay:i,id:r}=t[e];c.schedule(s,n,o,i,r)}}};return u}(this,{clock:o}),h&&!r&&this.system.inspect(T(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=a,this.options=n,this.src=n.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}),u&&(this._systemId=u,this.system._set(u,this)),this._initState(s?.snapshot??s?.state),u&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=T(t,e,s);if(this._processingStatus!==M.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){p(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){p(t)}else p(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===M.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=M.Running;const t=f(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===M.Stopped?this:(this.mailbox.clear(),this._processingStatus===M.NotStarted?(this._processingStatus=M.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()}_reportError(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,d(this.id,t))}_stopProcedure(){return this._processingStatus!==M.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=M.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==M.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:u)(this)}}toJSON(){return{xstate$$type:A,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[l](){return this}getSnapshot(){return this._snapshot}}function R(t,e){return new P(t,e)}const C=R;function D(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function J(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function V(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=D,e.execute=J,e}function B(t,e,s,n,{id:o,systemId:i,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?j(e.machine,r):r,h="function"==typeof o?o(s):o;let d;return u&&(d=R(u,{id:h,src:r,parent:t.self,syncSnapshot:c,systemId:i,input:"function"==typeof a?a({context:e.context,event:s.event,self:t.self}):a})),[zt(e,{children:{...e.children,[h]:d}}),{id:o,actorRef:d}]}function q(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==M.Stopped&&s.start()}))}function z(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=B,i.execute=q,i}function W(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let a=e.children;return r&&(a={...a},delete a[r.id]),[zt(e,{children:a}),r]}function U(t,e){e&&(t.system._unregister(e),e._processingStatus===M.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function Q(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=W,e.execute=U,e}const F=Q;function G(t,e,{stateValue:s}){if("string"==typeof s&&rt(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function X(t,{context:e,event:s},{guards:n}){return!L(n[0],e,s,t)}function H(t,{context:e,event:s},{guards:n}){return n.every((n=>L(n,e,s,t)))}function K(t,{context:e,event:s},{guards:n}){return n.some((n=>L(n,e,s,t)))}function L(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return L(r,e,s,n);const a={context:e,event:s},c=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(n,a,r)}const Y=t=>"atomic"===t.type||"final"===t.type;function Z(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function tt(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function et(t){const e=new Set(t),s=nt(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of Z(t))if("history"!==s.type&&!e.has(s)){const t=dt(s);for(const s of t)e.add(s)}}else dt(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}function st(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(Y(t))return t.key}const n={};for(const t of s)n[t.key]=st(t,e);return n}function nt(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function ot(t,e){return st(t,nt(et(e)))}function it(t,e){return"compound"===e.type?Z(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Z(e).every((e=>it(t,e))):"final"===e.type}const rt=t=>"#"===t[0];function at(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((s,n)=>{const o=e[s],i="string"==typeof o?{target:o}:o,r=Number.isNaN(+s)?s:+s,a=((e,s)=>{const n=(o=e,i=t.id,{type:`xstate.after.${o}.${i}`});var o,i;const r=n.type;return t.entry.push(Ht(n,{id:r,delay:e})),t.exit.push(V(r)),r})(r);return w(i).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...ct(t,e.event,e),delay:s}}))}function ct(t,e,n){const o=E(n.target),i=n.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(rt(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return lt(t,e.slice(1));const o=n?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 lt(t.parent,o)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,o),a={...n,actions:w(n.actions),guard:n.guard,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ut(t){const e=E(t.config.target);return e?{target:e.map((e=>"string"==typeof e?lt(t.parent,e):e))}:t.parent.initial}function ht(t){return"history"===t.type}function dt(t){const e=ft(t);for(const s of e)for(const n of tt(s,t))e.add(n);return e}function ft(t){const e=new Set;return function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)t(s.initial.target[0]);else if("parallel"===s.type)for(const e of Z(s))t(e)}(t),e}function pt(t,e){if(rt(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 s=t.states[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function lt(t,e){if("string"==typeof e&&rt(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=m(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=pt(n,t)}return n}function yt(t,e){if("string"==typeof e)return[t,t.states[e]];const s=Object.keys(e),n=s.map((e=>pt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const o=pt(t,n);if(!o)return s;const i=yt(o,e[n]);return s.concat(i)}),[]))}function gt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const o=pt(t,e).next(s,n);return o&&o.length?o:t.next(s,n)}(t,e,s,n):1===Object.keys(e).length?function(t,e,s,n){const o=Object.keys(e),i=gt(pt(t,o[0]),e[o[0]],s,n);return i&&i.length?i:t.next(s,n)}(t,e,s,n):function(t,e,s,n){const o=[];for(const i of Object.keys(e)){const r=e[i];if(!r)continue;const a=gt(pt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function mt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function _t(t,e){const s=new Set(t),n=new Set(e);for(const t of s)if(n.has(t))return!0;for(const t of n)if(s.has(t))return!0;return!1}function bt(t,e,s){const n=new Set;for(const o of t){let t=!1;const i=new Set;for(const r of n)if(_t(wt([o],e,s),wt([r],e,s))){if(!mt(o.source,r.source)){t=!0;break}i.add(r)}if(!t){for(const t of i)n.delete(t);n.add(o)}}return Array.from(n)}function St(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ht(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of St(ut(n),e))s.add(t);else s.add(n);return[...s]}function xt(t,e){const s=St(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||mt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of tt(e,void 0))if(s.every((e=>mt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function wt(t,e,s){const n=new Set;for(const o of t)if(o.target?.length){const t=xt(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)mt(s,t)&&n.add(s)}return[...n]}function kt(t,e,s,n,o,i){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const c=bt(t,r,a);let u=e;o||([u,a]=function(t,e,s,n,o,i,r){let a=t;const c=wt(n,o,i);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let s;s="deep"===e.history?e=>Y(e)&&mt(e,t):e=>e.parent===t,u??={...i},u[e.id]=Array.from(o).filter(s)}for(const t of c)a=jt(a,e,s,[...t.exit,...t.invoke.map((t=>Q(t.id)))],r),o.delete(t);return[a,u||i]}(u,n,s,c,r,a,i)),u=jt(u,n,s,c.flatMap((t=>t.actions)),i),u=function(t,e,s,n,o,i,r,a){let c=t;const u=new Set,d=new Set;(function(t,e,s,n){for(const o of t){const t=xt(o,e);for(const i of o.target||[])ht(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),$t(i,e,s,n);const i=St(o,e);for(const r of i){const i=tt(r,t);"parallel"===t?.type&&i.push(t),Et(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,d,u),a&&d.add(t.machine.root);const f=new Set;for(const t of[...u].sort(((t,e)=>t.order-e.order))){o.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(z(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(d.has(t)){const e=t.initial.actions;n.push(...e)}if(c=jt(c,e,s,n,i,t.invoke.map((t=>t.id))),"final"===t.type){const n=t.parent;let r="parallel"===n?.type?n:n?.parent,a=r||t;for("compound"===n?.type&&i.push(h(n.id,t.output?k(t.output,c.context,e,s.self):void 0));"parallel"===r?.type&&!f.has(r)&&it(o,r);)f.add(r),i.push(h(r.id)),a=r,r=r.parent;if(r)continue;c=zt(c,{status:"done",output:It(c,e,s,c.machine.root,a)})}}return c}(u,n,s,c,r,i,a,o);const d=[...r];"done"===u.status&&(u=jt(u,n,s,d.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),i));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0}(e._nodes,r)?u:zt(u,{_nodes:d,historyValue:a})}catch(t){throw t}}function It(t,e,s,n,o){if(!n.output)return;const i=h(o.id,o.output&&o.parent?k(o.output,t.context,e,s.self):void 0);return k(n.output,t.context,i,s.self)}function $t(t,e,s,n){if(ht(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),$t(t,e,s,n);for(const i of o)Tt(i,t.parent,n,e,s)}else{const o=ut(t);for(const i of o.target)n.add(i),o===t.parent?.initial&&s.add(t.parent),$t(i,e,s,n);for(const i of o.target)Tt(i,t.parent,n,e,s)}else if("compound"===t.type){const[o]=t.initial.target;ht(o)||(n.add(o),s.add(o)),$t(o,e,s,n),Tt(o,t,n,e,s)}else if("parallel"===t.type)for(const o of Z(t).filter((t=>!ht(t))))[...n].some((t=>mt(t,o)))||(ht(o)||(n.add(o),s.add(o)),$t(o,e,s,n))}function Et(t,e,s,n,o){for(const i of n)if(o&&!mt(i,o)||t.add(i),"parallel"===i.type)for(const n of Z(i).filter((t=>!ht(t))))[...t].some((t=>mt(t,n)))||(t.add(n),$t(n,e,s,t))}function Tt(t,e,s,n,o){Et(s,n,o,tt(t,e))}function Ot(t,e,s,n,o,i){const{machine:r}=t;let a=t;for(const t of n){const n="function"==typeof t,c=n?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:s.self,system:s.system},h=n||"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)){s.self._processingStatus===M.Running?c(u,h):s.defer((()=>{c(u,h)}));continue}const d=c,[f,p,l]=d.resolve(s,a,u,h,c,o);a=f,"retryResolve"in d&&i?.push([d,p]),"execute"in d&&(s.self._processingStatus===M.Running?d.execute(s,p):s.defer(d.execute.bind(null,s,p))),l&&(a=Ot(a,e,s,l,o,i))}return a}function jt(t,e,s,n,o,i){const r=i?[]:void 0,a=Ot(t,e,s,n,{internalQueue:o,deferredActorIds:i},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function At(t,e,s,n=[]){let o=t;const r=[];if(e.type===a)return o=zt(Mt(o,e,s),{status:"stopped"}),r.push(o),{snapshot:o,microstates:r};let c=e;if(c.type!==i){const e=c,i=function(t){return t.type.startsWith("xstate.error.actor")}(e),a=Nt(e,o);if(i&&!a.length)return o=zt(t,{status:"error",error:e.error}),r.push(o),{snapshot:o,microstates:r};o=kt(a,t,s,c,!1,n),r.push(o)}let u=!0;for(;"active"===o.status;){let t=u?Pt(o,c):[];const e=t.length?o:void 0;if(!t.length){if(!n.length)break;c=n.shift(),t=Nt(c,o)}o=kt(t,o,s,c,!1,n),u=o!==e,r.push(o)}return"active"!==o.status&&Mt(o,c,s),{snapshot:o,microstates:r}}function Mt(t,e,s){return jt(t,e,s,Object.values(t.children).map((t=>Q(t))),[])}function Nt(t,e){return e.machine.getTransitionData(e,t)}function Pt(t,e){const s=new Set,n=t._nodes.filter(Y);for(const o of n)t:for(const n of[o].concat(tt(o,void 0)))if(n.always)for(const o of n.always)if(void 0===o.guard||L(o.guard,t.context,e,t)){s.add(o);break t}return bt(Array.from(s),new Set(t._nodes),t.historyValue)}function Rt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Ct=function(t){return v(t,this.value)},Dt=function(t){return this.tags.has(t)},Jt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Vt=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Bt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function qt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:ot(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Ct,hasTag:Dt,can:Jt,getMeta:Bt,toJSON:Vt}}function zt(t,e={}){return qt({...t,...e},t.machine)}function Wt(t){let e;for(const s in t){const n=t[s];if(n&&"object"==typeof n)if("sessionId"in n&&"send"in n&&"ref"in n)e??=Array.isArray(t)?t.slice():{...t},e[s]={xstate$$type:A,id:n.id};else{const o=Wt(n);o!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=o)}}return e??t}function Ut(t,{machine:e,context:s},n,o){return(i,r)=>{const a=((i,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof i){const u=j(e,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const h=R(u,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof c?c({context:s,event:n,self:t.self}):c,src:i,systemId:a});return o[h.id]=h,h}return R(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:a})})(i,r);return o[a.id]=a,t.defer((()=>{a._processingStatus!==M.Stopped&&a.start()})),a}}function Qt(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Ut(t,e,s.event,i),self:t.self,system:t.system};let a={};if("function"==typeof o)a=o(r,n);else for(const t of Object.keys(o)){const e=o[t];a[t]="function"==typeof e?e(r,n):e}return[zt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Ft(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Qt,e}function Gt(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&a.push(u),[e,{event:u,id:i,delay:h}]}function Xt(t,e){const{event:s,delay:n,id:o}=e;"number"!=typeof n||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,s,n,o)}))}function Ht(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Gt,s.execute=Xt,s}let Kt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Lt(t,e,s,n,{to:o,event:i,id:r,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const h="function"==typeof i?i(s,n):i;let d;if("string"==typeof a){const t=u&&u[a];d="function"==typeof t?t(s,n):t}else d="function"==typeof a?a(s,n):a;const f="function"==typeof o?o(s,n):o;let p;if("string"==typeof f){if(p=f===Kt.Parent?t.self._parent:f===Kt.Internal?t.self:f.startsWith("#_")?e.children[f.slice(2)]:c.deferredActorIds?.includes(f)?f:e.children[f],!p)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else p=f||t.self;return[e,{to:p,event:h,id:r,delay:d}]}function Yt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Zt(t,e){t.defer((()=>{const{to:s,event:n,delay:o,id:i}=e;"number"!=typeof o?t.system._relay(t.self,s,n.type===r?d(t.self.id,n.data):n):t.system.scheduler.schedule(t.self,s,n,o,i)}))}function te(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Lt,n.retryResolve=Yt,n.execute=Zt,n}function ee(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Ft(...t))},r.cancel=(...t)=>{i.push(V(...t))},r.raise=(...t)=>{i.push(Ht(...t))},r.sendTo=(...t)=>{i.push(te(...t))},r.spawnChild=(...t)=>{i.push(z(...t))},r.stopChild=(...t)=>{i.push(Q(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>L(t,e.context,s.event,e),self:t.self,system:t.system}),[e,void 0,i]}function se(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ne({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function oe(t,e){return{config:t,transition:(e,s,n)=>({...e,context:t(e.context,s,n)}),getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const ie=new WeakMap;const re="xstate.observable.next",ae="xstate.observable.error",ce="xstate.observable.complete";const ue="xstate.promise.resolve",he="xstate.promise.reject";const de=oe((t=>{}),void 0);const fe=new WeakMap;function pe(t,e,s){let n=fe.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},fe.set(t,n)),n[e]}const le={},ye=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ge{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(s),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?S(this.config.states,((t,e)=>new ge(t,{_parent:this,_key:e,_machine:this.machine}))):le,"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 s of Object.keys(t.config.on)){if(s===o)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,$(n).map((e=>ct(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,$(t.config.onDone).map((e=>ct(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,$(s.onDone).map((e=>ct(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,$(s.onError).map((e=>ct(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,$(s.onSnapshot).map((e=>ct(t,n,e))))}}for(const s of t.after){let t=e.get(s.eventType);t||(t=[],e.set(s.eventType,t)),t.push(s)}return e}(this),this.config.always&&(this.always=$(this.config.always).map((t=>ct(this,o,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(ye),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ye),eventType:null})}:void 0,history:this.history,states:S(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ye)}))),entry:this.entry.map(ye),exit:this.exit.map(ye),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 pe(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??O(this.id,e),i="string"==typeof s?s:`xstate.invoke.${O(this.id,e)}`;return{...t,src:i,id:o,systemId:n,toJSON(){const{onDone:e,onError:s,...n}=t;return{...n,type:"xstate.invoke",src:i,id:o}}}}))))}get on(){return pe(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,s])=>(t[e]=t[e]||[],t[e].push(s),t)),{})))}get after(){return pe(this,"delayedTransitions",(()=>at(this)))}get initial(){return pe(this,"initial",(()=>function(t,e){const s="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!s&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const n={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${t.id}`,target:s?[`#${s.id}`]:[]})};return n}(this,this.config.initial)))}next(t,e){const s=e.type,n=[];let o;const i=pe(this,`candidates-${s}`,(()=>{return e=s,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let t=0;t<s.length;t++){const e=s[t],o=n[t];if("*"===e)return t===s.length-1;if(e!==o)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of i){const{guard:i}=r,a=t.context;let c=!1;try{c=!i||L(i,a,e,t)}catch(t){const e="string"==typeof i?i:"object"==typeof i?i.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(c){n.push(...r.actions),o=r;break}}return o?[o]:void 0}get events(){return pe(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const n=t[s];if(n.states)for(const t of n.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 ve{constructor(t,e){this.config=t,this.version=void 0,this.implementations=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.__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.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ge(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:s,actors:n,delays:o}=this.implementations;return new ve(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...o,...t.delays}})}resolveState(t){const e=(s=this.root,n=t.value,ot(s,[...et(yt(s,n))]));var s,n;const o=et(yt(this.root,e));return qt({_nodes:[...o],context:t.context||{},children:{},status:it(o,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return At(t,e,s).snapshot}microstep(t,e,s){return At(t,e,s).microstates}getTransitionData(t,e){return gt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=qt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return jt(o,e,t,[Ft((({spawn:t,event:e,self:s})=>n({spawn:t,input:e.input,self:s})))],s)}return o}getInitialSnapshot(t,e){const s=f(e),n=[],o=this.getPreInitialState(t,s,n),i=kt([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],o,t,s,!0,n),{snapshot:r}=At(i,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(s),n=e.slice(1),o=rt(e[0])?e[0].slice(1):e[0],i=this.idMap.get(o);if(!i)throw new Error(`Child state node '#${o}' does not exist on machine '${this.id}'`);return lt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:s,tags:n,machine:o,children:i,context:r,can:a,hasTag:c,matches:u,getMeta:h,toJSON:d,...f}=t,p={};for(const t in i){const s=i[t];p[t]={snapshot:s.getPersistedSnapshot(e),src:s.src,systemId:s._systemId,syncSnapshot:s._syncSnapshot}}return{...f,context:Wt(r),children:p}}(t,e)}restoreSnapshot(t,e){const s={},n=t.children;Object.keys(n).forEach((t=>{const o=n[t],i=o.snapshot,r=o.src,a="string"==typeof r?j(this,r):r;if(!a)return;const c=R(a,{id:t,parent:e.self,syncSnapshot:o.syncSnapshot,snapshot:i,src:r,systemId:o.systemId});s[t]=c}));const o=qt({...t,children:s,_nodes:Array.from(et(yt(this.root,t.value)))},this);let i=new Set;return function t(e,s){if(!i.has(e)){i.add(e);for(let n in e){const o=e[n];if(o&&"object"==typeof o){if("xstate$$type"in o&&o.xstate$$type===A){e[n]=s[o.id];continue}t(o,s)}}}}(o.context,s),o}}const me={timeout:1/0};function _e(t,e){return new ve(t,e)}t.Actor=P,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0,this._flushing=!1,this._flushingInvalidated=!1}now(){return this._now}getId(){return this._id++}setTimeout(t,e){this._flushingInvalidated=this._flushing;const s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}clearTimeout(t){this._flushingInvalidated=this._flushing,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(){if(this._flushing)return void(this._flushingInvalidated=!0);this._flushing=!0;const t=[...this.timeouts].sort((([t,e],[s,n])=>{const o=e.start+e.timeout;return n.start+n.timeout>o?-1:1}));for(const[e,s]of t){if(this._flushingInvalidated)return this._flushingInvalidated=!1,this._flushing=!1,void this.flushTimeouts();this.now()-s.start>=s.timeout&&(this.timeouts.delete(e),s.fn.call(null))}this._flushing=!1}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=Kt,t.StateMachine=ve,t.StateNode=ge,t.__unsafe_getAllOwnEventDescriptors=function(t){return[...new Set([...t._nodes.flatMap((t=>t.ownEvents))])]},t.and=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.assertEvent=function(t,e){const s=w(e);if(!s.includes(t.type)){const e=1===s.length?`type "${s[0]}"`:`one of types "${s.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(t)} to have ${e}`)}},t.assign=Ft,t.cancel=V,t.createActor=R,t.createEmptyActor=function(){return R(de)},t.createMachine=_e,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ee,e},t.forwardTo=function(t,e){return te(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(e,s)=>{const{self:n,system:o}=s,i={receivers:void 0,dispose:void 0};ie.set(n,i),i.dispose=t({input:e.input,system:o,self:n,sendBack:t=>{"stopped"!==n.getSnapshot().status&&n._parent&&o._relay(n,n._parent,t)},receive:t=>{i.receivers??=new Set,i.receivers.add(t)}})},transition:(t,e,s)=>{const n=ie.get(s.self);return e.type===a?(t={...t,status:"stopped",error:void 0},n.dispose?.(),t):(n.receivers?.forEach((t=>t(e))),t)},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce: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}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,e,{self:s,id:n,defer:o,system:i})=>{if("active"!==t.status)return t;switch(e.type){case re:return{...t,context:e.data};case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce: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}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{n._relay(s,s,{type:re,data:t})},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot: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 s=e.data;return{...t,status:"done",output:s,input:void 0}}case he: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:s,system:n})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:n,self:s})).then((t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ue,data:t})}),(t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:he,data:t})}))},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=oe,t.getNextSnapshot=function(t,e,s){const n=function(t){const e=R(t);return{self:e,defer:()=>{},id:"",logger:()=>{},sessionId:"",stopChild:()=>{},system:e.system}}(t);return n.self._snapshot=e,t.transition(e,s,n)},t.getStateNodes=yt,t.interpret=C,t.isMachineSnapshot=Rt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=se,s.execute=ne,s},t.matchesState=v,t.not=function(t){function e(t,e){return!1}return e.check=X,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=K,e.guards=t,e},t.pathToStateValue=b,t.raise=Ht,t.sendParent=function(t,e){return te(Kt.Parent,t,e)},t.sendTo=te,t.setup=function({actors:t,actions:e,guards:s,delays:n}){return{createMachine:o=>_e(o,{actors:t,actions:e,guards:s,delays:n})}},t.spawnChild=z,t.stateIn=function(t){function e(t,e){return!1}return e.check=G,e.stateValue=t,e},t.stop=F,t.stopChild=Q,t.toObserver=T,t.toPromise=function(t){return new Promise(((e,s)=>{t.subscribe({complete:()=>{e(t.getSnapshot().output)},error:s})}))},t.waitFor=function(t,e,s){const n={...me,...s};return new Promise(((s,o)=>{let i=!1;const r=n.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),a=()=>{clearTimeout(r),i=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),s(t))}let u;c(t.getSnapshot()),i||(u=t.subscribe({next:c,error:t=>{a(),o(t)},complete:()=>{a(),o(new Error("Actor terminated without satisfying predicate"))}}),i&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=xstate.umd.min.js.map

@@ -5,3 +5,3 @@ 'use strict';

var guards_dist_xstateGuards = require('../../dist/raise-5c58eb8e.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-ad8bb7c2.cjs.js');
require('../../dev/dist/xstate-dev.cjs.js');

@@ -8,0 +8,0 @@

@@ -5,3 +5,3 @@ 'use strict';

var guards_dist_xstateGuards = require('../../dist/raise-3d3d6d51.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-7af39710.development.cjs.js');
require('../../dev/dist/xstate-dev.development.cjs.js');

@@ -8,0 +8,0 @@

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

export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-057d17af.development.esm.js';
export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-8da27ebb.development.esm.js';
import '../../dev/dist/xstate-dev.development.esm.js';

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

export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-3b380e4b.esm.js';
export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-0e64ee6e.esm.js';
import '../../dev/dist/xstate-dev.esm.js';
{
"name": "xstate",
"version": "5.4.1",
"version": "5.5.0",
"description": "Finite State Machines and Statecharts for the Modern Web.",

@@ -5,0 +5,0 @@ "main": "dist/xstate.cjs.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is 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