xstate 6.0.0-alpha.47 → 6.0.0-alpha.49

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 (84) hide show
  1. package/README.md +30 -1
  2. package/dist/{StateMachine-7046f677.cjs.js → StateMachine-0adb3a70.cjs.js} +15 -12
  3. package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +15 -12
  4. package/dist/{StateMachine-74929087.esm.js → StateMachine-2af31c11.esm.js} +10 -7
  5. package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js} +10 -7
  6. package/dist/{createActor-915ea40c.esm.js → createActor-268165d4.esm.js} +79 -23
  7. package/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.development.esm.js} +79 -23
  8. package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +78 -25
  9. package/dist/{createActor-bfe8b6bd.cjs.js → createActor-b4dd05ae.cjs.js} +78 -25
  10. package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
  11. package/dist/declarations/src/fsm/createFSMActor.d.ts +67 -0
  12. package/dist/declarations/src/fsm/index.d.ts +2 -0
  13. package/dist/declarations/src/fsm.d.ts +5 -4
  14. package/dist/declarations/src/scxml/index.d.ts +1 -0
  15. package/dist/declarations/src/scxml/runtime.d.ts +251 -0
  16. package/dist/declarations/src/scxml/scxml.d.ts +19 -0
  17. package/dist/declarations/src/types.d.ts +1 -0
  18. package/dist/{effectDescriptor-8be60443.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
  19. package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
  20. package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
  21. package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-be348e50.cjs.js} +1 -1
  22. package/dist/fsm-7a2e9697.cjs.js +777 -0
  23. package/dist/fsm-b804b3e9.esm.js +775 -0
  24. package/dist/fsm-c1316948.development.cjs.js +777 -0
  25. package/dist/fsm-e18a7cb4.development.esm.js +775 -0
  26. package/dist/types-3c3455f7.esm.js +185 -0
  27. package/dist/types-adda3842.development.esm.js +185 -0
  28. package/dist/types-b3fea5bd.development.cjs.js +189 -0
  29. package/dist/types-fbabaeee.cjs.js +189 -0
  30. package/dist/validation-05f1d517.esm.js +8 -0
  31. package/dist/validation-4561b43c.cjs.js +10 -0
  32. package/dist/validation-e69470ad.development.esm.js +8 -0
  33. package/dist/validation-f2714a35.development.cjs.js +10 -0
  34. package/dist/xstate-actors.cjs.js +934 -9
  35. package/dist/xstate-actors.development.cjs.js +934 -9
  36. package/dist/xstate-actors.development.esm.js +932 -2
  37. package/dist/xstate-actors.esm.js +932 -2
  38. package/dist/xstate-durable.cjs.js +2 -2
  39. package/dist/xstate-durable.development.cjs.js +2 -2
  40. package/dist/xstate-durable.development.esm.js +2 -2
  41. package/dist/xstate-durable.esm.js +2 -2
  42. package/dist/xstate-fsm.cjs.d.mts +2 -0
  43. package/dist/xstate-fsm.cjs.d.ts +2 -0
  44. package/dist/xstate-fsm.cjs.js +409 -0
  45. package/dist/xstate-fsm.cjs.mjs +5 -0
  46. package/dist/xstate-fsm.development.cjs.js +409 -0
  47. package/dist/xstate-fsm.development.cjs.mjs +5 -0
  48. package/dist/xstate-fsm.development.esm.js +403 -0
  49. package/dist/xstate-fsm.esm.js +403 -0
  50. package/dist/xstate-fsm.umd.min.js +2 -0
  51. package/dist/xstate-fsm.umd.min.js.map +1 -0
  52. package/dist/xstate-graph.cjs.js +4 -3
  53. package/dist/xstate-graph.development.cjs.js +4 -3
  54. package/dist/xstate-graph.development.esm.js +4 -3
  55. package/dist/xstate-graph.esm.js +4 -3
  56. package/dist/xstate-graph.umd.min.js +1 -1
  57. package/dist/xstate-graph.umd.min.js.map +1 -1
  58. package/dist/xstate-scxml.cjs.d.mts +2 -0
  59. package/dist/xstate-scxml.cjs.d.ts +2 -0
  60. package/dist/xstate-scxml.cjs.js +2387 -0
  61. package/dist/xstate-scxml.cjs.mjs +3 -0
  62. package/dist/xstate-scxml.development.cjs.js +2387 -0
  63. package/dist/xstate-scxml.development.cjs.mjs +3 -0
  64. package/dist/xstate-scxml.development.esm.js +2383 -0
  65. package/dist/xstate-scxml.esm.js +2383 -0
  66. package/dist/xstate-scxml.umd.min.js +26 -0
  67. package/dist/xstate-scxml.umd.min.js.map +1 -0
  68. package/dist/xstate-validation.cjs.js +1 -1
  69. package/dist/xstate-validation.development.cjs.js +1 -1
  70. package/dist/xstate-validation.development.esm.js +1 -1
  71. package/dist/xstate-validation.esm.js +1 -1
  72. package/dist/xstate.cjs.js +143 -1412
  73. package/dist/xstate.development.cjs.js +143 -1412
  74. package/dist/xstate.development.esm.js +143 -1411
  75. package/dist/xstate.esm.js +143 -1411
  76. package/dist/xstate.umd.min.js +1 -1
  77. package/dist/xstate.umd.min.js.map +1 -1
  78. package/fsm/package.json +8 -0
  79. package/package.json +37 -3
  80. package/scxml/package.json +8 -0
  81. package/dist/index-0f498ef2.development.cjs.js +0 -946
  82. package/dist/index-70d56425.development.esm.js +0 -937
  83. package/dist/index-b051c924.esm.js +0 -937
  84. package/dist/index-b3fe59bc.cjs.js +0 -946
@@ -0,0 +1,26 @@
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).XStateSCXML={})}(this,function(t){"use strict";function e(t,e,s){return t(s={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&s.path)}},s.exports),s.exports}var s=e(function(t,e){
2
+ /**
3
+ * Character classes and associated utilities for the 5th edition of XML 1.0.
4
+ *
5
+ * @author Louis-Dominique Dubeau
6
+ * @license MIT
7
+ * @copyright Louis-Dominique Dubeau
8
+ */
9
+ Object.defineProperty(e,"__esModule",{value:!0}),e.CHAR="\t\n\r -퟿-�𐀀-􏿿",e.S=" \t\r\n",e.NAME_START_CHAR=":A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-῿‌‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿",e.NAME_CHAR="-"+e.NAME_START_CHAR+".0-9·̀-ͯ‿-⁀",e.CHAR_RE=new RegExp("^["+e.CHAR+"]$","u"),e.S_RE=new RegExp("^["+e.S+"]+$","u"),e.NAME_START_CHAR_RE=new RegExp("^["+e.NAME_START_CHAR+"]$","u"),e.NAME_CHAR_RE=new RegExp("^["+e.NAME_CHAR+"]$","u"),e.NAME_RE=new RegExp("^["+e.NAME_START_CHAR+"]["+e.NAME_CHAR+"]*$","u"),e.NMTOKEN_RE=new RegExp("^["+e.NAME_CHAR+"]+$","u");function s(t){return t>=65&&t<=90||t>=97&&t<=122||58===t||95===t||8204===t||8205===t||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}e.S_LIST=[32,10,13,9],e.isChar=function(t){return t>=32&&t<=55295||10===t||13===t||9===t||t>=57344&&t<=65533||t>=65536&&t<=1114111},e.isS=function(t){return 32===t||10===t||13===t||9===t},e.isNameStartChar=s,e.isNameChar=function(t){return s(t)||t>=48&&t<=57||45===t||46===t||183===t||t>=768&&t<=879||t>=8255&&t<=8256}}),n=e(function(t,e){
10
+ /**
11
+ * Character classes and associated utilities for the 2nd edition of XML 1.1.
12
+ *
13
+ * @author Louis-Dominique Dubeau
14
+ * @license MIT
15
+ * @copyright Louis-Dominique Dubeau
16
+ */
17
+ Object.defineProperty(e,"__esModule",{value:!0}),e.CHAR="-퟿-�𐀀-􏿿",e.RESTRICTED_CHAR="-\b\v\f--„†-Ÿ",e.S=" \t\r\n",e.NAME_START_CHAR=":A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-῿‌‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿",e.NAME_CHAR="-"+e.NAME_START_CHAR+".0-9·̀-ͯ‿-⁀",e.CHAR_RE=new RegExp("^["+e.CHAR+"]$","u"),e.RESTRICTED_CHAR_RE=new RegExp("^["+e.RESTRICTED_CHAR+"]$","u"),e.S_RE=new RegExp("^["+e.S+"]+$","u"),e.NAME_START_CHAR_RE=new RegExp("^["+e.NAME_START_CHAR+"]$","u"),e.NAME_CHAR_RE=new RegExp("^["+e.NAME_CHAR+"]$","u"),e.NAME_RE=new RegExp("^["+e.NAME_START_CHAR+"]["+e.NAME_CHAR+"]*$","u"),e.NMTOKEN_RE=new RegExp("^["+e.NAME_CHAR+"]+$","u");function s(t){return t>=65&&t<=90||t>=97&&t<=122||58===t||95===t||8204===t||8205===t||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}e.S_LIST=[32,10,13,9],e.isChar=function(t){return t>=1&&t<=55295||t>=57344&&t<=65533||t>=65536&&t<=1114111},e.isRestrictedChar=function(t){return t>=1&&t<=8||11===t||12===t||t>=14&&t<=31||t>=127&&t<=132||t>=134&&t<=159},e.isCharAndNotRestricted=function(t){return 9===t||10===t||13===t||t>31&&t<127||133===t||t>159&&t<=55295||t>=57344&&t<=65533||t>=65536&&t<=1114111},e.isS=function(t){return 32===t||10===t||13===t||9===t},e.isNameStartChar=s,e.isNameChar=function(t){return s(t)||t>=48&&t<=57||45===t||46===t||183===t||t>=768&&t<=879||t>=8255&&t<=8256}}),i=e(function(t,e){function s(t){return t>=65&&t<=90||95===t||t>=97&&t<=122||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8204&&t<=8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}
18
+ /**
19
+ * Character class utilities for XML NS 1.0 edition 3.
20
+ *
21
+ * @author Louis-Dominique Dubeau
22
+ * @license MIT
23
+ * @copyright Louis-Dominique Dubeau
24
+ */
25
+ Object.defineProperty(e,"__esModule",{value:!0}),e.NC_NAME_START_CHAR="A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿",e.NC_NAME_CHAR="-"+e.NC_NAME_START_CHAR+".0-9·̀-ͯ‿-⁀",e.NC_NAME_START_CHAR_RE=new RegExp("^["+e.NC_NAME_START_CHAR+"]$","u"),e.NC_NAME_CHAR_RE=new RegExp("^["+e.NC_NAME_CHAR+"]$","u"),e.NC_NAME_RE=new RegExp("^["+e.NC_NAME_START_CHAR+"]["+e.NC_NAME_CHAR+"]*$","u"),e.isNCNameStartChar=s,e.isNCNameChar=function(t){return s(t)||45===t||46===t||t>=48&&t<=57||183===t||t>=768&&t<=879||t>=8255&&t<=8256}}),r=e(function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.SaxesParser=e.EVENTS=void 0;var r=s.isS,o=s.isChar,a=s.isNameStartChar,c=s.isNameChar,h=s.S_LIST,l=s.NAME_RE,u=n.isChar,d=i.isNCNameStartChar,f=i.isNCNameChar,p=i.NC_NAME_RE;const m="http://www.w3.org/XML/1998/namespace",g="http://www.w3.org/2000/xmlns/",y={__proto__:null,xml:m,xmlns:g},v={__proto__:null,amp:"&",gt:">",lt:"<",quot:'"',apos:"'"},x=-1,_=-2,b=13,w=33,S=10,A=60,E=61,$=62,k=63,I=93,T=t=>34===t||39===t,C=[34,39],R=[...C,91,$],M=[...C,A,I],N=[E,k,...h],j=[...h,$,38,A];function O(t,e,s){switch(e){case"xml":s!==m&&t.fail(`xml prefix must be bound to ${m}.`);break;case"xmlns":s!==g&&t.fail(`xmlns prefix must be bound to ${g}.`)}switch(s){case g:t.fail(""===e?`the default namespace may not be set to ${s}.`:`may not assign a prefix (even "xmlns") to the URI ${g}.`);break;case m:switch(e){case"xml":break;case"":t.fail(`the default namespace may not be set to ${s}.`);break;default:t.fail("may not assign the xml namespace to another prefix.")}}}const D=t=>p.test(t),P=t=>l.test(t);e.EVENTS=["xmldecl","text","processinginstruction","doctype","comment","opentagstart","attribute","opentag","closetag","cdata","error","end","ready"];const H={xmldecl:"xmldeclHandler",text:"textHandler",processinginstruction:"piHandler",doctype:"doctypeHandler",comment:"commentHandler",opentagstart:"openTagStartHandler",attribute:"attributeHandler",opentag:"openTagHandler",closetag:"closeTagHandler",cdata:"cdataHandler",error:"errorHandler",end:"endHandler",ready:"readyHandler"};e.SaxesParser=class{constructor(t){this.opt=null!=t?t:{},this.fragmentOpt=!!this.opt.fragment;const e=this.xmlnsOpt=!!this.opt.xmlns;if(this.trackPosition=!1!==this.opt.position,this.fileName=this.opt.fileName,e){this.nameStartCheck=d,this.nameCheck=f,this.isName=D,this.processAttribs=this.processAttribsNS,this.pushAttrib=this.pushAttribNS,this.ns=Object.assign({__proto__:null},y);const t=this.opt.additionalNamespaces;null!=t&&(!function(t,e){for(const s of Object.keys(e))O(t,s,e[s])}(this,t),Object.assign(this.ns,t))}else this.nameStartCheck=a,this.nameCheck=c,this.isName=P,this.processAttribs=this.processAttribsPlain,this.pushAttrib=this.pushAttribPlain;this.stateTable=[this.sBegin,this.sBeginWhitespace,this.sDoctype,this.sDoctypeQuote,this.sDTD,this.sDTDQuoted,this.sDTDOpenWaka,this.sDTDOpenWakaBang,this.sDTDComment,this.sDTDCommentEnding,this.sDTDCommentEnded,this.sDTDPI,this.sDTDPIEnding,this.sText,this.sEntity,this.sOpenWaka,this.sOpenWakaBang,this.sComment,this.sCommentEnding,this.sCommentEnded,this.sCData,this.sCDataEnding,this.sCDataEnding2,this.sPIFirstChar,this.sPIRest,this.sPIBody,this.sPIEnding,this.sXMLDeclNameStart,this.sXMLDeclName,this.sXMLDeclEq,this.sXMLDeclValueStart,this.sXMLDeclValue,this.sXMLDeclSeparator,this.sXMLDeclEnding,this.sOpenTag,this.sOpenTagSlash,this.sAttrib,this.sAttribName,this.sAttribNameSawWhite,this.sAttribValue,this.sAttribValueQuoted,this.sAttribValueClosed,this.sAttribValueUnquoted,this.sCloseTag,this.sCloseTagSawWhite],this._init()}get closed(){return this._closed}_init(){var t;this.openWakaBang="",this.text="",this.name="",this.piTarget="",this.entity="",this.q=null,this.tags=[],this.tag=null,this.topNS=null,this.chunk="",this.chunkPosition=0,this.i=0,this.prevI=0,this.carriedFromPrevious=void 0,this.forbiddenState=0,this.attribList=[];const{fragmentOpt:e}=this;this.state=e?b:0,this.reportedTextBeforeRoot=this.reportedTextAfterRoot=this.closedRoot=this.sawRoot=e,this.xmlDeclPossible=!e,this.xmlDeclExpects=["version"],this.entityReturnState=void 0;let{defaultXMLVersion:s}=this.opt;if(void 0===s){if(!0===this.opt.forceXMLVersion)throw new Error("forceXMLVersion set but defaultXMLVersion is not set");s="1.0"}this.setXMLVersion(s),this.positionAtNewLine=0,this.doctype=!1,this._closed=!1,this.xmlDecl={version:void 0,encoding:void 0,standalone:void 0},this.line=1,this.column=0,this.ENTITIES=Object.create(v),null===(t=this.readyHandler)||void 0===t||t.call(this)}get position(){return this.chunkPosition+this.i}get columnIndex(){return this.position-this.positionAtNewLine}on(t,e){this[H[t]]=e}off(t){this[H[t]]=void 0}makeError(t){var e;let s=null!==(e=this.fileName)&&void 0!==e?e:"";return this.trackPosition&&(s.length>0&&(s+=":"),s+=`${this.line}:${this.column}`),s.length>0&&(s+=": "),new Error(s+t)}fail(t){const e=this.makeError(t),s=this.errorHandler;if(void 0===s)throw e;return s(e),this}write(t){if(this.closed)return this.fail("cannot write after close; assign an onready handler.");let e=!1;null===t?(e=!0,t=""):"object"==typeof t&&(t=t.toString()),void 0!==this.carriedFromPrevious&&(t=`${this.carriedFromPrevious}${t}`,this.carriedFromPrevious=void 0);let s=t.length;const n=t.charCodeAt(s-1);!e&&(13===n||n>=55296&&n<=56319)&&(this.carriedFromPrevious=t[s-1],s--,t=t.slice(0,s));const{stateTable:i}=this;for(this.chunk=t,this.i=0;this.i<s;)i[this.state].call(this);return this.chunkPosition+=s,e?this.end():this}close(){return this.write(null)}getCode10(){const{chunk:t,i:e}=this;if(this.prevI=e,this.i=e+1,e>=t.length)return x;const s=t.charCodeAt(e);if(this.column++,s<55296){if(s>=32||9===s)return s;switch(s){case S:return this.line++,this.column=0,this.positionAtNewLine=this.position,S;case 13:return t.charCodeAt(e+1)===S&&(this.i=e+2),this.line++,this.column=0,this.positionAtNewLine=this.position,_;default:return this.fail("disallowed character."),s}}if(s>56319)return s>=57344&&s<=65533||this.fail("disallowed character."),s;const n=65536+1024*(s-55296)+(t.charCodeAt(e+1)-56320);return this.i=e+2,n>1114111&&this.fail("disallowed character."),n}getCode11(){const{chunk:t,i:e}=this;if(this.prevI=e,this.i=e+1,e>=t.length)return x;const s=t.charCodeAt(e);if(this.column++,s<55296){if(s>31&&s<127||s>159&&8232!==s||9===s)return s;switch(s){case S:return this.line++,this.column=0,this.positionAtNewLine=this.position,S;case 13:{const s=t.charCodeAt(e+1);s!==S&&133!==s||(this.i=e+2)}case 133:case 8232:return this.line++,this.column=0,this.positionAtNewLine=this.position,_;default:return this.fail("disallowed character."),s}}if(s>56319)return s>=57344&&s<=65533||this.fail("disallowed character."),s;const n=65536+1024*(s-55296)+(t.charCodeAt(e+1)-56320);return this.i=e+2,n>1114111&&this.fail("disallowed character."),n}getCodeNorm(){const t=this.getCode();return t===_?S:t}unget(){this.i=this.prevI,this.column--}captureTo(t){let{i:e}=this;const{chunk:s}=this;for(;;){const n=this.getCode(),i=n===_,r=i?S:n;if(r===x||t.includes(r))return this.text+=s.slice(e,this.prevI),r;i&&(this.text+=`${s.slice(e,this.prevI)}\n`,e=this.i)}}captureToChar(t){let{i:e}=this;const{chunk:s}=this;for(;;){let n=this.getCode();switch(n){case _:this.text+=`${s.slice(e,this.prevI)}\n`,e=this.i,n=S;break;case x:return this.text+=s.slice(e),!1}if(n===t)return this.text+=s.slice(e,this.prevI),!0}}captureNameChars(){const{chunk:t,i:e}=this;for(;;){const s=this.getCode();if(s===x)return this.name+=t.slice(e),x;if(!c(s))return this.name+=t.slice(e,this.prevI),s===_?S:s}}skipSpaces(){for(;;){const t=this.getCodeNorm();if(t===x||!r(t))return t}}setXMLVersion(t){this.currentXMLVersion=t,"1.0"===t?(this.isChar=o,this.getCode=this.getCode10):(this.isChar=u,this.getCode=this.getCode11)}sBegin(){65279===this.chunk.charCodeAt(0)&&(this.i++,this.column++),this.state=1}sBeginWhitespace(){const t=this.i,e=this.skipSpaces();switch(this.prevI!==t&&(this.xmlDeclPossible=!1),e){case A:if(this.state=15,0!==this.text.length)throw new Error("no-empty text at start");break;case x:break;default:this.unget(),this.state=b,this.xmlDeclPossible=!1}}sDoctype(){var t;const e=this.captureTo(R);switch(e){case $:null===(t=this.doctypeHandler)||void 0===t||t.call(this,this.text),this.text="",this.state=b,this.doctype=!0;break;case x:break;default:this.text+=String.fromCodePoint(e),91===e?this.state=4:T(e)&&(this.state=3,this.q=e)}}sDoctypeQuote(){const t=this.q;this.captureToChar(t)&&(this.text+=String.fromCodePoint(t),this.q=null,this.state=2)}sDTD(){const t=this.captureTo(M);t!==x&&(this.text+=String.fromCodePoint(t),t===I?this.state=2:t===A?this.state=6:T(t)&&(this.state=5,this.q=t))}sDTDQuoted(){const t=this.q;this.captureToChar(t)&&(this.text+=String.fromCodePoint(t),this.state=4,this.q=null)}sDTDOpenWaka(){const t=this.getCodeNorm();switch(this.text+=String.fromCodePoint(t),t){case 33:this.state=7,this.openWakaBang="";break;case k:this.state=11;break;default:this.state=4}}sDTDOpenWakaBang(){const t=String.fromCodePoint(this.getCodeNorm()),e=this.openWakaBang+=t;this.text+=t,"-"!==e&&(this.state="--"===e?8:4,this.openWakaBang="")}sDTDComment(){this.captureToChar(45)&&(this.text+="-",this.state=9)}sDTDCommentEnding(){const t=this.getCodeNorm();this.text+=String.fromCodePoint(t),this.state=45===t?10:8}sDTDCommentEnded(){const t=this.getCodeNorm();this.text+=String.fromCodePoint(t),t===$?this.state=4:(this.fail("malformed comment."),this.state=8)}sDTDPI(){this.captureToChar(k)&&(this.text+="?",this.state=12)}sDTDPIEnding(){const t=this.getCodeNorm();this.text+=String.fromCodePoint(t),t===$&&(this.state=4)}sText(){0!==this.tags.length?this.handleTextInRoot():this.handleTextOutsideRoot()}sEntity(){let{i:t}=this;const{chunk:e}=this;t:for(;;)switch(this.getCode()){case _:this.entity+=`${e.slice(t,this.prevI)}\n`,t=this.i;break;case 59:{const{entityReturnState:s}=this,n=this.entity+e.slice(t,this.prevI);let i;this.state=s,""===n?(this.fail("empty entity name."),i="&;"):(i=this.parseEntity(n),this.entity=""),s===b&&void 0===this.textHandler||(this.text+=i);break t}case x:this.entity+=e.slice(t);break t}}sOpenWaka(){const t=this.getCode();if(a(t))this.state=34,this.unget(),this.xmlDeclPossible=!1;else switch(t){case 47:this.state=43,this.xmlDeclPossible=!1;break;case 33:this.state=16,this.openWakaBang="",this.xmlDeclPossible=!1;break;case k:this.state=23;break;default:this.fail("disallowed character in tag name"),this.state=b,this.xmlDeclPossible=!1}}sOpenWakaBang(){switch(this.openWakaBang+=String.fromCodePoint(this.getCodeNorm()),this.openWakaBang){case"[CDATA[":this.sawRoot||this.reportedTextBeforeRoot||(this.fail("text data outside of root node."),this.reportedTextBeforeRoot=!0),this.closedRoot&&!this.reportedTextAfterRoot&&(this.fail("text data outside of root node."),this.reportedTextAfterRoot=!0),this.state=20,this.openWakaBang="";break;case"--":this.state=17,this.openWakaBang="";break;case"DOCTYPE":this.state=2,(this.doctype||this.sawRoot)&&this.fail("inappropriately located doctype declaration."),this.openWakaBang="";break;default:this.openWakaBang.length>=7&&this.fail("incorrect syntax.")}}sComment(){this.captureToChar(45)&&(this.state=18)}sCommentEnding(){var t;const e=this.getCodeNorm();45===e?(this.state=19,null===(t=this.commentHandler)||void 0===t||t.call(this,this.text),this.text=""):(this.text+=`-${String.fromCodePoint(e)}`,this.state=17)}sCommentEnded(){const t=this.getCodeNorm();t!==$?(this.fail("malformed comment."),this.text+=`--${String.fromCodePoint(t)}`,this.state=17):this.state=b}sCData(){this.captureToChar(I)&&(this.state=21)}sCDataEnding(){const t=this.getCodeNorm();t===I?this.state=22:(this.text+=`]${String.fromCodePoint(t)}`,this.state=20)}sCDataEnding2(){var t;const e=this.getCodeNorm();switch(e){case $:null===(t=this.cdataHandler)||void 0===t||t.call(this,this.text),this.text="",this.state=b;break;case I:this.text+="]";break;default:this.text+=`]]${String.fromCodePoint(e)}`,this.state=20}}sPIFirstChar(){const t=this.getCodeNorm();this.nameStartCheck(t)?(this.piTarget+=String.fromCodePoint(t),this.state=24):t===k||r(t)?(this.fail("processing instruction without a target."),this.state=t===k?26:25):(this.fail("disallowed character in processing instruction name."),this.piTarget+=String.fromCodePoint(t),this.state=24)}sPIRest(){const{chunk:t,i:e}=this;for(;;){const s=this.getCodeNorm();if(s===x)return void(this.piTarget+=t.slice(e));if(!this.nameCheck(s)){this.piTarget+=t.slice(e,this.prevI);const n=s===k;n||r(s)?"xml"===this.piTarget?(this.xmlDeclPossible||this.fail("an XML declaration must be at the start of the document."),this.state=n?w:27):this.state=n?26:25:(this.fail("disallowed character in processing instruction name."),this.piTarget+=String.fromCodePoint(s));break}}}sPIBody(){if(0===this.text.length){const t=this.getCodeNorm();t===k?this.state=26:r(t)||(this.text=String.fromCodePoint(t))}else this.captureToChar(k)&&(this.state=26)}sPIEnding(){var t;const e=this.getCodeNorm();if(e===$){const{piTarget:e}=this;"xml"===e.toLowerCase()&&this.fail("the XML declaration must appear at the start of the document."),null===(t=this.piHandler)||void 0===t||t.call(this,{target:e,body:this.text}),this.piTarget=this.text="",this.state=b}else e===k?this.text+="?":(this.text+=`?${String.fromCodePoint(e)}`,this.state=25);this.xmlDeclPossible=!1}sXMLDeclNameStart(){const t=this.skipSpaces();t!==k?t!==x&&(this.state=28,this.name=String.fromCodePoint(t)):this.state=w}sXMLDeclName(){const t=this.captureTo(N);if(t===k)return this.state=w,this.name+=this.text,this.text="",void this.fail("XML declaration is incomplete.");if(r(t)||t===E){if(this.name+=this.text,this.text="",!this.xmlDeclExpects.includes(this.name))switch(this.name.length){case 0:this.fail("did not expect any more name/value pairs.");break;case 1:this.fail(`expected the name ${this.xmlDeclExpects[0]}.`);break;default:this.fail(`expected one of ${this.xmlDeclExpects.join(", ")}`)}this.state=t===E?30:29}}sXMLDeclEq(){const t=this.getCodeNorm();if(t===k)return this.state=w,void this.fail("XML declaration is incomplete.");r(t)||(t!==E&&this.fail("value required."),this.state=30)}sXMLDeclValueStart(){const t=this.getCodeNorm();if(t===k)return this.state=w,void this.fail("XML declaration is incomplete.");r(t)||(T(t)?this.q=t:(this.fail("value must be quoted."),this.q=32),this.state=31)}sXMLDeclValue(){const t=this.captureTo([this.q,k]);if(t===k)return this.state=w,this.text="",void this.fail("XML declaration is incomplete.");if(t===x)return;const e=this.text;switch(this.text="",this.name){case"version":{this.xmlDeclExpects=["encoding","standalone"];const t=e;this.xmlDecl.version=t,/^1\.[0-9]+$/.test(t)?this.opt.forceXMLVersion||this.setXMLVersion(t):this.fail("version number must match /^1\\.[0-9]+$/.");break}case"encoding":/^[A-Za-z][A-Za-z0-9._-]*$/.test(e)||this.fail("encoding value must match /^[A-Za-z0-9][A-Za-z0-9._-]*$/."),this.xmlDeclExpects=["standalone"],this.xmlDecl.encoding=e;break;case"standalone":"yes"!==e&&"no"!==e&&this.fail('standalone value must match "yes" or "no".'),this.xmlDeclExpects=[],this.xmlDecl.standalone=e}this.name="",this.state=32}sXMLDeclSeparator(){const t=this.getCodeNorm();t!==k?(r(t)||(this.fail("whitespace required."),this.unget()),this.state=27):this.state=w}sXMLDeclEnding(){var t;this.getCodeNorm()===$?("xml"!==this.piTarget?this.fail("processing instructions are not allowed before root."):"version"!==this.name&&this.xmlDeclExpects.includes("version")&&this.fail("XML declaration must contain a version."),null===(t=this.xmldeclHandler)||void 0===t||t.call(this,this.xmlDecl),this.name="",this.piTarget=this.text="",this.state=b):this.fail("The character ? is disallowed anywhere in XML declarations."),this.xmlDeclPossible=!1}sOpenTag(){var t;const e=this.captureNameChars();if(e===x)return;const s=this.tag={name:this.name,attributes:Object.create(null)};switch(this.name="",this.xmlnsOpt&&(this.topNS=s.ns=Object.create(null)),null===(t=this.openTagStartHandler)||void 0===t||t.call(this,s),this.sawRoot=!0,!this.fragmentOpt&&this.closedRoot&&this.fail("documents may contain only one root."),e){case $:this.openTag();break;case 47:this.state=35;break;default:r(e)||this.fail("disallowed character in tag name."),this.state=36}}sOpenTagSlash(){this.getCode()===$?this.openSelfClosingTag():(this.fail("forward-slash in opening tag not followed by >."),this.state=36)}sAttrib(){const t=this.skipSpaces();t!==x&&(a(t)?(this.unget(),this.state=37):t===$?this.openTag():47===t?this.state=35:this.fail("disallowed character in attribute name."))}sAttribName(){const t=this.captureNameChars();t===E?this.state=39:r(t)?this.state=38:t===$?(this.fail("attribute without value."),this.pushAttrib(this.name,this.name),this.name=this.text="",this.openTag()):t!==x&&this.fail("disallowed character in attribute name.")}sAttribNameSawWhite(){const t=this.skipSpaces();switch(t){case x:return;case E:this.state=39;break;default:this.fail("attribute without value."),this.text="",this.name="",t===$?this.openTag():a(t)?(this.unget(),this.state=37):(this.fail("disallowed character in attribute name."),this.state=36)}}sAttribValue(){const t=this.getCodeNorm();T(t)?(this.q=t,this.state=40):r(t)||(this.fail("unquoted attribute value."),this.state=42,this.unget())}sAttribValueQuoted(){const{q:t,chunk:e}=this;let{i:s}=this;for(;;)switch(this.getCode()){case t:return this.pushAttrib(this.name,this.text+e.slice(s,this.prevI)),this.name=this.text="",this.q=null,void(this.state=41);case 38:return this.text+=e.slice(s,this.prevI),this.state=14,void(this.entityReturnState=40);case S:case _:case 9:this.text+=`${e.slice(s,this.prevI)} `,s=this.i;break;case A:return this.text+=e.slice(s,this.prevI),void this.fail("disallowed character.");case x:return void(this.text+=e.slice(s))}}sAttribValueClosed(){const t=this.getCodeNorm();r(t)?this.state=36:t===$?this.openTag():47===t?this.state=35:a(t)?(this.fail("no whitespace between attributes."),this.unget(),this.state=37):this.fail("disallowed character in attribute name.")}sAttribValueUnquoted(){const t=this.captureTo(j);switch(t){case 38:this.state=14,this.entityReturnState=42;break;case A:this.fail("disallowed character.");break;case x:break;default:this.text.includes("]]>")&&this.fail('the string "]]>" is disallowed in char data.'),this.pushAttrib(this.name,this.text),this.name=this.text="",t===$?this.openTag():this.state=36}}sCloseTag(){const t=this.captureNameChars();t===$?this.closeTag():r(t)?this.state=44:t!==x&&this.fail("disallowed character in closing tag.")}sCloseTagSawWhite(){switch(this.skipSpaces()){case $:this.closeTag();break;case x:break;default:this.fail("disallowed character in closing tag.")}}handleTextInRoot(){let{i:t,forbiddenState:e}=this;const{chunk:s,textHandler:n}=this;t:for(;;)switch(this.getCode()){case A:if(this.state=15,void 0!==n){const{text:e}=this,i=s.slice(t,this.prevI);0!==e.length?(n(e+i),this.text=""):0!==i.length&&n(i)}e=0;break t;case 38:this.state=14,this.entityReturnState=b,void 0!==n&&(this.text+=s.slice(t,this.prevI)),e=0;break t;case I:switch(e){case 0:e=1;break;case 1:e=2;break;case 2:break;default:throw new Error("impossible state")}break;case $:2===e&&this.fail('the string "]]>" is disallowed in char data.'),e=0;break;case _:void 0!==n&&(this.text+=`${s.slice(t,this.prevI)}\n`),t=this.i,e=0;break;case x:void 0!==n&&(this.text+=s.slice(t));break t;default:e=0}this.forbiddenState=e}handleTextOutsideRoot(){let{i:t}=this;const{chunk:e,textHandler:s}=this;let n=!1;t:for(;;){const i=this.getCode();switch(i){case A:if(this.state=15,void 0!==s){const{text:n}=this,i=e.slice(t,this.prevI);0!==n.length?(s(n+i),this.text=""):0!==i.length&&s(i)}break t;case 38:this.state=14,this.entityReturnState=b,void 0!==s&&(this.text+=e.slice(t,this.prevI)),n=!0;break t;case _:void 0!==s&&(this.text+=`${e.slice(t,this.prevI)}\n`),t=this.i;break;case x:void 0!==s&&(this.text+=e.slice(t));break t;default:r(i)||(n=!0)}}n&&(this.sawRoot||this.reportedTextBeforeRoot||(this.fail("text data outside of root node."),this.reportedTextBeforeRoot=!0),this.closedRoot&&!this.reportedTextAfterRoot&&(this.fail("text data outside of root node."),this.reportedTextAfterRoot=!0))}pushAttribNS(t,e){var s;const{prefix:n,local:i}=this.qname(t),r={name:t,prefix:n,local:i,value:e};if(this.attribList.push(r),null===(s=this.attributeHandler)||void 0===s||s.call(this,r),"xmlns"===n){const t=e.trim();"1.0"===this.currentXMLVersion&&""===t&&this.fail("invalid attempt to undefine prefix in XML 1.0"),this.topNS[i]=t,O(this,i,t)}else if("xmlns"===t){const t=e.trim();this.topNS[""]=t,O(this,"",t)}}pushAttribPlain(t,e){var s;const n={name:t,value:e};this.attribList.push(n),null===(s=this.attributeHandler)||void 0===s||s.call(this,n)}end(){var t,e;this.sawRoot||this.fail("document must contain a root element.");const{tags:s}=this;for(;s.length>0;){const t=s.pop();this.fail(`unclosed tag: ${t.name}`)}0!==this.state&&this.state!==b&&this.fail("unexpected end.");const{text:n}=this;return 0!==n.length&&(null===(t=this.textHandler)||void 0===t||t.call(this,n),this.text=""),this._closed=!0,null===(e=this.endHandler)||void 0===e||e.call(this),this._init(),this}resolve(t){var e,s;let n=this.topNS[t];if(void 0!==n)return n;const{tags:i}=this;for(let e=i.length-1;e>=0;e--)if(n=i[e].ns[t],void 0!==n)return n;return n=this.ns[t],void 0!==n?n:null===(s=(e=this.opt).resolvePrefix)||void 0===s?void 0:s.call(e,t)}qname(t){const e=t.indexOf(":");if(-1===e)return{prefix:"",local:t};const s=t.slice(e+1),n=t.slice(0,e);return(""===n||""===s||s.includes(":"))&&this.fail(`malformed name: ${t}.`),{prefix:n,local:s}}processAttribsNS(){var t;const{attribList:e}=this,s=this.tag;{const{prefix:e,local:n}=this.qname(s.name);s.prefix=e,s.local=n;const i=s.uri=null!==(t=this.resolve(e))&&void 0!==t?t:"";""!==e&&("xmlns"===e&&this.fail('tags may not have "xmlns" as prefix.'),""===i&&(this.fail(`unbound namespace prefix: ${JSON.stringify(e)}.`),s.uri=e))}if(0===e.length)return;const{attributes:n}=s,i=new Set;for(const t of e){const{name:e,prefix:s,local:r}=t;let o,a;""===s?(o="xmlns"===e?g:"",a=e):(o=this.resolve(s),void 0===o&&(this.fail(`unbound namespace prefix: ${JSON.stringify(s)}.`),o=s),a=`{${o}}${r}`),i.has(a)&&this.fail(`duplicate attribute: ${a}.`),i.add(a),t.uri=o,n[e]=t}this.attribList=[]}processAttribsPlain(){const{attribList:t}=this,e=this.tag.attributes;for(const{name:s,value:n}of t)void 0!==e[s]&&this.fail(`duplicate attribute: ${s}.`),e[s]=n;this.attribList=[]}openTag(){var t;this.processAttribs();const{tags:e}=this,s=this.tag;s.isSelfClosing=!1,null===(t=this.openTagHandler)||void 0===t||t.call(this,s),e.push(s),this.state=b,this.name=""}openSelfClosingTag(){var t,e,s;this.processAttribs();const{tags:n}=this,i=this.tag;i.isSelfClosing=!0,null===(t=this.openTagHandler)||void 0===t||t.call(this,i),null===(e=this.closeTagHandler)||void 0===e||e.call(this,i);null===(this.tag=null!==(s=n[n.length-1])&&void 0!==s?s:null)&&(this.closedRoot=!0),this.state=b,this.name=""}closeTag(){const{tags:t,name:e}=this;if(this.state=b,this.name="",""===e)return this.fail("weird empty close tag."),void(this.text+="</>");const s=this.closeTagHandler;let n=t.length;for(;n-- >0;){const n=this.tag=t.pop();if(this.topNS=n.ns,null==s||s(n),n.name===e)break;this.fail("unexpected close tag.")}0===n?this.closedRoot=!0:n<0&&(this.fail(`unmatched closing tag: ${e}.`),this.text+=`</${e}>`)}parseEntity(t){if("#"!==t[0]){const e=this.ENTITIES[t];return void 0!==e?e:(this.fail(this.isName(t)?"undefined entity.":"disallowed character in entity name."),`&${t};`)}let e=NaN;return"x"===t[1]&&/^#x[0-9a-f]+$/i.test(t)?e=parseInt(t.slice(2),16):/^#[0-9]+$/.test(t)&&(e=parseInt(t.slice(1),10)),this.isChar(e)?String.fromCodePoint(e):(this.fail("malformed character entity."),`&${t};`)}}});class o{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 a="@xstate.init",c="@xstate.spawn",h="@xstate.stop",l="@xstate.terminate",u="xstate.timer";function d(t,e){return{type:"xstate.after",delay:t,stateId:e}}function f(t,e){return`xstate.after.${t}.${e}`}function p(t){return`xstate.timeout.${t}`}function m(t,e){return{type:"xstate.timeout.actor",actorId:t,sessionId:e}}function g(t){return`xstate.timeout.actor.${t}`}function y(t,e){return{type:"xstate.done.state",stateId:t,output:e}}function v(t,e){return{type:`xstate.error.${t}`,error:e}}function x(t){return{type:a,input:t}}function _(t){setTimeout(()=>{throw t})}const b="function"==typeof Symbol&&Symbol.observable||"@@observable";function w(t){if("string"==typeof t)throw new Error("Only event objects may be used with sendTo")}const S={"@xstate.spawn":t=>t.system.spawnActor(t._parent,t),"@xstate.start":t=>t.system.startActor(t),"@xstate.raise":(t,e,s)=>t.system.scheduleTimer(t.self,s.id,s?.delay??0),"@xstate.sendTo":(t,e,s,n)=>(w(s),void 0!==n?.delay?t.system.scheduleTimer(t.self,n.id,n?.delay??0):t.system._relay(t.self,e,s)),"@xstate.cancel":(t,e)=>t.system.cancelTimer(t.self,e),"@xstate.stop":(t,e)=>t.system.stopActor(e),"@xstate.terminate":(t,e)=>t.system.terminateActor(t,e)},A=new WeakMap;function E(t,e){let s=A.get(t);if(!s){s=new Map;for(const e of Object.keys(t)){const n=t[e];s.has(n)||s.set(n,e)}A.set(t,s)}return s.get(e)}const $=new WeakMap;function k(t,e){const s=(t,e)=>[{status:"active",output:void 0,error:void 0,input:t},[]];return{id:e,start:(e,{self:s,system:n})=>{const i=e.input.actor;if(!i||"stopped"===i.getSnapshot().status)return;const r=t(e.input,{self:s,system:n});if(!r)return;let o,a=!1;const c=()=>{a||(a=!0,r.unsubscribe(),o?.unsubscribe())},h=s._parent;h&&(o=h.subscribe({complete:c,error:c})),$.set(s,{unsubscribe:c})},transition:(t,e,{self:s})=>e.type===h?($.get(s)?.unsubscribe(),$.delete(s),[{...t,status:"stopped",error:void 0},[]]):[t,[]],initialTransition:s,getInitialSnapshot:(t,e)=>s(e)[0],getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}function I(t,e,s){"stopped"!==t.getSnapshot().status&&t._parent&&e._relay(t,t._parent,s())}function T(){return k(({actor:t,eventType:e,mapper:s},{self:n,system:i})=>{const r="*"!==e&&e.endsWith(".*");return t.on(r?"*":e,t=>{r&&!cs(t.type,e)||I(n,i,()=>s(t))})},"xstate.listener")}const C=T();function R(){return k(({actor:t,mappers:e},{self:s,system:n})=>{const{done:i,error:r,snapshot:o}=e;return t.subscribe({next:t=>{"done"===t.status&&i?I(s,n,()=>i(t.output)):"error"===t.status&&r?I(s,n,()=>r(t.error)):"active"===t.status&&o&&I(s,n,()=>o(t))},error:t=>{r&&I(s,n,()=>r(t))},complete:()=>{}})},"xstate.subscription")}const M=R(),N=Symbol();function j(t){return!!t[N]}function O(t){return j(t)?t._parent:t.self._parent}function D(t,e){if(!j(e)){const s=t,n=e.self;return s.self=n,s.system=e.system,s.parent=n._parent,s}return Object.defineProperties(t,{self:{enumerable:!0,get:()=>e.self},system:{enumerable:!0,get:()=>e.system},parent:{enumerable:!0,get:()=>O(e)}}),t}function P(){return this.action?.(...this.args)}function H(t=this.source.system){return t.emitEvent(this.source,this.event)}function L(t=this.actor.system){return t.spawnActor(this.source,this.actor)}function W(t=this.actor.system){return t.startActor(this.actor)}function V(t=this.source.system){return t.stopActor(this.actor)}function z(t=this.actor.system){const e="done"===this.status?{status:"done",output:this.output,error:void 0}:{status:"error",output:void 0,error:this.error};return t.terminateActor(this.actor,e)}function X(t=this.source.system){return t.scheduleTimer(this.source,this.id,this.delay??0)}function K(t=this.source.system){return w(this.event),void 0!==this.delay?t.scheduleTimer(this.source,this.id,this.delay):t.sendEvent(this.source,this.target,this.event)}function B(t=this.source.system){return t.cancelTimer(this.source,this.id)}function q(t,e,s){if(!dt(e))return t;if("@xstate.cancel"===e.type){if(!t.timers?.[e.id])return t;const s={...t.timers};return delete s[e.id],{...t,timers:s}}if("@xstate.raise"!==e.type&&"@xstate.sendTo"!==e.type||void 0===e.delay)return t;let n=t._nextTimerId??0;const i=e.id??"xstate.timer.auto."+n++;e.id=i;const r="@xstate.raise"===e.type||e.target===s.self?"self":e.target;return{...t,timers:{...t.timers,[i]:{id:i,delay:e.delay,type:e.type,event:e.event,target:r}},_nextTimerId:n}}function U(t,e){return{...t,...e}}function F(t,e,...s){const n={action:e,args:s};return t.push(n),n}function Z(t,e){const s={...t};for(const t of Object.keys(e))s[t]=Math.max(s[t]??0,e[t]);return s}function J(t,e,s){if("add"===e.type)return{...t,children:{...t.children,[e.id]:e.actor},...e.counters&&{_nextActorIds:Z(t._nextActorIds,e.counters)}};const n={...t.children};let i=e.actor._parent===s.self;for(const t of Object.keys(n))n[t]===e.actor&&(i=!0,delete n[t]);if(!i)throw new Error(`Cannot stop non-child actor ${e.actor.id}`);return s.system._unregister(e.actor),{...t,children:n}}function Q(t){if("object"==typeof t&&null!==t&&"action"in t&&"function"==typeof t.action)return t}const G=new WeakMap,Y=()=>({counters:new Map,explicitIds:new Set,stoppedIds:new Set});function tt(t){G.set(t,Y())}function et(t){return t.self._snapshot}function st(t,e,s){return Math.max(e.counters.get(s)??0,et(t)?._nextActorIds?.[s]??0)}function nt(t,e,s){const n=G.get(t)??s??Y(),i=gs(e),r=st(t,n,i);return n.counters.set(i,r+1),{id:`${i}:${r}`,counters:{[i]:r+1}}}function it(t,e,s){const n=G.get(t)??s??Y(),i=et(t)?.children?.[e],r=void 0!==i&&!n.stoppedIds.has(e)&&"active"===i.getSnapshot().status;if(n.explicitIds.has(e)||r)throw new Error(`Child actor id '${e}' is already in use`);n.explicitIds.add(e)}function rt(t,e,s){const n=vs(e);if(!n)return;n.prefix;const i=G.get(t)??s??Y(),r=Math.max(st(t,i,n.prefix),n.index+1);return i.counters.set(n.prefix,r),{[n.prefix]:r}}function ot(t,e,s,n=!1,i=!0){const r=G.get(t)??Y(),o={cancel:s=>{F(e,S["@xstate.cancel"],t,s)},emit:t=>{e.push(t)},log:(...s)=>{F(e,t.logger,...s)},raise:(n,i)=>{if("string"==typeof n)throw new Error("Only event objects may be used with raise");void 0!==i?.delay?F(e,S["@xstate.raise"],t,n,i):s.push(n)},spawn:(s,n)=>{const{logic:o,src:a}=function(t,e){const s=function(t){return t.self.logic?.sources?.actors}(t);if("string"==typeof e){const t=s?.[e];if(!t)throw new Error(`Actor source '${e}' is not provided`);return{logic:t,src:e}}return s?{logic:e,src:E(s,e)}:{logic:e,src:void 0}}(t,s);if(!i)return{id:n?.id??n?.registryKey??a??o.id};let c,h=n?.id;void 0===h?({id:h,counters:c}=nt(t,a??o,r)):(it(t,h,r),c=rt(t,h,r));const l=t.system.createActorRef(o,{...n,...void 0!==a&&{src:a},id:h,parent:t.self});return function(t,e,s,n){F(t,S["@xstate.spawn"],e).childUpdate={type:"add",actor:e,id:s,counters:n}}(e,l,h,c),l},sendTo:(n,i,r)=>{n?F(e,S["@xstate.sendTo"],t,n,i,r):s.push(v("communication",{message:"Unable to send event to an undefined actor",event:i}))},stop:s=>{if(s){const n=s;F(e,S["@xstate.stop"],t,n).childUpdate={type:"remove",actor:n},function(t,e){const s=G.get(t);s&&(s.stoppedIds.add(e.id),s.explicitIds.delete(e.id))}(t,n)}}};return n&&Object.assign(o,{listen:(s,n,r)=>{if(!i)return{id:void 0};const o={actor:s,eventType:n,mapper:r},a=t.system.createActorRef(C,{input:o,parent:t.self});return F(e,S["@xstate.spawn"],a),a},subscribeTo:(s,n)=>{if(!i)return{id:void 0};const r={actor:s,mappers:"function"==typeof n?{snapshot:n}:n},o=t.system.createActorRef(M,{input:r,parent:t.self});return F(e,S["@xstate.spawn"],o),o}}),pt(o,(t,...s)=>{F(e,t,...s)})}function at(t,e){switch(t){case S["@xstate.spawn"]:{const[t]=e;return{kind:"builtin",exec:L,source:t._parent,actor:t,id:t.id,logic:t.logic,src:t.src,input:t.options?.input}}case S["@xstate.raise"]:{const[,t,s]=e;return{kind:"builtin",exec:X,source:e[0].self,event:t,id:s?.id,delay:s?.delay}}case S["@xstate.sendTo"]:{const[,t,s,n]=e;return{kind:"builtin",exec:K,source:e[0].self,target:t,event:s,id:n?.id,delay:n?.delay}}case S["@xstate.cancel"]:{const[,t]=e;return{kind:"builtin",exec:B,source:e[0].self,id:t}}case S["@xstate.stop"]:{const[,t]=e;return{kind:"builtin",exec:V,source:e[0].self,actor:t,id:t.id}}default:return}}function ct(t){const e=[t];return{kind:"builtin",exec:W,type:"@xstate.start",source:t._parent,params:void 0,args:e,actor:t,id:t.id}}function ht(t,e,s){const n=[t,e,s,{}];return{kind:"builtin",exec:K,type:"@xstate.sendTo",source:t.self,target:e,event:s,id:void 0,delay:void 0,params:void 0,args:n}}function lt(t,e){if("done"!==e.status&&"error"!==e.status)throw new Error("Cannot terminate an active or stopped actor");const s="done"===e.status?{status:"done",output:e.output,error:void 0}:{status:"error",output:void 0,error:e.error},n=[t.self,s];return{kind:"builtin",exec:z,type:l,source:t.self,actor:t.self,id:t.self.id,...s,params:void 0,args:n}}function ut(t,e,[s,n]){const i="done"===s.status||"error"===s.status,r="done"===e?.status||"error"===e?.status,o=n.some(t=>"object"==typeof t&&null!==t&&"type"in t&&t.type===l);return!i||r||o?[s,n]:[s,[...n,lt(t,s)]]}function dt(t){return"builtin"===t.kind}function ft(t,e,s,n){let i=t;const r=[];for(const o of n){const n=j(s)?D({context:i.context,event:e,output:ss(e),children:i.children,actions:t.machine.sources.actions,actors:t.machine.sources.actors},s):{context:i.context,event:e,output:ss(e),self:s.self,system:s.system,parent:s.self._parent,children:i.children,actions:t.machine.sources.actions,actors:t.machine.sources.actors},a="function"==typeof o,c=Q(o),h=a?o:!!c&&c.action.bind(null,...c.args);let l;if("object"==typeof o&&null!==o){const{type:t,childUpdate:e,...s}=o;l=s}if(c?.childUpdate&&(i=J(i,c.childUpdate,s)),h&&"_special"in h){r.push({kind:"action",exec:P,type:"object"==typeof o?"action"in o&&"function"==typeof o.action?o.action.name??"(anonymous)":o.type??"(anonymous)":o.name||"(anonymous)",params:l,args:[],action:void 0});const t=h(n,yt);t&&("context"in t||"children"in t)&&(i={...i,...void 0!==t.context?{context:U(i.context,t.context)}:{},..."children"in t?{children:t.children}:{}});continue}if(!h||!("resolve"in h)){const t="object"==typeof o&&null!==o&&"action"in o&&"function"==typeof o.action?at(o.action,o.args):void 0,e="object"==typeof o&&null!==o&&!c,n={kind:t?"builtin":e?"emit":"action",type:"object"==typeof o?"action"in o&&"function"==typeof o.action?o.action.name??"(anonymous)":o.type:o.name||"(anonymous)",params:t?void 0:l,args:"object"==typeof o&&"action"in o?o.args:[],...t?{}:e?{source:s.self,event:o}:{action:c?.action??(a?o:void 0)},...t?{}:{exec:e?H:P},...t};i=q(i,n,s),r.push(n);continue}}return[i,r]}function pt(t,e){const s=(t,...s)=>{e(t,...s)};return Object.assign(s,{cancel:mt,emit:mt,log:mt,raise:mt,spawn:gt,sendTo:mt,stop:mt,listen:gt,subscribeTo:gt,...t}),s}const mt=()=>{},gt=()=>({}),yt=pt({},mt);function vt(t){const e=t.trim(),s=e.match(/^(\d+)ms$/i);if(s)return parseInt(s[1],10);const n=e.match(/^(\d*)(\.?)(\d*)s$/i);if(n){const t=n[1]?parseInt(n[1],10):0,e=!!n[2],s=n[3]?parseInt(n[3].padEnd(3,"0").slice(0,3),10):0;return 1e3*t+(e?s:0)}const i=e.match(/^P(?:(?<weeks>\d+(?:[.,]\d+)?)W)?(?:(?<days>\d+(?:[.,]\d+)?)D)?(?:T(?:(?<hours>\d+(?:[.,]\d+)?)H)?(?:(?<minutes>\d+(?:[.,]\d+)?)M)?(?:(?<seconds>\d+(?:[.,]\d+)?)S)?)?$/i);if(!i?.groups)return;const{weeks:r,days:o,hours:a,minutes:c,seconds:h}=i.groups;if(!(r||o||a||c||h))return;const l=t=>t?Number(t.replace(",",".")):0;return 7*l(r)*24*60*60*1e3+24*l(o)*60*60*1e3+60*l(a)*60*1e3+60*l(c)*1e3+1e3*l(h)}function xt(t){if(void 0!==t)return"number"==typeof t?t:vt(t)}const _t=new WeakMap,bt=new WeakMap,wt=new Map;function St(t){const e=t._peekKeyedActors;return e?e.call(t)??wt:t.keyedActors}function At(t){t._snapshotVersion++}function Et(t){return t._snapshotVersion}function $t(t,e,s){const n=function(t,e){if(e){const t=new Map(e.children);return e.root?.sessionId&&t.set(e.root.sessionId,e.root),t}return new Map(t.children)}(t,s),i=new Map(s?.keyedActors??St(t)),r=new WeakMap,o=Object.assign(Object.create(t),{children:n,keyedActors:i,reverseKeyedActors:r,_snapshot:{...s?.snapshot??t._snapshot},_snapshotVersion:s?.sourceVersion??t._snapshotVersion,_register:(t,e)=>(n.set(t,e),At(o),t),_unregister:t=>{t.sessionId&&n.delete(t.sessionId);const e=r.get(t);void 0!==e&&i.get(e)===t&&i.delete(e),r.delete(t),At(o)},_set:(t,e)=>{const s=i.get(t);if(s&&s!==e)throw new Error(`Actor with registry key '${String(t)}' already exists.`);i.set(t,e),r.set(e,t),At(o)},get:t=>i.get(t),getAll:()=>Object.fromEntries(i),_hasInspectionObservers:()=>!1,_sendInspectionEvent:()=>{}});for(const[t,e]of i)e&&r.set(e,t);for(const t of Object.values(e)){if(!t)continue;t.sessionId&&n.set(t.sessionId,t);const e=t.registryKey;e&&(i.set(e,t),r.set(t,e))}return o}function kt(t){const e=_t.get(t);if(e)return e;const s=bt.get(t);if(!s)return;const n=s();return _t.set(t,n),bt.delete(t),n}function It(t,e){const s=_t.get(t);if(s)return _t.set(e,s),!0;const n=bt.get(t);return!!n&&(bt.set(e,n),!0)}function Tt(t,e,s=e.system,n){bt.delete(t);const i=Et(s),r=n?kt(n):void 0,o=r?.actor===e?r:kt(t);if(o?.actor===e&&o.systemState.sourceSystem===s&&o.systemState.sourceVersion===i)return void _t.set(t,o);const a=function(t){const e=t._getRootActor?.(),s=t._peekChildren?.();if(!e&&!s){if(t._getRootActor&&t._peekChildren)return{};const e=new Map(t.children);return e.size?{children:e}:{}}return s?.size?{children:new Map(t.children)}:e?{root:e}:{}}(s);let c=a.children;const h=St(s);let l=h.size?new Map(h):wt;for(const e of Object.values(function(t){return"children"in t&&t.children?t.children:{}}(t))){if(!e)continue;e.sessionId&&(c??=new Map).set(e.sessionId,e);const t=e.registryKey;t&&(l===wt&&(l=new Map),l.set(t,e))}_t.set(t,{actor:e,systemState:{...a,children:c,keyedActors:l,snapshot:{...s._snapshot},sourceSystem:s,sourceVersion:i}})}function Ct(t,e,s=!0){const n=Ot(t);return n?(n.snapshot=e,n.materialized&&(n.materialized.self._snapshot=e)):t.self._snapshot=e,s&&e&&"object"==typeof e&&Tt(e,t.self),e}function Rt(t){return!!Ot(t)||!!t.self.options?._inert}function Mt(t,e){Ct(t,e,!1);const s=Ot(t);jt.set(e,t);const n=()=>(Tt(e,t.self,t.system),kt(e));return s&&(s.materialized?s.identityProvider=n:s.identityProvider??=n),function(t,e){_t.delete(t),bt.set(t,e)}(e,n),e}const Nt=Symbol(),jt=new WeakMap;function Ot(t){return t[Nt]}function Dt(t){return Ot(t).materialize()}const Pt={[N]:!0,get _parent(){const t=Ot(this);return t.parentKnown?t.parent:Dt(this).self._parent},get self(){return Dt(this).self},get defer(){return Dt(this).defer},get id(){return Dt(this).id},get logger(){return Dt(this).logger},get sessionId(){return Dt(this).sessionId},get stopChild(){return Dt(this).stopChild},get system(){return Dt(this).system},get emit(){return Dt(this).emit},get actionExecutor(){return Dt(this).actionExecutor}};function Ht(t,e,s,n,i){const r=e?.(),o=i??r?.actor,a=o?.system,c=o&&a?$t(a,s,i?void 0:r?.systemState):void 0,h=Ns(t,{_inert:!0,...o?{id:o.id,_sessionId:o.sessionId}:{},...c?{_systemRef:{current:c}}:{}});return o?._parent&&(h._parent=o._parent,h._address=void 0),n&&(h._snapshot=n),Object.create(h._actorScope,{defer:{value:()=>{}},stopChild:{value:t=>t._stop()},actionExecutor:{value:()=>{}}})}function Lt(t,e,s,n){const i=n??(e&&"object"==typeof e?jt.get(e):void 0),r=i?Ot(i):void 0,o=e&&"object"==typeof e?function(t){return _t.get(t)}(e):void 0,a=r?.identityProvider??(e&&"object"==typeof e?function(t){const e=_t.get(t);return e?()=>e:bt.get(t)}(e):void 0),c={snapshot:e,sourceRef:a,sourceChildren:He(e)?e.children:{},identityProvider:r?.identityProvider??a,parent:s?._parent??r?.parent??o?.actor._parent,parentKnown:!(!s&&!r?.parentKnown&&!o&&e),materialize:()=>c.materialized??=Ht(t,c.sourceRef,c.sourceChildren,c.snapshot,s)};if(!c.identityProvider&&!e){const e={},n=c.sourceRef,i=c.sourceChildren;let r,o;const a=()=>r??=Ht(t,n,i,void 0,s);c.materialize=()=>{const t=a();return void 0!==c.snapshot&&(t.self._snapshot=c.snapshot),c.materialized=t},c.identityProvider=()=>{if(o)return o;const t=a();return Tt(e,t.self,t.system),o=kt(e)}}const h=Object.create(Pt);return h[Nt]=c,h}function Wt(t,e,s){if("function"==typeof t)return t(s);const n=function(t,e){if("string"!=typeof t)return t;const s=e[t];return void 0!==s?s:vt(t)??t}(t,e);return"function"==typeof n?n(s):n}function Vt(t,e){return t._stateInputs?.[e]}function zt(t){return"atomic"===t.type||"final"===t.type||"choice"===t.type}function Xt(t){return Object.values(t.states).filter(t=>"history"!==t.type)}function Kt(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 Bt(t){const e=new Set(t),s=new Set;for(const t of e)t.parent&&s.add(t.parent);for(const t of e)if("compound"!==t.type||s.has(t)){if("parallel"===t.type)for(const s of Xt(t))if(!e.has(s)){const t=oe(s);for(const s of t)e.add(s)}}else for(const s of oe(t))e.add(s);for(const t of e){let s=t.parent;for(;s&&!e.has(s);)e.add(s),s=s.parent}return e}function qt(t,e){const s=Bt(e),n=new Map;for(const t of s)n.has(t)||n.set(t,[]),t.parent&&(n.has(t.parent)||n.set(t.parent,[]),n.get(t.parent).push(t));const i=t=>{const e=n.get(t);if(!e)return{};if("compound"===t.type){const t=e[0];if(!t)return{};if(zt(t))return t.key}const s={};for(const t of e)s[t.key]=i(t);return s};return i(t)}function Ut(t,e){return"compound"===e.type?Xt(e).some(e=>"final"===e.type&&t.has(e)):"parallel"===e.type?Xt(e).every(e=>Ut(t,e)):"final"===e.type}const Ft=t=>"#"===t[0];function Zt(t){switch(t.type){case"xstate.done.actor":case"xstate.error.actor":return`${t.type}.${t.actorId}`;case"xstate.snapshot.actor":return`xstate.snapshot.${t.actorId}`;case"xstate.done.state":return`xstate.done.state.${t.stateId}`;case"xstate.after":return`xstate.after.${t.delay}.${t.stateId}`;case"xstate.timeout":return`xstate.timeout.${t.stateId}`;case"xstate.timeout.actor":return`xstate.timeout.actor.${t.actorId}`;default:return}}function Jt(t,e,s){const n=e.children[s];return!n||!("sessionId"in t)||(void 0===n.sessionId||n.sessionId===t.sessionId)}function Qt(t,e){const s=function(t){const e=Zt(t);return e?[t.type,e]:[t.type]}(e),n=s.flatMap(e=>t.transitions.get(e)??[]),i=[...t.transitions.keys()].filter(t=>!s.includes(t)&&s.some(e=>cs(e,t))).sort((t,e)=>e.length-t.length).flatMap(e=>t.transitions.get(e));return n.length?[...n,...i]:i}function Gt(t,e,s,n){const i=t.entry;t.entry=(t,r)=>(r.raise(s(t),{id:e,delay:n(t)}),"function"==typeof i?i(t,r):void 0);const r=t.exit;t.exit=(t,s)=>(s.cancel(e),"function"==typeof r?r(t,s):void 0)}function Yt(t,e,s){const n=rs(s.target),i=s.reenter??!1,r=ne(t,n);se(t,r);const o={...s,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...o,source:`#${t.id}`,target:r?r.map(t=>`#${t.id}`):void 0})};return o}function te(t,e){for(let s=t.parent;s;s=s.parent)if(s===e)return!0;return!1}function ee(t,e){const s=new Set;for(let e=t;e;e=e.parent)s.add(e);for(let t=e;t;t=t.parent)if(s.has(t))return t}function se(t,e){if(e&&!(e.length<2))for(let s=0;s<e.length;s++)for(let n=s+1;n<e.length;n++){const i=e[s],r=e[n],o=ee(i,r);if(i===r||te(i,r)||te(r,i)||"parallel"!==o?.type)throw new Error(`Invalid target set for '${t.id}'`)}}function ne(t,e){if(void 0!==e)return e.map(e=>{if("string"!=typeof e)return e;if(Ft(e))return t.machine.getStateNodeById(e);const s="."===e[0];if(s&&!t.parent)return ce(t,e.slice(1));const n=s?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}"`);try{return ce(t.parent,n)}catch(e){throw new Error(`Invalid transition for '${t.id}': ${e.message}`)}})}function ie(t){const e=rs(t.config.target);if(!e)return"parallel"===t.parent.type?{target:[t.parent],source:t,reenter:!1,eventType:""}:t.parent.initial;const s=e.map(e=>"string"==typeof e?ce(t.parent,e):e);return se(t,s),{target:s,source:t,reenter:!1,eventType:"",to:t.config._historyDefaultTransition}}function re(t){return"history"===t.type}function oe(t){const e=new Set;!function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const e of s.initial.target??[])t(e);else if("parallel"===s.type)for(const e of Xt(s))t(e)}(t);for(const s of e)for(const n of Kt(s,t))e.add(n);return e}function ae(t,e){if(Ft(e))return t.machine.getStateNodeById(e);const s=t.states?.[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function ce(t,e){if("string"==typeof e&&Ft(e))try{return t.machine.getStateNodeById(e)}catch{}const s=Qe(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=ae(n,t)}return n}function he(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=new Array(s.length),i=[t.machine.root,t];for(let e=0;e<s.length;e++){const r=ae(t,s[e]);n[e]=r,i.push(r)}for(let t=0;t<s.length;t++)i.push(...he(n[t],e[s[t]]));return i}function le(t,e,s,n,i,r){if("string"==typeof e){const o=ae(t,e).next(s,n,i,r);return o&&o.length?o:t.next(s,n,i,r)}const o=Object.keys(e),a=o[0];if(1===o.length){const o=le(ae(t,a),e[a],s,n,i,r);return o&&o.length?o:t.next(s,n,i,r)}const c=[];for(const a of o){const o=e[a];if(!o)continue;const h=le(ae(t,a),o,s,n,i,r);h&&c.push(...h)}return c.length?c:t.next(s,n,i,r)}function ue(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function de(t,e){for(const s of t)if(ue(s,e))return!0;return!1}function fe(t,e){const s=t instanceof Set?t.size:Array.isArray(t)?t.length:void 0,n=e instanceof Set?e.size:Array.isArray(e)?e.length:void 0;void 0!==s&&void 0!==n&&n<s&&([t,e]=[e,t]);const i=t instanceof Set?t:new Set(t);for(const t of e)if(i.has(t))return!0;return!1}function pe(t,e,s,n){const i=new Set,r=new Map,o=t=>{let i=r.get(t);return i||(i=xe([t],e,s,n),r.set(t,i)),i};for(const e of t){let t=!1;const s=new Set;for(const n of i)if(fe(o(e),o(n)))if(ue(e.source,n.source))s.add(n);else{if("final"!==n.source.type||"final"===e.source.type){t=!0;break}s.add(n)}if(!t){for(const t of s)i.delete(t);i.add(e)}}return Array.from(i)}function me(t,e,s,n,i){let r;return o=>{if(!o.to)return be(o,t,e,s,{resolveActions:n,selectionResult:i?.get(o)});let a=r?.get(o);return a||(a=be(o,t,e,s,{resolveActions:n,selectionResult:i?.get(o)}),(r??=new Map).set(o,a)),a}}function ge(t,e,s){const n=e.historyValue,{targets:i}=s(t);if(!i)return[];const r=new Set;for(const t of i)if(re(t))if(n[t.id])for(const e of n[t.id])r.add(e);else for(const n of ge(ie(t),e,s))r.add(n);else r.add(t);return[...r]}function ye(t,e){let s=t;for(;"parallel"===s.type;){const t=Xt(s).find(t=>e.every(e=>e===t||ue(e,t)));if(!t)break;s=t}return s}function ve(t,e,s){const n=ge(t,e,s),{targets:i,reenter:r}=s(t);if(t._transitionDomain){if("internal"===t._transitionDomain&&"compound"===t.source.type&&n.every(e=>ue(e,t.source)))return t.source;const[e,...s]=n.concat(t.source);for(const t of Kt(e,void 0))if("compound"===t.type&&s.every(e=>ue(e,t)))return t;return}if(!(i?.some(re)&&n.some(e=>e===t.source))&&n.every(e=>e===t.source||ue(e,t.source)))return r?t.source:ye(t.source,n);const[o,...a]=n.concat(t.source);for(const t of Kt(o,void 0))if(a.every(e=>ue(e,t)))return r?t:ye(t,n);return r?void 0:ye(t.source.machine.root,n)}function xe(t,e,s,n){const i=new Set;for(const r of t){const{targets:t,reenter:o}=n(r);if(t?.length){const t=ve(r,s,n);o&&r.source===t&&i.add(t);for(const s of e)ue(s,t)&&i.add(s)}}return[...i]}function _e(t,e,s,n,i,r,o){const a=[];if(!t.length)return[e,a];{const c=new Set(e.nodes);let h=e.historyValue;const l=e.context,u=1===t.length?t:pe(t,c,e,me(e,n,s,!1,o)),d=me(e,n,s,!0,o),f=u.some(t=>{const{targets:e,reenter:s}=d(t);return!!e?.length||!!s}),p=(t,i,r,o)=>{if(2===t.length){const a=[],c=[];let h;const l=ot(s,a,c,!0),u=j(s)?D({context:i,event:n,children:r,actions:e.machine.sources.actions,actors:e.machine.sources.actors,guards:e.machine.sources.guards,delays:e.machine.sources.delays,input:o},s):{context:i,event:n,parent:s.self._parent,self:s.self,children:r,system:s.system,actions:e.machine.sources.actions,actors:e.machine.sources.actors,guards:e.machine.sources.guards,delays:e.machine.sources.delays,input:o},d=t(u,l);return void 0!==d?.context&&(h=U(i,d.context)),[a,h,c]}return[[Object.assign((e,n)=>t(j(s)?D({context:e.context,event:e.event,output:e.output,children:e.children,actions:e.actions,actors:e.actors,input:o},s):{...e,input:o},n),"_special"in t?{_special:!0}:{})],void 0,void 0]};let m=e;const g=(t,e)=>{const n=[],i=ot(s,n,[]);for(const s of t.invoke){const t=e[s.id];t&&i.stop(t)}return n},v=()=>{const t=xe(u,c,e,d);let i;t.sort((t,e)=>e.order-t.order);const o=[...c];for(const e of t)for(const t of Object.values(e.states)){if("history"!==t.type)continue;const s="deep"===t.history?t=>zt(t)&&ue(t,e):t=>t.parent===e;i??={...h},i[t.id]=o.filter(s)}for(const i of t){const t=Vt(e,i.id),[o,h,l]=i.exit?p(i.exit,m.context,e.children,t):[[],void 0,void 0];l?.length&&r.push(...l),h&&(m=Ue(m,{context:h}));const[u,d]=ft(m,n,s,o);m=u,a.push(...d);const f=g(i,m.children);if(f.length){const[t,e]=ft(m,n,s,f);m=t,a.push(...e)}c.delete(i)}h=i||h};!i&&f&&v();let x=m.context;const _=[],b=[];for(const t of u){t.actions&&_.push(...ts(t.actions));const e=d(t);void 0!==e.context&&(x=U(x,e.context)),e.actions&&_.push(...e.actions),e.internalEvents&&b.push(...e.internalEvents)}b.length&&r.push(...b);const w=()=>{const t=t=>{const e=m.machine.root;let i;if(void 0!==t.output&&t.parent){const o=r.find(t=>"xstate.done.state"===t.type&&t.stateId===e.id);i=o&&t.parent===e?o.output:es(t.output,m.context,n,s.self,x[t.id])}else if("parallel"===t.type){const e=r.find(e=>"xstate.done.state"===e.type&&e.stateId===t.id);i=e?.output}return void 0===e.output?t.parent===e?i:void 0:es(e.output,m.context,y(t.id,i),s.self)},o=new Set,l=new Set,f=new Map,g=(t,e)=>{for(const s of t)if(e&&!ue(s,e)||o.add(s),"parallel"===s.type)for(const t of Xt(s))de(o,t)||(o.add(t),v(t))},v=t=>{if(re(t))if(h[t.id]){const e=h[t.id];for(const t of e)o.add(t),v(t);for(const s of e)g(Kt(s,t.parent),void 0)}else{const e=ie(t),s=t.parent;l.add(s);const n=f.get(s)??[];n.push(e),f.set(s,n);const{targets:i}=d(e);for(const s of i??[])o.add(s),e===t.parent?.initial&&l.add(t.parent),v(s);for(const e of i??[])g(Kt(e,t.parent),void 0)}else{if("compound"===t.type){const e=d(t.initial).targets??[];for(const t of e)re(t)||o.add(t);l.add(t);for(const t of e)v(t);for(const s of e)g(Kt(s,t),void 0);return}if("parallel"===t.type)for(const e of Xt(t))de(o,e)||(o.add(e),l.add(e),v(e))}};for(const t of u){const s=ve(t,e,d),{targets:n,reenter:i}=d(t);for(const e of n??[])re(e)||t.source===e&&t.source===s&&!i||(o.add(e),l.add(e)),v(e);const r=ge(t,e,d);for(const e of r){const n=Kt(e,s);"parallel"===s?.type&&n.push(s),g(n,!t.source.parent&&i?void 0:s)}i&&s===t.source&&o.add(t.source)}if(i)for(const t of u[0]._statesForDefaultEntry??[e.machine.root])l.add(t);const x={...e._stateInputs};let _=!1;for(const t of u){const{targets:e,input:s}=d(t);if(s&&e)for(const t of e)x[t.id]=s,_=!0}const b=new Set,w={...m.children};for(const i of[...o].sort((t,e)=>t.order-e.order)){c.add(i);const o=[];let h=!1;for(const t of i.invoke){h=!0;let i=t.logic;"function"==typeof i&&(i=i({actors:e.machine.sources.actors,context:m.context,event:n,self:s.self}));const r="string"==typeof i?as(e.machine,i):i;if(!r)throw new Error(`Actor logic '${"string"==typeof i?i:"inline"}' not implemented`);const a="function"==typeof t.input?t.input({self:s.self,context:m.context,event:n,output:ss(n)}):t.input;it(s,t.id);const c=s.system.createActorRef(r,{...t,input:a,parent:s.self,syncSnapshot:!!t.onSnapshot});o.push({action:S["@xstate.spawn"],args:[c]}),t.id&&(w[t.id]=c)}h&&(m=Ue(m,{children:w}));let u=m.context,d=!1;const g=x[i.id];if(i.entry){const[t,e,s]=p(i.entry,u,w,g);o.push(...t),s?.length&&r.push(...s),e&&(u=e,d=!0)}if(d&&(m.context=u),l.has(i)){const t=[i.initial,...f.get(i)??[]].filter(Boolean);for(const e of t){const{actions:t,context:i,input:a,internalEvents:c}=be(e,m,n,s);if(t&&o.push(...t),c?.length&&r.push(...c),void 0!==i&&(m.context=U(m.context,i)),a&&e.target)for(const t of e.target)x[t.id]=a,_=!0}}const[v,A]=ft(m,n,s,o);if(m=v,o.length=0,a.push(...A),"final"!==i.type)continue;const E=i.parent;let $="parallel"===E?.type?E:E?.parent,k=$||i;for("compound"===E?.type&&r.push(y(E.id,void 0!==i.output?es(i.output,m.context,n,s.self,g):void 0));"parallel"===$?.type&&!b.has($)&&Ut(c,$);){b.add($);const t={};for(const e of Xt($)){if("final"===e.type){t[e.key]=void 0!==e.output?es(e.output,m.context,n,s.self,x[e.id]):void 0;continue}if("parallel"===e.type){const s=r.find(t=>"xstate.done.state"===t.type&&t.stateId===e.id);t[e.key]=s?.output;continue}const i=Xt(e).find(t=>"final"===t.type&&c.has(t));t[e.key]=void 0!==i?.output?es(i.output,m.context,n,s.self,x[i.id]):void 0}r.push(y($.id,t)),k=$,$=$.parent}$||(m=Ue(m,{status:"done",output:t(k)}))}_&&(m=Ue(m,{_stateInputs:x}))},[A,E]=ft(m,n,s,_);m=A,a.push(...E),x&&x!==e.context&&(m=Ue(m,{context:x})),(i||f)&&w();const $=[...c];if("done"===m.status){const t=[];$.sort((t,e)=>e.order-t.order).forEach(e=>{if(e.exit){const s=Vt(m,e.id),[n,,i]=p(e.exit,m.context,m.children,s);t.push(...n),i?.length&&r.push(...i)}});const[e,i]=ft(m,n,s,t);m=e,a.push(...i);const[o,c]=ke(m,n,s);m=o,a.push(...c);const[h,l]=Ie(m,n,s);m=h,a.push(...l)}return h===e.historyValue&&e.nodes.length===c.size&&e.nodes.every(t=>c.has(t))?m.context!==l?[m===e?Ue(m):m,a]:[m,a]:[Ue(m,{_nodes:$,historyValue:h}),a]}}function be(t,e,s,n,i){let r;const o=()=>r??=j(n)?D({context:e.context,event:s,output:ss(s),value:e.value,children:e.children,actions:e.machine.sources.actions,actors:e.machine.sources.actors,guards:e.machine.sources.guards,delays:e.machine.sources.delays,input:Vt(e,t.source.id)},n):{context:e.context,event:s,output:ss(s),value:e.value,children:e.children,system:n.system,parent:n.self._parent,self:n.self,actions:e.machine.sources.actions,actors:e.machine.sources.actors,guards:e.machine.sources.guards,delays:e.machine.sources.delays,input:Vt(e,t.source.id)};if(t.to){const r=[],a=[],c=i?.selectionResult?.reusable?i.selectionResult.result:t.to(o(),ot(n,r,a,!0,i?.resolveActions??!0)),h=c?.target?ne(t.source,ts(c.target)):void 0,l=c?.input??("function"==typeof t.input?t.input({context:e.context,event:s,output:ss(s)}):t.input);return{targets:h,context:c?.context,reenter:c?.reenter,actions:r,internalEvents:a,input:l}}const a="function"==typeof t.input?t.input({context:e.context,event:s,output:ss(s)}):t.input,c="function"==typeof t.context?t.context(o()):t.context;return{targets:t.target,context:c,reenter:t.reenter,actions:void 0,internalEvents:void 0,input:a}}function we(t,e,s,n,i=[]){let r=t;const o=i.slice();function l(t){if("xstate.done.actor"!==t.type&&"xstate.error.actor"!==t.type)return;const{actorId:e,sessionId:n}=t;if(!e)return;const i=r.children[e];if(!i)return;if(void 0!==i.sessionId&&i.sessionId!==n)return;const a={...r.children};if(delete a[e],s.system._unregister(i),r=Ue(r,{children:a}),o.length){const[,t]=o.at(-1);o[o.length-1]=[r,t]}else o.push([r,[]])}function d(){const e=function(t){const e=[],s=[];for(const n of t){if(!dt(n)||n.type!==c)continue;const{actor:t,logic:i}=n,r=ct(t);i===C||i===M?e.push(r):s.push(r)}return[...e,...s]}(o.flatMap(([,t])=>t)),n=("active"===t.status||i.length>0)&&("done"===r.status||"error"===r.status);if(e.length||n){const t=n?[...e,lt(s,r)]:e;if(o.length){const[e,s]=o.at(-1);o[o.length-1]=[e,[...s,...t]]}else o.push([r,t])}return{snapshot:r,microsteps:o}}function f(t,n){if(!Rt(s)&&(e.type===a||(s.system._hasInspectionObservers?.()??1))){const t=s.self._collectedMicrosteps||[];t.push(...n),s.self._collectedMicrosteps=t}o.push(t)}if(e.type===h){const[t,n]=ke(r,e,s),[i,o]=Ie(t,e,s);return r=Ue(i,{status:"stopped"}),f([r,[...n,...o]],[]),d()}let p=function(t,e){if("xstate.done.actor"===t.type||"xstate.error.actor"===t.type||"xstate.snapshot.actor"===t.type||"xstate.done.state"===t.type||"xstate.after"===t.type||"xstate.timeout"===t.type||"xstate.timeout.actor"===t.type)return t;const s=(e,s,n)=>t.type.startsWith(e)?{...t,type:s,[n]:t[n]??t.type.slice(e.length)}:void 0,n=s("xstate.done.actor.","xstate.done.actor","actorId")??s("xstate.error.actor.","xstate.error.actor","actorId")??s("xstate.snapshot.","xstate.snapshot.actor","actorId")??s("xstate.done.state.","xstate.done.state","stateId")??s("xstate.timeout.actor.","xstate.timeout.actor","actorId")??s("xstate.timeout.","xstate.timeout","stateId");if(n)return n;const i="xstate.after.";if(!t.type.startsWith(i))return t;const r=[...e.idMap.keys()].sort((t,e)=>e.length-t.length).find(e=>t.type.endsWith(`.${e}`));if(!r)return t;const o=t.type.slice(13,-r.length-1);return{...t,type:"xstate.after",delay:Number.isNaN(+o)?o:+o,stateId:r}}(e,t.machine);if(e.type===u){const t=r.timers[e.id];if(!t)return d();const i={...r.timers};if(delete i[t.id],r=Ue(r,{timers:i}),"@xstate.raise"===t.type)n.push(t.event),f([r,[]],[]);else{const e="self"===t.target?s.self:t.target;f([r,[ht(s,e,t.event)]],[])}}if(p.type!==a&&p.type!==u){const e=p,i=function(t){return t.type.startsWith("xstate.error.")}(e),o=new Map,a=r.machine.getTransitionData(r,e,s,o);if(i&&!a.length)return"xstate.error.actor"!==e.type||Jt(e,r,e.actorId)?(r=Ue(t,{status:"error",error:e.error}),f([r,[]],[]),l(e),d()):d();const c=_e(a,t,s,p,!1,n,o);r=c[0],f(c,a),l(e)}if(!n.length&&!1===t.machine._hasEventlessTransitions)return d();let m=!0;const g=t.machine.options?.maxIterations??1/0;let y=0,v=0;for(;"active"===r.status;){if(v++,v>1e3)throw new Error("Microstep count exceeded 1000");if(y++,y>g)throw new Error(`Infinite loop detected (>${g} microsteps)`);let t,e=m?Te(r,p,s):[];const i=e.length?r:void 0;if(!e.length){if(!n.length)break;p=n.shift(),t=new Map,e=r.machine.getTransitionData(r,p,s,t)}const o=_e(e,r,s,p,!1,n,t);r=o[0],m=r!==i,f(o,e),l(p)}return d()}function Se(t,e,s,n,i){return!!t.to&&$e(t.to,e,s,n,i,n.machine.sources,t.source.id).enabled}const Ae=()=>{throw fs};let Ee;function $e(t,e,s,n,i,r,o){let a;const c=O(i);c&&ps.push(c);try{a=t(D({context:e,event:s,output:ss(s),value:n.value,children:n.children,actions:r.actions,actors:r.actors,guards:r.guards,delays:r.delays,input:Vt(n,o)},i),Ee??=pt({emit:Ae,cancel:Ae,log:Ae,raise:Ae,spawn:Ae,sendTo:Ae,stop:Ae,listen:Ae,subscribeTo:Ae},Ae))}catch(t){if(t===fs)return{enabled:!0,result:void 0,reusable:!1};throw t}finally{c&&ps.pop()}return{enabled:void 0!==a,result:a,reusable:!0}}function ke(t,e,s){let n;if(!t.children||0===(n=Object.values(t.children).filter(Boolean)).length)return[t,[]];const i=[],r=ot(s,i,[]);for(const t of n)r.stop(t);return ft(t,e,s,i)}function Ie(t,e,s){const n=Object.keys(t.timers);if(!n.length)return[t,[]];const i=[],r=ot(s,i,[]);for(const t of n)r.cancel(t);return ft(t,e,s,i)}function Te(t,e,s){const n=new Set,i=t.nodes.filter(zt);for(const r of i)t:for(let i=r;i;i=i.parent)if(i.always)for(const r of i.always)if(Ce(r,e,t,i,s)){n.add(r);break t}return pe(Array.from(n),new Set(t.nodes),t,me(t,e,s,!1))}function Ce(t,e,s,n,i,r){if(t.matches&&!function(t,e){return Object.entries(e).every(([e,s])=>Object.is(t[e],s))}(e,t.matches))return!1;if(t._eventMatcher&&!t._eventMatcher(e,s))return!1;if(t.guard){const r=function(t,e){if(!j(e)){const s=e.self;return Object.assign(t,{self:s,parent:s._parent})}return Object.defineProperties(t,{self:{enumerable:!0,get:()=>e.self},parent:{enumerable:!0,get:()=>O(e)}}),t}({context:s.context,event:e,output:ss(e),children:s.children,actions:n.machine.sources.actions,actors:n.machine.sources.actors,guards:n.machine.sources.guards,delays:n.machine.sources.delays,_snapshot:s},i);if(!t.guard(r))return!1}if(t.to){const o=$e(t.to,s.context,e,s,i,n.machine.sources,t.source.id);return r?.set(t,o),o.enabled}return!0}const Re={unsubscribe(){}},Me="or restore this snapshot with embedded children on the runtime that owns them.";function Ne(t){return!0===t._remote}const je=Object.freeze({status:"active",output:void 0,error:void 0});function Oe(t,e){const s={_remote:!0,ref:void 0,id:e.id,address:e.address,src:e.src,registryKey:e.registryKey,sessionId:e.incarnation,system:t,_parent:e.parent,_syncSnapshot:e.syncSnapshot,send(e){t.sendEvent(void 0,n,e)},_send(t){throw new Error(`Remote actor '${e.address}' has no local mailbox to receive "${t.type}". Its state lives with another runtime; install a runtime that can reach it (via \`createDurable\`'s adapter runtime operations, or \`system.runtime\`) before sending, ${Me}`)},getSnapshot:()=>je,getPersistedSnapshot(){throw new Error(`Cannot persist remote actor '${e.address}' from here: its state lives with the runtime that owns it. Persist it there, ${Me}`)},start(){},_stop(){},stop(){throw new Error(`Cannot stop remote actor '${e.address}' directly: stopping is a co-located operation. Stop it through the system runtime that owns it (\`system.stopActor(ref)\`), ${Me}`)},select(){throw new Error(`Cannot select from remote actor '${e.address}': its snapshot is not synchronously readable because its state lives with another runtime. Read it on the runtime that owns it, ${Me}`)},get trigger(){throw new Error(`Remote actor '${e.address}' has no \`trigger\` shorthand: it requires a co-located actor. Use \`send(...)\`, which routes through the system runtime.`)},subscribe:()=>Re,on:()=>Re,_isRunning:()=>!1,toJSON:()=>({xstate$type:Es,id:e.id,address:e.address,src:e.src})},n=s;return s.ref=n,n}const De=Object.freeze({});function Pe(t){return t===De||t&&Object.keys(t).length?t:De}function He(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Le=function(t){return Je(t,this.value)},We=function(t){return this.tags.has(t)},Ve=function(t){return this.machine?._canTransition(this,t)??!1},ze=function(){const{nodes:t,_stateInputs:e,tags:s,machine:n,getMeta:i,getInputs:r,toJSON:o,can:a,hasTag:c,matches:h,...l}=this;return{...l,tags:Array.from(s)}},Xe=function(){const t={};for(const e of this.nodes)void 0!==e.meta&&(t[e.id]=e.meta);return t},Ke=function(){return this._stateInputs};function Be(t){const e=new Set;for(const s of t)for(const t of s.tags)e.add(t);return e}function qe(t,e,s){const n={status:t.status,output:t.output,error:t.error,machine:e,context:t.context,nodes:t._nodes,value:t.value??qt(e.root,t._nodes),tags:Be(t._nodes),children:Pe(t.children),timers:Pe(t.timers),historyValue:Pe(t.historyValue),_stateInputs:Pe(t._stateInputs),_nextTimerId:t._nextTimerId??0,_nextActorIds:t._nextActorIds,matches:Le,hasTag:We,can:Ve,getMeta:Xe,getInputs:Ke,toJSON:ze};return s&&Tt(n,s),n}function Ue(t,e={}){const s={...t,...e};if((e._nodes??t.nodes)===t.nodes){const e={status:s.status,output:s.output,error:s.error,machine:t.machine,context:s.context,nodes:t.nodes,value:t.value,tags:t.tags,children:Pe(s.children),timers:Pe(s.timers),historyValue:Pe(s.historyValue),_stateInputs:Pe(s._stateInputs),_nextTimerId:s._nextTimerId??0,_nextActorIds:s._nextActorIds,matches:Le,hasTag:We,can:Ve,getMeta:Xe,getInputs:Ke,toJSON:ze};return It(t,e),e}const n=qe({...s,value:void 0},t.machine);return It(t,n),n}function Fe(t){const e={};for(const s in t){const n=t[s];Array.isArray(n)&&(e[s]=n.map(t=>({id:t.id})))}return e}function Ze(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:Es,id:n.id};else{const i=Ze(n);i!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=i)}}return e??t}function Je(t,e){const s=Ge(t),n=Ge(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every(t=>t in n&&Je(s[t],n[t]))}function Qe(t){if(ns(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 Ge(t){if(He(t))return t.value;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}(Qe(t))}function Ye(t){return ns(t)?t:[t]}function ts(t){return void 0===t?[]:Ye(t)}function es(t,e,s,n,i){if("function"==typeof t){return t({context:e,event:s,output:ss(s),self:n,input:i})}return t}function ss(t){if(function(t){return"xstate.done.actor"===t.type||"xstate.done.state"===t.type}(t)){return t.output}}function ns(t){return Array.isArray(t)}function is(t){return Ye(t).map(t=>void 0===t||"string"==typeof t?{target:t}:"function"==typeof t?{to:t}:t)}function rs(t){if(void 0!==t&&""!==t)return ts(t)}function os(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function as(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.sources.actors[e];const[,n,i]=s,r=t.getStateNodeById(i).config.invoke,o=(Array.isArray(r)?r[n]:r).src;return"string"==typeof o?t.sources.actors[o]:o}function cs(t,e){if(e===t)return!0;if("*"===e)return!0;if(!e.endsWith(".*"))return!1;const s=e.split("."),n=t.split(".");for(let t=0;t<s.length;t++){const e=s[t],i=n[t];if("*"===e){return t===s.length-1}if(e!==i)return!1}return!0}async function hs(t,e,s,n=e=>{t.system.sendEvent(t,t,e)}){const i=function(t,e){return t.getSnapshot().effects?.[e]}(t,e);if("done"===i?.status)return i.output;if("error"===i?.status)throw i.error;if("active"===i?.status)return function(t,e){return new Promise((s,n)=>{const i=t.subscribe(t=>{const r=t.effects?.[e];"done"===r?.status?(i.unsubscribe(),s(r.output)):"error"===r?.status&&(i.unsubscribe(),n(r.error))})})}(t,e);n({type:"xstate.logic.effect.start",key:e});try{const t=await s();return n({type:"xstate.logic.effect.resolve",key:e,output:t}),t}catch(t){throw n({type:"xstate.logic.effect.reject",key:e,error:t}),t}}function ls(t,e,s){const n=e;if(t!==e&&n.logic?.isInternalEventType?.(s.type))throw new Error(`Internal event "${s.type}" cannot be sent to actor "${e.id}" from outside.`)}let us,ds=0;const fs=new Error("Transition effect"),ps=[];function ms(){return us??=function(){let t;try{t=globalThis.crypto}catch{}if(t?.getRandomValues)try{const e=new Uint32Array(4);return t.getRandomValues(e),Array.from(e,t=>t.toString(36).padStart(7,"0")).join("")}catch{}if(t?.randomUUID)try{return t.randomUUID().replaceAll("-","")}catch{}return`xstate-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}(),`${us}:${(ds++).toString(36)}`}function gs(t){if("string"==typeof t)return t;const e=t?.id;return"string"==typeof e&&e.length&&"(machine)"!==e?e:"x"}function ys(t){return t.includes("/")||t.includes("%")?t.replaceAll("%","%25").replaceAll("/","%2F"):t}function vs(t){const e=t.lastIndexOf(":");if(e<=0||e===t.length-1)return;const s=Number(t.slice(e+1));return Number.isSafeInteger(s)&&s>=0?{prefix:t.slice(0,e),index:s}:void 0}function xs(t,e){return`${t?t.address:""}|${e}`}function _s(t,e,s){const n=t._snapshot._nextActorIds;(n[e]??0)>=s||(t._snapshot._nextActorIds={...n,[e]:s},At(t))}const bs=Object.freeze({});function ws(t,e){return`${t.sessionId}.${e}`}class Ss{get children(){const t=this._children??=new Map;return this._getRootActor()&&t.set(this._rootActor.sessionId,this._rootActor),t}set children(t){this._children=t}_getRootActor(){return this._rootActor._isRunning()?this._rootActor:void 0}_peekChildren(){return this._children}get keyedActors(){return this._keyedActors??=new Map}set keyedActors(t){this._keyedActors=t}get reverseKeyedActors(){return this._reverseKeyedActors??=new WeakMap}set reverseKeyedActors(t){this._reverseKeyedActors=t}_peekKeyedActors(){return this._keyedActors}constructor(t,e){this._rootActor=t,this._identity={systemId:ms(),nextSessionId:0},this._snapshot=void 0,this._snapshotVersion=0,this.scheduler=this,this._clock=void 0,this._logger=void 0,this.createActorRef=void 0;const s="object"==typeof e.snapshot&&null!==e.snapshot?e.snapshot:void 0;this._clock=e.clock,this._logger=e.logger,this.createActorRef=e.createActorRef;const n=void 0;this._snapshot={_scheduledTimers:s?.scheduler??bs,_nextActorIds:{}}}_recordSent(t,e,s,n,i){if(!this._inspectionObservers?.size||!t)return;const r=t;(r._collectedSent??=[]).push({targetRef:e,targetId:e.id,event:s,delay:n,id:i})}schedule(t,e,s){const n=ws(t,e);void 0!==this._timerMap?.[n]&&this.cancel(t,e);const i=t.getSnapshot()?.timers?.[e];if(i){const n="self"===i.target?t:i.target;this._recordSent(t,n,i.event,s,e)}const r=this._clock.now?.()??Date.now(),o={source:t,delay:s,id:e,scheduledAt:r,dueAt:r+s},a=ws(t,e);this._snapshot._scheduledTimers===bs&&(this._snapshot._scheduledTimers={}),this._snapshot._scheduledTimers[a]=o,At(this);const c=this._clock.setTimeout(()=>{this._timerMap&&delete this._timerMap[a],delete this._snapshot._scheduledTimers[a],At(this),this._deliver(t,t,{type:u,id:e})},s);(this._timerMap??={})[a]=c}cancel(t,e){const s=ws(t,e),n=this._timerMap?.[s];this._timerMap&&delete this._timerMap[s],this._snapshot._scheduledTimers!==bs&&delete this._snapshot._scheduledTimers[s],At(this),void 0!==n&&this._clock.clearTimeout(n)}cancelAll(t){for(const e in this._snapshot._scheduledTimers){const s=this._snapshot._scheduledTimers[e];s.source===t&&this.cancel(t,s.id)}}_deliver(t,e,s){!function(t,e,s){ls(t,e,s);const n=e;n._lastSourceRef=t,n._send(s)}(t,e,s)}_register(t,e){return e===this._rootActor?this._children?.set(t,e):(this._children??=new Map).set(t,e),At(this),t}_unregister(t){let e;t===this._rootActor?(e=void 0!==this._getRootActor(),e=void 0!==t.sessionId&&(this._children?.delete(t.sessionId)??!1)||e):e=void 0!==t.sessionId&&(this._children?.delete(t.sessionId)??!1);const s=this._reverseKeyedActors?.get(t);void 0!==s&&(this._keyedActors?.get(s)===t&&(this._keyedActors.delete(s),e=!0),this._reverseKeyedActors?.delete(t)),e&&At(this)}get(t){return this._keyedActors?.get(t)}getAll(){return Object.fromEntries(this._keyedActors?.entries()??[])}_set(t,e){const s=this._keyedActors?.get(t);if(s&&s!==e)throw new Error(`Actor with registry key '${t}' already exists.`);(this._keyedActors??=new Map).set(t,e),(this._reverseKeyedActors??=new WeakMap).set(e,t),s!==e&&At(this)}inspect(t){const e=os(t);return(this._inspectionObservers??=new Set).add(e),{unsubscribe:()=>{this._inspectionObservers?.delete(e)}}}_hasInspectionObservers(){return!!this._inspectionObservers?.size}_sendInspectionEvent(t){if(!this._inspectionObservers?.size)return;const e={...t,rootId:this._rootActor.sessionId};this._inspectionObservers.forEach(t=>t.next?.(e))}spawnActor(t,e){return this.runtime?.spawnActor?.(t,e)}startActor(t){const e=this.runtime?.startActor;if(e)return e(t);t.start()}stopActor(t){const e=this.runtime?.stopActor;if(e)return e(t);!function(t){t._stop()}(t)}terminateActor(t,e){const s=this.runtime?.terminateActor;if(s)return s(t,e);!function(t,e){t._terminate(e)}(t,e)}sendEvent(t,e,s){ls(t,e,s),this._recordSent(t,e,s);const n=this.runtime?.sendEvent;if(n)return n(t,e,s);this._deliver(t,e,s)}emitEvent(t,e){const s=this.runtime?.emitEvent;if(s)return s(t,e);t._emit(e)}deadLetter(t,e,s,n){this._sendInspectionEvent({type:"@xstate.deadletter",actorRef:e,sourceRef:t,event:s,reason:n});const i=this.runtime?.deadLetter;if(i)return i(t,e,s,n)}runStep(t,e,s){const n=this.runtime?.runStep;return n?n(t,e,s):hs(t,e,s)}runLogic(t,e){const s=this.runtime?.runLogic;return s?s(t,e):e()}scheduleTimer(t,e,s){const n=this.runtime?.scheduleTimer;if(n){const i=t.getSnapshot()?.timers?.[e];if(i){const n="self"===i.target?t:i.target;this._recordSent(t,n,i.event,s,e)}return n(t,e,s)}this.schedule(t,e,s)}cancelTimer(t,e){const s=this.runtime?.cancelTimer;if(s)return s(t,e);this.cancel(t,e)}cancelAllTimers(t){const e=this.runtime?.cancelAllTimers;if(e)return e(t);this.cancelAll(t)}_relay(t,e,s){if(ps.length&&ps.includes(e))throw fs;return this.sendEvent(t,e,s)}getSnapshot(){return{_scheduledTimers:{...this._snapshot._scheduledTimers}}}start(){const t=this._snapshot._scheduledTimers;let e=!0;for(const s in t){e&&(this._snapshot._scheduledTimers={},e=!1);const{source:n,dueAt:i,id:r}=t[s];this.scheduleTimer(n,r,Math.max(0,i-(this._clock.now?.()??Date.now())))}}}let As=!1;const Es="actorRef",$s=Object.freeze([]);let ks=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const Is=Object.freeze({clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console)});function Ts(t,e){try{t?.(e)}catch(t){_(t)}}function Cs(t,e){if(t?.length)for(const s of t)e.actionExecutor(s)}function Rs(t,e){return new Ms(t,e)}class Ms{get address(){return this._address??=this._parent?`${this._parent.address}/${ys(this.id)}`:ys(this.id)}get trigger(){return this._trigger??=new Proxy({},{get:(t,e)=>t=>{this.send({...t,type:e})}})}get send(){return this._boundSend??=this._sendPublic.bind(this)}constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this._boundProcess=void 0,this.mailbox=void 0,this._mailboxStarted=!1,this.observers=void 0,this.eventListeners=void 0,this.logger=void 0,this._processingStatus=ks.NotStarted,this._forceDeferredActions=!1,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._lastSourceRef=void 0,this._collectedMicrosteps=void 0,this._collectedActions=void 0,this._collectedSent=void 0,this._initialEffects=void 0,this.registryKey=void 0,this.sessionId=void 0,this._address=void 0,this.system=void 0,this._trigger=void 0,this._boundSend=void 0,this.src=void 0,this._deferred=void 0,this._restored=!1;const s=e?{...Is,...e}:Is,{clock:n,logger:i,parent:r,syncSnapshot:o,id:a,registryKey:c,inspect:h}=s;var l;this.system=r?r.system:s._systemRef?.current??function(t,e){return new Ss(t,e)}(this,{clock:n,logger:i,snapshot:s.snapshot??s.state,createActorRef:Rs}),r||!s._systemRef||s._systemRef.current||(s._systemRef.current=this.system),h&&!r&&this.system.inspect(os(h)),this.sessionId=s._sessionId??`${(l=this.system)._identity.systemId}:${l._identity.nextSessionId++}`,this.id=function(t,e,s){if(void 0!==e){const n=vs(e);return n?_s(t,xs(s?.parent,n.prefix),n.index+1):s?.parent||_s(t,xs(void 0,e),1),e}const n=gs(s?.src),i=xs(s?.parent,n),r=t._snapshot._nextActorIds[i]??0;return _s(t,i,r+1),s?.parent||"x"===n||0!==r?`${n}:${r}`:n}(this.system,a,{parent:r,src:s.src??t}),this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=r,this._syncSnapshot=o,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope=this,c&&(this.registryKey=c,this.system._set(c,this)),this._collectedMicrosteps=void 0;const u=e?.snapshot??e?.state;this._restored=void 0!==u;try{if(u)this._setSnapshot(this.logic.restoreSnapshot?this.logic.restoreSnapshot(u,this._actorScope):u);else if(e?._inert);else{const[t,e]=ut(this._actorScope,void 0,this.logic.initialTransition(this.options?.input,this._actorScope));this._setSnapshot(t),this._initialEffects=e.length?e:void 0}}catch(t){this._setSnapshot({status:"error",output:void 0,error:t}),this._deferred&&(this._deferred.length=0)}c&&"active"!==this._snapshot.status&&this.system._unregister(this),(this.system._hasInspectionObservers?.()??1)&&this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this,parentRef:this._parent,id:this.id,src:this.src,snapshot:this._snapshot})}_getLogger(){return this.logger}get self(){return this}get defer(){const t=t=>this._defer(t);return Object.defineProperty(this,"defer",{value:t}),t}get stopChild(){const t=t=>this._stopChild(t);return Object.defineProperty(this,"stopChild",{value:t}),t}get emit(){const t=t=>this.system.emitEvent(this,t);return Object.defineProperty(this,"emit",{value:t}),t}get actionExecutor(){const t=t=>this._executeAction(t);return Object.defineProperty(this,"actionExecutor",{value:t}),t}_isRunning(){return this._processingStatus===ks.Running}_defer(t){(this._deferred??=[]).push(t)}_stopChild(t){if(t._parent!==this)throw new Error(`Cannot stop non-child actor ${t.id}`);t._stop()}_executeAction(t){const e=()=>{(this.system._hasInspectionObservers?.()??1)&&(this._collectedActions??=[]).push({type:t.type,params:t.params});const e=As;try{As=!0,t.exec()}finally{As=e}};this._processingStatus!==ks.Running||this._forceDeferredActions?(this._deferred??=[]).push(e):e()}_setSnapshot(t){const e=this._snapshot;this._snapshot=t,Tt(t,this,this.system,e)}_setErrorSnapshot(t,e=this._snapshot){this._setSnapshot({...e,status:"error",error:t})}_recoverOrError(t,e){return!!this._tryHandleExecutionError(t,e)||(this._setErrorSnapshot(t),this._error(t),!1)}_tryHandleExecutionError(t,e=this._snapshot){const s=this.logic.getExecutionErrorEvent?.(e,t);if(!s)return!1;try{const[t,n]=ut(this._actorScope,e,this.logic.transition(e,s,this._actorScope));return this._setSnapshot(t),Cs(n,this._actorScope),this.update(t,s),!0}catch{return!1}}_next(t){for(const e of this.observers??$s)Ts(e.next,t)}update(t,e){this._setSnapshot(t);const s=this._deferred;for(let e=0;e<(s?.length??0);e++){const n=s[e];try{n()}catch(e){if(s.length=0,this._tryHandleExecutionError(e,t))return;this._setErrorSnapshot(e,t),this._error(e);break}}if(s&&(s.length=0),"active"===this._snapshot.status)this._next(t);this._inspectTransition(this._snapshot,e)}_inspectTransition(t,e){(this.system._hasInspectionObservers?.()??1)&&this.system._sendInspectionEvent({type:"@xstate.transition",actorRef:this,event:e,sourceRef:this._lastSourceRef,targetRef:this,snapshot:t,microsteps:this._collectedMicrosteps??$s,actions:this._collectedActions??$s,sent:this._collectedSent??$s,eventType:e.type}),this._collectedMicrosteps=void 0,this._collectedActions=void 0,this._collectedSent=void 0}_flushInitialEffects(){if(!this._initialEffects?.length)return!0;this._forceDeferredActions=!0;try{return Cs(this._initialEffects,this._actorScope),this._initialEffects=void 0,!0}catch(t){return this._initialEffects=void 0,this._deferred&&(this._deferred.length=0),this._recoverOrError(t),"active"===this._snapshot.status}finally{this._forceDeferredActions=!1}}subscribe(t,e,s){const n=os(t,e,s);if(this._processingStatus!==ks.Stopped)(this.observers??=new Set).add(n);else switch(this._snapshot.status){case"done":Ts(n.complete);break;case"error":{const t=this._snapshot.error;n.error?Ts(n.error,t):_(t);break}}return{unsubscribe:()=>{this.observers?.delete(n)}}}on(t,e){let s=this.eventListeners?.get(t);return s||(s=new Set,(this.eventListeners??=new Map).set(t,s)),s.add(e),{unsubscribe:()=>{s.delete(e)}}}select(t,e=Object.is){return{subscribe:(s,n,i)=>{const r=os(s,n,i);let o=t(this.getSnapshot());return this.subscribe({next:s=>{const n=t(s);e(o,n)||(o=n,r.next?.(n))},error:r.error,complete:r.complete})},get:()=>t(this.getSnapshot())}}start(){if(this._processingStatus===ks.Running)return this;if(this._processingStatus===ks.Stopped)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:"xstate.snapshot.actor",actorId:this.id,sessionId:this.sessionId,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this.registryKey&&this.system._set(this.registryKey,this),this._processingStatus=ks.Running,this._lastSourceRef=this._parent;switch(this._snapshot.status){case"done":return this._restored?(this._next(this._snapshot),this._stopProcedure(),this._complete(),this):this._flushInitialEffects()?(this.update(this._snapshot,x(this.options.input)),this):this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),!this._flushInitialEffects())return this;if(this.logic.start)try{this.logic.start(this._snapshot,this._actorScope,{restored:this._restored})}catch(t){return this._setErrorSnapshot(t),this._error(t),this}if(this._restored||this._deferred?.length||this.observers?.size||(this.system._hasInspectionObservers?.()??1)?this.update(this._snapshot,x(this.options.input)):(function(t,e,s){const n=_t.get(t),i=Et(s);return n?.actor===e&&n.systemState.sourceSystem===s&&n.systemState.sourceVersion+1===i&&s._getRootActor?.()===e&&!s._peekChildren?.()&&(n.systemState.root=e,n.systemState.sourceVersion=i,!0)}(this._snapshot,this,this.system)||this._setSnapshot(this._snapshot),this._collectedMicrosteps=void 0,this._collectedActions=void 0,this._collectedSent=void 0),this._restored){const t=this._snapshot.timers??{},e=!this.system._clock.now,s=Date.now();for(const n of Object.values(t)){const t=e&&void 0!==n.startedAt?Math.min(n.delay,Math.max(0,n.startedAt+n.delay-s)):n.delay;this.system.scheduleTimer(this,n.id,t)}this._restored=!1}return this._mailboxStarted=!0,this.mailbox?.start(),this}_process(t){let e,s;try{e=ut(this._actorScope,this._snapshot,this.logic.transition(this._snapshot,t,this._actorScope))}catch(t){s={err:t}}if(s)return this._collectedMicrosteps=void 0,this._collectedActions=void 0,this._collectedSent=void 0,void(this._recoverOrError(s.err)||this._inspectTransition(this._snapshot,t));if(!e)return;let n=this._snapshot;try{const[s,i]=e;n=s,this._setSnapshot(n),Cs(i,this._actorScope),this.update(n,t)}catch(e){return void(this._recoverOrError(e,n)||this._inspectTransition(this._snapshot,t))}t.type===h&&(this._stopProcedure(),this._complete())}_emit(t){for(const e of[this.eventListeners?.get(t.type),this.eventListeners?.get("*")])if(e)for(const s of e)Ts(s,t)}_terminate(t){if("done"===t.status)return this._next(this._snapshot),this._stopProcedure(),this._complete(),void(this._parent&&this.system._relay(this,this._parent,(e=this.id,s=t.output,n=this.sessionId,{type:"xstate.done.actor",output:s,actorId:e,sessionId:n})));var e,s,n;"error"===t.status&&this._error(t.error)}_stop(){return this._processingStatus===ks.Stopped?this:(this.mailbox?.clear(),this._processingStatus===ks.NotStarted?(this._processingStatus=ks.Stopped,this.system._unregister(this),this):(this._send({type:h}),this.system._unregister(this),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??$s)Ts(t.complete);this.observers?.clear(),this.eventListeners?.clear()}_error(t){if(this._stopProcedure(),this.observers?.size){let e=!1;for(const s of this.observers){const n=s.error;e||=!n,Ts(n,t)}this.observers.clear(),e&&_(t)}else this._parent||_(t);var e,s,n;this.eventListeners?.clear(),this._parent&&this.system._relay(this,this._parent,(e=this.id,s=t,n=this.sessionId,{type:"xstate.error.actor",error:s,actorId:e,sessionId:n}))}_stopProcedure(){this._processingStatus===ks.Running&&(this.system.cancelAllTimers(this),this.mailbox?.clear(),this.mailbox=void 0,this._boundProcess=void 0,this._mailboxStarted=!1,this._processingStatus=ks.Stopped,this.system._unregister(this))}_send(t){if(this._processingStatus===ks.Stopped)return void this.system.deadLetter(this._lastSourceRef,this,t,"stopped");let e=this.mailbox;e||(this._boundProcess??=this._process.bind(this),e=this.mailbox=new o(this._boundProcess),this._mailboxStarted&&e.start()),e.enqueue(t)}_sendPublic(t){this.system._relay(void 0,this,t)}toJSON(){return{xstate$type:Es,id:this.id,address:this.address,src:"string"==typeof this.src?this.src:void 0}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[b](){return this}getSnapshot(){return this._snapshot}}function Ns(t,e){return new Ms(t,e)}const js=new WeakMap;const Os={};class Ds{constructor(t,e){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.schemas=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.invoke=void 0,this.on=void 0,this.after=void 0,this.events=void 0,this.ownEvents=void 0,this._candidateCache=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[];const s=this.config.states?Object.keys(this.config.states)[0]:void 0;if(this.id=this.config.id||[this.machine.id,...this.path].join("."),this.type=this.config.type||(void 0!==s?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.schemas=this.config.schemas,function(t){const e=t.config;if("history"===t.type&&!("string"==typeof e.target&&e.target.trim().length>0||Array.isArray(e.target)&&e.target.length>0&&e.target.every(t=>"string"==typeof t&&t.trim().length>0)))throw new Error(`Missing history target on "${t.id}"`);if("choice"!==t.type)return;if("function"!=typeof e.choice)throw new Error(`Missing \`choice\` function on "${t.id}"`)}(this),this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?function(t,e){const s={},n=Object.keys(t);for(let i=0;i<n.length;i++){const r=n[i];s[r]=e(t[r],r,t,i)}return s}(this.config.states,(t,e)=>new Ds(t,{_parent:this,_key:e,_machine:this.machine})):Os,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}".`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=this.config.entry,this.exit=this.config.exit,this.entry&&(this.entry._special=!0),this.exit&&(this.exit._special=!0),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=ts(t.tags).slice(),this.invoke=ts(this.config.invoke).map((t,e)=>{const{src:s,registryKey:n}=t,i=(r=this.id,`${e}.${r}`);var r;const o=t.id??i,a="string"==typeof s?s:`xstate.invoke.${i}`;return{...t,src:a,logic:s,id:o,registryKey:n}})}_initialize(){this.after=function(t){const e=t.config.after,s=t.config.timeout,n=t.config.onTimeout,i=t.invoke.filter(t=>void 0!==t.timeout);if(!e&&void 0===s&&0===i.length)return[];const r=[];if(e)for(const s of Object.keys(e)){const n=Number.isNaN(+s)?s:+s;r.push({event:d(n,t.id),timerId:f(n,t.id),delay:n,transitions:e[s],fromDelaysMap:!0})}var o;void 0!==s&&n&&r.push({event:(o=t.id,{type:"xstate.timeout",stateId:o}),timerId:p(t.id),delay:s,transitions:n,fromDelaysMap:!0});for(const t of i)r.push({event:m(t.id),timerId:g(t.id),resolveEvent:({children:e})=>m(t.id,e[t.id]?.sessionId),eventMatcher:(e,s)=>Jt(e,s,t.id),delay:t.timeout,transitions:t.onTimeout,fromDelaysMap:!1});const a=[];for(const{event:e,timerId:s,resolveEvent:n,eventMatcher:i,delay:o,transitions:c,fromDelaysMap:h}of r){Gt(t,s,n??(()=>e),e=>Wt(o,h?e.delays:{},{context:e.context,event:e.event,stateNode:t,input:e.input}));const{type:r,...l}=e;for(const t of is(c))a.push({...t,matches:{...t.matches,...Object.fromEntries(Object.entries(l).filter(([,t])=>void 0!==t))},event:r,delay:o,_eventMatcher:i})}return a.map(e=>({...Yt(t,e.event,e),delay:e.delay}))}(this),this.transitions=function(t){const e=new Map,s=(t,s)=>{e.set(t,[...e.get(t)??[],...s])};if(t.config.on)for(const s of Object.keys(t.config.on)){if(""===s)throw new Error("Null event transition key");const n=t.config.on[s];e.set(s,Ps(n,e=>Yt(t,s,e)))}if(t.config.onDone){const e="xstate.done.state";s(e,Ps(t.config.onDone,s=>Yt(t,e,{...s,matches:{...s.matches,stateId:t.id}})))}if(t.config.onError){const s="xstate.error.*";e.set(s,Ps(t.config.onError,e=>Yt(t,s,e)))}const n=(e,s,n)=>Yt(t,e,{matches:{actorId:n},_eventMatcher:(t,e)=>Jt(t,e,n),to:(t,e)=>(e.cancel(s),{})}),i=(e,s,n)=>{const{target:i,to:r,reenter:o,...a}=s;return Yt(t,e,{...a,reenter:o,to:(t,e)=>{if(r){let s=!1;const i=new Proxy(e,{apply:(t,e,n)=>(s=!0,Reflect.apply(t,e,n)),get(t,e,n){const i=Reflect.get(t,e,n);return"function"!=typeof i?i:(...e)=>(s=!0,i.apply(t,e))}}),o=r(t,i);return(void 0!==o||s)&&e.cancel(n),o}return e.cancel(n),{target:i,reenter:o}}})};for(const e of t.invoke){const r=t=>({...t,matches:{...t.matches,actorId:e.id},_eventMatcher:(t,s)=>Jt(t,s,e.id)}),o=void 0!==e.timeout?g(e.id):void 0;if(e.onDone){const a="xstate.done.actor",c=Ps(e.onDone,e=>{const s=r(e);return o?i(a,s,o):Yt(t,a,s)});o&&c.push(n(a,o,e.id)),s(a,c)}else if(o){const t="xstate.done.actor";s(t,[n(t,o,e.id)])}if(e.onError){const n="xstate.error.actor";s(n,Ps(e.onError,e=>{const s=r(e);return o?i(n,s,o):Yt(t,n,s)}))}if(e.onSnapshot){const n="xstate.snapshot.actor";s(n,Ps(e.onSnapshot,e=>Yt(t,n,r(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),"choice"===this.type?this.always=function(t){const e=t.config.choice,s=e=>{if(!e||void 0===e.target)throw new Error(`Choice "${t.id}" has no target`);return e};return[Yt(t,"",{to:t=>s(e(t))})]}(this):this.config.always&&(this.always=Ps(this.config.always,t=>Yt(this,"",t)));for(const t of Object.keys(this.states))this.states[t]._initialize();this._refreshEventMetadata()}_refreshEventMetadata(){const t={},e=[];for(const[s,n]of this.transitions)t[s]=n.slice(),n.some(t=>t.target||t.reenter||t.to)&&e.push(s);this.on=t,this.ownEvents=e;const s=new Set(e);for(const t of Object.values(this.states))for(const e of t.events)s.add(e);this.events=Array.from(s)}get initial(){return function(t,e,s){let n=js.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},js.set(t,n)),n[e]}(this,"initial",()=>function(t,e){const s="object"==typeof e&&null!==e?e.target:e,n="object"==typeof e&&null!==e?e.input:void 0,i="object"==typeof e&&null!==e?e.to:void 0,r=(Array.isArray(s)?s:s?[s]:[]).map(e=>e.startsWith("#")?t.machine.getStateNodeById(e.slice(1)):t.states[e]);if(r.some(t=>!t))throw new Error(`Initial state not found on "#${t.id}"`);return{source:t,target:r.length?r:void 0,input:n,to:i}}(this,this.config.initial))}next(t,e,s,n){const i=function(t){const e=Zt(t);return e?`${t.type}|${e}`:t.type}(e);let r=this._candidateCache?.get(i);r||(r=Qt(this,e),(this._candidateCache??=new Map).set(i,r));for(const i of r){if(Ce(i,e,t,this,s,n))return[i]}}}function Ps(t,e){const s=is(t),n=new Array(s.length);for(let t=0;t<s.length;t++)n[t]=e(s[t]);return n}function Hs(t,e){const s=t.check(e);if(s)throw s}function Ls(t,e){if(!t)return;if(Object.hasOwn(t,e))return t[e];const s=Object.keys(t).find(t=>cs(e,t));return void 0===s?void 0:t[s]}let Ws,Vs;function zs(){if(Vs)return Vs;const t=Ws??=Ns({transition:t=>[t,[]],initialTransition:()=>[{status:"active",output:void 0,error:void 0},[]],getInitialSnapshot:()=>({status:"active",output:void 0,error:void 0}),getPersistedSnapshot:t=>t});return Vs={self:t,logger:()=>{},id:"",sessionId:"",defer:()=>{},system:t.system,stopChild:()=>{},emit:()=>{},actionExecutor:()=>{}},Vs}class Xs{constructor(t,e,s){this.config=t,this.validator=s,this._internalEventType=void 0,this.version=void 0,this.schemas=void 0,this.snapshotSchema=void 0,this.eventSchema=void 0,this.sources=void 0,this.options=void 0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.internalEventDescriptors=void 0,this._hasEventlessTransitions=void 0,this._json=void 0,this.id=t.id||"(machine)",this.sources={actors:t.actors??{},actions:t.actions??{},delays:t.delays??{},guards:t.guards??{},...e},this.version=this.config.version,this.schemas=this.config.schemas,this.snapshotSchema={"~standard":{version:1,vendor:"xstate",validate:async t=>{if(null===t||"object"!=typeof t)return{issues:[{message:"Expected a persisted snapshot."}]};const e={historyValue:{},timers:{},...t},s=this.schemas?.context;let n=e.context;if(s){const t=await s["~standard"].validate(n);if(t.issues)return{issues:[{message:`Invalid context for machine '${this.id}' version '${this.version}': ${t.issues[0]?.message}`}]};n=t.value}for(const t of["value","children"])if(!(t in e))return{issues:[{message:`Persisted snapshot is missing '${t}'.`}]};if(!["active","done","error","stopped"].includes(e.status))return{issues:[{message:"Persisted snapshot has invalid status."}]};for(const t of["children","historyValue","timers"])if(null===e[t]||"object"!=typeof e[t]||Array.isArray(e[t]))return{issues:[{message:`Persisted snapshot has invalid '${t}'.`}]};try{this.resolveState({value:e.value,context:n})}catch(t){return{issues:[{message:t instanceof Error?t.message:"Persisted snapshot has invalid state value."}]}}return{value:{...e,context:n}}}}},this.eventSchema={"~standard":{version:1,vendor:"xstate",validate:async t=>{if(null===t||"object"!=typeof t||"string"!=typeof t.type)return{issues:[{message:"Expected an event object."}]};const e=t,s=this.schemas?.events,n=this.schemas?.internalEvents,i=e.type.startsWith("xstate.")||e.type.startsWith("@xstate."),r=Ls(n,e.type)??Ls(s,e.type);if((s||n)&&!r&&!i)return{issues:[{message:`Unknown event '${e.type}' for machine '${this.id}' version '${this.version}'.`}]};if(!r)return{value:e};const{type:o,...a}=e,c=await r["~standard"].validate(a);return c.issues?c:null===c.value||"object"!=typeof c.value?{issues:[{message:"Expected an event payload."}]}:{value:{...c.value,type:o}}}}},this.internalEventDescriptors=[...Object.keys(this.schemas?.internalEvents??{}),...this.config.internalEvents??[]],this.options={maxIterations:1/0,...this.config.options},this.transition=this.transition.bind(this),this.initialTransition=this.initialTransition.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 Ds(t,{_key:this.id,_machine:this}),this.root._initialize(),function(t){const e=[],s=n=>{Object.values(n).forEach(n=>{if(n.config.route&&n.config.id){const i=n.config.id,r=n.config.route,o=({event:t})=>t.to===`#${i}`;if("function"==typeof r)return e.push(Yt(t,"xstate.route",{guard:o,to:t=>{const e=r(t);if(e)return{...!0===e?{}:e,target:`#${i}`}}})),void(n.states&&s(n.states));const{guard:a,...c}=r,h={...c,guard:o,target:`#${i}`};e.push(Yt(t,"xstate.route",h))}n.states&&s(n.states)})};s(t.states),e.length>0&&t.transitions.set("xstate.route",e)}(this.root),this.root._refreshEventMetadata(),this._hasEventlessTransitions=Array.from(this.idMap.values()).some(t=>!!t.always?.length),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:s,actors:n,delays:i}=this.sources,r=new Xs(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...i,...t.delays}},this.validator);return r._json=this._json,r}resolveState(t){const e=(s=this.root,n=t.value,qt(s,Bt(he(s,n))));var s,n;const i=Bt(he(this.root,e));return qe({_nodes:[...i],value:e,context:t.context||{},children:{},status:Ut(i,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){const n=!s,i=s??Lt(this,t);this.validator&&Hs(this.validator,{kind:"event",logic:this,event:e,eventOrigin:s&&s.self._lastSourceRef?"actor":"external"}),n&&Ct(i,t,!1),tt(i);const r=this._transitionFast(t,e,i);if(r){n&&Ct(i,r,!1);const e=n&&r!==t?Mt(i,r):this._attachPureActorRef(r,i);return this.validator&&Hs(this.validator,{kind:"result",logic:this,snapshot:e,effects:[]}),[e,[]]}const{snapshot:o,microsteps:a}=we(t,e,i,[]);n&&Ct(i,o,!1);const c=n?o===t?o:Mt(i,o):this._attachPureActorRef(o,i),h=this._collectEffects(a);return this.validator&&Hs(this.validator,{kind:"result",logic:this,snapshot:c,effects:h}),[c,h]}_collectEffects(t){return t.flatMap(([,t])=>t)}_attachPureActorRef(t,e,s=!1){return Rt(e)||s&&e.self._actorScope===e&&void 0===e.self._snapshot||Tt(t,e.self,e.system),t}_transitionFast(t,e,s){if("active"!==t.status||"string"!=typeof t.value||this.root.always?.length)return;const n=this.root.states[t.value];if(!n||"atomic"!==n.type||n.exit||n.invoke.length||n.always?.length||n.after?.length)return;const i=n.transitions.get(e.type);if(1!==i?.length)return;const r=i[0];if(r.guard||r.actions||r.to||r.reenter||r.input||"function"==typeof r.context||r.target&&1!==r.target.length)return;const o=r.target?.[0]??n,a=o!==n;if(o.parent!==this.root||"atomic"!==o.type||a&&(o.entry||o.invoke.length||o.always?.length||o.after?.length))return;const c=void 0!==r.context?{...t.context,...r.context}:t.context;if(!Rt(s)&&(s.system._hasInspectionObservers?.()??1)){const t=s.self._collectedMicrosteps||[];t.push(r),s.self._collectedMicrosteps=t}return Ue(t,{...c!==t.context?{context:c}:{},...a?{_nodes:[this.root,o]}:{}})}microstep(t,e,s){const{microsteps:n}=we(t,e,s,[]),i=new Array(n.length);for(let t=0;t<n.length;t++)i[t]=n[t][0];return i}getTransitionData(t,e,s,n){return le(this.root,t.value,t,e,s,n)||[]}isInternalEventType(t){if(t===u)return!0;for(const e of this.internalEventDescriptors)if(cs(t,e))return!0;return!1}_canTransition(t,e){const s=zs(),n=this.getTransitionData(t,e,s);if(!n?.length)return!1;for(const i of n){if(void 0!==i.target)return!0;const n=be(i,t,e,s,{resolveActions:!1});if(n.targets?.length||n.context||Se(i,t.context,e,t,s))return!0}return!1}getExecutionErrorEvent(t,e){if("active"===t?.status&&t.nodes?.some(t=>t.config.onError))return v("execution",e)}_getPreInitialState(t,e){const{context:s}=this.config,n=qe({context:"function"!=typeof s&&s?s:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof s){const i={},r=function(t,e,s){return(n,i)=>{const r=E(e,n),o=i?.id??nt(t,r??n).id;void 0!==i?.id&&(it(t,i.id),rt(t,i.id));const a=t.system.createActorRef(n,{id:o,parent:t.self,syncSnapshot:i?.syncSnapshot,input:i?.input,src:r??n,registryKey:i?.registryKey});return s[a.id]=a,a}}(t,this.sources.actors,i),o=s(function(t,e){return j(e)?(Object.defineProperty(t,"self",{enumerable:!0,get:()=>e.self}),t):Object.assign(t,{self:e.self})}({spawn:r,input:e.input,actors:this.sources.actors},t)),[a]=ft(n,e,t,[]);if(o&&(a.context=o),Object.keys(i).length>0){a.children={...a.children,...i};const e=function(t){const e=G.get(t)?.counters;if(e?.size)return Object.fromEntries(e)}(t);e&&(a._nextActorIds=Z(a._nextActorIds,e))}return a}return n}getInitialSnapshot(t,e){return this.initialTransition(e,t)[0]}initialTransition(t,e){this.validator&&Hs(this.validator,{kind:"input",logic:this,input:t});const s=!e,n=e??Lt(this);tt(n);const i=x(t),r=[],o=this._getPreInitialState(n,i),a=Object.values(o.children).filter(Boolean).map(t=>function(t){const e=[t];return{kind:"builtin",exec:L,type:c,source:t._parent,params:void 0,args:e,actor:t,id:t.id,logic:t.logic,src:t.src,input:t.options?.input}}(t)),h=(t,e)=>{s&&Ct(n,t,!1);const i=s?Mt(n,t):this._attachPureActorRef(t,n,!0),r=this._collectEffects(e);return this.validator&&Hs(this.validator,{kind:"result",logic:this,snapshot:i,effects:r}),[i,r]};try{const[t,e]=function(t,e,s,n,i){const r=[...oe(t)],o=new Set,a=t=>{if("compound"===t.type){o.add(t);for(const e of t.initial.target??[])a(e)}else if("parallel"===t.type)for(const e of Xt(t))a(e)};return a(t),_e([{target:r.filter(t=>!r.some(e=>e!==t&&ue(e,t))),source:t,reenter:!0,eventType:null,toJSON:null,_statesForDefaultEntry:[...o]}],e,s,n,!0,i)}(this.root,o,n,i,r),{snapshot:s,microsteps:c}=we(t,i,n,r,[[t,[...a,...e]]]);return h(s,c)}catch(t){if(!this.root.config.onError)throw t;const e=we(o,v("execution",t),n,[],[[o,a]]);return h(e.snapshot,e.microsteps)}}start(t){if(!t?.children)return;const e=t.children;for(const t in e){if(!Object.hasOwn(e,t))continue;const s=e[t];s._rehydrated&&"active"===s.getSnapshot?.().status&&s.start()}}getStateNodeById(t){const e=Qe(t),s=e.slice(1),n=Ft(e[0])?e[0].slice(1):e[0],i=this.idMap.get(n);if(!i)throw new Error(`Child state node '#${n}' does not exist on machine '${this.id}'`);return ce(i,s)}getPersistedSnapshot(t,e){return function(t,e){const{nodes:s,_stateInputs:n,tags:i,machine:r,children:o,timers:a,context:c,can:h,hasTag:l,matches:u,getMeta:d,getInputs:f,toJSON:p,...m}=t,g={},y={},v=!1!==e?.embedChildren;for(const t in o){const s=o[t];if(!("string"==typeof s.src||e&&"__unsafeAllowInlineActors"in e))throw new Error("An inline child actor cannot be persisted.");const n=v&&!Ne(s);if(!n&&"string"!=typeof s.src)throw new Error(`Unable to persist child '${t}' by address: it requires a registered source key.`);g[t]={address:s.address,...n?{snapshot:s.getPersistedSnapshot(e)}:{remote:!0,incarnation:Ne(s)?s.sessionId:void 0},src:s.src,registryKey:s.registryKey,syncSnapshot:s._syncSnapshot}}const x=kt(t)?.actor,_=x?.system?._clock?.now?void 0:x?.system?._snapshot?._scheduledTimers;for(const e in a){const s=a[e];let n,i=s.event;if("xstate.timeout.actor"===i.type&&(i={...i},delete i.sessionId),"self"===s.target)n="self";else{const i=Object.entries(o).find(([,t])=>t===s.target)?.[0];if(i)n=i;else{if(s.target!==kt(t)?.actor._parent)throw new Error(`Unable to persist timer '${e}': target actor '${s.target.id}' is no longer addressable from this snapshot.`);n={type:"parent"}}}const r=_?.[`${x.sessionId}.${e}`],c=r?r.dueAt-s.delay:s.startedAt;y[e]={id:s.id,delay:s.delay,type:s.type,event:i,target:n,...void 0!==c&&{startedAt:c}}}const b={...m,context:Ze(c),children:g,timers:y,historyValue:Fe(m.historyValue)};return n&&Object.keys(n).length>0&&(b.stateInputs=n),void 0!==r.version&&(b.machine={id:r.id,version:r.version},b.version=r.version),b}(t,e)}restoreSnapshot(t,e){const s=!e,n=e??Lt(this),i=t.machine,r=i&&"object"==typeof i&&"function"==typeof i.transition&&"root"in i?void 0:i,o=t.version,a="string"==typeof r?.version?r.version:o;if(void 0!==o&&void 0!==r?.version&&r.version!==o)throw new Error(`Persisted snapshot version '${o}' conflicts with machine version '${r.version}'.`);if(r&&"string"==typeof r.id&&r.id!==this.id)throw new Error(`Machine ID mismatch: persisted snapshot machine '${r.id}' does not match '${this.id}'.`);if(a!==this.version){const e=this.config.migrate;if("function"!=typeof e)throw new Error(`Persisted snapshot version '${a}' does not match machine version '${this.version}'.`);t=e(t,a)}const c=t,h={},l=c.children;for(const t of Object.keys(l)){const e=l[t];if(!0===e.remote&&void 0!==e.address){if("string"!=typeof e.src)throw new Error(`Unable to restore remote child '${t}': a child referenced by address requires a registered source key.`);const s=Oe(n.system,{id:t,address:e.address,src:e.src,parent:n.self,registryKey:e.registryKey,syncSnapshot:e.syncSnapshot,incarnation:e.incarnation});e.registryKey&&n.system._set(e.registryKey,s),h[t]=s;continue}const s=e.snapshot,i=e.src,r="string"==typeof i?as(this,i):i;if(!r){throw new Error(`Unable to restore child actor '${t}': child source '${"string"==typeof i?i:"<unknown>"}' is not provided in machine '${this.id}'.`)}const o=n.system.createActorRef(r,{id:t,parent:n.self,syncSnapshot:e.syncSnapshot,snapshot:s,src:i,registryKey:e.registryKey});o._rehydrated=!0,h[t]=o}const u={},d=c.timers??{};for(const[t,e]of Object.entries(d)){let s=e.event;if("xstate.timeout.actor"===s.type){const t=s.actorId,e=h[t];e&&(s=m(t,e.sessionId))}const i="string"==typeof e.target?"self"===e.target?"self":h[e.target]:n.self._parent;if(!i){const s="string"==typeof e.target?e.target:e.target.type;throw new Error(`Unable to restore timer '${t}': target actor '${s}' is unavailable.`)}u[t]={...e,event:s,target:i}}const f=(t=>{if(!t||"object"!=typeof t)return{};const e={};for(const s of Object.keys(t)){const n=t[s];for(const t of n){let n;if(t instanceof Ds)n=t;else try{n=this.root.machine.getStateNodeById(t.id)}catch{}n&&(e[s]??=[],e[s].push(n))}}return e})(c.historyValue),p=(t,e,s)=>{const n=t=>new Error(`Persisted snapshot references state '${t.join(".")}' which does not exist on machine '${this.id}'.`);if("string"!=typeof t){if(t&&"object"==typeof t)for(const i of Object.keys(t)){const r=e.states[i];if(!r)throw n(s.concat(i));p(t[i],r,s.concat(i))}}else if(!e.states[t])throw n(s.concat(t))};p(c.value,this.root,[]);const g=Array.from(Bt(he(this.root,c.value))),{version:y,_nextActorId:v,...x}=t;let _=x._nextActorIds;for(const t of Object.keys(l)){const e=vs(t);e&&(_?.[e.prefix]??0)<=e.index&&(_={..._,[e.prefix]:e.index+1})}const b=qe({...x,children:h,timers:u,_nextActorIds:_,_nodes:g,value:c.value,historyValue:f,_stateInputs:c.stateInputs??{}},this,n.self),w=new WeakSet;return function t(e){if(!w.has(e)){w.add(e);for(const s of Object.keys(e)){const n=e[s];if(n&&"object"==typeof n){if("xstate$type"in n&&n.xstate$type===Es){e[s]=h[n.id];continue}t(n)}}}}(b.context),s?(Ct(n,b,!1),Mt(n,b)):this._attachPureActorRef(b,n)}}function Ks(t){const e=xt(t);return void 0!==e?e:"string"==typeof t?parseFloat(t)||0:t}function Bs(t){return/^error(\.|$)/.test(t)?`xstate.${t}`:t}function qs(t){return t.startsWith("xstate.error.")?t.slice(7):t}function Us(t){return!!t&&"object"==typeof t&&"string"==typeof t["@expr"]}function Fs(t){return Us(t)||function(t){return!!t&&"object"==typeof t&&"string"==typeof t["@code"]}(t)}function Zs(t,e){return"number"==typeof e?`${t}[${e}]`:`${t}.${e}`}function Js(t){const e={};if(!t)return e;for(const s of Object.keys(t)){const n=t[s];"number"==typeof n?e[s]=n:n&&"object"==typeof n&&"number"==typeof n.duration&&(e[s]=n.duration)}return e}function Qs(t){return void 0===t?[]:Array.isArray(t)?t:[t]}function Gs(t,e){Array.isArray(t)&&t.forEach((s,n)=>{if(void 0===s.when&&n!==t.length-1)throw new Error(`Choice fallback branch at ${e}[${n}] must be last.`)})}const Ys=new Set(["_sessionid","_name","_ioprocessors","_event","_xstateScxmlInputKeys"]),tn=new WeakMap,en=new WeakMap,sn=new WeakMap,nn=new WeakMap,rn=new WeakMap;function on(t,e){let s=sn.get(t);if(!s){const n={location:`#_scxml_${e}`};s={scxml:n,"http://www.w3.org/TR/scxml/#SCXMLEventProcessor":n},sn.set(t,s)}return s}function an(t,e,s,n){const i=e.replace(/;+\s*$/,""),r=n?.sessionId??"session_scxml",o=n?en.get(n)??"(machine)":"(machine)",a=Object.fromEntries(Object.entries(t).filter(([t])=>!Ys.has(t))),c=`\n${n?tn.get(n)?.declarations.join("\n")??"":""}\nwith (context) {\n return (${i});\n}\n `.trim(),h=new Function("context","_event","_sessionid","_name","_ioprocessors","In",c),l=`#_scxml_${r}`,u=s&&s._scxmlExternal,d=s&&"@xstate.init"===s.type,f=s&&"string"==typeof s.type&&s.type.startsWith("xstate.done."),p=s&&s._scxmlEventType;let m;s&&!d&&(m=nn.get(s),m||(m={name:s._scxmlEventName??qs(s.type),type:p||(u?"external":"internal"),sendid:s._scxmlSendId,origin:u?l:void 0,origintype:u?"http://www.w3.org/TR/scxml/#SCXMLEventProcessor":void 0,invokeid:s._scxmlInvokeId??s.actorId,data:f?s.output:void 0!==s._scxmlEventData?s._scxmlEventData:s},nn.set(s,m)));return h(a,m,r,o,n?on(n,r):{scxml:{location:`#_scxml_${r}`}},t=>{if(!n)return!1;const e=t.replace(/\./g,"$");if(rn.get(n)?.some(t=>t===e||t.endsWith("."+e)))return!0;try{const t=n.getSnapshot?.();if(t?.nodes)return t.nodes.some(t=>t.id===e||t.id.endsWith("."+e))}catch{}return!1})}function cn(t,e,s,n){const i=Object.keys(t),r=i.filter(t=>!Ys.has(t)),o=r.map(t=>`var ${t} = context.${t};`).join("\n"),a=r.map(t=>`updates.${t} = ${t};`).join("\n"),c=e.replace(/\/\/.*$/gm,""),h=function(t){const e=[],s=/\bfunction\s+[$_a-zA-Z][$_a-zA-Z0-9]*\s*\([^)]*\)\s*\{/g;for(const n of t.matchAll(s)){let s=1,i=n.index+n[0].length;for(;i<t.length&&s;)"{"===t[i]&&s++,"}"===t[i]&&s--,i++;e.push(t.slice(n.index,i))}return e}(e),l=h.reduce((t,e)=>t.replace(e,""),c),u=(n?[...l.matchAll(/\bvar\s+([$_a-zA-Z][$_a-zA-Z0-9]*)/g)].map(t=>t[1]):[]).filter(t=>!i.includes(t)&&!Ys.has(t)).map(t=>`updates.${t} = ${t};`).join("\n"),d=tn.get(s)??{declarations:[]};tn.set(s,d);for(const t of h)d.declarations.includes(t)||d.declarations.push(t);const f=`\n${o}\n${d.declarations.join("\n")}\n${e}\n${a}\n${u}\nreturn updates;\n `,p=s.sessionId,m=en.get(s)??"(machine)";return new Function("context","updates","_sessionid","_name","_ioprocessors",f)(t,{},p,m,on(s,p))}function hn(t){const e=(t.children??[]).map(hn);return{tagName:t.name,getAttribute:e=>t.attributes?.[e]??null,getElementsByTagName:s=>[...t.name===s?[hn(t)]:[],...e.flatMap(t=>t.getElementsByTagName(s))]}}function ln(t,e={}){const s=function(t,e){return{actions:e.actions??{},guards:e.guards??{},actors:e.actors??{},delays:{...Js(t.delays),...e.delays??{}},evaluators:e.evaluators??{}}}(t,e),n=function(t,e){function s(s,n){const i=s["@lang"]??t;if(!i)throw new Error(`Missing @exprLang for expression at ${n}`);const r=e.evaluators[i];if(!r)throw new Error(`Missing evaluator for @lang '${i}' at ${n}`);return r}function n(t,e,n,i){const r=Us(t)?"expr":"code",o=Us(t)?t["@expr"]:t["@code"];return s(t,i)({source:o,kind:r,slot:e,scope:n,path:i})}function i(t,e,s,r){if(Fs(t))return n(t,e,s,r);if(Array.isArray(t))return t.map((t,n)=>i(t,e,s,Zs(r,n)));if(!t||"object"!=typeof t)return t;const o={};for(const n of Object.keys(t))o[n]=i(t[n],e,s,Zs(r,n));return o}function r(t,e){return{context:t.context,event:t.event,input:t.input,self:t.self,children:t.children,params:t.params,...e}}return{evaluateResolvable:n,resolveValue:i,makeScope:r,getDurationConfig:function(t,e){return Fs(t)?s=>Ks(i(t,"delay",r(s),e)):t},assertResolvable:function t(e,n){if(Fs(e))s(e,n);else if(Array.isArray(e))e.forEach((e,s)=>t(e,Zs(n,s)));else if(e&&"object"==typeof e)for(const s of Object.keys(e))t(e[s],Zs(n,s))}}}(t["@exprLang"],s),{evaluateResolvable:i,resolveValue:r,makeScope:o,getDurationConfig:a}=n,c=new WeakMap;function h(e,s,n){if(e)return Fs(e)?t=>!!i(e,s,o(t),n):i=>{const a=r(e.params,s,o(i),`${n}.params`),c=t.guards?.[e.type];if(c){const t=h(c.when,"guard",`$.guards.${e.type}.when`);return!!t?.({...i,params:a})}const l=i.guards?.[e.type];if(!l)throw new Error((u=e.type,d=i.guards??{},`Guard '${u}' is not implemented in machine '${t.id??"(machine)"}'. Available guards: ${Object.keys(d).map(t=>`'${t}'`).join(", ")||"(none)"}.`));var u,d;return l(i,a)}}function l(t,e){if(t)return Fs(t)?s=>i(t,"choice",o(s),e):(Gs(t,e),s=>{for(let n=0;n<t.length;n++){const i=t[n],a=h(i.when,"choice",`${e}[${n}].when`);if(!a||a(s))return{target:i.target,context:i.context?r(i.context,"transitionContext",o(s),`${e}[${n}].context`):void 0,input:void 0!==i.input?r(i.input,"input",o(s),`${e}[${n}].input`):void 0,description:i.description,reenter:i.reenter,meta:i.meta}}throw new Error(`Choice state at ${e} did not match any branch.`)})}const u={},d=[];let f=null,p=null;const m=[],g=new WeakMap;function y(t,e){if(!t||"function"==typeof t)return t;if(Fs(t))return s=>i(t,"transition",o(s),e);const{guard:s,...n}=t;if(!s)return n;const r=h({type:s},"guard",e);return t=>r(t)?n:void 0}function v(t){return({self:e})=>g.get(e)?.get(t)}function x(t){return(Array.isArray(t)?t:[t]).map(t=>{const e=t;let n;return n=e._nestedScxmlIR?ln(e._nestedScxmlIR,s):s.actors[t.src]??t.src,{src:n,id:t.id,registryKey:t.registryKey,input:t._scxmlInput?({context:e,event:s,self:n})=>{const i={};for(const s of t._scxmlInput.namelist??[]){if(!(s in e))throw new ReferenceError(`${s} is not defined`);i[s]=e[s]}for(const r of t._scxmlInput.params??[])i[r.name]=r.expr?an(e,r.expr,s,n):r.location?an(e,r.location,s,n):void 0;return i}:void 0!==t.input?e=>r(t.input,"input",o(e),"$.invoke.input"):void 0,onDone:t.onDone?A(t.onDone):void 0,onError:t.onError?A(t.onError):void 0,onSnapshot:t.onSnapshot?A(t.onSnapshot):void 0,timeout:a(t.timeout,"$.invoke.timeout"),onTimeout:t.onTimeout?A(t.onTimeout):void 0}})}function _(t,e,s,n){const i=s instanceof Error?s.message:"string"==typeof s?s:"unknown error",r={type:"xstate.error.execution",error:{tagname:e,message:i,line:0,column:0,reason:i},_scxmlEventType:"platform",_scxmlEventName:"error.execution",...n?{_scxmlSendId:n}:{},_scxmlEventData:{tagname:e,message:i,line:0,column:0,reason:i}};t.enq.raise(r),t.errored=!0}function b(e,s,n,i,r,o){const a=t.actions?.[e.type];if(!a)return n(s.actions[e.type],i),{context:void 0,errored:r.errored};if(o.includes(e.type))return _(r,"action",new Error(`Circular action reference: ${o.concat(e.type).join(" -> ")}`)),{context:void 0,errored:!0};return w(Array.isArray(a)?a:[a],{...s,params:i},n,r,o.concat(e.type))}function w(t,e,s,n,a=[]){const h=n??{enq:s,self:e.self,errored:!1};let l;for(const n of t){if(h.errored)break;if(Fs(n)){const t=i(n,"action",o(e,{params:e.params,enq:s}),"$.actions");t&&"object"==typeof t&&"context"in t&&t.context&&(l??={},Object.assign(l,t.context))}else if(un(n))switch(n.type){case"@xstate.raise":{const t=void 0!==n.delay,i=r(n.event,"actionParams",o(e,{params:e.params}),"$.actions.event"),a=t||void 0!==n.id?{...i,...t?{_scxmlExternal:!0}:{},...void 0!==n.id?{_scxmlSendId:n.id}:{}}:i;s.raise(a,{id:n.id,delay:n.delay});break}case"@xstate.cancel":s.cancel(n.id);break;case"@xstate.log":s.log(...n.args);break;case"@xstate.emit":s.emit(r(n.event,"actionParams",o(e,{params:e.params}),"$.actions.event"));break;case"@xstate.assign":l??={},Object.assign(l,r(n.context,"transitionContext",o(e,{params:e.params}),"$.actions.context"));break;default:throw new Error(`Unknown built-in action: ${n.type}`)}else if("scxml.finalize"===n.type){const t=n;if((e.event._scxmlInvokeId??e.event.actorId)===t.invokeId){const n=w(t.actions,{...e,context:{...e.context,...l}},s,h);n.context&&(l=n.context)}}else if("scxml.forward"===n.type){const t=e.children?.[n.invokeId];t&&s.sendTo(t,{...e.event,_scxmlExternal:!0})}else if("scxml.log"===n.type){const t=n;try{const n=t.expr?an({...e.context,...l},t.expr,e.event,e.self):void 0;s.log(...t.label?[t.label,n]:[n])}catch(t){_(h,"log",t)}}else if("scxml.assign"===n.type){const t=n,s={...e.context,...l};let i;try{i=an(s,t.expr,e.event,e.self)}catch(t){_(h,"assign",t);continue}if(Ys.has(t.location.split(".")[0])){_(h,"assign",new Error(`Cannot assign to SCXML system variable: ${t.location}`));continue}if(t.location.includes(".")){const e=t.location.split("."),n=e.shift();let r=s[n];if(!r||"object"!=typeof r){_(h,"assign",new Error(`Invalid assign location: ${t.location}`));continue}const o=Array.isArray(r)?[...r]:{...r};r=o;for(const s of e.slice(0,-1)){const e=r[s];if(!e||"object"!=typeof e){_(h,"assign",new Error(`Invalid assign location: ${t.location}`));break}const n=Array.isArray(e)?[...e]:{...e};r[s]=n,r=n}if(h.errored)continue;r[e.at(-1)]=i,l??={},l[n]=o;continue}l??={},l[t.location]=i}else if("scxml.datamodel"===n.type){const t=n;l??={};for(const s of t.data)if(!Array.isArray(e.context._xstateScxmlInputKeys)||!e.context._xstateScxmlInputKeys.includes(s.id)){if(s.src){_(h,"data",new Error(`Unresolved data resource: ${s.src}`));break}if(void 0!==s.expr)try{l[s.id]=an({...e.context,...l},s.expr,e.event,e.self)}catch(t){_(h,"data",t);break}else if(void 0!==s.content)try{l[s.id]=an({...e.context,...l},s.content,e.event,e.self)}catch{l[s.id]=s.content.replace(/\s+/g," ").trim()}else s.xml?l[s.id]=hn(s.xml):void 0===e.context[s.id]&&(l[s.id]=void 0)}}else if("scxml.raise"===n.type){const t=n,i={...e.context,...l};let r,o,a,u;try{if(t.processorType&&!["scxml","http://www.w3.org/TR/scxml/#SCXMLEventProcessor"].includes(t.processorType))throw new Error(`Unsupported send type: ${t.processorType}`);r=t.eventexpr?an(i,t.eventexpr,e.event,e.self):t.event||"unknown",r=Bs(r),o={type:r,_scxmlEventName:qs(r)};const s={};if(t.namelist)for(const n of t.namelist)s[n]=an(i,n,e.event,e.self);if(t.params)for(const n of t.params)s[n.name]=an(i,n.expr??n.location,e.event,e.self);if(t.content){const s=t.content;let n;if(void 0!==s.expr)n=an(i,s.expr,e.event,e.self);else if(s.xml)n=hn(s.xml);else{const t=s.text?.replace(/\s+/g," ").trim()??"";try{n=an(i,t,e.event,e.self)}catch{n=t}}o._scxmlEventData=n}else Object.keys(s).length&&(Object.assign(o,s),o._scxmlEventData=s);if(t.idlocation){const s=(c.get(e.self)??0)+1;c.set(e.self,s);const n=`${e.self.sessionId}.send.${s}`;l??={},l[t.idlocation]=n,o._scxmlSendId=n}a=t.targetexpr?an(i,t.targetexpr,e.event,e.self):t.target;const n="#_internal"===a;u=t.delayexpr?Ks(an(i,t.delayexpr,e.event,e.self)):n?void 0:t.delay}catch(t){_(h,"send",t);continue}const d="#_internal"===a,f="#_parent"===a;if(d||(o._scxmlExternal=!0),f&&(o._scxmlInvokeId=e.self.id),"string"==typeof a&&a.length>0&&!a.startsWith("#_")){_(h,"send",new Error(`Invalid send target: ${a}`),o._scxmlSendId);continue}if(void 0!==t.id&&void 0===o._scxmlSendId&&(o._scxmlSendId=t.id),f&&e.parent)s.sendTo(e.parent,o,void 0!==u?{delay:u}:void 0);else if("string"!=typeof a||!a.startsWith("#_")||f||d)d?s.raise(o,{id:t.id,delay:u}):(o._scxmlExternal=!0,s.sendTo(e.self,o,{id:t.id,delay:u}));else{const n=a.slice(2),i=e.children?.[n];if(i)s.sendTo(i,o);else if(n.startsWith("scxml_")&&n!==`scxml_${e.self.sessionId}`){const t=`Unable to dispatch event to target: ${a}`;s.raise({type:"xstate.error.communication",error:{tagname:"send",message:t,line:NaN,column:NaN,reason:t},_scxmlEventType:"platform",_scxmlEventName:"error.communication",_scxmlEventData:{tagname:"send",message:t,line:NaN,column:NaN,reason:t}})}else o._scxmlExternal=!0,s.sendTo(e.self,o,{id:t.id,delay:u})}}else if("scxml.cancel"===n.type){const t=n,i={...e.context,...l};try{const n=an(i,t.sendidexpr,e.event,e.self);n&&s.cancel(n)}catch{}}else if("scxml.script"===n.type){const t=n,s={...e.context,...l};try{const n=cn(s,t.code,e.self,t.global??!1);l??={},Object.assign(l,n)}catch(t){_(h,"script",t)}}else if("scxml.foreach"===n.type){const t=n,i={...e.context,...l},r=t=>/^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(t);if(!r(t.item)||t.index&&!r(t.index)){_(h,"foreach",new Error("foreach item/index is not a legal location"));continue}let o;try{o=an(i,t.array,e.event,e.self)}catch(t){_(h,"foreach",t);continue}if(!Array.isArray(o)){_(h,"foreach",new Error("foreach array is not iterable"));continue}l??={};for(let n=0;n<o.length;n++){l[t.item]=o[n],t.index&&(l[t.index]=n);const i={...e,context:{...e.context,...l}},r=w(t.actions,i,s,h);if(r.context&&Object.assign(l,r.context),h.errored)break}}else if("scxml.block"===n.type){const t=n,i={...e,context:{...e.context,...l}},r=w(t.actions,i,s);if(r.context){l??={};for(const t of Object.keys(r.context))r.context[t]!==e.context[t]&&(l[t]=r.context[t])}}else if("scxml.if"===n.type){const t=n,i={...e.context,...l};for(const n of t.branches){let t;if(n.cond)try{t=!!an(i,n.cond,e.event,e.self)}catch(e){_(h,"if",e),t=!1}else t=!0;if(t){if(n.actions.length){const t={...e,context:i},r=w(n.actions,t,s,h);if(r.context){l??={};for(const t of Object.keys(r.context))r.context[t]!==e.context[t]&&(l[t]=r.context[t])}}break}}}else{const t=b(n,e,s,r(n.params,"actionParams",o(e,{params:e.params}),"$.actions.params"),h,a);t.context&&(l??={},Object.assign(l,t.context))}}return{context:l?{...e.context,...l}:void 0,errored:h.errored}}function S(t,e,s,n){const i=e._scxmlInvokeId??e.actorId,r={...t};for(const t of n??[])if(t.invokeId===i)for(const n of t.actions){if(!("type"in n)||"scxml.assign"!==n.type)continue;const t=n;r[t.location]=an(r,t.expr,e,s)}return r}function A(t){const e=Array.isArray(t)?t:[t];return e.map((t,s)=>{if(Fs(t))return(n,r)=>i(t,"transition",o(n,{enq:r}),"$.transition"+(e.length>1?`[${s}]`:""));const n=Array.isArray(t.target)?t.target[0]:t.target,a=t.target,c=h(t.guard,"guard","$.transition.guard"),l=c&&t._scxml?.finalize?.length?e=>c({...e,context:S(e.context,e.event,e.self,t._scxml.finalize)}):c,m=e=>t.context?r(t.context,"transitionContext",o(e),"$.transition.context"):void 0,g=e=>void 0!==t.input?r(t.input,"input",o(e),"$.transition.input"):void 0,y=t._scxml?.eventDescriptors?e=>t._scxml.eventDescriptors.some(t=>function(t,e){if("*"===t)return!0;if(t.endsWith(".*")){const s=t.slice(0,-2);return e.type===s||e.type.startsWith(`${s}.`)}return t.startsWith("xstate.done.actor.")?"xstate.done.actor"===e.type&&e.actorId===t.slice(18):t.startsWith("xstate.done.state.")?"xstate.done.state"===e.type&&e.stateId===t.slice(18):e.type===t||e.type.startsWith(`${t}.`)}(t,e)):void 0;return l||t.actions?.length?l&&!t.actions?.length?t.context?{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,guard:l,to:e=>({target:a,context:m(e),reenter:t.reenter}),description:t.description,meta:t.meta,input:void 0!==t.input?g:void 0}:{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,target:a,guard:l,description:t.description,reenter:t.reenter,meta:t.meta,input:void 0!==t.input?g:void 0}:n?{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,guard:l,description:t.description,reenter:t.reenter,meta:t.meta,input:void 0!==t.input?g:void 0,to:(e,s)=>{const i=m(e);if(t.actions?.length){const e=n.replace(/^#/,"");u[e]=t.actions,d.includes(t.actions)||d.push(t.actions)}return{target:a,context:i,reenter:t.reenter}}}:{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,guard:l,description:t.description,reenter:t.reenter,meta:t.meta,input:void 0!==t.input?g:void 0,to:(e,s)=>{const n=m(e);if(t.actions?.length){d.includes(t.actions)||d.push(t.actions),f??=e.context,p??=e.event;const i=w(t.actions,e,s);if(i.context)return{context:{...n,...i.context}}}return n?{context:n}:{}}}:t.context?{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,to:e=>({target:a,context:m(e),reenter:t.reenter}),description:t.description,meta:t.meta,input:void 0!==t.input?g:void 0}:{matches:t.matches,_transitionDomain:t._scxml?.type,_eventMatcher:y,target:a,description:t.description,reenter:t.reenter,meta:t.meta,input:void 0!==t.input?g:void 0}})}if(t.delays)for(const e of Object.keys(t.delays)){const n=t.delays[e];"number"==typeof n?s.delays[e]=n:"string"==typeof n?s.delays[e]=Ks(n):n&&"object"==typeof n&&(s.delays[e]=t=>Ks(r(n.duration,"delay",o(t),`$.delays.${e}.duration`)))}!function(t,e,s){const{assertResolvable:n}=s;function i(s,r){if(s)if(Fs(s))n(s,r);else if(n(s.params,`${r}.params`),t.guards?.[s.type])i(t.guards[s.type].when,`$.guards.${s.type}.when`);else if(!e.guards[s.type]&&!["scxml.cond","xstate.stateIn","xstate.not"].includes(s.type))throw new Error(`Missing guard source "${s.type}"`)}function r(s,i,o=[]){if(Fs(s))return void n(s,i);if(!s||"string"!=typeof s.type)throw new Error(`Invalid action at ${i}`);if(n(s.params,`${i}.params`),s.type.startsWith("@xstate.")||s.type.startsWith("scxml."))return void n(s,i);const a=t.actions?.[s.type];if(a){if(o.includes(s.type))throw new Error(`Circular action reference: ${o.concat(s.type).join(" -> ")}`);const t=Array.isArray(a)?a:[a];return void t.forEach((e,n)=>r(e,`${i}.actions.${s.type}${t.length>1?`[${n}]`:""}`,o.concat(s.type)))}if(!e.actions[s.type])throw new Error(`Missing action source "${s.type}"`)}function o(t,e){Qs(t).forEach((t,s)=>r(t,`${e}[${s}]`))}function a(t,e){(Array.isArray(t)?t:t?[t]:[]).forEach((s,r)=>{const a=Array.isArray(t)?`${e}[${r}]`:e;Fs(s)?n(s,a):(i(s.guard,`${a}.guard`),o(s.actions,`${a}.actions`),n(s.context,`${a}.context`),n(s.input,`${a}.input`))})}if(t.actions)for(const e of Object.keys(t.actions)){const s=Array.isArray(t.actions[e])?t.actions[e]:[t.actions[e]];s.forEach((t,n)=>r(t,`$.actions.${e}${s.length>1?`[${n}]`:""}`,[e]))}if(t.guards)for(const e of Object.keys(t.guards))i(t.guards[e].when,`$.guards.${e}.when`);if(t.delays)for(const e of Object.keys(t.delays)){const s=t.delays[e];n(s&&"object"==typeof s&&"duration"in s?s.duration:s,`$.delays.${e}`)}!function s(r,c){if(("history"===r.type||void 0!==r.history)&&!("string"==typeof r.target&&r.target.trim().length>0||Array.isArray(r.target)&&r.target.length>0&&r.target.every(t=>t.trim().length>0)))throw new Error(`History state at ${c} must declare a non-empty target.`);if(n(r.context,`${c}.context`),n(r.input,`${c}.input`),n(r.output,`${c}.output`),n(r.timeout,`${c}.timeout`),o(r.entry,`${c}.entry`),o(r.exit,`${c}.exit`),"choice"===r.type){if(!r.choice)throw new Error(`Choice state at ${c} must declare choice.`);Array.isArray(r.choice)?(Gs(r.choice,`${c}.choice`),r.choice.forEach((t,e)=>{i(t.when,`${c}.choice[${e}].when`),n(t.context,`${c}.choice[${e}].context`),n(t.input,`${c}.choice[${e}].input`)})):n(r.choice,`${c}.choice`)}if(Fs(r.route)&&n(r.route,`${c}.route`),r.invoke&&(Array.isArray(r.invoke)?r.invoke:[r.invoke]).forEach((t,s)=>{const i=`${c}.invoke${Array.isArray(r.invoke)?`[${s}]`:""}`;if(!t._nestedScxmlIR&&!e.actors[t.src])throw new Error(`Missing actor source "${t.src}"`);n(t.input,`${i}.input`),n(t.timeout,`${i}.timeout`),a(t.onDone,`${i}.onDone`),a(t.onError,`${i}.onError`),a(t.onSnapshot,`${i}.onSnapshot`),a(t.onTimeout,`${i}.onTimeout`)}),r.on)for(const t of Object.keys(r.on))a(r.on[t],`${c}.on.${t}`);if(r.after)for(const s of Object.keys(r.after)){if(Number.isNaN(Number(s))&&void 0===xt(s)&&!t.delays?.[s]&&!e.delays[s])throw new Error(`Missing delay source "${s}"`);a(r.after[s],`${c}.after.${s}`)}if(a(r.always,`${c}.always`),a(r.onError,`${c}.onError`),a(r.onTimeout,`${c}.onTimeout`),r.states)for(const t of Object.keys(r.states))s(r.states[t],`${c}.states.${t}`)}(t,"$")}(t,s,n);const E=function e(s,n,r=[]){const o=[...s._scxmlData?.length?[{type:"scxml.datamodel",data:s._scxmlData}]:[],...Qs(s.entry)],c=s.id||n;var h;return{id:s.id,initial:s._scxmlInitial?{target:s._scxmlInitial.targets,to:s._scxmlInitial.actions?(t,e)=>({...w(s._scxmlInitial.actions,t,e),target:s._scxmlInitial.targets}):void 0}:s.initial,type:s.type,history:s.history,target:s.target,_historyDefaultTransition:s._scxmlHistoryActions?(t,e)=>({...w(s._scxmlHistoryActions,t,e),target:s.target}):void 0,description:s.description,tags:s.tags,input:s.input,timeout:a(s.timeout,`$.states.${n}.timeout`),states:s.states?Object.entries(s.states).reduce((t,[s,n])=>(t[s]=e(n,s,c?[...r,c]:r),t),{}):void 0,on:s.on?Object.entries(s.on).reduce((t,[e,s])=>(t[e]=A(s),t),{}):void 0,always:s.always?A(s.always):void 0,onError:s.onError?A(s.onError):void 0,choice:l(s.choice,`$.states.${n}.choice`),route:y(s.route,`$.states.${n}.route`),after:s.after?Object.entries(s.after).reduce((t,[e,s])=>(t[e]=A(s),t),{}):void 0,onTimeout:s.onTimeout?A(s.onTimeout):void 0,entry:"choice"===s.type?void 0:(e,n)=>{for(en.set(e.self,t.id??"(machine)"),c&&rn.set(e.self,[...r,c]);m.length;){const t=m.shift();n.raise({type:"xstate.error.execution",error:t,_scxmlEventType:"platform",_scxmlEventName:"error.execution",_scxmlEventData:t})}let i;if(f&&p===e.event&&d.length>0&&Object.keys(u).length>0){let t=f;for(const s of d){const i=w(s,{...e,context:t},n);i.context&&(t=i.context)}d.length=0,f=null,p=null;for(const t of Object.keys(u))delete u[t];i=t}else{const t=c?u[c]:void 0;if(t){delete u[c];const s=w(t,e,n);s.context&&(i=s.context)}f=null,p=null,d.length=0}if(o.length){const t=i?{...e,context:i}:e,s=w(o,t,n);s.context&&(i=s.context)}if(s._scxmlDonedata&&c){let t=g.get(e.self);t||(t=new Map,g.set(e.self,t));try{t.set(c,function(t,e,s,n){if(t.params?.length){const i={};for(const r of t.params)i[r.name]=an(e,r.expr,s,n);return i}if(void 0!==t.contentExpr)return an(e,t.contentExpr,s,n);if(void 0!==t.contentText)try{return an(e,t.contentText,s,n)}catch{return t.contentText}}(s._scxmlDonedata,i??e.context,e.event,e.self))}catch(s){t.set(c,void 0),_({enq:n,self:e.self,errored:!1},"donedata",s)}}return rn.delete(e.self),{context:i}},exit:s.exit?(h=Qs(s.exit),(t,e)=>w(h,t,e)):void 0,invoke:s.invoke?x(s.invoke):void 0,meta:s.meta,output:s._scxmlDonedata?v(c):Fs(s.output)?({context:t,event:e,self:r})=>i(s.output,"output",{context:t,event:e,self:r},`$.states.${n}.output`):s.output}}(t),$=t.context||t._scxmlDataIds?.length?{context:e=>({...Object.fromEntries((t._scxmlDataIds??[]).map(t=>[t,void 0])),...t.context?r(t.context,"context",e,"$.context"):{},...t._scxmlDataIds?.length&&e.input&&"object"==typeof e.input?e.input:{},...t._scxmlDataIds?.length&&e.input&&"object"==typeof e.input?{_xstateScxmlInputKeys:Object.keys(e.input)}:{}})}:{};var k;const I={"scxml.cond":({context:t,event:e,self:s},n)=>{const i=n?.expr;if(!i)return!0;try{return!!an(t,i,e,s)}catch(t){const e=t instanceof Error?t.message:"string"==typeof t?t:"unknown error";return m.push({tagname:"cond",message:e,line:NaN,column:NaN,reason:e}),!1}},"xstate.stateIn":(t,e)=>{const s=e?.stateId;if(!s)return!1;const n=s.replace(/^#/,""),i=t._snapshot;return!!i?.nodes&&i.nodes.some(t=>t.id===n)},"xstate.not":(t,e)=>{const s=e?.guard,n=s&&t.guards?.[s.type];if(!n)throw new Error(`Guard '${s?.type}' referenced by 'xstate.not' is not implemented.`);return!n(t,s.params)}},T=(k={...E,...$,version:t.version},new Xs(k)).provide({actions:s.actions,actors:s.actors,guards:{...I,...s.guards},delays:s.delays});return T._json=t,T}function un(t){return!Fs(t)&&t.type.startsWith("@xstate.")}let dn=function(t){return t.Internal="#_internal",t}({});function fn(t){const e={elements:[]},s=[e],n=t=>s[s.length-1].elements.push(t),i=new r.SaxesParser;return i.on("opentag",t=>{const e={...t.attributes},i={type:"element",name:t.name,...Object.keys(e).length?{attributes:e}:void 0,elements:[]};n(i),s.push(i)}),i.on("closetag",()=>{const t=s.pop();t.elements?.length||delete t.elements}),i.on("text",t=>{t.trim()&&n({type:"text",text:t})}),i.on("cdata",t=>n({type:"cdata",cdata:t})),i.on("comment",t=>n({type:"comment",text:t})),i.write(t).close(),e}function pn(t){return t.replace(/\./g,"$")}function mn(t){t.name?.includes(":")&&(t.name=t.name.slice(t.name.lastIndexOf(":")+1));for(const e of t.elements??[])mn(e);return t}function gn(t,e,s){if(!t.resolveResource)throw new Error(`No SCXML resource resolver provided for ${s}: ${e}`);return t.resolveResource(e,s)}function yn(t,e){return t.attributes?t.attributes[e]:void 0}function vn(t){return{name:t.name,...t.attributes?{attributes:Object.fromEntries(Object.entries(t.attributes).map(([t,e])=>[t,String(e)]))}:void 0,...(t.elements??[]).some(t=>t.name)?{children:(t.elements??[]).filter(t=>t.name).map(vn)}:void 0}}function xn(t){if(void 0!==t.attributes?.expr)return{expr:String(t.attributes.expr)};const e=t.elements?.find(t=>t.name);return e?{xml:vn(e)}:{text:(t.elements??[]).filter(t=>"text"===t.type||"cdata"===t.type).map(t=>String(t.text??t.cdata??"")).join("")}}function _n(t){return/^error(\.|$)/.test(t)?`xstate.${t}`:t}function bn(t,e){switch(t.name){case"raise":return{type:"@xstate.raise",event:{type:_n(t.attributes.event)}};case"assign":return{type:"scxml.assign",location:t.attributes.location,expr:void 0!==t.attributes?.expr?String(t.attributes.expr):JSON.stringify(vn(t.elements.find(t=>t.name)))};case"cancel":if("sendid"in t.attributes){return{type:"@xstate.cancel",id:t.attributes.sendid}}return"sendidexpr"in t.attributes?{type:"scxml.cancel",sendidexpr:t.attributes.sendidexpr}:{type:"@xstate.cancel",id:""};case"send":{const{event:e,eventexpr:s,target:n,targetexpr:i,id:r,idlocation:o,delay:a,delayexpr:c,namelist:h,type:l}=t.attributes,u=[];let d;if(t.elements)for(const e of t.elements)"param"===e.name?u.push({name:e.attributes.name,...void 0!==e.attributes.expr?{expr:e.attributes.expr}:{location:e.attributes.location}}):"content"===e.name&&(d=xn(e));const f=n===String(dn.Internal),p=a?function(t){if(!t)return;const e=xt(t);if(void 0!==e)return e;throw new Error(`Can't parse "${t} delay."`)}(a):void 0;if("string"==typeof n&&n.length>0&&!f||u.length||s||c||i||h||d||o||l){return{type:"scxml.raise",event:"string"==typeof e?_n(e):void 0,eventexpr:s,params:u.length?u:void 0,namelist:"string"==typeof h?h.trim().split(/\s+/):void 0,id:r,idlocation:o,delay:p,delayexpr:c,target:n,targetexpr:i,processorType:l,content:d}}return{type:"scxml.raise",event:e,eventexpr:void 0,params:void 0,namelist:void 0,id:r,idlocation:o,delay:p,target:n,targetexpr:void 0,processorType:l,content:d}}case"log":{const e=t.attributes.label,s=t.attributes.expr;return{type:"scxml.log",...void 0!==e?{label:String(e)}:void 0,...void 0!==s?{expr:String(s)}:void 0}}case"if":return function(t,e){const s=[];let n=t.attributes?.cond,i=[];if(t.elements)for(const r of t.elements)"comment"!==r.type&&("elseif"===r.name?(s.push({cond:n,actions:i}),n=r.attributes?.cond,i=[]):"else"===r.name?(s.push({cond:n,actions:i}),n=void 0,i=[]):i.push(bn(r,e)));return s.push({cond:n,actions:i}),{type:"scxml.if",branches:s}}(t,e);case"foreach":{const s=t.attributes.array,n=t.attributes.item,i=t.attributes?.index;return{type:"scxml.foreach",array:s,item:n,index:i,actions:t.elements?wn(t.elements,e):[]}}case"script":{if(t.attributes?.src)return{type:"scxml.script",code:gn(e,String(t.attributes.src),"script")};const s=t.elements?.find(t=>"text"===t.type);return{type:"scxml.script",code:(s?.text||"").trim()}}default:throw new Error(`Conversion of "${t.name}" elements is not implemented yet.`)}}function wn(t,e){const s=[];for(const n of t)"comment"!==n.type&&s.push(bn(n,e));return s}function Sn(t){if(t.startsWith("In")){const e=t.trim().match(/^In\('(.*)'\)/);if(e)return{type:"xstate.stateIn",params:{stateId:`#${pn(e[1])}`}}}if(t.startsWith("!In")){const e=t.trim().match(/^!In\('(.*)'\)/);if(e)return{type:"xstate.not",params:{guard:{type:"xstate.stateIn",params:{stateId:`#${pn(e[1])}`}}}}}return{type:"scxml.cond",params:{expr:t}}}function An(t,e){return(t.elements??[]).filter(t=>"datamodel"===t.name).flatMap(t=>(t.elements??[]).filter(t=>"data"===t.name).map(t=>{const s=t.attributes?.src,n=void 0!==s?gn(e,String(s),"data"):void 0,i=(t.elements??[]).filter(t=>"text"===t.type||"cdata"===t.type).map(t=>String(t.text??t.cdata??"")).join("").trim(),r=t.elements?.find(t=>t.name);let o;if(void 0!==n)try{o=mn(fn(n)).elements?.find(t=>t.name)}catch{o=void 0}return{id:String(t.attributes.id),...void 0!==t.attributes?.expr?{expr:String(t.attributes.expr)}:void 0,...void 0===n||o?i?{content:i}:void 0:{content:n.trim()},...o?{xml:vn(o)}:r?{xml:vn(r)}:void 0}}))}function En(t,e){return[...An(t,e),...(t.elements??[]).filter(t=>["state","parallel","final"].includes(t.name??"")).flatMap(t=>En(t,e))]}function $n(t,e,s,n="early",i={}){const r="parallel"===t.name;let o,a=r?void 0:t.attributes?.initial;const c=void 0!==a,{elements:h}=t,l=s?`${s}.${e}`:e;if("history"===t.name){const s=yn(t,"type")||"shallow";if(!h)return{id:pn(e),type:"history",history:s};const[n]=h.filter(t=>"transition"===t.name),r=yn(n,"target");return{id:pn(e),type:"history",history:s,target:r?`#${pn(r)}`:void 0,...n.elements?.length?{_scxmlHistoryActions:wn(n.elements,i)}:void 0}}if(!t.elements)return{id:pn(e),..."final"===t.name?{type:"final"}:void 0};let u;if("final"===t.name){const e=t.elements.find(t=>"donedata"===t.name);if(e?.elements){const t=[];let s,n;for(const i of e.elements)if("param"===i.name)t.push({name:i.attributes.name,expr:String(i.attributes?.expr??i.attributes?.location??"").trim()});else if("content"===i.name)if(i.attributes?.expr)s=i.attributes.expr;else if(i.elements){const t=i.elements.find(t=>"text"===t.type||"cdata"===t.type);n=t?String(t.text??t.cdata??"").trim():""}u={params:t,contentExpr:s,contentText:n}}}const d=t.elements.filter(t=>"state"===t.name||"parallel"===t.name||"final"===t.name||"history"===t.name);d.forEach((t,s)=>{void 0===t.attributes?.id&&(t.attributes={...t.attributes,id:`${e}.anonymous.${s}`})});const f=t.elements.filter(t=>"transition"===t.name),p=t.elements.filter(t=>"invoke"===t.name),m=t.elements.filter(t=>"onentry"===t.name),g=t.elements.filter(t=>"onexit"===t.name),y=t.elements.filter(t=>"script"===t.name).map(t=>({...bn(t,i),global:!0})),v={};for(const t of d){const e=pn(`${t.attributes.id}`);v[e]=$n(t,e,l,n,i)}const x=a?void 0:t.elements.find(t=>"initial"===t.name);if(x&&x.elements?.length){const t=x.elements.find(t=>"transition"===t.name);a=t.attributes.target,o=t.elements?.length?wn(t.elements,i):void 0}else a||x||!d.length||(a=d[0].attributes.id);const _=[],b={};f.forEach(t=>{const e=(yn(t,"event")||"").trim().split(/\s+/),s=yn(t,"target"),n="internal"===yn(t,"type"),r=void 0!==s,o=e.filter(Boolean).map(t=>/^(error|done\.state)(\.|$)/.test(t)?`xstate.${t}`:/^done\.invoke(\.|$)/.test(t)?t.replace(/^done\.invoke/,"xstate.done.actor"):t),a={target:(c=s,c?`${c}`.split(/\s+/).map(t=>`#${pn(t)}`):void 0),_scxml:{...r&&{type:n?"internal":"external"},...o.length&&{eventDescriptors:o}},...t.elements?.length?{actions:wn(t.elements,i)}:void 0,...t.attributes?.cond?{guard:Sn(t.attributes.cond)}:void 0,...r&&!n&&{reenter:!0}};var c;if(!o.length)return void _.push(a);const h=b["*"];h?Array.isArray(h)?h.push(a):b["*"]=[h,a]:b["*"]=a});const w=[...y,...m.map(t=>({type:"scxml.block",actions:wn(t.elements||[],i)}))],S=g.length?g.map(t=>({type:"scxml.block",actions:wn(t.elements||[],i)})):void 0,A=p.map((t,s)=>{const n=t.attributes?.type;if(void 0!==n&&!["scxml","http://www.w3.org/TR/scxml","http://www.w3.org/TR/scxml/"].includes(n))throw new Error(`Currently only converting invoke elements of type SCXML is supported (received ${String(n)}).`);const r=t.elements?.find(t=>"content"===t.name),o=r?.elements?.find(t=>"scxml"===t.name),a=t=>m.flatMap(t=>t.elements??[]).find(e=>"assign"===e.name&&e.attributes?.location===t);let c;if(o){c=kn({elements:[o]},i)}else if(t.attributes?.src){c=kn(mn(fn(gn(i,String(t.attributes.src),"invoke"))),i)}else if(t.attributes?.srcexpr){const e=a(String(t.attributes.srcexpr)),s=String(e?.attributes?.expr??"").match(/^(['"])(.*)\1$/s)?.[2];s&&(c=kn(mn(fn(gn(i,s,"invoke"))),i))}else if(r?.attributes?.expr){const t=a(String(r.attributes.expr)),e=t?.elements?.find(t=>"scxml"===t.name);e&&(c=kn({elements:[e]},i))}const h=String(t.attributes?.id??`${pn(e)}.invoke.${s}`),l=(t.elements??[]).filter(t=>"param"===t.name).map(t=>({name:String(t.attributes.name),...void 0!==t.attributes?.expr?{expr:String(t.attributes.expr)}:void 0,...void 0!==t.attributes?.location?{location:String(t.attributes.location)}:void 0})),u=String(t.attributes?.namelist??"").trim().split(/\s+/).filter(Boolean);return t.attributes?.idlocation&&w.push({type:"scxml.assign",location:String(t.attributes.idlocation),expr:JSON.stringify(h)}),{id:h,src:"scxml.nested",_nestedScxmlIR:c,...(l.length||u.length)&&{_scxmlInput:{...l.length?{params:l}:void 0,...u.length?{namelist:u}:void 0}}}}),E=p.flatMap((t,e)=>"true"===String(t.attributes?.autoforward)?[A[e].id]:[]),$=p.flatMap((t,e)=>{const s=t.elements?.find(t=>"finalize"===t.name);return s?[{invokeId:A[e].id,actions:wn(s.elements??[],i)}]:[]});if($.length)for(const t of Object.values(b))for(const e of Array.isArray(t)?t:[t])e._scxml={...e._scxml,finalize:$},e.actions=[...$.map(t=>({type:"scxml.finalize",...t})),...e.actions??[]];if(E.length)for(const t of Object.values(b))for(const e of Array.isArray(t)?t:[t])e.actions=[...E.map(t=>({type:"scxml.forward",invokeId:t})),...e.actions??[]];const k=a&&String(a).split(" "),I=c||!!x;return{id:pn(e),...k&&!I?{initial:pn(k[0])}:void 0,...k&&I?{_scxmlInitial:{targets:k.map(t=>`#${pn(t)}`),...o?.length?{actions:o}:void 0}}:void 0,...r?{type:"parallel"}:void 0,..."final"===t.name?{type:"final"}:void 0,...u?{_scxmlDonedata:u}:void 0,...Object.keys(v).length?{states:v}:void 0,...Object.keys(b).length?{on:b}:void 0,..._.length?{always:_}:void 0,...w.length?{entry:w}:void 0,...S?.length?{exit:S}:void 0,...A.length?{invoke:A}:void 0,..."late"===n&&An(t,i).length?{_scxmlData:An(t,i)}:void 0}}function kn(t,e){const s=t.elements.find(t=>"scxml"===t.name);if(!s)throw new Error("SCXML document must contain an <scxml> root element.");const n="late"===s.attributes?.binding?"late":"early",i=En(s,e),r=$n(s,s.attributes?.name||"(machine)",void 0,n,e),o=new Set(i.map(({id:t})=>t)),a=t=>{if(t.invoke){const e=(Array.isArray(t.invoke)?t.invoke:[t.invoke]).filter(t=>(t._scxmlInput?.namelist??[]).every(t=>o.has(t)));t.invoke=e.length?e:void 0}for(const e of Object.values(t.states??{}))a(e)};return a(r),{...r,..."early"===n&&i.length?{_scxmlData:i}:void 0,...i.length?{_scxmlDataIds:i.map(({id:t})=>t)}:void 0}}t.createMachineFromSCXML=function(t,e={}){return ln(function(t,e={}){return kn(mn(fn(t)),e)}(t,e))},Object.defineProperty(t,"__esModule",{value:!0})});
26
+ //# sourceMappingURL=xstate-scxml.umd.min.js.map