Socket
Socket
Sign inDemoInstall

@sanity/preview-kit-compat

Package Overview
Dependencies
Maintainers
56
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-kit-compat - npm Package Compare versions

Comparing version 1.5.8-canary.1 to 1.5.8-canary.2

2

dist/index.d.ts

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

import type {QueryParams} from '@sanity/client'
import type {ContentSourceMapDocuments} from '@sanity/client/csm'
import type {QueryParams} from '@sanity/client'

@@ -4,0 +4,0 @@ /**

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

import{useState as t,useEffect as e,useMemo as n,useSyncExternalStore as s,useCallback as r}from"react";for(var o=[],i=0;i<256;++i)o.push((i+256).toString(16).slice(1));var a,c=new Uint8Array(16);function u(){if(!a&&!(a=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(c)}var f={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function l(t,e,n){if(f.randomUUID&&!e&&!t)return f.randomUUID();var s=(t=t||{}).random||(t.rng||u)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}function h(){const t=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:void 0;if(t.__xstate__)return t.__xstate__}const d=t=>{if(typeof window>"u")return;const e=h();e&&e.register(t)};class p{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const y=".",v="",m="xstate.init",g="xstate.error",b="xstate.stop";function _(t,e){return{type:`xstate.done.state.${t}`,output:e}}function w(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function x(t){return{type:m,input:t}}function S(t){setTimeout((()=>{throw t}))}const k="function"==typeof Symbol&&Symbol.observable||"@@observable";function I(t,e){const n=T(t),s=T(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&I(n[t],s[t])))}function E(t){if(q(t))return t;let e=[],n="";for(let s=0;s<t.length;s++){switch(t.charCodeAt(s)){case 92:n+=t[s+1],s++;continue;case 46:e.push(n),n="";continue}n+=t[s]}return e.push(n),e}function T(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;return function(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}(E(t))}function $(t,e){const n={},s=Object.keys(t);for(let r=0;r<s.length;r++){const o=s[r];n[o]=e(t[o],o,t,r)}return n}function O(t){return q(t)?t:[t]}function A(t){return void 0===t?[]:O(t)}function j(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function q(t){return Array.isArray(t)}function R(t){return O(t).map((t=>typeof t>"u"||"string"==typeof t?{target:t}:t))}function P(t){if(void 0!==t&&t!==v)return A(t)}function N(t,e,n){const s="object"==typeof t,r=s?t:void 0;return{next:(s?t.next:t)?.bind(r),error:(s?t.error:e)?.bind(r),complete:(s?t.complete:n)?.bind(r)}}function M(t,e){return`${e}.${t}`}function L(t,e){const n=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return t.implementations.actors[e];const[,s,r]=n,o=t.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}function D(t,e){return`${t.sessionId}.${e}`}let U=0;const z=1;let J=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const C={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class B{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new p(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=J.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...C,...e},{clock:s,logger:r,parent:o,syncSnapshot:i,id:a,systemId:c,inspect:u}=n;this.system=o?o.system:function(t,e){const n=new Map,s=new Map,r=new WeakMap,o=new Set,i={},{clock:a,logger:c}=e,u={schedule:(t,e,n,s,r=Math.random().toString(36).slice(2))=>{const o={source:t,target:e,event:n,delay:s,id:r,startedAt:Date.now()},c=D(t,r);f._snapshot._scheduledEvents[c]=o;const u=a.setTimeout((()=>{delete i[c],delete f._snapshot._scheduledEvents[c],f._relay(t,e,n)}),s);i[c]=u},cancel:(t,e)=>{const n=D(t,e),s=i[n];delete i[n],delete f._snapshot._scheduledEvents[n],void 0!==s&&a.clearTimeout(s)},cancelAll:t=>{for(const e in f._snapshot._scheduledEvents){const n=f._snapshot._scheduledEvents[e];n.source===t&&u.cancel(t,n.id)}}},f={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+U++,_register:(t,e)=>(n.set(t,e),t),_unregister:t=>{n.delete(t.sessionId);const e=r.get(t);void 0!==e&&(s.delete(e),r.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const n=s.get(t);if(n&&n!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),r.set(e,t)},inspect:t=>{const e=N(t);return o.add(e),{unsubscribe(){o.delete(e)}}},_sendInspectionEvent:e=>{if(!o.size)return;const n={...e,rootId:t.sessionId};o.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:n}),e._send(n)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const t=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const e in t){const{source:n,target:s,event:r,delay:o,id:i}=t[e];u.schedule(n,s,r,o,i)}},_clock:a,_logger:c};return f}(this,{clock:s,logger:r}),u&&!o&&this.system.inspect(N(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=o,this._syncSnapshot=i,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()},emit:t=>{const e=this.eventListeners.get(t.type),n=this.eventListeners.get("*");if(!e&&!n)return;const s=new Set([...e?e.values():[],...n?n.values():[]]);for(const e of Array.from(s))e(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this._systemId=c,this.system._set(c,this)),this._initState(e?.snapshot??e?.state),c&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let n;for(this._snapshot=t;n=this._deferred.shift();)try{n()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){S(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){S(t)}this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${s}`,output:r,actorId:s}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var s,r;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=N(t,e,n);if(this._processingStatus!==J.Stopped)this.observers.add(s);else switch(this._snapshot.status){case"done":try{s.complete?.()}catch(t){S(t)}break;case"error":{const t=this._snapshot.error;if(s.error)try{s.error(t)}catch(t){S(t)}else S(t);break}}return{unsubscribe:()=>{this.observers.delete(s)}}}on(t,e){let n=this.eventListeners.get(t);n||(n=new Set,this.eventListeners.set(t,n));const s=e.bind(void 0);return n.add(s),{unsubscribe:()=>{n.delete(s)}}}start(){if(this._processingStatus===J.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=J.Running;const t=x(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===b&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===J.Stopped?this:(this.mailbox.clear(),this._processingStatus===J.NotStarted?(this._processingStatus=J.Stopped,this):(this.mailbox.enqueue({type:b}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){S(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||S(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){S(t)}}this.observers.clear(),e&&S(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,w(this.id,t))}_stopProcedure(){return this._processingStatus!==J.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new p(this._process.bind(this)),this._processingStatus=J.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==J.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&("function"==typeof t?t:d)(this)}toJSON(){return{xstate$$type:z,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[k](){return this}getSnapshot(){return this._snapshot}}function V(t,...[e]){return new B(t,e)}function W(t,e,n,s,{sendId:r}){return[e,"function"==typeof r?r(n,s):r]}function F(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function Q(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=W,e.execute=F,e}function Y(t,e,n,s,{id:r,systemId:o,src:i,input:a,syncSnapshot:c}){const u="string"==typeof i?L(e.machine,i):i,f="function"==typeof r?r(n):r;let l;return u&&(l=V(u,{id:f,src:i,parent:t.self,syncSnapshot:c,systemId:o,input:"function"==typeof a?a({context:e.context,event:n.event,self:t.self}):a})),[Wt(e,{children:{...e.children,[f]:l}}),{id:r,actorRef:l}]}function G(t,{id:e,actorRef:n}){n&&t.defer((()=>{n._processingStatus!==J.Stopped&&n.start()}))}function H(...[t,{id:e,systemId:n,input:s,syncSnapshot:r=!1}={}]){function o(t,e){}return o.type="snapshot.spawnChild",o.id=e,o.systemId=n,o.src=t,o.input=s,o.syncSnapshot=r,o.resolve=Y,o.execute=G,o}function K(t,e,n,s,{actorRef:r}){const o="function"==typeof r?r(n,s):r,i="string"==typeof o?e.children[o]:o;let a=e.children;return i&&(a={...a},delete a[i.id]),[Wt(e,{children:a}),i]}function X(t,e){if(e){if(t.system._unregister(e),e._processingStatus!==J.Running)return void t.stopChild(e);t.defer((()=>{t.stopChild(e)}))}}function Z(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=K,e.execute=X,e}function tt(t,e,n,s){const{machine:r}=s,o="function"==typeof t,i=o?t:r.implementations.guards["string"==typeof t?t:t.type];if(!o&&!i)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof i)return tt(i,e,n,s);const a={context:e,event:n},c=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:n}):t.params:void 0;return"check"in i?i.check(s,a,i):i(a,c)}const et=t=>"atomic"===t.type||"final"===t.type;function nt(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function st(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function rt(t){const e=new Set(t),n=it(e);for(const t of e)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const n of nt(t))if("history"!==n.type&&!e.has(n)){const t=pt(n);for(const n of t)e.add(n)}}else pt(t).forEach((t=>e.add(t)));for(const t of e){let n=t.parent;for(;n;)e.add(n),n=n.parent}return e}function ot(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(et(t))return t.key}const s={};for(const t of n)s[t.key]=ot(t,e);return s}function it(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function at(t,e){return ot(t,it(rt(e)))}function ct(t,e){return"compound"===e.type?nt(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?nt(e).every((e=>ct(t,e))):"final"===e.type}const ut=t=>"#"===t[0];function ft(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const r=e[n],o="string"==typeof r?{target:r}:r,i=Number.isNaN(+n)?n:+n,a=(e=>{const n=(r=e,o=t.id,{type:`xstate.after.${r}.${o}`}),s=n.type;var r,o;return t.entry.push(Gt(n,{id:s,delay:e})),t.exit.push(Q(s)),s})(i);return A(o).map((t=>({...t,event:a,delay:i})))})).map((e=>{const{delay:n}=e;return{...lt(t,e.event,e),delay:n}}))}function lt(t,e,n){const s=P(n.target),r=n.reenter??!1,o=function(t,e){if(void 0!==e)return e.map((e=>{if("string"!=typeof e)return e;if(ut(e))return t.machine.getStateNodeById(e);const n=e[0]===y;if(n&&!t.parent)return mt(t,e.slice(1));const s=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return mt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,s),i={...n,actions:A(n.actions),guard:n.guard,target:o,source:t,reenter:r,eventType:e,toJSON:()=>({...i,source:`#${t.id}`,target:o?o.map((t=>`#${t.id}`)):void 0})};return i}function ht(t){const e=P(t.config.target);return e?{target:e.map((e=>"string"==typeof e?mt(t.parent,e):e))}:t.parent.initial}function dt(t){return"history"===t.type}function pt(t){const e=yt(t);for(const n of e)for(const s of st(n,t))e.add(s);return e}function yt(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of nt(n))t(e)}(t),e}function vt(t,e){if(ut(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function mt(t,e){if("string"==typeof e&&ut(e))try{return t.machine.getStateNodeById(e)}catch{}const n=E(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=vt(s,t)}return s}function gt(t,e){if("string"==typeof e){const n=t.states[e];if(!n)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,n]}const n=Object.keys(e),s=n.map((e=>vt(t,e))).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce(((n,s)=>{const r=vt(t,s);if(!r)return n;const o=gt(r,e[s]);return n.concat(o)}),[]))}function bt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const r=vt(t,e).next(n,s);return r&&r.length?r:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const r=Object.keys(e),o=bt(vt(t,r[0]),e[r[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const r=[];for(const o of Object.keys(e)){const i=e[o];if(!i)continue;const a=bt(vt(t,o),i,n,s);a&&r.push(...a)}return r.length?r:t.next(n,s)}(t,e,n,s)}function _t(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function wt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function xt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function St(t,e,n){const s=new Set;for(const r of t){let t=!1;const o=new Set;for(const i of s)if(xt(Et([r],e,n),Et([i],e,n))){if(!wt(r.source,i.source)){t=!0;break}o.add(i)}if(!t){for(const t of o)s.delete(t);s.add(r)}}return Array.from(s)}function kt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(dt(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of kt(ht(s),e))n.add(t);else n.add(s);return[...n]}function It(t,e){const n=kt(t,e);if(!n)return;if(!t.reenter&&n.every((e=>e===t.source||wt(e,t.source))))return t.source;const s=function(t){const[e,...n]=t;for(const t of st(e,void 0))if(n.every((e=>wt(e,t))))return t}(n.concat(t.source));return s||(t.reenter?void 0:t.source.machine.root)}function Et(t,e,n){const s=new Set;for(const r of t)if(r.target?.length){const t=It(r,n);r.reenter&&r.source===t&&s.add(t);for(const n of e)wt(n,t)&&s.add(n)}return[...s]}function Tt(t,e,n,s,r,o){if(!t.length)return e;const i=new Set(e._nodes);let a=e.historyValue;const c=St(t,i,a);let u=e;r||([u,a]=function(t,e,n,s,r,o,i){let a=t;const c=Et(s,r,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of _t(t)){let n;n="deep"===e.history?e=>et(e)&&wt(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(r).filter(n)}for(const t of c)a=Pt(a,e,n,[...t.exit,...t.invoke.map((t=>Z(t.id)))],i),r.delete(t);return[a,u||o]}(u,s,n,c,i,a,o)),u=Pt(u,s,n,c.flatMap((t=>t.actions)),o),u=function(t,e,n,s,r,o,i,a){let c=t;const u=new Set,f=new Set;(function(t,e,n,s){for(const r of t){const t=It(r,e);for(const o of r.target||[])!dt(o)&&(r.source!==o||r.source!==t||r.reenter)&&(s.add(o),n.add(o)),Ot(o,e,n,s);const o=kt(r,e);for(const i of o){const o=st(i,t);"parallel"===t?.type&&o.push(t),At(s,e,n,o,!r.source.parent&&r.reenter?void 0:t)}}})(s,i,f,u),a&&f.add(t.machine.root);const l=new Set;for(const t of[...u].sort(((t,e)=>t.order-e.order))){r.add(t);const s=[];s.push(...t.entry);for(const e of t.invoke)s.push(H(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(f.has(t)){const e=t.initial.actions;s.push(...e)}if(c=Pt(c,e,n,s,o,t.invoke.map((t=>t.id))),"final"===t.type){const s=t.parent;let i="parallel"===s?.type?s:s?.parent,a=i||t;for("compound"===s?.type&&o.push(_(s.id,void 0!==t.output?j(t.output,c.context,e,n.self):void 0));"parallel"===i?.type&&!l.has(i)&&ct(r,i);)l.add(i),o.push(_(i.id)),a=i,i=i.parent;if(i)continue;c=Wt(c,{status:"done",output:$t(c,e,n,c.machine.root,a)})}}return c}(u,s,n,c,i,o,a,r);const f=[...i];"done"===u.status&&(u=Pt(u,s,n,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(e._nodes,i)?u:Wt(u,{_nodes:f,historyValue:a})}catch(t){throw t}}function $t(t,e,n,s,r){if(void 0===s.output)return;const o=_(r.id,void 0!==r.output&&r.parent?j(r.output,t.context,e,n.self):void 0);return j(s.output,t.context,o,n.self)}function Ot(t,e,n,s){if(dt(t))if(e[t.id]){const r=e[t.id];for(const t of r)s.add(t),Ot(t,e,n,s);for(const o of r)jt(o,t.parent,s,e,n)}else{const r=ht(t);for(const o of r.target)s.add(o),r===t.parent?.initial&&n.add(t.parent),Ot(o,e,n,s);for(const o of r.target)jt(o,t.parent,s,e,n)}else if("compound"===t.type){const[r]=t.initial.target;dt(r)||(s.add(r),n.add(r)),Ot(r,e,n,s),jt(r,t,s,e,n)}else if("parallel"===t.type)for(const r of nt(t).filter((t=>!dt(t))))[...s].some((t=>wt(t,r)))||(dt(r)||(s.add(r),n.add(r)),Ot(r,e,n,s))}function At(t,e,n,s,r){for(const o of s)if((!r||wt(o,r))&&t.add(o),"parallel"===o.type)for(const s of nt(o).filter((t=>!dt(t))))[...t].some((t=>wt(t,s)))||(t.add(s),Ot(s,e,n,t))}function jt(t,e,n,s,r){At(n,s,r,st(t,e))}let qt=!1;function Rt(t,e,n,s,r,o){const{machine:i}=t;let a=t;for(const t of s){let s=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:"string"==typeof t?t:"object"==typeof t?t.type:t.name||"(anonymous)",params:l}});try{qt=u,u(f,l)}finally{qt=!1}};const c="function"==typeof t,u=c?t:i.implementations.actions["string"==typeof t?t:t.type];if(!u)continue;const f={context:a.context,event:e,self:n.self,system:n.system},l=c||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in u)){n.self._processingStatus===J.Running?s():n.defer((()=>{s()}));continue}const h=u,[d,p,y]=h.resolve(n,a,f,l,u,r);a=d,"retryResolve"in h&&o?.push([h,p]),"execute"in h&&(n.self._processingStatus===J.Running?h.execute(n,p):n.defer(h.execute.bind(null,n,p))),y&&(a=Rt(a,e,n,y,r,o))}return a}function Pt(t,e,n,s,r,o){const i=o?[]:void 0,a=Rt(t,e,n,s,{internalQueue:r,deferredActorIds:o},i);return i?.forEach((([t,e])=>{t.retryResolve(n,a,e)})),a}function Nt(t,e,n,s=[]){let r=t;const o=[];function i(t,e,s){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:e,snapshot:t,_transitions:s}),o.push(t)}if(e.type===b)return r=Wt(Mt(r,e,n),{status:"stopped"}),i(r,e,[]),{snapshot:r,microstates:o};let a=e;if(a.type!==m){const e=a,c=function(t){return t.type.startsWith("xstate.error.actor")}(e),u=Lt(e,r);if(c&&!u.length)return r=Wt(t,{status:"error",error:e.error}),i(r,e,[]),{snapshot:r,microstates:o};r=Tt(u,t,n,a,!1,s),i(r,e,u)}let c=!0;for(;"active"===r.status;){let t=c?Dt(r,a):[];const e=t.length?r:void 0;if(!t.length){if(!s.length)break;a=s.shift(),t=Lt(a,r)}r=Tt(t,r,n,a,!1,s),c=r!==e,i(r,a,t)}return"active"!==r.status&&Mt(r,a,n),{snapshot:r,microstates:o}}function Mt(t,e,n){return Pt(t,e,n,Object.values(t.children).map((t=>Z(t))),[])}function Lt(t,e){return e.machine.getTransitionData(e,t)}function Dt(t,e){const n=new Set,s=t._nodes.filter(et);for(const r of s)t:for(const s of[r].concat(st(r,void 0)))if(s.always)for(const r of s.always)if(void 0===r.guard||tt(r.guard,t.context,e,t)){n.add(r);break t}return St(Array.from(n),new Set(t._nodes),t.historyValue)}const Ut=function(t){return I(t,this.value)},zt=function(t){return this.tags.has(t)},Jt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Ct=function(){const{_nodes:t,tags:e,machine:n,getMeta:s,toJSON:r,can:o,hasTag:i,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Bt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Vt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:at(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Ut,hasTag:zt,can:Jt,getMeta:Bt,toJSON:Ct}}function Wt(t,e={}){return Vt({...t,...e},t.machine)}function Ft(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:z,id:s.id};else{const r=Ft(s);r!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=r)}}return e??t}function Qt(t,e,n,s,{event:r,id:o,delay:i},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof r)throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const u="function"==typeof r?r(n,s):r;let f;if("string"==typeof i){const t=c&&c[i];f="function"==typeof t?t(n,s):t}else f="function"==typeof i?i(n,s):i;return"number"!=typeof f&&a.push(u),[e,{event:u,id:o,delay:f}]}function Yt(t,e){const{event:n,delay:s,id:r}=e;"number"!=typeof s||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,n,s,r)}))}function Gt(t,e){function n(t,e){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Qt,n.execute=Yt,n}const Ht="xstate.observable.error",Kt="xstate.observable.complete";function Xt(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case Ht:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case Kt:return{...t,status:"done",input:void 0,_subscription:void 0};case b:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:n,system:s,emit:r})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:s,self:n,emit:r}).subscribe({next:t=>{n._parent&&s._relay(n,n._parent,t)},error:t=>{s._relay(n,n,{type:Ht,data:t})},complete:()=>{s._relay(n,n,{type:Kt})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}}function Zt(t,{machine:e,context:n},s,r){return(o,i)=>{const a=((o,i={})=>{const{systemId:a,input:c}=i;if("string"==typeof o){const u=L(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=V(u,{id:i.id,parent:t.self,syncSnapshot:i.syncSnapshot,input:"function"==typeof c?c({context:n,event:s,self:t.self}):c,src:o,systemId:a});return r[f.id]=f,f}return V(o,{id:i.id,parent:t.self,syncSnapshot:i.syncSnapshot,input:i.input,src:o,systemId:a})})(o,i);return r[a.id]=a,t.defer((()=>{a._processingStatus!==J.Stopped&&a.start()})),a}}function te(t,e,n,s,{assignment:r}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},i={context:e.context,event:n.event,spawn:Zt(t,e,n.event,o),self:t.self,system:t.system};let a={};if("function"==typeof r)a=r(i,s);else for(const t of Object.keys(r)){const e=r[t];a[t]="function"==typeof e?e(i,s):e}return[Wt(e,{context:Object.assign({},e.context,a),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function ee(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=te,e}function ne(t,e,n,s,{event:r}){return[e,{event:"function"==typeof r?r(n,s):r}]}function se(t,{event:e}){t.defer((()=>t.emit(e)))}function re(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=ne,e.execute=se,e}let oe=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ie(t,e,n,s,{to:r,event:o,id:i,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const f="function"==typeof o?o(n,s):o;let l;if("string"==typeof a){const t=u&&u[a];l="function"==typeof t?t(n,s):t}else l="function"==typeof a?a(n,s):a;const h="function"==typeof r?r(n,s):r;let d;if("string"==typeof h){if(d=h===oe.Parent?t.self._parent:h===oe.Internal?t.self:h.startsWith("#_")?e.children[h.slice(2)]:c.deferredActorIds?.includes(h)?h:e.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else d=h||t.self;return[e,{to:d,event:f,id:i,delay:l}]}function ae(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function ce(t,e){t.defer((()=>{const{to:n,event:s,delay:r,id:o}=e;"number"!=typeof r?t.system._relay(t.self,n,s.type===g?w(t.self.id,s.data):s):t.system.scheduler.schedule(t.self,n,s,r,o)}))}function ue(t,e,n){function s(t,e){}return s.type="xsnapshot.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=ie,s.retryResolve=ae,s.execute=ce,s}function fe(t,e){return ue(oe.Parent,t,e)}function le(t,e,n,s,{collect:r}){const o=[],i=function(t){o.push(t)};return i.assign=(...t)=>{o.push(ee(...t))},i.cancel=(...t)=>{o.push(Q(...t))},i.raise=(...t)=>{o.push(Gt(...t))},i.sendTo=(...t)=>{o.push(ue(...t))},i.sendParent=(...t)=>{o.push(fe(...t))},i.spawnChild=(...t)=>{o.push(H(...t))},i.stopChild=(...t)=>{o.push(Z(...t))},i.emit=(...t)=>{o.push(re(...t))},r({context:n.context,event:n.event,enqueue:i,check:t=>tt(t,e.context,n.event,e),self:t.self,system:t.system},s),[e,void 0,o]}function he(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=le,e}function de(t,e){const n=A(e);if(!n.includes(t.type)){const e=1===n.length?`type "${n[0]}"`:`one of types "${n.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(t)} to have ${e}`)}}const pe=new WeakMap;function ye(t,e,n){let s=pe.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},pe.set(t,s)),s[e]}const ve={},me=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ge{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(y),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?$(this.config.states,((t,e)=>new ge(t,{_parent:this,_key:e,_machine:this.machine}))):ve,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=A(this.config.entry).slice(),this.exit=A(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=A(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(""===n)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,R(s).map((e=>lt(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,R(t.config.onDone).map((e=>lt(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,R(n.onDone).map((e=>lt(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,R(n.onError).map((e=>lt(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,R(n.onSnapshot).map((e=>lt(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=R(this.config.always).map((t=>lt(this,"",t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(me),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(me),eventType:null})}:void 0,history:this.history,states:$(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(me)}))),entry:this.entry.map(me),exit:this.exit.map(me),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return ye(this,"invoke",(()=>A(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,r=t.id??M(this.id,e),o="string"==typeof n?n:`xstate.invoke.${M(this.id,e)}`;return{...t,src:o,id:r,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:r}}}}))))}get on(){return ye(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return ye(this,"delayedTransitions",(()=>ft(this)))}get initial(){return ye(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?A(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type;let s;const r=ye(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],r=s[t];if("*"===e)return t===n.length-1;if(e!==r)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const o of r){const{guard:r}=o,i=t.context;let a=!1;try{a=!r||tt(r,i,e,t)}catch(t){const e="string"==typeof r?r:"object"==typeof r?r.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(a){s=o;break}}return s?[s]:void 0}get events(){return ye(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class be{constructor(t,e){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ge(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:r}=this.implementations;return new be(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const e=(s=this.root,r=t.value,at(s,[...rt(gt(s,r))])),n=rt(gt(this.root,e));var s,r;return Vt({_nodes:[...n],context:t.context||{},children:{},status:ct(n,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,n){return Nt(t,e,n).snapshot}microstep(t,e,n){return Nt(t,e,n).microstates}getTransitionData(t,e){return bt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:s}=this.config,r=Vt({context:"function"!=typeof s&&s?s:{},_nodes:[this.root],children:{},status:"active"},this);return"function"==typeof s?Pt(r,e,t,[ee((({spawn:t,event:e,self:n})=>s({spawn:t,input:e.input,self:n})))],n):r}getInitialSnapshot(t,e){const n=x(e),s=[],r=this.getPreInitialState(t,n,s),o=Tt([{target:[...yt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,n,!0,s),{snapshot:i}=Nt(o,n,t,s);return i}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=E(t),n=e.slice(1),s=ut(e[0])?e[0].slice(1):e[0],r=this.idMap.get(s);if(!r)throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);return mt(r,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:n,tags:s,machine:r,children:o,context:i,can:a,hasTag:c,matches:u,getMeta:f,toJSON:l,...h}=t,d={};for(const t in o){const n=o[t];d[t]={snapshot:n.getPersistedSnapshot(e),src:n.src,systemId:n._systemId,syncSnapshot:n._syncSnapshot}}return{...h,context:Ft(i),children:d}}(t,e)}restoreSnapshot(t,e){const n={},s=t.children;Object.keys(s).forEach((t=>{const r=s[t],o=r.snapshot,i=r.src,a="string"==typeof i?L(this,i):i;if(!a)return;const c=V(a,{id:t,parent:e.self,syncSnapshot:r.syncSnapshot,snapshot:o,src:i,systemId:r.systemId});n[t]=c}));const r=Vt({...t,children:n,_nodes:Array.from(rt(gt(this.root,t.value)))},this);let o=new Set;return function t(e,n){if(!o.has(e)){o.add(e);for(let s in e){const r=e[s];if(r&&"object"==typeof r){if("xstate$$type"in r&&r.xstate$$type===z){e[s]=n[r.id];continue}t(r,n)}}}}(r.context,n),r}}function _e({schemas:t,actors:e,actions:n,guards:s,delays:r}){return{createMachine:o=>function(t,e){return new be(t,e)}({...o,schemas:t},{actors:e,actions:n,guards:s,delays:r})}}var we=function(t,e){return(we=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function xe(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}we(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function Se(t,e,n,s){return new(n||(n=Promise))((function(r,o){function i(t){try{c(s.next(t))}catch(t){o(t)}}function a(t){try{c(s.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((s=s.apply(t,e||[])).next())}))}function ke(t,e){var n,s,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(n=1,s&&(r=2&a[0]?s.return:a[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,a[1])).done)return r;switch(s=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,s=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(r=(r=o.trys).length>0&&r[r.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],s=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Ie(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],s=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ee(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var s,r,o=n.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(s=o.next()).done;)i.push(s.value)}catch(t){r={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i}function Te(t,e,n){if(n||2===arguments.length)for(var s,r=0,o=e.length;r<o;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}function $e(t){return this instanceof $e?(this.v=t,this):new $e(t)}function Oe(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s,r=n.apply(t,e||[]),o=[];return s=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),s[Symbol.asyncIterator]=function(){return this},s;function i(t,e){r[t]&&(s[t]=function(e){return new Promise((function(n,s){o.push([t,e,n,s])>1||a(t,e)}))},e&&(s[t]=e(s[t])))}function a(t,e){try{(n=r[t](e)).value instanceof $e?Promise.resolve(n.value.v).then(c,u):f(o[0][2],n)}catch(t){f(o[0][3],t)}var n}function c(t){a("next",t)}function u(t){a("throw",t)}function f(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}function Ae(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=Ie(t),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(n){e[n]=t[n]&&function(e){return new Promise((function(s,r){(function(t,e,n,s){Promise.resolve(s).then((function(e){t({value:e,done:n})}),e)})(s,r,(e=t[n](e)).done,e.value)}))}}}function je(t){return"function"==typeof t}var qe,Re,Pe=(qe=function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}},(Re=qe((function(t){Error.call(t),t.stack=(new Error).stack}))).prototype=Object.create(Error.prototype),Re.prototype.constructor=Re,Re);function Ne(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var Me=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var t,e,n,s,r;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var i=Ie(o),a=i.next();!a.done;a=i.next()){a.value.remove(this)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}else o.remove(this);var c=this.initialTeardown;if(je(c))try{c()}catch(t){r=t instanceof Pe?t.errors:[t]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var f=Ie(u),l=f.next();!l.done;l=f.next()){var h=l.value;try{De(h)}catch(t){r=r??[],t instanceof Pe?r=Te(Te([],Ee(r)),Ee(t.errors)):r.push(t)}}}catch(t){n={error:t}}finally{try{l&&!l.done&&(s=f.return)&&s.call(f)}finally{if(n)throw n.error}}}if(r)throw new Pe(r)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)De(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Ne(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&Ne(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t;var e}();function Le(t){return t instanceof Me||t&&"closed"in t&&je(t.remove)&&je(t.add)&&je(t.unsubscribe)}function De(t){je(t)?t():t.unsubscribe()}var Ue=void 0,ze=!1,Je={setTimeout:function(t,e){for(var n=[],s=2;s<arguments.length;s++)n[s-2]=arguments[s];return setTimeout.apply(void 0,Te([t,e],Ee(n)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function Ce(t){Je.setTimeout((function(){throw t}))}function Be(){}var Ve=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,Le(e)&&e.add(n)):n.destination=He,n}return xe(e,t),e.create=function(t,e,n){return new Ye(t,e,n)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Me),We=Function.prototype.bind;function Fe(t,e){return We.call(t,e)}var Qe=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){Ge(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){Ge(t)}else Ge(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){Ge(t)}},t}(),Ye=function(t){function e(e,n,s){var r,o,i=t.call(this)||this;je(e)||!e?r={next:e??void 0,error:n??void 0,complete:s??void 0}:i&&ze?((o=Object.create(e)).unsubscribe=function(){return i.unsubscribe()},r={next:e.next&&Fe(e.next,o),error:e.error&&Fe(e.error,o),complete:e.complete&&Fe(e.complete,o)}):r=e;return i.destination=new Qe(r),i}return xe(e,t),e}(Ve);function Ge(t){Ce(t)}var He={closed:!0,next:Be,error:function(t){throw t},complete:Be},Ke="function"==typeof Symbol&&Symbol.observable||"@@observable";function Xe(t){return t}function Ze(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return tn(t)}function tn(t){return 0===t.length?Xe:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var en=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var s,r=this,o=(s=t)&&s instanceof Ve||function(t){return t&&je(t.next)&&je(t.error)&&je(t.complete)}(s)&&Le(s)?t:new Ye(t,e,n);return function(){var t=r,e=t.operator,n=t.source;o.add(e?e.call(o,n):n?r._subscribe(o):r._trySubscribe(o))}(),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=nn(e))((function(e,s){var r=new Ye({next:function(e){try{t(e)}catch(t){s(t),r.unsubscribe()}},error:s,complete:e});n.subscribe(r)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[Ke]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return tn(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=nn(t))((function(t,n){var s;e.subscribe((function(t){return s=t}),(function(t){return n(t)}),(function(){return t(s)}))}))},t.create=function(e){return new t(e)},t}();function nn(t){var e;return null!==(e=t??Ue)&&void 0!==e?e:Promise}function sn(t){return function(e){if(function(t){return je(t?.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function rn(t,e,n,s,r){return new on(t,e,n,s,r)}var on=function(t){function e(e,n,s,r,o,i){var a=t.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=i,a._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=r?function(t){try{r(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=s?function(){try{s()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return xe(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}(Ve),an=new en((function(t){return t.complete()})),cn=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};var un="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function fn(t){if(t instanceof en)return t;if(null!=t){if(function(t){return je(t[Ke])}(t))return o=t,new en((function(t){var e=o[Ke]();if(je(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(cn(t))return r=t,new en((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(s=t,je(s?.then))return n=t,new en((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,Ce)}));if(function(t){return Symbol.asyncIterator&&je(t?.[Symbol.asyncIterator])}(t))return ln(t);if(function(t){return je(t?.[un])}(t))return e=t,new en((function(t){var n,s;try{for(var r=Ie(e),o=r.next();!o.done;o=r.next()){var i=o.value;if(t.next(i),t.closed)return}}catch(t){n={error:t}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(n)throw n.error}}t.complete()}));if(function(t){return je(t?.getReader)}(t))return ln(function(t){return Oe(this,arguments,(function(){var e,n,s;return ke(this,(function(r){switch(r.label){case 0:e=t.getReader(),r.label=1;case 1:r.trys.push([1,,9,10]),r.label=2;case 2:return[4,$e(e.read())];case 3:return n=r.sent(),s=n.value,n.done?[4,$e(void 0)]:[3,5];case 4:return[2,r.sent()];case 5:return[4,$e(s)];case 6:return[4,r.sent()];case 7:return r.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t))}var e,n,s,r,o;throw function(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}(t)}function ln(t){return new en((function(e){(function(t,e){var n,s,r,o;return Se(this,void 0,void 0,(function(){var i,a;return ke(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=Ae(t),c.label=1;case 1:return[4,n.next()];case 2:if((s=c.sent()).done)return[3,4];if(i=s.value,e.next(i),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),r={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),s&&!s.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(r)throw r.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function hn(t,e){return sn((function(n,s){var r=0;n.subscribe(rn(s,(function(n){s.next(t.call(e,n,r++))})))}))}var dn=Array.isArray;function pn(t){return hn((function(e){return function(t,e){return dn(e)?t.apply(void 0,Te([],Ee(e))):t(e)}(t,e)}))}function yn(t,e,n){return void 0===n&&(n=1/0),je(e)?yn((function(n,s){return hn((function(t,r){return e(n,t,s,r)}))(fn(t(n,s)))}),n):("number"==typeof e&&(n=e),sn((function(e,s){return function(t,e,n,s,r,o,i){var a=[],c=0,u=0,f=!1,l=function(){f&&!a.length&&!c&&e.complete()},h=function(t){c++;var r=!1;fn(n(t,u++)).subscribe(rn(e,(function(t){e.next(t)}),(function(){r=!0}),void 0,(function(){if(r)try{for(c--;a.length&&c<s;)t=void 0,t=a.shift(),i||h(t);l()}catch(t){e.error(t)}var t})))};return t.subscribe(rn(e,(function(t){return c<s?h(t):a.push(t)}),(function(){f=!0,l()}))),function(){}}(e,s,t,n)})))}var vn=["addListener","removeListener"],mn=["addEventListener","removeEventListener"],gn=["on","off"];function bn(t,e,n,s){if(je(n)&&(s=n,n=void 0),s)return bn(t,e,n).pipe(pn(s));var r=Ee(function(t){return je(t.addEventListener)&&je(t.removeEventListener)}(t)?mn.map((function(s){return function(r){return t[s](e,r,n)}})):function(t){return je(t.addListener)&&je(t.removeListener)}(t)?vn.map(_n(t,e)):function(t){return je(t.on)&&je(t.off)}(t)?gn.map(_n(t,e)):[],2),o=r[0],i=r[1];if(!o&&cn(t))return yn((function(t){return bn(t,e,n)}))(fn(t));if(!o)throw new TypeError("Invalid event target");return new en((function(t){var e=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.next(1<e.length?e:e[0])};return o(e),function(){return i(e)}}))}function _n(t,e){return function(n){return function(s){return t[n](e,s)}}}function wn(t,e){return sn((function(n,s){var r=0;n.subscribe(rn(s,(function(n){return t.call(e,n,r++)&&s.next(n)})))}))}function xn(t){return t<=0?function(){return an}:sn((function(e,n){var s=0;e.subscribe(rn(n,(function(e){++s<=t&&(n.next(e),t<=s&&n.complete())})))}))}const Sn=t=>({context:e})=>{const{count:n,include:s,exclude:r,responseType:o="message.received"}=t;return{count:n,domain:e.domain,from:e.connectTo,include:s?Array.isArray(s)?s:[s]:[],exclude:r?Array.isArray(r)?r:[r]:[],responseType:o,target:e.target,to:e.name}},kn=(qn=()=>bn(window,"message"),new en((function(t){fn(qn()).subscribe(t)}))),In=t=>Xt((({input:t})=>{return kn.pipe(Ze(),wn((t=>e=>{const{data:n}=e;return(!t.include.length||t.include.includes(n.type))&&(!t.exclude.length||!t.exclude.includes(n.type))&&n.domain===t.domain&&n.from===t.from&&n.to===t.to&&(!t.target||e.source===t.target)})(t)),hn((o=t.responseType,t=>({type:o,message:t}))),t.count?Ze((s=t.count,void 0===r&&(r=null),r=r??s,sn((function(t,e){var n=[],o=0;t.subscribe(rn(e,(function(t){var i,a,c,u,f=null;o++%r==0&&n.push([]);try{for(var l=Ie(n),h=l.next();!h.done;h=l.next())(y=h.value).push(t),s<=y.length&&(f=f??[]).push(y)}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=l.return)&&a.call(l)}finally{if(i)throw i.error}}if(f)try{for(var d=Ie(f),p=d.next();!p.done;p=d.next()){var y=p.value;Ne(n,y),e.next(y)}}catch(t){c={error:t}}finally{try{p&&!p.done&&(u=d.return)&&u.call(d)}finally{if(c)throw c.error}}}),(function(){var t,s;try{for(var r=Ie(n),o=r.next();!o.done;o=r.next()){var i=o.value;e.next(i)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(t)throw t.error}}e.complete()}),void 0,(function(){n=null})))}))),(e=t=>t,je(n)?yn(e,n,1):yn(e,1)),xn(t.count)):Ze());var e,n,s,r,o})),En="comlink/response",Tn="comlink/heartbeat",$n="comlink/disconnect",On="comlink/handshake/ack",An=()=>_e({types:{},actors:{listen:Xt((({input:t})=>{return bn(window,"message").pipe(wn((e=>e.data.type===En&&e.data.responseTo===t.requestId&&!!e.source&&t.sources.has(e.source))),xn(t.sources.size),t.signal?(o=bn(t.signal,"abort"),sn((function(t,e){fn(o).subscribe(rn(e,(function(){return e.complete()}),Be)),!e.closed&&t.subscribe(e)}))):(r=je(e)||n||s?{next:e,error:n,complete:s}:e)?sn((function(t,e){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var s=!0;t.subscribe(rn(e,(function(t){var n;null===(n=r.next)||void 0===n||n.call(r,t),e.next(t)}),(function(){var t;s=!1,null===(t=r.complete)||void 0===t||t.call(r),e.complete()}),(function(t){var n;s=!1,null===(n=r.error)||void 0===n||n.call(r,t),e.error(t)}),(function(){var t,e;s&&(null===(t=r.unsubscribe)||void 0===t||t.call(r)),null===(e=r.finalize)||void 0===e||e.call(r)})))})):Xe);var e,n,s,r,o}))},actions:{"send message":({context:t},e)=>{const{sources:n,targetOrigin:s}=t,{message:r}=e;n.forEach((t=>{t.postMessage(r,{targetOrigin:s})}))},"on success":fe((({context:t,self:e})=>(t.response&&t.resolvable?.resolve(t.response),{type:"request.success",requestId:e.id,response:t.response,responseTo:t.responseTo}))),"on fail":fe((({context:t,self:e})=>(console.warn(`Received no response to message '${t.type}' on client '${t.from}' (ID: '${t.id}').`),t.resolvable?.reject(new Error("No response received")),{type:"request.failed",requestId:e.id}))),"on abort":fe((({context:t,self:e})=>(console.log("on abort..."),t.resolvable?.reject(new Error("Request aborted")),{type:"request.aborted",requestId:e.id})))},guards:{expectsResponse:({context:t})=>t.expectResponse},delays:{initialTimeout:0,responseTimeout:1e3}}).createMachine({context:({input:t})=>({connectionId:t.connectionId,data:t.data,domain:t.domain,expectResponse:t.expectResponse??!1,from:t.from,id:`msg-${l()}`,resolvable:t.resolvable,response:null,responseTo:t.responseTo,signal:t.signal,sources:t.sources instanceof Set?t.sources:new Set([t.sources]),targetOrigin:t.targetOrigin,to:t.to,type:t.type}),initial:"idle",on:{abort:".aborted"},states:{idle:{after:{initialTimeout:[{target:"sending"}]}},sending:{entry:{type:"send message",params:({context:t})=>{const{connectionId:e,data:n,domain:s,from:r,id:o,responseTo:i,to:a,type:c}=t;return{message:{connectionId:e,data:n,domain:s,from:r,id:o,to:a,type:c,responseTo:i}}}},always:[{guard:"expectsResponse",target:"awaiting"},"success"]},awaiting:{invoke:{id:"listen for response",src:"listen",input:({context:t})=>({requestId:t.id,sources:t.sources,signal:t.signal})},after:{responseTimeout:"failed"},on:{message:{actions:ee({response:({event:t})=>t.data.data,responseTo:({event:t})=>t.data.responseTo}),target:"success"}}},failed:{type:"final",entry:"on fail"},success:{type:"final",entry:"on success"},aborted:{type:"final",entry:"on abort"}},output:({context:t,self:e})=>({requestId:e.id,response:t.response,responseTo:t.responseTo})}),jn=(t,e=(()=>_e({types:{},actors:{requestMachine:An(),listen:In()},actions:{"buffer incoming message":ee({handshakeBuffer:({event:t,context:e})=>(de(t,"message.received"),[...e.handshakeBuffer,t])}),"buffer message":he((({enqueue:t})=>{t.assign({buffer:({event:t,context:e})=>(de(t,"post"),[...e.buffer,{data:t.data,resolvable:t.resolvable,signal:t.signal}])}),t.emit((({event:t})=>(de(t,"post"),{type:"_buffer.added",message:t.data})))})),"create request":ee({requests:({context:t,event:e,spawn:n})=>{de(e,"request");const s=(Array.isArray(e.data)?e.data:[e.data]).map((e=>{const s=`req-${l()}`;return n("requestMachine",{id:s,input:{connectionId:t.connectionId,data:e.data,domain:t.domain,expectResponse:e.expectResponse,from:t.name,resolvable:e.resolvable,responseTo:e.responseTo,sources:t.target,targetOrigin:t.targetOrigin,to:t.connectTo,type:e.type,signal:e.signal}})}));return[...t.requests,...s]}}),"emit heartbeat":re((()=>({type:"_heartbeat"}))),"emit received message":he((({enqueue:t})=>{t.emit((({event:t})=>(de(t,"message.received"),{type:"_message",message:t.message.data}))),t.emit((({event:t})=>(de(t,"message.received"),{type:t.message.data.type,message:t.message.data})))})),"flush buffer":he((({enqueue:t})=>{t.raise((({context:t})=>({type:"request",data:t.buffer.map((({data:t,resolvable:e,signal:n})=>({data:t.data,type:t.type,expectResponse:!!e,resolvable:e,signal:n})))}))),t.emit((({context:t})=>({type:"_buffer.flushed",messages:t.buffer.map((({data:t})=>t))}))),t.assign({buffer:[]})})),"flush handshake buffer":he((({context:t,enqueue:e})=>{t.handshakeBuffer.forEach((t=>e.raise(t))),e.assign({handshakeBuffer:[]})})),post:Gt((({event:t})=>(de(t,"post"),{type:"request",data:{data:t.data.data,expectResponse:!!t.resolvable,type:t.data.type,resolvable:t.resolvable,signal:t.signal}}))),"remove request":he((({context:t,enqueue:e,event:n})=>{de(n,["request.success","request.failed"]),Z(n.requestId),e.assign({requests:t.requests.filter((({id:t})=>t!==n.requestId))})})),"send response":Gt((({event:t})=>(de(t,["message.received","heartbeat.received"]),{type:"request",data:{type:En,responseTo:t.message.data.id,data:void 0}}))),"send handshake syn ack":Gt({type:"request",data:{type:"comlink/handshake/syn-ack"}}),"set connection config":ee({connectionId:({event:t})=>(de(t,"message.received"),t.message.data.connectionId),target:({event:t})=>(de(t,"message.received"),t.message.source||void 0),targetOrigin:({event:t})=>(de(t,"message.received"),t.message.origin)})},guards:{hasSource:({context:t})=>null!==t.target}}).createMachine({id:"node",context:({input:t})=>({buffer:[],connectionId:null,connectTo:t.connectTo,domain:t.domain??"sanity/comlink",handshakeBuffer:[],name:t.name,requests:[],target:void 0,targetOrigin:null}),on:{"request.success":{actions:"remove request"},"request.failed":{actions:"remove request"}},initial:"idle",states:{idle:{invoke:{id:"listen for handshake syn",src:"listen",input:Sn({include:"comlink/handshake/syn",count:1}),onDone:{target:"handshaking",guard:"hasSource"}},on:{"message.received":{actions:"set connection config"},post:{actions:"buffer message"}}},handshaking:{entry:"send handshake syn ack",invoke:[{id:"listen for handshake ack",src:"listen",input:Sn({include:On,count:1}),onDone:"connected"},{id:"listen for disconnect",src:"listen",input:Sn({include:$n,count:1,responseType:"disconnect"})},{id:"listen for messages",src:"listen",input:Sn({exclude:[$n,On,Tn,En]})}],on:{request:{actions:"create request"},post:{actions:"buffer message"},"message.received":{actions:"buffer incoming message"},disconnect:{target:"idle"}}},connected:{entry:["flush handshake buffer","flush buffer"],invoke:[{id:"listen for messages",src:"listen",input:Sn({exclude:[En,Tn]})},{id:"listen for heartbeat",src:"listen",input:Sn({include:Tn,responseType:"heartbeat.received"})},{id:"listen for disconnect",src:"listen",input:Sn({include:$n,count:1,responseType:"disconnect"})}],on:{request:{actions:"create request"},post:{actions:"post"},disconnect:{target:"idle"},"message.received":{actions:["send response","emit received message"]},"heartbeat.received":{actions:["send response","emit heartbeat"]}}}}}))())=>{const n=V(e,{input:t}),s=()=>{n.stop()};return{actor:n,fetch:(t,e)=>{const s=Promise.withResolvers();return n.send({type:"post",data:t,resolvable:s,signal:e?.signal}),s.promise},machine:e,on:(t,e)=>{const{unsubscribe:s}=n.on(t,(t=>{e(t.message.data)}));return s},onStatus:t=>{const e=n.getSnapshot();let s="string"==typeof e.value?e.value:Object.keys(e.value)[0];const{unsubscribe:r}=n.subscribe((e=>{const n="string"==typeof e.value?e.value:Object.keys(e.value)[0];s!==n&&(s=n,t(n))}));return r},post:t=>{n.send({type:"post",data:t})},start:()=>(n.start(),s),stop:s}};var qn;function Rn(n,s,r){const[o,i]=t(null),[a,c]=t(!1);e((()=>{if(window.self===window.top&&!window.opener)return;const t=jn({name:"preview-kit",connectTo:"presentation"});t.onStatus((t=>{"connected"===t?c(!0):"disconnected"===t&&c(!1)}));const e=setTimeout((()=>i(t)),0),n=t.start();return()=>{n(),i(null),clearTimeout(e)}}),[r,s]);const u=JSON.stringify(Array.from(n.keys()));e((()=>{"[]"!==u&&o&&a&&o.post({type:"preview-kit/documents",data:{projectId:s,dataset:r,perspective:"previewDrafts",documents:Array.from(n.values())}})}),[u,o,a,r,n,s])}function Pn(t){const e=n((()=>JSON.stringify(t||{})),[t]);return n((()=>JSON.parse(e)),[e])}function Nn(n){const{refreshInterval:o}=n,i=function(){const[n,r]=t(!1);e((()=>{r(navigator.onLine);const t=()=>r(!0),e=()=>r(!1);return window.addEventListener("online",t),window.addEventListener("offline",e),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",e)}}),[]);const o=s(Mn,(()=>document.visibilityState),(()=>"hidden"));return!n||"hidden"===o}(),[a,c]=t("hit"),u=r((()=>(c("inflight"),()=>c("hit"))),[]);return e((()=>{if(!o||"hit"!==a)return;const t=setTimeout((()=>c("stale")),o);return()=>clearTimeout(t)}),[o,a]),e((()=>{if("hit"!==a)return;const t=()=>c("stale");return window.addEventListener("focus",t),()=>window.removeEventListener("focus",t)}),[o,a]),e((()=>{i&&"hit"===a&&c("stale"),!i&&"stale"===a&&c("refresh")}),[i,a]),[a,u]}function Mn(t){return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)}export{Rn as useDocumentsInUse,Pn as useQueryParams,Nn as useRevalidate};//# sourceMappingURL=index.js.map
import{useState as t,useEffect as e,useMemo as n,useSyncExternalStore as s,useCallback as r}from"react";for(var o=[],i=0;i<256;++i)o.push((i+256).toString(16).slice(1));var a,c=new Uint8Array(16);function u(){if(!a&&!(a=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(c)}var f={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function h(t,e,n){if(f.randomUUID&&!e&&!t)return f.randomUUID();var s=(t=t||{}).random||(t.rng||u)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}function l(){const t=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:void 0;if(t.__xstate__)return t.__xstate__}const d=t=>{if(typeof window>"u")return;const e=l();e&&e.register(t)};class p{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const y="xstate.init",v="xstate.stop";function m(t,e){return{type:`xstate.done.state.${t}`,output:e}}function g(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function b(t){return{type:y,input:t}}function _(t){setTimeout((()=>{throw t}))}const w="function"==typeof Symbol&&Symbol.observable||"@@observable";function x(t,e){const n=k(t),s=k(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&x(n[t],s[t])))}function S(t){if(O(t))return t;let e=[],n="";for(let s=0;s<t.length;s++){switch(t.charCodeAt(s)){case 92:n+=t[s+1],s++;continue;case 46:e.push(n),n="";continue}n+=t[s]}return e.push(n),e}function k(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;return function(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}(S(t))}function I(t,e){const n={},s=Object.keys(t);for(let r=0;r<s.length;r++){const o=s[r];n[o]=e(t[o],o,t,r)}return n}function E(t){return O(t)?t:[t]}function T(t){return void 0===t?[]:E(t)}function $(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function O(t){return Array.isArray(t)}function q(t){return E(t).map((t=>typeof t>"u"||"string"==typeof t?{target:t}:t))}function A(t){if(void 0!==t&&""!==t)return T(t)}function j(t,e,n){const s="object"==typeof t,r=s?t:void 0;return{next:(s?t.next:t)?.bind(r),error:(s?t.error:e)?.bind(r),complete:(s?t.complete:n)?.bind(r)}}function R(t,e){return`${e}.${t}`}function P(t,e){const n=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return t.implementations.actors[e];const[,s,r]=n,o=t.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}function N(t,e){return`${t.sessionId}.${e}`}let M=0;let L=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const D={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class U{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new p(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=L.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...D,...e},{clock:s,logger:r,parent:o,syncSnapshot:i,id:a,systemId:c,inspect:u}=n;this.system=o?o.system:function(t,e){const n=new Map,s=new Map,r=new WeakMap,o=new Set,i={},{clock:a,logger:c}=e,u={schedule:(t,e,n,s,r=Math.random().toString(36).slice(2))=>{const o={source:t,target:e,event:n,delay:s,id:r,startedAt:Date.now()},c=N(t,r);f._snapshot._scheduledEvents[c]=o;const u=a.setTimeout((()=>{delete i[c],delete f._snapshot._scheduledEvents[c],f._relay(t,e,n)}),s);i[c]=u},cancel:(t,e)=>{const n=N(t,e),s=i[n];delete i[n],delete f._snapshot._scheduledEvents[n],void 0!==s&&a.clearTimeout(s)},cancelAll:t=>{for(const e in f._snapshot._scheduledEvents){const n=f._snapshot._scheduledEvents[e];n.source===t&&u.cancel(t,n.id)}}},f={_snapshot:{_scheduledEvents:(e?.snapshot&&e.snapshot.scheduler)??{}},_bookId:()=>"x:"+M++,_register:(t,e)=>(n.set(t,e),t),_unregister:t=>{n.delete(t.sessionId);const e=r.get(t);void 0!==e&&(s.delete(e),r.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const n=s.get(t);if(n&&n!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),r.set(e,t)},inspect:t=>{const e=j(t);return o.add(e),{unsubscribe(){o.delete(e)}}},_sendInspectionEvent:e=>{if(!o.size)return;const n={...e,rootId:t.sessionId};o.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:n}),e._send(n)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const t=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const e in t){const{source:n,target:s,event:r,delay:o,id:i}=t[e];u.schedule(n,s,r,o,i)}},_clock:a,_logger:c};return f}(this,{clock:s,logger:r}),u&&!o&&this.system.inspect(j(u)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=o,this._syncSnapshot=i,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()},emit:t=>{const e=this.eventListeners.get(t.type),n=this.eventListeners.get("*");if(!e&&!n)return;const s=new Set([...e?e.values():[],...n?n.values():[]]);for(const e of Array.from(s))e(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this._systemId=c,this.system._set(c,this)),this._initState(e?.snapshot??e?.state),c&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let n;for(this._snapshot=t;n=this._deferred.shift();)try{n()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){_(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){_(t)}this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${s}`,output:r,actorId:s}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var s,r;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=j(t,e,n);if(this._processingStatus!==L.Stopped)this.observers.add(s);else switch(this._snapshot.status){case"done":try{s.complete?.()}catch(t){_(t)}break;case"error":{const t=this._snapshot.error;if(s.error)try{s.error(t)}catch(t){_(t)}else _(t);break}}return{unsubscribe:()=>{this.observers.delete(s)}}}on(t,e){let n=this.eventListeners.get(t);n||(n=new Set,this.eventListeners.set(t,n));const s=e.bind(void 0);return n.add(s),{unsubscribe:()=>{n.delete(s)}}}start(){if(this._processingStatus===L.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=L.Running;const t=b(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===v&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===L.Stopped?this:(this.mailbox.clear(),this._processingStatus===L.NotStarted?(this._processingStatus=L.Stopped,this):(this.mailbox.enqueue({type:v}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){_(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||_(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){_(t)}}this.observers.clear(),e&&_(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,g(this.id,t))}_stopProcedure(){return this._processingStatus!==L.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new p(this._process.bind(this)),this._processingStatus=L.Stopped,this.system._unregister(this)),this}_send(t){this._processingStatus!==L.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&("function"==typeof t?t:d)(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[w](){return this}getSnapshot(){return this._snapshot}}function z(t,...[e]){return new U(t,e)}function J(t,e,n,s,{sendId:r}){return[e,"function"==typeof r?r(n,s):r]}function C(t,e){t.defer((()=>{t.system.scheduler.cancel(t.self,e)}))}function B(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=J,e.execute=C,e}function V(t,e,n,s,{id:r,systemId:o,src:i,input:a,syncSnapshot:c}){const u="string"==typeof i?P(e.machine,i):i,f="function"==typeof r?r(n):r;let h;return u&&(h=z(u,{id:f,src:i,parent:t.self,syncSnapshot:c,systemId:o,input:"function"==typeof a?a({context:e.context,event:n.event,self:t.self}):a})),[Jt(e,{children:{...e.children,[f]:h}}),{id:r,actorRef:h}]}function W(t,{id:e,actorRef:n}){n&&t.defer((()=>{n._processingStatus!==L.Stopped&&n.start()}))}function F(...[t,{id:e,systemId:n,input:s,syncSnapshot:r=!1}={}]){function o(t,e){}return o.type="snapshot.spawnChild",o.id=e,o.systemId=n,o.src=t,o.input=s,o.syncSnapshot=r,o.resolve=V,o.execute=W,o}function Q(t,e,n,s,{actorRef:r}){const o="function"==typeof r?r(n,s):r,i="string"==typeof o?e.children[o]:o;let a=e.children;return i&&(a={...a},delete a[i.id]),[Jt(e,{children:a}),i]}function Y(t,e){if(e){if(t.system._unregister(e),e._processingStatus!==L.Running)return void t.stopChild(e);t.defer((()=>{t.stopChild(e)}))}}function G(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=Q,e.execute=Y,e}function H(t,e,n,s){const{machine:r}=s,o="function"==typeof t,i=o?t:r.implementations.guards["string"==typeof t?t:t.type];if(!o&&!i)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof i)return H(i,e,n,s);const a={context:e,event:n},c=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:n}):t.params:void 0;return"check"in i?i.check(s,a,i):i(a,c)}const K=t=>"atomic"===t.type||"final"===t.type;function X(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function Z(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function tt(t){const e=new Set(t),n=nt(e);for(const t of e)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const n of X(t))if("history"!==n.type&&!e.has(n)){const t=ft(n);for(const n of t)e.add(n)}}else ft(t).forEach((t=>e.add(t)));for(const t of e){let n=t.parent;for(;n;)e.add(n),n=n.parent}return e}function et(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(K(t))return t.key}const s={};for(const t of n)s[t.key]=et(t,e);return s}function nt(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function st(t,e){return et(t,nt(tt(e)))}function rt(t,e){return"compound"===e.type?X(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?X(e).every((e=>rt(t,e))):"final"===e.type}const ot=t=>"#"===t[0];function it(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const r=e[n],o="string"==typeof r?{target:r}:r,i=Number.isNaN(+n)?n:+n,a=(e=>{const n=(r=e,o=t.id,{type:`xstate.after.${r}.${o}`}),s=n.type;var r,o;return t.entry.push(Wt(n,{id:s,delay:e})),t.exit.push(B(s)),s})(i);return T(o).map((t=>({...t,event:a,delay:i})))})).map((e=>{const{delay:n}=e;return{...at(t,e.event,e),delay:n}}))}function at(t,e,n){const s=A(n.target),r=n.reenter??!1,o=function(t,e){if(void 0!==e)return e.map((e=>{if("string"!=typeof e)return e;if(ot(e))return t.machine.getStateNodeById(e);const n="."===e[0];if(n&&!t.parent)return dt(t,e.slice(1));const s=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return dt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,s),i={...n,actions:T(n.actions),guard:n.guard,target:o,source:t,reenter:r,eventType:e,toJSON:()=>({...i,source:`#${t.id}`,target:o?o.map((t=>`#${t.id}`)):void 0})};return i}function ct(t){const e=A(t.config.target);return e?{target:e.map((e=>"string"==typeof e?dt(t.parent,e):e))}:t.parent.initial}function ut(t){return"history"===t.type}function ft(t){const e=ht(t);for(const n of e)for(const s of Z(n,t))e.add(s);return e}function ht(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of X(n))t(e)}(t),e}function lt(t,e){if(ot(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function dt(t,e){if("string"==typeof e&&ot(e))try{return t.machine.getStateNodeById(e)}catch{}const n=S(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=lt(s,t)}return s}function pt(t,e){if("string"==typeof e){const n=t.states[e];if(!n)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,n]}const n=Object.keys(e),s=n.map((e=>lt(t,e))).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce(((n,s)=>{const r=lt(t,s);if(!r)return n;const o=pt(r,e[s]);return n.concat(o)}),[]))}function yt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const r=lt(t,e).next(n,s);return r&&r.length?r:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const r=Object.keys(e),o=yt(lt(t,r[0]),e[r[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const r=[];for(const o of Object.keys(e)){const i=e[o];if(!i)continue;const a=yt(lt(t,o),i,n,s);a&&r.push(...a)}return r.length?r:t.next(n,s)}(t,e,n,s)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function mt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function gt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function bt(t,e,n){const s=new Set;for(const r of t){let t=!1;const o=new Set;for(const i of s)if(gt(xt([r],e,n),xt([i],e,n))){if(!mt(r.source,i.source)){t=!0;break}o.add(i)}if(!t){for(const t of o)s.delete(t);s.add(r)}}return Array.from(s)}function _t(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ut(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of _t(ct(s),e))n.add(t);else n.add(s);return[...n]}function wt(t,e){const n=_t(t,e);if(!n)return;if(!t.reenter&&n.every((e=>e===t.source||mt(e,t.source))))return t.source;const s=function(t){const[e,...n]=t;for(const t of Z(e,void 0))if(n.every((e=>mt(e,t))))return t}(n.concat(t.source));return s||(t.reenter?void 0:t.source.machine.root)}function xt(t,e,n){const s=new Set;for(const r of t)if(r.target?.length){const t=wt(r,n);r.reenter&&r.source===t&&s.add(t);for(const n of e)mt(n,t)&&s.add(n)}return[...s]}function St(t,e,n,s,r,o){if(!t.length)return e;const i=new Set(e._nodes);let a=e.historyValue;const c=bt(t,i,a);let u=e;r||([u,a]=function(t,e,n,s,r,o,i){let a=t;const c=xt(s,r,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let n;n="deep"===e.history?e=>K(e)&&mt(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(r).filter(n)}for(const t of c)a=qt(a,e,n,[...t.exit,...t.invoke.map((t=>G(t.id)))],i),r.delete(t);return[a,u||o]}(u,s,n,c,i,a,o)),u=qt(u,s,n,c.flatMap((t=>t.actions)),o),u=function(t,e,n,s,r,o,i,a){let c=t;const u=new Set,f=new Set;(function(t,e,n,s){for(const r of t){const t=wt(r,e);for(const o of r.target||[])!ut(o)&&(r.source!==o||r.source!==t||r.reenter)&&(s.add(o),n.add(o)),It(o,e,n,s);const o=_t(r,e);for(const i of o){const o=Z(i,t);"parallel"===t?.type&&o.push(t),Et(s,e,n,o,!r.source.parent&&r.reenter?void 0:t)}}})(s,i,f,u),a&&f.add(t.machine.root);const h=new Set;for(const t of[...u].sort(((t,e)=>t.order-e.order))){r.add(t);const s=[];s.push(...t.entry);for(const e of t.invoke)s.push(F(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(f.has(t)){const e=t.initial.actions;s.push(...e)}if(c=qt(c,e,n,s,o,t.invoke.map((t=>t.id))),"final"===t.type){const s=t.parent;let i="parallel"===s?.type?s:s?.parent,a=i||t;for("compound"===s?.type&&o.push(m(s.id,void 0!==t.output?$(t.output,c.context,e,n.self):void 0));"parallel"===i?.type&&!h.has(i)&&rt(r,i);)h.add(i),o.push(m(i.id)),a=i,i=i.parent;if(i)continue;c=Jt(c,{status:"done",output:kt(c,e,n,c.machine.root,a)})}}return c}(u,s,n,c,i,o,a,r);const f=[...i];"done"===u.status&&(u=qt(u,s,n,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(e._nodes,i)?u:Jt(u,{_nodes:f,historyValue:a})}catch(t){throw t}}function kt(t,e,n,s,r){if(void 0===s.output)return;const o=m(r.id,void 0!==r.output&&r.parent?$(r.output,t.context,e,n.self):void 0);return $(s.output,t.context,o,n.self)}function It(t,e,n,s){if(ut(t))if(e[t.id]){const r=e[t.id];for(const t of r)s.add(t),It(t,e,n,s);for(const o of r)Tt(o,t.parent,s,e,n)}else{const r=ct(t);for(const o of r.target)s.add(o),r===t.parent?.initial&&n.add(t.parent),It(o,e,n,s);for(const o of r.target)Tt(o,t.parent,s,e,n)}else if("compound"===t.type){const[r]=t.initial.target;ut(r)||(s.add(r),n.add(r)),It(r,e,n,s),Tt(r,t,s,e,n)}else if("parallel"===t.type)for(const r of X(t).filter((t=>!ut(t))))[...s].some((t=>mt(t,r)))||(ut(r)||(s.add(r),n.add(r)),It(r,e,n,s))}function Et(t,e,n,s,r){for(const o of s)if((!r||mt(o,r))&&t.add(o),"parallel"===o.type)for(const s of X(o).filter((t=>!ut(t))))[...t].some((t=>mt(t,s)))||(t.add(s),It(s,e,n,t))}function Tt(t,e,n,s,r){Et(n,s,r,Z(t,e))}let $t=!1;function Ot(t,e,n,s,r,o){const{machine:i}=t;let a=t;for(const t of s){let s=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:"string"==typeof t?t:"object"==typeof t?t.type:t.name||"(anonymous)",params:h}});try{$t=u,u(f,h)}finally{$t=!1}};const c="function"==typeof t,u=c?t:i.implementations.actions["string"==typeof t?t:t.type];if(!u)continue;const f={context:a.context,event:e,self:n.self,system:n.system},h=c||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in u)){n.self._processingStatus===L.Running?s():n.defer((()=>{s()}));continue}const l=u,[d,p,y]=l.resolve(n,a,f,h,u,r);a=d,"retryResolve"in l&&o?.push([l,p]),"execute"in l&&(n.self._processingStatus===L.Running?l.execute(n,p):n.defer(l.execute.bind(null,n,p))),y&&(a=Ot(a,e,n,y,r,o))}return a}function qt(t,e,n,s,r,o){const i=o?[]:void 0,a=Ot(t,e,n,s,{internalQueue:r,deferredActorIds:o},i);return i?.forEach((([t,e])=>{t.retryResolve(n,a,e)})),a}function At(t,e,n,s=[]){let r=t;const o=[];function i(t,e,s){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:e,snapshot:t,_transitions:s}),o.push(t)}if(e.type===v)return r=Jt(jt(r,e,n),{status:"stopped"}),i(r,e,[]),{snapshot:r,microstates:o};let a=e;if(a.type!==y){const e=a,c=function(t){return t.type.startsWith("xstate.error.actor")}(e),u=Rt(e,r);if(c&&!u.length)return r=Jt(t,{status:"error",error:e.error}),i(r,e,[]),{snapshot:r,microstates:o};r=St(u,t,n,a,!1,s),i(r,e,u)}let c=!0;for(;"active"===r.status;){let t=c?Pt(r,a):[];const e=t.length?r:void 0;if(!t.length){if(!s.length)break;a=s.shift(),t=Rt(a,r)}r=St(t,r,n,a,!1,s),c=r!==e,i(r,a,t)}return"active"!==r.status&&jt(r,a,n),{snapshot:r,microstates:o}}function jt(t,e,n){return qt(t,e,n,Object.values(t.children).map((t=>G(t))),[])}function Rt(t,e){return e.machine.getTransitionData(e,t)}function Pt(t,e){const n=new Set,s=t._nodes.filter(K);for(const r of s)t:for(const s of[r].concat(Z(r,void 0)))if(s.always)for(const r of s.always)if(void 0===r.guard||H(r.guard,t.context,e,t)){n.add(r);break t}return bt(Array.from(n),new Set(t._nodes),t.historyValue)}const Nt=function(t){return x(t,this.value)},Mt=function(t){return this.tags.has(t)},Lt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Dt=function(){const{_nodes:t,tags:e,machine:n,getMeta:s,toJSON:r,can:o,hasTag:i,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Ut=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function zt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:st(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Nt,hasTag:Mt,can:Lt,getMeta:Ut,toJSON:Dt}}function Jt(t,e={}){return zt({...t,...e},t.machine)}function Ct(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:1,id:s.id};else{const r=Ct(s);r!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=r)}}return e??t}function Bt(t,e,n,s,{event:r,id:o,delay:i},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof r)throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const u="function"==typeof r?r(n,s):r;let f;if("string"==typeof i){const t=c&&c[i];f="function"==typeof t?t(n,s):t}else f="function"==typeof i?i(n,s):i;return"number"!=typeof f&&a.push(u),[e,{event:u,id:o,delay:f}]}function Vt(t,e){const{event:n,delay:s,id:r}=e;"number"!=typeof s||t.defer((()=>{const e=t.self;t.system.scheduler.schedule(e,e,n,s,r)}))}function Wt(t,e){function n(t,e){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Bt,n.execute=Vt,n}const Ft="xstate.observable.error",Qt="xstate.observable.complete";function Yt(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case Ft:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case Qt:return{...t,status:"done",input:void 0,_subscription:void 0};case v:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:n,system:s,emit:r})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:s,self:n,emit:r}).subscribe({next:t=>{n._parent&&s._relay(n,n._parent,t)},error:t=>{s._relay(n,n,{type:Ft,data:t})},complete:()=>{s._relay(n,n,{type:Qt})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}}function Gt(t,{machine:e,context:n},s,r){return(o,i)=>{const a=((o,i={})=>{const{systemId:a,input:c}=i;if("string"==typeof o){const u=P(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=z(u,{id:i.id,parent:t.self,syncSnapshot:i.syncSnapshot,input:"function"==typeof c?c({context:n,event:s,self:t.self}):c,src:o,systemId:a});return r[f.id]=f,f}return z(o,{id:i.id,parent:t.self,syncSnapshot:i.syncSnapshot,input:i.input,src:o,systemId:a})})(o,i);return r[a.id]=a,t.defer((()=>{a._processingStatus!==L.Stopped&&a.start()})),a}}function Ht(t,e,n,s,{assignment:r}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},i={context:e.context,event:n.event,spawn:Gt(t,e,n.event,o),self:t.self,system:t.system};let a={};if("function"==typeof r)a=r(i,s);else for(const t of Object.keys(r)){const e=r[t];a[t]="function"==typeof e?e(i,s):e}return[Jt(e,{context:Object.assign({},e.context,a),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function Kt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ht,e}function Xt(t,e,n,s,{event:r}){return[e,{event:"function"==typeof r?r(n,s):r}]}function Zt(t,{event:e}){t.defer((()=>t.emit(e)))}function te(t){function e(t,e){}return e.type="xstate.emit",e.event=t,e.resolve=Xt,e.execute=Zt,e}let ee=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ne(t,e,n,s,{to:r,event:o,id:i,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const f="function"==typeof o?o(n,s):o;let h;if("string"==typeof a){const t=u&&u[a];h="function"==typeof t?t(n,s):t}else h="function"==typeof a?a(n,s):a;const l="function"==typeof r?r(n,s):r;let d;if("string"==typeof l){if(d=l===ee.Parent?t.self._parent:l===ee.Internal?t.self:l.startsWith("#_")?e.children[l.slice(2)]:c.deferredActorIds?.includes(l)?l:e.children[l],!d)throw new Error(`Unable to send event to actor '${l}' from machine '${e.machine.id}'.`)}else d=l||t.self;return[e,{to:d,event:f,id:i,delay:h}]}function se(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function re(t,e){t.defer((()=>{const{to:n,event:s,delay:r,id:o}=e;"number"!=typeof r?t.system._relay(t.self,n,"xstate.error"===s.type?g(t.self.id,s.data):s):t.system.scheduler.schedule(t.self,n,s,r,o)}))}function oe(t,e,n){function s(t,e){}return s.type="xsnapshot.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=ne,s.retryResolve=se,s.execute=re,s}function ie(t,e,n,s,{collect:r}){const o=[],i=function(t){o.push(t)};return i.assign=(...t)=>{o.push(Kt(...t))},i.cancel=(...t)=>{o.push(B(...t))},i.raise=(...t)=>{o.push(Wt(...t))},i.sendTo=(...t)=>{o.push(oe(...t))},i.sendParent=(...t)=>{o.push(function(t,e){return oe(ee.Parent,t,e)}(...t))},i.spawnChild=(...t)=>{o.push(F(...t))},i.stopChild=(...t)=>{o.push(G(...t))},i.emit=(...t)=>{o.push(te(...t))},r({context:n.context,event:n.event,enqueue:i,check:t=>H(t,e.context,n.event,e),self:t.self,system:t.system},s),[e,void 0,o]}function ae(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ie,e}function ce(t,e){const n=T(e);if(!n.includes(t.type)){const e=1===n.length?`type "${n[0]}"`:`one of types "${n.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(t)} to have ${e}`)}}const ue=new WeakMap;function fe(t,e,n){let s=ue.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},ue.set(t,s)),s[e]}const he={},le=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class de{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join("."),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?I(this.config.states,((t,e)=>new de(t,{_parent:this,_key:e,_machine:this.machine}))):he,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=T(this.config.entry).slice(),this.exit=T(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=T(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(""===n)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,q(s).map((e=>at(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,q(t.config.onDone).map((e=>at(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,q(n.onDone).map((e=>at(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,q(n.onError).map((e=>at(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,q(n.onSnapshot).map((e=>at(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=q(this.config.always).map((t=>at(this,"",t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(le),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(le),eventType:null})}:void 0,history:this.history,states:I(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(le)}))),entry:this.entry.map(le),exit:this.exit.map(le),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return fe(this,"invoke",(()=>T(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,r=t.id??R(this.id,e),o="string"==typeof n?n:`xstate.invoke.${R(this.id,e)}`;return{...t,src:o,id:r,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:r}}}}))))}get on(){return fe(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return fe(this,"delayedTransitions",(()=>it(this)))}get initial(){return fe(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?T(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type;let s;const r=fe(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],r=s[t];if("*"===e)return t===n.length-1;if(e!==r)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const o of r){const{guard:r}=o,i=t.context;let a=!1;try{a=!r||H(r,i,e,t)}catch(t){const e="string"==typeof r?r:"object"==typeof r?r.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(a){s=o;break}}return s?[s]:void 0}get events(){return fe(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class pe{constructor(t,e){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new de(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:r}=this.implementations;return new pe(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const e=(s=this.root,r=t.value,st(s,[...tt(pt(s,r))])),n=tt(pt(this.root,e));var s,r;return zt({_nodes:[...n],context:t.context||{},children:{},status:rt(n,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,n){return At(t,e,n).snapshot}microstep(t,e,n){return At(t,e,n).microstates}getTransitionData(t,e){return yt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:s}=this.config,r=zt({context:"function"!=typeof s&&s?s:{},_nodes:[this.root],children:{},status:"active"},this);return"function"==typeof s?qt(r,e,t,[Kt((({spawn:t,event:e,self:n})=>s({spawn:t,input:e.input,self:n})))],n):r}getInitialSnapshot(t,e){const n=b(e),s=[],r=this.getPreInitialState(t,n,s),o=St([{target:[...ht(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,n,!0,s),{snapshot:i}=At(o,n,t,s);return i}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=S(t),n=e.slice(1),s=ot(e[0])?e[0].slice(1):e[0],r=this.idMap.get(s);if(!r)throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);return dt(r,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:n,tags:s,machine:r,children:o,context:i,can:a,hasTag:c,matches:u,getMeta:f,toJSON:h,...l}=t,d={};for(const t in o){const n=o[t];d[t]={snapshot:n.getPersistedSnapshot(e),src:n.src,systemId:n._systemId,syncSnapshot:n._syncSnapshot}}return{...l,context:Ct(i),children:d}}(t,e)}restoreSnapshot(t,e){const n={},s=t.children;Object.keys(s).forEach((t=>{const r=s[t],o=r.snapshot,i=r.src,a="string"==typeof i?P(this,i):i;if(!a)return;const c=z(a,{id:t,parent:e.self,syncSnapshot:r.syncSnapshot,snapshot:o,src:i,systemId:r.systemId});n[t]=c}));const r=zt({...t,children:n,_nodes:Array.from(tt(pt(this.root,t.value)))},this);let o=new Set;return function t(e,n){if(!o.has(e)){o.add(e);for(let s in e){const r=e[s];if(r&&"object"==typeof r){if("xstate$$type"in r&&1===r.xstate$$type){e[s]=n[r.id];continue}t(r,n)}}}}(r.context,n),r}}function ye({schemas:t,actors:e,actions:n,guards:s,delays:r}){return{createMachine:o=>function(t,e){return new pe(t,e)}({...o,schemas:t},{actors:e,actions:n,guards:s,delays:r})}}var ve=function(t,e){return(ve=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function me(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}ve(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function ge(t,e,n,s){return new(n||(n=Promise))((function(r,o){function i(t){try{c(s.next(t))}catch(t){o(t)}}function a(t){try{c(s.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((s=s.apply(t,e||[])).next())}))}function be(t,e){var n,s,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(n=1,s&&(r=2&a[0]?s.return:a[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,a[1])).done)return r;switch(s=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,s=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(r=(r=o.trys).length>0&&r[r.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],s=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function _e(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],s=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function we(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var s,r,o=n.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(s=o.next()).done;)i.push(s.value)}catch(t){r={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i}function xe(t,e,n){if(n||2===arguments.length)for(var s,r=0,o=e.length;r<o;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}function Se(t){return this instanceof Se?(this.v=t,this):new Se(t)}function ke(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s,r=n.apply(t,e||[]),o=[];return s=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),s[Symbol.asyncIterator]=function(){return this},s;function i(t,e){r[t]&&(s[t]=function(e){return new Promise((function(n,s){o.push([t,e,n,s])>1||a(t,e)}))},e&&(s[t]=e(s[t])))}function a(t,e){try{(n=r[t](e)).value instanceof Se?Promise.resolve(n.value.v).then(c,u):f(o[0][2],n)}catch(t){f(o[0][3],t)}var n}function c(t){a("next",t)}function u(t){a("throw",t)}function f(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}function Ie(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=_e(t),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(n){e[n]=t[n]&&function(e){return new Promise((function(s,r){(function(t,e,n,s){Promise.resolve(s).then((function(e){t({value:e,done:n})}),e)})(s,r,(e=t[n](e)).done,e.value)}))}}}function Ee(t){return"function"==typeof t}var Te,$e,Oe=(Te=function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}},($e=Te((function(t){Error.call(t),t.stack=(new Error).stack}))).prototype=Object.create(Error.prototype),$e.prototype.constructor=$e,$e);function qe(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var Ae=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var t,e,n,s,r;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var i=_e(o),a=i.next();!a.done;a=i.next()){a.value.remove(this)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}else o.remove(this);var c=this.initialTeardown;if(Ee(c))try{c()}catch(t){r=t instanceof Oe?t.errors:[t]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var f=_e(u),h=f.next();!h.done;h=f.next()){var l=h.value;try{Re(l)}catch(t){r=r??[],t instanceof Oe?r=xe(xe([],we(r)),we(t.errors)):r.push(t)}}}catch(t){n={error:t}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(n)throw n.error}}}if(r)throw new Oe(r)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)Re(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&qe(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&qe(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t;var e}();function je(t){return t instanceof Ae||t&&"closed"in t&&Ee(t.remove)&&Ee(t.add)&&Ee(t.unsubscribe)}function Re(t){Ee(t)?t():t.unsubscribe()}var Pe=void 0,Ne=!1,Me=function(t,e){for(var n=[],s=2;s<arguments.length;s++)n[s-2]=arguments[s];return setTimeout.apply(void 0,xe([t,e],we(n)))};function Le(t){Me((function(){throw t}))}function De(){}var Ue=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,je(e)&&e.add(n)):n.destination=We,n}return me(e,t),e.create=function(t,e,n){return new Be(t,e,n)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Ae),ze=Function.prototype.bind;function Je(t,e){return ze.call(t,e)}var Ce=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){Ve(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){Ve(t)}else Ve(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){Ve(t)}},t}(),Be=function(t){function e(e,n,s){var r,o,i=t.call(this)||this;Ee(e)||!e?r={next:e??void 0,error:n??void 0,complete:s??void 0}:i&&Ne?((o=Object.create(e)).unsubscribe=function(){return i.unsubscribe()},r={next:e.next&&Je(e.next,o),error:e.error&&Je(e.error,o),complete:e.complete&&Je(e.complete,o)}):r=e;return i.destination=new Ce(r),i}return me(e,t),e}(Ue);function Ve(t){Le(t)}var We={closed:!0,next:De,error:function(t){throw t},complete:De},Fe="function"==typeof Symbol&&Symbol.observable||"@@observable";function Qe(t){return t}function Ye(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ge(t)}function Ge(t){return 0===t.length?Qe:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var He=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var s,r=this,o=(s=t)&&s instanceof Ue||function(t){return t&&Ee(t.next)&&Ee(t.error)&&Ee(t.complete)}(s)&&je(s)?t:new Be(t,e,n);return function(){var t=r,e=t.operator,n=t.source;o.add(e?e.call(o,n):n?r._subscribe(o):r._trySubscribe(o))}(),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=Ke(e))((function(e,s){var r=new Be({next:function(e){try{t(e)}catch(t){s(t),r.unsubscribe()}},error:s,complete:e});n.subscribe(r)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[Fe]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ge(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=Ke(t))((function(t,n){var s;e.subscribe((function(t){return s=t}),(function(t){return n(t)}),(function(){return t(s)}))}))},t.create=function(e){return new t(e)},t}();function Ke(t){var e;return null!==(e=t??Pe)&&void 0!==e?e:Promise}function Xe(t){return function(e){if(function(t){return Ee(t?.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function Ze(t,e,n,s,r){return new tn(t,e,n,s,r)}var tn=function(t){function e(e,n,s,r,o,i){var a=t.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=i,a._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=r?function(t){try{r(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=s?function(){try{s()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return me(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}(Ue),en=new He((function(t){return t.complete()})),nn=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};var sn="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function rn(t){if(t instanceof He)return t;if(null!=t){if(function(t){return Ee(t[Fe])}(t))return o=t,new He((function(t){var e=o[Fe]();if(Ee(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(nn(t))return r=t,new He((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(s=t,Ee(s?.then))return n=t,new He((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,Le)}));if(function(t){return Symbol.asyncIterator&&Ee(t?.[Symbol.asyncIterator])}(t))return on(t);if(function(t){return Ee(t?.[sn])}(t))return e=t,new He((function(t){var n,s;try{for(var r=_e(e),o=r.next();!o.done;o=r.next()){var i=o.value;if(t.next(i),t.closed)return}}catch(t){n={error:t}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(n)throw n.error}}t.complete()}));if(function(t){return Ee(t?.getReader)}(t))return on(function(t){return ke(this,arguments,(function(){var e,n,s;return be(this,(function(r){switch(r.label){case 0:e=t.getReader(),r.label=1;case 1:r.trys.push([1,,9,10]),r.label=2;case 2:return[4,Se(e.read())];case 3:return n=r.sent(),s=n.value,n.done?[4,Se(void 0)]:[3,5];case 4:return[2,r.sent()];case 5:return[4,Se(s)];case 6:return[4,r.sent()];case 7:return r.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t))}var e,n,s,r,o;throw function(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}(t)}function on(t){return new He((function(e){(function(t,e){var n,s,r,o;return ge(this,void 0,void 0,(function(){var i,a;return be(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=Ie(t),c.label=1;case 1:return[4,n.next()];case 2:if((s=c.sent()).done)return[3,4];if(i=s.value,e.next(i),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),r={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),s&&!s.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(r)throw r.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function an(t,e){return Xe((function(n,s){var r=0;n.subscribe(Ze(s,(function(n){s.next(t.call(e,n,r++))})))}))}var cn=Array.isArray;function un(t){return an((function(e){return function(t,e){return cn(e)?t.apply(void 0,xe([],we(e))):t(e)}(t,e)}))}function fn(t,e,n){return void 0===n&&(n=1/0),Ee(e)?fn((function(n,s){return an((function(t,r){return e(n,t,s,r)}))(rn(t(n,s)))}),n):("number"==typeof e&&(n=e),Xe((function(e,s){return function(t,e,n,s,r,o,i){var a=[],c=0,u=0,f=!1,h=function(){f&&!a.length&&!c&&e.complete()},l=function(t){c++;var r=!1;rn(n(t,u++)).subscribe(Ze(e,(function(t){e.next(t)}),(function(){r=!0}),void 0,(function(){if(r)try{for(c--;a.length&&c<s;)t=void 0,t=a.shift(),i||l(t);h()}catch(t){e.error(t)}var t})))};return t.subscribe(Ze(e,(function(t){return c<s?l(t):a.push(t)}),(function(){f=!0,h()}))),function(){}}(e,s,t,n)})))}var hn=["addListener","removeListener"],ln=["addEventListener","removeEventListener"],dn=["on","off"];function pn(t,e,n,s){if(Ee(n)&&(s=n,n=void 0),s)return pn(t,e,n).pipe(un(s));var r=we(function(t){return Ee(t.addEventListener)&&Ee(t.removeEventListener)}(t)?ln.map((function(s){return function(r){return t[s](e,r,n)}})):function(t){return Ee(t.addListener)&&Ee(t.removeListener)}(t)?hn.map(yn(t,e)):function(t){return Ee(t.on)&&Ee(t.off)}(t)?dn.map(yn(t,e)):[],2),o=r[0],i=r[1];if(!o&&nn(t))return fn((function(t){return pn(t,e,n)}))(rn(t));if(!o)throw new TypeError("Invalid event target");return new He((function(t){var e=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.next(1<e.length?e:e[0])};return o(e),function(){return i(e)}}))}function yn(t,e){return function(n){return function(s){return t[n](e,s)}}}function vn(t,e){return Xe((function(n,s){var r=0;n.subscribe(Ze(s,(function(n){return t.call(e,n,r++)&&s.next(n)})))}))}function mn(t){return t<=0?function(){return en}:Xe((function(e,n){var s=0;e.subscribe(Ze(n,(function(e){++s<=t&&(n.next(e),t<=s&&n.complete())})))}))}const gn=t=>({context:e})=>{const{count:n,include:s,exclude:r,responseType:o="message.received"}=t;return{count:n,domain:e.domain,from:e.connectTo,include:s?Array.isArray(s)?s:[s]:[],exclude:r?Array.isArray(r)?r:[r]:[],responseType:o,target:e.target,to:e.name}},bn=(Tn=()=>pn(window,"message"),new He((function(t){rn(Tn()).subscribe(t)}))),_n=t=>Yt((({input:t})=>{return bn.pipe(Ye(),vn((t=>e=>{const{data:n}=e;return(!t.include.length||t.include.includes(n.type))&&(!t.exclude.length||!t.exclude.includes(n.type))&&n.domain===t.domain&&n.from===t.from&&n.to===t.to&&(!t.target||e.source===t.target)})(t)),an((o=t.responseType,t=>({type:o,message:t}))),t.count?Ye((s=t.count,void 0===r&&(r=null),r=r??s,Xe((function(t,e){var n=[],o=0;t.subscribe(Ze(e,(function(t){var i,a,c,u,f=null;o++%r==0&&n.push([]);try{for(var h=_e(n),l=h.next();!l.done;l=h.next())(y=l.value).push(t),s<=y.length&&(f=f??[]).push(y)}catch(t){i={error:t}}finally{try{l&&!l.done&&(a=h.return)&&a.call(h)}finally{if(i)throw i.error}}if(f)try{for(var d=_e(f),p=d.next();!p.done;p=d.next()){var y=p.value;qe(n,y),e.next(y)}}catch(t){c={error:t}}finally{try{p&&!p.done&&(u=d.return)&&u.call(d)}finally{if(c)throw c.error}}}),(function(){var t,s;try{for(var r=_e(n),o=r.next();!o.done;o=r.next()){var i=o.value;e.next(i)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(s=r.return)&&s.call(r)}finally{if(t)throw t.error}}e.complete()}),void 0,(function(){n=null})))}))),(e=t=>t,Ee(n)?fn(e,n,1):fn(e,1)),mn(t.count)):Ye());var e,n,s,r,o})),wn="comlink/response",xn="comlink/heartbeat",Sn="comlink/disconnect",kn="comlink/handshake/ack",In=()=>ye({types:{},actors:{listen:Yt((({input:t})=>{const e=t.signal?pn(t.signal,"abort").pipe((n=`Request ${t.requestId} aborted`,t=>t.pipe(mn(1),an((()=>{throw new Error(n)}))))):en;var n,s;return pn(window,"message").pipe(vn((e=>e.data?.type===wn&&e.data?.responseTo===t.requestId&&!!e.source&&t.sources.has(e.source))),mn(t.sources.size),(s=e,Xe((function(t,e){rn(s).subscribe(Ze(e,(function(){return e.complete()}),De)),!e.closed&&t.subscribe(e)}))))}))},actions:{"send message":({context:t},e)=>{const{sources:n,targetOrigin:s}=t,{message:r}=e;n.forEach((t=>{t.postMessage(r,{targetOrigin:s})}))},"on success":oe((({context:t})=>t.parentRef),(({context:t,self:e})=>(t.response&&t.resolvable?.resolve(t.response),{type:"request.success",requestId:e.id,response:t.response,responseTo:t.responseTo}))),"on fail":oe((({context:t})=>t.parentRef),(({context:t,self:e})=>(console.warn(`Received no response to message '${t.type}' on client '${t.from}' (ID: '${t.id}').`),t.resolvable?.reject(new Error("No response received")),{type:"request.failed",requestId:e.id}))),"on abort":oe((({context:t})=>t.parentRef),(({context:t,self:e})=>(t.resolvable?.reject(new Error("Request aborted")),{type:"request.aborted",requestId:e.id})))},guards:{expectsResponse:({context:t})=>t.expectResponse},delays:{initialTimeout:0,responseTimeout:1e3}}).createMachine({context:({input:t})=>({connectionId:t.connectionId,data:t.data,domain:t.domain,expectResponse:t.expectResponse??!1,from:t.from,id:`msg-${h()}`,parentRef:t.parentRef,resolvable:t.resolvable,response:null,responseTo:t.responseTo,signal:t.signal,sources:t.sources instanceof Set?t.sources:new Set([t.sources]),targetOrigin:t.targetOrigin,to:t.to,type:t.type}),initial:"idle",on:{abort:".aborted"},states:{idle:{after:{initialTimeout:[{target:"sending"}]}},sending:{entry:{type:"send message",params:({context:t})=>{const{connectionId:e,data:n,domain:s,from:r,id:o,responseTo:i,to:a,type:c}=t;return{message:{connectionId:e,data:n,domain:s,from:r,id:o,to:a,type:c,responseTo:i}}}},always:[{guard:"expectsResponse",target:"awaiting"},"success"]},awaiting:{invoke:{id:"listen for response",src:"listen",input:({context:t})=>({requestId:t.id,sources:t.sources,signal:t.signal}),onError:"aborted"},after:{responseTimeout:"failed"},on:{message:{actions:Kt({response:({event:t})=>t.data.data,responseTo:({event:t})=>t.data.responseTo}),target:"success"}}},failed:{type:"final",entry:"on fail"},success:{type:"final",entry:"on success"},aborted:{type:"final",entry:"on abort"}},output:({context:t,self:e})=>({requestId:e.id,response:t.response,responseTo:t.responseTo})}),En=(t,e=(()=>ye({types:{},actors:{requestMachine:In(),listen:_n()},actions:{"buffer incoming message":Kt({handshakeBuffer:({event:t,context:e})=>(ce(t,"message.received"),[...e.handshakeBuffer,t])}),"buffer message":ae((({enqueue:t})=>{t.assign({buffer:({event:t,context:e})=>(ce(t,"post"),[...e.buffer,{data:t.data,resolvable:t.resolvable,signal:t.signal}])}),t.emit((({event:t})=>(ce(t,"post"),{type:"_buffer.added",message:t.data})))})),"create request":Kt({requests:({context:t,event:e,self:n,spawn:s})=>{ce(e,"request");const r=(Array.isArray(e.data)?e.data:[e.data]).map((e=>{const r=`req-${h()}`;return s("requestMachine",{id:r,input:{connectionId:t.connectionId,data:e.data,domain:t.domain,expectResponse:e.expectResponse,from:t.name,parentRef:n,resolvable:e.resolvable,responseTo:e.responseTo,sources:t.target,targetOrigin:t.targetOrigin,to:t.connectTo,type:e.type,signal:e.signal}})}));return[...t.requests,...r]}}),"emit heartbeat":te((()=>({type:"_heartbeat"}))),"emit received message":ae((({enqueue:t})=>{t.emit((({event:t})=>(ce(t,"message.received"),{type:"_message",message:t.message.data}))),t.emit((({event:t})=>(ce(t,"message.received"),{type:t.message.data.type,message:t.message.data})))})),"flush buffer":ae((({enqueue:t})=>{t.raise((({context:t})=>({type:"request",data:t.buffer.map((({data:t,resolvable:e,signal:n})=>({data:t.data,type:t.type,expectResponse:!!e,resolvable:e,signal:n})))}))),t.emit((({context:t})=>({type:"_buffer.flushed",messages:t.buffer.map((({data:t})=>t))}))),t.assign({buffer:[]})})),"flush handshake buffer":ae((({context:t,enqueue:e})=>{t.handshakeBuffer.forEach((t=>e.raise(t))),e.assign({handshakeBuffer:[]})})),post:Wt((({event:t})=>(ce(t,"post"),{type:"request",data:{data:t.data.data,expectResponse:!!t.resolvable,type:t.data.type,resolvable:t.resolvable,signal:t.signal}}))),"remove request":ae((({context:t,enqueue:e,event:n})=>{ce(n,["request.success","request.failed","request.aborted"]),G(n.requestId),e.assign({requests:t.requests.filter((({id:t})=>t!==n.requestId))})})),"send response":Wt((({event:t})=>(ce(t,["message.received","heartbeat.received"]),{type:"request",data:{type:wn,responseTo:t.message.data.id,data:void 0}}))),"send handshake syn ack":Wt({type:"request",data:{type:"comlink/handshake/syn-ack"}}),"set connection config":Kt({connectionId:({event:t})=>(ce(t,"message.received"),t.message.data.connectionId),target:({event:t})=>(ce(t,"message.received"),t.message.source||void 0),targetOrigin:({event:t})=>(ce(t,"message.received"),t.message.origin)})},guards:{hasSource:({context:t})=>null!==t.target}}).createMachine({id:"node",context:({input:t})=>({buffer:[],connectionId:null,connectTo:t.connectTo,domain:t.domain??"sanity/comlink",handshakeBuffer:[],name:t.name,requests:[],target:void 0,targetOrigin:null}),on:{"request.success":{actions:"remove request"},"request.failed":{actions:"remove request"},"request.aborted":{actions:"remove request"}},initial:"idle",states:{idle:{invoke:{id:"listen for handshake syn",src:"listen",input:gn({include:"comlink/handshake/syn",count:1}),onDone:{target:"handshaking",guard:"hasSource"}},on:{"message.received":{actions:"set connection config"},post:{actions:"buffer message"}}},handshaking:{entry:"send handshake syn ack",invoke:[{id:"listen for handshake ack",src:"listen",input:gn({include:kn,count:1}),onDone:"connected"},{id:"listen for disconnect",src:"listen",input:gn({include:Sn,count:1,responseType:"disconnect"})},{id:"listen for messages",src:"listen",input:gn({exclude:[Sn,kn,xn,wn]})}],on:{request:{actions:"create request"},post:{actions:"buffer message"},"message.received":{actions:"buffer incoming message"},disconnect:{target:"idle"}}},connected:{entry:["flush handshake buffer","flush buffer"],invoke:[{id:"listen for messages",src:"listen",input:gn({exclude:[wn,xn]})},{id:"listen for heartbeat",src:"listen",input:gn({include:xn,responseType:"heartbeat.received"})},{id:"listen for disconnect",src:"listen",input:gn({include:Sn,count:1,responseType:"disconnect"})}],on:{request:{actions:"create request"},post:{actions:"post"},disconnect:{target:"idle"},"message.received":{actions:["send response","emit received message"]},"heartbeat.received":{actions:["send response","emit heartbeat"]}}}}}))())=>{const n=z(e,{input:t}),s=()=>{n.stop()};return{actor:n,fetch:(t,e)=>{const s=Promise.withResolvers();return n.send({type:"post",data:t,resolvable:s,signal:e?.signal}),s.promise},machine:e,on:(t,e)=>{const{unsubscribe:s}=n.on(t,(t=>{e(t.message.data)}));return s},onStatus:t=>{const e=n.getSnapshot();let s="string"==typeof e.value?e.value:Object.keys(e.value)[0];const{unsubscribe:r}=n.subscribe((e=>{const n="string"==typeof e.value?e.value:Object.keys(e.value)[0];s!==n&&(s=n,t(n))}));return r},post:t=>{n.send({type:"post",data:t})},start:()=>(n.start(),s),stop:s}};var Tn;function $n(n,s,r){const[o,i]=t(null),[a,c]=t(!1);e((()=>{if(window.self===window.top&&!window.opener)return;const t=En({name:"preview-kit",connectTo:"presentation"});t.onStatus((t=>{"connected"===t?c(!0):"disconnected"===t&&c(!1)}));const e=setTimeout((()=>i(t)),0),n=t.start();return()=>{n(),i(null),clearTimeout(e)}}),[r,s]);const u=JSON.stringify(Array.from(n.keys()));e((()=>{"[]"!==u&&o&&a&&o.post({type:"preview-kit/documents",data:{projectId:s,dataset:r,perspective:"previewDrafts",documents:Array.from(n.values())}})}),[u,o,a,r,n,s])}function On(t){const e=n((()=>JSON.stringify(t||{})),[t]);return n((()=>JSON.parse(e)),[e])}function qn(n){const{refreshInterval:o}=n,i=function(){const[n,r]=t(!1);e((()=>{r(navigator.onLine);const t=()=>r(!0),e=()=>r(!1);return window.addEventListener("online",t),window.addEventListener("offline",e),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",e)}}),[]);const o=s(An,(()=>document.visibilityState),(()=>"hidden"));return!n||"hidden"===o}(),[a,c]=t("hit"),u=r((()=>(c("inflight"),()=>c("hit"))),[]);return e((()=>{if(!o||"hit"!==a)return;const t=setTimeout((()=>c("stale")),o);return()=>clearTimeout(t)}),[o,a]),e((()=>{if("hit"!==a)return;const t=()=>c("stale");return window.addEventListener("focus",t),()=>window.removeEventListener("focus",t)}),[o,a]),e((()=>{i&&"hit"===a&&c("stale"),!i&&"stale"===a&&c("refresh")}),[i,a]),[a,u]}function An(t){return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)}export{$n as useDocumentsInUse,On as useQueryParams,qn as useRevalidate};//# sourceMappingURL=index.js.map
{
"name": "@sanity/preview-kit-compat",
"version": "1.5.8-canary.1",
"version": "1.5.8-canary.2",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-kit-compat#readme",

@@ -35,55 +35,7 @@ "bugs": {

"browserslist": "extends @sanity/browserslist-config",
"prettier": "@sanity/prettier-config",
"prettier": "@repo/prettier-config",
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
}
},
"plugins": [
"@typescript-eslint",
"simple-import-sort",
"prettier"
],
"extends": [
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:react/jsx-runtime",
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"@repo/eslint-config"
],
"rules": {
"no-console": "error",
"no-warning-comments": [
"warn",
{
"location": "start",
"terms": [
"todo",
"@todo",
"fixme"
]
}
],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "warn",
"prettier/prettier": "warn",
"react-hooks/exhaustive-deps": "error",
"react-hooks/rules-of-hooks": "error",
"react/prop-types": "off",
"simple-import-sort/exports": "warn",
"simple-import-sort/imports": "warn"
},
"root": true

@@ -93,16 +45,13 @@ },

"@sanity/client": "^6.21.3",
"@sanity/comlink": "^0.0.1",
"@sanity/pkg-utils": "6.11.1",
"@types/react": "^18.3.5",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"@sanity/pkg-utils": "6.11.2",
"@types/react": "^18.3.7",
"eslint": "^8.57.1",
"react": "^18.3.1",
"typescript": "5.6.2",
"vitest": "^2.0.5",
"vitest": "^2.1.1",
"@repo/eslint-config": "0.0.0",
"@repo/package.config": "0.0.0",
"@repo/visual-editing-helpers": "0.6.21"
"@repo/prettier-config": "0.0.0",
"@repo/visual-editing-helpers": "0.6.21",
"@sanity/comlink": "^0.0.2-canary.0"
},

@@ -122,5 +71,5 @@ "peerDependencies": {

"dev": "pkg build --strict",
"lint": "eslint .",
"lint": "eslint --cache .",
"test": "vitest --pass-with-no-tests --typecheck"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc