Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xstate

Package Overview
Dependencies
Maintainers
3
Versions
249
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.18.2 to 5.19.0

dist/declarations/src/transition.d.ts

4

actions/dist/xstate-actions.cjs.js

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

var log = require('../../dist/log-98fcce74.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-b1e0b9a9.cjs.js');
var log = require('../../dist/log-b0ee96de.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-60cebf03.cjs.js');
require('../../dev/dist/xstate-dev.cjs.js');

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

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

var log = require('../../dist/log-b7ed1b61.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-e919c5d4.development.cjs.js');
var log = require('../../dist/log-17337367.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-4acdb210.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 emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-38475d87.development.esm.js';
export { M as cancel, O as raise, P as spawnChild, Q as stop, R as stopChild } from '../../dist/raise-5ea71f04.development.esm.js';
export { a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-ef30c65f.development.esm.js';
export { M as cancel, O as raise, P as spawnChild, Q as stop, R as stopChild } from '../../dist/raise-1db27a82.development.esm.js';
import '../../dev/dist/xstate-dev.development.esm.js';

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

export { a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-15d0f775.esm.js';
export { M as cancel, O as raise, P as spawnChild, Q as stop, R as stopChild } from '../../dist/raise-0f7cf128.esm.js';
export { a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-2a773d37.esm.js';
export { M as cancel, O as raise, P as spawnChild, Q as stop, R as stopChild } from '../../dist/raise-c17ec2bc.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="xstate.error",n="xstate.stop";function o(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const i=t=>{const e=o();e&&e.register(t)};function r(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function c(t){setTimeout((()=>{throw t}))}const a="function"==typeof Symbol&&Symbol.observable||"@@observable";function h(t,e){const s=d(t),n=d(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&h(s[t],n[t])))}function u(t){if(e=t,Array.isArray(e))return t;var e;let s=[],n="";for(let e=0;e<t.length;e++){switch(t.charCodeAt(e)){case 92:n+=t[e+1],e++;continue;case 46:s.push(n),n="";continue}n+=t[e]}return s.push(n),s}function d(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}(u(t))}function p(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 l(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}function f(t,e){return`${t.sessionId}.${e}`}let y=0;let _=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const v={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class g{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.eventListeners=new Map,this.logger=void 0,this._processingStatus=_.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={...v,...s},{clock:o,logger:i,parent:r,syncSnapshot:c,id:a,systemId:h,inspect:u}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},{clock:c,logger:a}=e,h={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=f(t,o);u._snapshot._scheduledEvents[a]=i;const h=c.setTimeout((()=>{delete r[a],delete u._snapshot._scheduledEvents[a],u._relay(t,e,s)}),n);r[a]=h},cancel:(t,e)=>{const s=f(t,e),n=r[s];delete r[s],delete u._snapshot._scheduledEvents[s],void 0!==n&&c.clearTimeout(n)},cancelAll:t=>{for(const e in u._snapshot._scheduledEvents){const s=u._snapshot._scheduledEvents[e];s.source===t&&h.cancel(t,s.id)}}},u={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+y++,_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=>{const e=p(t);return i.add(e),{unsubscribe(){i.delete(e)}}},_sendInspectionEvent:e=>{if(!i.size)return;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:h,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];h.schedule(s,n,o,i,r)}},_clock:c,_logger:a};return u}(this,{clock:o,logger:i}),u&&!r&&this.system.inspect(p(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,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()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(!e&&!s)return;const n=new Set([...e?e.values():[],...s?s.values():[]]);for(const e of Array.from(n))e(t)}},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){c(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){c(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o,actorId:n}),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=p(t,e,s);if(this._processingStatus!==_.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){c(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){c(t)}else c(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const n=e.bind(void 0);return s.add(n),{unsubscribe:()=>{s.delete(n)}}}start(){if(this._processingStatus===_.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=_.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===n&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===_.Stopped?this:(this.mailbox.clear(),this._processingStatus===_.NotStarted?(this._processingStatus=_.Stopped,this):(this.mailbox.enqueue({type:n}),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){c(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||c(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){c(t)}}this.observers.clear(),e&&c(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,r(this.id,t))}_stopProcedure(){return this._processingStatus!==_.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=_.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==_.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:i)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[a](){return this}getSnapshot(){return this._snapshot}}function m(t,...[e]){return new g(t,e)}function b(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function x(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function S(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=b,e.execute=x,e}function w(t,e,s,n,{id:o,systemId:i,src:r,input:c,syncSnapshot:a}){const h="string"==typeof r?l(e.machine,r):r,u="function"==typeof o?o(s):o;let d;return h&&(d=m(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})),[W(e,{children:{...e.children,[u]:d}}),{id:o,actorRef:d}]}function I(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==_.Stopped&&s.start()}))}function E(...[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=w,i.execute=I,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]),[W(e,{children:c}),r]}function T(t,e){e&&(t.system._unregister(e),e._processingStatus===_.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function A(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=k,e.execute=T,e}const R=A;function $(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 $(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 P(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function j(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 O(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]=O(t,e);return n}function M(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 N(t,e){const s=function(t){const e=new Set(t),s=M(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 P(t))if("history"!==s.type&&!e.has(s)){const t=q(s);for(const s of t)e.add(s)}}else q(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 O(t,M(s))}function q(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 P(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of j(s,t))e.add(n);return e}const D=function(t){return h(t,this.value)},L=function(t){return this.tags.has(t)},J=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)}},V=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function W(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:N(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:D,hasTag:L,can:J,getMeta:V,toJSON:z}}({...t,...e},t.machine)}function B(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=l(e,i);if(!h)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const u=m(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 m(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!==_.Stopped&&c.start()})),c}}function G(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:B(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[W(e,{context:Object.assign({},e.context,c),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Q(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=G,e}function U(t,e,s,n,{event:o}){return[e,{event:"function"==typeof o?o(s,n):o}]}function X(t,{event:e}){t.defer((()=>t.emit(e)))}function F(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=U,e.execute=X,e}function H(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 K(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 Y(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=H,s.execute=K,s}let Z=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function tt(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===Z.Parent?t.self._parent:p===Z.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 et(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function st(t,e){t.defer((()=>{const{to:n,event:o,delay:i,id:c}=e;"number"!=typeof i?t.system._relay(t.self,n,o.type===s?r(t.self.id,o.data):o):t.system.scheduler.schedule(t.self,n,o,i,c)}))}function nt(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=tt,n.retryResolve=et,n.execute=st,n}function ot(t,e){return nt(Z.Parent,t,e)}function it(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Q(...t))},r.cancel=(...t)=>{i.push(S(...t))},r.raise=(...t)=>{i.push(Y(...t))},r.sendTo=(...t)=>{i.push(nt(...t))},r.sendParent=(...t)=>{i.push(ot(...t))},r.spawnChild=(...t)=>{i.push(E(...t))},r.stopChild=(...t)=>{i.push(A(...t))},r.emit=(...t)=>{i.push(F(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>$(t,e.context,s.event,e),self:t.self,system:t.system},n),[e,void 0,i]}function rt(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ct({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=Q,t.cancel=S,t.emit=F,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=it,e},t.forwardTo=function(t,e){return nt(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=rt,s.execute=ct,s},t.raise=Y,t.sendParent=ot,t.sendTo=nt,t.spawnChild=E,t.stop=R,t.stopChild=A,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="xstate.error",n="xstate.stop";function o(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const i=t=>{const e=o();e&&e.register(t)};function r(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function c(t){setTimeout((()=>{throw t}))}const a="function"==typeof Symbol&&Symbol.observable||"@@observable";function h(t,e){const s=d(t),n=d(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&h(s[t],n[t])))}function u(t){if(e=t,Array.isArray(e))return t;var e;const s=[];let n="";for(let e=0;e<t.length;e++){switch(t.charCodeAt(e)){case 92:n+=t[e+1],e++;continue;case 46:s.push(n),n="";continue}n+=t[e]}return s.push(n),s}function d(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}(u(t))}function p(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 l(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}function f(t,e){return`${t.sessionId}.${e}`}let y=0;let _=!1;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.eventListeners=new Map,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:u}=n;this.system=r?r.system:function(t,e){const s=new Map,n=new Map,o=new WeakMap,i=new Set,r={},{clock:c,logger:a}=e,h={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=f(t,o);u._snapshot._scheduledEvents[a]=i;const h=c.setTimeout((()=>{delete r[a],delete u._snapshot._scheduledEvents[a],u._relay(t,e,s)}),n);r[a]=h},cancel:(t,e)=>{const s=f(t,e),n=r[s];delete r[s],delete u._snapshot._scheduledEvents[s],void 0!==n&&c.clearTimeout(n)},cancelAll:t=>{for(const e in u._snapshot._scheduledEvents){const s=u._snapshot._scheduledEvents[e];s.source===t&&h.cancel(t,s.id)}}},u={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+y++,_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=>{const e=p(t);return i.add(e),{unsubscribe(){i.delete(e)}}},_sendInspectionEvent:e=>{if(!i.size)return;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:h,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];h.schedule(s,n,o,i,r)}},_clock:c,_logger:a};return u}(this,{clock:o,logger:i}),u&&!r&&this.system.inspect(p(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,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()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(!e&&!s)return;const n=[...e?e.values():[],...s?s.values():[]];for(const e of n)e(t)},actionExecutor:t=>{const e=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:t.type,params:t.params}}),!t.exec)return;const e=_;try{_=!0,t.exec(t.info,t.params)}finally{_=e}};this._processingStatus===v.Running?e():this._deferred.push(e)}},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){c(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){c(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o,actorId:n}),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=p(t,e,s);if(this._processingStatus!==v.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){c(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){c(t)}else c(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const n=e.bind(void 0);return s.add(n),{unsubscribe:()=>{s.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===n&&(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:n}),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){c(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||c(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){c(t)}}this.observers.clear(),e&&c(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,r(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:i)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[a](){return this}getSnapshot(){return this._snapshot}}function x(t,...[e]){return new m(t,e)}function b(t,e,s,n,{sendId:o}){return[e,{sendId:"function"==typeof o?o(s,n):o},void 0]}function S(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e.sendId)}))}function w(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=b,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?l(e.machine,r):r,u="function"==typeof o?o(s):o;let d,p;return h&&(p="function"==typeof c?c({context:e.context,event:s.event,self:t.self}):c,d=x(h,{id:u,src:r,parent:t.self,syncSnapshot:a,systemId:i,input:p})),[B(e,{children:{...e.children,[u]:d}}),{id:o,systemId:i,actorRef:d,src:r,input:p},void 0]}function E(t,{actorRef:e}){e&&t.defer((()=>{e._processingStatus!==v.Stopped&&e.start()}))}function k(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="xstate.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=I,i.execute=E,i}function T(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]),[B(e,{children:c}),r,void 0]}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=T,e.execute=R,e}const A=$;function C(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 C(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 P=t=>"atomic"===t.type||"final"===t.type;function j(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function O(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(P(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 j(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 j(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of O(s,t))e.add(n);return e}const L=function(t){return h(t,this.value)},J=function(t){return this.tags.has(t)},z=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},V=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)}},W=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function B(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:L,hasTag:J,can:z,getMeta:W,toJSON:V}}({...t,...e},t.machine)}function G(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=l(e,i);if(!h)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const u=x(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 x(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 Q(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:G(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[B(e,{context:Object.assign({},e.context,c),children:Object.keys(i).length?{...e.children,...i}:e.children}),void 0,void 0]}function U(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Q,e}function X(t,e,s,n,{event:o}){return[e,{event:"function"==typeof o?o(s,n):o},void 0]}function F(t,{event:e}){t.defer((()=>t.emit(e)))}function H(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=X,e.execute=F,e}function K(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},void 0]}function Y(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 Z(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=K,s.execute=Y,s}let tt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function et(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===tt.Parent?t.self._parent:p===tt.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,targetId:"string"==typeof p?p:void 0,event:u,id:r,delay:d},void 0]}function st(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function nt(t,e){t.defer((()=>{const{to:n,event:o,delay:i,id:c}=e;"number"!=typeof i?t.system._relay(t.self,n,o.type===s?r(t.self.id,o.data):o):t.system.scheduler.schedule(t.self,n,o,i,c)}))}function ot(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=et,n.retryResolve=st,n.execute=nt,n}function it(t,e){return ot(tt.Parent,t,e)}function rt(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(U(...t))},r.cancel=(...t)=>{i.push(w(...t))},r.raise=(...t)=>{i.push(Z(...t))},r.sendTo=(...t)=>{i.push(ot(...t))},r.sendParent=(...t)=>{i.push(it(...t))},r.spawnChild=(...t)=>{i.push(k(...t))},r.stopChild=(...t)=>{i.push($(...t))},r.emit=(...t)=>{i.push(H(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>C(t,e.context,s.event,e),self:t.self,system:t.system},n),[e,void 0,i]}function ct(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i},void 0]}function at({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=U,t.cancel=w,t.emit=H,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=rt,e},t.forwardTo=function(t,e){return ot(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=ct,s.execute=at,s},t.raise=Z,t.sendParent=it,t.sendTo=ot,t.spawnChild=k,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-b1e0b9a9.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-60cebf03.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-e919c5d4.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-4acdb210.development.cjs.js');
require('../../dev/dist/xstate-dev.development.cjs.js');

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

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

import { X as XSTATE_STOP, A as createActor } from '../../dist/raise-5ea71f04.development.esm.js';
import { X as XSTATE_STOP, A as createActor } from '../../dist/raise-1db27a82.development.esm.js';
import '../../dev/dist/xstate-dev.development.esm.js';

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

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

import { X as XSTATE_STOP, A as createActor } from '../../dist/raise-0f7cf128.esm.js';
import { X as XSTATE_STOP, A as createActor } from '../../dist/raise-c17ec2bc.esm.js';
import '../../dev/dist/xstate-dev.esm.js';

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

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

!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class s{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 s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const e="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 s=i();s&&s.register(t)};function o(t){setTimeout((()=>{throw t}))}const n="function"==typeof Symbol&&Symbol.observable||"@@observable";function a(t,s,e){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:s)?.bind(r),complete:(i?t.complete:e)?.bind(r)}}function h(t,s){return`${t.sessionId}.${s}`}let c=0;let p=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const u={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class d{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=p.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 i={...u,...e},{clock:r,logger:o,parent:n,syncSnapshot:d,id:l,systemId:_,inspect:v}=i;this.system=n?n.system:function(t,s){const e=new Map,i=new Map,r=new WeakMap,o=new Set,n={},{clock:p,logger:u}=s,d={schedule:(t,s,e,i,r=Math.random().toString(36).slice(2))=>{const o={source:t,target:s,event:e,delay:i,id:r,startedAt:Date.now()},a=h(t,r);l._snapshot._scheduledEvents[a]=o;const c=p.setTimeout((()=>{delete n[a],delete l._snapshot._scheduledEvents[a],l._relay(t,s,e)}),i);n[a]=c},cancel:(t,s)=>{const e=h(t,s),i=n[e];delete n[e],delete l._snapshot._scheduledEvents[e],void 0!==i&&p.clearTimeout(i)},cancelAll:t=>{for(const s in l._snapshot._scheduledEvents){const e=l._snapshot._scheduledEvents[s];e.source===t&&d.cancel(t,e.id)}}},l={_snapshot:{_scheduledEvents:(s?.snapshot&&s.snapshot.scheduler)??{}},_bookId:()=>"x:"+c++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const s=r.get(t);void 0!==s&&(i.delete(s),r.delete(t))},get:t=>i.get(t),_set:(t,s)=>{const e=i.get(t);if(e&&e!==s)throw new Error(`Actor with system ID '${t}' already exists.`);i.set(t,s),r.set(s,t)},inspect:t=>{const s=a(t);return o.add(s),{unsubscribe(){o.delete(s)}}},_sendInspectionEvent:s=>{if(!o.size)return;const e={...s,rootId:t.sessionId};o.forEach((t=>t.next?.(e)))},_relay:(t,s,e)=>{l._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:s,event:e}),s._send(e)},scheduler:d,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const t=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const s in t){const{source:e,target:i,event:r,delay:o,id:n}=t[s];d.schedule(e,i,r,o,n)}},_clock:p,_logger:u};return l}(this,{clock:r,logger:o}),v&&!n&&this.system.inspect(a(v)),this.sessionId=this.system._bookId(),this.id=l??this.sessionId,this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=n,this._syncSnapshot=d,this.options=i,this.src=i.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()},emit:t=>{const s=this.eventListeners.get(t.type),e=this.eventListeners.get("*");if(!s&&!e)return;const i=new Set([...s?s.values():[],...e?e.values():[]]);for(const s of Array.from(i))s(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),_&&(this._systemId=_,this.system._set(_,this)),this._initState(e?.snapshot??e?.state),_&&"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,s){let e;for(this._snapshot=t;e=this._deferred.shift();)try{e()}catch(s){this._deferred.length=0,this._snapshot={...t,status:"error",error:s}}switch(this._snapshot.status){case"active":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}break;case"done":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${i}`,output:r,actorId:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var i,r;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,e){const i=a(t,s,e);if(this._processingStatus!==p.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(t){o(t)}break;case"error":{const t=this._snapshot.error;if(i.error)try{i.error(t)}catch(t){o(t)}else o(t);break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,s){let e=this.eventListeners.get(t);e||(e=new Set,this.eventListeners.set(t,e));const i=s.bind(void 0);return e.add(i),{unsubscribe:()=>{e.delete(i)}}}start(){if(this._processingStatus===p.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=p.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 s,i;try{s=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){i={err:t}}if(i){const{err:t}=i;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(s,t),t.type===e&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===p.Stopped?this:(this.mailbox.clear(),this._processingStatus===p.NotStarted?(this._processingStatus=p.Stopped,this):(this.mailbox.enqueue({type:e}),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){o(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||o(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){o(t)}}this.observers.clear(),s&&o(t)}_error(t){var s;this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${s=this.id}`,error:t,actorId:s})}_stopProcedure(){return this._processingStatus!==p.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this._processingStatus=p.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==p.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)}[n](){return this}getSnapshot(){return this._snapshot}}function l(t,s){return{config:t,transition:(s,e,i)=>({...s,context:t(s.context,e,i)}),getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof s?s({input:e}):s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const _=new WeakMap;const v="xstate.observable.next",f="xstate.observable.error",y="xstate.observable.complete";const g="xstate.promise.resolve",b="xstate.promise.reject",m=new WeakMap;const S=l((t=>{}),void 0);t.createEmptyActor=function(){return function(t,...[s]){return new d(t,s)}(S)},t.fromCallback=function(t){return{config:t,start:(s,e)=>{const{self:i,system:r,emit:o}=e,n={receivers:void 0,dispose:void 0};_.set(i,n),n.dispose=t({input:s.input,system:r,self:i,sendBack:t=>{"stopped"!==i.getSnapshot().status&&i._parent&&r._relay(i,i._parent,t)},receive:t=>{n.receivers??=new Set,n.receivers.add(t)},emit:o})},transition:(t,s,i)=>{const r=_.get(i.self);return s.type===e?(t={...t,status:"stopped",error:void 0},r.dispose?.(),t):(r.receivers?.forEach((t=>t(s))),t)},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case f:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case y:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i,emit:r})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e,emit:r}).subscribe({next:t=>{e._parent&&i._relay(e,e._parent,t)},error:t=>{i._relay(e,e,{type:f,data:t})},complete:()=>{i._relay(e,e,{type:y})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case v:return{...t,context:s.data};case f:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case y:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i,emit:r})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e,emit:r}).subscribe({next:t=>{i._relay(e,e,{type:v,data:t})},error:t=>{i._relay(e,e,{type:f,data:t})},complete:()=>{i._relay(e,e,{type:y})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s,i)=>{if("active"!==t.status)return t;switch(s.type){case g:{const e=s.data;return{...t,status:"done",output:e,input:void 0}}case b:return{...t,status:"error",error:s.data,input:void 0};case e:return m.get(i.self)?.abort(),{...t,status:"stopped",input:void 0};default:return t}},start:(s,{self:e,system:i,emit:r})=>{if("active"!==s.status)return;const o=new AbortController;m.set(e,o);Promise.resolve(t({input:s.input,system:i,self:e,signal:o.signal,emit:r})).then((t=>{"active"===e.getSnapshot().status&&(m.delete(e),i._relay(e,e,{type:g,data:t}))}),(t=>{"active"===e.getSnapshot().status&&(m.delete(e),i._relay(e,e,{type:b,data:t}))}))},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=l,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class s{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 s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const e="xstate.stop";function i(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const o=t=>{const s=i();s&&s.register(t)};function r(t){setTimeout((()=>{throw t}))}const n="function"==typeof Symbol&&Symbol.observable||"@@observable";function a(t,s,e){const i="object"==typeof t,o=i?t:void 0;return{next:(i?t.next:t)?.bind(o),error:(i?t.error:s)?.bind(o),complete:(i?t.complete:e)?.bind(o)}}function h(t,s){return`${t.sessionId}.${s}`}let c=0;let p=!1;let u=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const d={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class l{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=u.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 i={...d,...e},{clock:o,logger:r,parent:n,syncSnapshot:l,id:_,systemId:v,inspect:f}=i;this.system=n?n.system:function(t,s){const e=new Map,i=new Map,o=new WeakMap,r=new Set,n={},{clock:p,logger:u}=s,d={schedule:(t,s,e,i,o=Math.random().toString(36).slice(2))=>{const r={source:t,target:s,event:e,delay:i,id:o,startedAt:Date.now()},a=h(t,o);l._snapshot._scheduledEvents[a]=r;const c=p.setTimeout((()=>{delete n[a],delete l._snapshot._scheduledEvents[a],l._relay(t,s,e)}),i);n[a]=c},cancel:(t,s)=>{const e=h(t,s),i=n[e];delete n[e],delete l._snapshot._scheduledEvents[e],void 0!==i&&p.clearTimeout(i)},cancelAll:t=>{for(const s in l._snapshot._scheduledEvents){const e=l._snapshot._scheduledEvents[s];e.source===t&&d.cancel(t,e.id)}}},l={_snapshot:{_scheduledEvents:(s?.snapshot&&s.snapshot.scheduler)??{}},_bookId:()=>"x:"+c++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const s=o.get(t);void 0!==s&&(i.delete(s),o.delete(t))},get:t=>i.get(t),_set:(t,s)=>{const e=i.get(t);if(e&&e!==s)throw new Error(`Actor with system ID '${t}' already exists.`);i.set(t,s),o.set(s,t)},inspect:t=>{const s=a(t);return r.add(s),{unsubscribe(){r.delete(s)}}},_sendInspectionEvent:s=>{if(!r.size)return;const e={...s,rootId:t.sessionId};r.forEach((t=>t.next?.(e)))},_relay:(t,s,e)=>{l._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:s,event:e}),s._send(e)},scheduler:d,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const t=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const s in t){const{source:e,target:i,event:o,delay:r,id:n}=t[s];d.schedule(e,i,o,r,n)}},_clock:p,_logger:u};return l}(this,{clock:o,logger:r}),f&&!n&&this.system.inspect(a(f)),this.sessionId=this.system._bookId(),this.id=_??this.sessionId,this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=n,this._syncSnapshot=l,this.options=i,this.src=i.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()},emit:t=>{const s=this.eventListeners.get(t.type),e=this.eventListeners.get("*");if(!s&&!e)return;const i=[...s?s.values():[],...e?e.values():[]];for(const s of i)s(t)},actionExecutor:t=>{const s=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:t.type,params:t.params}}),!t.exec)return;const s=p;try{p=!0,t.exec(t.info,t.params)}finally{p=s}};this._processingStatus===u.Running?s():this._deferred.push(s)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),v&&(this._systemId=v,this.system._set(v,this)),this._initState(e?.snapshot??e?.state),v&&"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,s){let e;for(this._snapshot=t;e=this._deferred.shift();)try{e()}catch(s){this._deferred.length=0,this._snapshot={...t,status:"error",error:s}}switch(this._snapshot.status){case"active":for(const s of this.observers)try{s.next?.(t)}catch(t){r(t)}break;case"done":for(const s of this.observers)try{s.next?.(t)}catch(t){r(t)}this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${i}`,output:o,actorId:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var i,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,e){const i=a(t,s,e);if(this._processingStatus!==u.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(t){r(t)}break;case"error":{const t=this._snapshot.error;if(i.error)try{i.error(t)}catch(t){r(t)}else r(t);break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,s){let e=this.eventListeners.get(t);e||(e=new Set,this.eventListeners.set(t,e));const i=s.bind(void 0);return e.add(i),{unsubscribe:()=>{e.delete(i)}}}start(){if(this._processingStatus===u.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=u.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 s,i;try{s=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){i={err:t}}if(i){const{err:t}=i;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(s,t),t.type===e&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===u.Stopped?this:(this.mailbox.clear(),this._processingStatus===u.NotStarted?(this._processingStatus=u.Stopped,this):(this.mailbox.enqueue({type:e}),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){r(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||r(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){r(t)}}this.observers.clear(),s&&r(t)}_error(t){var s;this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${s=this.id}`,error:t,actorId:s})}_stopProcedure(){return this._processingStatus!==u.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this._processingStatus=u.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==u.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:o)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[n](){return this}getSnapshot(){return this._snapshot}}function _(t,s){return{config:t,transition:(s,e,i)=>({...s,context:t(s.context,e,i)}),getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof s?s({input:e}):s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const v=new WeakMap;const f="xstate.observable.next",y="xstate.observable.error",g="xstate.observable.complete";const b="xstate.promise.resolve",m="xstate.promise.reject",S=new WeakMap;const x=_((t=>{}),void 0);t.createEmptyActor=function(){return function(t,...[s]){return new l(t,s)}(x)},t.fromCallback=function(t){return{config:t,start:(s,e)=>{const{self:i,system:o,emit:r}=e,n={receivers:void 0,dispose:void 0};v.set(i,n),n.dispose=t({input:s.input,system:o,self:i,sendBack:t=>{"stopped"!==i.getSnapshot().status&&i._parent&&o._relay(i,i._parent,t)},receive:t=>{n.receivers??=new Set,n.receivers.add(t)},emit:r})},transition:(t,s,i)=>{const o=v.get(i.self);return s.type===e?(t={...t,status:"stopped",error:void 0},o.dispose?.(),t):(o.receivers?.forEach((t=>t(s))),t)},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case y:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case g:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i,emit:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e,emit:o}).subscribe({next:t=>{e._parent&&i._relay(e,e._parent,t)},error:t=>{i._relay(e,e,{type:y,data:t})},complete:()=>{i._relay(e,e,{type:g})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case f:return{...t,context:s.data};case y:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case g:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i,emit:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e,emit:o}).subscribe({next:t=>{i._relay(e,e,{type:f,data:t})},error:t=>{i._relay(e,e,{type:y,data:t})},complete:()=>{i._relay(e,e,{type:g})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s,i)=>{if("active"!==t.status)return t;switch(s.type){case b:{const e=s.data;return{...t,status:"done",output:e,input:void 0}}case m:return{...t,status:"error",error:s.data,input:void 0};case e:return S.get(i.self)?.abort(),{...t,status:"stopped",input:void 0};default:return t}},start:(s,{self:e,system:i,emit:o})=>{if("active"!==s.status)return;const r=new AbortController;S.set(e,r);Promise.resolve(t({input:s.input,system:i,self:e,signal:r.signal,emit:o})).then((t=>{"active"===e.getSnapshot().status&&(S.delete(e),i._relay(e,e,{type:b,data:t}))}),(t=>{"active"===e.getSnapshot().status&&(S.delete(e),i._relay(e,e,{type:m,data:t}))}))},getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=_,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=xstate-actors.umd.min.js.map

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

const w = getGlobal();
if (!!w.__xstate__) {
if (w.__xstate__) {
return w.__xstate__;

@@ -25,0 +25,0 @@ }

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

const w = getGlobal();
if (!!w.__xstate__) {
if (w.__xstate__) {
return w.__xstate__;

@@ -28,0 +28,0 @@ }

@@ -21,3 +21,3 @@ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

const w = getGlobal();
if (!!w.__xstate__) {
if (w.__xstate__) {
return w.__xstate__;

@@ -24,0 +24,0 @@ }

@@ -18,3 +18,3 @@ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

const w = getGlobal();
if (!!w.__xstate__) {
if (w.__xstate__) {
return w.__xstate__;

@@ -21,0 +21,0 @@ }

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

import { ActionArgs, ActionFunction, DoNotInfer, EventObject, MachineContext, ParameterizedObject, RaiseActionOptions, SendExpr } from "../types.js";
import { ActionArgs, ActionFunction, DoNotInfer, EventObject, ExecutableActionObject, MachineContext, ParameterizedObject, RaiseActionOptions, SendExpr } from "../types.js";
export interface RaiseAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {

@@ -14,1 +14,9 @@ (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;

export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TDelay extends string = never, TUsedDelay extends TDelay = never>(eventOrExpr: DoNotInfer<TEvent> | SendExpr<TContext, TExpressionEvent, TParams, DoNotInfer<TEvent>, TEvent>, options?: RaiseActionOptions<TContext, TExpressionEvent, TParams, DoNotInfer<TEvent>, TUsedDelay>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, TDelay, never>;
export interface ExecutableRaiseAction extends ExecutableActionObject {
type: 'xstate.raise';
params: {
event: EventObject;
id: string | undefined;
delay: number | undefined;
};
}

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

import { ActionArgs, ActionFunction, AnyActorRef, AnyEventObject, Cast, DoNotInfer, EventFrom, EventObject, InferEvent, MachineContext, ParameterizedObject, SendExpr, SendToActionOptions } from "../types.js";
import { ActionArgs, ActionFunction, AnyActorRef, AnyEventObject, Cast, DoNotInfer, EventFrom, EventObject, ExecutableActionObject, InferEvent, MachineContext, ParameterizedObject, SendExpr, SendToActionOptions } from "../types.js";
export interface SendToAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {

@@ -33,2 +33,11 @@ (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;

export declare function forwardTo<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string = never, TUsedDelay extends TDelay = never>(target: Target<TContext, TExpressionEvent, TParams, TEvent>, options?: SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TUsedDelay>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, TDelay, never>;
export interface ExecutableSendToAction extends ExecutableActionObject {
type: 'xstate.sendTo';
params: {
event: EventObject;
id: string | undefined;
delay: number | undefined;
to: AnyActorRef;
};
}
export {};
import { symbolObservable } from "./symbolObservable.js";
import { AnyActorSystem, Clock } from "./system.js";
export declare let executingCustomAction: boolean;
import type { AnyActorLogic, AnyActorRef, ConditionalRequired, EmittedFrom, EventFromLogic, InputFrom, IsNotNever, Snapshot, SnapshotFrom } from "./types.js";

@@ -114,3 +115,3 @@ import { ActorOptions, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";

subscribe(nextListener?: (snapshot: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? {} : {
on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? unknown : {
type: TType;

@@ -117,0 +118,0 @@ })) => void): Subscription;

import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
/** @deprecated Use `initialTransition(…)` instead. */
export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;

@@ -10,2 +11,3 @@ /**

*
* @deprecated Use `transition(…)` instead.
* @example

@@ -12,0 +14,0 @@ *

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

export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, pathToStateValue, toObserver } from "./utils.js";
export { transition, initialTransition } from "./transition.js";
export { waitFor } from "./waitFor.js";

@@ -22,0 +23,0 @@ declare global {

@@ -29,3 +29,3 @@ import { ActorRefLike, AnyEventObject, AnyTransitionDefinition, Snapshot } from "./types.js";

type: string;
params: Record<string, unknown>;
params: unknown;
};

@@ -32,0 +32,0 @@ }

@@ -7,3 +7,3 @@ import type { StateNode } from "./StateNode.js";

};
export declare function isMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject>(value: unknown): value is AnyMachineSnapshot;
export declare function isMachineSnapshot(value: unknown): value is AnyMachineSnapshot;
interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta, TStateSchema extends StateSchema = StateSchema> {

@@ -10,0 +10,0 @@ /** The state machine that produced this state snapshot. */

import { MachineSnapshot } from "./State.js";
import type { StateNode } from "./StateNode.js";
import { AnyEventObject, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, TransitionDefinition, TODO, UnknownAction, ActionFunction, AnyTransitionConfig, AnyActorScope } from "./types.js";
import { ActionArgs, AnyEventObject, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, TransitionDefinition, TODO, UnknownAction, ParameterizedObject, AnyTransitionConfig, AnyActorScope } from "./types.js";
type StateNodeIterable<TContext extends MachineContext, TE extends EventObject> = Iterable<StateNode<TContext, TE>>;

@@ -13,3 +13,3 @@ type AnyStateNodeIterable = StateNodeIterable<any, any>;

export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
export declare function formatTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
export declare function formatTransition(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;

@@ -29,9 +29,19 @@ export declare function formatInitialTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, _target: string | undefined | InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO>): InitialTransitionDefinition<TContext, TEvent>;

*/
export declare function getStateNodes<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
export declare function getStateNodes(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
/** https://www.w3.org/TR/scxml/#microstepProcedure */
export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>, currentSnapshot: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
export declare let executingCustomAction: ActionFunction<any, any, any, any, any, any, any, any, any> | false;
export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds?: string[]): AnyMachineSnapshot;
export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue?: AnyEventObject[]): {
export declare function microstep(transitions: Array<AnyTransitionDefinition>, currentSnapshot: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
export interface BuiltinAction {
(): void;
type: `xstate.${string}`;
resolve: (actorScope: AnyActorScope, snapshot: AnyMachineSnapshot, actionArgs: ActionArgs<any, any, any>, actionParams: ParameterizedObject['params'] | undefined, action: unknown, extra: unknown) => [
newState: AnyMachineSnapshot,
params: unknown,
actions?: UnknownAction[]
];
retryResolve: (actorScope: AnyActorScope, snapshot: AnyMachineSnapshot, params: unknown) => void;
execute: (actorScope: AnyActorScope, params: unknown) => void;
}
export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds: string[] | undefined): AnyMachineSnapshot;
export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue: AnyEventObject[]): {
snapshot: typeof snapshot;

@@ -38,0 +48,0 @@ microstates: Array<typeof snapshot>;

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

import { InspectionEvent } from "./inspection.js";
import { ExecutableRaiseAction } from "./actions/raise.js";
import { ExecutableSendToAction } from "./actions/send.js";
export type Identity<T> = {

@@ -46,3 +48,3 @@ [K in keyof T]: T[K];

export type IsNotNever<T> = [T] extends [never] ? false : true;
export type Compute<A extends any> = {
export type Compute<A> = {
[K in keyof A]: A[K];

@@ -60,3 +62,3 @@ } & unknown;

}> = IndexByProp<T, 'type'>;
export type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
export type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
export type IsAny<T> = Equals<T, any>;

@@ -67,3 +69,3 @@ export type Cast<A, B> = A extends B ? A : B;

export type NoInfer<T> = DoNotInfer<T>;
export type LowInfer<T> = T & {};
export type LowInfer<T> = T & NonNullable<unknown>;
export type MetaObject = Record<string, any>;

@@ -182,3 +184,3 @@ export type Lazy<T> = () => T;

};
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | ({} & string);
export type SingleOrArray<T> = readonly T[] | T;

@@ -254,4 +256,4 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {

/**
* The transition to take upon the invoked child machine sending an error
* event.
* The transition to take upon the invoked child machine sending an
* error event.
*/

@@ -262,3 +264,3 @@ onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;

export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> {
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject> {
/** The initial state transition. */

@@ -765,7 +767,8 @@ initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;

src: string | AnyActorLogic;
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? {} : {
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
type: TType;
})) => void) => Subscription;
}
export type AnyActorRef = ActorRef<any, any, any>;
export type AnyActorRef = ActorRef<any, any, // TODO: shouldn't this be AnyEventObject?
any>;
export type ActorRefLike = Pick<AnyActorRef, 'sessionId' | 'send' | 'getSnapshot'>;

@@ -790,2 +793,3 @@ export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;

stopChild: (child: AnyActorRef) => void;
actionExecutor: ActionExecutor;
}

@@ -827,11 +831,11 @@ export type AnyActorScope = ActorScope<any, // TSnapshot

/**
* Transition function that processes the current state and an incoming
* message to produce a new state.
* Transition function that processes the current state and an incoming event
* to produce a new state.
*
* @param snapshot - The current state.
* @param message - The incoming message.
* @param event - The incoming event.
* @param actorScope - The actor scope.
* @returns The new state.
*/
transition: (snapshot: TSnapshot, message: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
/**

@@ -908,3 +912,3 @@ * Called to provide the initial state of the actor.

};
exclude: {};
exclude: unknown;
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;

@@ -974,2 +978,31 @@ export type StateSchema = {

}>> : never) : {};
export interface ExecutableActionObject {
type: string;
info: ActionArgs<MachineContext, EventObject, EventObject>;
params: NonReducibleUnknown;
exec: ((info: ActionArgs<any, any, any>, params: unknown) => void) | undefined;
}
export interface ToExecutableAction<T extends ParameterizedObject> extends ExecutableActionObject {
type: T['type'];
params: T['params'];
exec: undefined;
}
export interface ExecutableSpawnAction extends ExecutableActionObject {
type: 'xstate.spawnChild';
info: ActionArgs<MachineContext, EventObject, EventObject>;
params: {
id: string;
actorRef: AnyActorRef | undefined;
src: string | AnyActorLogic;
};
}
export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig> ? SpecialExecutableAction | (string extends TAction['type'] ? never : ToExecutableAction<TAction>) : never;
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
export type BuiltinActionResolution = [
AnyMachineSnapshot,
NonReducibleUnknown,
// params
UnknownAction[] | undefined
];
export {};

@@ -12,3 +12,3 @@ import type { StateNode } from "./StateNode.js";

export declare function isErrorActorEvent(event: AnyEventObject): event is ErrorActorEvent;
export declare function toTransitionConfigArray<TContext extends MachineContext, TEvent extends EventObject>(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget>): Array<AnyTransitionConfig>;
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget>): Array<AnyTransitionConfig>;
export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): ReadonlyArray<string | StateNode<TContext, TEvent>> | undefined;

@@ -15,0 +15,0 @@ export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;

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

var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
var guards_dist_xstateGuards = require('./raise-b1e0b9a9.cjs.js');
var log = require('./log-98fcce74.cjs.js');
var guards_dist_xstateGuards = require('./raise-60cebf03.cjs.js');
var log = require('./log-b0ee96de.cjs.js');
require('../dev/dist/xstate-dev.cjs.js');

@@ -228,6 +228,6 @@

const resolvedId = invokeConfig.id ?? guards_dist_xstateGuards.createInvokeId(this.id, i);
const resolvedSrc = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
return {
...invokeConfig,
src: resolvedSrc,
src: sourceName,
id: resolvedId,

@@ -244,3 +244,3 @@ systemId: systemId,

type: 'xstate.invoke',
src: resolvedSrc,
src: sourceName,
id: resolvedId

@@ -428,3 +428,3 @@ };

transition(snapshot, event, actorScope) {
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
}

@@ -440,3 +440,3 @@

microstep(snapshot, event, actorScope) {
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microstates;
}

@@ -471,3 +471,3 @@ getTransitionData(snapshot, event) {

});
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue);
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue, undefined);
}

@@ -550,3 +550,3 @@ return preInitial;

}, this);
let seen = new Set();
const seen = new Set();
function reviveContext(contextPart, children) {

@@ -557,3 +557,3 @@ if (seen.has(contextPart)) {

seen.add(contextPart);
for (let key in contextPart) {
for (const key in contextPart) {
const value = contextPart[key];

@@ -574,6 +574,2 @@ if (value && typeof value === 'object') {

// this is not 100% accurate since we can't make parallel regions required in the result
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
// this is fine for most practical use cases anyway though
/**

@@ -636,6 +632,9 @@ * Creates a state machine (statechart) with the given configuration.

system: self.system,
emit: () => {}
emit: () => {},
actionExecutor: () => {}
};
return inertActorScope;
}
/** @deprecated Use `initialTransition(…)` instead. */
function getInitialSnapshot(actorLogic, ...[input]) {

@@ -653,2 +652,3 @@ const actorScope = createInertActorScope(actorLogic);

*
* @deprecated Use `transition(…)` instead.
* @example

@@ -708,2 +708,5 @@ *

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
class SimulatedClock {

@@ -809,2 +812,35 @@ constructor() {

/**
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
* `nextSnapshot` and `actions` to execute.
*
* This is a pure function that does not execute `actions`.
*/
function transition(logic, snapshot, event) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.transition(snapshot, event, actorScope);
return [nextSnapshot, executableActions];
}
/**
* Given actor `logic` and optional `input`, returns a tuple of the
* `nextSnapshot` and `actions` to execute from the initial transition (no
* previous state).
*
* This is a pure function that does not execute `actions`.
*/
function initialTransition(logic, ...[input]) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
return [nextSnapshot, executableActions];
}
const defaultWaitForOptions = {

@@ -845,2 +881,3 @@ timeout: Infinity // much more than 10 seconds

if (signal?.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -874,2 +911,3 @@ return;

let abortListener;
// eslint-disable-next-line prefer-const
let sub; // avoid TDZ when disposing synchronously

@@ -888,2 +926,3 @@

// XState does not "own" the signal, so we should reject with its reason (if any)
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -897,2 +936,3 @@ };

dispose();
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(err);

@@ -950,4 +990,6 @@ },

exports.getNextSnapshot = getNextSnapshot;
exports.initialTransition = initialTransition;
exports.setup = setup;
exports.toPromise = toPromise;
exports.transition = transition;
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-e919c5d4.development.cjs.js');
var log = require('./log-b7ed1b61.development.cjs.js');
var guards_dist_xstateGuards = require('./raise-4acdb210.development.cjs.js');
var log = require('./log-17337367.development.cjs.js');
require('../dev/dist/xstate-dev.development.cjs.js');

@@ -228,6 +228,6 @@

const resolvedId = invokeConfig.id ?? guards_dist_xstateGuards.createInvokeId(this.id, i);
const resolvedSrc = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
return {
...invokeConfig,
src: resolvedSrc,
src: sourceName,
id: resolvedId,

@@ -244,3 +244,3 @@ systemId: systemId,

type: 'xstate.invoke',
src: resolvedSrc,
src: sourceName,
id: resolvedId

@@ -431,3 +431,3 @@ };

transition(snapshot, event, actorScope) {
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
}

@@ -443,3 +443,3 @@

microstep(snapshot, event, actorScope) {
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microstates;
}

@@ -474,3 +474,3 @@ getTransitionData(snapshot, event) {

});
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue);
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue, undefined);
}

@@ -553,3 +553,3 @@ return preInitial;

}, this);
let seen = new Set();
const seen = new Set();
function reviveContext(contextPart, children) {

@@ -560,3 +560,3 @@ if (seen.has(contextPart)) {

seen.add(contextPart);
for (let key in contextPart) {
for (const key in contextPart) {
const value = contextPart[key];

@@ -577,6 +577,2 @@ if (value && typeof value === 'object') {

// this is not 100% accurate since we can't make parallel regions required in the result
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
// this is fine for most practical use cases anyway though
/**

@@ -639,6 +635,9 @@ * Creates a state machine (statechart) with the given configuration.

system: self.system,
emit: () => {}
emit: () => {},
actionExecutor: () => {}
};
return inertActorScope;
}
/** @deprecated Use `initialTransition(…)` instead. */
function getInitialSnapshot(actorLogic, ...[input]) {

@@ -656,2 +655,3 @@ const actorScope = createInertActorScope(actorLogic);

*
* @deprecated Use `transition(…)` instead.
* @example

@@ -711,2 +711,5 @@ *

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
class SimulatedClock {

@@ -812,2 +815,35 @@ constructor() {

/**
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
* `nextSnapshot` and `actions` to execute.
*
* This is a pure function that does not execute `actions`.
*/
function transition(logic, snapshot, event) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.transition(snapshot, event, actorScope);
return [nextSnapshot, executableActions];
}
/**
* Given actor `logic` and optional `input`, returns a tuple of the
* `nextSnapshot` and `actions` to execute from the initial transition (no
* previous state).
*
* This is a pure function that does not execute `actions`.
*/
function initialTransition(logic, ...[input]) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
return [nextSnapshot, executableActions];
}
const defaultWaitForOptions = {

@@ -848,2 +884,3 @@ timeout: Infinity // much more than 10 seconds

if (signal?.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -880,2 +917,3 @@ return;

let abortListener;
// eslint-disable-next-line prefer-const
let sub; // avoid TDZ when disposing synchronously

@@ -894,2 +932,3 @@

// XState does not "own" the signal, so we should reject with its reason (if any)
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -903,2 +942,3 @@ };

dispose();
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(err);

@@ -956,4 +996,6 @@ },

exports.getNextSnapshot = getNextSnapshot;
exports.initialTransition = initialTransition;
exports.setup = setup;
exports.toPromise = toPromise;
exports.transition = transition;
exports.waitFor = waitFor;
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
import { t as toArray, S as STATE_DELIMITER, m as mapValues, 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 toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-5ea71f04.development.esm.js';
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-5ea71f04.development.esm.js';
import { a as assign } from './log-38475d87.development.esm.js';
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-38475d87.development.esm.js';
import { t as toArray, S as STATE_DELIMITER, m as mapValues, 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 toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-1db27a82.development.esm.js';
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-1db27a82.development.esm.js';
import { a as assign } from './log-ef30c65f.development.esm.js';
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-ef30c65f.development.esm.js';
import '../dev/dist/xstate-dev.development.esm.js';

@@ -225,6 +225,6 @@

const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
const resolvedSrc = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
return {
...invokeConfig,
src: resolvedSrc,
src: sourceName,
id: resolvedId,

@@ -241,3 +241,3 @@ systemId: systemId,

type: 'xstate.invoke',
src: resolvedSrc,
src: sourceName,
id: resolvedId

@@ -428,3 +428,3 @@ };

transition(snapshot, event, actorScope) {
return macrostep(snapshot, event, actorScope).snapshot;
return macrostep(snapshot, event, actorScope, []).snapshot;
}

@@ -440,3 +440,3 @@

microstep(snapshot, event, actorScope) {
return macrostep(snapshot, event, actorScope).microstates;
return macrostep(snapshot, event, actorScope, []).microstates;
}

@@ -471,3 +471,3 @@ getTransitionData(snapshot, event) {

});
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue);
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
}

@@ -550,3 +550,3 @@ return preInitial;

}, this);
let seen = new Set();
const seen = new Set();
function reviveContext(contextPart, children) {

@@ -557,3 +557,3 @@ if (seen.has(contextPart)) {

seen.add(contextPart);
for (let key in contextPart) {
for (const key in contextPart) {
const value = contextPart[key];

@@ -574,6 +574,2 @@ if (value && typeof value === 'object') {

// this is not 100% accurate since we can't make parallel regions required in the result
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
// this is fine for most practical use cases anyway though
/**

@@ -636,6 +632,9 @@ * Creates a state machine (statechart) with the given configuration.

system: self.system,
emit: () => {}
emit: () => {},
actionExecutor: () => {}
};
return inertActorScope;
}
/** @deprecated Use `initialTransition(…)` instead. */
function getInitialSnapshot(actorLogic, ...[input]) {

@@ -653,2 +652,3 @@ const actorScope = createInertActorScope(actorLogic);

*
* @deprecated Use `transition(…)` instead.
* @example

@@ -708,2 +708,5 @@ *

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
class SimulatedClock {

@@ -809,2 +812,35 @@ constructor() {

/**
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
* `nextSnapshot` and `actions` to execute.
*
* This is a pure function that does not execute `actions`.
*/
function transition(logic, snapshot, event) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.transition(snapshot, event, actorScope);
return [nextSnapshot, executableActions];
}
/**
* Given actor `logic` and optional `input`, returns a tuple of the
* `nextSnapshot` and `actions` to execute from the initial transition (no
* previous state).
*
* This is a pure function that does not execute `actions`.
*/
function initialTransition(logic, ...[input]) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
return [nextSnapshot, executableActions];
}
const defaultWaitForOptions = {

@@ -845,2 +881,3 @@ timeout: Infinity // much more than 10 seconds

if (signal?.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -877,2 +914,3 @@ return;

let abortListener;
// eslint-disable-next-line prefer-const
let sub; // avoid TDZ when disposing synchronously

@@ -891,2 +929,3 @@

// XState does not "own" the signal, so we should reject with its reason (if any)
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -900,2 +939,3 @@ };

dispose();
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(err);

@@ -914,2 +954,2 @@ },

export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, waitFor };
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
import { t as toArray, S as STATE_DELIMITER, m as mapValues, 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 toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-0f7cf128.esm.js';
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-0f7cf128.esm.js';
import { a as assign } from './log-15d0f775.esm.js';
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-15d0f775.esm.js';
import { t as toArray, S as STATE_DELIMITER, m as mapValues, 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 toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-c17ec2bc.esm.js';
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-c17ec2bc.esm.js';
import { a as assign } from './log-2a773d37.esm.js';
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-2a773d37.esm.js';
import '../dev/dist/xstate-dev.esm.js';

@@ -225,6 +225,6 @@

const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
const resolvedSrc = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
return {
...invokeConfig,
src: resolvedSrc,
src: sourceName,
id: resolvedId,

@@ -241,3 +241,3 @@ systemId: systemId,

type: 'xstate.invoke',
src: resolvedSrc,
src: sourceName,
id: resolvedId

@@ -425,3 +425,3 @@ };

transition(snapshot, event, actorScope) {
return macrostep(snapshot, event, actorScope).snapshot;
return macrostep(snapshot, event, actorScope, []).snapshot;
}

@@ -437,3 +437,3 @@

microstep(snapshot, event, actorScope) {
return macrostep(snapshot, event, actorScope).microstates;
return macrostep(snapshot, event, actorScope, []).microstates;
}

@@ -468,3 +468,3 @@ getTransitionData(snapshot, event) {

});
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue);
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
}

@@ -547,3 +547,3 @@ return preInitial;

}, this);
let seen = new Set();
const seen = new Set();
function reviveContext(contextPart, children) {

@@ -554,3 +554,3 @@ if (seen.has(contextPart)) {

seen.add(contextPart);
for (let key in contextPart) {
for (const key in contextPart) {
const value = contextPart[key];

@@ -571,6 +571,2 @@ if (value && typeof value === 'object') {

// this is not 100% accurate since we can't make parallel regions required in the result
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
// this is fine for most practical use cases anyway though
/**

@@ -633,6 +629,9 @@ * Creates a state machine (statechart) with the given configuration.

system: self.system,
emit: () => {}
emit: () => {},
actionExecutor: () => {}
};
return inertActorScope;
}
/** @deprecated Use `initialTransition(…)` instead. */
function getInitialSnapshot(actorLogic, ...[input]) {

@@ -650,2 +649,3 @@ const actorScope = createInertActorScope(actorLogic);

*
* @deprecated Use `transition(…)` instead.
* @example

@@ -705,2 +705,5 @@ *

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
class SimulatedClock {

@@ -806,2 +809,35 @@ constructor() {

/**
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
* `nextSnapshot` and `actions` to execute.
*
* This is a pure function that does not execute `actions`.
*/
function transition(logic, snapshot, event) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.transition(snapshot, event, actorScope);
return [nextSnapshot, executableActions];
}
/**
* Given actor `logic` and optional `input`, returns a tuple of the
* `nextSnapshot` and `actions` to execute from the initial transition (no
* previous state).
*
* This is a pure function that does not execute `actions`.
*/
function initialTransition(logic, ...[input]) {
const executableActions = [];
const actorScope = createInertActorScope(logic);
actorScope.actionExecutor = action => {
executableActions.push(action);
};
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
return [nextSnapshot, executableActions];
}
const defaultWaitForOptions = {

@@ -842,2 +878,3 @@ timeout: Infinity // much more than 10 seconds

if (signal?.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -871,2 +908,3 @@ return;

let abortListener;
// eslint-disable-next-line prefer-const
let sub; // avoid TDZ when disposing synchronously

@@ -885,2 +923,3 @@

// XState does not "own" the signal, so we should reject with its reason (if any)
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(signal.reason);

@@ -894,2 +933,3 @@ };

dispose();
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
rej(err);

@@ -908,2 +948,2 @@ },

export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, 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="xstate.init",i="xstate.error",r="xstate.stop";function a(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=a();e&&e.register(t)};function u(t,e){return{type:`xstate.done.state.${t}`,output:e}}function h(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function f(t){return{type:o,input:t}}function d(t){setTimeout((()=>{throw t}))}const p="function"==typeof Symbol&&Symbol.observable||"@@observable";function l(t,e){const s=g(t),n=g(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&l(s[t],n[t])))}function y(t){if(x(t))return t;let e=[],s="";for(let n=0;n<t.length;n++){switch(t.charCodeAt(n)){case 92:s+=t[n+1],n++;continue;case 46:e.push(s),s="";continue}s+=t[n]}return e.push(s),e}function g(t){if(Rt(t))return t.value;if("string"!=typeof t)return t;return v(y(t))}function v(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 m(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 _(t){return x(t)?t:[t]}function b(t){return void 0===t?[]:_(t)}function S(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function x(t){return Array.isArray(t)}function w(t){return _(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function I(t){if(void 0!==t&&t!==n)return b(t)}function k(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){return`${e}.${t}`}function E(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}function T(t,e){return`${t.sessionId}.${e}`}let O=0;const j=1;let A=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const M={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class N{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.eventListeners=new Map,this.logger=void 0,this._processingStatus=A.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={...M,...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={},{clock:a,logger:c}=e,u={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=T(t,o);h._snapshot._scheduledEvents[c]=i;const u=a.setTimeout((()=>{delete r[c],delete h._snapshot._scheduledEvents[c],h._relay(t,e,s)}),n);r[c]=u},cancel:(t,e)=>{const s=T(t,e),n=r[s];delete r[s],delete h._snapshot._scheduledEvents[s],void 0!==n&&a.clearTimeout(n)},cancelAll:t=>{for(const e in h._snapshot._scheduledEvents){const s=h._snapshot._scheduledEvents[e];s.source===t&&u.cancel(t,s.id)}}},h={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+O++,_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=>{const e=k(t);return i.add(e),{unsubscribe(){i.delete(e)}}},_sendInspectionEvent:e=>{if(!i.size)return;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:u,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];u.schedule(s,n,o,i,r)}},_clock:a,_logger:c};return h}(this,{clock:o,logger:i}),h&&!r&&this.system.inspect(k(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,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()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(!e&&!s)return;const n=new Set([...e?e.values():[],...s?s.values():[]]);for(const e of Array.from(n))e(t)}},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){d(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){d(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o,actorId:n}),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=k(t,e,s);if(this._processingStatus!==A.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){d(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){d(t)}else d(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const n=e.bind(void 0);return s.add(n),{unsubscribe:()=>{s.delete(n)}}}start(){if(this._processingStatus===A.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=A.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===r&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===A.Stopped?this:(this.mailbox.clear(),this._processingStatus===A.NotStarted?(this._processingStatus=A.Stopped,this):(this.mailbox.enqueue({type:r}),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){d(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||d(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){d(t)}}this.observers.clear(),e&&d(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,h(this.id,t))}_stopProcedure(){return this._processingStatus!==A.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=A.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==A.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:c)(this)}}toJSON(){return{xstate$$type:j,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[p](){return this}getSnapshot(){return this._snapshot}}function P(t,...[e]){return new N(t,e)}const R=P;function C(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function D(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function J(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=D,e}function V(t,e,s,n,{id:o,systemId:i,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?E(e.machine,r):r,h="function"==typeof o?o(s):o;let f;return u&&(f=P(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})),[Lt(e,{children:{...e.children,[h]:f}}),{id:o,actorRef:f}]}function B(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==A.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=V,i.execute=B,i}function L(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]),[Lt(e,{children:a}),r]}function W(t,e){e&&(t.system._unregister(e),e._processingStatus===A.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=L,e.execute=W,e}const U=q;function Q(t,e,{stateValue:s}){if("string"==typeof s&&it(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function F(t,{context:e,event:s},{guards:n}){return!H(n[0],e,s,t)}function G(t,{context:e,event:s},{guards:n}){return n.every((n=>H(n,e,s,t)))}function X(t,{context:e,event:s},{guards:n}){return n.some((n=>H(n,e,s,t)))}function H(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 H(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 K=t=>"atomic"===t.type||"final"===t.type;function Y(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function Z(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 tt(t){const e=new Set(t),s=st(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 Y(t))if("history"!==s.type&&!e.has(s)){const t=ht(s);for(const s of t)e.add(s)}}else ht(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 et(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(K(t))return t.key}const n={};for(const t of s)n[t.key]=et(t,e);return n}function st(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 nt(t,e){return et(t,st(tt(e)))}function ot(t,e){return"compound"===e.type?Y(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Y(e).every((e=>ot(t,e))):"final"===e.type}const it=t=>"#"===t[0];function rt(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=>{const s=(n=e,o=t.id,{type:`xstate.after.${n}.${o}`});var n,o;const i=s.type;return t.entry.push(Yt(s,{id:i,delay:e})),t.exit.push(J(i)),i})(r);return b(i).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...at(t,e.event,e),delay:s}}))}function at(t,e,n){const o=I(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(it(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return pt(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 pt(t.parent,o)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,o),a={...n,actions:b(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 ct(t){const e=I(t.config.target);return e?{target:e.map((e=>"string"==typeof e?pt(t.parent,e):e))}:t.parent.initial}function ut(t){return"history"===t.type}function ht(t){const e=ft(t);for(const s of e)for(const n of Z(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 Y(s))t(e)}(t),e}function dt(t,e){if(it(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 pt(t,e){if("string"==typeof e&&it(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=y(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=dt(n,t)}return n}function lt(t,e){if("string"==typeof e){const s=t.states[e];if(!s)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,s]}const s=Object.keys(e),n=s.map((e=>dt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const o=dt(t,n);if(!o)return s;const i=lt(o,e[n]);return s.concat(i)}),[]))}function yt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const o=dt(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=yt(dt(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=yt(dt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function gt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function vt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function mt(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 _t(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(mt(xt([o],e,s),xt([r],e,s))){if(!vt(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 bt(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ut(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of bt(ct(n),e))s.add(t);else s.add(n);return[...s]}function St(t,e){const s=bt(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||vt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of Z(e,void 0))if(s.every((e=>vt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function xt(t,e,s){const n=new Set;for(const o of t)if(o.target?.length){const t=St(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)vt(s,t)&&n.add(s)}return[...n]}function wt(t,e,s,n,o,i){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const c=_t(t,r,a);let h=e;o||([h,a]=function(t,e,s,n,o,i,r){let a=t;const c=xt(n,o,i);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of gt(t)){let s;s="deep"===e.history?e=>K(e)&&vt(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]}(h,n,s,c,r,a,i)),h=jt(h,n,s,c.flatMap((t=>t.actions)),i),h=function(t,e,s,n,o,i,r,a){let c=t;const h=new Set,f=new Set;(function(t,e,s,n){for(const o of t){const t=St(o,e);for(const i of o.target||[])ut(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),kt(i,e,s,n);const i=bt(o,e);for(const r of i){const i=Z(r,t);"parallel"===t?.type&&i.push(t),$t(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,f,h),a&&f.add(t.machine.root);const d=new Set;for(const t of[...h].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(f.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(u(n.id,void 0!==t.output?S(t.output,c.context,e,s.self):void 0));"parallel"===r?.type&&!d.has(r)&&ot(o,r);)d.add(r),i.push(u(r.id)),a=r,r=r.parent;if(r)continue;c=Lt(c,{status:"done",output:It(c,e,s,c.machine.root,a)})}}return c}(h,n,s,c,r,i,a,o);const f=[...r];"done"===h.status&&(h=jt(h,n,s,f.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)?h:Lt(h,{_nodes:f,historyValue:a})}catch(t){throw t}}function It(t,e,s,n,o){if(void 0===n.output)return;const i=u(o.id,void 0!==o.output&&o.parent?S(o.output,t.context,e,s.self):void 0);return S(n.output,t.context,i,s.self)}function kt(t,e,s,n){if(ut(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),kt(t,e,s,n);for(const i of o)Et(i,t.parent,n,e,s)}else{const o=ct(t);for(const i of o.target)n.add(i),o===t.parent?.initial&&s.add(t.parent),kt(i,e,s,n);for(const i of o.target)Et(i,t.parent,n,e,s)}else if("compound"===t.type){const[o]=t.initial.target;ut(o)||(n.add(o),s.add(o)),kt(o,e,s,n),Et(o,t,n,e,s)}else if("parallel"===t.type)for(const o of Y(t).filter((t=>!ut(t))))[...n].some((t=>vt(t,o)))||(ut(o)||(n.add(o),s.add(o)),kt(o,e,s,n))}function $t(t,e,s,n,o){for(const i of n)if(o&&!vt(i,o)||t.add(i),"parallel"===i.type)for(const n of Y(i).filter((t=>!ut(t))))[...t].some((t=>vt(t,n)))||(t.add(n),kt(n,e,s,t))}function Et(t,e,s,n,o){$t(s,n,o,Z(t,e))}let Tt=!1;function Ot(t,e,s,n,o,i){const{machine:r}=t;let a=t;for(const c of n){const u="function"==typeof c,h=u?c:r.implementations.actions["string"==typeof c?c:c.type];if(!h)continue;const f={context:a.context,event:e,self:s.self,system:s.system},d=u||"string"==typeof c?void 0:"params"in c?"function"==typeof c.params?c.params({context:a.context,event:e}):c.params:void 0;function p(){s.system._sendInspectionEvent({type:"@xstate.action",actorRef:s.self,action:{type:"string"==typeof c?c:"object"==typeof c?c.type:c.name||"(anonymous)",params:d}});try{Tt=h,h(f,d)}finally{Tt=!1}}if(!("resolve"in h)){s.self._processingStatus===A.Running?p():s.defer((()=>{p()}));continue}const l=h,[y,g,v]=l.resolve(s,a,f,d,h,o);a=y,"retryResolve"in l&&i?.push([l,g]),"execute"in l&&(s.self._processingStatus===A.Running?l.execute(s,g):s.defer(l.execute.bind(null,s,g))),v&&(a=Ot(a,e,s,v,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 i=t;const a=[];function c(t,e,n){s.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:s.self,event:e,snapshot:t,_transitions:n}),a.push(t)}if(e.type===r)return i=Lt(Mt(i,e,s),{status:"stopped"}),c(i,e,[]),{snapshot:i,microstates:a};let u=e;if(u.type!==o){const e=u,o=function(t){return t.type.startsWith("xstate.error.actor")}(e),r=Nt(e,i);if(o&&!r.length)return i=Lt(t,{status:"error",error:e.error}),c(i,e,[]),{snapshot:i,microstates:a};i=wt(r,t,s,u,!1,n),c(i,e,r)}let h=!0;for(;"active"===i.status;){let t=h?Pt(i,u):[];const e=t.length?i:void 0;if(!t.length){if(!n.length)break;u=n.shift(),t=Nt(u,i)}i=wt(t,i,s,u,!1,n),h=i!==e,c(i,u,t)}return"active"!==i.status&&Mt(i,u,s),{snapshot:i,microstates:a}}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(K);for(const o of n)t:for(const n of[o].concat(Z(o,void 0)))if(n.always)for(const o of n.always)if(void 0===o.guard||H(o.guard,t.context,e,t)){s.add(o);break t}return _t(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 l(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 zt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:nt(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 Lt(t,e={}){return zt({...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:j,id:n.id};else{const o=Wt(n);o!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=o)}}return e??t}function qt(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=E(e,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const h=P(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 P(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!==A.Stopped&&a.start()})),a}}function Ut(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:qt(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[Lt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Qt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function Ft(t,e,s,n,{event:o}){return[e,{event:"function"==typeof o?o(s,n):o}]}function Gt(t,{event:e}){t.defer((()=>t.emit(e)))}function Xt(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=Ft,e.execute=Gt,e}function Ht(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 Kt(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 Yt(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Ht,s.execute=Kt,s}let Zt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function te(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 f;if("string"==typeof a){const t=u&&u[a];f="function"==typeof t?t(s,n):t}else f="function"==typeof a?a(s,n):a;const d="function"==typeof o?o(s,n):o;let p;if("string"==typeof d){if(p=d===Zt.Parent?t.self._parent:d===Zt.Internal?t.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t.self;return[e,{to:p,event:h,id:r,delay:f}]}function ee(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function se(t,e){t.defer((()=>{const{to:s,event:n,delay:o,id:r}=e;"number"!=typeof o?t.system._relay(t.self,s,n.type===i?h(t.self.id,n.data):n):t.system.scheduler.schedule(t.self,s,n,o,r)}))}function ne(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=te,n.retryResolve=ee,n.execute=se,n}function oe(t,e){return ne(Zt.Parent,t,e)}function ie(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Qt(...t))},r.cancel=(...t)=>{i.push(J(...t))},r.raise=(...t)=>{i.push(Yt(...t))},r.sendTo=(...t)=>{i.push(ne(...t))},r.sendParent=(...t)=>{i.push(oe(...t))},r.spawnChild=(...t)=>{i.push(z(...t))},r.stopChild=(...t)=>{i.push(q(...t))},r.emit=(...t)=>{i.push(Xt(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>H(t,e.context,s.event,e),self:t.self,system:t.system},n),[e,void 0,i]}function re(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ae({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function ce(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 ue=new WeakMap;const he="xstate.observable.next",fe="xstate.observable.error",de="xstate.observable.complete";const pe="xstate.promise.resolve",le="xstate.promise.reject",ye=new WeakMap;const ge=ce((t=>{}),void 0);const ve=new WeakMap;function me(t,e,s){let n=ve.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},ve.set(t,n)),n[e]}const _e={},be=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class Se{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?m(this.config.states,((t,e)=>new Se(t,{_parent:this,_key:e,_machine:this.machine}))):_e,"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=b(this.config.entry).slice(),this.exit=b(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=b(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)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,w(n).map((e=>at(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,w(t.config.onDone).map((e=>at(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,w(s.onDone).map((e=>at(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,w(s.onError).map((e=>at(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,w(s.onSnapshot).map((e=>at(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=w(this.config.always).map((t=>at(this,"",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(be),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(be),eventType:null})}:void 0,history:this.history,states:m(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(be)}))),entry:this.entry.map(be),exit:this.exit.map(be),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 me(this,"invoke",(()=>b(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??$(this.id,e),i="string"==typeof s?s:`xstate.invoke.${$(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 me(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 me(this,"delayedTransitions",(()=>rt(this)))}get initial(){return me(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?b(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=me(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||H(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 me(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 xe{constructor(t,e){this.config=t,this.version=void 0,this.schemas=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.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,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 Se(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 xe(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,nt(s,[...tt(lt(s,n))]));var s,n;const o=tt(lt(this.root,e));return zt({_nodes:[...o],context:t.context||{},children:{},status:ot(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 yt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=zt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return jt(o,e,t,[Qt((({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=wt([{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=y(t),s=e.slice(1),n=it(e[0])?e[0].slice(1):e[0],o=this.idMap.get(n);if(!o)throw new Error(`Child state node '#${n}' does not exist on machine '${this.id}'`);return pt(o,s)}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:f,...d}=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{...d,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?E(this,r):r;if(!a)return;const c=P(a,{id:t,parent:e.self,syncSnapshot:o.syncSnapshot,snapshot:i,src:r,systemId:o.systemId});s[t]=c}));const o=zt({...t,children:s,_nodes:Array.from(tt(lt(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===j){e[n]=s[o.id];continue}t(o,s)}}}}(o.context,s),o}}function we(t,e){return new xe(t,e)}function Ie(t){const e=P(t);return{self:e,defer:()=>{},id:"",logger:()=>{},sessionId:"",stopChild:()=>{},system:e.system,emit:()=>{}}}const ke={timeout:1/0};t.Actor=N,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=Zt,t.StateMachine=xe,t.StateNode=Se,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=G,e.guards=t,e},t.assertEvent=function(t,e){const s=b(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=Qt,t.cancel=J,t.createActor=P,t.createEmptyActor=function(){return P(ge)},t.createMachine=we,t.emit=Xt,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ie,e},t.forwardTo=function(t,e){return ne(t,(({event:t})=>t),e)},t.fromCallback=function(t){const e={config:t,start:(e,s)=>{const{self:n,system:o,emit:i}=s,r={receivers:void 0,dispose:void 0};ue.set(n,r),r.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=>{r.receivers??=new Set,r.receivers.add(t)},emit:i})},transition:(t,e,s)=>{const n=ue.get(s.self);return e.type===r?(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};return e},t.fromEventObservable=function(t){const e={config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case fe:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case de:return{...t,status:"done",input:void 0,_subscription:void 0};case r: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,emit:o})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s,emit:o}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:fe,data:t})},complete:()=>{n._relay(s,s,{type:de})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})};return e},t.fromObservable=function(t){const e={config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case he:return{...t,context:e.data};case fe:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case de:return{...t,status:"done",input:void 0,_subscription:void 0};case r: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,emit:o})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s,emit:o}).subscribe({next:t=>{n._relay(s,s,{type:he,data:t})},error:t=>{n._relay(s,s,{type:fe,data:t})},complete:()=>{n._relay(s,s,{type:de})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})};return e},t.fromPromise=function(t){const e={config:t,transition:(t,e,s)=>{if("active"!==t.status)return t;switch(e.type){case pe:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case le:return{...t,status:"error",error:e.data,input:void 0};case r:return ye.get(s.self)?.abort(),{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:n,emit:o})=>{if("active"!==e.status)return;const i=new AbortController;ye.set(s,i);Promise.resolve(t({input:e.input,system:n,self:s,signal:i.signal,emit:o})).then((t=>{"active"===s.getSnapshot().status&&(ye.delete(s),n._relay(s,s,{type:pe,data:t}))}),(t=>{"active"===s.getSnapshot().status&&(ye.delete(s),n._relay(s,s,{type:le,data:t}))}))},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t};return e},t.fromTransition=ce,t.getInitialSnapshot=function(t,...[e]){const s=Ie(t);return t.getInitialSnapshot(s,e)},t.getNextSnapshot=function(t,e,s){const n=Ie(t);return n.self._snapshot=e,t.transition(e,s,n)},t.getStateNodes=lt,t.interpret=R,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=re,s.execute=ae,s},t.matchesState=l,t.not=function(t){function e(t,e){return!1}return e.check=F,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=X,e.guards=t,e},t.pathToStateValue=v,t.raise=Yt,t.sendParent=oe,t.sendTo=ne,t.setup=function({schemas:t,actors:e,actions:s,guards:n,delays:o}){return{createMachine:i=>we({...i,schemas:t},{actors:e,actions:s,guards:n,delays:o})}},t.spawnChild=z,t.stateIn=function(t){function e(t,e){return!1}return e.check=Q,e.stateValue=t,e},t.stop=U,t.stopChild=q,t.toObserver=k,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={...ke,...s};return new Promise(((s,o)=>{const{signal:i}=n;if(i?.aborted)return void o(i.reason);let r=!1;const a=n.timeout===1/0?void 0:setTimeout((()=>{c(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),c=()=>{clearTimeout(a),r=!0,f?.unsubscribe(),h&&i.removeEventListener("abort",h)};function u(t){e(t)&&(c(),s(t))}let h,f;u(t.getSnapshot()),r||(i&&(h=()=>{c(),o(i.reason)},i.addEventListener("abort",h)),f=t.subscribe({next:u,error:t=>{c(),o(t)},complete:()=>{c(),o(new Error("Actor terminated without satisfying predicate"))}}),r&&f.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="xstate.init",i="xstate.error",r="xstate.stop";function a(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=a();e&&e.register(t)};function u(t,e){return{type:`xstate.done.state.${t}`,output:e}}function h(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function d(t){return{type:o,input:t}}function f(t){setTimeout((()=>{throw t}))}const p="function"==typeof Symbol&&Symbol.observable||"@@observable";function l(t,e){const s=v(t),n=v(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&l(s[t],n[t])))}function y(t){if(S(t))return t;const e=[];let s="";for(let n=0;n<t.length;n++){switch(t.charCodeAt(n)){case 92:s+=t[n+1],n++;continue;case 46:e.push(s),s="";continue}s+=t[n]}return e.push(s),e}function v(t){if(Ct(t))return t.value;if("string"!=typeof t)return t;return g(y(t))}function g(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 m(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 _(t){return S(t)?t:[t]}function b(t){return void 0===t?[]:_(t)}function x(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function S(t){return Array.isArray(t)}function w(t){return _(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function I(t){if(void 0!==t&&t!==n)return b(t)}function k(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 E(t,e){return`${e}.${t}`}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}function T(t,e){return`${t.sessionId}.${e}`}let O=0;let j=!1;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.eventListeners=new Map,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={},{clock:a,logger:c}=e,u={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=T(t,o);h._snapshot._scheduledEvents[c]=i;const u=a.setTimeout((()=>{delete r[c],delete h._snapshot._scheduledEvents[c],h._relay(t,e,s)}),n);r[c]=u},cancel:(t,e)=>{const s=T(t,e),n=r[s];delete r[s],delete h._snapshot._scheduledEvents[s],void 0!==n&&a.clearTimeout(n)},cancelAll:t=>{for(const e in h._snapshot._scheduledEvents){const s=h._snapshot._scheduledEvents[e];s.source===t&&u.cancel(t,s.id)}}},h={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+O++,_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=>{const e=k(t);return i.add(e),{unsubscribe(){i.delete(e)}}},_sendInspectionEvent:e=>{if(!i.size)return;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:u,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];u.schedule(s,n,o,i,r)}},_clock:a,_logger:c};return h}(this,{clock:o,logger:i}),h&&!r&&this.system.inspect(k(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,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()},emit:t=>{const e=this.eventListeners.get(t.type),s=this.eventListeners.get("*");if(!e&&!s)return;const n=[...e?e.values():[],...s?s.values():[]];for(const e of n)e(t)},actionExecutor:t=>{const e=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:t.type,params:t.params}}),!t.exec)return;const e=j;try{j=!0,t.exec(t.info,t.params)}finally{j=e}};this._processingStatus===M.Running?e():this._deferred.push(e)}},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){f(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){f(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o,actorId:n}),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=k(t,e,s);if(this._processingStatus!==M.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(t){f(t)}break;case"error":{const t=this._snapshot.error;if(n.error)try{n.error(t)}catch(t){f(t)}else f(t);break}}return{unsubscribe:()=>{this.observers.delete(n)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const n=e.bind(void 0);return s.add(n),{unsubscribe:()=>{s.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=d(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===r&&(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:r}),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){f(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||f(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){f(t)}}this.observers.clear(),e&&f(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,h(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:c)(this)}}toJSON(){return{xstate$$type:A,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[p](){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,{sendId:"function"==typeof o?o(s,n):o},void 0]}function J(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e.sendId)}))}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?$(e.machine,r):r,h="function"==typeof o?o(s):o;let d,f;return u&&(f="function"==typeof a?a({context:e.context,event:s.event,self:t.self}):a,d=R(u,{id:h,src:r,parent:t.self,syncSnapshot:c,systemId:i,input:f})),[Wt(e,{children:{...e.children,[h]:d}}),{id:o,systemId:i,actorRef:d,src:r,input:f},void 0]}function z(t,{actorRef:e}){e&&t.defer((()=>{e._processingStatus!==M.Stopped&&e.start()}))}function L(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="xstate.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=B,i.execute=z,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]),[Wt(e,{children:a}),r,void 0]}function q(t,e){e&&(t.system._unregister(e),e._processingStatus===M.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function U(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=W,e.execute=q,e}const Q=U;function F(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 G(t,{context:e,event:s},{guards:n}){return!K(n[0],e,s,t)}function X(t,{context:e,event:s},{guards:n}){return n.every((n=>K(n,e,s,t)))}function H(t,{context:e,event:s},{guards:n}){return n.some((n=>K(n,e,s,t)))}function K(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 K(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[];const s=Object.keys(e).flatMap((s=>{const n=e[s],o="string"==typeof n?{target:n}:n,i=Number.isNaN(+s)?s:+s,r=(e=>{const s=(n=e,o=t.id,{type:`xstate.after.${n}.${o}`});var n,o;const i=s.type;return t.entry.push(Zt(s,{id:i,delay:e})),t.exit.push(V(i)),i})(i);return b(o).map((t=>({...t,event:r,delay:i})))}));return s.map((e=>{const{delay:s}=e;return{...ct(t,e.event,e),delay:s}}))}function ct(t,e,n){const o=I(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:b(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=I(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{}const s=y(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){const s=t.states[e];if(!s)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,s]}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 vt(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=vt(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=vt(pt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function gt(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 xt(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 xt(ut(n),e))s.add(t);else s.add(n);return[...s]}function St(t,e){const s=xt(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=St(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)mt(s,t)&&n.add(s)}return[...n]}function It(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 h=e;o||([h,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 gt(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=At(a,e,s,[...t.exit,...t.invoke.map((t=>U(t.id)))],r,void 0),o.delete(t);return[a,u||i]}(h,n,s,c,r,a,i,s.actionExecutor)),h=At(h,n,s,c.flatMap((t=>t.actions)),i,void 0),h=function(t,e,s,n,o,i,r,a){let c=t;const h=new Set,d=new Set;(function(t,e,s,n){for(const o of t){const t=St(o,e);for(const i of o.target||[])ht(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),Et(i,e,s,n);const i=xt(o,e);for(const r of i){const i=tt(r,t);"parallel"===t?.type&&i.push(t),$t(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,d,h),a&&d.add(t.machine.root);const f=new Set;for(const t of[...h].sort(((t,e)=>t.order-e.order))){o.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(L(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(d.has(t)){const e=t.initial.actions;n.push(...e)}if(c=At(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(u(n.id,void 0!==t.output?x(t.output,c.context,e,s.self):void 0));"parallel"===r?.type&&!f.has(r)&&it(o,r);)f.add(r),i.push(u(r.id)),a=r,r=r.parent;if(r)continue;c=Wt(c,{status:"done",output:kt(c,e,s,c.machine.root,a)})}}return c}(h,n,s,c,r,i,a,o);const d=[...r];"done"===h.status&&(h=At(h,n,s,d.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),i,void 0));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)?h:Wt(h,{_nodes:d,historyValue:a})}catch(t){throw t}}function kt(t,e,s,n,o){if(void 0===n.output)return;const i=u(o.id,void 0!==o.output&&o.parent?x(o.output,t.context,e,s.self):void 0);return x(n.output,t.context,i,s.self)}function Et(t,e,s,n){if(ht(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),Et(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),Et(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)),Et(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)),Et(o,e,s,n))}function $t(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),Et(n,e,s,t))}function Tt(t,e,s,n,o){$t(s,n,o,tt(t,e))}function Ot(t,e){return t.implementations.actions[e]}function jt(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:Ot(r,"string"==typeof t?t:t.type),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(!c||!("resolve"in c)){s.actionExecutor({type:"string"==typeof t?t:"object"==typeof t?t.type:t.name||"(anonymous)",info:u,params:h,exec:c});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.actionExecutor({type:d.type,info:u,params:p,exec:d.execute.bind(null,s,p)}),l&&(a=jt(a,e,s,l,o,i))}return a}function At(t,e,s,n,o,i){const r=i?[]:void 0,a=jt(t,e,s,n,{internalQueue:o,deferredActorIds:i},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function Mt(t,e,s,n){let i=t;const a=[];function c(t,e,n){s.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:s.self,event:e,snapshot:t,_transitions:n}),a.push(t)}if(e.type===r)return i=Wt(Nt(i,e,s),{status:"stopped"}),c(i,e,[]),{snapshot:i,microstates:a};let u=e;if(u.type!==o){const e=u,o=function(t){return t.type.startsWith("xstate.error.actor")}(e),r=Pt(e,i);if(o&&!r.length)return i=Wt(t,{status:"error",error:e.error}),c(i,e,[]),{snapshot:i,microstates:a};i=It(r,t,s,u,!1,n),c(i,e,r)}let h=!0;for(;"active"===i.status;){let t=h?Rt(i,u):[];const e=t.length?i:void 0;if(!t.length){if(!n.length)break;u=n.shift(),t=Pt(u,i)}i=It(t,i,s,u,!1,n),h=i!==e,c(i,u,t)}return"active"!==i.status&&Nt(i,u,s),{snapshot:i,microstates:a}}function Nt(t,e,s){return At(t,e,s,Object.values(t.children).map((t=>U(t))),[],void 0)}function Pt(t,e){return e.machine.getTransitionData(e,t)}function Rt(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||K(o.guard,t.context,e,t)){s.add(o);break t}return bt(Array.from(s),new Set(t._nodes),t.historyValue)}function Ct(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Dt=function(t){return l(t,this.value)},Jt=function(t){return this.tags.has(t)},Vt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Bt=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)}},zt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Lt(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:Dt,hasTag:Jt,can:Vt,getMeta:zt,toJSON:Bt}}function Wt(t,e={}){return Lt({...t,...e},t.machine)}function qt(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=qt(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=$(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[Wt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children}),void 0,void 0]}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}){return[e,{event:"function"==typeof o?o(s,n):o},void 0]}function Xt(t,{event:e}){t.defer((()=>t.emit(e)))}function Ht(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=Gt,e.execute=Xt,e}function Kt(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},void 0]}function Yt(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 Zt(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Kt,s.execute=Yt,s}let te=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ee(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===te.Parent?t.self._parent:f===te.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,targetId:"string"==typeof f?f:void 0,event:h,id:r,delay:d},void 0]}function se(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function ne(t,e){t.defer((()=>{const{to:s,event:n,delay:o,id:r}=e;"number"!=typeof o?t.system._relay(t.self,s,n.type===i?h(t.self.id,n.data):n):t.system.scheduler.schedule(t.self,s,n,o,r)}))}function oe(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=ee,n.retryResolve=se,n.execute=ne,n}function ie(t,e){return oe(te.Parent,t,e)}function re(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(Zt(...t))},r.sendTo=(...t)=>{i.push(oe(...t))},r.sendParent=(...t)=>{i.push(ie(...t))},r.spawnChild=(...t)=>{i.push(L(...t))},r.stopChild=(...t)=>{i.push(U(...t))},r.emit=(...t)=>{i.push(Ht(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>K(t,e.context,s.event,e),self:t.self,system:t.system},n),[e,void 0,i]}function ae(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i},void 0]}function ce({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function ue(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 he=new WeakMap;const de="xstate.observable.next",fe="xstate.observable.error",pe="xstate.observable.complete";const le="xstate.promise.resolve",ye="xstate.promise.reject",ve=new WeakMap;const ge=ue((t=>{}),void 0);const me=new WeakMap;function _e(t,e,s){let n=me.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},me.set(t,n)),n[e]}const be={},xe=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class Se{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?m(this.config.states,((t,e)=>new Se(t,{_parent:this,_key:e,_machine:this.machine}))):be,"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=b(this.config.entry).slice(),this.exit=b(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=b(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)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,w(n).map((e=>ct(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,w(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,w(s.onDone).map((e=>ct(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,w(s.onError).map((e=>ct(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,w(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=w(this.config.always).map((t=>ct(this,"",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(xe),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(xe),eventType:null})}:void 0,history:this.history,states:m(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(xe)}))),entry:this.entry.map(xe),exit:this.exit.map(xe),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 _e(this,"invoke",(()=>b(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??E(this.id,e),i="string"==typeof s?s:`xstate.invoke.${E(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 _e(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 _e(this,"delayedTransitions",(()=>at(this)))}get initial(){return _e(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?b(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=_e(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||K(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 _e(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 we{constructor(t,e){this.config=t,this.version=void 0,this.schemas=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.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,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 Se(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 we(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 Lt({_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 Mt(t,e,s,[]).snapshot}microstep(t,e,s){return Mt(t,e,s,[]).microstates}getTransitionData(t,e){return vt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=Lt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return At(o,e,t,[Ft((({spawn:t,event:e,self:s})=>n({spawn:t,input:e.input,self:s})))],s,void 0)}return o}getInitialSnapshot(t,e){const s=d(e),n=[],o=this.getPreInitialState(t,s,n),i=It([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],o,t,s,!0,n),{snapshot:r}=Mt(i,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=y(t),s=e.slice(1),n=rt(e[0])?e[0].slice(1):e[0],o=this.idMap.get(n);if(!o)throw new Error(`Child state node '#${n}' does not exist on machine '${this.id}'`);return lt(o,s)}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:qt(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?$(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=Lt({...t,children:s,_nodes:Array.from(et(yt(this.root,t.value)))},this),i=new Set;return function t(e,s){if(!i.has(e)){i.add(e);for(const 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}}function Ie(t,e){return new we(t,e)}function ke(t){const e=R(t);return{self:e,defer:()=>{},id:"",logger:()=>{},sessionId:"",stopChild:()=>{},system:e.system,emit:()=>{},actionExecutor:()=>{}}}const Ee={timeout:1/0};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=te,t.StateMachine=we,t.StateNode=Se,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=X,e.guards=t,e},t.assertEvent=function(t,e){const s=b(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(ge)},t.createMachine=Ie,t.emit=Ht,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=re,e},t.forwardTo=function(t,e){return oe(t,(({event:t})=>t),e)},t.fromCallback=function(t){const e={config:t,start:(e,s)=>{const{self:n,system:o,emit:i}=s,r={receivers:void 0,dispose:void 0};he.set(n,r),r.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=>{r.receivers??=new Set,r.receivers.add(t)},emit:i})},transition:(t,e,s)=>{const n=he.get(s.self);return e.type===r?(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};return e},t.fromEventObservable=function(t){const e={config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case fe:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case pe:return{...t,status:"done",input:void 0,_subscription:void 0};case r: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,emit:o})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s,emit:o}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:fe,data:t})},complete:()=>{n._relay(s,s,{type:pe})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})};return e},t.fromObservable=function(t){const e={config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case de:return{...t,context:e.data};case fe:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case pe:return{...t,status:"done",input:void 0,_subscription:void 0};case r: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,emit:o})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s,emit:o}).subscribe({next:t=>{n._relay(s,s,{type:de,data:t})},error:t=>{n._relay(s,s,{type:fe,data:t})},complete:()=>{n._relay(s,s,{type:pe})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})};return e},t.fromPromise=function(t){const e={config:t,transition:(t,e,s)=>{if("active"!==t.status)return t;switch(e.type){case le:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case ye:return{...t,status:"error",error:e.data,input:void 0};case r:return ve.get(s.self)?.abort(),{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:n,emit:o})=>{if("active"!==e.status)return;const i=new AbortController;ve.set(s,i);Promise.resolve(t({input:e.input,system:n,self:s,signal:i.signal,emit:o})).then((t=>{"active"===s.getSnapshot().status&&(ve.delete(s),n._relay(s,s,{type:le,data:t}))}),(t=>{"active"===s.getSnapshot().status&&(ve.delete(s),n._relay(s,s,{type:ye,data:t}))}))},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t};return e},t.fromTransition=ue,t.getInitialSnapshot=function(t,...[e]){const s=ke(t);return t.getInitialSnapshot(s,e)},t.getNextSnapshot=function(t,e,s){const n=ke(t);return n.self._snapshot=e,t.transition(e,s,n)},t.getStateNodes=yt,t.initialTransition=function(t,...[e]){const s=[],n=ke(t);return n.actionExecutor=t=>{s.push(t)},[t.getInitialSnapshot(n,e),s]},t.interpret=C,t.isMachineSnapshot=Ct,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=ae,s.execute=ce,s},t.matchesState=l,t.not=function(t){function e(t,e){return!1}return e.check=G,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.pathToStateValue=g,t.raise=Zt,t.sendParent=ie,t.sendTo=oe,t.setup=function({schemas:t,actors:e,actions:s,guards:n,delays:o}){return{createMachine:i=>Ie({...i,schemas:t},{actors:e,actions:s,guards:n,delays:o})}},t.spawnChild=L,t.stateIn=function(t){function e(){return!1}return e.check=F,e.stateValue=t,e},t.stop=Q,t.stopChild=U,t.toObserver=k,t.toPromise=function(t){return new Promise(((e,s)=>{t.subscribe({complete:()=>{e(t.getSnapshot().output)},error:s})}))},t.transition=function(t,e,s){const n=[],o=ke(t);return o.actionExecutor=t=>{n.push(t)},[t.transition(e,s,o),n]},t.waitFor=function(t,e,s){const n={...Ee,...s};return new Promise(((s,o)=>{const{signal:i}=n;if(i?.aborted)return void o(i.reason);let r=!1;const a=n.timeout===1/0?void 0:setTimeout((()=>{c(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),c=()=>{clearTimeout(a),r=!0,d?.unsubscribe(),h&&i.removeEventListener("abort",h)};function u(t){e(t)&&(c(),s(t))}let h,d;u(t.getSnapshot()),r||(i&&(h=()=>{c(),o(i.reason)},i.addEventListener("abort",h)),d=t.subscribe({next:u,error:t=>{c(),o(t)},complete:()=>{c(),o(new Error("Actor terminated without satisfying predicate"))}}),r&&d.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-b1e0b9a9.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-60cebf03.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-e919c5d4.development.cjs.js');
var guards_dist_xstateGuards = require('../../dist/raise-4acdb210.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-5ea71f04.development.esm.js';
export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-1db27a82.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-0f7cf128.esm.js';
export { D as and, e as evaluateGuard, E as not, F as or, G as stateIn } from '../../dist/raise-c17ec2bc.esm.js';
import '../../dev/dist/xstate-dev.esm.js';

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateGuards={})}(this,(function(e){"use strict";const t=e=>"#"===e[0];function n(e,n,{stateValue:r}){if("string"==typeof r&&t(r)){const t=e.machine.getStateNodeById(r);return e._nodes.some((e=>e===t))}return e.matches(r)}function r(e,{context:t,event:n},{guards:r}){return!i(r[0],t,n,e)}function o(e,{context:t,event:n},{guards:r}){return r.every((r=>i(r,t,n,e)))}function u(e,{context:t,event:n},{guards:r}){return r.some((r=>i(r,t,n,e)))}function i(e,t,n,r){const{machine:o}=r,u="function"==typeof e,c=u?e:o.implementations.guards["string"==typeof e?e:e.type];if(!u&&!c)throw new Error(`Guard '${"string"==typeof e?e:e.type}' is not implemented.'.`);if("function"!=typeof c)return i(c,t,n,r);const f={context:t,event:n},s=u||"string"==typeof e?void 0:"params"in e?"function"==typeof e.params?e.params({context:t,event:n}):e.params:void 0;if(!("check"in c))return c(f,s);return c.check(r,f,c)}e.and=function(e){function t(e,t){return!1}return t.check=o,t.guards=e,t},e.evaluateGuard=i,e.not=function(e){function t(e,t){return!1}return t.check=r,t.guards=[e],t},e.or=function(e){function t(e,t){return!1}return t.check=u,t.guards=e,t},e.stateIn=function(e){function t(e,t){return!1}return t.check=n,t.stateValue=e,t},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XStateGuards={})}(this,(function(e){"use strict";const t=e=>"#"===e[0];function n(e,n,{stateValue:r}){if("string"==typeof r&&t(r)){const t=e.machine.getStateNodeById(r);return e._nodes.some((e=>e===t))}return e.matches(r)}function r(e,{context:t,event:n},{guards:r}){return!i(r[0],t,n,e)}function o(e,{context:t,event:n},{guards:r}){return r.every((r=>i(r,t,n,e)))}function u(e,{context:t,event:n},{guards:r}){return r.some((r=>i(r,t,n,e)))}function i(e,t,n,r){const{machine:o}=r,u="function"==typeof e,c=u?e:o.implementations.guards["string"==typeof e?e:e.type];if(!u&&!c)throw new Error(`Guard '${"string"==typeof e?e:e.type}' is not implemented.'.`);if("function"!=typeof c)return i(c,t,n,r);const f={context:t,event:n},s=u||"string"==typeof e?void 0:"params"in e?"function"==typeof e.params?e.params({context:t,event:n}):e.params:void 0;if(!("check"in c))return c(f,s);return c.check(r,f,c)}e.and=function(e){function t(e,t){return!1}return t.check=o,t.guards=e,t},e.evaluateGuard=i,e.not=function(e){function t(e,t){return!1}return t.check=r,t.guards=[e],t},e.or=function(e){function t(e,t){return!1}return t.check=u,t.guards=e,t},e.stateIn=function(e){function t(){return!1}return t.check=n,t.stateValue=e,t},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=xstate-guards.umd.min.js.map
{
"name": "xstate",
"version": "5.18.2",
"version": "5.19.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

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