@doeixd/machine 0.0.23 → 1.0.1

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