xstate 5.0.0-beta.27 → 5.0.0-beta.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +9 -7
  2. package/actions/dist/xstate-actions.cjs.js +11 -17
  3. package/actions/dist/xstate-actions.cjs.mjs +0 -8
  4. package/actions/dist/xstate-actions.development.cjs.js +11 -17
  5. package/actions/dist/xstate-actions.development.cjs.mjs +0 -8
  6. package/actions/dist/xstate-actions.development.esm.js +3 -1
  7. package/actions/dist/xstate-actions.esm.js +3 -1
  8. package/actions/dist/xstate-actions.umd.min.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  10. package/actors/dist/xstate-actors.cjs.js +413 -11
  11. package/actors/dist/xstate-actors.development.cjs.js +413 -11
  12. package/actors/dist/xstate-actors.development.esm.js +405 -4
  13. package/actors/dist/xstate-actors.esm.js +405 -4
  14. package/actors/dist/xstate-actors.umd.min.js +1 -1
  15. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  16. package/dist/declarations/src/StateNode.d.ts +3 -3
  17. package/dist/declarations/src/actions/assign.d.ts +8 -3
  18. package/dist/declarations/src/actions/choose.d.ts +4 -3
  19. package/dist/declarations/src/actions/pure.d.ts +5 -4
  20. package/dist/declarations/src/actions.d.ts +8 -44
  21. package/dist/declarations/src/actors/index.d.ts +2 -2
  22. package/dist/declarations/src/constants.d.ts +1 -0
  23. package/dist/declarations/src/index.d.ts +9 -16
  24. package/dist/declarations/src/spawn.d.ts +25 -0
  25. package/dist/declarations/src/stateUtils.d.ts +1 -1
  26. package/dist/declarations/src/typegenTypes.d.ts +4 -4
  27. package/dist/declarations/src/types.d.ts +72 -94
  28. package/dist/declarations/src/utils.d.ts +2 -2
  29. package/dist/interpreter-672794ae.cjs.js +792 -0
  30. package/dist/interpreter-a1432c7d.development.cjs.js +800 -0
  31. package/dist/interpreter-a77bb0ec.development.esm.js +765 -0
  32. package/dist/interpreter-b5203bcb.esm.js +757 -0
  33. package/dist/{actions-9754d2ca.development.esm.js → raise-436a57a2.cjs.js} +130 -1307
  34. package/dist/{actions-ca622922.development.cjs.js → raise-74b72ca5.development.cjs.js} +101 -1306
  35. package/dist/{actions-020463e9.esm.js → raise-a60c9290.development.esm.js} +109 -1203
  36. package/dist/{actions-d1dba4ac.cjs.js → raise-b9c9a234.esm.js} +65 -1267
  37. package/dist/send-35e1a689.cjs.js +349 -0
  38. package/dist/send-4192e7bc.esm.js +339 -0
  39. package/dist/send-e63b7b83.development.esm.js +364 -0
  40. package/dist/send-e8b55d00.development.cjs.js +374 -0
  41. package/dist/xstate.cjs.js +110 -106
  42. package/dist/xstate.cjs.mjs +4 -2
  43. package/dist/xstate.development.cjs.js +110 -106
  44. package/dist/xstate.development.cjs.mjs +4 -2
  45. package/dist/xstate.development.esm.js +72 -68
  46. package/dist/xstate.esm.js +72 -68
  47. package/dist/xstate.umd.min.js +1 -1
  48. package/dist/xstate.umd.min.js.map +1 -1
  49. package/guards/dist/xstate-guards.cjs.js +2 -1
  50. package/guards/dist/xstate-guards.development.cjs.js +2 -1
  51. package/guards/dist/xstate-guards.development.esm.js +2 -1
  52. package/guards/dist/xstate-guards.esm.js +2 -1
  53. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  54. package/package.json +1 -1
  55. package/dist/declarations/src/constantPrefixes.d.ts +0 -6
  56. package/dist/promise-2ad94e3b.development.esm.js +0 -406
  57. package/dist/promise-3b7e3357.development.cjs.js +0 -412
  58. package/dist/promise-5b07c38e.esm.js +0 -406
  59. package/dist/promise-7a8c1768.cjs.js +0 -412
package/README.md CHANGED
@@ -21,7 +21,6 @@ JavaScript and TypeScript [finite state machines](https://en.wikipedia.org/wiki/
21
21
  ## Packages
22
22
 
23
23
  - 🤖 `xstate` - Core finite state machine and statecharts library + interpreter
24
- - [🔬 `@xstate/fsm`](https://github.com/statelyai/xstate/tree/main/packages/xstate-fsm) - Minimal finite state machine library
25
24
  - [📉 `@xstate/graph`](https://github.com/statelyai/xstate/tree/main/packages/xstate-graph) - Graph traversal utilities for XState
26
25
  - [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) - React hooks and utilities for using XState in React applications
27
26
  - [✅ `@xstate/test`](https://github.com/statelyai/xstate/tree/main/packages/xstate-test) - Model-based testing utilities for XState
@@ -117,8 +116,9 @@ const lightMachine = createMachine({
117
116
 
118
117
  const currentState = 'green';
119
118
 
120
- const nextState = lightMachine.transition(currentState, { type: 'TIMER' })
121
- .value;
119
+ const nextState = lightMachine.transition(currentState, {
120
+ type: 'TIMER'
121
+ }).value;
122
122
 
123
123
  // => 'yellow'
124
124
  ```
@@ -172,8 +172,9 @@ const lightMachine = createMachine({
172
172
 
173
173
  const currentState = 'yellow';
174
174
 
175
- const nextState = lightMachine.transition(currentState, { type: 'TIMER' })
176
- .value;
175
+ const nextState = lightMachine.transition(currentState, {
176
+ type: 'TIMER'
177
+ }).value;
177
178
  // => {
178
179
  // red: 'walk'
179
180
  // }
@@ -263,8 +264,9 @@ const wordMachine = createMachine({
263
264
  }
264
265
  });
265
266
 
266
- const boldState = wordMachine.transition('bold.off', { type: 'TOGGLE_BOLD' })
267
- .value;
267
+ const boldState = wordMachine.transition('bold.off', {
268
+ type: 'TOGGLE_BOLD'
269
+ }).value;
268
270
 
269
271
  // {
270
272
  // bold: 'on',
@@ -2,27 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var guards_dist_xstateGuards = require('../../dist/actions-d1dba4ac.cjs.js');
5
+ var send = require('../../dist/send-35e1a689.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-436a57a2.cjs.js');
7
+ require('../../dist/interpreter-672794ae.cjs.js');
6
8
  require('../../dev/dist/xstate-dev.cjs.js');
7
9
 
8
10
 
9
11
 
10
- exports.after = guards_dist_xstateGuards.after;
11
- exports.assign = guards_dist_xstateGuards.assign;
12
+ exports.assign = send.assign;
13
+ exports.choose = send.choose;
14
+ exports.escalate = send.escalate;
15
+ exports.forwardTo = send.forwardTo;
16
+ exports.log = send.log;
17
+ exports.pure = send.pure;
18
+ exports.sendParent = send.sendParent;
19
+ exports.sendTo = send.sendTo;
12
20
  exports.cancel = guards_dist_xstateGuards.cancel;
13
- exports.choose = guards_dist_xstateGuards.choose;
14
- exports.constantPrefixes = guards_dist_xstateGuards.constantPrefixes;
15
- exports.createInitEvent = guards_dist_xstateGuards.createInitEvent;
16
- exports.done = guards_dist_xstateGuards.done;
17
- exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
18
- exports.doneInvokeEventType = guards_dist_xstateGuards.doneInvokeEventType;
19
- exports.error = guards_dist_xstateGuards.error;
20
- exports.errorEventType = guards_dist_xstateGuards.errorEventType;
21
- exports.escalate = guards_dist_xstateGuards.escalate;
22
- exports.forwardTo = guards_dist_xstateGuards.forwardTo;
23
- exports.log = guards_dist_xstateGuards.log;
24
- exports.pure = guards_dist_xstateGuards.pure;
25
21
  exports.raise = guards_dist_xstateGuards.raise;
26
- exports.sendParent = guards_dist_xstateGuards.sendParent;
27
- exports.sendTo = guards_dist_xstateGuards.sendTo;
28
22
  exports.stop = guards_dist_xstateGuards.stop;
@@ -1,15 +1,7 @@
1
1
  export {
2
- after,
3
2
  assign,
4
3
  cancel,
5
4
  choose,
6
- constantPrefixes,
7
- createInitEvent,
8
- done,
9
- doneInvoke,
10
- doneInvokeEventType,
11
- error,
12
- errorEventType,
13
5
  escalate,
14
6
  forwardTo,
15
7
  log,
@@ -2,27 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var guards_dist_xstateGuards = require('../../dist/actions-ca622922.development.cjs.js');
5
+ var send = require('../../dist/send-e8b55d00.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-74b72ca5.development.cjs.js');
7
+ require('../../dist/interpreter-a1432c7d.development.cjs.js');
6
8
  require('../../dev/dist/xstate-dev.development.cjs.js');
7
9
 
8
10
 
9
11
 
10
- exports.after = guards_dist_xstateGuards.after;
11
- exports.assign = guards_dist_xstateGuards.assign;
12
+ exports.assign = send.assign;
13
+ exports.choose = send.choose;
14
+ exports.escalate = send.escalate;
15
+ exports.forwardTo = send.forwardTo;
16
+ exports.log = send.log;
17
+ exports.pure = send.pure;
18
+ exports.sendParent = send.sendParent;
19
+ exports.sendTo = send.sendTo;
12
20
  exports.cancel = guards_dist_xstateGuards.cancel;
13
- exports.choose = guards_dist_xstateGuards.choose;
14
- exports.constantPrefixes = guards_dist_xstateGuards.constantPrefixes;
15
- exports.createInitEvent = guards_dist_xstateGuards.createInitEvent;
16
- exports.done = guards_dist_xstateGuards.done;
17
- exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
18
- exports.doneInvokeEventType = guards_dist_xstateGuards.doneInvokeEventType;
19
- exports.error = guards_dist_xstateGuards.error;
20
- exports.errorEventType = guards_dist_xstateGuards.errorEventType;
21
- exports.escalate = guards_dist_xstateGuards.escalate;
22
- exports.forwardTo = guards_dist_xstateGuards.forwardTo;
23
- exports.log = guards_dist_xstateGuards.log;
24
- exports.pure = guards_dist_xstateGuards.pure;
25
21
  exports.raise = guards_dist_xstateGuards.raise;
26
- exports.sendParent = guards_dist_xstateGuards.sendParent;
27
- exports.sendTo = guards_dist_xstateGuards.sendTo;
28
22
  exports.stop = guards_dist_xstateGuards.stop;
@@ -1,15 +1,7 @@
1
1
  export {
2
- after,
3
2
  assign,
4
3
  cancel,
5
4
  choose,
6
- constantPrefixes,
7
- createInitEvent,
8
- done,
9
- doneInvoke,
10
- doneInvokeEventType,
11
- error,
12
- errorEventType,
13
5
  escalate,
14
6
  forwardTo,
15
7
  log,
@@ -1,2 +1,4 @@
1
- export { a8 as after, w as assign, L as cancel, M as choose, a7 as constantPrefixes, x as createInitEvent, a9 as done, I as doneInvoke, aa as doneInvokeEventType, a4 as error, ab as errorEventType, ac as escalate, R as forwardTo, O as log, P as pure, Q as raise, T as sendParent, U as sendTo, V as stop } from '../../dist/actions-9754d2ca.development.esm.js';
1
+ export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-e63b7b83.development.esm.js';
2
+ export { z as cancel, A as raise, B as stop } from '../../dist/raise-a60c9290.development.esm.js';
3
+ import '../../dist/interpreter-a77bb0ec.development.esm.js';
2
4
  import '../../dev/dist/xstate-dev.development.esm.js';
@@ -1,2 +1,4 @@
1
- export { a8 as after, w as assign, L as cancel, M as choose, a7 as constantPrefixes, x as createInitEvent, a9 as done, I as doneInvoke, aa as doneInvokeEventType, a4 as error, ab as errorEventType, ac as escalate, R as forwardTo, O as log, P as pure, Q as raise, T as sendParent, U as sendTo, V as stop } from '../../dist/actions-020463e9.esm.js';
1
+ export { a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from '../../dist/send-4192e7bc.esm.js';
2
+ export { z as cancel, A as raise, B as stop } from '../../dist/raise-b9c9a234.esm.js';
3
+ import '../../dist/interpreter-b5203bcb.esm.js';
2
4
  import '../../dev/dist/xstate-dev.esm.js';
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActions={})}(this,(function(t){"use strict";let e=function(t){return t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.After,i=e.DoneState,o=e.ErrorExecution,r=e.ErrorPlatform,c=e.ErrorCustom;var a=Object.freeze({__proto__:null,after:s,doneState:i,errorExecution:o,errorPlatform:r,error:c});const u=".",h="xstate.stop";function f(t,e,s,{to:i,event:o,id:r,delay:c}){const a=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const u="function"==typeof o?o(s):o;let h;if("string"==typeof c){const t=a&&a[c];h="function"==typeof t?t(s):t}else h="function"==typeof c?c(s):c;const f="function"==typeof i?i(s):i;let d;if("string"==typeof f){if(d=f===n.Parent?t?.self._parent:f===n.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:e.children[f],!d)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else d=f||t?.self;return[e,{to:d,event:u,id:r,delay:h}]}function d(t,e){if("number"==typeof e.delay)return void t.self.delaySend(e);const{to:n,event:s}=e;t.defer((()=>{n.send(s.type===c?{type:`${rt(t.self.id)}`,data:s.data}:s)}))}function l(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=f,s.execute=d,s}function p(t,e){return l(n.Parent,t,e)}const y=new WeakMap;function v(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function g(t,e){t.self.cancel(e)}class m{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)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}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),t===this._current&&(this._current=this._current.next)}this._last=null}}function _(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const x=t=>{const e=_();e&&e.register(t)};function b(t){setTimeout((()=>{throw t}))}const w="function"==typeof Symbol&&Symbol.observable||"@@observable";function S(t,e){const n=E(t),s=E(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&S(n[t],s[t])))}function E(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(T(t))return $(t);if("string"!=typeof t)return t;return $(function(t){try{return T(t)?t:t.toString().split(u)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function $(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function I(t){return[].concat(...t)}function k(t){return void 0===t?[]:function(t){return T(t)?t:[t]}(t)}function T(t){return Array.isArray(t)}let P=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const j={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class O{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new m(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=P.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=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={...j,...e},{clock:s,logger:i,parent:o,id:r,systemId:c}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),c&&(this._systemId=c,this.system._set(c,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)try{t.next?.(e)}catch(t){b(t)}const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=it(this.id,s.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(rt(this.id,s.data))}}subscribe(t,e,n){const s=function(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}(t,e,n);if(this.status!==P.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){b(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===P.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=P.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(rt(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(rt(this.id,t))}this.update(e),t.type===h&&(this._stopProcedure(),this._complete())}_stop(){return this.status===P.Stopped?this:(this.mailbox.clear(),this.status===P.NotStarted?(this.status=P.Stopped,this):(this.mailbox.enqueue({type:h}),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){b(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||b(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){b(t)}}this.observers.clear(),e&&b(t)}_stopProcedure(){if(this.status!==P.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new m(this._process.bind(this)),this.status=P.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==P.Stopped){if(this.status!==P.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend({event:t,id:e,delay:n,to:s}){const i=this.clock.setTimeout((()=>{s?s.send(t):this.send(t)}),n);e&&(this.delayedEventsMap[e]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:x)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[w](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function C(t,e){return new O(t,e)}function M(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return M(r,e,n,s);const c={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:e,event:n})}:t};if(!("check"in r))return r(c);return r.check(s,c,r)}const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function R(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function N(t){const e=new Set(t),n=new Set(t),s=q(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))if("history"!==e.type&&!n.has(e))for(const t of V(e))n.add(t)}else V(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function Q(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};for(const t of n)s[t.key]=Q(t,e);return s}function q(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function z(t,e){return Q(t,q(N(e)))}const J=t=>"#"===t[0];function V(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of R(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of D(s))n(t)}(t),[...e]}function W(t,e){if(J(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function B(t,e){const n=e instanceof U?e.value:E(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>W(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=W(t,s);if(!i)return e;const o=B(i,n[s]);return e.concat(o)}),[]))}class U{static from(t,e={},n){if(t instanceof U)return t.context!==e?new U({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=N(B(n.root,t));return new U({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(N(B(e.root,t.value))),this.children=t.children,this.value=z(e.root,this.configuration),this.tags=new Set(I(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const e=Object.keys(t);return e.concat(...e.map((e=>this.toStrings(t[e]).map((t=>e+u+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return S(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return function(t,e,n){let s=y.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},y.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(I([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function G(t,e={}){return new U({...t,...e},t.machine)}function X(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[G(e,{children:r}),o]}function F(t,e){e&&(e.status===P.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function H(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function K({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function L(t,{machine:e,context:n},s,i){return(o,r)=>{const c=((o,r={})=>{const{systemId:c}=r;if("string"==typeof o){const a=function(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}(e.implementations.actors[o]);if(!a)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:a.input,h=C(a.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,systemId:c});return i[h.id]=h,h}return C(o,{id:r.id,parent:t.self,input:r.input,systemId:c})})(o,r);return i[c.id]=c,t.defer((()=>{if(c.status!==P.Stopped)try{c.start?.()}catch(e){return void t.self.send(rt(c.id,e))}})),c}}function Y(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:L(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[G(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Z(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const c="function"==typeof s?s(n):s;let a;if("string"==typeof o){const t=r&&r[o];a="function"==typeof t?t(n):t}else a="function"==typeof o?o(n):o;return["number"!=typeof a?G(e,{_internalQueue:e._internalQueue.concat(c)}):e,{event:c,id:i,delay:a}]}function tt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function et(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||M(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,k(i)]}function nt(t,e,n,{get:s}){return[e,void 0,k(s({context:n.context,event:n.event}))]}function st(t){return`${e.DoneInvoke}.${t}`}function it(t,e){const n=st(t),s={type:n,output:e,toString:()=>n};return s}function ot(t){return`${e.ErrorPlatform}.${t}`}function rt(t,e){const n=ot(t),s={type:n,data:e,toString:()=>n};return s}t.after=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`},t.assign=function(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Y,e},t.cancel=function(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=v,e.execute=g,e},t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=et,e},t.constantPrefixes=a,t.createInitEvent=function(t){return{type:"xstate.init",input:t}},t.done=function(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i},t.doneInvoke=it,t.doneInvokeEventType=st,t.error=rt,t.errorEventType=ot,t.escalate=function(t,e){return p((e=>({type:c,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return l(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=H,n.execute=K,n},t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=nt,e},t.raise=function(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Z,n.execute=tt,n},t.sendParent=p,t.sendTo=l,t.stop=function(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=X,e.execute=F,e},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActions={})}(this,(function(t){"use strict";const e=".",n="xstate.error",s="xstate.stop",i=new WeakMap;function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function c(t,e){t.self.cancel(e)}class a{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)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}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),t===this._current&&(this._current=this._current.next)}this._last=null}}function u(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const h=t=>{const e=u();e&&e.register(t)};function d(t){setTimeout((()=>{throw t}))}const f="function"==typeof Symbol&&Symbol.observable||"@@observable";function l(t,e){const n=p(t),s=p(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&l(n[t],s[t])))}function p(t){if("object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n)return t.value;var n;if(m(t))return y(t);if("string"!=typeof t)return t;return y(function(t){try{return m(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t))}function y(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function v(t){return[].concat(...t)}function g(t){return void 0===t?[]:function(t){return m(t)?t:[t]}(t)}function m(t){return Array.isArray(t)}let _=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const b={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class x{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new a(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=_.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=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={...b,...e},{clock:s,logger:i,parent:o,id:r,systemId:c}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),c&&(this._systemId=c,this.system._set(c,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)try{t.next?.(e)}catch(t){d(t)}const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,r=s.data,{type:`xstate.done.actor.${i}`,output:r}),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(o(this.id,s.data))}var i,r}subscribe(t,e,n){const s=function(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}(t,e,n);if(this.status!==_.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){d(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===_.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=_.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(o(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(o(this.id,t))}this.update(e),t.type===s&&(this._stopProcedure(),this._complete())}_stop(){return this.status===_.Stopped?this:(this.mailbox.clear(),this.status===_.NotStarted?(this.status=_.Stopped,this):(this.mailbox.enqueue({type:s}),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()}_error(t){if(!this.observers.size)return void(this._parent||d(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){d(t)}}this.observers.clear(),e&&d(t)}_stopProcedure(){if(this.status!==_.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new a(this._process.bind(this)),this.status=_.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==_.Stopped){if(this.status!==_.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend({event:t,id:e,delay:n,to:s}){const i=this.clock.setTimeout((()=>{s?s.send(t):this.send(t)}),n);e&&(this.delayedEventsMap[e]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:h)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[f](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function w(t,e){return new x(t,e)}function S(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[q(e,{children:r}),o]}function E(t,e){e&&(e.status===_.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function I(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return I(r,e,n,s);const c={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:e,event:n})}:t};if(!("check"in r))return r(c);return r.check(s,c,r)}const T=t=>"atomic"===t.type||"final"===t.type;function k(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function $(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function j(t){const e=new Set(t),n=new Set(t),s=M(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of k(t))if("history"!==e.type&&!n.has(e))for(const t of A(e))n.add(t)}else A(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function O(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(T(t))return t.key}const s={};for(const t of n)s[t.key]=O(t,e);return s}function M(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function P(t,e){return O(t,M(j(e)))}const C=t=>"#"===t[0];function A(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of $(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of k(s))n(t)}(t),[...e]}function R(t,e){if(C(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function N(t,e){const n=e instanceof Q?e.value:p(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>R(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=R(t,s);if(!i)return e;const o=N(i,n[s]);return e.concat(o)}),[]))}class Q{static from(t,e={},n){if(t instanceof Q)return t.context!==e?new Q({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=j(N(n.root,t));return new Q({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(j(N(e.root,t.value))),this.children=t.children,this.value=P(e.root,this.configuration),this.tags=new Set(v(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n]).map((t=>n+e+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return l(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return function(t,e,n){let s=i.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},i.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(v([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function q(t,e={}){return new Q({...t,...e},t.machine)}function D(t,{machine:e,context:n},s,i){return(r,c)=>{const a=((o,r={})=>{const{systemId:c}=r;if("string"==typeof o){const a=function(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}(e.implementations.actors[o]);if(!a)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:a.input,h=w(a.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,systemId:c});return i[h.id]=h,h}return w(o,{id:r.id,parent:t.self,input:r.input,systemId:c})})(r,c);return i[a.id]=a,t.defer((()=>{if(a.status!==_.Stopped)try{a.start?.()}catch(e){return void t.self.send(o(a.id,e))}})),a}}function J(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:D(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[q(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function V(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||I(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,g(i)]}function W(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function z({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function B(t,e,n,{get:s}){return[e,void 0,g(s({context:n.context,event:n.event}))]}function U(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const c="function"==typeof s?s(n):s;let a;if("string"==typeof o){const t=r&&r[o];a="function"==typeof t?t(n):t}else a="function"==typeof o?o(n):o;return["number"!=typeof a?q(e,{_internalQueue:e._internalQueue.concat(c)}):e,{event:c,id:i,delay:a}]}function G(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}let X=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function F(t,e,n,{to:s,event:i,id:o,delay:r}){const c=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 a="function"==typeof i?i(n):i;let u;if("string"==typeof r){const t=c&&c[r];u="function"==typeof t?t(n):t}else u="function"==typeof r?r(n):r;const h="function"==typeof s?s(n):s;let d;if("string"==typeof h){if(d=h===X.Parent?t?.self._parent:h===X.Internal?t?.self:h.startsWith("#_")?e.children[h.slice(2)]:e.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else d=h||t?.self;return[e,{to:d,event:a,id:o,delay:u}]}function H(t,e){if("number"==typeof e.delay)return void t.self.delaySend(e);const{to:s,event:i}=e;t.defer((()=>{s.send(i.type===n?o(t.self.id,i.data):i)}))}function K(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=F,s.execute=H,s}function L(t,e){return K(X.Parent,t,e)}t.assign=function(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=J,e},t.cancel=function(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=r,e.execute=c,e},t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=V,e},t.escalate=function(t,e){return L((e=>({type:n,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return K(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=W,n.execute=z,n},t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=B,e},t.raise=function(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=U,n.execute=G,n},t.sendParent=L,t.sendTo=K,t.stop=function(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=S,e.execute=E,e},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate-actions.umd.min.js.map