@doeixd/machine 1.2.0 → 1.3.0

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 +1 @@
1
- "use strict";var G=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Qe=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ye(t))!Je.call(e,o)&&o!==n&&G(e,o,{get:()=>t[o],enumerable:!(r=qe(t,o))||r.enumerable});return e};var Ze=e=>Xe(G({},"__esModule",{value:!0}),e);var Ft={};Qe(Ft,{BoundMachine:()=>z,CANCEL:()=>q,META_KEY:()=>ge,MachineBase:()=>m,MiddlewareBuilder:()=>K,MultiMachineBase:()=>H,action:()=>we,bindTransitions:()=>oe,branch:()=>ft,call:()=>ze,chain:()=>yt,combine:()=>ht,combineFactories:()=>$e,compose:()=>dt,composeTyped:()=>B,createAsyncMachine:()=>se,createCustomMiddleware:()=>ct,createEnsemble:()=>Re,createEnsembleFactory:()=>et,createEvent:()=>Oe,createFetchMachine:()=>st,createFlow:()=>Me,createFunctionalMachine:()=>ae,createMachine:()=>p,createMachineBuilder:()=>De,createMachineFactory:()=>We,createMiddleware:()=>g,createMiddlewareFactory:()=>At,createMiddlewareRegistry:()=>Mt,createMultiMachine:()=>rt,createMutableMachine:()=>ot,createParallelMachine:()=>U,createPipeline:()=>xt,createRunner:()=>Se,createTransition:()=>Ne,createTransitionExtender:()=>ie,createTransitionFactory:()=>_e,delegateToChild:()=>it,describe:()=>me,extendTransitions:()=>_,guard:()=>R,guardAsync:()=>j,guarded:()=>Te,hasState:()=>Le,inDevelopment:()=>ut,invoke:()=>be,isConditionalMiddleware:()=>pt,isMiddlewareContext:()=>Ct,isMiddlewareError:()=>mt,isMiddlewareFn:()=>re,isMiddlewareHooks:()=>Tt,isMiddlewareOptions:()=>bt,isMiddlewareResult:()=>gt,isNamedMiddleware:()=>wt,isPipelineConfig:()=>Et,isState:()=>Pe,logState:()=>Ke,matchMachine:()=>Ie,mergeContext:()=>Be,metadata:()=>Fe,middlewareBuilder:()=>je,next:()=>Ue,overrideTransitions:()=>He,pipeTransitions:()=>ke,run:()=>W,runAsync:()=>he,runMachine:()=>Ve,runSequence:()=>le,runWithDebug:()=>xe,runWithEnsemble:()=>nt,runWithRunner:()=>tt,setContext:()=>T,state:()=>Ge,step:()=>ye,stepAsync:()=>fe,toggle:()=>at,transitionTo:()=>Ce,when:()=>N,whenContext:()=>lt,whenGuard:()=>Ee,whenGuardAsync:()=>Ae,withAnalytics:()=>J,withDebugging:()=>ve,withErrorReporting:()=>Z,withHistory:()=>v,withLogging:()=>Y,withPerformanceMonitoring:()=>ee,withPermissions:()=>X,withRetry:()=>te,withSnapshot:()=>P,withTimeTravel:()=>O,withValidation:()=>Q,yieldMachine:()=>ue});module.exports=Ze(Ft);var de=Symbol.for("__machine_transitions__");function A(e,t){return Object.defineProperty(e,de,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[de]}function S(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function W(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ye(e){return function*(){return yield e}()}function ue(e){return e}function le(e,t){return t.reduce((n,r)=>W(r,n),e)}function Me(e){return e}function xe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*fe(e){return yield e}var ge=Symbol("MachineMeta"),pe=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[pe]||{},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,pe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ce(e,t){return w(t,{target:e.name||e.toString()}),t}function me(e,t){return w(t,{description:e}),t}function Te(e,t){return w(t,{guards:[e]}),t}function be(e,t){return w(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 w(t,{actions:[e]}),t}function R(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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,u);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:a,enumerable:!1}),w(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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,u);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:a,enumerable:!1}),w(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"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 Ae(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Fe(e,t){return t}function Se(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,u){let c=n[u];if(typeof c=="function")return(...d)=>{let M=c.apply(n,d),l=Object.assign({context:M.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Re(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),u=s[a];if(typeof u!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>u.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function et(e,t){return function(r){return Re(e,r,t)}}function tt(e,t){let n=Se(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function nt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var H=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function rt(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function ot(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),u=s[i];if(typeof u=="function")return(...c)=>{let d=u.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(M=>delete o[M]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function it(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return T(this,{...this.context,child:r})}return this}}function at(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.`),T(this,{...this.context,[e]:!this.context[e]})}}var $=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=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 I(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new D(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new L(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,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},I=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},L=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(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 E(this.config,n!=null?n:this.config.initialParams,1)}};function st(e){return new $(e)}function U(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...u)=>{let c=s.apply(e,u);return U(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return U(e,c)}}return{context:n,...i}}var q=Symbol("CANCEL");function g(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let u=e[s];typeof u=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,M=a.context,l=()=>{let y;try{y=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:M,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:M,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(y&&typeof y.then=="function")return y.then(f=>{if(x(f),t.after)try{let C=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>f)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${d}:`,C),i==null||i(C,"after",{transitionName:d,prevContext:M,nextContext:f.context,args:c})}return f});if(x(y),t.after)try{let h=t.after({transitionName:d,prevContext:M,nextContext:y.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>y).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c}),y})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c})}return y};if(t.before)try{let y=t.before({transitionName:d,context:M,args:[...c]});if(y&&typeof y=="object"&&y&&"then"in y)return y.then(x=>x===q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:M,args:c}),l()});if(y===q)return a}catch(y){if(!r)throw y;o&&console.error(`Middleware before hook error for ${d}:`,y),i==null||i(y,"before",{transitionName:d,context:M,args:c})}return l()})}return a}function Y(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return g(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function J(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return g(e,{after:({transitionName:a,prevContext:s,nextContext:u,args:c})=>{let d=`${r}.${a}`,M={transition:a};o&&(M.from=s),M.to=u,i&&(M.args=c),t(d,M)}})}function Q(e,t){return g(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function X(e,t){return g(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function Z(e,t,n={}){let{includeArgs:r=!1}=n;return g(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function ee(e,t){let n=new Map;return g(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function te(e,t={}){var u,c;let{maxAttempts:n=(u=t.maxRetries)!=null?u:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let M=e[d];typeof M=="function"&&d!=="context"&&(s[d]=async function(...l){let y,x=0;for(;x<n;)try{return await M.apply(this,l)}catch(h){if(y=h,x++,x<n&&r(y,x)){a==null||a(y,x);let C=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,C))}else throw y}throw y})}return s}function ct(e,t){return n=>g(n,e,t)}function v(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=g(e,{before:({transitionName:u,args:c})=>{let d={id:`entry-${a++}`,transitionName:u,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(M){console.error("Failed to serialize history args:",M)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function P(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=g(e,{after:({transitionName:d,prevContext:M,nextContext:l})=>{if(i&&JSON.stringify(M)===JSON.stringify(l))return;let y={id:`snapshot-${s++}`,transitionName:d,before:{...M},after:{...l},timestamp:Date.now()};if(r)try{y.serializedBefore=r.serialize(M),y.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{y.diff=o(M,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(y),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let M=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:d},M)}})}function O(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=g(e,{before:({transitionName:l,args:y})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...y],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(y)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:y,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:l,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(y),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,u=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,u=0},restoreSnapshot:l=>{let y=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:l},y)},replayFrom:l=>{var C;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let y=(C=a[l])==null?void 0:C.before;if(!y)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:y},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let ce=f[b.transitionName];ce&&(f=ce.apply(f,b.args))}return f}})}function dt(e,...t){return t.reduce((n,r)=>r(n),e)}function B(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 yt(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 ut(e){return N(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function lt(e,t,n){return N(n,r=>r.context[e]===t)}function Mt(){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 i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return B(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return B(t,...n.map(r=>r.middleware))}}}function xt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],u=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(M){if(u=!1,!t)throw M;s.push({error:M,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,M),r==null||r(M,c,d.name)}}return{machine:a,errors:s,success:u}}}function ht(...e){return t=>B(t,...e)}function ft(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 pt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&re(e.middleware)&&typeof e.when=="function"}function gt(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||k(e.prevContext,t)&&k(e.nextContext,t))}function Ct(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||k(e.context,t))}function mt(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||k(e.context,t))}function Tt(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 bt(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,t){return e!==null&&typeof e=="object"}function wt(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 Et(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 K=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>Y(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>J(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=>v(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=>ve(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 je(e){return new K(e)}function At(e={}){return{create:t=>{let n=je(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 ve(e){return O(P(v(e)))}function Pe(e,t){return e instanceof t}function Oe(e,...t){return{type:e,args:t}}function Be(e,t){return T(e,n=>({...n,...t}))}async function ke(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 Ne(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function ze(e,t,...n){return e.apply(t,n)}function oe(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?oe(i):i}:r}})}var z=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"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function _e(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function ie(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=_(e,{[t]:r});return ie(o)}}}function ae(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let u=a(this.context,...s);return p(u,r)}]));return Object.assign(r,o),p(e,r)}}function Ge(e,t){return t!==void 0?p(e,t):ae(e)}function p(e,t){if(typeof t=="function"){let i;return i=t(s=>p(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function se(e,t){if(typeof t=="function"){let i;return i=t(s=>se(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function We(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function T(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:S(e),o=typeof t=="function"?t(n):t;return p(o,r)}function He(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function _(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function $e(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:u,...c}=o,d={...s,...c};return p(i,d)}}function De(e){let{context:t,...n}=e;return r=>p(r,n)}function Ie(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 Le(e,t,n){return e.context[t]===n}function Ve(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.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)}}}function Ue(e,t){return T(e,n=>t(n))}
1
+ "use strict";var G=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Qe=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ye(t))!Je.call(e,o)&&o!==n&&G(e,o,{get:()=>t[o],enumerable:!(r=qe(t,o))||r.enumerable});return e};var Ze=e=>Xe(G({},"__esModule",{value:!0}),e);var Ft={};Qe(Ft,{BoundMachine:()=>z,CANCEL:()=>q,META_KEY:()=>ge,MachineBase:()=>m,MiddlewareBuilder:()=>K,MultiMachineBase:()=>H,action:()=>we,bindTransitions:()=>oe,branch:()=>ft,call:()=>ze,chain:()=>yt,combine:()=>ht,combineFactories:()=>$e,compose:()=>dt,composeTyped:()=>B,createAsyncMachine:()=>se,createCustomMiddleware:()=>ct,createEnsemble:()=>Re,createEnsembleFactory:()=>et,createEvent:()=>Oe,createFetchMachine:()=>st,createFlow:()=>Me,createFunctionalMachine:()=>ae,createMachine:()=>p,createMachineBuilder:()=>De,createMachineFactory:()=>We,createMiddleware:()=>g,createMiddlewareFactory:()=>At,createMiddlewareRegistry:()=>Mt,createMultiMachine:()=>rt,createMutableMachine:()=>ot,createParallelMachine:()=>U,createPipeline:()=>xt,createRunner:()=>Se,createTransition:()=>Ne,createTransitionExtender:()=>ie,createTransitionFactory:()=>_e,delegateToChild:()=>it,describe:()=>me,extendTransitions:()=>_,guard:()=>R,guardAsync:()=>j,guarded:()=>Te,hasState:()=>Le,inDevelopment:()=>ut,invoke:()=>be,isConditionalMiddleware:()=>pt,isMiddlewareContext:()=>Ct,isMiddlewareError:()=>mt,isMiddlewareFn:()=>re,isMiddlewareHooks:()=>Tt,isMiddlewareOptions:()=>bt,isMiddlewareResult:()=>gt,isNamedMiddleware:()=>wt,isPipelineConfig:()=>Et,isState:()=>Pe,logState:()=>Ke,matchMachine:()=>Ie,mergeContext:()=>Be,metadata:()=>Fe,middlewareBuilder:()=>je,next:()=>Ue,overrideTransitions:()=>He,pipeTransitions:()=>ke,run:()=>W,runAsync:()=>he,runMachine:()=>Ve,runSequence:()=>le,runWithDebug:()=>xe,runWithEnsemble:()=>nt,runWithRunner:()=>tt,setContext:()=>T,state:()=>Ge,step:()=>ye,stepAsync:()=>fe,toggle:()=>at,transitionTo:()=>Ce,when:()=>N,whenContext:()=>lt,whenGuard:()=>Ee,whenGuardAsync:()=>Ae,withAnalytics:()=>J,withDebugging:()=>ve,withErrorReporting:()=>Z,withHistory:()=>v,withLogging:()=>Y,withPerformanceMonitoring:()=>ee,withPermissions:()=>X,withRetry:()=>te,withSnapshot:()=>P,withTimeTravel:()=>O,withValidation:()=>Q,yieldMachine:()=>ue});module.exports=Ze(Ft);var de=Symbol.for("__machine_transitions__");function A(e,t){return Object.defineProperty(e,de,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[de]}function S(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function W(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ye(e){return function*(){return yield e}()}function ue(e){return e}function le(e,t){return t.reduce((n,r)=>W(r,n),e)}function Me(e){return e}function xe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*fe(e){return yield e}var ge=Symbol("MachineMeta"),pe=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[pe]||{},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,pe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ce(e,t){return w(t,{target:e.name||e.toString()}),t}function me(e,t){return w(t,{description:e}),t}function Te(e,t){return w(t,{guards:[e]}),t}function be(e,t){return w(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 w(t,{actions:[e]}),t}function R(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...y){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...y)){let l=c?this:{context:this};return t.apply(l,y)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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,y);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:a,enumerable:!1}),w(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...y){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...y))){let l=c?this:{context:this};return t.apply(l,y)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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,y);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:a,enumerable:!1}),w(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"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 Ae(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Fe(e,t){return t}function Se(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,y){let c=n[y];if(typeof c=="function")return(...d)=>{let M=c.apply(n,d),l=Object.assign({context:M.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Re(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),y=s[a];if(typeof y!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>y.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function et(e,t){return function(r){return Re(e,r,t)}}function tt(e,t){let n=Se(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function nt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var H=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function rt(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function ot(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),y=s[i];if(typeof y=="function")return(...c)=>{let d=y.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(M=>delete o[M]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function it(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return T(this,{...this.context,child:r})}return this}}function at(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.`),T(this,{...this.context,[e]:!this.context[e]})}}var $=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=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 I(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new D(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new L(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,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},I=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},L=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(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 E(this.config,n!=null?n:this.config.initialParams,1)}};function st(e){return new $(e)}function U(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...y)=>{let c=s.apply(e,y);return U(c,t)}}for(let a in o){let s=o[a];i[a]=(...y)=>{let c=s.apply(t,y);return U(e,c)}}return{context:n,...i}}var q=Symbol("CANCEL");function g(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let y=e[s];typeof y=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,M=a.context,l=()=>{let u;try{u=y.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:M,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:M,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(u&&typeof u.then=="function")return u.then(f=>{if(x(f),t.after)try{let C=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>f)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${d}:`,C),i==null||i(C,"after",{transitionName:d,prevContext:M,nextContext:f.context,args:c})}return f});if(x(u),t.after)try{let h=t.after({transitionName:d,prevContext:M,nextContext:u.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>u).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:M,nextContext:u.context,args:c}),u})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:M,nextContext:u.context,args:c})}return u};if(t.before)try{let u=t.before({transitionName:d,context:M,args:[...c]});if(u&&typeof u=="object"&&u&&"then"in u)return u.then(x=>x===q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:M,args:c}),l()});if(u===q)return a}catch(u){if(!r)throw u;o&&console.error(`Middleware before hook error for ${d}:`,u),i==null||i(u,"before",{transitionName:d,context:M,args:c})}return l()})}return a}function Y(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return g(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function J(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return g(e,{after:({transitionName:a,prevContext:s,nextContext:y,args:c})=>{let d=`${r}.${a}`,M={transition:a};o&&(M.from=s),M.to=y,i&&(M.args=c),t(d,M)}})}function Q(e,t){return g(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function X(e,t){return g(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function Z(e,t,n={}){let{includeArgs:r=!1}=n;return g(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function ee(e,t){let n=new Map;return g(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function te(e,t={}){var y,c;let{maxAttempts:n=(y=t.maxRetries)!=null?y:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let M=e[d];typeof M=="function"&&d!=="context"&&(s[d]=async function(...l){let u,x=0;for(;x<n;)try{return await M.apply(this,l)}catch(h){if(u=h,x++,x<n&&r(u,x)){a==null||a(u,x);let C=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,C))}else throw u}throw u})}return s}function ct(e,t){return n=>g(n,e,t)}function v(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=g(e,{before:({transitionName:y,args:c})=>{let d={id:`entry-${a++}`,transitionName:y,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(M){console.error("Failed to serialize history args:",M)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function P(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,y=g(e,{after:({transitionName:d,prevContext:M,nextContext:l})=>{if(i&&JSON.stringify(M)===JSON.stringify(l))return;let u={id:`snapshot-${s++}`,transitionName:d,before:{...M},after:{...l},timestamp:Date.now()};if(r)try{u.serializedBefore=r.serialize(M),u.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{u.diff=o(M,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(u),n&&a.length>n&&a.shift()}});return Object.assign(y,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let M=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:d},M)}})}function O(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,y=0,c=g(e,{before:({transitionName:l,args:u})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...u],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(u)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:u,nextContext:x})=>{let h={id:`snapshot-${y++}`,transitionName:l,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(u),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,y=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,y=0},restoreSnapshot:l=>{let u=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:l},u)},replayFrom:l=>{var C;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let u=(C=a[l])==null?void 0:C.before;if(!u)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:u},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let ce=f[b.transitionName];ce&&(f=ce.apply(f,b.args))}return f}})}function dt(e,...t){return t.reduce((n,r)=>r(n),e)}function B(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 yt(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 ut(e){return N(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function lt(e,t,n){return N(n,r=>r.context[e]===t)}function Mt(){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 i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return B(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return B(t,...n.map(r=>r.middleware))}}}function xt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],y=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(M){if(y=!1,!t)throw M;s.push({error:M,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,M),r==null||r(M,c,d.name)}}return{machine:a,errors:s,success:y}}}function ht(...e){return t=>B(t,...e)}function ft(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 pt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&re(e.middleware)&&typeof e.when=="function"}function gt(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||k(e.prevContext,t)&&k(e.nextContext,t))}function Ct(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||k(e.context,t))}function mt(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||k(e.context,t))}function Tt(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 bt(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,t){return e!==null&&typeof e=="object"}function wt(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 Et(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 K=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>Y(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>J(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=>v(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=>ve(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 je(e){return new K(e)}function At(e={}){return{create:t=>{let n=je(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 ve(e){return O(P(v(e)))}function Pe(e,t){return e instanceof t}function Oe(e,...t){return{type:e,args:t}}function Be(e,t){return T(e,n=>({...n,...t}))}async function ke(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 Ne(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function ze(e,t,...n){return e.apply(t,n)}function oe(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?oe(i):i}:r}})}var z=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"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function _e(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function ie(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=_(e,{[t]:r});return ie(o)}}}function ae(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let y=a(this.context,...s);return p(y,r)}]));return Object.assign(r,o),p(e,r)}}function Ge(e,t){return t!==void 0?p(e,t):ae(e)}function p(e,t){if(typeof t=="function"){let i,a;return a=t(y=>y===e?i:p(y,a)),i=A(Object.assign({context:e},a),a),i}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function se(e,t){if(typeof t=="function"){let i;return i=t(s=>se(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function We(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function T(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:S(e),o=typeof t=="function"?t(n):t;return p(o,r)}function He(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function _(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function $e(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:y,...c}=o,d={...s,...c};return p(i,d)}}function De(e){let{context:t,...n}=e;return r=>p(r,n)}function Ie(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 Le(e,t,n){return e.context[t]===n}function Ve(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.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)}}}function Ue(e,t){return T(e,n=>t(n))}
@@ -1,4 +1,4 @@
1
- "use strict";var V=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},pt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mt(t))!ft.call(e,o)&&o!==n&&V(e,o,{get:()=>t[o],enumerable:!(r=xt(t,o))||r.enumerable});return e};var ht=e=>pt(V({},"__esModule",{value:!0}),e);var yn={};q(yn,{Actor:()=>A,BoundMachine:()=>$,CANCEL:()=>re,META_KEY:()=>Se,MachineBase:()=>m,MachineExclude:()=>Ge,MachineUnion:()=>We,MiddlewareBuilder:()=>z,MultiMachineBase:()=>J,action:()=>_e,bindTransitions:()=>Me,branch:()=>Kt,call:()=>Qe,callWithContext:()=>ct,chain:()=>At,classCase:()=>tt,combine:()=>kt,combineFactories:()=>on,compose:()=>jt,composeTyped:()=>H,createActor:()=>F,createAsyncMachine:()=>lt,createContext:()=>nn,createContextBoundMachine:()=>Ce,createCustomMiddleware:()=>Rt,createEnsemble:()=>ze,createEnsembleFactory:()=>Ct,createEvent:()=>Le,createFetchMachine:()=>vt,createFlow:()=>ve,createFunctionalMachine:()=>pe,createMachine:()=>h,createMachineBuilder:()=>an,createMachineFactory:()=>tn,createMatcher:()=>et,createMiddleware:()=>C,createMiddlewareFactory:()=>Wt,createMiddlewareRegistry:()=>Ot,createMultiMachine:()=>Tt,createMutableMachine:()=>bt,createParallelMachine:()=>ne,createPipeline:()=>Pt,createRunner:()=>Ie,createTransition:()=>Je,createTransitionExtender:()=>fe,createTransitionFactory:()=>Xe,customCase:()=>rt,delegate:()=>L,delegateToChild:()=>wt,describe:()=>Pe,discriminantCase:()=>nt,extendTransitions:()=>he,forContext:()=>ot,freeze:()=>ge,fromObservable:()=>it,fromPromise:()=>st,guard:()=>k,guardAsync:()=>K,guarded:()=>ke,hasState:()=>W,inDevelopment:()=>Ft,invoke:()=>Ke,isConditionalMiddleware:()=>_t,isContextBound:()=>dt,isMiddlewareContext:()=>Nt,isMiddlewareError:()=>Ht,isMiddlewareFn:()=>le,isMiddlewareHooks:()=>It,isMiddlewareOptions:()=>zt,isMiddlewareResult:()=>Bt,isNamedMiddleware:()=>Dt,isPipelineConfig:()=>$t,isState:()=>Ue,logState:()=>Ye,machineExclude:()=>Ut,machineUnion:()=>Gt,matchMachine:()=>sn,mergeContext:()=>Ve,metadata:()=>He,middlewareBuilder:()=>De,minimal:()=>U,next:()=>dn,overrideTransitions:()=>rn,pipeTransitions:()=>qe,run:()=>Y,runAsync:()=>je,runMachine:()=>cn,runSequence:()=>Ee,runWithDebug:()=>Re,runWithEnsemble:()=>mt,runWithRunner:()=>gt,setContext:()=>v,spawn:()=>at,state:()=>Ze,step:()=>be,stepAsync:()=>Ae,tag:()=>S,toggle:()=>Et,transitionTo:()=>Oe,when:()=>D,whenContext:()=>St,whenGuard:()=>Be,whenGuardAsync:()=>Ne,withAnalytics:()=>ae,withDebugging:()=>$e,withErrorReporting:()=>ce,withHistory:()=>_,withLogging:()=>oe,withPerformanceMonitoring:()=>de,withPermissions:()=>ie,withRetry:()=>ye,withSnapshot:()=>B,withTimeTravel:()=>N,withValidation:()=>se,yieldMachine:()=>we});module.exports=ht(yn);var Te=Symbol.for("__machine_transitions__");function b(e,t){return Object.defineProperty(e,Te,{value:t,enumerable:!1,configurable:!1}),e}function O(e){if(!(!e||typeof e!="object"))return e[Te]}function P(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function Y(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=n.next(r);if(a)return o;r=o}}function be(e){return function*(){return yield e}()}function we(e){return e}function Ee(e,t){return t.reduce((n,r)=>Y(r,n),e)}function ve(e){return e}function Re(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:s,done:i}=r.next(o);if(i)return console.log("Final:",s),s;o=s,a++,n(a,o)}}async function je(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*Ae(e){return yield e}var Se=Symbol("MachineMeta"),Fe=Symbol("__machine_runtime_meta__");function w(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 Oe(e,t){return w(t,{target:e.name||e.toString()}),t}function Pe(e,t){return w(t,{description:e}),t}function ke(e,t){return w(t,{guards:[e]}),t}function Ke(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function _e(e,t){return w(t,{actions:[e]}),t}function k(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(e(y,...c)){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)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(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),i}function K(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=async function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(await Promise.resolve(e(y,...c))){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)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(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),i}function Be(e){return{do(t){let n=k(e,t);return n.else=function(r){return k(e,t,{onFail:r})},n}}}function Ne(e){return{do(t){let n=K(e,t);return n.else=function(r){return K(e,t,{onFail:r})},n}}}function He(e,t){return t}function Ie(e,t){let n=e,r=i=>{n=i,t==null||t(i)},{context:o,...a}=e,s=new Proxy({},{get(i,c){let d=n[c];if(typeof d=="function")return(...y)=>{let u=d.apply(n,y),x=Object.assign({context:u.context},a);return r(x),x}}});return{get state(){return n},get context(){return n.context},actions:s,setState:r}}function ze(e,t,n){let r=()=>{let a=e.getContext(),s=n(a),i=t[s];if(!i)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(s)}".`);return i(a)},o=new Proxy({},{get(a,s){let i=r(),c=i[s];if(typeof c!="function")throw new Error(`[Ensemble] Transition "${s}" is not valid in the current state.`);return(...d)=>c.apply(i,d)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Ct(e,t){return function(r){return ze(e,r,t)}}function gt(e,t){let n=Ie(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function mt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var J=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function Tt(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 s=n[o];if(typeof s=="function")return(...i)=>s.apply(n,i)},set(r,o,a){let s=t.getContext();if(o in s){let i={...s,[o]:a};return t.setContext(i),!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),s=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(i=>i!=="constructor"&&typeof n[i]=="function");return Array.from(new Set([...a,...s]))},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 bt(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,s){if(a in o)return o[a];let i=r(),c=i[a];if(typeof c=="function")return(...d)=>{let y=c.apply(i,d);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(a)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(u=>delete o[u]),Object.assign(o,y)}},set(o,a,s,i){return o[a]=s,!0},has(o,a){let s=r();return a in o||typeof s[a]=="function"}})}function wt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return v(this,{...this.context,child:r})}return this}}function Et(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.`),v(this,{...this.context,[e]:!this.context[e]})}}var Q=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=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 Z(this.config,{status:"success",data:n})};this.fail=n=>{var o,a,s;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new X(this.config,this.params,n,this.context.attempts):((s=(a=this.config).onError)==null||s.call(a,n),new ee(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new te(this.config));this.execute()}async execute(){}},X=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 E(this.config,n!=null?n:this.params,this.context.attempts+1)}},Z=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},ee=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},te=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function vt(e){return new Q(e)}function ne(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let a={};for(let s in r){let i=r[s];a[s]=(...c)=>{let d=i.apply(e,c);return ne(d,t)}}for(let s in o){let i=o[s];a[s]=(...c)=>{let d=i.apply(t,c);return ne(e,d)}}return{context:n,...a}}var re=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:a}=n,s={...e};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&i!=="context"&&typeof e[i]!="function"&&(s[i]=e[i]);for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let c=e[i];typeof c=="function"&&i!=="context"&&(s[i]=function(...d){let y=i,u=s.context,x=()=>{let l;try{l=c.apply(this,d)}catch(f){if(t.error)try{t.error({transitionName:y,context:u,args:[...d],error:f})}catch(p){if(!r)throw p;o&&console.error(`Middleware error hook error for ${y}:`,p),a==null||a(p,"error",{transitionName:y,context:u,args:d,error:f})}throw f}let M=f=>{if(f&&typeof f=="object"&&f.context){for(let p in s)Object.prototype.hasOwnProperty.call(s,p)&&p!=="context"&&!(p in f)&&(f[p]=s[p]);for(let p in f){if(!Object.prototype.hasOwnProperty.call(f,p))continue;typeof f[p]=="function"&&p!=="context"&&s[p]&&(f[p]=s[p])}}return f};if(l&&typeof l.then=="function")return l.then(p=>{if(M(p),t.after)try{let g=t.after({transitionName:y,prevContext:u,nextContext:p.context,args:[...d]});if(g&&typeof g.then=="function")return g.then(()=>p)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${y}:`,g),a==null||a(g,"after",{transitionName:y,prevContext:u,nextContext:p.context,args:d})}return p});if(M(l),t.after)try{let f=t.after({transitionName:y,prevContext:u,nextContext:l.context,args:[...d]});if(f&&typeof f=="object"&&f&&"then"in f)return f.then(()=>l).catch(p=>{if(!r)throw p;return o&&console.error(`Middleware after hook error for ${y}:`,p),a==null||a(p,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d}),l})}catch(f){if(!r)throw f;o&&console.error(`Middleware after hook error for ${y}:`,f),a==null||a(f,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d})}return l};if(t.before)try{let l=t.before({transitionName:y,context:u,args:[...d]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(M=>M===re?s:x()).catch(M=>{if(!r)throw M;return o&&console.error(`Middleware before hook error for ${y}:`,M),a==null||a(M,"before",{transitionName:y,context:u,args:d}),x()});if(l===re)return s}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${y}:`,l),a==null||a(l,"before",{transitionName:y,context:u,args:d})}return x()})}return s}function oe(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:a,args:s})=>{let i=r?`→ ${a} [${s.join(", ")}]`:`→ ${a}`;n(i)},after:({transitionName:a,nextContext:s})=>{let i=o?` ${JSON.stringify(s)}`:"";n(`✓ ${a}${i}`)},error:({transitionName:a,error:s})=>{console.error(`[Machine] ${a} failed:`,s)}})}function ae(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=n;return C(e,{after:({transitionName:s,prevContext:i,nextContext:c,args:d})=>{let y=`${r}.${s}`,u={transition:s};o&&(u.from=i),u.to=c,a&&(u.args=d),t(y,u)}})}function se(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ie(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ce(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 de(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 s={transitionName:r.transitionName,duration:a,context:r.nextContext||r.prevContext};t(s)}}})}function ye(e,t={}){var c,d;let{maxAttempts:n=(c=t.maxRetries)!=null?c:3,shouldRetry:r=()=>!0,backoffMs:o=(d=t.delay)!=null?d:100,backoffMultiplier:a=2,onRetry:s}=t,i={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let u=e[y];typeof u=="function"&&y!=="context"&&(i[y]=async function(...x){let l,M=0;for(;M<n;)try{return await u.apply(this,x)}catch(f){if(l=f,M++,M<n&&r(l,M)){s==null||s(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 i}function Rt(e,t){return n=>C(n,e,t)}function _(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,a=[],s=0,i=C(e,{before:({transitionName:c,args:d})=>{let y={id:`entry-${s++}`,transitionName:c,args:[...d],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(d)}catch(u){console.error("Failed to serialize history args:",u)}a.push(y),n&&a.length>n&&a.shift(),o==null||o(y)}});return Object.assign(i,{history:a,clearHistory:()=>{a.length=0,s=0}})}function B(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=t,s=[],i=0,c=C(e,{after:({transitionName:y,prevContext:u,nextContext:x})=>{if(a&&JSON.stringify(u)===JSON.stringify(x))return;let l={id:`snapshot-${i++}`,transitionName:y,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(u),l.serializedAfter=r.serialize(x)}catch(M){console.error("Failed to serialize snapshot:",M)}if(o)try{l.diff=o(u,x)}catch(M){console.error("Failed to capture snapshot:",M)}s.push(l),n&&s.length>n&&s.shift()}});return Object.assign(c,{snapshots:s,clearSnapshots:()=>{s.length=0,i=0},restoreSnapshot:y=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="snapshots"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&typeof e[x]=="function"));return Object.assign({context:y},u)}})}function N(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,a=[],s=[],i=0,c=0,d=C(e,{before:({transitionName:x,args:l})=>{let M={id:`entry-${i++}`,transitionName:x,args:[...l],timestamp:Date.now()};if(r)try{M.serializedArgs=r.serialize(l)}catch(f){console.error("Failed to serialize history args:",f)}a.push(M),n&&a.length>n&&a.shift(),o==null||o("history",M)},after:({transitionName:x,prevContext:l,nextContext:M})=>{let f={id:`snapshot-${c++}`,transitionName:x,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{f.serializedBefore=r.serialize(l),f.serializedAfter=r.serialize(M)}catch(p){console.error("Failed to serialize snapshot:",p)}s.push(f),n&&s.length>n&&s.shift(),o==null||o("snapshot",f)}});return Object.assign(d,{history:a,snapshots:s,clearHistory:()=>{a.length=0,i=0},clearSnapshots:()=>{s.length=0,c=0},clearTimeTravel:()=>{a.length=0,s.length=0,i=0,c=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=s[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 me=p[T.transitionName];me&&(p=me.apply(p,T.args))}return p}})}function jt(e,...t){return t.reduce((n,r)=>r(n),e)}function H(e,...t){return t.reduce((n,r)=>r(n),e)}var ue=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function At(e){return new ue(e)}function D(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ft(e){return D(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function St(e,t,n){return D(n,r=>r.context[e]===t)}function Ot(){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 s,i;return((s=o.priority)!=null?s:0)-((i=a.priority)!=null?i:0)});return H(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return H(t,...n.map(r=>r.middleware))}}}function Pt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...a)=>{let s=o,i=[],c=!0;for(let d=0;d<a.length;d++){let y=a[d];try{if("middleware"in y&&"when"in y){if(!y.when(s))continue;s=y.middleware(s)}else s=y(s)}catch(u){if(c=!1,!t)throw u;i.push({error:u,middlewareIndex:d,middlewareName:y.name}),n&&console.error(`Pipeline middleware error at index ${d}:`,u),r==null||r(u,d,y.name)}}return{machine:s,errors:i,success:c}}}function kt(...e){return t=>H(t,...e)}function Kt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function le(e){return typeof e=="function"&&e.length===1}function _t(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&le(e.middleware)&&typeof e.when=="function"}function Bt(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||I(e.prevContext,t)&&I(e.nextContext,t))}function Nt(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||I(e.context,t))}function Ht(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||I(e.context,t))}function It(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 zt(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 I(e,t){return e!==null&&typeof e=="object"}function Dt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&le(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 $t(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 z=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>oe(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>ae(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>se(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ie(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ce(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>de(r,t)),this}withRetry(t){return this.middlewares.push(n=>ye(n,t)),this}withHistory(t){return this.middlewares.push(n=>_(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>B(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>N(n,t)),this}withDebugging(){return this.middlewares.push(t=>$e(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(D(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 De(e){return new z(e)}function Wt(e={}){return{create:t=>{let n=De(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 $e(e){return N(B(_(e)))}function xe(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 We(...e){let t=e[0];class n extends t{constructor(a){super(a)}}let r=o=>function(...a){let s=o.apply(this,a);if(s&&typeof s=="object"&&"context"in s){let i={...this.context,...s.context};return new n(i)}return s};for(let o of e){let a=xe(o.prototype);for(let[s,i]of Object.entries(a))if(s!=="constructor")if(typeof i.value=="function"){let c=i.value,d=r(c);Object.defineProperty(n.prototype,s,{...i,value:d})}else Object.defineProperty(n.prototype,s,i)}return n}function Ge(e,...t){class n extends m{constructor(a){super(a)}}let r=xe(e.prototype);for(let[o,a]of Object.entries(r))if(o!=="constructor")if(typeof a.value=="function"){let s=a.value,i=function(...c){let d=s.apply(this,c);return d&&typeof d=="object"&&"context"in d?new n({...this.context,...d.context}):d};Object.defineProperty(n.prototype,o,{...a,value:i})}else Object.defineProperty(n.prototype,o,a);for(let o of t){let a=xe(o.prototype);for(let s of Object.keys(a))Object.prototype.hasOwnProperty.call(n.prototype,s)&&delete n.prototype[s]}return n}function Gt(...e){let t=e.map(a=>a.constructor),n=e.map(a=>a.context),r=Object.assign({},...n),o=We(...t);return new o(r)}function Ut(e,...t){let n=e.constructor,r=t.map(a=>a.constructor),o=Ge(n,...r);return new o(e.context)}function Ue(e,t){return e instanceof t}function Le(e,...t){return{type:e,args:t}}function Ve(e,t){return v(e,n=>({...n,...t}))}async function qe(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Ye(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Je(e,t){return function(...n){let r=t(this.context,...n);return h(r,e())}}function Qe(e,t,...n){return e.apply(t,n)}function Me(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let a=r.apply(t,o);return a&&typeof a=="object"&&"context"in a?Me(a):a}:r}})}var $=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 s=o.apply(this.wrappedMachine,a);return s&&typeof s=="object"&&"context"in s?new e(s):s}:o}})}};function Xe(){return function(t){return function(...n){let r=t(this.context,...n);return h(r,this)}}}function fe(e){return{machine:e,addTransition:function(t,n){let r=function(...a){let s=n(this.context,...a);return h(s,this)},o=he(e,{[t]:r});return fe(o)}}}function pe(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([a,s])=>[a,function(...i){let c=s(this.context,...i);return h(c,r)}]));return Object.assign(r,o),h(e,r)}}function Ze(e,t){return t!==void 0?h(e,t):pe(e)}function et(...e){let t=new Map;for(let[i,c,d]of e){if(t.has(i))throw new Error(`Duplicate matcher case name: "${i}"`);t.set(i,{predicate:d})}let n=new Proxy({},{get(i,c){return function(y){let u=t.get(c);if(!u){let x=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${x}`)}return u.predicate(y)}}}),r=new Proxy({},{get(i,c){return function(y){if(!t.has(c)){let u=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${u}`)}return{__brand:"CaseHandler",__name:c,__machine:void 0,__return:void 0,handler:y}}}}),o={__exhaustive:!0};function a(i){return{is(...c){if(c.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let d=c[c.length-1];if(!d||typeof d!="object"||!("__exhaustive"in d))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=c.slice(0,-1);for(let l of y){let M=l.__name,f=t.get(M);if(!f)throw new Error(`Internal error: Unknown matcher case in handler: ${M}`);if(f.predicate(i))return l.handler(i)}let u=y.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.
1
+ "use strict";var V=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},pt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mt(t))!ft.call(e,o)&&o!==n&&V(e,o,{get:()=>t[o],enumerable:!(r=xt(t,o))||r.enumerable});return e};var ht=e=>pt(V({},"__esModule",{value:!0}),e);var yn={};q(yn,{Actor:()=>A,BoundMachine:()=>$,CANCEL:()=>re,META_KEY:()=>Se,MachineBase:()=>m,MachineExclude:()=>Ue,MachineUnion:()=>We,MiddlewareBuilder:()=>z,MultiMachineBase:()=>J,action:()=>_e,bindTransitions:()=>Me,branch:()=>Kt,call:()=>Qe,callWithContext:()=>ct,chain:()=>At,classCase:()=>tt,combine:()=>kt,combineFactories:()=>on,compose:()=>jt,composeTyped:()=>H,createActor:()=>F,createAsyncMachine:()=>lt,createContext:()=>nn,createContextBoundMachine:()=>Ce,createCustomMiddleware:()=>vt,createEnsemble:()=>ze,createEnsembleFactory:()=>Ct,createEvent:()=>Le,createFetchMachine:()=>Rt,createFlow:()=>Re,createFunctionalMachine:()=>pe,createMachine:()=>h,createMachineBuilder:()=>an,createMachineFactory:()=>tn,createMatcher:()=>et,createMiddleware:()=>C,createMiddlewareFactory:()=>Wt,createMiddlewareRegistry:()=>Ot,createMultiMachine:()=>Tt,createMutableMachine:()=>bt,createParallelMachine:()=>ne,createPipeline:()=>Pt,createRunner:()=>Ie,createTransition:()=>Je,createTransitionExtender:()=>fe,createTransitionFactory:()=>Xe,customCase:()=>rt,delegate:()=>L,delegateToChild:()=>wt,describe:()=>Pe,discriminantCase:()=>nt,extendTransitions:()=>he,forContext:()=>ot,freeze:()=>ge,fromObservable:()=>it,fromPromise:()=>st,guard:()=>k,guardAsync:()=>K,guarded:()=>ke,hasState:()=>W,inDevelopment:()=>Ft,invoke:()=>Ke,isConditionalMiddleware:()=>_t,isContextBound:()=>dt,isMiddlewareContext:()=>Nt,isMiddlewareError:()=>Ht,isMiddlewareFn:()=>le,isMiddlewareHooks:()=>It,isMiddlewareOptions:()=>zt,isMiddlewareResult:()=>Bt,isNamedMiddleware:()=>Dt,isPipelineConfig:()=>$t,isState:()=>Ge,logState:()=>Ye,machineExclude:()=>Gt,machineUnion:()=>Ut,matchMachine:()=>sn,mergeContext:()=>Ve,metadata:()=>He,middlewareBuilder:()=>De,minimal:()=>G,next:()=>dn,overrideTransitions:()=>rn,pipeTransitions:()=>qe,run:()=>Y,runAsync:()=>je,runMachine:()=>cn,runSequence:()=>Ee,runWithDebug:()=>ve,runWithEnsemble:()=>mt,runWithRunner:()=>gt,setContext:()=>R,spawn:()=>at,state:()=>Ze,step:()=>be,stepAsync:()=>Ae,tag:()=>S,toggle:()=>Et,transitionTo:()=>Oe,when:()=>D,whenContext:()=>St,whenGuard:()=>Be,whenGuardAsync:()=>Ne,withAnalytics:()=>ae,withDebugging:()=>$e,withErrorReporting:()=>ce,withHistory:()=>_,withLogging:()=>oe,withPerformanceMonitoring:()=>de,withPermissions:()=>ie,withRetry:()=>ye,withSnapshot:()=>B,withTimeTravel:()=>N,withValidation:()=>se,yieldMachine:()=>we});module.exports=ht(yn);var Te=Symbol.for("__machine_transitions__");function b(e,t){return Object.defineProperty(e,Te,{value:t,enumerable:!1,configurable:!1}),e}function O(e){if(!(!e||typeof e!="object"))return e[Te]}function P(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function Y(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=n.next(r);if(a)return o;r=o}}function be(e){return function*(){return yield e}()}function we(e){return e}function Ee(e,t){return t.reduce((n,r)=>Y(r,n),e)}function Re(e){return e}function ve(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:s,done:i}=r.next(o);if(i)return console.log("Final:",s),s;o=s,a++,n(a,o)}}async function je(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*Ae(e){return yield e}var Se=Symbol("MachineMeta"),Fe=Symbol("__machine_runtime_meta__");function w(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 Oe(e,t){return w(t,{target:e.name||e.toString()}),t}function Pe(e,t){return w(t,{description:e}),t}function ke(e,t){return w(t,{guards:[e]}),t}function Ke(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function _e(e,t){return w(t,{actions:[e]}),t}function k(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(e(y,...c)){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)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(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),i}function K(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=async function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(await Promise.resolve(e(y,...c))){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)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(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),i}function Be(e){return{do(t){let n=k(e,t);return n.else=function(r){return k(e,t,{onFail:r})},n}}}function Ne(e){return{do(t){let n=K(e,t);return n.else=function(r){return K(e,t,{onFail:r})},n}}}function He(e,t){return t}function Ie(e,t){let n=e,r=i=>{n=i,t==null||t(i)},{context:o,...a}=e,s=new Proxy({},{get(i,c){let d=n[c];if(typeof d=="function")return(...y)=>{let u=d.apply(n,y),x=Object.assign({context:u.context},a);return r(x),x}}});return{get state(){return n},get context(){return n.context},actions:s,setState:r}}function ze(e,t,n){let r=()=>{let a=e.getContext(),s=n(a),i=t[s];if(!i)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(s)}".`);return i(a)},o=new Proxy({},{get(a,s){let i=r(),c=i[s];if(typeof c!="function")throw new Error(`[Ensemble] Transition "${s}" is not valid in the current state.`);return(...d)=>c.apply(i,d)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Ct(e,t){return function(r){return ze(e,r,t)}}function gt(e,t){let n=Ie(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function mt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var J=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function Tt(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 s=n[o];if(typeof s=="function")return(...i)=>s.apply(n,i)},set(r,o,a){let s=t.getContext();if(o in s){let i={...s,[o]:a};return t.setContext(i),!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),s=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(i=>i!=="constructor"&&typeof n[i]=="function");return Array.from(new Set([...a,...s]))},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 bt(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,s){if(a in o)return o[a];let i=r(),c=i[a];if(typeof c=="function")return(...d)=>{let y=c.apply(i,d);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(a)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(u=>delete o[u]),Object.assign(o,y)}},set(o,a,s,i){return o[a]=s,!0},has(o,a){let s=r();return a in o||typeof s[a]=="function"}})}function wt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return R(this,{...this.context,child:r})}return this}}function Et(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.`),R(this,{...this.context,[e]:!this.context[e]})}}var Q=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=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 Z(this.config,{status:"success",data:n})};this.fail=n=>{var o,a,s;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new X(this.config,this.params,n,this.context.attempts):((s=(a=this.config).onError)==null||s.call(a,n),new ee(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new te(this.config));this.execute()}async execute(){}},X=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 E(this.config,n!=null?n:this.params,this.context.attempts+1)}},Z=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},ee=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},te=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function Rt(e){return new Q(e)}function ne(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let a={};for(let s in r){let i=r[s];a[s]=(...c)=>{let d=i.apply(e,c);return ne(d,t)}}for(let s in o){let i=o[s];a[s]=(...c)=>{let d=i.apply(t,c);return ne(e,d)}}return{context:n,...a}}var re=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:a}=n,s={...e};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&i!=="context"&&typeof e[i]!="function"&&(s[i]=e[i]);for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let c=e[i];typeof c=="function"&&i!=="context"&&(s[i]=function(...d){let y=i,u=s.context,x=()=>{let l;try{l=c.apply(this,d)}catch(f){if(t.error)try{t.error({transitionName:y,context:u,args:[...d],error:f})}catch(p){if(!r)throw p;o&&console.error(`Middleware error hook error for ${y}:`,p),a==null||a(p,"error",{transitionName:y,context:u,args:d,error:f})}throw f}let M=f=>{if(f&&typeof f=="object"&&f.context){for(let p in s)Object.prototype.hasOwnProperty.call(s,p)&&p!=="context"&&!(p in f)&&(f[p]=s[p]);for(let p in f){if(!Object.prototype.hasOwnProperty.call(f,p))continue;typeof f[p]=="function"&&p!=="context"&&s[p]&&(f[p]=s[p])}}return f};if(l&&typeof l.then=="function")return l.then(p=>{if(M(p),t.after)try{let g=t.after({transitionName:y,prevContext:u,nextContext:p.context,args:[...d]});if(g&&typeof g.then=="function")return g.then(()=>p)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${y}:`,g),a==null||a(g,"after",{transitionName:y,prevContext:u,nextContext:p.context,args:d})}return p});if(M(l),t.after)try{let f=t.after({transitionName:y,prevContext:u,nextContext:l.context,args:[...d]});if(f&&typeof f=="object"&&f&&"then"in f)return f.then(()=>l).catch(p=>{if(!r)throw p;return o&&console.error(`Middleware after hook error for ${y}:`,p),a==null||a(p,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d}),l})}catch(f){if(!r)throw f;o&&console.error(`Middleware after hook error for ${y}:`,f),a==null||a(f,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d})}return l};if(t.before)try{let l=t.before({transitionName:y,context:u,args:[...d]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(M=>M===re?s:x()).catch(M=>{if(!r)throw M;return o&&console.error(`Middleware before hook error for ${y}:`,M),a==null||a(M,"before",{transitionName:y,context:u,args:d}),x()});if(l===re)return s}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${y}:`,l),a==null||a(l,"before",{transitionName:y,context:u,args:d})}return x()})}return s}function oe(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:a,args:s})=>{let i=r?`→ ${a} [${s.join(", ")}]`:`→ ${a}`;n(i)},after:({transitionName:a,nextContext:s})=>{let i=o?` ${JSON.stringify(s)}`:"";n(`✓ ${a}${i}`)},error:({transitionName:a,error:s})=>{console.error(`[Machine] ${a} failed:`,s)}})}function ae(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=n;return C(e,{after:({transitionName:s,prevContext:i,nextContext:c,args:d})=>{let y=`${r}.${s}`,u={transition:s};o&&(u.from=i),u.to=c,a&&(u.args=d),t(y,u)}})}function se(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ie(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ce(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 de(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 s={transitionName:r.transitionName,duration:a,context:r.nextContext||r.prevContext};t(s)}}})}function ye(e,t={}){var c,d;let{maxAttempts:n=(c=t.maxRetries)!=null?c:3,shouldRetry:r=()=>!0,backoffMs:o=(d=t.delay)!=null?d:100,backoffMultiplier:a=2,onRetry:s}=t,i={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let u=e[y];typeof u=="function"&&y!=="context"&&(i[y]=async function(...x){let l,M=0;for(;M<n;)try{return await u.apply(this,x)}catch(f){if(l=f,M++,M<n&&r(l,M)){s==null||s(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 i}function vt(e,t){return n=>C(n,e,t)}function _(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,a=[],s=0,i=C(e,{before:({transitionName:c,args:d})=>{let y={id:`entry-${s++}`,transitionName:c,args:[...d],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(d)}catch(u){console.error("Failed to serialize history args:",u)}a.push(y),n&&a.length>n&&a.shift(),o==null||o(y)}});return Object.assign(i,{history:a,clearHistory:()=>{a.length=0,s=0}})}function B(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=t,s=[],i=0,c=C(e,{after:({transitionName:y,prevContext:u,nextContext:x})=>{if(a&&JSON.stringify(u)===JSON.stringify(x))return;let l={id:`snapshot-${i++}`,transitionName:y,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(u),l.serializedAfter=r.serialize(x)}catch(M){console.error("Failed to serialize snapshot:",M)}if(o)try{l.diff=o(u,x)}catch(M){console.error("Failed to capture snapshot:",M)}s.push(l),n&&s.length>n&&s.shift()}});return Object.assign(c,{snapshots:s,clearSnapshots:()=>{s.length=0,i=0},restoreSnapshot:y=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="snapshots"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&typeof e[x]=="function"));return Object.assign({context:y},u)}})}function N(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,a=[],s=[],i=0,c=0,d=C(e,{before:({transitionName:x,args:l})=>{let M={id:`entry-${i++}`,transitionName:x,args:[...l],timestamp:Date.now()};if(r)try{M.serializedArgs=r.serialize(l)}catch(f){console.error("Failed to serialize history args:",f)}a.push(M),n&&a.length>n&&a.shift(),o==null||o("history",M)},after:({transitionName:x,prevContext:l,nextContext:M})=>{let f={id:`snapshot-${c++}`,transitionName:x,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{f.serializedBefore=r.serialize(l),f.serializedAfter=r.serialize(M)}catch(p){console.error("Failed to serialize snapshot:",p)}s.push(f),n&&s.length>n&&s.shift(),o==null||o("snapshot",f)}});return Object.assign(d,{history:a,snapshots:s,clearHistory:()=>{a.length=0,i=0},clearSnapshots:()=>{s.length=0,c=0},clearTimeTravel:()=>{a.length=0,s.length=0,i=0,c=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=s[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 me=p[T.transitionName];me&&(p=me.apply(p,T.args))}return p}})}function jt(e,...t){return t.reduce((n,r)=>r(n),e)}function H(e,...t){return t.reduce((n,r)=>r(n),e)}var ue=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function At(e){return new ue(e)}function D(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ft(e){return D(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function St(e,t,n){return D(n,r=>r.context[e]===t)}function Ot(){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 s,i;return((s=o.priority)!=null?s:0)-((i=a.priority)!=null?i:0)});return H(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return H(t,...n.map(r=>r.middleware))}}}function Pt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...a)=>{let s=o,i=[],c=!0;for(let d=0;d<a.length;d++){let y=a[d];try{if("middleware"in y&&"when"in y){if(!y.when(s))continue;s=y.middleware(s)}else s=y(s)}catch(u){if(c=!1,!t)throw u;i.push({error:u,middlewareIndex:d,middlewareName:y.name}),n&&console.error(`Pipeline middleware error at index ${d}:`,u),r==null||r(u,d,y.name)}}return{machine:s,errors:i,success:c}}}function kt(...e){return t=>H(t,...e)}function Kt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function le(e){return typeof e=="function"&&e.length===1}function _t(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&le(e.middleware)&&typeof e.when=="function"}function Bt(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||I(e.prevContext,t)&&I(e.nextContext,t))}function Nt(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||I(e.context,t))}function Ht(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||I(e.context,t))}function It(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 zt(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 I(e,t){return e!==null&&typeof e=="object"}function Dt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&le(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 $t(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 z=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>oe(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>ae(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>se(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ie(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ce(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>de(r,t)),this}withRetry(t){return this.middlewares.push(n=>ye(n,t)),this}withHistory(t){return this.middlewares.push(n=>_(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>B(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>N(n,t)),this}withDebugging(){return this.middlewares.push(t=>$e(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(D(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 De(e){return new z(e)}function Wt(e={}){return{create:t=>{let n=De(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 $e(e){return N(B(_(e)))}function xe(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 We(...e){let t=e[0];class n extends t{constructor(a){super(a)}}let r=o=>function(...a){let s=o.apply(this,a);if(s&&typeof s=="object"&&"context"in s){let i={...this.context,...s.context};return new n(i)}return s};for(let o of e){let a=xe(o.prototype);for(let[s,i]of Object.entries(a))if(s!=="constructor")if(typeof i.value=="function"){let c=i.value,d=r(c);Object.defineProperty(n.prototype,s,{...i,value:d})}else Object.defineProperty(n.prototype,s,i)}return n}function Ue(e,...t){class n extends m{constructor(a){super(a)}}let r=xe(e.prototype);for(let[o,a]of Object.entries(r))if(o!=="constructor")if(typeof a.value=="function"){let s=a.value,i=function(...c){let d=s.apply(this,c);return d&&typeof d=="object"&&"context"in d?new n({...this.context,...d.context}):d};Object.defineProperty(n.prototype,o,{...a,value:i})}else Object.defineProperty(n.prototype,o,a);for(let o of t){let a=xe(o.prototype);for(let s of Object.keys(a))Object.prototype.hasOwnProperty.call(n.prototype,s)&&delete n.prototype[s]}return n}function Ut(...e){let t=e.map(a=>a.constructor),n=e.map(a=>a.context),r=Object.assign({},...n),o=We(...t);return new o(r)}function Gt(e,...t){let n=e.constructor,r=t.map(a=>a.constructor),o=Ue(n,...r);return new o(e.context)}function Ge(e,t){return e instanceof t}function Le(e,...t){return{type:e,args:t}}function Ve(e,t){return R(e,n=>({...n,...t}))}async function qe(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Ye(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Je(e,t){return function(...n){let r=t(this.context,...n);return h(r,e())}}function Qe(e,t,...n){return e.apply(t,n)}function Me(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let a=r.apply(t,o);return a&&typeof a=="object"&&"context"in a?Me(a):a}:r}})}var $=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 s=o.apply(this.wrappedMachine,a);return s&&typeof s=="object"&&"context"in s?new e(s):s}:o}})}};function Xe(){return function(t){return function(...n){let r=t(this.context,...n);return h(r,this)}}}function fe(e){return{machine:e,addTransition:function(t,n){let r=function(...a){let s=n(this.context,...a);return h(s,this)},o=he(e,{[t]:r});return fe(o)}}}function pe(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([a,s])=>[a,function(...i){let c=s(this.context,...i);return h(c,r)}]));return Object.assign(r,o),h(e,r)}}function Ze(e,t){return t!==void 0?h(e,t):pe(e)}function et(...e){let t=new Map;for(let[i,c,d]of e){if(t.has(i))throw new Error(`Duplicate matcher case name: "${i}"`);t.set(i,{predicate:d})}let n=new Proxy({},{get(i,c){return function(y){let u=t.get(c);if(!u){let x=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${x}`)}return u.predicate(y)}}}),r=new Proxy({},{get(i,c){return function(y){if(!t.has(c)){let u=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${u}`)}return{__brand:"CaseHandler",__name:c,__machine:void 0,__return:void 0,handler:y}}}}),o={__exhaustive:!0};function a(i){return{is(...c){if(c.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let d=c[c.length-1];if(!d||typeof d!="object"||!("__exhaustive"in d))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=c.slice(0,-1);for(let l of y){let M=l.__name,f=t.get(M);if(!f)throw new Error(`Internal error: Unknown matcher case in handler: ${M}`);if(f.predicate(i))return l.handler(i)}let u=y.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: [${u}]
3
3
  All cases: [${x}]
4
- This may occur if predicates don't cover all runtime possibilities.`)}}}function s(i){for(let[c,d,y]of e)if(y(i))return c;return null}return Object.assign(s,{is:n,when:a,case:r,exhaustive:o})}function tt(e,t){return[e,void 0,n=>n instanceof t]}function nt(e,t,n){return[e,void 0,r=>W(r,t,n)]}function rt(e,t){return[e,void 0,t]}function ot(){return{case(e,t,n){return[e,void 0,r=>W(r,t,n)]}}}var R=class R{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){R._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(R._inspector&&R._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,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))}};R._inspector=null;var A=R;function F(e){return new A(e)}function at(e){return F(e)}function st(e){let n=h({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 it(e){let n=h({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 Ce(e,t){let n=t,r=Object.fromEntries(Object.entries(t).map(([o,a])=>[o,function(...s){let i={context:this.context},c=a.apply(i,s);return Ce(c,n)}]));return Object.values(r).forEach(o=>{typeof o=="function"&&Object.defineProperty(o,"__contextBound",{value:!0,enumerable:!1})}),b(Object.assign({context:e},r),r)}function ct(e,t,...n){let r=e[t],o={context:e.context};return r.apply(o,n)}function dt(e){let t=Object.values(e).find(n=>typeof n=="function");return t?t.__contextBound===!0:!1}var U={};q(U,{factory:()=>Jt,freeze:()=>ge,isState:()=>Lt,machine:()=>G,match:()=>Vt,run:()=>Yt,runnable:()=>qt,tag:()=>S,union:()=>Qt,withChildren:()=>yt});function S(e,t){return typeof e=="object"?e:t?{...t,tag:e}:{tag:e}}(t=>{function e(n){return n?r=>t(n,r):r=>o=>t(r,o)}t.factory=e})(S||(S={}));function Lt(e,t){return e.tag===t}function ge(e){if(Object.freeze(e),typeof Object.values=="function")for(let t of Object.values(e))t&&typeof t=="object"&&ge(t);return e}function G(e,t){let r=t(e,o=>G(o,t));return Object.assign({},e,r)}function Vt(e,t){let n=t[e.tag];return n(e)}var j=Symbol("lifecycle");function qt(e,t){let n={...e};return n[j]=t,n}function Yt(e){let t=e,n=null,r=new Set,o=()=>{r.forEach(i=>i(t))},a=()=>{n&&(n(),n=null);let i=t[j],c=t.tag,d=i==null?void 0:i[c];d!=null&&d.onEnter&&(n=d.onEnter(s))},s=(i,...c)=>{let d=t[i];if(typeof d=="function"){let y=d(...c);if(y&&typeof y=="object"&&"tag"in y){let u=y;!u[j]&&t[j]&&(u[j]=t[j]),t=u,a(),o()}}};return a(),{get:()=>t,send:s,stop:()=>{n&&(n(),n=null),r.clear()},subscribe:i=>(r.add(i),()=>r.delete(i))}}function yt(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r],a=new Proxy(o,{get(s,i){let c=s[i];return typeof c=="function"?(...d)=>{let y=c(...d);return yt({...e},{...t,[r]:y})}:c}});n[r]=a}return n}function Jt(){return e=>t=>G(t,e)}function Qt(){return e=>{let t=n=>{let r=e[n.tag];return G(n,(o,a)=>r(o,t))};return t}}var L={};q(L,{createDelegate:()=>Xt,delegate:()=>ut,delegateAll:()=>Zt,renameMap:()=>en});function ut(e,t,n,r){let o=e[t],a={},s=Object.keys(o).filter(c=>typeof o[c]=="function"),i;if(!r)i=Object.fromEntries(s.map(c=>[c,c]));else if("pick"in r)i=Object.fromEntries(r.pick.filter(c=>s.includes(c)).map(c=>[c,c]));else if("omit"in r){let c=new Set(r.omit);i=Object.fromEntries(s.filter(d=>!c.has(d)).map(d=>[d,d]))}else"rename"in r?i=Object.fromEntries(Object.entries(r.rename).filter(([c])=>s.includes(c))):i={};for(let[c,d]of Object.entries(i)){let y=o[c];a[d]=(...u)=>{let x=y.apply(o,u);return n({...e,[t]:x})}}return a}function Xt(e,t){return(n,r)=>ut(e,n,t,r)}function Zt(e,t,n,r=!1){let o={};for(let a of t){let s=e[a],i=Object.keys(s).filter(c=>typeof s[c]=="function");for(let c of i){let d=r?`${String(a)}_${c}`:c,y=s[c];o[d]=(...u)=>{let x=y.apply(s,u);return n({...e,[a]:x})}}}return o}function en(){return e=>e}function h(e,t){if(typeof t=="function"){let a;return a=t(i=>h(i,a)),b(Object.assign({context:e},a),a)}let n=O(t),r=n!=null?n:"context"in t?P(t):t,o=Object.assign({context:e},r);return b(o,r)}function lt(e,t){if(typeof t=="function"){let a;return a=t(i=>lt(i,a)),b(Object.assign({context:e},a),a)}let n=O(t),r=n!=null?n:"context"in t?P(t):t,o=Object.assign({context:e},r);return b(o,r)}function tn(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let a=r(this.context,...o);return h(a,t)}]));return n=>h(n,t)}}function v(e,t){var a;let n=e.context,r=(a=O(e))!=null?a:P(e),o=typeof t=="function"?t(n):t;return h(o,r)}function nn(e){return{context:e}}function rn(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function he(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function on(e,t){return(...n)=>{let r=e(...n),o=t(),a={...r.context,...o.context},{context:s,...i}=r,{context:c,...d}=o,y={...i,...d};return h(a,y)}}function an(e){let{context:t,...n}=e;return r=>h(r,n)}function sn(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 W(e,t,n){return e.context[t]===n}function cn(e,t){let n=e,r=null;async function o(a){r&&(r.abort(),r=null);let s=n[a.type];if(typeof s!="function")throw new Error(`[Machine] Unknown event type '${String(a.type)}' on current state.`);let i=new AbortController;r=i;try{let d=await s.apply(n,[...a.args,{signal:i.signal}]);return i.signal.aborted||(n=d,t==null||t(n)),n}finally{r===i&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function dn(e,t){return v(e,n=>t(n))}
4
+ This may occur if predicates don't cover all runtime possibilities.`)}}}function s(i){for(let[c,d,y]of e)if(y(i))return c;return null}return Object.assign(s,{is:n,when:a,case:r,exhaustive:o})}function tt(e,t){return[e,void 0,n=>n instanceof t]}function nt(e,t,n){return[e,void 0,r=>W(r,t,n)]}function rt(e,t){return[e,void 0,t]}function ot(){return{case(e,t,n){return[e,void 0,r=>W(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,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 at(e){return F(e)}function st(e){let n=h({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 it(e){let n=h({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 Ce(e,t){let n=t,r=Object.fromEntries(Object.entries(t).map(([o,a])=>[o,function(...s){let i={context:this.context},c=a.apply(i,s);return Ce(c,n)}]));return Object.values(r).forEach(o=>{typeof o=="function"&&Object.defineProperty(o,"__contextBound",{value:!0,enumerable:!1})}),b(Object.assign({context:e},r),r)}function ct(e,t,...n){let r=e[t],o={context:e.context};return r.apply(o,n)}function dt(e){let t=Object.values(e).find(n=>typeof n=="function");return t?t.__contextBound===!0:!1}var G={};q(G,{factory:()=>Jt,freeze:()=>ge,isState:()=>Lt,machine:()=>U,match:()=>Vt,run:()=>Yt,runnable:()=>qt,tag:()=>S,union:()=>Qt,withChildren:()=>yt});function S(e,t){return typeof e=="object"?e:t?{...t,tag:e}:{tag:e}}(t=>{function e(n){return n?r=>t(n,r):r=>o=>t(r,o)}t.factory=e})(S||(S={}));function Lt(e,t){return e.tag===t}function ge(e){if(Object.freeze(e),typeof Object.values=="function")for(let t of Object.values(e))t&&typeof t=="object"&&ge(t);return e}function U(e,t){let n;return n=Object.assign({},e,t(e,o=>o===e?n:U(o,t))),n}function Vt(e,t){let n=t[e.tag];return n(e)}var j=Symbol("lifecycle");function qt(e,t){let n={...e};return n[j]=t,n}function Yt(e){let t=e,n=null,r=new Set,o=()=>{r.forEach(i=>i(t))},a=()=>{n&&(n(),n=null);let i=t[j],c=t.tag,d=i==null?void 0:i[c];d!=null&&d.onEnter&&(n=d.onEnter(s))},s=(i,...c)=>{let d=t[i];if(typeof d=="function"){let y=d(...c);if(y&&typeof y=="object"&&"tag"in y){let u=y;!u[j]&&t[j]&&(u[j]=t[j]),t=u,a(),o()}}};return a(),{get:()=>t,send:s,stop:()=>{n&&(n(),n=null),r.clear()},subscribe:i=>(r.add(i),()=>r.delete(i))}}function yt(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r],a=new Proxy(o,{get(s,i){let c=s[i];return typeof c=="function"?(...d)=>{let y=c(...d);return yt({...e},{...t,[r]:y})}:c}});n[r]=a}return n}function Jt(){return e=>{let t=n=>{let r=o=>t(o);return U(n,o=>e(o,r))};return t}}function Qt(){return e=>{let t=n=>{let r=e[n.tag],o=a=>t(a);return U(n,a=>r(a,o))};return t}}var L={};q(L,{createDelegate:()=>Xt,delegate:()=>ut,delegateAll:()=>Zt,renameMap:()=>en});function ut(e,t,n,r){let o=e[t],a={},s=Object.keys(o).filter(c=>typeof o[c]=="function"),i;if(!r)i=Object.fromEntries(s.map(c=>[c,c]));else if("pick"in r)i=Object.fromEntries(r.pick.filter(c=>s.includes(c)).map(c=>[c,c]));else if("omit"in r){let c=new Set(r.omit);i=Object.fromEntries(s.filter(d=>!c.has(d)).map(d=>[d,d]))}else"rename"in r?i=Object.fromEntries(Object.entries(r.rename).filter(([c])=>s.includes(c))):i={};for(let[c,d]of Object.entries(i)){let y=o[c];a[d]=(...u)=>{let x=y.apply(o,u);return n({...e,[t]:x})}}return a}function Xt(e,t){return(n,r)=>ut(e,n,t,r)}function Zt(e,t,n,r=!1){let o={};for(let a of t){let s=e[a],i=Object.keys(s).filter(c=>typeof s[c]=="function");for(let c of i){let d=r?`${String(a)}_${c}`:c,y=s[c];o[d]=(...u)=>{let x=y.apply(s,u);return n({...e,[a]:x})}}}return o}function en(){return e=>e}function h(e,t){if(typeof t=="function"){let a,s;return s=t(c=>c===e?a:h(c,s)),a=b(Object.assign({context:e},s),s),a}let n=O(t),r=n!=null?n:"context"in t?P(t):t,o=Object.assign({context:e},r);return b(o,r)}function lt(e,t){if(typeof t=="function"){let a;return a=t(i=>lt(i,a)),b(Object.assign({context:e},a),a)}let n=O(t),r=n!=null?n:"context"in t?P(t):t,o=Object.assign({context:e},r);return b(o,r)}function tn(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let a=r(this.context,...o);return h(a,t)}]));return n=>h(n,t)}}function R(e,t){var a;let n=e.context,r=(a=O(e))!=null?a:P(e),o=typeof t=="function"?t(n):t;return h(o,r)}function nn(e){return{context:e}}function rn(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function he(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function on(e,t){return(...n)=>{let r=e(...n),o=t(),a={...r.context,...o.context},{context:s,...i}=r,{context:c,...d}=o,y={...i,...d};return h(a,y)}}function an(e){let{context:t,...n}=e;return r=>h(r,n)}function sn(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 W(e,t,n){return e.context[t]===n}function cn(e,t){let n=e,r=null;async function o(a){r&&(r.abort(),r=null);let s=n[a.type];if(typeof s!="function")throw new Error(`[Machine] Unknown event type '${String(a.type)}' on current state.`);let i=new AbortController;r=i;try{let d=await s.apply(n,[...a.args,{signal:i.signal}]);return i.signal.aborted||(n=d,t==null||t(n)),n}finally{r===i&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function dn(e,t){return R(e,n=>t(n))}
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},j=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!b.call(t,r)&&r!==n&&p(t,r,{get:()=>e[r],enumerable:!(a=M(e,r))||a.enumerable});return t};var R=t=>j(p({},"__esModule",{value:!0}),t);var F={};h(F,{factory:()=>O,freeze:()=>T,isState:()=>K,machine:()=>u,match:()=>k,run:()=>P,runnable:()=>E,tag:()=>y,union:()=>w,withChildren:()=>C});module.exports=R(F);function y(t,e){return typeof t=="object"?t:e?{...e,tag:t}:{tag:t}}(e=>{function t(n){return n?a=>e(n,a):a=>r=>e(a,r)}e.factory=t})(y||(y={}));function K(t,e){return t.tag===e}function T(t){if(Object.freeze(t),typeof Object.values=="function")for(let e of Object.values(t))e&&typeof e=="object"&&T(e);return t}function u(t,e){let a=e(t,r=>u(r,e));return Object.assign({},t,a)}function k(t,e){let n=e[t.tag];return n(t)}var g=Symbol("lifecycle");function E(t,e){let n={...t};return n[g]=e,n}function P(t){let e=t,n=null,a=new Set,r=()=>{a.forEach(s=>s(e))},x=()=>{n&&(n(),n=null);let s=e[g],c=e.tag,o=s==null?void 0:s[c];o!=null&&o.onEnter&&(n=o.onEnter(d))},d=(s,...c)=>{let o=e[s];if(typeof o=="function"){let i=o(...c);if(i&&typeof i=="object"&&"tag"in i){let f=i;!f[g]&&e[g]&&(f[g]=e[g]),e=f,x(),r()}}};return x(),{get:()=>e,send:d,stop:()=>{n&&(n(),n=null),a.clear()},subscribe:s=>(a.add(s),()=>a.delete(s))}}function C(t,e){let n={...t};for(let a of Object.keys(e)){let r=e[a],x=new Proxy(r,{get(d,s){let c=d[s];return typeof c=="function"?(...o)=>{let i=c(...o);return C({...t},{...e,[a]:i})}:c}});n[a]=x}return n}function O(){return t=>e=>u(e,t)}function w(){return t=>{let e=n=>{let a=t[n.tag];return u(n,(r,x)=>a(r,e))};return e}}
1
+ "use strict";var T=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var n in e)T(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!b.call(t,r)&&r!==n&&T(t,r,{get:()=>e[r],enumerable:!(a=l(e,r))||a.enumerable});return t};var R=t=>K(T({},"__esModule",{value:!0}),t);var w={};h(w,{factory:()=>F,freeze:()=>p,isState:()=>j,machine:()=>u,match:()=>k,run:()=>P,runnable:()=>E,tag:()=>y,union:()=>O,withChildren:()=>C});module.exports=R(w);function y(t,e){return typeof t=="object"?t:e?{...e,tag:t}:{tag:t}}(e=>{function t(n){return n?a=>e(n,a):a=>r=>e(a,r)}e.factory=t})(y||(y={}));function j(t,e){return t.tag===e}function p(t){if(Object.freeze(t),typeof Object.values=="function")for(let e of Object.values(t))e&&typeof e=="object"&&p(e);return t}function u(t,e){let n;return n=Object.assign({},t,e(t,r=>r===t?n:u(r,e))),n}function k(t,e){let n=e[t.tag];return n(t)}var x=Symbol("lifecycle");function E(t,e){let n={...t};return n[x]=e,n}function P(t){let e=t,n=null,a=new Set,r=()=>{a.forEach(s=>s(e))},c=()=>{n&&(n(),n=null);let s=e[x],i=e.tag,o=s==null?void 0:s[i];o!=null&&o.onEnter&&(n=o.onEnter(d))},d=(s,...i)=>{let o=e[s];if(typeof o=="function"){let g=o(...i);if(g&&typeof g=="object"&&"tag"in g){let f=g;!f[x]&&e[x]&&(f[x]=e[x]),e=f,c(),r()}}};return c(),{get:()=>e,send:d,stop:()=>{n&&(n(),n=null),a.clear()},subscribe:s=>(a.add(s),()=>a.delete(s))}}function C(t,e){let n={...t};for(let a of Object.keys(e)){let r=e[a],c=new Proxy(r,{get(d,s){let i=d[s];return typeof i=="function"?(...o)=>{let g=i(...o);return C({...t},{...e,[a]:g})}:i}});n[a]=c}return n}function F(){return t=>{let e=n=>{let a=r=>e(r);return u(n,r=>t(r,a))};return e}}function O(){return t=>{let e=n=>{let a=t[n.tag],r=c=>e(c);return u(n,c=>a(c,r))};return e}}
@@ -1 +1 @@
1
- "use strict";var $=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nt(t))!rt.call(e,o)&&o!==n&&$(e,o,{get:()=>t[o],enumerable:!(r=tt(t,o))||r.enumerable});return e};var at=e=>it($({},"__esModule",{value:!0}),e);var Bt={};ot(Bt,{BoundMachine:()=>G,CANCEL:()=>Q,META_KEY:()=>be,MachineBase:()=>T,MiddlewareBuilder:()=>z,MultiMachineBase:()=>I,action:()=>Fe,bindTransitions:()=>se,branch:()=>wt,call:()=>We,chain:()=>pt,combine:()=>bt,combineFactories:()=>Ve,compose:()=>ft,composeTyped:()=>K,createAsyncMachine:()=>ue,createCustomMiddleware:()=>ht,createEnsemble:()=>P,createEnsembleFactory:()=>st,createEvent:()=>Ke,createFetchMachine:()=>xt,createFlow:()=>pe,createFunctionalMachine:()=>de,createMachine:()=>g,createMachineBuilder:()=>Le,createMachineContext:()=>Xe,createMachineFactory:()=>De,createMiddleware:()=>C,createMiddlewareFactory:()=>Ot,createMiddlewareRegistry:()=>mt,createMultiMachine:()=>ut,createMutableMachine:()=>Mt,createParallelMachine:()=>J,createPipeline:()=>Tt,createRunner:()=>Pe,createTransition:()=>Ge,createTransitionExtender:()=>ce,createTransitionFactory:()=>He,delegateToChild:()=>yt,describe:()=>Ee,extendTransitions:()=>W,guard:()=>j,guardAsync:()=>v,guarded:()=>Ae,hasState:()=>qe,inDevelopment:()=>gt,invoke:()=>Se,isConditionalMiddleware:()=>Et,isMiddlewareContext:()=>St,isMiddlewareError:()=>Ft,isMiddlewareFn:()=>ae,isMiddlewareHooks:()=>Rt,isMiddlewareOptions:()=>jt,isMiddlewareResult:()=>At,isNamedMiddleware:()=>vt,isPipelineConfig:()=>Pt,isState:()=>ke,logState:()=>_e,matchMachine:()=>Ue,mergeContext:()=>Ne,metadata:()=>ve,middlewareBuilder:()=>Oe,next:()=>Ye,overrideTransitions:()=>Ie,pipeTransitions:()=>ze,run:()=>D,runAsync:()=>Ce,runMachine:()=>H,runSequence:()=>fe,runWithDebug:()=>ge,runWithEnsemble:()=>dt,runWithRunner:()=>ct,setContext:()=>b,state:()=>$e,step:()=>xe,stepAsync:()=>me,toggle:()=>lt,transitionTo:()=>we,useActor:()=>Ze,useActorSelector:()=>et,useEnsemble:()=>Qe,useMachine:()=>Je,useMachineSelector:()=>Me,when:()=>_,whenContext:()=>Ct,whenGuard:()=>Re,whenGuardAsync:()=>je,withAnalytics:()=>Z,withDebugging:()=>Be,withErrorReporting:()=>ne,withHistory:()=>O,withLogging:()=>X,withPerformanceMonitoring:()=>re,withPermissions:()=>te,withRetry:()=>oe,withSnapshot:()=>B,withTimeTravel:()=>k,withValidation:()=>ee,yieldMachine:()=>he});module.exports=at(Bt);var le=Symbol.for("__machine_transitions__");function S(e,t){return Object.defineProperty(e,le,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[le]}function R(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var T=class{constructor(t){this.context=t}};function D(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function xe(e){return function*(){return yield e}()}function he(e){return e}function fe(e,t){return t.reduce((n,r)=>D(r,n),e)}function pe(e){return e}function ge(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function Ce(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*me(e){return yield e}var be=Symbol("MachineMeta"),Te=Symbol("__machine_runtime_meta__");function E(e,t){let n=e[Te]||{},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,Te,{value:r,enumerable:!1,writable:!1,configurable:!0})}function we(e,t){return E(t,{target:e.name||e.toString()}),t}function Ee(e,t){return E(t,{description:e}),t}function Ae(e,t){return E(t,{guards:[e]}),t}function Se(e,t){return E(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function Fe(e,t){return E(t,{actions:[e]}),t}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let y=c?this:{context:this};return t.apply(y,u)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}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,u);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:a,enumerable:!1}),E(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function v(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let y=c?this:{context:this};return t.apply(y,u)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}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,u);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:a,enumerable:!1}),E(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function Re(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function je(e){return{do(t){let n=v(e,t);return n.else=function(r){return v(e,t,{onFail:r})},n}}}function ve(e,t){return t}function Pe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,u){let c=n[u];if(typeof c=="function")return(...d)=>{let l=c.apply(n,d),y=Object.assign({context:l.context},i);return r(y),y}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function P(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),u=s[a];if(typeof u!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>u.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function st(e,t){return function(r){return P(e,r,t)}}function ct(e,t){let n=Pe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function dt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var I=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function ut(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Mt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),u=s[i];if(typeof u=="function")return(...c)=>{let d=u.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(l=>delete o[l]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function yt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return b(this,{...this.context,child:r})}return this}}function lt(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.`),b(this,{...this.context,[e]:!this.context[e]})}}var V=class extends T{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},A=class extends T{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 U(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new L(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new q(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new Y(this.config));this.execute()}async execute(){}},L=class extends T{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new A(this.config,n!=null?n:this.params,this.context.attempts+1)}},U=class extends T{constructor(n,r){super(r);this.config=n;this.refetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},q=class extends T{constructor(n,r){super(r);this.config=n;this.retry=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},Y=class extends T{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}};function xt(e){return new V(e)}function J(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...u)=>{let c=s.apply(e,u);return J(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return J(e,c)}}return{context:n,...i}}var Q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let u=e[s];typeof u=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,l=a.context,y=()=>{let M;try{M=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:l,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:l,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(M&&typeof M.then=="function")return M.then(f=>{if(x(f),t.after)try{let m=t.after({transitionName:d,prevContext:l,nextContext:f.context,args:[...c]});if(m&&typeof m.then=="function")return m.then(()=>f)}catch(m){if(!r)throw m;o&&console.error(`Middleware after hook error for ${d}:`,m),i==null||i(m,"after",{transitionName:d,prevContext:l,nextContext:f.context,args:c})}return f});if(x(M),t.after)try{let h=t.after({transitionName:d,prevContext:l,nextContext:M.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>M).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:l,nextContext:M.context,args:c}),M})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:l,nextContext:M.context,args:c})}return M};if(t.before)try{let M=t.before({transitionName:d,context:l,args:[...c]});if(M&&typeof M=="object"&&M&&"then"in M)return M.then(x=>x===Q?a:y()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:l,args:c}),y()});if(M===Q)return a}catch(M){if(!r)throw M;o&&console.error(`Middleware before hook error for ${d}:`,M),i==null||i(M,"before",{transitionName:d,context:l,args:c})}return y()})}return a}function X(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function Z(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:u,args:c})=>{let d=`${r}.${a}`,l={transition:a};o&&(l.from=s),l.to=u,i&&(l.args=c),t(d,l)}})}function ee(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function te(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ne(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function re(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 i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function oe(e,t={}){var u,c;let{maxAttempts:n=(u=t.maxRetries)!=null?u:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let l=e[d];typeof l=="function"&&d!=="context"&&(s[d]=async function(...y){let M,x=0;for(;x<n;)try{return await l.apply(this,y)}catch(h){if(M=h,x++,x<n&&r(M,x)){a==null||a(M,x);let m=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(w=>setTimeout(w,m))}else throw M}throw M})}return s}function ht(e,t){return n=>C(n,e,t)}function O(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:u,args:c})=>{let d={id:`entry-${a++}`,transitionName:u,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(l){console.error("Failed to serialize history args:",l)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function B(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=C(e,{after:({transitionName:d,prevContext:l,nextContext:y})=>{if(i&&JSON.stringify(l)===JSON.stringify(y))return;let M={id:`snapshot-${s++}`,transitionName:d,before:{...l},after:{...y},timestamp:Date.now()};if(r)try{M.serializedBefore=r.serialize(l),M.serializedAfter=r.serialize(y)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{M.diff=o(l,y)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(M),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let l=Object.fromEntries(Object.entries(e).filter(([y])=>y!=="context"&&y!=="snapshots"&&y!=="clearSnapshots"&&y!=="restoreSnapshot"&&typeof e[y]=="function"));return Object.assign({context:d},l)}})}function k(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=C(e,{before:({transitionName:y,args:M})=>{let x={id:`entry-${s++}`,transitionName:y,args:[...M],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(M)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:y,prevContext:M,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:y,before:{...M},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(M),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,u=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,u=0},restoreSnapshot:y=>{let M=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:y},M)},replayFrom:y=>{var m;if(y<0||y>=i.length)throw new Error(`Invalid replay start index: ${y}`);let M=(m=a[y])==null?void 0:m.before;if(!M)throw new Error(`No snapshot available for index ${y}`);let x=i.slice(y),f=Object.assign({context:M},Object.fromEntries(Object.entries(e).filter(([w])=>w!=="context"&&typeof e[w]=="function")));for(let w of x){let ye=f[w.transitionName];ye&&(f=ye.apply(f,w.args))}return f}})}function ft(e,...t){return t.reduce((n,r)=>r(n),e)}function K(e,...t){return t.reduce((n,r)=>r(n),e)}var ie=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function pt(e){return new ie(e)}function _(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function gt(e){return _(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Ct(e,t,n){return _(n,r=>r.context[e]===t)}function mt(){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 i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.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 Tt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],u=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(l){if(u=!1,!t)throw l;s.push({error:l,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,l),r==null||r(l,c,d.name)}}return{machine:a,errors:s,success:u}}}function bt(...e){return t=>K(t,...e)}function wt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ae(e){return typeof e=="function"&&e.length===1}function Et(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ae(e.middleware)&&typeof e.when=="function"}function At(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||N(e.prevContext,t)&&N(e.nextContext,t))}function St(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||N(e.context,t))}function Ft(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||N(e.context,t))}function Rt(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 jt(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 N(e,t){return e!==null&&typeof e=="object"}function vt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ae(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 Pt(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 z=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>X(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ee(r,t)),this}withPermissions(t){return this.middlewares.push(n=>te(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>re(r,t)),this}withRetry(t){return this.middlewares.push(n=>oe(n,t)),this}withHistory(t){return this.middlewares.push(n=>O(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>B(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>k(n,t)),this}withDebugging(){return this.middlewares.push(t=>Be(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(_(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 Oe(e){return new z(e)}function Ot(e={}){return{create:t=>{let n=Oe(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 Be(e){return k(B(O(e)))}function ke(e,t){return e instanceof t}function Ke(e,...t){return{type:e,args:t}}function Ne(e,t){return b(e,n=>({...n,...t}))}async function ze(e,...t){let n=e;for(let r of t)n=await r(n);return n}function _e(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Ge(e,t){return function(...n){let r=t(this.context,...n);return g(r,e())}}function We(e,t,...n){return e.apply(t,n)}function se(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?se(i):i}:r}})}var G=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"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function He(){return function(t){return function(...n){let r=t(this.context,...n);return g(r,this)}}}function ce(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return g(a,this)},o=W(e,{[t]:r});return ce(o)}}}function de(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let u=a(this.context,...s);return g(u,r)}]));return Object.assign(r,o),g(e,r)}}function $e(e,t){return t!==void 0?g(e,t):de(e)}function g(e,t){if(typeof t=="function"){let i;return i=t(s=>g(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function ue(e,t){if(typeof t=="function"){let i;return i=t(s=>ue(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function De(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return g(i,t)}]));return n=>g(n,t)}}function b(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:R(e),o=typeof t=="function"?t(n):t;return g(o,r)}function Ie(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function W(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function Ve(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:u,...c}=o,d={...s,...c};return g(i,d)}}function Le(e){let{context:t,...n}=e;return r=>g(r,n)}function Ue(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 qe(e,t,n){return e.context[t]===n}function H(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.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)}}}function Ye(e,t){return b(e,n=>t(n))}var p=require("react");function Je(e){let[t,n]=(0,p.useState)(e),r=(0,p.useMemo)(()=>H(t,i=>{n(i)}),[]),o=(0,p.useMemo)(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function Me(e,t,n=Object.is){let[r,o]=(0,p.useState)(()=>t(e)),i=(0,p.useRef)(t),a=(0,p.useRef)(n);return i.current=t,a.current=n,(0,p.useEffect)(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function Qe(e,t,n){let[r,o]=(0,p.useState)(e),i=(0,p.useRef)(r);i.current=r;let a=(0,p.useMemo)(()=>({getContext:()=>i.current,setContext:u=>{o(u)}}),[]);return(0,p.useMemo)(()=>P(a,t,n),[a,t,n])}function Xe(){let e=(0,p.createContext)(null),t=({machine:a,actions:s,children:u})=>{let c=(0,p.useMemo)(()=>[a,s],[a,s]);return(0,p.createElement)(e.Provider,{value:c},u)},n=()=>{let a=(0,p.useContext)(e);if(!a)throw new Error("useMachineContext must be used within a Machine.Provider");return a},r=()=>n()[0];return{Provider:t,useMachineContext:n,useMachineState:r,useMachineActions:()=>n()[1],useSelector:(a,s)=>{let u=r();return Me(u,a,s)}}}function Ze(e){let t=(0,p.useMemo)(()=>e.subscribe.bind(e),[e]),n=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]);return(0,p.useSyncExternalStore)(t,n)}function et(e,t,n=Object.is){let r=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=(0,p.useState)(o);return(0,p.useEffect)(()=>{let s=()=>{let u=t(e.getSnapshot());a(c=>n(c,u)?c:u)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}
1
+ "use strict";var $=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nt(t))!rt.call(e,o)&&o!==n&&$(e,o,{get:()=>t[o],enumerable:!(r=tt(t,o))||r.enumerable});return e};var at=e=>it($({},"__esModule",{value:!0}),e);var Bt={};ot(Bt,{BoundMachine:()=>G,CANCEL:()=>Q,META_KEY:()=>be,MachineBase:()=>T,MiddlewareBuilder:()=>z,MultiMachineBase:()=>I,action:()=>Fe,bindTransitions:()=>se,branch:()=>wt,call:()=>We,chain:()=>pt,combine:()=>bt,combineFactories:()=>Ve,compose:()=>ft,composeTyped:()=>K,createAsyncMachine:()=>ue,createCustomMiddleware:()=>ht,createEnsemble:()=>P,createEnsembleFactory:()=>st,createEvent:()=>Ke,createFetchMachine:()=>xt,createFlow:()=>pe,createFunctionalMachine:()=>de,createMachine:()=>g,createMachineBuilder:()=>Le,createMachineContext:()=>Xe,createMachineFactory:()=>De,createMiddleware:()=>C,createMiddlewareFactory:()=>Ot,createMiddlewareRegistry:()=>mt,createMultiMachine:()=>ut,createMutableMachine:()=>Mt,createParallelMachine:()=>J,createPipeline:()=>Tt,createRunner:()=>Pe,createTransition:()=>Ge,createTransitionExtender:()=>ce,createTransitionFactory:()=>He,delegateToChild:()=>lt,describe:()=>Ee,extendTransitions:()=>W,guard:()=>j,guardAsync:()=>v,guarded:()=>Ae,hasState:()=>qe,inDevelopment:()=>gt,invoke:()=>Se,isConditionalMiddleware:()=>Et,isMiddlewareContext:()=>St,isMiddlewareError:()=>Ft,isMiddlewareFn:()=>ae,isMiddlewareHooks:()=>Rt,isMiddlewareOptions:()=>jt,isMiddlewareResult:()=>At,isNamedMiddleware:()=>vt,isPipelineConfig:()=>Pt,isState:()=>ke,logState:()=>_e,matchMachine:()=>Ue,mergeContext:()=>Ne,metadata:()=>ve,middlewareBuilder:()=>Oe,next:()=>Ye,overrideTransitions:()=>Ie,pipeTransitions:()=>ze,run:()=>D,runAsync:()=>Ce,runMachine:()=>H,runSequence:()=>fe,runWithDebug:()=>ge,runWithEnsemble:()=>dt,runWithRunner:()=>ct,setContext:()=>b,state:()=>$e,step:()=>xe,stepAsync:()=>me,toggle:()=>yt,transitionTo:()=>we,useActor:()=>Ze,useActorSelector:()=>et,useEnsemble:()=>Qe,useMachine:()=>Je,useMachineSelector:()=>Me,when:()=>_,whenContext:()=>Ct,whenGuard:()=>Re,whenGuardAsync:()=>je,withAnalytics:()=>Z,withDebugging:()=>Be,withErrorReporting:()=>ne,withHistory:()=>O,withLogging:()=>X,withPerformanceMonitoring:()=>re,withPermissions:()=>te,withRetry:()=>oe,withSnapshot:()=>B,withTimeTravel:()=>k,withValidation:()=>ee,yieldMachine:()=>he});module.exports=at(Bt);var ye=Symbol.for("__machine_transitions__");function S(e,t){return Object.defineProperty(e,ye,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[ye]}function R(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var T=class{constructor(t){this.context=t}};function D(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function xe(e){return function*(){return yield e}()}function he(e){return e}function fe(e,t){return t.reduce((n,r)=>D(r,n),e)}function pe(e){return e}function ge(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function Ce(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*me(e){return yield e}var be=Symbol("MachineMeta"),Te=Symbol("__machine_runtime_meta__");function E(e,t){let n=e[Te]||{},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,Te,{value:r,enumerable:!1,writable:!1,configurable:!0})}function we(e,t){return E(t,{target:e.name||e.toString()}),t}function Ee(e,t){return E(t,{description:e}),t}function Ae(e,t){return E(t,{guards:[e]}),t}function Se(e,t){return E(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function Fe(e,t){return E(t,{actions:[e]}),t}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(e(u,...d)){let l=c?this:{context:this};return t.apply(l,d)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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:a,enumerable:!1}),E(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function v(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,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 l=c?this:{context:this};return t.apply(l,d)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}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:a,enumerable:!1}),E(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function Re(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function je(e){return{do(t){let n=v(e,t);return n.else=function(r){return v(e,t,{onFail:r})},n}}}function ve(e,t){return t}function Pe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,d){let c=n[d];if(typeof c=="function")return(...u)=>{let y=c.apply(n,u),l=Object.assign({context:y.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function P(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),d=s[a];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>d.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function st(e,t){return function(r){return P(e,r,t)}}function ct(e,t){let n=Pe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function dt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var I=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function ut(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Mt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),d=s[i];if(typeof d=="function")return(...c)=>{let u=d.apply(s,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(o).forEach(y=>delete o[y]),Object.assign(o,u)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function lt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return b(this,{...this.context,child:r})}return this}}function yt(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.`),b(this,{...this.context,[e]:!this.context[e]})}}var V=class extends T{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},A=class extends T{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 U(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new L(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new q(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new Y(this.config));this.execute()}async execute(){}},L=class extends T{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new A(this.config,n!=null?n:this.params,this.context.attempts+1)}},U=class extends T{constructor(n,r){super(r);this.config=n;this.refetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},q=class extends T{constructor(n,r){super(r);this.config=n;this.retry=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}},Y=class extends T{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new A(this.config,n!=null?n:this.config.initialParams,1)}};function xt(e){return new V(e)}function J(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...d)=>{let c=s.apply(e,d);return J(c,t)}}for(let a in o){let s=o[a];i[a]=(...d)=>{let c=s.apply(t,d);return J(e,c)}}return{context:n,...i}}var Q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[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"&&(a[s]=function(...c){let u=s,y=a.context,l=()=>{let M;try{M=d.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:u,context:y,args:[...c],error:h})}catch(f){if(!r)throw f;o&&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 a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(M&&typeof M.then=="function")return M.then(f=>{if(x(f),t.after)try{let m=t.after({transitionName:u,prevContext:y,nextContext:f.context,args:[...c]});if(m&&typeof m.then=="function")return m.then(()=>f)}catch(m){if(!r)throw m;o&&console.error(`Middleware after hook error for ${u}:`,m),i==null||i(m,"after",{transitionName:u,prevContext:y,nextContext:f.context,args:c})}return f});if(x(M),t.after)try{let h=t.after({transitionName:u,prevContext:y,nextContext:M.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>M).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${u}:`,f),i==null||i(f,"after",{transitionName:u,prevContext:y,nextContext:M.context,args:c}),M})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${u}:`,h),i==null||i(h,"after",{transitionName:u,prevContext:y,nextContext:M.context,args:c})}return M};if(t.before)try{let M=t.before({transitionName:u,context:y,args:[...c]});if(M&&typeof M=="object"&&M&&"then"in M)return M.then(x=>x===Q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${u}:`,x),i==null||i(x,"before",{transitionName:u,context:y,args:c}),l()});if(M===Q)return a}catch(M){if(!r)throw M;o&&console.error(`Middleware before hook error for ${u}:`,M),i==null||i(M,"before",{transitionName:u,context:y,args:c})}return l()})}return a}function X(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function Z(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:d,args:c})=>{let u=`${r}.${a}`,y={transition:a};o&&(y.from=s),y.to=d,i&&(y.args=c),t(u,y)}})}function ee(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function te(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ne(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function re(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 i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function oe(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:i=2,onRetry:a}=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(...l){let M,x=0;for(;x<n;)try{return await y.apply(this,l)}catch(h){if(M=h,x++,x<n&&r(M,x)){a==null||a(M,x);let m=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(w=>setTimeout(w,m))}else throw M}throw M})}return s}function ht(e,t){return n=>C(n,e,t)}function O(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:d,args:c})=>{let u={id:`entry-${a++}`,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),n&&i.length>n&&i.shift(),o==null||o(u)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function B(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,d=C(e,{after:({transitionName:u,prevContext:y,nextContext:l})=>{if(i&&JSON.stringify(y)===JSON.stringify(l))return;let M={id:`snapshot-${s++}`,transitionName:u,before:{...y},after:{...l},timestamp:Date.now()};if(r)try{M.serializedBefore=r.serialize(y),M.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{M.diff=o(y,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(M),n&&a.length>n&&a.shift()}});return Object.assign(d,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:u=>{let y=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:u},y)}})}function k(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,d=0,c=C(e,{before:({transitionName:l,args:M})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...M],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(M)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:M,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:l,before:{...M},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(M),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,d=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,d=0},restoreSnapshot:l=>{let M=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:l},M)},replayFrom:l=>{var m;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let M=(m=a[l])==null?void 0:m.before;if(!M)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:M},Object.fromEntries(Object.entries(e).filter(([w])=>w!=="context"&&typeof e[w]=="function")));for(let w of x){let le=f[w.transitionName];le&&(f=le.apply(f,w.args))}return f}})}function ft(e,...t){return t.reduce((n,r)=>r(n),e)}function K(e,...t){return t.reduce((n,r)=>r(n),e)}var ie=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function pt(e){return new ie(e)}function _(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function gt(e){return _(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Ct(e,t,n){return _(n,r=>r.context[e]===t)}function mt(){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 i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.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 Tt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,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(a))continue;a=u.middleware(a)}else a=u(a)}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:a,errors:s,success:d}}}function bt(...e){return t=>K(t,...e)}function wt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ae(e){return typeof e=="function"&&e.length===1}function Et(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ae(e.middleware)&&typeof e.when=="function"}function At(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||N(e.prevContext,t)&&N(e.nextContext,t))}function St(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||N(e.context,t))}function Ft(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||N(e.context,t))}function Rt(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 jt(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 N(e,t){return e!==null&&typeof e=="object"}function vt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ae(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 Pt(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 z=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>X(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ee(r,t)),this}withPermissions(t){return this.middlewares.push(n=>te(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>re(r,t)),this}withRetry(t){return this.middlewares.push(n=>oe(n,t)),this}withHistory(t){return this.middlewares.push(n=>O(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>B(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>k(n,t)),this}withDebugging(){return this.middlewares.push(t=>Be(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(_(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 Oe(e){return new z(e)}function Ot(e={}){return{create:t=>{let n=Oe(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 Be(e){return k(B(O(e)))}function ke(e,t){return e instanceof t}function Ke(e,...t){return{type:e,args:t}}function Ne(e,t){return b(e,n=>({...n,...t}))}async function ze(e,...t){let n=e;for(let r of t)n=await r(n);return n}function _e(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Ge(e,t){return function(...n){let r=t(this.context,...n);return g(r,e())}}function We(e,t,...n){return e.apply(t,n)}function se(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?se(i):i}:r}})}var G=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"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function He(){return function(t){return function(...n){let r=t(this.context,...n);return g(r,this)}}}function ce(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return g(a,this)},o=W(e,{[t]:r});return ce(o)}}}function de(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let d=a(this.context,...s);return g(d,r)}]));return Object.assign(r,o),g(e,r)}}function $e(e,t){return t!==void 0?g(e,t):de(e)}function g(e,t){if(typeof t=="function"){let i,a;return a=t(d=>d===e?i:g(d,a)),i=S(Object.assign({context:e},a),a),i}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function ue(e,t){if(typeof t=="function"){let i;return i=t(s=>ue(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function De(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return g(i,t)}]));return n=>g(n,t)}}function b(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:R(e),o=typeof t=="function"?t(n):t;return g(o,r)}function Ie(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function W(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function Ve(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:d,...c}=o,u={...s,...c};return g(i,u)}}function Le(e){let{context:t,...n}=e;return r=>g(r,n)}function Ue(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 qe(e,t,n){return e.context[t]===n}function H(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.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)}}}function Ye(e,t){return b(e,n=>t(n))}var p=require("react");function Je(e){let[t,n]=(0,p.useState)(e),r=(0,p.useMemo)(()=>H(t,i=>{n(i)}),[]),o=(0,p.useMemo)(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function Me(e,t,n=Object.is){let[r,o]=(0,p.useState)(()=>t(e)),i=(0,p.useRef)(t),a=(0,p.useRef)(n);return i.current=t,a.current=n,(0,p.useEffect)(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function Qe(e,t,n){let[r,o]=(0,p.useState)(e),i=(0,p.useRef)(r);i.current=r;let a=(0,p.useMemo)(()=>({getContext:()=>i.current,setContext:d=>{o(d)}}),[]);return(0,p.useMemo)(()=>P(a,t,n),[a,t,n])}function Xe(){let e=(0,p.createContext)(null),t=({machine:a,actions:s,children:d})=>{let c=(0,p.useMemo)(()=>[a,s],[a,s]);return(0,p.createElement)(e.Provider,{value:c},d)},n=()=>{let a=(0,p.useContext)(e);if(!a)throw new Error("useMachineContext must be used within a Machine.Provider");return a},r=()=>n()[0];return{Provider:t,useMachineContext:n,useMachineState:r,useMachineActions:()=>n()[1],useSelector:(a,s)=>{let d=r();return Me(d,a,s)}}}function Ze(e){let t=(0,p.useMemo)(()=>e.subscribe.bind(e),[e]),n=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]);return(0,p.useSyncExternalStore)(t,n)}function et(e,t,n=Object.is){let r=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=(0,p.useState)(o);return(0,p.useEffect)(()=>{let s=()=>{let d=t(e.getSnapshot());a(c=>n(c,d)?c:d)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}
@@ -1597,12 +1597,14 @@ function state(context, transitions) {
1597
1597
  // src/index.ts
1598
1598
  function createMachine(context, fnsOrFactory) {
1599
1599
  if (typeof fnsOrFactory === "function") {
1600
+ let self;
1600
1601
  let transitions2;
1601
1602
  const transition = (newContext) => {
1602
- return createMachine(newContext, transitions2);
1603
+ return newContext === context ? self : createMachine(newContext, transitions2);
1603
1604
  };
1604
1605
  transitions2 = fnsOrFactory(transition);
1605
- return attachTransitions(Object.assign({ context }, transitions2), transitions2);
1606
+ self = attachTransitions(Object.assign({ context }, transitions2), transitions2);
1607
+ return self;
1606
1608
  }
1607
1609
  const stored = getStoredTransitions(fnsOrFactory);
1608
1610
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;