@nhost/hasura-storage-js
Version:
Hasura-storage client
16 lines (14 loc) • 64.3 kB
JavaScript
(function(C,X){typeof exports=="object"&&typeof module!="undefined"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(C=typeof globalThis!="undefined"?globalThis:C||self,X(C["@nhost/hasura-storage-js"]={}))})(this,function(C){"use strict";var Gr=Object.defineProperty;var zr=(C,X,te)=>X in C?Gr(C,X,{enumerable:!0,configurable:!0,writable:!0,value:te}):C[X]=te;var oe=(C,X,te)=>zr(C,typeof X!="symbol"?X+"":X,te);var X=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function te(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var qe={exports:{}};(function(t,e){(function(r){function n(a){var i=a&&a.Promise||r.Promise,o=a&&a.XMLHttpRequest||r.XMLHttpRequest;return function(){var u=Object.create(r,{fetch:{value:void 0,writable:!0}});return function(f,l){l(e)}(this,function(f){var l=typeof u!="undefined"&&u||typeof self!="undefined"&&self||typeof l!="undefined"&&l,v={searchParams:"URLSearchParams"in l,iterable:"Symbol"in l&&"iterator"in Symbol,blob:"FileReader"in l&&"Blob"in l&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in l,arrayBuffer:"ArrayBuffer"in l};function w(s){return s&&DataView.prototype.isPrototypeOf(s)}if(v.arrayBuffer)var h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(s){return s&&h.indexOf(Object.prototype.toString.call(s))>-1};function m(s){if(typeof s!="string"&&(s=String(s)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(s)||s==="")throw new TypeError("Invalid character in header field name");return s.toLowerCase()}function g(s){return typeof s!="string"&&(s=String(s)),s}function E(s){var c={next:function(){var b=s.shift();return{done:b===void 0,value:b}}};return v.iterable&&(c[Symbol.iterator]=function(){return c}),c}function y(s){this.map={},s instanceof y?s.forEach(function(c,b){this.append(b,c)},this):Array.isArray(s)?s.forEach(function(c){this.append(c[0],c[1])},this):s&&Object.getOwnPropertyNames(s).forEach(function(c){this.append(c,s[c])},this)}y.prototype.append=function(s,c){s=m(s),c=g(c);var b=this.map[s];this.map[s]=b?b+", "+c:c},y.prototype.delete=function(s){delete this.map[m(s)]},y.prototype.get=function(s){return s=m(s),this.has(s)?this.map[s]:null},y.prototype.has=function(s){return this.map.hasOwnProperty(m(s))},y.prototype.set=function(s,c){this.map[m(s)]=g(c)},y.prototype.forEach=function(s,c){for(var b in this.map)this.map.hasOwnProperty(b)&&s.call(c,this.map[b],b,this)},y.prototype.keys=function(){var s=[];return this.forEach(function(c,b){s.push(b)}),E(s)},y.prototype.values=function(){var s=[];return this.forEach(function(c){s.push(c)}),E(s)},y.prototype.entries=function(){var s=[];return this.forEach(function(c,b){s.push([b,c])}),E(s)},v.iterable&&(y.prototype[Symbol.iterator]=y.prototype.entries);function S(s){if(s.bodyUsed)return i.reject(new TypeError("Already read"));s.bodyUsed=!0}function A(s){return new i(function(c,b){s.onload=function(){c(s.result)},s.onerror=function(){b(s.error)}})}function O(s){var c=new FileReader,b=A(c);return c.readAsArrayBuffer(s),b}function k(s){var c=new FileReader,b=A(c);return c.readAsText(s),b}function N(s){for(var c=new Uint8Array(s),b=new Array(c.length),U=0;U<c.length;U++)b[U]=String.fromCharCode(c[U]);return b.join("")}function G(s){if(s.slice)return s.slice(0);var c=new Uint8Array(s.byteLength);return c.set(new Uint8Array(s)),c.buffer}function H(){return this.bodyUsed=!1,this._initBody=function(s){this.bodyUsed=this.bodyUsed,this._bodyInit=s,s?typeof s=="string"?this._bodyText=s:v.blob&&Blob.prototype.isPrototypeOf(s)?this._bodyBlob=s:v.formData&&FormData.prototype.isPrototypeOf(s)?this._bodyFormData=s:v.searchParams&&URLSearchParams.prototype.isPrototypeOf(s)?this._bodyText=s.toString():v.arrayBuffer&&v.blob&&w(s)?(this._bodyArrayBuffer=G(s.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):v.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(s)||d(s))?this._bodyArrayBuffer=G(s):this._bodyText=s=Object.prototype.toString.call(s):this._bodyText="",this.headers.get("content-type")||(typeof s=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):v.searchParams&&URLSearchParams.prototype.isPrototypeOf(s)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},v.blob&&(this.blob=function(){var s=S(this);if(s)return s;if(this._bodyBlob)return i.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return i.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return i.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var s=S(this);return s||(ArrayBuffer.isView(this._bodyArrayBuffer)?i.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):i.resolve(this._bodyArrayBuffer))}else return this.blob().then(O)}),this.text=function(){var s=S(this);if(s)return s;if(this._bodyBlob)return k(this._bodyBlob);if(this._bodyArrayBuffer)return i.resolve(N(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return i.resolve(this._bodyText)},v.formData&&(this.formData=function(){return this.text().then(I)}),this.json=function(){return this.text().then(JSON.parse)},this}var V=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function $(s){var c=s.toUpperCase();return V.indexOf(c)>-1?c:s}function x(s,c){if(!(this instanceof x))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');c=c||{};var b=c.body;if(s instanceof x){if(s.bodyUsed)throw new TypeError("Already read");this.url=s.url,this.credentials=s.credentials,c.headers||(this.headers=new y(s.headers)),this.method=s.method,this.mode=s.mode,this.signal=s.signal,!b&&s._bodyInit!=null&&(b=s._bodyInit,s.bodyUsed=!0)}else this.url=String(s);if(this.credentials=c.credentials||this.credentials||"same-origin",(c.headers||!this.headers)&&(this.headers=new y(c.headers)),this.method=$(c.method||this.method||"GET"),this.mode=c.mode||this.mode||null,this.signal=c.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&b)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(b),(this.method==="GET"||this.method==="HEAD")&&(c.cache==="no-store"||c.cache==="no-cache")){var U=/([?&])_=[^&]*/;if(U.test(this.url))this.url=this.url.replace(U,"$1_="+new Date().getTime());else{var T=/\?/;this.url+=(T.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}x.prototype.clone=function(){return new x(this,{body:this._bodyInit})};function I(s){var c=new FormData;return s.trim().split("&").forEach(function(b){if(b){var U=b.split("="),T=U.shift().replace(/\+/g," "),D=U.join("=").replace(/\+/g," ");c.append(decodeURIComponent(T),decodeURIComponent(D))}}),c}function z(s){var c=new y,b=s.replace(/\r?\n[\t ]+/g," ");return b.split("\r").map(function(U){return U.indexOf(`
`)===0?U.substr(1,U.length):U}).forEach(function(U){var T=U.split(":"),D=T.shift().trim();if(D){var he=T.join(":").trim();c.append(D,he)}}),c}H.call(x.prototype);function B(s,c){if(!(this instanceof B))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');c||(c={}),this.type="default",this.status=c.status===void 0?200:c.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in c?c.statusText:"",this.headers=new y(c.headers),this.url=c.url||"",this._initBody(s)}H.call(B.prototype),B.prototype.clone=function(){return new B(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},B.error=function(){var s=new B(null,{status:0,statusText:""});return s.type="error",s};var ie=[301,302,303,307,308];B.redirect=function(s,c){if(ie.indexOf(c)===-1)throw new RangeError("Invalid status code");return new B(null,{status:c,headers:{location:s}})},f.DOMException=l.DOMException;try{new f.DOMException}catch{f.DOMException=function(c,b){this.message=c,this.name=b;var U=Error(c);this.stack=U.stack},f.DOMException.prototype=Object.create(Error.prototype),f.DOMException.prototype.constructor=f.DOMException}function ae(s,c){return new i(function(b,U){var T=new x(s,c);if(T.signal&&T.signal.aborted)return U(new f.DOMException("Aborted","AbortError"));var D=new o;function he(){D.abort()}D.onload=function(){var q={status:D.status,statusText:D.statusText,headers:z(D.getAllResponseHeaders()||"")};q.url="responseURL"in D?D.responseURL:q.headers.get("X-Request-URL");var $e="response"in D?D.response:D.responseText;setTimeout(function(){b(new B($e,q))},0)},D.onerror=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},D.ontimeout=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},D.onabort=function(){setTimeout(function(){U(new f.DOMException("Aborted","AbortError"))},0)};function W(q){try{return q===""&&l.location.href?l.location.href:q}catch{return q}}D.open(T.method,W(T.url),!0),T.credentials==="include"?D.withCredentials=!0:T.credentials==="omit"&&(D.withCredentials=!1),"responseType"in D&&(v.blob?D.responseType="blob":v.arrayBuffer&&T.headers.get("Content-Type")&&T.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(D.responseType="arraybuffer")),c&&typeof c.headers=="object"&&!(c.headers instanceof y)?Object.getOwnPropertyNames(c.headers).forEach(function(q){D.setRequestHeader(q,g(c.headers[q]))}):T.headers.forEach(function(q,$e){D.setRequestHeader($e,q)}),T.signal&&(T.signal.addEventListener("abort",he),D.onreadystatechange=function(){D.readyState===4&&T.signal.removeEventListener("abort",he)}),D.send(typeof T._bodyInit=="undefined"?null:T._bodyInit)})}ae.polyfill=!0,l.fetch||(l.fetch=ae,l.Headers=y,l.Request=x,l.Response=B),f.Headers=y,f.Request=x,f.Response=B,f.fetch=ae,Object.defineProperty(f,"__esModule",{value:!0})}),{fetch:u.fetch,Headers:u.Headers,Request:u.Request,Response:u.Response,DOMException:u.DOMException}}()}t.exports=n})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:X)})(qe,qe.exports);var Zt=qe.exports;const ut=te(Zt);var er=typeof self=="object"?self.FormData:window.FormData;const Ge=te(er);let ft=globalThis.fetch;const ze=async(t,e,{accessToken:r,name:n,fileId:a,bucketId:i,adminSecret:o,onUploadProgress:u,headers:f={}}={})=>{var w;const l={...f};i&&e.append("bucket-id",i),o&&(l["x-hasura-admin-secret"]=o),r&&(l.Authorization=`Bearer ${r}`);const v=`${t}/files`;if(typeof XMLHttpRequest=="undefined")try{e instanceof Ge&&(ft=ut().fetch);const h=await ft(v,{method:"POST",headers:l,body:e}),d=await h.json();return h.ok?{fileMetadata:d,error:null}:{error:{status:h.status,message:((w=d==null?void 0:d.error)==null?void 0:w.message)||h.statusText,error:h.statusText},fileMetadata:null}}catch(h){return{error:{status:0,message:h.message,error:h.message},fileMetadata:null}}return new Promise(h=>{let d=new XMLHttpRequest;d.responseType="json",d.onload=()=>{var m,g,E,y,S,A,O,k;if(d.status<200||d.status>=300){const N={error:(S=(y=(g=(m=d.response)==null?void 0:m.error)==null?void 0:g.message)!=null?y:(E=d.response)==null?void 0:E.error)!=null?S:d.response,message:(k=(O=(A=d.response)==null?void 0:A.error)==null?void 0:O.message)!=null?k:d.response,status:d.status};return h({fileMetadata:null,error:N})}return h({fileMetadata:d.response,error:null})},d.onerror=()=>{const m={error:d.statusText,message:d.statusText,status:d.status};return h({fileMetadata:null,error:m})},u&&d.upload.addEventListener("progress",u,!1),d.open("POST",v,!0),Object.entries(l).forEach(([m,g])=>{d.setRequestHeader(m,g)}),d.send(e)})};function Oe(t,e){if(!e||Object.keys(e).length===0)return t;const r=new URL(t),n=Object.entries(e).reduce((a,[i,o])=>({...a,[i.charAt(0)]:o}),{});return Object.entries(n).forEach(([a,i])=>{i&&r.searchParams.set(a,i)}),r.toString()}let pe;typeof pe=="undefined"&&(pe=ut().fetch);class lt{constructor({url:e}){oe(this,"url");oe(this,"accessToken");oe(this,"adminSecret");oe(this,"headers",{});this.url=e}async uploadFormData({formData:e,bucketId:r,headers:n}){const{error:a,fileMetadata:i}=await ze(this.url,e,{bucketId:r,headers:{...this.headers,...n},accessToken:this.accessToken,adminSecret:this.adminSecret});return a?{fileMetadata:null,error:a}:i&&!("processedFiles"in i)?{fileMetadata:{processedFiles:[i]},error:null}:{fileMetadata:i,error:null}}async uploadFile({file:e,bucketId:r,id:n,name:a,headers:i}){const o=typeof window=="undefined"?new Ge:new FormData;o.append("file[]",e),o.append("metadata[]",JSON.stringify({id:n,name:a}));const{error:u,fileMetadata:f}=await ze(this.url,o,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:r,fileId:n,name:a,headers:{...this.headers,...i}});return u?{fileMetadata:null,error:u}:f&&"processedFiles"in f?{fileMetadata:f.processedFiles[0],error:null}:{fileMetadata:f,error:null}}async downloadFile(e){try{const{fileId:r,headers:n,...a}=e,i=Oe(`${this.url}/files/${r}`,a),o=await pe(i,{method:"GET",headers:{...this.generateAuthHeaders(),...this.headers,...n}});if(!o.ok)throw new Error(await o.text());return{file:await o.blob(),error:null}}catch(r){return{file:null,error:r}}}async getPresignedUrl(e){try{const{fileId:r,headers:n}=e,a=await pe(`${this.url}/files/${r}/presignedurl`,{method:"GET",headers:{...this.generateAuthHeaders(),...this.headers,...n}});if(!a.ok)throw new Error(await a.text());return{presignedUrl:await a.json(),error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r,headers:n}=e,a=await pe(`${this.url}/files/${r}`,{method:"DELETE",headers:{...this.generateAuthHeaders(),...this.headers,...n}});if(!a.ok)throw new Error(await a.text());return{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}getHeaders(){return this.headers}setHeaders(e){return e?(this.headers={...this.headers,...e},this):this}unsetHeaders(){const e=this.headers["x-hasura-role"];return this.headers=e?{"x-hasura-role":e}:{},this}generateAuthHeaders(){if(!(!this.adminSecret&&!this.accessToken))return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}class tr{constructor({url:e,adminSecret:r}){oe(this,"url");oe(this,"api");this.url=e,this.api=new lt({url:e}),this.setAdminSecret(r)}async upload(e){return"file"in e?this.api.uploadFile(e):this.api.uploadFormData(e)}getPublicUrl(e){const{fileId:r,...n}=e;return Oe(`${this.url}/files/${r}`,n)}async getPresignedUrl(e){const{fileId:r,headers:n,...a}=e,{presignedUrl:i,error:o}=await this.api.getPresignedUrl(e);if(o)return{presignedUrl:null,error:o};if(!i)return{presignedUrl:null,error:new Error("Invalid file id")};const u=Oe(i.url,a);return{presignedUrl:{...i,url:u},error:null}}async download(e){const{file:r,error:n}=await this.api.downloadFile(e);return n?{file:null,error:n}:r?{file:r,error:null}:{file:null,error:new Error("File does not exist")}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}getHeaders(){return this.api.getHeaders()}setHeaders(e){return this.api.setHeaders(e),this}unsetHeaders(){return this.api.unsetHeaders(),this}}/*! *****************************************************************************
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 p=function(){return p=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},p.apply(this,arguments)};function Xe(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 a=0,n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(r[n[a]]=t[n[a]]);return r}function _(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 j(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),a,i=[],o;try{for(;(e===void 0||e-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(u){o={error:u}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function F(t,e,r){if(arguments.length===2)for(var n=0,a=e.length,i;n<a;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}var R;(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"})(R||(R={}));var se;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(se||(se={}));var Ve=R.Start,Je=R.Stop,ve=R.Raise,Te=R.Send,ct=R.Cancel,dt=R.NullEvent,Pe=R.Assign,rr=R.After,nr=R.DoneState,Ye=R.Log,ht=R.Init,De=R.Invoke,ir=R.ErrorExecution,ar=R.ErrorPlatform,pt=R.ErrorCustom,We=R.Update,vt=R.Choose,yt=R.Pure;const or=Object.freeze(Object.defineProperty({__proto__:null,after:rr,assign:Pe,cancel:ct,choose:vt,doneState:nr,error:pt,errorExecution:ir,errorPlatform:ar,init:ht,invoke:De,log:Ye,nullEvent:dt,pure:yt,raise:ve,send:Te,start:Ve,stop:Je,update:We},Symbol.toStringTag,{value:"Module"}));var gt=".",mt={},Ke="xstate.guard",sr="",Y=process.env.NODE_ENV==="production",je;function Qe(t,e,r){r===void 0&&(r=gt);var n=ye(t,r),a=ye(e,r);return P(a)?P(n)?a===n:!1:P(n)?n in a:Object.keys(n).every(function(i){return i in a?Qe(n[i],a[i]):!1})}function wt(t){try{return P(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 Ze(t,e){try{return me(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function ur(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function ye(t,e){if(ur(t))return t.value;if(me(t))return Re(t);if(typeof t!="string")return t;var r=Ze(t,e);return Re(r)}function Re(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 ge(t,e){for(var r={},n=Object.keys(t),a=0;a<n.length;a++){var i=n[a];r[i]=e(t[i],i,t,a)}return r}function bt(t,e,r){var n,a,i={};try{for(var o=_(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];r(l)&&(i[f]=e(l,f,t))}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}var fr=function(t){return function(e){var r,n,a=e;try{for(var i=_(t),o=i.next();!o.done;o=i.next()){var u=o.value;a=a[u]}}catch(f){r={error:f}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}};function lr(t,e){return function(r){var n,a,i=r;try{for(var o=_(t),u=o.next();!u.done;u=o.next()){var f=u.value;i=i[e][f]}}catch(l){n={error:l}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}}function Ue(t){if(!t)return[[]];if(P(t))return[[t]];var e=M(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Ue(t[r]).map(function(a){return[r].concat(a)})}));return e}function M(t){var e;return(e=[]).concat.apply(e,F([],j(t),!1))}function St(t){return me(t)?t:[t]}function K(t){return t===void 0?[]:St(t)}function Et(t,e,r){var n,a;if(L(t))return t(e,r.data);var i={};try{for(var o=_(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];L(l)?i[f]=l(e,r.data):i[f]=l}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}function cr(t){return/^(done|error)\./.test(t)}function dr(t,e){var r,n,a=j([[],[]],2),i=a[0],o=a[1];try{for(var u=_(t),f=u.next();!f.done;f=u.next()){var l=f.value;e(l)?i.push(l):o.push(l)}}catch(v){r={error:v}}finally{try{f&&!f.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return[i,o]}function xt(t,e){return ge(t.states,function(r,n){if(r){var a=(P(e)?void 0:e[n])||(r?r.current:void 0);if(a)return{current:a,states:xt(r,a)}}})}function hr(t,e){return{current:e,states:xt(t,e)}}function At(t,e,r,n){Y||Q(!!t,"Attempting to update undefined context");var a=t&&r.reduce(function(i,o){var u,f,l=o.assignment,v={state:n,action:o,_event:e},w={};if(L(l))w=l(i,e.data,v);else try{for(var h=_(Object.keys(l)),d=h.next();!d.done;d=h.next()){var m=d.value,g=l[m];w[m]=L(g)?g(i,e.data,v):g}}catch(E){u={error:E}}finally{try{d&&!d.done&&(f=h.return)&&f.call(h)}finally{if(u)throw u.error}}return Object.assign({},i,w)},t);return a}var Q=function(){};Y||(Q=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 me(t){return Array.isArray(t)}function L(t){return typeof t=="function"}function P(t){return typeof t=="string"}function Ot(t,e){if(t)return P(t)?{type:Ke,name:t,predicate:e?e[t]:void 0}:L(t)?{type:Ke,name:t.name,predicate:t}:t}var Tt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();je={},je[Tt]=function(){return this},je[Symbol.observable]=function(){return this};function re(t){return!!t&&"__xstatenode"in t}var pr=function(){var t=0;return function(){return t++,t.toString(16)}}();function et(t,e){return P(t)||typeof t=="number"?p({type:t},e):t}function we(t,e){if(!P(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=et(t);return p({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function ue(t,e){var r=St(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||re(n)?{target:n,event:t}:p(p({},n),{event:t})});return r}function vr(t){if(!(t===void 0||t===sr))return K(t)}function Pt(t,e,r,n,a){var i=t.options.guards,o={state:a,cond:e,_event:n};if(e.type===Ke)return((i==null?void 0:i[e.name])||e.predicate)(r,n.data,o);var u=i==null?void 0:i[e.type];if(!u)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return u(r,n.data,o)}function yr(t){return typeof t=="string"?{type:t}:t}function Ne(t,e){return"".concat(t,":invocation[").concat(e,"]")}function Dt(t){return(t.type===ve||t.type===Te&&t.to===se.Internal)&&typeof t.delay!="number"}var Ie=we({type:ht});function tt(t,e){return e&&e[t]||void 0}function fe(t,e){var r;if(P(t)||typeof t=="number"){var n=tt(t,e);L(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(L(t))r={type:t.name||t.toString(),exec:t};else{var n=tt(t.type,e);if(L(n))r=p(p({},t),{exec:n});else if(n){var a=n.type||t.type;r=p(p(p({},n),t),{type:a})}else r=t}return r}var Z=function(t,e){if(!t)return[];var r=me(t)?t:[t];return r.map(function(n){return fe(n,e)})};function Fe(t){var e=fe(t);return p(p({id:P(t)?t:e.id},e),{type:e.type})}function jt(t,e){return{type:ve,event:typeof t=="function"?t:et(t),delay:e?e.delay:void 0,id:e==null?void 0:e.id}}function Rt(t,e,r,n){var a={_event:r},i=we(L(t.event)?t.event(e,r.data,a):t.event),o;if(P(t.delay)){var u=n&&n[t.delay];o=L(u)?u(e,r.data,a):u}else o=L(t.delay)?t.delay(e,r.data,a):t.delay;return p(p({},t),{type:ve,_event:i,delay:o})}function ne(t,e){return{to:e?e.to:void 0,type:Te,event:L(t)?t:et(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:L(t)?t.name:wt(t)}}function Ut(t,e,r,n){var a={_event:r},i=we(L(t.event)?t.event(e,r.data,a):t.event),o;if(P(t.delay)){var u=n&&n[t.delay];o=L(u)?u(e,r.data,a):u}else o=L(t.delay)?t.delay(e,r.data,a):t.delay;var f=L(t.to)?t.to(e,r.data,a):t.to;return p(p({},t),{to:f,_event:i,event:i.data,delay:o})}function rt(t,e){return ne(t,p(p({},e),{to:se.Parent}))}function gr(t,e,r){return ne(e,p(p({},r),{to:t}))}function mr(){return rt(We)}function wr(t,e){return ne(t,p(p({},e),{to:function(r,n,a){var i=a._event;return i.origin}}))}var br=function(t,e){return{context:t,event:e}};function Sr(t,e){return t===void 0&&(t=br),{type:Ye,label:e,expr:t}}var Nt=function(t,e,r){return p(p({},t),{value:P(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},It=function(t){return{type:ct,sendId:t}};function Ft(t){var e=Fe(t);return{type:R.Start,activity:e,exec:void 0}}function Lt(t){var e=L(t)?t:Fe(t);return{type:R.Stop,activity:e,exec:void 0}}function _t(t,e,r){var n=L(t.activity)?t.activity(e,r.data):t.activity,a=typeof n=="string"?{id:n}:n,i={type:R.Stop,activity:a};return i}var Mt=function(t){return{type:Pe,assignment:t}};function Er(t){return typeof t=="object"&&"type"in t}function Bt(t,e){var r=e?"#".concat(e):"";return"".concat(R.After,"(").concat(t,")").concat(r)}function be(t,e){var r="".concat(R.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ht(t,e){var r="".concat(R.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ct(t,e){var r="".concat(R.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function xr(t){return{type:R.Pure,get:t}}function Ar(t,e){if(!Y&&(!t||typeof t=="function")){var r=t;t=function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var i=typeof r=="function"?r.apply(void 0,F([],j(n),!1)):r;if(!i)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return i}}return ne(function(n,a){return a},p(p({},e),{to:t}))}function Or(t,e){return rt(function(r,n,a){return{type:pt,data:L(t)?t(r,n,a):t}},p(p({},e),{to:se.Parent}))}function Tr(t){return{type:R.Choose,conds:t}}var Pr=function(t){var e,r,n=[];try{for(var a=_(t),i=a.next();!i.done;i=a.next())for(var o=i.value,u=0;u<o.actions.length;){if(o.actions[u].type===Pe){n.push(o.actions[u]),o.actions.splice(u,1);continue}u++}}catch(f){e={error:f}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n};function Le(t,e,r,n,a,i,o){o===void 0&&(o=!1);var u=o?[]:Pr(a),f=u.length?At(r,n,u,e):r,l=o?[r]:void 0,v=[];function w(m,g){var E;switch(g.type){case ve:{var y=Rt(g,f,n,t.options.delays);return i&&typeof y.delay=="number"&&i(y,f,n),y}case Te:var S=Ut(g,f,n,t.options.delays);if(!Y){var A=g.delay;Q(!P(A)||typeof S.delay=="number","No delay reference for delay expression '".concat(A,"' was found on machine '").concat(t.id,"'"))}return i&&S.to!==se.Internal&&(m==="entry"?v.push(S):i(S,f,n)),S;case Ye:{var O=Nt(g,f,n);return i==null||i(O,f,n),O}case vt:{var k=g,N=(E=k.conds.find(function(s){var c=Ot(s.cond,t.options.guards);return!c||Pt(t,c,f,n,i?void 0:e)}))===null||E===void 0?void 0:E.actions;if(!N)return[];var G=j(Le(t,e,f,n,[{type:m,actions:Z(K(N),t.options.actions)}],i,o),2),H=G[0],V=G[1];return f=V,l==null||l.push(f),H}case yt:{var N=g.get(f,n.data);if(!N)return[];var $=j(Le(t,e,f,n,[{type:m,actions:Z(K(N),t.options.actions)}],i,o),2),x=$[0],I=$[1];return f=I,l==null||l.push(f),x}case Je:{var O=_t(g,f,n);return i==null||i(O,r,n),O}case Pe:{f=At(f,n,[g],i?void 0:e),l==null||l.push(f);break}default:var z=fe(g,t.options.actions),B=z.exec;if(i)i(z,f,n);else if(B&&l){var ie=l.length-1,ae=p(p({},z),{exec:function(s){for(var c=[],b=1;b<arguments.length;b++)c[b-1]=arguments[b];B.apply(void 0,F([l[ie]],j(c),!1))}});z=ae}return z}}function h(m){var g,E,y=[];try{for(var S=_(m.actions),A=S.next();!A.done;A=S.next()){var O=A.value,k=w(m.type,O);k&&(y=y.concat(k))}}catch(N){g={error:N}}finally{try{A&&!A.done&&(E=S.return)&&E.call(S)}finally{if(g)throw g.error}}return v.forEach(function(N){i(N,f,n)}),v.length=0,y}var d=M(a.map(h));return[d,f]}const Dr=Object.freeze(Object.defineProperty({__proto__:null,actionTypes:or,after:Bt,assign:Mt,cancel:It,choose:Tr,done:be,doneInvoke:Ht,error:Ct,escalate:Or,forwardTo:Ar,getActionFunction:tt,initEvent:Ie,isActionObject:Er,log:Sr,pure:xr,raise:jt,resolveActions:Le,resolveLog:Nt,resolveRaise:Rt,resolveSend:Ut,resolveStop:_t,respond:wr,send:ne,sendParent:rt,sendTo:gr,sendUpdate:mr,start:Ft,stop:Lt,toActionObject:fe,toActionObjects:Z,toActivityDefinition:Fe},Symbol.toStringTag,{value:"Module"}));var _e=[],jr=function(t,e){_e.push(t);var r=e(t);return _e.pop(),r},Rr=function(t){return t(_e[_e.length-1])};function kt(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[Tt]=function(){return this},e}function Ur(t,e,r,n){var a,i=yr(t.src),o=(a=e==null?void 0:e.options.services)===null||a===void 0?void 0:a[i.type],u=t.data?Et(t.data,r,n):void 0,f=o?$t(o,t.id,u):kt(t.id);return f.meta=t,f}function $t(t,e,r){var n=kt(e);if(n.deferred=!0,re(t)){var a=n.state=jr(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return a}}return n}var Me=function(t){return t.type==="atomic"||t.type==="final"};function qt(t){return Object.keys(t.states).map(function(e){return t.states[e]})}function Se(t){return qt(t).filter(function(e){return e.type!=="history"})}function Gt(t){var e=[t];return Me(t)?e:e.concat(M(Se(t).map(Gt)))}function Ee(t,e){var r,n,a,i,o,u,f,l,v=new Set(t),w=nt(v),h=new Set(e);try{for(var d=_(h),m=d.next();!m.done;m=d.next())for(var g=m.value,E=g.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(V){r={error:V}}finally{try{m&&!m.done&&(n=d.return)&&n.call(d)}finally{if(r)throw r.error}}var y=nt(h);try{for(var S=_(h),A=S.next();!A.done;A=S.next()){var g=A.value;if(g.type==="compound"&&(!y.get(g)||!y.get(g).length))w.get(g)?w.get(g).forEach(function($){return h.add($)}):g.initialStateNodes.forEach(function($){return h.add($)});else if(g.type==="parallel")try{for(var O=(o=void 0,_(Se(g))),k=O.next();!k.done;k=O.next()){var N=k.value;h.has(N)||(h.add(N),w.get(N)?w.get(N).forEach(function($){return h.add($)}):N.initialStateNodes.forEach(function($){return h.add($)}))}}catch($){o={error:$}}finally{try{k&&!k.done&&(u=O.return)&&u.call(O)}finally{if(o)throw o.error}}}}catch(V){a={error:V}}finally{try{A&&!A.done&&(i=S.return)&&i.call(S)}finally{if(a)throw a.error}}try{for(var G=_(h),H=G.next();!H.done;H=G.next())for(var g=H.value,E=g.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(V){f={error:V}}finally{try{H&&!H.done&&(l=G.return)&&l.call(G)}finally{if(f)throw f.error}}return h}function zt(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(Me(n))return n.key}else return{}}var a={};return r.forEach(function(i){a[i.key]=zt(i,e)}),a}function nt(t){var e,r,n=new Map;try{for(var a=_(t),i=a.next();!i.done;i=a.next()){var o=i.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(u){e={error:u}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n}function Nr(t,e){var r=Ee([t],e);return zt(t,nt(r))}function xe(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Ir(t){return F([],j(new Set(M(F([],j(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Be(t,e){return e.type==="compound"?Se(e).some(function(r){return r.type==="final"&&xe(t,r)}):e.type==="parallel"?Se(e).every(function(r){return Be(t,r)}):!1}function Fr(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function Xt(t){return new Set(M(t.map(function(e){return e.tags})))}function Vt(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(P(t)||P(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(a){return Vt(t[a],e[a])})}var ee=function(){function t(e){var r=this,n;this.actions=[],this.activities=mt,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||mt,this.meta=Fr(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 Ir(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=Ie;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=Ie;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="."),P(e))return[e];var a=Object.keys(e);return a.concat.apply(a,F([],j(a.map(function(i){return n.toStrings(e[i],r).map(function(o){return i+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Xe(e,["configuration","transitions","tags","machine"]);return p(p({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Qe(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;Y&&Q(!!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(a){return a.target!==void 0||a.actions.length})},t}(),Jt={sync:!1,autoForward:!1},Yt;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(Yt||(Yt={}));var Lr=function(t){return P(t)?p(p({},Jt),{name:t}):p(p(p({},Jt),{name:pr()}),t)};function _r(t,e){var r=Lr(e);return Rr(function(n){if(!Y){var a=re(t)||L(t);Q(!!n||a,'Attempted to spawn an Actor (ID: "'.concat(re(t)?t.id:"undefined",'") outside of a service. This will have no effect.'))}return n?n.spawn(t,r.name,r):$t(t,r.name)})}function Mr(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function He(t){return p(p({type:De},t),{toJSON:function(){t.onDone,t.onError;var e=Xe(t,["onDone","onError"]);return p(p({},e),{type:De,src:Mr(t.src)})}})}var le="",it="#",Ae="*",ce={},de=function(t){return t[0]===it},Br=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Hr=function(t,e,r){var n=r.slice(0,-1).some(function(i){return!("cond"in i)&&!("in"in i)&&(P(i.target)||re(i.target))}),a=e===le?"the transient event":"event '".concat(e,"'");Q(!n,"One or more transitions for ".concat(a," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},Cr=function(){function t(e,r,n,a){n===void 0&&(n="context"in e?e.context:void 0);var i=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(Br(),r),this.parent=a==null?void 0:a.parent,this.key=this.config.key||(a==null?void 0:a.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:gt),this.id=this.config.id||F([this.machine.key],j(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,Y||Q(!("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?ge(this.config.states,function(l,v){var w,h=new t(l,{},void 0,{parent:i,key:v});return Object.assign(i.idMap,p((w={},w[h.id]=h,w),h.idMap)),h}):ce;var u=0;function f(l){var v,w;l.order=u++;try{for(var h=_(qt(l)),d=h.next();!d.done;d=h.next()){var m=d.value;f(m)}}catch(g){v={error:g}}finally{try{d&&!d.done&&(w=h.return)&&w.call(h)}finally{if(v)throw v.error}}}f(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(l){var v=l.event;return v===le}):le in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=K(this.config.entry||this.config.onEntry).map(function(l){return fe(l)}),this.onExit=K(this.config.exit||this.config.onExit).map(function(l){return fe(l)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=K(this.config.invoke).map(function(l,v){var w,h;if(re(l)){var d=Ne(i.id,v);return i.machine.options.services=p((w={},w[d]=l,w),i.machine.options.services),He({src:d,id:d})}else if(P(l.src)){var d=l.id||Ne(i.id,v);return He(p(p({},l),{id:d,src:l.src}))}else if(re(l.src)||L(l.src)){var d=l.id||Ne(i.id,v);return i.machine.options.services=p((h={},h[d]=l.src,h),i.machine.options.services),He(p(p({id:d},l),{src:d}))}else{var m=l.src;return He(p(p({id:Ne(i.id,v)},l),{src:m}))}}),this.activities=K(this.config.activities).concat(this.invoke).map(function(l){return Fe(l)}),this.transition=this.transition.bind(this),this.tags=K(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Gt(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,a=n.actions,i=n.activities,o=n.guards,u=n.services,f=n.delays;return new t(this.config,{actions:p(p({},a),e.actions),activities:p(p({},i),e.activities),guards:p(p({},o),e.guards),services:p(p({},u),e.services),delays:p(p({},f),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 L(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:ge(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===le,n=this.transitions.filter(function(a){var i=a.eventType===e;return r?i:i||a.eventType===Ae});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(i,o){var u=L(i)?"".concat(e.id,":delay[").concat(o,"]"):i,f=Bt(u,e.id);return e.onEntry.push(ne(f,{delay:i})),e.onExit.push(It(f)),f},a=me(r)?r.map(function(i,o){var u=n(i.delay,o);return p(p({},i),{event:u})}):M(Object.keys(r).map(function(i,o){var u=r[i],f=P(u)?{target:u}:u,l=isNaN(+i)?i:+i,v=n(l,o);return K(f).map(function(w){return p(p({},w),{event:v,delay:l})})}));return a.map(function(i){var o=i.delay;return p(p({},e.formatTransition(i)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var a=e instanceof ee?e.value:ye(e,this.delimiter);if(P(a)){var i=this.getStateNode(a).initial;return i!==void 0?this.getStateNodes((r={},r[a]=i,r)):[this,this.states[a]]}var o=Object.keys(a),u=[this];return u.push.apply(u,F([],j(M(o.map(function(f){return n.getStateNode(f).getStateNodes(a[f])}))),!1)),u},t.prototype.handles=function(e){var r=wt(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof ee?e:ee.create(e),n=Array.from(Ee([],this.getStateNodes(r.value)));return new ee(p(p({},r),{value:this.resolve(r.value),configuration:n,done:Be(n,this),tags:Xt(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var a=this.getStateNode(e),i=a.next(r,n);return!i||!i.transitions.length?this.next(r,n):i},t.prototype.transitionCompoundNode=function(e,r,n){var a=Object.keys(e),i=this.getStateNode(a[0]),o=i._transition(e[a[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var a,i,o={};try{for(var u=_(Object.keys(e)),f=u.next();!f.done;f=u.next()){var l=f.value,v=e[l];if(v){var w=this.getStateNode(l),h=w._transition(v,r,n);h&&(o[l]=h)}}}catch(y){a={error:y}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(a)throw a.error}}var d=Object.keys(o).map(function(y){return o[y]}),m=M(d.map(function(y){return y.transitions})),g=d.some(function(y){return y.transitions.length>0});if(!g)return this.next(r,n);var E=M(Object.keys(o).map(function(y){return o[y].configuration}));return{transitions:m,exitSet:M(d.map(function(y){return y.exitSet})),configuration:E,source:r,actions:M(Object.keys(o).map(function(y){return o[y].actions}))}},t.prototype._transition=function(e,r,n){return P(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,we(r))},t.prototype.next=function(e,r){var n,a,i=this,o=r.name,u=[],f=[],l;try{for(var v=_(this.getCandidates(o)),w=v.next();!w.done;w=v.next()){var h=w.value,d=h.cond,m=h.in,g=e.context,E=m?P(m)&&de(m)?e.matches(ye(this.getStateNodeById(m).path,this.delimiter)):Qe(ye(m,this.delimiter),fr(this.path.slice(0,-2))(e.value)):!0,y=!1;try{y=!d||Pt(this.machine,d,g,r,e)}catch(O){throw new Error("Unable to evaluate guard '".concat(d.name||d.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`':
`).concat(O.message))}if(y&&E){h.target!==void 0&&(f=h.target),u.push.apply(u,F([],j(h.actions),!1)),l=h;break}}}catch(O){n={error:O}}finally{try{w&&!w.done&&(a=v.return)&&a.call(v)}finally{if(n)throw n.error}}if(l){if(!f.length)return{transitions:[l],exitSet:[],configuration:e.value?[this]:[],source:e,actions:u};var S=M(f.map(function(O){return i.getRelativeStateNodes(O,e.historyValue)})),A=!!l.internal;return{transitions:[l],exitSet:A?[]:M(f.map(function(O){return i.getPotentiallyReenteringNodes(O)})),configuration:S,source:e,actions:u}}},t.prototype.getPotentiallyReenteringNodes=function(e){if(this.order<e.order)return[this];for(var r=[],n=this,a=e;n&&n!==a;)r.push(n),n=n.parent;return n!==a?[]:(r.push(a),r)},t.prototype.getActions=function(e,r,n,a,i,o,u){var f,l,v,w,h=this,d=o?Ee([],this.getStateNodes(o.value)):[],m=new Set;try{for(var g=_(Array.from(e).sort(function(x,I){return x.order-I.order})),E=g.next();!E.done;E=g.next()){var y=E.value;(!xe(d,y)||xe(n.exitSet,y)||y.parent&&m.has(y.parent))&&m.add(y)}}catch(x){f={error:x}}finally{try{E&&!E.done&&(l=g.return)&&l.call(g)}finally{if(f)throw f.error}}try{for(var S=_(d),A=S.next();!A.done;A=S.next()){var y=A.value;(!xe(e,y)||xe(n.exitSet,y.parent))&&n.exitSet.push(y)}}catch(x){v={error:x}}finally{try{A&&!A.done&&(w=S.return)&&w.call(S)}finally{if(v)throw v.error}}n.exitSet.sort(function(x,I){return I.order-x.order});var O=Array.from(m).sort(function(x,I){return x.order-I.order}),k=new Set(n.exitSet),N=M(O.map(function(x){var I=[];if(x.type!=="final")return I;var z=x.parent;if(!z.parent)return I;I.push(be(x.id,x.doneData),be(z.id,x.doneData?Et(x.doneData,a,i):void 0));var B=z.parent;return B.type==="parallel"&&Se(B).every(function(ie){return Be(n.configuration,ie)})&&I.push(be(B.id)),I})),G=O.map(function(x){var I=x.onEntry,z=x.activities.map(function(B){return Ft(B)});return{type:"entry",actions:Z(u?F(F([],j(I),!1),j(z),!1):F(F([],j(z),!1),j(I),!1),h.machine.options.actions)}}).concat({type:"state_done",actions:N.map(function(x){return jt(x)})}),H=Array.from(k).map(function(x){return{type:"exit",actions:Z(F(F([],j(x.onExit),!1),j(x.activities.map(function(I){return Lt(I)})),!1),h.machine.options.actions)}}),V=H.concat({type:"transition",actions:Z(n.actions,this.machine.options.actions)}).concat(G);if(r){var $=Z(M(F([],j(e),!1).sort(function(x,I){return I.order-x.order}).map(function(x){return x.onExit})),this.machine.options.actions).filter(function(x){return!Dt(x)});return V.concat({type:"stop",actions:$})}return V},t.prototype.transition=function(e,r,n,a){e===void 0&&(e=this.initialState);var i=we(r),o;if(e instanceof ee)o=n===void 0?e:this.resolveState(ee.from(e,n));else{var u=P(e)?this.resolve(Re(this.getResolvedPath(e))):this.resolve(e),f=n!=null?n:this.machine.context;o=this.resolveState(ee.from(u,f))}if(!Y&&i.name===Ae)throw new Error("An event cannot have the wildcard type ('".concat(Ae,"')"));if(this.strict&&!this.events.includes(i.name)&&!cr(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var l=this._transition(o.value,o,i)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},v=Ee([],this.getStateNodes(o.value)),w=l.configuration.length?Ee(v,l.configuration):v;return l.configuration=F([],j(w),!1),this.resolveTransition(l,o,o.context,a,i)},t.prototype.resolveRaisedTransition=function(e,r,n,a){var i,o=e.actions;return e=this.transition(e,r,void 0,a),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,F([],j(o),!1)),e},t.prototype.resolveTransition=function(e,r,n,a,i){var o,u,f,l,v=this;i===void 0&&(i=Ie);var w=e.configuration,h=!r||e.transitions.length>0,d=h?e.configuration:r?r.configuration:[],m=Be(d,this),g=h?Nr(this.machine,w):void 0,E=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,y=this.getActions(new Set(d),m,e,n,i,r,a),S=r?p({},r.activities):{};try{for(var A=_(y),O=A.next();!O.done;O=A.next()){var k=O.value;try{for(var N=(f=void 0,_(k.actions)),G=N.next();!G.done;G=N.next()){var H=G.value;H.type===Ve?S[H.activity.id||H.activity.type]=H:H.type===Je&&(S[H.activity.id||H.activity.type]=!1)}}catch(W){f={error:W}}finally{try{G&&!G.done&&(l=N.return)&&l.call(N)}finally{if(f)throw f.error}}}}catch(W){o={error:W}}finally{try{O&&!O.done&&(u=A.return)&&u.call(A)}finally{if(o)throw o.error}}var V=j(Le(this,r,n,i,y,a,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),$=V[0],x=V[1],I=j(dr($,Dt),2),z=I[0],B=I[1],ie=$.filter(function(W){var q;return W.type===Ve&&((q=W.activity)===null||q===void 0?void 0:q.type)===De}),ae=ie.reduce(function(W,q){return W[q.activity.id]=Ur(q.activity,v.machine,x,i),W},r?p({},r.children):{}),s=new ee({value:g||r.value,context:x,_event:i,_sessionid:r?r._sessionid:null,historyValue:g?E?hr(E,g):void 0:r?r.historyValue:void 0,history:!g||e.source?r:void 0,actions:g?B:[],activities:g?S:r?r.activities:{},events:[],configuration:d,transitions:e.transitions,children:ae,done:m,tags:Xt(d),machine:this}),c=n!==x;s.cha