@doeixd/machine 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var z=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Qe=(e,n)=>{for(var t in n)z(e,t,{get:n[t],enumerable:!0})},Xe=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of Je(n))!Ye.call(e,a)&&a!==t&&z(e,a,{get:()=>n[a],enumerable:!(r=qe(n,a))||r.enumerable});return e};var Ze=e=>Xe(z({},"__esModule",{value:!0}),e);var Bn={};Qe(Bn,{Actor:()=>A,BoundMachine:()=>K,CANCEL:()=>q,META_KEY:()=>pe,MachineBase:()=>m,MiddlewareBuilder:()=>B,MultiMachineBase:()=>W,action:()=>be,bindTransitions:()=>ae,branch:()=>pn,call:()=>Ne,chain:()=>yn,classCase:()=>$e,combine:()=>fn,combineFactories:()=>jn,compose:()=>un,composeTyped:()=>_,createActor:()=>F,createAsyncMachine:()=>Le,createContext:()=>Rn,createCustomMiddleware:()=>dn,createEnsemble:()=>Fe,createEnsembleFactory:()=>en,createEvent:()=>Pe,createFetchMachine:()=>cn,createFlow:()=>le,createFunctionalMachine:()=>oe,createMachine:()=>p,createMachineBuilder:()=>Pn,createMachineFactory:()=>Fn,createMatcher:()=>ze,createMiddleware:()=>C,createMiddlewareFactory:()=>An,createMiddlewareRegistry:()=>xn,createMultiMachine:()=>rn,createMutableMachine:()=>an,createParallelMachine:()=>L,createPipeline:()=>hn,createRunner:()=>Ae,createTransition:()=>Be,createTransitionExtender:()=>ie,createTransitionFactory:()=>Ke,customCase:()=>Ge,delegateToChild:()=>on,describe:()=>ge,discriminantCase:()=>We,extendTransitions:()=>se,forContext:()=>De,fromObservable:()=>Ue,fromPromise:()=>Ve,guard:()=>R,guardAsync:()=>S,guarded:()=>me,hasState:()=>H,inDevelopment:()=>ln,invoke:()=>Te,isConditionalMiddleware:()=>Cn,isMiddlewareContext:()=>mn,isMiddlewareError:()=>Tn,isMiddlewareFn:()=>re,isMiddlewareHooks:()=>bn,isMiddlewareOptions:()=>wn,isMiddlewareResult:()=>gn,isNamedMiddleware:()=>En,isPipelineConfig:()=>vn,isState:()=>je,logState:()=>ke,matchMachine:()=>On,mergeContext:()=>Oe,metadata:()=>ve,middlewareBuilder:()=>Re,next:()=>kn,overrideTransitions:()=>Sn,pipeTransitions:()=>_e,run:()=>$,runAsync:()=>xe,runMachine:()=>_n,runSequence:()=>ye,runWithDebug:()=>Me,runWithEnsemble:()=>tn,runWithRunner:()=>nn,setContext:()=>E,spawn:()=>Ie,state:()=>He,step:()=>de,stepAsync:()=>he,toggle:()=>sn,transitionTo:()=>Ce,when:()=>N,whenContext:()=>Mn,whenGuard:()=>we,whenGuardAsync:()=>Ee,withAnalytics:()=>Y,withDebugging:()=>Se,withErrorReporting:()=>Z,withHistory:()=>j,withLogging:()=>J,withPerformanceMonitoring:()=>ee,withPermissions:()=>X,withRetry:()=>ne,withSnapshot:()=>P,withTimeTravel:()=>O,withValidation:()=>Q,yieldMachine:()=>ue});module.exports=Ze(Bn);function $(e,n){let t=e(n),r=n;for(;;){let{value:a,done:i}=t.next(r);if(i)return a;r=a}}function de(e){return function*(){return yield e}()}function ue(e){return e}function ye(e,n){return n.reduce((t,r)=>$(r,t),e)}function le(e){return e}function Me(e,n,t=(r,a)=>{console.log(`Step ${r}:`,a.context)}){let r=e(n),a=n,i=0;for(t(i,a);;){let{value:o,done:s}=r.next(a);if(s)return console.log("Final:",o),o;a=o,i++,t(i,a)}}async function xe(e,n){let t=e(n),r=n;for(;;){let{value:a,done:i}=await t.next(r);if(i)return a;r=a}}async function*he(e){return yield e}var pe=Symbol("MachineMeta"),fe=Symbol("__machine_runtime_meta__");function b(e,n){let t=e[fe]||{},r={...t,...n};n.guards&&t.guards?r.guards=[...n.guards,...t.guards]:n.guards&&(r.guards=[...n.guards]),n.actions&&t.actions?r.actions=[...n.actions,...t.actions]:n.actions&&(r.actions=[...n.actions]),Object.defineProperty(e,fe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ce(e,n){return b(n,{target:e.name||e.toString()}),n}function ge(e,n){return b(n,{description:e}),n}function me(e,n){return b(n,{guards:[e]}),n}function Te(e,n){return b(n,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),n}function be(e,n){return b(n,{actions:[e]}),n}function R(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:i}=t,o={...t,onFail:r,errorMessage:a,description:i},s=function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(e(u,...d)){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:o,enumerable:!1}),b(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function S(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:i}=t,o={...t,onFail:r,errorMessage:a,description:i},s=async function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(await Promise.resolve(e(u,...d))){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:o,enumerable:!1}),b(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function we(e){return{do(n){let t=R(e,n);return t.else=function(r){return R(e,n,{onFail:r})},t}}}function Ee(e){return{do(n){let t=S(e,n);return t.else=function(r){return S(e,n,{onFail:r})},t}}}function ve(e,n){return n}function Ae(e,n){let t=e,r=s=>{t=s,n==null||n(s)},{context:a,...i}=e,o=new Proxy({},{get(s,d){let c=t[d];if(typeof c=="function")return(...u)=>{let y=c.apply(t.context,u),M=Object.assign({context:y.context},i);return r(M),M}}});return{get state(){return t},get context(){return t.context},actions:o,setState:r}}function Fe(e,n,t){let r=()=>{let i=e.getContext(),o=t(i),s=n[o];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(o)}".`);return s(i)},a=new Proxy({},{get(i,o){let s=r(),d=s[o];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${o}" is not valid in the current state.`);return(...c)=>d.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:a}}function en(e,n){return function(r){return Fe(e,r,n)}}function nn(e,n){let t=Ae(n),r=e(t),a=r.next();for(;!a.done;)a=r.next();return a.value}function tn(e,n){let t=e(n),r=t.next();for(;!r.done;)r=t.next();return r.value}var W=class{constructor(n){this.store=n}get context(){return this.store.getContext()}setContext(n){this.store.setContext(n)}};function rn(e,n){let t=new e(n);return new Proxy({},{get(r,a){let i=n.getContext();if(a in i)return i[a];let o=t[a];if(typeof o=="function")return(...s)=>o.apply(t,s)},set(r,a,i){let o=n.getContext();if(a in o){let s={...o,[a]:i};return n.setContext(s),!0}return!1},has(r,a){let i=n.getContext();return a in i||typeof t[a]=="function"},ownKeys(r){let a=n.getContext(),i=Object.keys(a),o=Object.getOwnPropertyNames(Object.getPrototypeOf(t)).filter(s=>s!=="constructor"&&typeof t[s]=="function");return Array.from(new Set([...i,...o]))},getOwnPropertyDescriptor(r,a){let i=n.getContext();if(a in i||typeof t[a]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function an(e,n,t){let r=()=>{let a=t(e),i=n[a];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(a)}".`);return i(e)};return new Proxy(e,{get(a,i,o){if(i in a)return a[i];let s=r(),d=s[i];if(typeof d=="function")return(...c)=>{let u=d.apply(s.context,c);if(typeof u!="object"||u===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(a).forEach(y=>delete a[y]),Object.assign(a,u)}},set(a,i,o,s){return a[i]=o,!0},has(a,i){let o=r();return i in a||typeof o[i]=="function"}})}function on(e){return function(...n){let t=this.context.child;if(typeof t[e]=="function"){let r=t[e](...n);return E(this,{...this.context,child:r})}return this}}function sn(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var G=class extends m{constructor(t){super({status:"idle"});this.config=t;this.fetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},w=class extends m{constructor(t,r,a){super({status:"loading",abortController:new AbortController,attempts:a});this.config=t;this.params=r;this.succeed=t=>{var r,a;return(a=(r=this.config).onSuccess)==null||a.call(r,t),new I(this.config,{status:"success",data:t})};this.fail=t=>{var a,i,o;let r=(a=this.config.maxRetries)!=null?a:3;return this.context.attempts<r?new D(this.config,this.params,t,this.context.attempts):((o=(i=this.config).onError)==null||o.call(i,t),new V(this.config,{status:"error",error:t}))};this.cancel=()=>(this.context.abortController.abort(),new U(this.config));this.execute()}async execute(){}},D=class extends m{constructor(t,r,a,i){super({status:"retrying",error:a,attempts:i});this.config=t;this.params=r;this.retry=t=>new w(this.config,t!=null?t:this.params,this.context.attempts+1)}},I=class extends m{constructor(t,r){super(r);this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},V=class extends m{constructor(t,r){super(r);this.config=t;this.retry=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},U=class extends m{constructor(t){super({status:"canceled"});this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}};function cn(e){return new G(e)}function L(e,n){let t={...e.context,...n.context},r={...e},a={...n};delete r.context,delete a.context;let i={};for(let o in r){let s=r[o];i[o]=(...d)=>{let c=s.apply(e.context,d);return L(c,n)}}for(let o in a){let s=a[o];i[o]=(...d)=>{let c=s.apply(n.context,d);return L(e,c)}}return{context:t,...i}}var q=Symbol("CANCEL");function C(e,n,t={}){let{continueOnError:r=!1,logErrors:a=!0,onError:i}=t,o={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(o[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(o[s]=function(...c){let u=s,y=o.context,M=()=>{let l;try{l=d.apply(this,c)}catch(h){if(n.error)try{n.error({transitionName:u,context:y,args:[...c],error:h})}catch(f){if(!r)throw f;a&&console.error(`Middleware error hook error for ${u}:`,f),i==null||i(f,"error",{transitionName:u,context:y,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in o)Object.prototype.hasOwnProperty.call(o,f)&&f!=="context"&&!(f in h)&&(h[f]=o[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&o[f]&&(h[f]=o[f])}}return h};if(l&&typeof l.then=="function")return l.then(f=>{if(x(f),n.after)try{let g=n.after({transitionName:u,prevContext:y,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;a&&console.error(`Middleware after hook error for ${u}:`,g),i==null||i(g,"after",{transitionName:u,prevContext:y,nextContext:f.context,args:c})}return f});if(x(l),n.after)try{let h=n.after({transitionName:u,prevContext:y,nextContext:l.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>l).catch(f=>{if(!r)throw f;return a&&console.error(`Middleware after hook error for ${u}:`,f),i==null||i(f,"after",{transitionName:u,prevContext:y,nextContext:l.context,args:c}),l})}catch(h){if(!r)throw h;a&&console.error(`Middleware after hook error for ${u}:`,h),i==null||i(h,"after",{transitionName:u,prevContext:y,nextContext:l.context,args:c})}return l};if(n.before)try{let l=n.before({transitionName:u,context:y,args:[...c]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(x=>x===q?o:M()).catch(x=>{if(!r)throw x;return a&&console.error(`Middleware before hook error for ${u}:`,x),i==null||i(x,"before",{transitionName:u,context:y,args:c}),M()});if(l===q)return o}catch(l){if(!r)throw l;a&&console.error(`Middleware before hook error for ${u}:`,l),i==null||i(l,"before",{transitionName:u,context:y,args:c})}return M()})}return o}function J(e,n={}){let{logger:t=console.log,includeArgs:r=!1,includeContext:a=!0}=n;return C(e,{before:({transitionName:i,args:o})=>{let s=r?`→ ${i} [${o.join(", ")}]`:`→ ${i}`;t(s)},after:({transitionName:i,nextContext:o})=>{let s=a?` ${JSON.stringify(o)}`:"";t(`✓ ${i}${s}`)},error:({transitionName:i,error:o})=>{console.error(`[Machine] ${i} failed:`,o)}})}function Y(e,n,t={}){let{eventPrefix:r="state_transition",includePrevContext:a=!1,includeArgs:i=!1}=t;return C(e,{after:({transitionName:o,prevContext:s,nextContext:d,args:c})=>{let u=`${r}.${o}`,y={transition:o};a&&(y.from=s),y.to=d,i&&(y.args=c),n(u,y)}})}function Q(e,n){return C(e,{before:t=>{if(n(t)===!1)throw new Error(`Validation failed for transition: ${t.transitionName}`)}})}function X(e,n){return C(e,{before:t=>{if(!n(t))throw new Error(`Unauthorized transition: ${t.transitionName}`)}})}function Z(e,n,t={}){let{includeArgs:r=!1}=t;return C(e,{error:a=>{let i={transition:a.transitionName,context:a.context,...r&&{args:a.args}};n(a.error,i)}})}function ee(e,n){let t=new Map;return C(e,{before:r=>{t.set(r.transitionName,Date.now())},after:r=>{let a=t.get(r.transitionName);if(a){let i=Date.now()-a;t.delete(r.transitionName);let o={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};n(o)}}})}function ne(e,n={}){var d,c;let{maxAttempts:t=(d=n.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:a=(c=n.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:o}=n,s={...e};for(let u in e){if(!Object.prototype.hasOwnProperty.call(e,u))continue;let y=e[u];typeof y=="function"&&u!=="context"&&(s[u]=async function(...M){let l,x=0;for(;x<t;)try{return await y.apply(this,M)}catch(h){if(l=h,x++,x<t&&r(l,x)){o==null||o(l,x);let g=(typeof a=="function"?a(x):a)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw l}throw l})}return s}function dn(e,n){return t=>C(t,e,n)}function j(e,n={}){let{maxSize:t,serializer:r,onEntry:a}=n,i=[],o=0,s=C(e,{before:({transitionName:d,args:c})=>{let u={id:`entry-${o++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{u.serializedArgs=r.serialize(c)}catch(y){console.error("Failed to serialize history args:",y)}i.push(u),t&&i.length>t&&i.shift(),a==null||a(u)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,o=0}})}function P(e,n={}){let{maxSize:t,serializer:r,captureSnapshot:a,onlyOnChange:i=!1}=n,o=[],s=0,d=C(e,{after:({transitionName:u,prevContext:y,nextContext:M})=>{if(i&&JSON.stringify(y)===JSON.stringify(M))return;let l={id:`snapshot-${s++}`,transitionName:u,before:{...y},after:{...M},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(y),l.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(a)try{l.diff=a(y,M)}catch(x){console.error("Failed to capture snapshot:",x)}o.push(l),t&&o.length>t&&o.shift()}});return Object.assign(d,{snapshots:o,clearSnapshots:()=>{o.length=0,s=0},restoreSnapshot:u=>{let y=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:u},y)}})}function O(e,n={}){let{maxSize:t,serializer:r,onRecord:a}=n,i=[],o=[],s=0,d=0,c=C(e,{before:({transitionName:M,args:l})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...l],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(l)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),t&&i.length>t&&i.shift(),a==null||a("history",x)},after:({transitionName:M,prevContext:l,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:M,before:{...l},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(l),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}o.push(h),t&&o.length>t&&o.shift(),a==null||a("snapshot",h)}});return Object.assign(c,{history:i,snapshots:o,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{o.length=0,d=0},clearTimeTravel:()=>{i.length=0,o.length=0,s=0,d=0},restoreSnapshot:M=>{let l=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:M},l)},replayFrom:M=>{var g;if(M<0||M>=i.length)throw new Error(`Invalid replay start index: ${M}`);let l=(g=o[M])==null?void 0:g.before;if(!l)throw new Error(`No snapshot available for index ${M}`);let x=i.slice(M),f=Object.assign({context:l},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let ce=f[T.transitionName];ce&&(f=ce.apply(f.context,T.args))}return f}})}function un(e,...n){return n.reduce((t,r)=>r(t),e)}function _(e,...n){return n.reduce((t,r)=>r(t),e)}var te=class e{constructor(n){this.machine=n}with(n){let t=n(this.machine);return new e(t)}build(){return this.machine}};function yn(e){return new te(e)}function N(e,n){let t=function(r){return n(r)?e(r):r};return t.middleware=e,t.when=n,t}function ln(e){return N(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Mn(e,n,t){return N(t,r=>r.context[e]===n)}function xn(){let e=new Map;return{register(n,t,r,a){if(e.has(n))throw new Error(`Middleware '${n}' is already registered`);return e.set(n,{name:n,middleware:t,description:r,priority:a}),this},unregister(n){return e.delete(n)},has(n){return e.has(n)},get(n){return e.get(n)},list(){return Array.from(e.values()).sort((n,t)=>{var r,a;return((r=n.priority)!=null?r:0)-((a=t.priority)!=null?a:0)})},apply(n,t){let r=t.map(a=>{let i=e.get(a);if(!i)throw new Error(`Middleware '${a}' is not registered`);return i}).sort((a,i)=>{var o,s;return((o=a.priority)!=null?o:0)-((s=i.priority)!=null?s:0)});return _(n,...r.map(a=>a.middleware))},applyAll(n){let t=this.list();return _(n,...t.map(r=>r.middleware))}}}function hn(e={}){let{continueOnError:n=!1,logErrors:t=!0,onError:r}=e;return(a,...i)=>{let o=a,s=[],d=!0;for(let c=0;c<i.length;c++){let u=i[c];try{if("middleware"in u&&"when"in u){if(!u.when(o))continue;o=u.middleware(o)}else o=u(o)}catch(y){if(d=!1,!n)throw y;s.push({error:y,middlewareIndex:c,middlewareName:u.name}),t&&console.error(`Pipeline middleware error at index ${c}:`,y),r==null||r(y,c,u.name)}}return{machine:o,errors:s,success:d}}}function fn(...e){return n=>_(n,...e)}function pn(e,n){return t=>{for(let[r,a]of e)if(r(t))return a(t);return n?n(t):t}}function re(e){return typeof e=="function"&&e.length===1}function Cn(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&re(e.middleware)&&typeof e.when=="function"}function gn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||k(e.prevContext,n)&&k(e.nextContext,n))}function mn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||k(e.context,n))}function Tn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!n||k(e.context,n))}function bn(e,n){if(e===null||typeof e!="object")return!1;let t=e;return!("before"in t&&t.before!==void 0&&typeof t.before!="function"||"after"in t&&t.after!==void 0&&typeof t.after!="function"||"error"in t&&t.error!==void 0&&typeof t.error!="function")}function wn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function k(e,n){return e!==null&&typeof e=="object"}function En(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&re(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function vn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var B=class{constructor(n){this.machine=n;this.middlewares=[]}withLogging(n){return this.middlewares.push(t=>J(t,n)),this}withAnalytics(n,t){return this.middlewares.push(r=>Y(r,n,t)),this}withValidation(n,t){return this.middlewares.push(r=>Q(r,n)),this}withPermissions(n){return this.middlewares.push(t=>X(t,n)),this}withErrorReporting(n,t){return this.middlewares.push(r=>Z(r,n,t)),this}withPerformanceMonitoring(n,t){return this.middlewares.push(r=>ee(r,n)),this}withRetry(n){return this.middlewares.push(t=>ne(t,n)),this}withHistory(n){return this.middlewares.push(t=>j(t,n)),this}withSnapshot(n){return this.middlewares.push(t=>P(t,n)),this}withTimeTravel(n){return this.middlewares.push(t=>O(t,n)),this}withDebugging(){return this.middlewares.push(n=>Se(n)),this}withCustom(n){return this.middlewares.push(n),this}withConditional(n,t){return this.middlewares.push(N(n,t)),this}build(){let n=this.machine;for(let t of this.middlewares)n=t(n);return n}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Re(e){return new B(e)}function An(e={}){return{create:n=>{let t=Re(n);return e.logging&&t.withLogging(e.logging),e.analytics&&t.withAnalytics(e.analytics.track,e.analytics.options),e.history&&t.withHistory(e.history),e.snapshot&&t.withSnapshot(e.snapshot),e.timeTravel&&t.withTimeTravel(e.timeTravel),e.retry&&t.withRetry(e.retry),t}}}function Se(e){return O(P(j(e)))}function je(e,n){return e instanceof n}function Pe(e,...n){return{type:e,args:n}}function Oe(e,n){return E(e,t=>({...t,...n}))}async function _e(e,...n){let t=e;for(let r of n)t=await r(t);return t}function ke(e,n){return n?console.log(n,e.context):console.log(e.context),e}function Be(e,n){return function(...t){let r=n(this.context,...t);return p(r,e())}}function Ne(e,n,...t){return e.apply(n,t)}function ae(e){return new Proxy(e,{get(n,t){let r=n[t];return typeof r=="function"?function(...a){let i=r.apply(n.context,a);return i&&typeof i=="object"&&"context"in i?ae(i):i}:r}})}var K=class e{constructor(n){return this.wrappedMachine=n,new Proxy(this,{get:(t,r)=>{if(r==="wrappedMachine")return Reflect.get(t,r);if(r==="context")return this.wrappedMachine.context;let a=this.wrappedMachine[r];return typeof a=="function"?(...i)=>{let o=a.apply(this.wrappedMachine.context,i);return o&&typeof o=="object"&&"context"in o?new e(o):o}:a}})}};function Ke(){return function(n){return function(...t){let r=n(this.context,...t);return p(r,this)}}}function ie(e){return{machine:e,addTransition:function(n,t){let r=function(...i){let o=t(this.context,...i);return p(o,this)},a=se(e,{[n]:r});return ie(a)}}}function oe(e){return function(t){let r={},a=Object.fromEntries(Object.entries(t).map(([i,o])=>[i,function(...s){let d=o(this.context,...s);return p(d,r)}]));return Object.assign(r,a),p(e,r)}}function He(e,n){return n!==void 0?p(e,n):oe(e)}function ze(...e){let n=new Map;for(let[s,d,c]of e){if(n.has(s))throw new Error(`Duplicate matcher case name: "${s}"`);n.set(s,{predicate:c})}let t=new Proxy({},{get(s,d){return function(u){let y=n.get(d);if(!y){let M=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${M}`)}return y.predicate(u)}}}),r=new Proxy({},{get(s,d){return function(u){if(!n.has(d)){let y=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${y}`)}return{__brand:"CaseHandler",__name:d,__machine:void 0,__return:void 0,handler:u}}}}),a={__exhaustive:!0};function i(s){return{is(...d){if(d.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let c=d[d.length-1];if(!c||typeof c!="object"||!("__exhaustive"in c))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let u=d.slice(0,-1);for(let l of u){let x=l.__name,h=n.get(x);if(!h)throw new Error(`Internal error: Unknown matcher case in handler: ${x}`);if(h.predicate(s))return l.handler(s)}let y=u.map(l=>l.__name).join(", "),M=Array.from(n.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
1
+ "use strict";var I=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ze=Object.prototype.hasOwnProperty;var et=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},tt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xe(t))!Ze.call(e,o)&&o!==n&&I(e,o,{get:()=>t[o],enumerable:!(r=Qe(t,o))||r.enumerable});return e};var nt=e=>tt(I({},"__esModule",{value:!0}),e);var It={};et(It,{Actor:()=>A,BoundMachine:()=>K,CANCEL:()=>q,META_KEY:()=>Ce,MachineBase:()=>m,MachineExclude:()=>Oe,MachineUnion:()=>Pe,MiddlewareBuilder:()=>B,MultiMachineBase:()=>$,action:()=>we,bindTransitions:()=>ae,branch:()=>gt,call:()=>Ie,chain:()=>xt,classCase:()=>De,combine:()=>Ct,combineFactories:()=>_t,compose:()=>lt,composeTyped:()=>k,createActor:()=>F,createAsyncMachine:()=>Ye,createContext:()=>Ot,createCustomMiddleware:()=>yt,createEnsemble:()=>Re,createEnsembleFactory:()=>rt,createEvent:()=>_e,createFetchMachine:()=>ut,createFlow:()=>xe,createFunctionalMachine:()=>se,createMachine:()=>f,createMachineBuilder:()=>Bt,createMachineFactory:()=>Pt,createMatcher:()=>We,createMiddleware:()=>C,createMiddlewareFactory:()=>Rt,createMiddlewareRegistry:()=>pt,createMultiMachine:()=>it,createMutableMachine:()=>st,createParallelMachine:()=>L,createPipeline:()=>ft,createRunner:()=>Fe,createTransition:()=>He,createTransitionExtender:()=>ie,createTransitionFactory:()=>ze,customCase:()=>Ue,delegateToChild:()=>ct,describe:()=>me,discriminantCase:()=>Ge,extendTransitions:()=>ce,forContext:()=>Ve,fromObservable:()=>Je,fromPromise:()=>qe,guard:()=>R,guardAsync:()=>S,guarded:()=>Te,hasState:()=>H,inDevelopment:()=>Mt,invoke:()=>be,isConditionalMiddleware:()=>mt,isMiddlewareContext:()=>bt,isMiddlewareError:()=>wt,isMiddlewareFn:()=>re,isMiddlewareHooks:()=>Et,isMiddlewareOptions:()=>vt,isMiddlewareResult:()=>Tt,isNamedMiddleware:()=>At,isPipelineConfig:()=>Ft,isState:()=>ke,logState:()=>Ke,machineExclude:()=>jt,machineUnion:()=>St,matchMachine:()=>Nt,mergeContext:()=>Be,metadata:()=>Ae,middlewareBuilder:()=>Se,next:()=>Ht,overrideTransitions:()=>kt,pipeTransitions:()=>Ne,run:()=>z,runAsync:()=>he,runMachine:()=>Kt,runSequence:()=>le,runWithDebug:()=>Me,runWithEnsemble:()=>at,runWithRunner:()=>ot,setContext:()=>E,spawn:()=>Le,state:()=>$e,step:()=>ue,stepAsync:()=>pe,toggle:()=>dt,transitionTo:()=>ge,when:()=>N,whenContext:()=>ht,whenGuard:()=>Ee,whenGuardAsync:()=>ve,withAnalytics:()=>Y,withDebugging:()=>je,withErrorReporting:()=>Z,withHistory:()=>j,withLogging:()=>J,withPerformanceMonitoring:()=>ee,withPermissions:()=>X,withRetry:()=>te,withSnapshot:()=>P,withTimeTravel:()=>O,withValidation:()=>Q,yieldMachine:()=>ye});module.exports=nt(It);function z(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=n.next(r);if(a)return o;r=o}}function ue(e){return function*(){return yield e}()}function ye(e){return e}function le(e,t){return t.reduce((n,r)=>z(r,n),e)}function xe(e){return e}function Me(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,a=0;for(n(a,o);;){let{value:i,done:s}=r.next(o);if(s)return console.log("Final:",i),i;o=i,a++,n(a,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=await n.next(r);if(a)return o;r=o}}async function*pe(e){return yield e}var Ce=Symbol("MachineMeta"),fe=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[fe]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,fe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,t){return b(t,{target:e.name||e.toString()}),t}function me(e,t){return b(t,{description:e}),t}function Te(e,t){return b(t,{guards:[e]}),t}function be(e,t){return b(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function we(e,t){return b(t,{actions:[e]}),t}function R(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,i={...n,onFail:r,errorMessage:o,description:a},s=function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(e(u,...d)){let x=c?this.context:this;return t.apply(x,d)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),s}function S(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,i={...n,onFail:r,errorMessage:o,description:a},s=async function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(await Promise.resolve(e(u,...d))){let x=c?this.context:this;return t.apply(x,d)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),s}function Ee(e){return{do(t){let n=R(e,t);return n.else=function(r){return R(e,t,{onFail:r})},n}}}function ve(e){return{do(t){let n=S(e,t);return n.else=function(r){return S(e,t,{onFail:r})},n}}}function Ae(e,t){return t}function Fe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...a}=e,i=new Proxy({},{get(s,d){let c=n[d];if(typeof c=="function")return(...u)=>{let y=c.apply(n.context,u),x=Object.assign({context:y.context},a);return r(x),x}}});return{get state(){return n},get context(){return n.context},actions:i,setState:r}}function Re(e,t,n){let r=()=>{let a=e.getContext(),i=n(a),s=t[i];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(i)}".`);return s(a)},o=new Proxy({},{get(a,i){let s=r(),d=s[i];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${i}" is not valid in the current state.`);return(...c)=>d.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function rt(e,t){return function(r){return Re(e,r,t)}}function ot(e,t){let n=Fe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function at(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var $=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function it(e,t){let n=new e(t);return new Proxy({},{get(r,o){let a=t.getContext();if(o in a)return a[o];let i=n[o];if(typeof i=="function")return(...s)=>i.apply(n,s)},set(r,o,a){let i=t.getContext();if(o in i){let s={...i,[o]:a};return t.setContext(s),!0}return!1},has(r,o){let a=t.getContext();return o in a||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),a=Object.keys(o),i=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...a,...i]))},getOwnPropertyDescriptor(r,o){let a=t.getContext();if(o in a||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function st(e,t,n){let r=()=>{let o=n(e),a=t[o];if(!a)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return a(e)};return new Proxy(e,{get(o,a,i){if(a in o)return o[a];let s=r(),d=s[a];if(typeof d=="function")return(...c)=>{let u=d.apply(s.context,c);if(typeof u!="object"||u===null){console.warn(`[MutableMachine] Transition "${String(a)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(y=>delete o[y]),Object.assign(o,u)}},set(o,a,i,s){return o[a]=i,!0},has(o,a){let i=r();return a in o||typeof i[a]=="function"}})}function ct(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return E(this,{...this.context,child:r})}return this}}function dt(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var W=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},w=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new G(this.config,{status:"success",data:n})};this.fail=n=>{var o,a,i;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new D(this.config,this.params,n,this.context.attempts):((i=(a=this.config).onError)==null||i.call(a,n),new U(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new V(this.config));this.execute()}async execute(){}},D=class extends m{constructor(n,r,o,a){super({status:"retrying",error:o,attempts:a});this.config=n;this.params=r;this.retry=n=>new w(this.config,n!=null?n:this.params,this.context.attempts+1)}},G=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},U=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},V=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}};function ut(e){return new W(e)}function L(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let a={};for(let i in r){let s=r[i];a[i]=(...d)=>{let c=s.apply(e.context,d);return L(c,t)}}for(let i in o){let s=o[i];a[i]=(...d)=>{let c=s.apply(t.context,d);return L(e,c)}}return{context:n,...a}}var q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:a}=n,i={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(i[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(i[s]=function(...c){let u=s,y=i.context,x=()=>{let l;try{l=d.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:u,context:y,args:[...c],error:h})}catch(p){if(!r)throw p;o&&console.error(`Middleware error hook error for ${u}:`,p),a==null||a(p,"error",{transitionName:u,context:y,args:c,error:h})}throw h}let M=h=>{if(h&&typeof h=="object"&&h.context){for(let p in i)Object.prototype.hasOwnProperty.call(i,p)&&p!=="context"&&!(p in h)&&(h[p]=i[p]);for(let p in h){if(!Object.prototype.hasOwnProperty.call(h,p))continue;typeof h[p]=="function"&&p!=="context"&&i[p]&&(h[p]=i[p])}}return h};if(l&&typeof l.then=="function")return l.then(p=>{if(M(p),t.after)try{let g=t.after({transitionName:u,prevContext:y,nextContext:p.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>p)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${u}:`,g),a==null||a(g,"after",{transitionName:u,prevContext:y,nextContext:p.context,args:c})}return p});if(M(l),t.after)try{let h=t.after({transitionName:u,prevContext:y,nextContext:l.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>l).catch(p=>{if(!r)throw p;return o&&console.error(`Middleware after hook error for ${u}:`,p),a==null||a(p,"after",{transitionName:u,prevContext:y,nextContext:l.context,args:c}),l})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${u}:`,h),a==null||a(h,"after",{transitionName:u,prevContext:y,nextContext:l.context,args:c})}return l};if(t.before)try{let l=t.before({transitionName:u,context:y,args:[...c]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(M=>M===q?i:x()).catch(M=>{if(!r)throw M;return o&&console.error(`Middleware before hook error for ${u}:`,M),a==null||a(M,"before",{transitionName:u,context:y,args:c}),x()});if(l===q)return i}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${u}:`,l),a==null||a(l,"before",{transitionName:u,context:y,args:c})}return x()})}return i}function J(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:a,args:i})=>{let s=r?`→ ${a} [${i.join(", ")}]`:`→ ${a}`;n(s)},after:({transitionName:a,nextContext:i})=>{let s=o?` ${JSON.stringify(i)}`:"";n(`✓ ${a}${s}`)},error:({transitionName:a,error:i})=>{console.error(`[Machine] ${a} failed:`,i)}})}function Y(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=n;return C(e,{after:({transitionName:i,prevContext:s,nextContext:d,args:c})=>{let u=`${r}.${i}`,y={transition:i};o&&(y.from=s),y.to=d,a&&(y.args=c),t(u,y)}})}function Q(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function X(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function Z(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let a={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,a)}})}function ee(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let a=Date.now()-o;n.delete(r.transitionName);let i={transitionName:r.transitionName,duration:a,context:r.nextContext||r.prevContext};t(i)}}})}function te(e,t={}){var d,c;let{maxAttempts:n=(d=t.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:a=2,onRetry:i}=t,s={...e};for(let u in e){if(!Object.prototype.hasOwnProperty.call(e,u))continue;let y=e[u];typeof y=="function"&&u!=="context"&&(s[u]=async function(...x){let l,M=0;for(;M<n;)try{return await y.apply(this,x)}catch(h){if(l=h,M++,M<n&&r(l,M)){i==null||i(l,M);let g=(typeof o=="function"?o(M):o)*Math.pow(a,M-1);await new Promise(T=>setTimeout(T,g))}else throw l}throw l})}return s}function yt(e,t){return n=>C(n,e,t)}function j(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,a=[],i=0,s=C(e,{before:({transitionName:d,args:c})=>{let u={id:`entry-${i++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{u.serializedArgs=r.serialize(c)}catch(y){console.error("Failed to serialize history args:",y)}a.push(u),n&&a.length>n&&a.shift(),o==null||o(u)}});return Object.assign(s,{history:a,clearHistory:()=>{a.length=0,i=0}})}function P(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=t,i=[],s=0,d=C(e,{after:({transitionName:u,prevContext:y,nextContext:x})=>{if(a&&JSON.stringify(y)===JSON.stringify(x))return;let l={id:`snapshot-${s++}`,transitionName:u,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(y),l.serializedAfter=r.serialize(x)}catch(M){console.error("Failed to serialize snapshot:",M)}if(o)try{l.diff=o(y,x)}catch(M){console.error("Failed to capture snapshot:",M)}i.push(l),n&&i.length>n&&i.shift()}});return Object.assign(d,{snapshots:i,clearSnapshots:()=>{i.length=0,s=0},restoreSnapshot:u=>{let y=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="snapshots"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&typeof e[x]=="function"));return Object.assign({context:u},y)}})}function O(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,a=[],i=[],s=0,d=0,c=C(e,{before:({transitionName:x,args:l})=>{let M={id:`entry-${s++}`,transitionName:x,args:[...l],timestamp:Date.now()};if(r)try{M.serializedArgs=r.serialize(l)}catch(h){console.error("Failed to serialize history args:",h)}a.push(M),n&&a.length>n&&a.shift(),o==null||o("history",M)},after:({transitionName:x,prevContext:l,nextContext:M})=>{let h={id:`snapshot-${d++}`,transitionName:x,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(l),h.serializedAfter=r.serialize(M)}catch(p){console.error("Failed to serialize snapshot:",p)}i.push(h),n&&i.length>n&&i.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:a,snapshots:i,clearHistory:()=>{a.length=0,s=0},clearSnapshots:()=>{i.length=0,d=0},clearTimeTravel:()=>{a.length=0,i.length=0,s=0,d=0},restoreSnapshot:x=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="history"&&M!=="snapshots"&&M!=="clearHistory"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&M!=="clearTimeTravel"&&M!=="replayFrom"&&typeof e[M]=="function"));return Object.assign({context:x},l)},replayFrom:x=>{var g;if(x<0||x>=a.length)throw new Error(`Invalid replay start index: ${x}`);let l=(g=i[x])==null?void 0:g.before;if(!l)throw new Error(`No snapshot available for index ${x}`);let M=a.slice(x),p=Object.assign({context:l},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of M){let de=p[T.transitionName];de&&(p=de.apply(p.context,T.args))}return p}})}function lt(e,...t){return t.reduce((n,r)=>r(n),e)}function k(e,...t){return t.reduce((n,r)=>r(n),e)}var ne=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function xt(e){return new ne(e)}function N(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Mt(e){return N(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function ht(e,t,n){return N(n,r=>r.context[e]===t)}function pt(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let a=e.get(o);if(!a)throw new Error(`Middleware '${o}' is not registered`);return a}).sort((o,a)=>{var i,s;return((i=o.priority)!=null?i:0)-((s=a.priority)!=null?s:0)});return k(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return k(t,...n.map(r=>r.middleware))}}}function ft(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...a)=>{let i=o,s=[],d=!0;for(let c=0;c<a.length;c++){let u=a[c];try{if("middleware"in u&&"when"in u){if(!u.when(i))continue;i=u.middleware(i)}else i=u(i)}catch(y){if(d=!1,!t)throw y;s.push({error:y,middlewareIndex:c,middlewareName:u.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,y),r==null||r(y,c,u.name)}}return{machine:i,errors:s,success:d}}}function Ct(...e){return t=>k(t,...e)}function gt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function re(e){return typeof e=="function"&&e.length===1}function mt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&re(e.middleware)&&typeof e.when=="function"}function Tt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||_(e.prevContext,t)&&_(e.nextContext,t))}function bt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||_(e.context,t))}function wt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||_(e.context,t))}function Et(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function vt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function _(e,t){return e!==null&&typeof e=="object"}function At(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&re(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Ft(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var B=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>J(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Y(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>Q(r,t)),this}withPermissions(t){return this.middlewares.push(n=>X(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ee(r,t)),this}withRetry(t){return this.middlewares.push(n=>te(n,t)),this}withHistory(t){return this.middlewares.push(n=>j(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>P(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>O(n,t)),this}withDebugging(){return this.middlewares.push(t=>je(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(N(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Se(e){return new B(e)}function Rt(e={}){return{create:t=>{let n=Se(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function je(e){return O(P(j(e)))}function oe(e){let t={},n=e;for(;n&&n!==Object.prototype;){let r=Object.getOwnPropertyDescriptors(n);for(let[o,a]of Object.entries(r))o!=="constructor"&&(o in t||(t[o]=a));n=Object.getPrototypeOf(n)}return t}function Pe(...e){let t=e[0];class n extends t{constructor(a){super(a)}}let r=o=>function(...a){let i=o.apply(this,a);if(i&&typeof i=="object"&&"context"in i){let s={...this.context,...i.context};return new n(s)}return i};for(let o of e){let a=oe(o.prototype);for(let[i,s]of Object.entries(a))if(i!=="constructor")if(typeof s.value=="function"){let d=s.value,c=r(d);Object.defineProperty(n.prototype,i,{...s,value:c})}else Object.defineProperty(n.prototype,i,s)}return n}function Oe(e,...t){class n extends m{constructor(a){super(a)}}let r=oe(e.prototype);for(let[o,a]of Object.entries(r))if(o!=="constructor")if(typeof a.value=="function"){let i=a.value,s=function(...d){let c=i.apply(this,d);return c&&typeof c=="object"&&"context"in c?new n({...this.context,...c.context}):c};Object.defineProperty(n.prototype,o,{...a,value:s})}else Object.defineProperty(n.prototype,o,a);for(let o of t){let a=oe(o.prototype);for(let i of Object.keys(a))Object.prototype.hasOwnProperty.call(n.prototype,i)&&delete n.prototype[i]}return n}function St(...e){let t=e.map(a=>a.constructor),n=e.map(a=>a.context),r=Object.assign({},...n),o=Pe(...t);return new o(r)}function jt(e,...t){let n=e.constructor,r=t.map(a=>a.constructor),o=Oe(n,...r);return new o(e.context)}function ke(e,t){return e instanceof t}function _e(e,...t){return{type:e,args:t}}function Be(e,t){return E(e,n=>({...n,...t}))}async function Ne(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Ke(e,t){return t?console.log(t,e.context):console.log(e.context),e}function He(e,t){return function(...n){let r=t(this.context,...n);return f(r,e())}}function Ie(e,t,...n){return e.apply(t,n)}function ae(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let a=r.apply(t.context,o);return a&&typeof a=="object"&&"context"in a?ae(a):a}:r}})}var K=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...a)=>{let i=o.apply(this.wrappedMachine.context,a);return i&&typeof i=="object"&&"context"in i?new e(i):i}:o}})}};function ze(){return function(t){return function(...n){let r=t(this.context,...n);return f(r,this)}}}function ie(e){return{machine:e,addTransition:function(t,n){let r=function(...a){let i=n(this.context,...a);return f(i,this)},o=ce(e,{[t]:r});return ie(o)}}}function se(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([a,i])=>[a,function(...s){let d=i(this.context,...s);return f(d,r)}]));return Object.assign(r,o),f(e,r)}}function $e(e,t){return t!==void 0?f(e,t):se(e)}function We(...e){let t=new Map;for(let[s,d,c]of e){if(t.has(s))throw new Error(`Duplicate matcher case name: "${s}"`);t.set(s,{predicate:c})}let n=new Proxy({},{get(s,d){return function(u){let y=t.get(d);if(!y){let x=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${x}`)}return y.predicate(u)}}}),r=new Proxy({},{get(s,d){return function(u){if(!t.has(d)){let y=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${y}`)}return{__brand:"CaseHandler",__name:d,__machine:void 0,__return:void 0,handler:u}}}}),o={__exhaustive:!0};function a(s){return{is(...d){if(d.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let c=d[d.length-1];if(!c||typeof c!="object"||!("__exhaustive"in c))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let u=d.slice(0,-1);for(let l of u){let M=l.__name,h=t.get(M);if(!h)throw new Error(`Internal error: Unknown matcher case in handler: ${M}`);if(h.predicate(s))return l.handler(s)}let y=u.map(l=>l.__name).join(", "),x=Array.from(t.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
2
2
  Handled cases: [${y}]
3
- All cases: [${M}]
4
- This may occur if predicates don't cover all runtime possibilities.`)}}}function o(s){for(let[d,c,u]of e)if(u(s))return d;return null}return Object.assign(o,{is:t,when:i,case:r,exhaustive:a})}function $e(e,n){return[e,void 0,t=>t instanceof n]}function We(e,n,t){return[e,void 0,r=>H(r,n,t)]}function Ge(e,n){return[e,void 0,n]}function De(){return{case(e,n,t){return[e,void 0,r=>H(r,n,t)]}}}var v=class v{constructor(n){this._observers=new Set;this._queue=[];this._processing=!1;this._state=n,this.ref={send:t=>this.dispatch(t)},this.send=new Proxy({},{get:(t,r)=>(...a)=>{this.dispatch({type:r,args:a})}})}static inspect(n){v._inspector=n}getSnapshot(){return this._state}subscribe(n){return this._observers.add(n),()=>{this._observers.delete(n)}}select(n){return n(this._state)}start(){return this}stop(){this._observers.clear()}dispatch(n){if(v._inspector&&v._inspector({type:"@actor/send",actor:this,event:n,snapshot:this._state}),this._processing){this._queue.push(n);return}this._processing=!0,this._queue.push(n),this._flush()}_flush(){for(;this._queue.length>0;){let n=this._queue[0];this._queue.shift();let r=this._state[n.type];if(typeof r!="function"){console.warn(`[Actor] Transition '${String(n.type)}' not found.`);continue}let a;try{a=r.apply(this._state.context,n.args)}catch(i){console.error(`[Actor] Error in transition '${String(n.type)}':`,i);continue}if(a instanceof Promise){a.then(i=>{this._state=i,this._notify(),this._flush()}).catch(i=>{console.error(`[Actor] Async error in transition '${String(n.type)}':`,i),this._flush()});return}else this._state=a,this._notify()}this._processing=!1}_notify(){let n=this.getSnapshot();this._observers.forEach(t=>t(n))}};v._inspector=null;var A=v;function F(e){return new A(e)}function Ie(e){return F(e)}function Ve(e){let t=p({status:"pending",data:void 0,error:void 0},a=>({resolve(i){return a({status:"resolved",data:i,error:void 0})},reject(i){return a({status:"rejected",error:i,data:void 0})}})),r=F(t);return e().then(a=>r.send.resolve(a)).catch(a=>r.send.reject(a)),r}function Ue(e){let t=p({status:"active",value:void 0,error:void 0},a=>({next(i){return a({status:"active",value:i,error:void 0})},error(i){return a({status:"error",error:i,value:void 0})},complete(){return a({status:"done",value:void 0,error:void 0})}})),r=F(t);return e.subscribe(a=>r.send.next(a),a=>r.send.error(a),()=>r.send.complete()),r}function p(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=p(s,a),c=Object.fromEntries(Object.entries(a).map(([u,y])=>[u,y.bind(s)]));return Object.assign(d,c)});let o=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},o)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function Le(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=Le(s,a),c=Object.fromEntries(Object.entries(a).map(([u,y])=>[u,y.bind(s)]));return Object.assign(d,c)});let o=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},o)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function Fn(){return e=>{let n=Object.fromEntries(Object.entries(e).map(([t,r])=>[t,function(...a){let i=r(this.context,...a);return p(i,n)}]));return t=>p(t,n)}}function E(e,n){let{context:t,...r}=e,a=typeof n=="function"?n(t):n;return p(a,r)}function Rn(e){return{context:e}}function Sn(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function se(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function jn(e,n){return(...t)=>{let r=e(...t),a=n(),i={...r.context,...a.context},{context:o,...s}=r,{context:d,...c}=a,u={...s,...c};return p(i,u)}}function Pn(e){let{context:n,...t}=e;return r=>p(r,t)}function On(e,n,t){let r=e.context[n],a=t[r];if(!a)throw new Error(`No handler found for state: ${String(r)}`);return a(e.context)}function H(e,n,t){return e.context[n]===t}function _n(e,n){let t=e,r=null;async function a(i){r&&(r.abort(),r=null);let o=t[i.type];if(typeof o!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await o.apply(t.context,[...i.args,{signal:s.signal}]);return s.signal.aborted||(t=c,n==null||n(t)),t}finally{r===s&&(r=null)}}return{get state(){return t.context},dispatch:a,stop:()=>{r&&(r.abort(),r=null)}}}var m=class{constructor(n){this.context=n}};function kn(e,n){let{context:t,...r}=e;return p(n(t),r)}
3
+ All cases: [${x}]
4
+ This may occur if predicates don't cover all runtime possibilities.`)}}}function i(s){for(let[d,c,u]of e)if(u(s))return d;return null}return Object.assign(i,{is:n,when:a,case:r,exhaustive:o})}function De(e,t){return[e,void 0,n=>n instanceof t]}function Ge(e,t,n){return[e,void 0,r=>H(r,t,n)]}function Ue(e,t){return[e,void 0,t]}function Ve(){return{case(e,t,n){return[e,void 0,r=>H(r,t,n)]}}}var v=class v{constructor(t){this._observers=new Set;this._queue=[];this._processing=!1;this._state=t,this.ref={send:n=>this.dispatch(n)},this.send=new Proxy({},{get:(n,r)=>(...o)=>{this.dispatch({type:r,args:o})}})}static inspect(t){v._inspector=t}getSnapshot(){return this._state}subscribe(t){return this._observers.add(t),()=>{this._observers.delete(t)}}select(t){return t(this._state)}start(){return this}stop(){this._observers.clear()}dispatch(t){if(v._inspector&&v._inspector({type:"@actor/send",actor:this,event:t,snapshot:this._state}),this._processing){this._queue.push(t);return}this._processing=!0,this._queue.push(t),this._flush()}_flush(){for(;this._queue.length>0;){let t=this._queue[0];this._queue.shift();let r=this._state[t.type];if(typeof r!="function"){console.warn(`[Actor] Transition '${String(t.type)}' not found.`);continue}let o;try{o=r.apply(this._state.context,t.args)}catch(a){console.error(`[Actor] Error in transition '${String(t.type)}':`,a);continue}if(o instanceof Promise){o.then(a=>{this._state=a,this._notify(),this._flush()}).catch(a=>{console.error(`[Actor] Async error in transition '${String(t.type)}':`,a),this._flush()});return}else this._state=o,this._notify()}this._processing=!1}_notify(){let t=this.getSnapshot();this._observers.forEach(n=>n(t))}};v._inspector=null;var A=v;function F(e){return new A(e)}function Le(e){return F(e)}function qe(e){let n=f({status:"pending",data:void 0,error:void 0},o=>({resolve(a){return o({status:"resolved",data:a,error:void 0})},reject(a){return o({status:"rejected",error:a,data:void 0})}})),r=F(n);return e().then(o=>r.send.resolve(o)).catch(o=>r.send.reject(o)),r}function Je(e){let n=f({status:"active",value:void 0,error:void 0},o=>({next(a){return o({status:"active",value:a,error:void 0})},error(a){return o({status:"error",error:a,value:void 0})},complete(){return o({status:"done",value:void 0,error:void 0})}})),r=F(n);return e.subscribe(o=>r.send.next(o),o=>r.send.error(o),()=>r.send.complete()),r}function f(e,t){if(typeof t=="function"){let o;o=t(s=>{let d=f(s,o),c=Object.fromEntries(Object.entries(o).map(([u,y])=>[u,y.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(o).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function Ye(e,t){if(typeof t=="function"){let o;o=t(s=>{let d=Ye(s,o),c=Object.fromEntries(Object.entries(o).map(([u,y])=>[u,y.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(o).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function Pt(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let a=r(this.context,...o);return f(a,t)}]));return n=>f(n,t)}}function E(e,t){let{context:n,...r}=e,o=typeof t=="function"?t(n):t;return f(o,r)}function Ot(e){return{context:e}}function kt(e,t){let{context:n,...r}=e,o={...r,...t};return f(n,o)}function ce(e,t){let{context:n,...r}=e,o={...r,...t};return f(n,o)}function _t(e,t){return(...n)=>{let r=e(...n),o=t(),a={...r.context,...o.context},{context:i,...s}=r,{context:d,...c}=o,u={...s,...c};return f(a,u)}}function Bt(e){let{context:t,...n}=e;return r=>f(r,n)}function Nt(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function H(e,t,n){return e.context[t]===n}function Kt(e,t){let n=e,r=null;async function o(a){r&&(r.abort(),r=null);let i=n[a.type];if(typeof i!="function")throw new Error(`[Machine] Unknown event type '${String(a.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await i.apply(n.context,[...a.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}var m=class{constructor(t){this.context=t}};function Ht(e,t){let{context:n,...r}=e;return f(t(n),r)}