@nhost/hasura-auth-js
Version:
Hasura-auth client
17 lines (15 loc) • 135 kB
JavaScript
(function(T,ce){typeof exports=="object"&&typeof module!="undefined"?ce(exports):typeof define=="function"&&define.amd?define(["exports"],ce):(T=typeof globalThis!="undefined"?globalThis:T||self,ce(T["@nhost/hasura-auth-js"]={}))})(this,function(T){"use strict";const ce="nhostRefreshToken",ke="nhostRefreshTokenId",he="nhostRefreshTokenExpiresAt";class ve extends Error{constructor(e){super(e.message),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),e instanceof Error?(this.name=e.name,this.error={error:e.name,status:1,message:e.message}):(this.name=e.error,this.error=e)}}const se={status:10,error:"invalid-email",message:"Email is incorrectly formatted"},Gt={status:10,error:"invalid-mfa-type",message:"MFA type is invalid"},Bt={status:10,error:"invalid-mfa-code",message:"MFA code is invalid"},He={status:10,error:"invalid-password",message:"Password is incorrectly formatted"},dt={status:10,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},Ft={status:10,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Ht={status:10,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},$t={status:10,error:"no-refresh-token",message:"No refresh token has been provided"},Wt={status:20,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},Z={status:20,error:"already-signed-in",message:"User is already signed in"},Yt={status:20,error:"unauthenticated-user",message:"User is not authenticated"},an={status:20,error:"user-not-anonymous",message:"User is not anonymous"},qt={status:20,error:"unverified-user",message:"Email needs verification"},zt={status:10,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},Xt={status:1,error:"invalid-sign-in-method",message:"Invalid sign-in method"};class Pe extends Error{}Pe.prototype.name="InvalidTokenError";function cn(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,r)=>{let n=r.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}function un(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return cn(e)}catch{return atob(e)}}function ln(t,e){if(typeof t!="string")throw new Pe("Invalid token specified: must be a string");e||(e={});const r=e.header===!0?0:1,n=t.split(".")[r];if(typeof n!="string")throw new Pe(`Invalid token specified: missing part #${r+1}`);let i;try{i=un(n)}catch(s){throw new Pe(`Invalid token specified: invalid base64 for part #${r+1} (${s.message})`)}try{return JSON.parse(i)}catch(s){throw new Pe(`Invalid token specified: invalid json for part #${r+1} (${s.message})`)}}/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var w=function(){return w=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},w.apply(this,arguments)};function ht(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function I(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function N(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(l){o={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function G(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var L;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(L||(L={}));var ge;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(ge||(ge={}));var vt=L.Start,pt=L.Stop,Ne=L.Raise,$e=L.Send,Qt=L.Cancel,fn=L.NullEvent,yt=L.Assign;L.After,L.DoneState;var Jt=L.Log,dn=L.Init,mt=L.Invoke;L.ErrorExecution;var Zt=L.ErrorPlatform,hn=L.ErrorCustom,er=L.Update,vn=L.Choose,pn=L.Pure,tr=".",rr={},gt="xstate.guard",yn="",W=process.env.NODE_ENV==="production",We;function Et(t,e,r){r===void 0&&(r=tr);var n=xe(t,r),i=xe(e,r);return x(i)?x(n)?i===n:!1:x(n)?n in i:Object.keys(n).every(function(s){return s in i?Et(n[s],i[s]):!1})}function nr(t){try{return x(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function Tt(t,e){try{return Ee(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function mn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function xe(t,e){if(mn(t))return t.value;if(Ee(t))return Ye(t);if(typeof t!="string")return t;var r=Tt(t,e);return Ye(r)}function Ye(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function De(t,e){for(var r={},n=Object.keys(t),i=0;i<n.length;i++){var s=n[i];r[s]=e(t[s],s,t,i)}return r}function ir(t,e,r){var n,i,s={};try{for(var o=I(Object.keys(t)),l=o.next();!l.done;l=o.next()){var u=l.value,f=t[u];r(f)&&(s[u]=e(f,u,t))}}catch(h){n={error:h}}finally{try{l&&!l.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}var gn=function(t){return function(e){var r,n,i=e;try{for(var s=I(t),o=s.next();!o.done;o=s.next()){var l=o.value;i=i[l]}}catch(u){r={error:u}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function En(t,e){return function(r){var n,i,s=r;try{for(var o=I(t),l=o.next();!l.done;l=o.next()){var u=l.value;s=s[e][u]}}catch(f){n={error:f}}finally{try{l&&!l.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}}function qe(t){if(!t)return[[]];if(x(t))return[[t]];var e=H(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:qe(t[r]).map(function(i){return[r].concat(i)})}));return e}function H(t){var e;return(e=[]).concat.apply(e,G([],N(t),!1))}function sr(t){return Ee(t)?t:[t]}function oe(t){return t===void 0?[]:sr(t)}function ze(t,e,r){var n,i;if(D(t))return t(e,r.data);var s={};try{for(var o=I(Object.keys(t)),l=o.next();!l.done;l=o.next()){var u=l.value,f=t[u];D(f)?s[u]=f(e,r.data):s[u]=f}}catch(h){n={error:h}}finally{try{l&&!l.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}function Tn(t){return/^(done|error)\./.test(t)}function or(t){return!!(t instanceof Promise||t!==null&&(D(t)||typeof t=="object")&&D(t.then))}function wn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function Sn(t,e){var r,n,i=N([[],[]],2),s=i[0],o=i[1];try{for(var l=I(t),u=l.next();!u.done;u=l.next()){var f=u.value;e(f)?s.push(f):o.push(f)}}catch(h){r={error:h}}finally{try{u&&!u.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}return[s,o]}function ar(t,e){return De(t.states,function(r,n){if(r){var i=(x(e)?void 0:e[n])||(r?r.current:void 0);if(i)return{current:i,states:ar(r,i)}}})}function Rn(t,e){return{current:e,states:ar(t,e)}}function cr(t,e,r,n){W||X(!!t,"Attempting to update undefined context");var i=t&&r.reduce(function(s,o){var l,u,f=o.assignment,h={state:n,action:o,_event:e},y={};if(D(f))y=f(s,e.data,h);else try{for(var a=I(Object.keys(f)),c=a.next();!c.done;c=a.next()){var d=c.value,p=f[d];y[d]=D(p)?p(s,e.data,h):p}}catch(E){l={error:E}}finally{try{c&&!c.done&&(u=a.return)&&u.call(a)}finally{if(l)throw l.error}}return Object.assign({},s,y)},t);return i}var X=function(){};W||(X=function(t,e){var r=t instanceof Error?t:void 0;if(!(!r&&t)&&console!==void 0){var n=["Warning: ".concat(e)];r&&n.push(r),console.warn.apply(console,n)}});function Ee(t){return Array.isArray(t)}function D(t){return typeof t=="function"}function x(t){return typeof t=="string"}function ur(t,e){if(t)return x(t)?{type:gt,name:t,predicate:e?e[t]:void 0}:D(t)?{type:gt,name:t.name,predicate:t}:t}function An(t){try{return"subscribe"in t&&D(t.subscribe)}catch{return!1}}var fe=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();We={},We[fe]=function(){return this},We[Symbol.observable]=function(){return this};function pe(t){return!!t&&"__xstatenode"in t}function _n(t){return!!t&&typeof t.send=="function"}function Xe(t,e){return x(t)||typeof t=="number"?w({type:t},e):t}function Q(t,e){if(!x(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Xe(t);return w({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function Te(t,e){var r=sr(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||pe(n)?{target:n,event:t}:w(w({},n),{event:t})});return r}function bn(t){if(!(t===void 0||t===yn))return oe(t)}function On(t,e,r){if(!W){var n=t.stack?" Stacktrace was '".concat(t.stack,"'"):"";if(t===e)console.error("Missing onError handler for invocation '".concat(r,"', error was '").concat(t,"'.").concat(n));else{var i=e.stack?" Stacktrace was '".concat(e.stack,"'"):"";console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(r,"'. ")+"Original error: '".concat(t,"'. ").concat(n," Current error is '").concat(e,"'.").concat(i))}}}function lr(t,e,r,n,i){var s=t.options.guards,o={state:i,cond:e,_event:n};if(e.type===gt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,o);var l=s==null?void 0:s[e.type];if(!l)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return l(r,n.data,o)}function fr(t){return typeof t=="string"?{type:t}:t}function Qe(t,e,r){var n=function(){},i=typeof t=="object",s=i?t:null;return{next:((i?t.next:t)||n).bind(s),error:((i?t.error:e)||n).bind(s),complete:((i?t.complete:r)||n).bind(s)}}function Je(t,e){return"".concat(t,":invocation[").concat(e,"]")}function wt(t){return(t.type===Ne||t.type===$e&&t.to===ge.Internal)&&typeof t.delay!="number"}var we=Q({type:dn});function St(t,e){return e&&e[t]||void 0}function Ce(t,e){var r;if(x(t)||typeof t=="number"){var n=St(t,e);D(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(D(t))r={type:t.name||t.toString(),exec:t};else{var n=St(t.type,e);if(D(n))r=w(w({},t),{exec:n});else if(n){var i=n.type||t.type;r=w(w(w({},n),t),{type:i})}else r=t}return r}var de=function(t,e){if(!t)return[];var r=Ee(t)?t:[t];return r.map(function(n){return Ce(n,e)})};function Rt(t){var e=Ce(t);return w(w({id:x(t)?t:e.id},e),{type:e.type})}function In(t,e){return{type:Ne,event:typeof t=="function"?t:Xe(t),delay:e?e.delay:void 0,id:e==null?void 0:e.id}}function kn(t,e,r,n){var i={_event:r},s=Q(D(t.event)?t.event(e,r.data,i):t.event),o;if(x(t.delay)){var l=n&&n[t.delay];o=D(l)?l(e,r.data,i):l}else o=D(t.delay)?t.delay(e,r.data,i):t.delay;return w(w({},t),{type:Ne,_event:s,delay:o})}function dr(t,e){return{to:e?e.to:void 0,type:$e,event:D(t)?t:Xe(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:D(t)?t.name:nr(t)}}function Pn(t,e,r,n){var i={_event:r},s=Q(D(t.event)?t.event(e,r.data,i):t.event),o;if(x(t.delay)){var l=n&&n[t.delay];o=D(l)?l(e,r.data,i):l}else o=D(t.delay)?t.delay(e,r.data,i):t.delay;var u=D(t.to)?t.to(e,r.data,i):t.to;return w(w({},t),{to:u,_event:s,event:s.data,delay:o})}var Nn=function(t,e,r){return w(w({},t),{value:x(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},xn=function(t){return{type:Qt,sendId:t}};function Dn(t){var e=Rt(t);return{type:L.Start,activity:e,exec:void 0}}function Cn(t){var e=D(t)?t:Rt(t);return{type:L.Stop,activity:e,exec:void 0}}function Un(t,e,r){var n=D(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:L.Stop,activity:i};return s}var Mn=function(t){return{type:yt,assignment:t}};function Ln(t,e){var r=e?"#".concat(e):"";return"".concat(L.After,"(").concat(t,")").concat(r)}function Ze(t,e){var r="".concat(L.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function et(t,e){var r="".concat(L.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ue(t,e){var r="".concat(L.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}var jn=function(t){var e,r,n=[];try{for(var i=I(t),s=i.next();!s.done;s=i.next())for(var o=s.value,l=0;l<o.actions.length;){if(o.actions[l].type===yt){n.push(o.actions[l]),o.actions.splice(l,1);continue}l++}}catch(u){e={error:u}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n};function tt(t,e,r,n,i,s,o){o===void 0&&(o=!1);var l=o?[]:jn(i),u=l.length?cr(r,n,l,e):r,f=o?[r]:void 0,h=[];function y(d,p){var E;switch(p.type){case Ne:{var m=kn(p,u,n,t.options.delays);return s&&typeof m.delay=="number"&&s(m,u,n),m}case $e:var S=Pn(p,u,n,t.options.delays);if(!W){var R=p.delay;X(!x(R)||typeof S.delay=="number","No delay reference for delay expression '".concat(R,"' was found on machine '").concat(t.id,"'"))}return s&&S.to!==ge.Internal&&(d==="entry"?h.push(S):s(S,u,n)),S;case Jt:{var b=Nn(p,u,n);return s==null||s(b,u,n),b}case vn:{var j=p,C=(E=j.conds.find(function(v){var g=ur(v.cond,t.options.guards);return!g||lr(t,g,u,n,s?void 0:e)}))===null||E===void 0?void 0:E.actions;if(!C)return[];var k=N(tt(t,e,u,n,[{type:d,actions:de(oe(C),t.options.actions)}],s,o),2),M=k[0],O=k[1];return u=O,f==null||f.push(u),M}case pn:{var C=p.get(u,n.data);if(!C)return[];var $=N(tt(t,e,u,n,[{type:d,actions:de(oe(C),t.options.actions)}],s,o),2),_=$[0],K=$[1];return u=K,f==null||f.push(u),_}case pt:{var b=Un(p,u,n);return s==null||s(b,r,n),b}case yt:{u=cr(u,n,[p],s?void 0:e),f==null||f.push(u);break}default:var Y=Ce(p,t.options.actions),F=Y.exec;if(s)s(Y,u,n);else if(F&&f){var ye=f.length-1,me=w(w({},Y),{exec:function(v){for(var g=[],A=1;A<arguments.length;A++)g[A-1]=arguments[A];F.apply(void 0,G([f[ye]],N(g),!1))}});Y=me}return Y}}function a(d){var p,E,m=[];try{for(var S=I(d.actions),R=S.next();!R.done;R=S.next()){var b=R.value,j=y(d.type,b);j&&(m=m.concat(j))}}catch(C){p={error:C}}finally{try{R&&!R.done&&(E=S.return)&&E.call(S)}finally{if(p)throw p.error}}return h.forEach(function(C){s(C,u,n)}),h.length=0,m}var c=H(i.map(a));return[c,u]}var Se=function(t,e){var r=e(t);return r};function hr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[fe]=function(){return this},e}function Kn(t,e,r,n){var i,s=fr(t.src),o=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],l=t.data?ze(t.data,r,n):void 0,u=o?vr(o,t.id,l):hr(t.id);return u.meta=t,u}function vr(t,e,r){var n=hr(e);if(n.deferred=!0,pe(t)){var i=n.state=Se(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function Vn(t){try{return typeof t.send=="function"}catch{return!1}}function Gn(t){return Vn(t)&&"id"in t}function Bn(t){var e;return w((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[fe]=function(){return this},e),t)}var rt=function(t){return t.type==="atomic"||t.type==="final"};function pr(t){return Object.keys(t.states).map(function(e){return t.states[e]})}function Me(t){return pr(t).filter(function(e){return e.type!=="history"})}function yr(t){var e=[t];return rt(t)?e:e.concat(H(Me(t).map(yr)))}function Le(t,e){var r,n,i,s,o,l,u,f,h=new Set(t),y=At(h),a=new Set(e);try{for(var c=I(a),d=c.next();!d.done;d=c.next())for(var p=d.value,E=p.parent;E&&!a.has(E);)a.add(E),E=E.parent}catch(O){r={error:O}}finally{try{d&&!d.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}var m=At(a);try{for(var S=I(a),R=S.next();!R.done;R=S.next()){var p=R.value;if(p.type==="compound"&&(!m.get(p)||!m.get(p).length))y.get(p)?y.get(p).forEach(function($){return a.add($)}):p.initialStateNodes.forEach(function($){return a.add($)});else if(p.type==="parallel")try{for(var b=(o=void 0,I(Me(p))),j=b.next();!j.done;j=b.next()){var C=j.value;a.has(C)||(a.add(C),y.get(C)?y.get(C).forEach(function($){return a.add($)}):C.initialStateNodes.forEach(function($){return a.add($)}))}}catch($){o={error:$}}finally{try{j&&!j.done&&(l=b.return)&&l.call(b)}finally{if(o)throw o.error}}}}catch(O){i={error:O}}finally{try{R&&!R.done&&(s=S.return)&&s.call(S)}finally{if(i)throw i.error}}try{for(var k=I(a),M=k.next();!M.done;M=k.next())for(var p=M.value,E=p.parent;E&&!a.has(E);)a.add(E),E=E.parent}catch(O){u={error:O}}finally{try{M&&!M.done&&(f=k.return)&&f.call(k)}finally{if(u)throw u.error}}return a}function mr(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(rt(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=mr(s,e)}),i}function At(t){var e,r,n=new Map;try{for(var i=I(t),s=i.next();!s.done;s=i.next()){var o=s.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(l){e={error:l}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function Fn(t,e){var r=Le([t],e);return mr(t,At(r))}function je(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Hn(t){return G([],N(new Set(H(G([],N(t.map(function(e){return e.ownEvents})),!1)))),!1)}function nt(t,e){return e.type==="compound"?Me(e).some(function(r){return r.type==="final"&&je(t,r)}):e.type==="parallel"?Me(e).every(function(r){return nt(t,r)}):!1}function $n(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function gr(t){return new Set(H(t.map(function(e){return e.tags})))}function Er(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(x(t)||x(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return Er(t[i],e[i])})}function Wn(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function Yn(t,e){var r=t.exec,n=w(w({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var ue=function(){function t(e){var r=this,n;this.actions=[],this.activities=rr,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||rr,this.meta=$n(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Hn(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=we;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=we;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),x(e))return[e];var i=Object.keys(e);return i.concat.apply(i,G([],N(i.map(function(s){return n.toStrings(e[s],r).map(function(o){return s+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=ht(e,["configuration","transitions","tags","machine"]);return w(w({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Et(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;W&&X(!!this.machine,"state.can(...) used outside of a machine-created State object; this will always return false.");var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(i){return i.target!==void 0||i.actions.length})},t}(),qn={deferEvents:!1},Tr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=w(w({},qn),e)}return t.prototype.initialize=function(e){if(this.initialized=!0,e){if(!this.options.deferEvents){this.schedule(e);return}this.process(e)}this.flushEvents()},t.prototype.schedule=function(e){if(!this.initialized||this.processingEvent){this.queue.push(e);return}if(this.queue.length!==0)throw new Error("Event queue should be empty when it is not processing events");this.process(e),this.flushEvents()},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var e=this.queue.shift();e;)this.process(e),e=this.queue.shift()},t.prototype.process=function(e){this.processingEvent=!0;try{e()}catch(r){throw this.clear(),r}finally{this.processingEvent=!1}},t}(),_t=new Map,zn=0,Ke={bookId:function(){return"x:".concat(zn++)},register:function(t,e){return _t.set(t,e),t},get:function(t){return _t.get(t)},free:function(t){_t.delete(t)}};function bt(){if(typeof globalThis!="undefined")return globalThis;if(typeof self!="undefined")return self;if(typeof window!="undefined")return window;if(typeof global!="undefined")return global;W||console.warn("XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues")}function Xn(){var t=bt();if(t&&"__xstate__"in t)return t.__xstate__}function Qn(t){if(bt()){var e=Xn();e&&e.register(t)}}function Jn(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,o=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,u),n.forEach(function(h){return h.next(r)})}s=!1}},l=Bn({id:e.id,send:function(f){i.push(f),o()},getSnapshot:function(){return r},subscribe:function(f,h,y){var a=Qe(f,h,y);return n.add(a),a.next(r),{unsubscribe:function(){n.delete(a)}}}}),u={parent:e.parent,self:l,id:e.id||"anonymous",observers:n};return r=t.start?t.start(u):r,l}var Zn={sync:!1,autoForward:!1},q;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(q||(q={}));var ei=function(){function t(e,r){r===void 0&&(r=t.defaultOptions);var n=this;this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=q.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(h,y){if(Ee(h))return n.batch(h),n.state;var a=Q(Xe(h,y));if(n.status===q.Stopped)return W||X(!1,'Event "'.concat(a.name,'" was sent to stopped service "').concat(n.machine.id,`". This service has already reached its final state, and will not transition.
Event: `).concat(JSON.stringify(a.data))),n.state;if(n.status!==q.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(a.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
Event: `).concat(JSON.stringify(a.data)));return n.scheduler.schedule(function(){n.forward(a);var c=n._nextState(a);n.update(c,a)}),n._state},this.sendTo=function(h,y,a){var c=n.parent&&(y===ge.Parent||n.parent.id===y),d=c?n.parent:x(y)?y===ge.Internal?n:n.children.get(y)||Ke.get(y):_n(y)?y:void 0;if(!d){if(!c)throw new Error("Unable to send event to child '".concat(y,"' from service '").concat(n.id,"'."));W||X(!1,"Service '".concat(n.id,"' has no parent: unable to send event ").concat(h.type));return}if("machine"in d){if(n.status!==q.Stopped||n.parent!==d||n.state.done){var p=w(w({},h),{name:h.name===hn?"".concat(Ue(n.id)):h.name,origin:n.sessionId});!a&&n.machine.config.predictableActionArguments?n._outgoingQueue.push([d,p]):d.send(p)}}else!a&&n.machine.config.predictableActionArguments?n._outgoingQueue.push([d,h.data]):d.send(h.data)},this._exec=function(h,y,a,c){c===void 0&&(c=n.machine.options.actions);var d=h.exec||St(h.type,c),p=D(d)?d:d?d.exec:h.exec;if(p)try{return p(y,a.data,n.machine.config.predictableActionArguments?{action:h,_event:a}:{action:h,state:n.state,_event:a})}catch(F){throw n.parent&&n.parent.send({type:"xstate.error",data:F}),F}switch(h.type){case Ne:{var E=h;n.defer(E);break}case $e:var m=h;if(typeof m.delay=="number"){n.defer(m);return}else m.to?n.sendTo(m._event,m.to,a===we):n.send(m._event);break;case Qt:n.cancel(h.sendId);break;case vt:{if(n.status!==q.Running)return;var S=h.activity;if(!n.machine.config.predictableActionArguments&&!n.state.activities[S.id||S.type])break;if(S.type===L.Invoke){var R=fr(S.src),b=n.machine.options.services?n.machine.options.services[R.type]:void 0,j=S.id,C=S.data;W||X(!("forward"in S),"`forward` property is deprecated (found in invocation of '".concat(S.src,"' in in machine '").concat(n.machine.id,"'). ")+"Please use `autoForward` instead.");var k="autoForward"in S?S.autoForward:!!S.forward;if(!b){W||X(!1,"No service found for invocation '".concat(S.src,"' in machine '").concat(n.machine.id,"'."));return}var M=C?ze(C,y,a):void 0;if(typeof b=="string")return;var O=D(b)?b(y,a.data,{data:M,src:R,meta:S.meta}):b;if(!O)return;var $=void 0;pe(O)&&(O=M?O.withContext(M):O,$={autoForward:k}),n.spawn(O,j,$)}else n.spawnActivity(S);break}case pt:{n.stopChild(h.activity.id);break}case Jt:var _=h,K=_.label,Y=_.value;K?n.logger(K,Y):n.logger(Y);break;default:W||X(!1,"No implementation found for action type '".concat(h.type,"'"));break}};var i=w(w({},t.defaultOptions),r),s=i.clock,o=i.logger,l=i.parent,u=i.id,f=u!==void 0?u:e.id;this.id=f,this.logger=o,this.clock=s,this.parent=l,this.options=i,this.scheduler=new Tr({deferEvents:this.options.deferEvents}),this.sessionId=Ke.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Se(this,function(){return e._initialState=e.machine.initialState,e._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return W||X(this.status!==q.NotStarted,"Attempted to read state from uninitialized service '".concat(this.id,"'. Make sure the service is started first.")),this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(e,r){var n,i;try{for(var s=I(e.actions),o=s.next();!o.done;o=s.next()){var l=o.value;this.exec(l,e,r)}}catch(u){n={error:u}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,o,l,u,f,h,y=this;if(e._sessionid=this.sessionId,this._state=e,(!this.machine.config.predictableActionArguments||r===we)&&this.options.execute)this.execute(this.state);else for(var a=void 0;a=this._outgoingQueue.shift();)a[0].send(a[1]);if(this.children.forEach(function(O){y.state.children[O.id]=O}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var c=I(this.eventListeners),d=c.next();!d.done;d=c.next()){var p=d.value;p(e.event)}}catch(O){n={error:O}}finally{try{d&&!d.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}try{for(var E=I(this.listeners),m=E.next();!m.done;m=E.next()){var p=m.value;p(e,e.event)}}catch(O){s={error:O}}finally{try{m&&!m.done&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var S=I(this.contextListeners),R=S.next();!R.done;R=S.next()){var b=R.value;b(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(O){l={error:O}}finally{try{R&&!R.done&&(u=S.return)&&u.call(S)}finally{if(l)throw l.error}}if(this.state.done){var j=e.configuration.find(function(O){return O.type==="final"&&O.parent===y.machine}),C=j&&j.doneData?ze(j.doneData,e.context,r):void 0;this._doneEvent=et(this.id,C);try{for(var k=I(this.doneListeners),M=k.next();!M.done;M=k.next()){var p=M.value;p(this._doneEvent)}}catch(O){f={error:O}}finally{try{M&&!M.done&&(h=k.return)&&h.call(k)}finally{if(f)throw f.error}}this._stop(),this._stopChildren(),Ke.free(this.sessionId)}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===q.Running&&e(this.state,this.state.event),this},t.prototype.subscribe=function(e,r,n){var i=this,s=Qe(e,r,n);this.listeners.add(s.next),this.status!==q.NotStarted&&s.next(this.state);var o=function(){i.doneListeners.delete(o),i.stopListeners.delete(o),s.complete()};return this.status===q.Stopped?s.complete():(this.onDone(o),this.onStop(o)),{unsubscribe:function(){i.listeners.delete(s.next),i.doneListeners.delete(o),i.stopListeners.delete(o)}}},t.prototype.onEvent=function(e){return this.eventListeners.add(e),this},t.prototype.onSend=function(e){return this.sendListeners.add(e),this},t.prototype.onChange=function(e){return this.contextListeners.add(e),this},t.prototype.onStop=function(e){return this.stopListeners.add(e),this},t.prototype.onDone=function(e){return this.status===q.Stopped&&this._doneEvent?e(this._doneEvent):this.doneListeners.add(e),this},t.prototype.off=function(e){return this.listeners.delete(e),this.eventListeners.delete(e),this.sendListeners.delete(e),this.stopListeners.delete(e),this.doneListeners.delete(e),this.contextListeners.delete(e),this},t.prototype.start=function(e){var r=this;if(this.status===q.Running)return this;this.machine._init(),Ke.register(this.sessionId,this),this.initialized=!0,this.status=q.Running;var n=e===void 0?this.initialState:Se(this,function(){return Wn(e)?r.machine.resolveState(e):r.machine.resolveState(ue.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,we)}),this},t.prototype._stopChildren=function(){this.children.forEach(function(e){D(e.stop)&&e.stop()}),this.children.clear()},t.prototype._stop=function(){var e,r,n,i,s,o,l,u,f,h;try{for(var y=I(this.listeners),a=y.next();!a.done;a=y.next()){var c=a.value;this.listeners.delete(c)}}catch(k){e={error:k}}finally{try{a&&!a.done&&(r=y.return)&&r.call(y)}finally{if(e)throw e.error}}try{for(var d=I(this.stopListeners),p=d.next();!p.done;p=d.next()){var c=p.value;c(),this.stopListeners.delete(c)}}catch(k){n={error:k}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var E=I(this.contextListeners),m=E.next();!m.done;m=E.next()){var c=m.value;this.contextListeners.delete(c)}}catch(k){s={error:k}}finally{try{m&&!m.done&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var S=I(this.doneListeners),R=S.next();!R.done;R=S.next()){var c=R.value;this.doneListeners.delete(c)}}catch(k){l={error:k}}finally{try{R&&!R.done&&(u=S.return)&&u.call(S)}finally{if(l)throw l.error}}if(!this.initialized)return this;this.initialized=!1,this.status=q.Stopped,this._initialState=void 0;try{for(var b=I(Object.keys(this.delayedEventsMap)),j=b.next();!j.done;j=b.next()){var C=j.value;this.clock.clearTimeout(this.delayedEventsMap[C])}}catch(k){f={error:k}}finally{try{j&&!j.done&&(h=b.return)&&h.call(b)}finally{if(f)throw f.error}}this.scheduler.clear(),this.scheduler=new Tr({deferEvents:this.options.deferEvents})},t.prototype.stop=function(){var e=this,r=this.scheduler;return this._stop(),r.schedule(function(){var n;if(!(!((n=e._state)===null||n===void 0)&&n.done)){var i=Q({type:"xstate.stop"}),s=Se(e,function(){var o=H(G([],N(e.state.configuration),!1).sort(function(y,a){return a.order-y.order}).map(function(y){return de(y.onExit,e.machine.options.actions)})),l=N(tt(e.machine,e.state,e.state.context,i,[{type:"exit",actions:o}],e.machine.config.predictableActionArguments?e._exec:void 0,e.machine.config.predictableActionArguments||e.machine.config.preserveActionOrder),2),u=l[0],f=l[1],h=new ue({value:e.state.value,context:f,_event:i,_sessionid:e.sessionId,historyValue:void 0,history:e.state,actions:u.filter(function(y){return!wt(y)}),activities:{},events:[],configuration:[],transitions:[],children:{},done:e.state.done,tags:e.state.tags,machine:e.machine});return h.changed=!0,h});e.update(s,i),e._stopChildren(),Ke.free(e.sessionId)}}),this},t.prototype.batch=function(e){var r=this;if(this.status===q.NotStarted&&this.options.deferEvents)W||X(!1,"".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,`" and are deferred. Make sure .start() is called for this service.
Event: `).concat(JSON.stringify(event)));else if(this.status!==q.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var n=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(function(){var i,s,o=r.state,l=!1,u=[],f=function(c){var d=Q(c);r.forward(d),o=Se(r,function(){return r.machine.transition(o,d,void 0,n||void 0)}),u.push.apply(u,G([],N(r.machine.config.predictableActionArguments?o.actions:o.actions.map(function(p){return Yn(p,o)})),!1)),l=l||!!o.changed};try{for(var h=I(e),y=h.next();!y.done;y=h.next()){var a=y.value;f(a)}}catch(c){i={error:c}}finally{try{y&&!y.done&&(s=h.return)&&s.call(h)}finally{if(i)throw i.error}}o.changed=l,o.actions=u,r.update(o,Q(e[e.length-1]))})}},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype._nextState=function(e,r){var n=this;r===void 0&&(r=!!this.machine.config.predictableActionArguments&&this._exec);var i=Q(e);if(i.name.indexOf(Zt)===0&&!this.state.nextEvents.some(function(o){return o.indexOf(Zt)===0}))throw i.data.data;var s=Se(this,function(){return n.machine.transition(n.state,i,void 0,r||void 0)});return s},t.prototype.nextState=function(e){return this._nextState(e,!1)},t.prototype.forward=function(e){var r,n;try{for(var i=I(this.forwardTo),s=i.next();!s.done;s=i.next()){var o=s.value,l=this.children.get(o);if(!l)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(o,"'."));l.send(e)}}catch(u){r={error:u}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this,n=this.clock.setTimeout(function(){"to"in e&&e.to?r.sendTo(e._event,e.to,!0):r.send(e._event)},e.delay);e.id&&(this.delayedEventsMap[e.id]=n)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions),this._exec(e,r.context,r._event,n)},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);r&&(this.removeChild(e),D(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(this.status!==q.Running)return vr(e,r);if(or(e))return this.spawnPromise(Promise.resolve(e),r);if(D(e))return this.spawnCallback(e,r);if(Gn(e))return this.spawnActor(e,r);if(An(e))return this.spawnObservable(e,r);if(pe(e))return this.spawnMachine(e,w(w({},n),{id:r}));if(wn(e))return this.spawnBehavior(e,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof e,'".'))},t.prototype.spawnMachine=function(e,r){var n=this;r===void 0&&(r={});var i=new t(e,w(w({},this.options),{parent:this,id:r.id||e.id})),s=w(w({},Zn),r);s.sync&&i.onTransition(function(l){n.send(er,{state:l,id:i.id})});var o=i;return this.children.set(i.id,o),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(l){n.removeChild(i.id),n.send(Q(l,{origin:i.id}))}).start(),o},t.prototype.spawnBehavior=function(e,r){var n=Jn(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,o;e.then(function(u){s||(o=u,i.removeChild(r),i.send(Q(et(r,u),{origin:r})))},function(u){if(!s){i.removeChild(r);var f=Ue(r,u);try{i.send(Q(f,{origin:r}))}catch(h){On(u,h,r),i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var l=(n={id:r,send:function(){},subscribe:function(u,f,h){var y=Qe(u,f,h),a=!1;return e.then(function(c){a||(y.next(c),!a&&y.complete())},function(c){a||y.error(c)}),{unsubscribe:function(){return a=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[fe]=function(){return this},n);return this.children.set(r,l),l},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,o=new Set,l=new Set,u,f=function(a){u=a,l.forEach(function(c){return c(a)}),!s&&i.send(Q(a,{origin:r}))},h;try{h=e(f,function(a){o.add(a)})}catch(a){this.send(Ue(r,a))}if(or(h))return this.spawnPromise(h,r);var y=(n={id:r,send:function(a){return o.forEach(function(c){return c(a)})},subscribe:function(a){var c=Qe(a);return l.add(c.next),{unsubscribe:function(){l.delete(c.next)}}},stop:function(){s=!0,D(h)&&h()},toJSON:function(){return{id:r}},getSnapshot:function(){return u}},n[fe]=function(){return this},n);return this.children.set(r,y),y},t.prototype.spawnObservable=function(e,r){var n,i=this,s,o=e.subscribe(function(u){s=u,i.send(Q(u,{origin:r}))},function(u){i.removeChild(r),i.send(Q(Ue(r,u),{origin:r}))},function(){i.removeChild(r),i.send(Q(et(r),{origin:r}))}),l=(n={id:r,send:function(){},subscribe:function(u,f,h){return e.subscribe(u,f,h)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[fe]=function(){return this},n);return this.children.set(r,l),l},t.prototype.spawnActor=function(e,r){return this.children.set(r,e),e},t.prototype.spawnActivity=function(e){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[e.type]:void 0;if(!r){W||X(!1,"No implementation found for activity '".concat(e.type,"'"));return}var n=r(this.state.context,e);this.spawnEffect(e.id,n)},t.prototype.spawnEffect=function(e,r){var n;this.children.set(e,(n={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:e}}},n[fe]=function(){return this},n))},t.prototype.attachDev=function(){var e=bt();if(this.options.devTools&&e){if(e.__REDUX_DEVTOOLS_EXTENSION__){var r=typeof this.options.devTools=="object"?this.options.devTools:void 0;this.devTools=e.__REDUX_DEVTOOLS_EXTENSION__.connect(w(w({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:w({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Qn(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[fe]=function(){return this},t.prototype.getSnapshot=function(){return this.status===q.NotStarted?this.initialState:this._state},t.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(e,r){return setTimeout(e,r)},clearTimeout:function(e){return clearTimeout(e)}},logger:console.log.bind(console),devTools:!1},t.interpret=Re,t}();function Re(t,e){var r=new ei(t,e);return r}function ti(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function it(t){return w(w({type:mt},t),{toJSON:function(){t.onDone,t.onError;var e=ht(t,["onDone","onError"]);return w(w({},e),{type:mt,src:ti(t.src)})}})}var Ae="",Ot="#",Ve="*",_e={},be=function(t){return t[0]===Ot},ri=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},ni=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(x(s.target)||pe(s.target))}),i=e===Ae?"the transient event":"event '".concat(e,"'");X(!n,"One or more transitions for ".concat(i," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},ii=function(){function t(e,r,n,i){n===void 0&&(n="context"in e?e.context:void 0);var s=this,o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(ri(),r),this.parent=i==null?void 0:i.parent,this.key=this.config.key||(i==null?void 0:i.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:tr),this.id=this.config.id||G([this.machine.key],N(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,W||X(!("parallel"in this.config),'The "parallel" property is deprecated and will be removed in version 4.1. '.concat(this.config.parallel?"Replace with `type: 'parallel'`":"Use `type: '".concat(this.type,"'`")," in the config for state node '").concat(this.id,"' instead.")),this.initial=this.config.initial,this.states=this.config.states?De(this.config.states,function(f,h){var y,a=new t(f,{},void 0,{parent:s,key:h});return Object.assign(s.idMap,w((y={},y[a.id]=a,y),a.idMap)),a}):_e;var l=0;function u(f){var h,y;f.order=l++;try{for(var a=I(pr(f)),c=a.next();!c.done;c=a.next()){var d=c.value;u(d)}}catch(p){h={error:p}}finally{try{c&&!c.done&&(y=a.return)&&y.call(a)}finally{if(h)throw h.error}}}u(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(f){var h=f.event;return h===Ae}):Ae in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=oe(this.config.entry||this.config.onEntry).map(function(f){return Ce(f)}),this.onExit=oe(this.config.exit||this.config.onExit).map(function(f){return Ce(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=oe(this.config.invoke).map(function(f,h){var y,a;if(pe(f)){var c=Je(s.id,h);return s.machine.options.services=w((y={},y[c]=f,y),s.machine.options.services),it({src:c,id:c})}else if(x(f.src)){var c=f.id||Je(s.id,h);return it(w(w({},f),{id:c,src:f.src}))}else if(pe(f.src)||D(f.src)){var c=f.id||Je(s.id,h);return s.machine.options.services=w((a={},a[c]=f.src,a),s.machine.options.services),it(w(w({id:c},f),{src:c}))}else{var d=f.src;return it(w(w({id:Je(s.id,h)},f),{src:d}))}}),this.activities=oe(this.config.activities).concat(this.invoke).map(function(f){return Rt(f)}),this.transition=this.transition.bind(this),this.tags=oe(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||yr(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,o=n.guards,l=n.services,u=n.delays;return new t(this.config,{actions:w(w({},i),e.actions),activities:w(w({},s),e.activities),guards:w(w({},o),e.guards),services:w(w({},l),e.services),delays:w(w({},u),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return D(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:De(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===Ae,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===Ve});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(s,o){var l=D(s)?"".concat(e.id,":delay[").concat(o,"]"):s,u=Ln(l,e.id);return e.onEntry.push(dr(u,{delay:s})),e.onExit.push(xn(u)),u},i=Ee(r)?r.map(function(s,o){var l=n(s.delay,o);return w(w({},s),{event:l})}):H(Object.keys(r).map(function(s,o){var l=r[s],u=x(l)?{target:l}:l,f=isNaN(+s)?s:+s,h=n(f,o);return oe(u).map(function(y){return w(w({},y),{event:h,delay:f})})}));return i.map(function(s){var o=s.delay;return w(w({},e.formatTransition(s)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof ue?e.value:xe(e,this.delimiter);if(x(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var o=Object.keys(i),l=[this];return l.push.apply(l,G([],N(H(o.map(function(u){return n.getStateNode(u).getStateNodes(i[u])}))),!1)),l},t.prototype.handles=function(e){var r=nr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof ue?e:ue.create(e),n=Array.from(Le([],this.getStateNodes(r.value)));return new ue(w(w({},r),{value:this.resolve(r.value),configuration:n,done:nt(n,this),tags:gr(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var i=this.getStateNode(e),s=i.next(r,n);return!s||!s.transitions.length?this.next(r,n):s},t.prototype.transitionCompoundNode=function(e,r,n){var i=Object.keys(e),s=this.getStateNode(i[0]),o=s._transition(e[i[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var i,s,o={};try{for(var l=I(Object.keys(e)),u=l.next();!u.done;u=l.next()){var f=u.value,h=e[f];if(h){var y=this.getStateNode(f),a=y._transition(h,r,n);a&&(o[f]=a)}}}catch(m){i={error:m}}finally{try{u&&!u.done&&(s=l.return)&&s.call(l)}finally{if(i)throw i.error}}var c=Object.keys(o).map(function(m){return o[m]}),d=H(c.map(function(m){return m.transitions})),p=c.some(function(m){return m.transitions.length>0});if(!p)return this.next(r,n);var E=H(Object.keys(o).map(function(m){return o[m].configuration}));return{transitions:d,exitSet:H(c.map(function(m){return m.exitSet})),configuration:E,source:r,actions:H(Object.keys(o).map(function(m){return o[m].actions}))}},t.prototype._transition=function(e,r,n){return x(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,Q(r))},t.prototype.next=function(e,r){var n,i,s=this,o=r.name,l=[],u=[],f;try{for(var h=I(this.getCandidates(o)),y=h.next();!y.done;y=h.next()){var a=y.value,c=a.cond,d=a.in,p=e.context,E=d?x(d)&&be(d)?e.matches(xe(this.getStateNodeById(d).path,this.delimiter)):Et(xe(d,this.delimiter),gn(this.path.slice(0,-2))(e.value)):!0,m=!1;try{m=!c||lr(this.machine,c,p,r,e)}catch(b){throw new Error("Unable to evaluate guard '".concat(c.name||c.type,"' in transition for event '").concat