@doeixd/machine 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function D(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ae(e){return function*(){return yield e}()}function se(e){return e}function ce(e,t){return t.reduce((n,r)=>D(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 Me=Symbol("MachineMeta"),I=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[I]||{},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,I,{value:r,enumerable:!1,writable:!1,configurable:!0})}function xe(e,t){return b(t,{target:e.name||e.toString()}),t}function he(e,t){return b(t,{description:e}),t}function fe(e,t){return b(t,{guards:[e]}),t}function pe(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 ge(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(...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 S(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 Ce(e){return{do(t){let n=F(e,t);return n.else=function(r){return F(e,t,{onFail:r})},n}}}function me(e){return{do(t){let n=S(e,t);return n.else=function(r){return S(e,t,{onFail:r})},n}}}function Te(e,t){return t}function be(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 we(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 Le(e,t){return function(r){return we(e,r,t)}}function Ve(e,t){let n=be(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ue(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var L=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function qe(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 Ye(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 R=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 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 j(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new P(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new O(this.config));this.execute()}async execute(){}},j=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)}},v=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)}},P=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)}},O=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 R(e)}function V(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 V(c,t)}}for(let a in o){let s=o[a];i[a]=(...l)=>{let c=s.apply(t,l);return V(e,c)}}return{context:n,...i}}var U=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 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 g=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"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===U?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===U)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 q(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 Y(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(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 J(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function Q(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function X(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 Z(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 ee(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 g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw y}throw y})}return s}function it(e,t){return n=>C(n,e,t)}function B(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(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 k(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,l=C(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 K(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,l=0,c=C(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 g;if(u<0||u>=i.length)throw new Error(`Invalid replay start index: ${u}`);let y=(g=a[u])==null?void 0:g.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 $=f[T.transitionName];$&&(f=$.apply(f,T.args))}return f}})}function pt(e,...t){return t.reduce((n,r)=>r(n),e)}function N(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 gt(e){return new z(e)}function _(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ct(e){return _(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function mt(e,t,n){return _(n,r=>r.context[e]===t)}function Tt(){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 N(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return N(t,...n.map(r=>r.middleware))}}}function bt(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 wt(...e){return t=>N(t,...e)}function Et(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function te(e){return typeof e=="function"&&e.length===1}function At(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&te(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||A(e.prevContext,t)&&A(e.nextContext,t))}function St(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||A(e.context,t))}function Rt(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||A(e.context,t))}function jt(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 A(e,t){return e!==null&&typeof e=="object"}function Pt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&te(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 Ot(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 G=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>q(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Y(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>J(r,t)),this}withPermissions(t){return this.middlewares.push(n=>Q(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>X(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>Z(r,t)),this}withRetry(t){return this.middlewares.push(n=>ee(n,t)),this}withHistory(t){return this.middlewares.push(n=>B(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>k(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>K(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(_(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 Ee(e){return new G(e)}function Bt(e={}){return{create:t=>{let n=Ee(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 K(k(B(e)))}function Fe(e,t){return e instanceof t}function Se(e,...t){return{type:e,args:t}}function Re(e,t){return E(e,n=>({...n,...t}))}async function je(e,...t){let n=e;for(let r of t)n=await r(n);return n}function ve(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 Oe(e,t,...n){return e.apply(t,n)}function ne(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?ne(i):i}:r}})}var W=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 Be(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function re(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=H(e,{[t]:r});return re(o)}}}function oe(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):oe(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 ie(e,t){if(typeof t=="function"){let o;return o=t(a=>ie(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 Ke(){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 Ne(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function H(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function ze(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 Ge(e){let{context:t,...n}=e;return r=>p(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 We(e,t,n){return e.context[t]===n}function He(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 $e(e,t){let{context:n,...r}=e;return p(t(n),r)}export{W as BoundMachine,U as CANCEL,Me as META_KEY,m as MachineBase,G as MiddlewareBuilder,L as MultiMachineBase,ge as action,ne as bindTransitions,Et as branch,Oe as call,gt as chain,wt as combine,ze as combineFactories,pt as compose,N as composeTyped,ie as createAsyncMachine,it as createCustomMiddleware,we as createEnsemble,Le as createEnsembleFactory,Se as createEvent,rt as createFetchMachine,de as createFlow,oe as createFunctionalMachine,p as createMachine,Ge as createMachineBuilder,Ke as createMachineFactory,C as createMiddleware,Bt as createMiddlewareFactory,Tt as createMiddlewareRegistry,qe as createMultiMachine,Ye as createMutableMachine,V as createParallelMachine,bt as createPipeline,be as createRunner,Pe as createTransition,re as createTransitionExtender,Be as createTransitionFactory,tt as delegateToChild,he as describe,H as extendTransitions,F as guard,S as guardAsync,fe as guarded,We as hasState,Ct as inDevelopment,pe as invoke,At as isConditionalMiddleware,St as isMiddlewareContext,Rt as isMiddlewareError,te as isMiddlewareFn,jt as isMiddlewareHooks,vt as isMiddlewareOptions,Ft as isMiddlewareResult,Pt as isNamedMiddleware,Ot as isPipelineConfig,Fe as isState,ve as logState,_e as matchMachine,Re as mergeContext,Te as metadata,Ee as middlewareBuilder,$e as next,Ne as overrideTransitions,je as pipeTransitions,D as run,le as runAsync,He as runMachine,ce as runSequence,ye as runWithDebug,Ue as runWithEnsemble,Ve as runWithRunner,E as setContext,ke as state,ae as step,ue as stepAsync,nt as toggle,xe as transitionTo,_ as when,mt as whenContext,Ce as whenGuard,me as whenGuardAsync,Y as withAnalytics,Ae as withDebugging,X as withErrorReporting,B as withHistory,q as withLogging,Z as withPerformanceMonitoring,Q as withPermissions,ee as withRetry,k as withSnapshot,K as withTimeTravel,J as withValidation,se as yieldMachine};
1
+ var V=Symbol.for("__machine_transitions__");function A(e,t){return Object.defineProperty(e,V,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[V]}function S(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function U(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ye(e){return function*(){return yield e}()}function ue(e){return e}function le(e,t){return t.reduce((n,r)=>U(r,n),e)}function Me(e){return e}function xe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*fe(e){return yield e}var pe=Symbol("MachineMeta"),q=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[q]||{},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,q,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,t){return b(t,{target:e.name||e.toString()}),t}function Ce(e,t){return b(t,{description:e}),t}function me(e,t){return b(t,{guards:[e]}),t}function Te(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 be(e,t){return b(t,{actions:[e]}),t}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function v(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function we(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Ee(e){return{do(t){let n=v(e,t);return n.else=function(r){return v(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,u){let c=n[u];if(typeof c=="function")return(...d)=>{let M=c.apply(n,d),l=Object.assign({context:M.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Se(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 Qe(e,t){return function(r){return Se(e,r,t)}}function Xe(e,t){let n=Fe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ze(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var Y=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function et(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 tt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),u=s[i];if(typeof u=="function")return(...c)=>{let d=u.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(M=>delete o[M]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function 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 P=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 B(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 O(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new k(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new K(this.config));this.execute()}async execute(){}},O=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)}},B=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)}},k=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)}},K=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 yt(e){return new P(e)}function J(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...u)=>{let c=s.apply(e,u);return J(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return J(e,c)}}return{context:n,...i}}var Q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let u=e[s];typeof u=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,M=a.context,l=()=>{let y;try{y=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:M,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:M,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(y&&typeof y.then=="function")return y.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"after",{transitionName:d,prevContext:M,nextContext:f.context,args:c})}return f});if(x(y),t.after)try{let h=t.after({transitionName:d,prevContext:M,nextContext:y.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>y).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c}),y})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c})}return y};if(t.before)try{let y=t.before({transitionName:d,context:M,args:[...c]});if(y&&typeof y=="object"&&y&&"then"in y)return y.then(x=>x===Q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:M,args:c}),l()});if(y===Q)return a}catch(y){if(!r)throw y;o&&console.error(`Middleware before hook error for ${d}:`,y),i==null||i(y,"before",{transitionName:d,context:M,args:c})}return l()})}return a}function X(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function Z(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:u,args:c})=>{let d=`${r}.${a}`,M={transition:a};o&&(M.from=s),M.to=u,i&&(M.args=c),t(d,M)}})}function ee(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function te(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ne(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function re(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function oe(e,t={}){var u,c;let{maxAttempts:n=(u=t.maxRetries)!=null?u:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let M=e[d];typeof M=="function"&&d!=="context"&&(s[d]=async function(...l){let y,x=0;for(;x<n;)try{return await M.apply(this,l)}catch(h){if(y=h,x++,x<n&&r(y,x)){a==null||a(y,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw y}throw y})}return s}function lt(e,t){return n=>C(n,e,t)}function N(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(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 z(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=C(e,{after:({transitionName:d,prevContext:M,nextContext:l})=>{if(i&&JSON.stringify(M)===JSON.stringify(l))return;let y={id:`snapshot-${s++}`,transitionName:d,before:{...M},after:{...l},timestamp:Date.now()};if(r)try{y.serializedBefore=r.serialize(M),y.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{y.diff=o(M,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(y),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let M=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:d},M)}})}function _(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=C(e,{before:({transitionName:l,args:y})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...y],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(y)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:y,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:l,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(y),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,u=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,u=0},restoreSnapshot:l=>{let y=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:l},y)},replayFrom:l=>{var g;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let y=(g=a[l])==null?void 0:g.before;if(!y)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:y},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let L=f[T.transitionName];L&&(f=L.apply(f,T.args))}return f}})}function Et(e,...t){return t.reduce((n,r)=>r(n),e)}function G(e,...t){return t.reduce((n,r)=>r(n),e)}var W=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 W(e)}function $(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ft(e){return $(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function St(e,t,n){return $(n,r=>r.context[e]===t)}function Rt(){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 G(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return G(t,...n.map(r=>r.middleware))}}}function jt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],u=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(M){if(u=!1,!t)throw M;s.push({error:M,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,M),r==null||r(M,c,d.name)}}return{machine:a,errors:s,success:u}}}function vt(...e){return t=>G(t,...e)}function Pt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ie(e){return typeof e=="function"&&e.length===1}function Ot(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ie(e.middleware)&&typeof e.when=="function"}function Bt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||R(e.prevContext,t)&&R(e.nextContext,t))}function kt(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||R(e.context,t))}function Kt(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||R(e.context,t))}function Nt(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function R(e,t){return e!==null&&typeof e=="object"}function _t(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ie(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 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)}var H=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>X(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ee(r,t)),this}withPermissions(t){return this.middlewares.push(n=>te(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>re(r,t)),this}withRetry(t){return this.middlewares.push(n=>oe(n,t)),this}withHistory(t){return this.middlewares.push(n=>N(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>z(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>_(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($(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 H(e)}function Wt(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 _(z(N(e)))}function ve(e,t){return e instanceof t}function Pe(e,...t){return{type:e,args:t}}function Oe(e,t){return E(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 p(r,e())}}function Ne(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 i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?ae(i):i}:r}})}var D=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 p(r,this)}}}function se(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=I(e,{[t]:r});return se(o)}}}function ce(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 _e(e,t){return t!==void 0?p(e,t):ce(e)}function p(e,t){if(typeof t=="function"){let i;return i=t(s=>p(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function de(e,t){if(typeof t=="function"){let i;return i=t(s=>de(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function Ge(){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){var i;let n=e.context,r=(i=F(e))!=null?i:S(e),o=typeof t=="function"?t(n):t;return p(o,r)}function We(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function I(e,t){let{context:n,...r}=e,o={...r,...t};return p(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 p(i,d)}}function $e(e){let{context:t,...n}=e;return r=>p(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 Ie(e,t,n){return e.context[t]===n}function Le(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Ve(e,t){return E(e,n=>t(n))}export{D as BoundMachine,Q as CANCEL,pe as META_KEY,m as MachineBase,H as MiddlewareBuilder,Y as MultiMachineBase,be as action,ae as bindTransitions,Pt as branch,Ne as call,At as chain,vt as combine,He as combineFactories,Et as compose,G as composeTyped,de as createAsyncMachine,lt as createCustomMiddleware,Se as createEnsemble,Qe as createEnsembleFactory,Pe as createEvent,yt as createFetchMachine,Me as createFlow,ce as createFunctionalMachine,p as createMachine,$e as createMachineBuilder,Ge as createMachineFactory,C as createMiddleware,Wt as createMiddlewareFactory,Rt as createMiddlewareRegistry,et as createMultiMachine,tt as createMutableMachine,J as createParallelMachine,jt as createPipeline,Fe as createRunner,Ke as createTransition,se as createTransitionExtender,ze as createTransitionFactory,ct as delegateToChild,Ce as describe,I as extendTransitions,j as guard,v as guardAsync,me as guarded,Ie as hasState,Ft as inDevelopment,Te as invoke,Ot as isConditionalMiddleware,kt as isMiddlewareContext,Kt as isMiddlewareError,ie as isMiddlewareFn,Nt as isMiddlewareHooks,zt as isMiddlewareOptions,Bt as isMiddlewareResult,_t as isNamedMiddleware,Gt as isPipelineConfig,ve as isState,ke as logState,De as matchMachine,Oe as mergeContext,Ae as metadata,Re as middlewareBuilder,Ve as next,We as overrideTransitions,Be as pipeTransitions,U as run,he as runAsync,Le as runMachine,le as runSequence,xe as runWithDebug,Ze as runWithEnsemble,Xe as runWithRunner,E as setContext,_e as state,ye as step,fe as stepAsync,dt as toggle,ge as transitionTo,$ as when,St as whenContext,we as whenGuard,Ee as whenGuardAsync,Z as withAnalytics,je as withDebugging,ne as withErrorReporting,N as withHistory,X as withLogging,re as withPerformanceMonitoring,te as withPermissions,oe as withRetry,z as withSnapshot,_ as withTimeTravel,ee as withValidation,ue as yieldMachine};
@@ -1,4 +1,4 @@
1
- function L(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)=>L(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 Ce=Symbol("MachineMeta"),q=Symbol("__machine_runtime_meta__");function b(e,n){let t=e[q]||{},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,q,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,n){return b(n,{target:e.name||e.toString()}),n}function me(e,n){return b(n,{description:e}),n}function Te(e,n){return b(n,{guards:[e]}),n}function be(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 we(e,n){return b(n,{actions:[e]}),n}function S(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 j(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 Ee(e){return{do(n){let t=S(e,n);return t.else=function(r){return S(e,n,{onFail:r})},t}}}function ve(e){return{do(n){let t=j(e,n);return t.else=function(r){return j(e,n,{onFail:r})},t}}}function Ae(e,n){return n}function Re(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 Fe(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 nn(e,n){return function(r){return Fe(e,r,n)}}function tn(e,n){let t=Re(n),r=e(t),o=r.next();for(;!o.done;)o=r.next();return o.value}function rn(e,n){let t=e(n),r=t.next();for(;!r.done;)r=t.next();return r.value}var J=class{constructor(n){this.store=n}get context(){return this.store.getContext()}setContext(n){this.store.setContext(n)}};function on(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 an(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 v(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.`),v(this,{...this.context,[e]:!this.context[e]})}}var P=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 k(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 O(this.config,this.params,t,this.context.attempts):((i=(a=this.config).onError)==null||i.call(a,t),new B(this.config,{status:"error",error:t}))};this.cancel=()=>(this.context.abortController.abort(),new _(this.config));this.execute()}async execute(){}},O=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)}},k=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)}},B=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)}},_=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 P(e)}function Y(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 Y(c,n)}}for(let i in o){let s=o[i];a[i]=(...d)=>{let c=s.apply(n,d);return Y(e,c)}}return{context:t,...a}}var Q=Symbol("CANCEL");function g(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 C=n.after({transitionName:u,prevContext:l,nextContext:p.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>p)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${u}:`,C),a==null||a(C,"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 X(e,n={}){let{logger:t=console.log,includeArgs:r=!1,includeContext:o=!0}=n;return g(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 Z(e,n,t={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=t;return g(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 ee(e,n){return g(e,{before:t=>{if(n(t)===!1)throw new Error(`Validation failed for transition: ${t.transitionName}`)}})}function ne(e,n){return g(e,{before:t=>{if(!n(t))throw new Error(`Unauthorized transition: ${t.transitionName}`)}})}function te(e,n,t={}){let{includeArgs:r=!1}=t;return g(e,{error:o=>{let a={transition:o.transitionName,context:o.context,...r&&{args:o.args}};n(o.error,a)}})}function re(e,n){let t=new Map;return g(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 oe(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 C=(typeof o=="function"?o(M):o)*Math.pow(a,M-1);await new Promise(T=>setTimeout(T,C))}else throw y}throw y})}return s}function pn(e,n){return t=>g(t,e,n)}function N(e,n={}){let{maxSize:t,serializer:r,onEntry:o}=n,a=[],i=0,s=g(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 K(e,n={}){let{maxSize:t,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=n,i=[],s=0,d=g(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 H(e,n={}){let{maxSize:t,serializer:r,onRecord:o}=n,a=[],i=[],s=0,d=0,c=g(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 C;if(x<0||x>=a.length)throw new Error(`Invalid replay start index: ${x}`);let y=(C=i[x])==null?void 0:C.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 V=p[T.transitionName];V&&(p=V.apply(p,T.args))}return p}})}function Fn(e,...n){return n.reduce((t,r)=>r(t),e)}function I(e,...n){return n.reduce((t,r)=>r(t),e)}var z=class e{constructor(n){this.machine=n}with(n){let t=n(this.machine);return new e(t)}build(){return this.machine}};function Sn(e){return new z(e)}function W(e,n){let t=function(r){return n(r)?e(r):r};return t.middleware=e,t.when=n,t}function jn(e){return W(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Pn(e,n,t){return W(t,r=>r.context[e]===n)}function On(){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 I(n,...r.map(o=>o.middleware))},applyAll(n){let t=this.list();return I(n,...t.map(r=>r.middleware))}}}function kn(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=>I(n,...e)}function _n(e,n){return t=>{for(let[r,o]of e)if(r(t))return o(t);return n?n(t):t}}function ae(e){return typeof e=="function"&&e.length===1}function Nn(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ae(e.middleware)&&typeof e.when=="function"}function Kn(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||A(e.prevContext,n)&&A(e.nextContext,n))}function Hn(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||A(e.context,n))}function In(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||A(e.context,n))}function zn(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 $n(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 A(e,n){return e!==null&&typeof e=="object"}function Wn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ae(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Dn(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=>X(t,n)),this}withAnalytics(n,t){return this.middlewares.push(r=>Z(r,n,t)),this}withValidation(n,t){return this.middlewares.push(r=>ee(r,n)),this}withPermissions(n){return this.middlewares.push(t=>ne(t,n)),this}withErrorReporting(n,t){return this.middlewares.push(r=>te(r,n,t)),this}withPerformanceMonitoring(n,t){return this.middlewares.push(r=>re(r,n)),this}withRetry(n){return this.middlewares.push(t=>oe(t,n)),this}withHistory(n){return this.middlewares.push(t=>N(t,n)),this}withSnapshot(n){return this.middlewares.push(t=>K(t,n)),this}withTimeTravel(n){return this.middlewares.push(t=>H(t,n)),this}withDebugging(){return this.middlewares.push(n=>je(n)),this}withCustom(n){return this.middlewares.push(n),this}withConditional(n,t){return this.middlewares.push(W(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 Se(e){return new $(e)}function Gn(e={}){return{create:n=>{let t=Se(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 je(e){return H(K(N(e)))}function D(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 Pe(...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=D(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 Oe(e,...n){class t extends m{constructor(a){super(a)}}let r=D(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=D(o.prototype);for(let i of Object.keys(a))Object.prototype.hasOwnProperty.call(t.prototype,i)&&delete t.prototype[i]}return t}function Ln(...e){let n=e.map(a=>a.constructor),t=e.map(a=>a.context),r=Object.assign({},...t),o=Pe(...n);return new o(r)}function qn(e,...n){let t=e.constructor,r=n.map(a=>a.constructor),o=Oe(t,...r);return new o(e.context)}function ke(e,n){return e instanceof n}function Be(e,...n){return{type:e,args:n}}function _e(e,n){return v(e,t=>({...t,...n}))}async function Ne(e,...n){let t=e;for(let r of n)t=await r(t);return t}function Ke(e,n){return n?console.log(n,e.context):console.log(e.context),e}function He(e,n){return function(...t){let r=n(this.context,...t);return f(r,e())}}function Ie(e,n,...t){return e.apply(n,t)}function ie(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?ie(a):a}:r}})}var G=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 ze(){return function(n){return function(...t){let r=n(this.context,...t);return f(r,this)}}}function se(e){return{machine:e,addTransition:function(n,t){let r=function(...a){let i=t(this.context,...a);return f(i,this)},o=de(e,{[n]:r});return se(o)}}}function ce(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 $e(e,n){return n!==void 0?f(e,n):ce(e)}function We(...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.
1
+ var J=Symbol.for("__machine_transitions__");function b(e,n){return Object.defineProperty(e,J,{value:n,enumerable:!1,configurable:!1}),e}function R(e){if(!(!e||typeof e!="object"))return e[J]}function S(e){if(!e||typeof e!="object")return{};let n=Object.entries(e).filter(([t,r])=>t!=="context"&&typeof r=="function");return Object.fromEntries(n)}var m=class{constructor(n){this.context=n}};function Q(e,n){let t=e(n),r=n;for(;;){let{value:o,done:a}=t.next(r);if(a)return o;r=o}}function he(e){return function*(){return yield e}()}function pe(e){return e}function fe(e,n){return n.reduce((t,r)=>Q(r,t),e)}function Ce(e){return e}function ge(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 me(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*Te(e){return yield e}var be=Symbol("MachineMeta"),X=Symbol("__machine_runtime_meta__");function w(e,n){let t=e[X]||{},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,X,{value:r,enumerable:!1,writable:!1,configurable:!0})}function we(e,n){return w(n,{target:e.name||e.toString()}),n}function Ee(e,n){return w(n,{description:e}),n}function ve(e,n){return w(n,{guards:[e]}),n}function Ae(e,n){return w(n,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),n}function Re(e,n){return w(n,{actions:[e]}),n}function O(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}),w(s,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),s}function k(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}),w(s,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),s}function Se(e){return{do(n){let t=O(e,n);return t.else=function(r){return O(e,n,{onFail:r})},t}}}function Fe(e){return{do(n){let t=k(e,n);return t.else=function(r){return k(e,n,{onFail:r})},t}}}function je(e,n){return n}function Pe(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 Oe(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 cn(e,n){return function(r){return Oe(e,r,n)}}function dn(e,n){let t=Pe(n),r=e(t),o=r.next();for(;!o.done;)o=r.next();return o.value}function un(e,n){let t=e(n),r=t.next();for(;!r.done;)r=t.next();return r.value}var Z=class{constructor(n){this.store=n}get context(){return this.store.getContext()}setContext(n){this.store.setContext(n)}};function yn(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 ln(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 gn(e){return function(...n){let t=this.context.child;if(typeof t[e]=="function"){let r=t[e](...n);return v(this,{...this.context,child:r})}return this}}function mn(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),v(this,{...this.context,[e]:!this.context[e]})}}var _=class extends m{constructor(t){super({status:"idle"});this.config=t;this.fetch=t=>new E(this.config,t!=null?t:this.config.initialParams,1)}},E=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 N(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 B(this.config,this.params,t,this.context.attempts):((i=(a=this.config).onError)==null||i.call(a,t),new K(this.config,{status:"error",error:t}))};this.cancel=()=>(this.context.abortController.abort(),new H(this.config));this.execute()}async execute(){}},B=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 E(this.config,t!=null?t:this.params,this.context.attempts+1)}},N=class extends m{constructor(t,r){super(r);this.config=t;this.refetch=t=>new E(this.config,t!=null?t:this.config.initialParams,1)}},K=class extends m{constructor(t,r){super(r);this.config=t;this.retry=t=>new E(this.config,t!=null?t:this.config.initialParams,1)}},H=class extends m{constructor(t){super({status:"canceled"});this.config=t;this.refetch=t=>new E(this.config,t!=null?t:this.config.initialParams,1)}};function Tn(e){return new _(e)}function ee(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 ee(c,n)}}for(let i in o){let s=o[i];a[i]=(...d)=>{let c=s.apply(n,d);return ee(e,c)}}return{context:t,...a}}var ne=Symbol("CANCEL");function g(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 C=n.after({transitionName:u,prevContext:l,nextContext:p.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>p)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${u}:`,C),a==null||a(C,"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===ne?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===ne)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 te(e,n={}){let{logger:t=console.log,includeArgs:r=!1,includeContext:o=!0}=n;return g(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 re(e,n,t={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=t;return g(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 oe(e,n){return g(e,{before:t=>{if(n(t)===!1)throw new Error(`Validation failed for transition: ${t.transitionName}`)}})}function ae(e,n){return g(e,{before:t=>{if(!n(t))throw new Error(`Unauthorized transition: ${t.transitionName}`)}})}function ie(e,n,t={}){let{includeArgs:r=!1}=t;return g(e,{error:o=>{let a={transition:o.transitionName,context:o.context,...r&&{args:o.args}};n(o.error,a)}})}function se(e,n){let t=new Map;return g(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 ce(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 C=(typeof o=="function"?o(M):o)*Math.pow(a,M-1);await new Promise(T=>setTimeout(T,C))}else throw y}throw y})}return s}function wn(e,n){return t=>g(t,e,n)}function I(e,n={}){let{maxSize:t,serializer:r,onEntry:o}=n,a=[],i=0,s=g(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 z(e,n={}){let{maxSize:t,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=n,i=[],s=0,d=g(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 $(e,n={}){let{maxSize:t,serializer:r,onRecord:o}=n,a=[],i=[],s=0,d=0,c=g(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 C;if(x<0||x>=a.length)throw new Error(`Invalid replay start index: ${x}`);let y=(C=i[x])==null?void 0:C.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 Y=p[T.transitionName];Y&&(p=Y.apply(p,T.args))}return p}})}function Bn(e,...n){return n.reduce((t,r)=>r(t),e)}function W(e,...n){return n.reduce((t,r)=>r(t),e)}var D=class e{constructor(n){this.machine=n}with(n){let t=n(this.machine);return new e(t)}build(){return this.machine}};function Nn(e){return new D(e)}function U(e,n){let t=function(r){return n(r)?e(r):r};return t.middleware=e,t.when=n,t}function Kn(e){return U(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Hn(e,n,t){return U(t,r=>r.context[e]===n)}function In(){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 W(n,...r.map(o=>o.middleware))},applyAll(n){let t=this.list();return W(n,...t.map(r=>r.middleware))}}}function zn(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 $n(...e){return n=>W(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 de(e){return typeof e=="function"&&e.length===1}function Dn(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&de(e.middleware)&&typeof e.when=="function"}function Gn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||F(e.prevContext,n)&&F(e.nextContext,n))}function Un(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||F(e.context,n))}function Vn(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||F(e.context,n))}function Ln(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 qn(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 F(e,n){return e!==null&&typeof e=="object"}function Yn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&de(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 Jn(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 G=class{constructor(n){this.machine=n;this.middlewares=[]}withLogging(n){return this.middlewares.push(t=>te(t,n)),this}withAnalytics(n,t){return this.middlewares.push(r=>re(r,n,t)),this}withValidation(n,t){return this.middlewares.push(r=>oe(r,n)),this}withPermissions(n){return this.middlewares.push(t=>ae(t,n)),this}withErrorReporting(n,t){return this.middlewares.push(r=>ie(r,n,t)),this}withPerformanceMonitoring(n,t){return this.middlewares.push(r=>se(r,n)),this}withRetry(n){return this.middlewares.push(t=>ce(t,n)),this}withHistory(n){return this.middlewares.push(t=>I(t,n)),this}withSnapshot(n){return this.middlewares.push(t=>z(t,n)),this}withTimeTravel(n){return this.middlewares.push(t=>$(t,n)),this}withDebugging(){return this.middlewares.push(n=>_e(n)),this}withCustom(n){return this.middlewares.push(n),this}withConditional(n,t){return this.middlewares.push(U(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 ke(e){return new G(e)}function Qn(e={}){return{create:n=>{let t=ke(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 _e(e){return $(z(I(e)))}function V(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 Be(...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=V(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 Ne(e,...n){class t extends m{constructor(a){super(a)}}let r=V(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=V(o.prototype);for(let i of Object.keys(a))Object.prototype.hasOwnProperty.call(t.prototype,i)&&delete t.prototype[i]}return t}function et(...e){let n=e.map(a=>a.constructor),t=e.map(a=>a.context),r=Object.assign({},...t),o=Be(...n);return new o(r)}function nt(e,...n){let t=e.constructor,r=n.map(a=>a.constructor),o=Ne(t,...r);return new o(e.context)}function Ke(e,n){return e instanceof n}function He(e,...n){return{type:e,args:n}}function Ie(e,n){return v(e,t=>({...t,...n}))}async function ze(e,...n){let t=e;for(let r of n)t=await r(t);return t}function $e(e,n){return n?console.log(n,e.context):console.log(e.context),e}function We(e,n){return function(...t){let r=n(this.context,...t);return f(r,e())}}function De(e,n,...t){return e.apply(n,t)}function ue(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?ue(a):a}:r}})}var L=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 Ge(){return function(n){return function(...t){let r=n(this.context,...t);return f(r,this)}}}function ye(e){return{machine:e,addTransition:function(n,t){let r=function(...a){let i=t(this.context,...a);return f(i,this)},o=xe(e,{[n]:r});return ye(o)}}}function le(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 Ue(e,n){return n!==void 0?f(e,n):le(e)}function Ve(...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
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:t,when:a,case:r,exhaustive:o})}function De(e,n){return[e,void 0,t=>t instanceof n]}function Ge(e,n,t){return[e,void 0,r=>U(r,n,t)]}function Ue(e,n){return[e,void 0,n]}function Ve(){return{case(e,n,t){return[e,void 0,r=>U(r,n,t)]}}}var E=class E{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){E._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(E._inspector&&E._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))}};E._inspector=null;var R=E;function F(e){return new R(e)}function Le(e){return F(e)}function qe(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=F(t);return e().then(o=>r.send.resolve(o)).catch(o=>r.send.reject(o)),r}function Je(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=F(t);return e.subscribe(o=>r.send.next(o),o=>r.send.error(o),()=>r.send.complete()),r}function ue(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 ue(d,t)}]));return Object.assign({context:e},r)}function Ye(e,n,...t){let r=e[n],o={context:e.context};return r.apply(o,t)}function Qe(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 Xe(e,n){if(typeof n=="function"){let o;return o=n(i=>Xe(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 gt(){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 v(e,n){let{context:t,...r}=e,o=typeof n=="function"?n(t):n;return f(o,r)}function mt(e){return{context:e}}function Tt(e,n){let{context:t,...r}=e,o={...r,...n};return f(t,o)}function de(e,n){let{context:t,...r}=e,o={...r,...n};return f(t,o)}function bt(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 wt(e){let{context:n,...t}=e;return r=>f(r,t)}function Et(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 U(e,n,t){return e.context[n]===t}function vt(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 At(e,n){let{context:t,...r}=e;return f(n(t),r)}export{R as Actor,G as BoundMachine,Q as CANCEL,Ce as META_KEY,m as MachineBase,Oe as MachineExclude,Pe as MachineUnion,$ as MiddlewareBuilder,J as MultiMachineBase,we as action,ie as bindTransitions,_n as branch,Ie as call,Ye as callWithContext,Sn as chain,De as classCase,Bn as combine,bt as combineFactories,Fn as compose,I as composeTyped,F as createActor,Xe as createAsyncMachine,mt as createContext,ue as createContextBoundMachine,pn as createCustomMiddleware,Fe as createEnsemble,nn as createEnsembleFactory,Be as createEvent,Mn as createFetchMachine,Me as createFlow,ce as createFunctionalMachine,f as createMachine,wt as createMachineBuilder,gt as createMachineFactory,We as createMatcher,g as createMiddleware,Gn as createMiddlewareFactory,On as createMiddlewareRegistry,on as createMultiMachine,an as createMutableMachine,Y as createParallelMachine,kn as createPipeline,Re as createRunner,He as createTransition,se as createTransitionExtender,ze as createTransitionFactory,Ue as customCase,ln as delegateToChild,me as describe,Ge as discriminantCase,de as extendTransitions,Ve as forContext,Je as fromObservable,qe as fromPromise,S as guard,j as guardAsync,Te as guarded,U as hasState,jn as inDevelopment,be as invoke,Nn as isConditionalMiddleware,Qe as isContextBound,Hn as isMiddlewareContext,In as isMiddlewareError,ae as isMiddlewareFn,zn as isMiddlewareHooks,$n as isMiddlewareOptions,Kn as isMiddlewareResult,Wn as isNamedMiddleware,Dn as isPipelineConfig,ke as isState,Ke as logState,qn as machineExclude,Ln as machineUnion,Et as matchMachine,_e as mergeContext,Ae as metadata,Se as middlewareBuilder,At as next,Tt as overrideTransitions,Ne as pipeTransitions,L as run,pe as runAsync,vt as runMachine,xe as runSequence,he as runWithDebug,rn as runWithEnsemble,tn as runWithRunner,v as setContext,Le as spawn,$e as state,ye as step,fe as stepAsync,xn as toggle,ge as transitionTo,W as when,Pn as whenContext,Ee as whenGuard,ve as whenGuardAsync,Z as withAnalytics,je as withDebugging,te as withErrorReporting,N as withHistory,X as withLogging,re as withPerformanceMonitoring,ne as withPermissions,oe as withRetry,K as withSnapshot,H as withTimeTravel,ee as withValidation,le as yieldMachine};
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 Le(e,n){return[e,void 0,t=>t instanceof n]}function qe(e,n,t){return[e,void 0,r=>q(r,n,t)]}function Ye(e,n){return[e,void 0,n]}function Je(){return{case(e,n,t){return[e,void 0,r=>q(r,n,t)]}}}var A=class A{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){A._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(A._inspector&&A._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))}};A._inspector=null;var j=A;function P(e){return new j(e)}function Qe(e){return P(e)}function Xe(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=P(t);return e().then(o=>r.send.resolve(o)).catch(o=>r.send.reject(o)),r}function Ze(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=P(t);return e.subscribe(o=>r.send.next(o),o=>r.send.error(o),()=>r.send.complete()),r}function Me(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 Me(d,t)}]));return Object.values(r).forEach(o=>{typeof o=="function"&&Object.defineProperty(o,"__contextBound",{value:!0,enumerable:!1})}),b(Object.assign({context:e},r),r)}function en(e,n,...t){let r=e[n],o={context:e.context};return r.apply(o,t)}function nn(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 a;return a=n(s=>f(s,a)),b(Object.assign({context:e},a),a)}let t=R(n),r=t!=null?t:"context"in n?S(n):n,o=Object.assign({context:e},r);return b(o,r)}function tn(e,n){if(typeof n=="function"){let a;return a=n(s=>tn(s,a)),b(Object.assign({context:e},a),a)}let t=R(n),r=t!=null?t:"context"in n?S(n):n,o=Object.assign({context:e},r);return b(o,r)}function St(){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 v(e,n){var a;let t=e.context,r=(a=R(e))!=null?a:S(e),o=typeof n=="function"?n(t):n;return f(o,r)}function Ft(e){return{context:e}}function jt(e,n){let{context:t,...r}=e,o={...r,...n};return f(t,o)}function xe(e,n){let{context:t,...r}=e,o={...r,...n};return f(t,o)}function Pt(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 Ot(e){let{context:n,...t}=e;return r=>f(r,t)}function kt(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 q(e,n,t){return e.context[n]===t}function _t(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)}}}function Bt(e,n){return v(e,t=>n(t))}export{j as Actor,L as BoundMachine,ne as CANCEL,be as META_KEY,m as MachineBase,Ne as MachineExclude,Be as MachineUnion,G as MiddlewareBuilder,Z as MultiMachineBase,Re as action,ue as bindTransitions,Wn as branch,De as call,en as callWithContext,Nn as chain,Le as classCase,$n as combine,Pt as combineFactories,Bn as compose,W as composeTyped,P as createActor,tn as createAsyncMachine,Ft as createContext,Me as createContextBoundMachine,wn as createCustomMiddleware,Oe as createEnsemble,cn as createEnsembleFactory,He as createEvent,Tn as createFetchMachine,Ce as createFlow,le as createFunctionalMachine,f as createMachine,Ot as createMachineBuilder,St as createMachineFactory,Ve as createMatcher,g as createMiddleware,Qn as createMiddlewareFactory,In as createMiddlewareRegistry,yn as createMultiMachine,ln as createMutableMachine,ee as createParallelMachine,zn as createPipeline,Pe as createRunner,We as createTransition,ye as createTransitionExtender,Ge as createTransitionFactory,Ye as customCase,gn as delegateToChild,Ee as describe,qe as discriminantCase,xe as extendTransitions,Je as forContext,Ze as fromObservable,Xe as fromPromise,O as guard,k as guardAsync,ve as guarded,q as hasState,Kn as inDevelopment,Ae as invoke,Dn as isConditionalMiddleware,nn as isContextBound,Un as isMiddlewareContext,Vn as isMiddlewareError,de as isMiddlewareFn,Ln as isMiddlewareHooks,qn as isMiddlewareOptions,Gn as isMiddlewareResult,Yn as isNamedMiddleware,Jn as isPipelineConfig,Ke as isState,$e as logState,nt as machineExclude,et as machineUnion,kt as matchMachine,Ie as mergeContext,je as metadata,ke as middlewareBuilder,Bt as next,jt as overrideTransitions,ze as pipeTransitions,Q as run,me as runAsync,_t as runMachine,fe as runSequence,ge as runWithDebug,un as runWithEnsemble,dn as runWithRunner,v as setContext,Qe as spawn,Ue as state,he as step,Te as stepAsync,mn as toggle,we as transitionTo,U as when,Hn as whenContext,Se as whenGuard,Fe as whenGuardAsync,re as withAnalytics,_e as withDebugging,ie as withErrorReporting,I as withHistory,te as withLogging,se as withPerformanceMonitoring,ae as withPermissions,ce as withRetry,z as withSnapshot,$ as withTimeTravel,oe as withValidation,pe as yieldMachine};
@@ -1 +1 @@
1
- function q(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function le(e){return function*(){return yield e}()}function xe(e){return e}function he(e,t){return t.reduce((n,r)=>q(r,n),e)}function fe(e){return e}function pe(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 ge(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*Ce(e){return yield e}var me=Symbol("MachineMeta"),Y=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[Y]||{},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,Y,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Te(e,t){return w(t,{target:e.name||e.toString()}),t}function be(e,t){return w(t,{description:e}),t}function we(e,t){return w(t,{guards:[e]}),t}function Ee(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 Ae(e,t){return w(t,{actions:[e]}),t}function R(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let 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 j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let 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 Se(e){return{do(t){let n=R(e,t);return n.else=function(r){return R(e,t,{onFail:r})},n}}}function Fe(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Re(e,t){return t}function je(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 v(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 it(e,t){return function(r){return v(e,r,t)}}function at(e,t){let n=je(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function st(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var J=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function ct(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 dt(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 ht(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 ft(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 P=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new B(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 O(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new k(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new K(this.config));this.execute()}async execute(){}},O=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},B=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},k=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},K=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function pt(e){return new P(e)}function Q(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 Q(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return Q(e,c)}}return{context:n,...i}}var X=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 g=t.after({transitionName:d,prevContext:l,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"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===X?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===X)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 Z(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 ee(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 te(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ne(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function re(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 oe(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 ie(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 g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,g))}else throw M}throw M})}return s}function Ct(e,t){return n=>C(n,e,t)}function N(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 z(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 _(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 g;if(y<0||y>=i.length)throw new Error(`Invalid replay start index: ${y}`);let M=(g=a[y])==null?void 0:g.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 U=f[b.transitionName];U&&(f=U.apply(f,b.args))}return f}})}function Pt(e,...t){return t.reduce((n,r)=>r(n),e)}function G(e,...t){return t.reduce((n,r)=>r(n),e)}var W=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function Ot(e){return new W(e)}function $(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Bt(e){return $(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function kt(e,t,n){return $(n,r=>r.context[e]===t)}function Kt(){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 G(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return G(t,...n.map(r=>r.middleware))}}}function Nt(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 zt(...e){return t=>G(t,...e)}function _t(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ae(e){return typeof e=="function"&&e.length===1}function Gt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ae(e.middleware)&&typeof e.when=="function"}function Wt(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||S(e.prevContext,t)&&S(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||S(e.context,t))}function $t(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||S(e.context,t))}function Dt(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 S(e,t){return e!==null&&typeof e=="object"}function It(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ae(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Lt(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 H=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>Z(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>ee(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>te(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ne(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>re(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>oe(r,t)),this}withRetry(t){return this.middlewares.push(n=>ie(n,t)),this}withHistory(t){return this.middlewares.push(n=>N(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>z(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>_(n,t)),this}withDebugging(){return this.middlewares.push(t=>Pe(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push($(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function ve(e){return new H(e)}function Ut(e={}){return{create:t=>{let n=ve(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 Pe(e){return _(z(N(e)))}function Oe(e,t){return e instanceof t}function Be(e,...t){return{type:e,args:t}}function ke(e,t){return A(e,n=>({...n,...t}))}async function Ke(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Ne(e,t){return t?console.log(t,e.context):console.log(e.context),e}function ze(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function _e(e,t,...n){return e.apply(t,n)}function se(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?se(i):i}:r}})}var D=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 Ge(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function ce(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=V(e,{[t]:r});return ce(o)}}}function de(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let u=a(this.context,...s);return p(u,r)}]));return Object.assign(r,o),p(e,r)}}function We(e,t){return t!==void 0?p(e,t):de(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 ue(e,t){if(typeof t=="function"){let o;return o=t(a=>ue(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 He(){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 A(e,t){let{context:n,...r}=e,o=typeof t=="function"?t(n):t;return p(o,r)}function $e(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function V(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function De(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 Ve(e){let{context:t,...n}=e;return r=>p(r,n)}function Ie(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Le(e,t,n){return e.context[t]===n}function I(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 Ue(e,t){let{context:n,...r}=e;return p(t(n),r)}import{useState as F,useRef as L,useEffect as Me,useMemo as T,createContext as qe,useContext as Ye,createElement as Je,useSyncExternalStore as Qe}from"react";function Xe(e){let[t,n]=F(e),r=T(()=>I(t,i=>{n(i)}),[]),o=T(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function ye(e,t,n=Object.is){let[r,o]=F(()=>t(e)),i=L(t),a=L(n);return i.current=t,a.current=n,Me(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function Ze(e,t,n){let[r,o]=F(e),i=L(r);i.current=r;let a=T(()=>({getContext:()=>i.current,setContext:u=>{o(u)}}),[]);return T(()=>v(a,t,n),[a,t,n])}function et(){let e=qe(null),t=({machine:a,actions:s,children:u})=>{let c=T(()=>[a,s],[a,s]);return Je(e.Provider,{value:c},u)},n=()=>{let a=Ye(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 ye(u,a,s)}}}function tt(e){let t=T(()=>e.subscribe.bind(e),[e]),n=T(()=>e.getSnapshot.bind(e),[e]);return Qe(t,n)}function nt(e,t,n=Object.is){let r=T(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=F(o);return Me(()=>{let s=()=>{let u=t(e.getSnapshot());a(c=>n(c,u)?c:u)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}export{D as BoundMachine,X as CANCEL,me as META_KEY,m as MachineBase,H as MiddlewareBuilder,J as MultiMachineBase,Ae as action,se as bindTransitions,_t as branch,_e as call,Ot as chain,zt as combine,De as combineFactories,Pt as compose,G as composeTyped,ue as createAsyncMachine,Ct as createCustomMiddleware,v as createEnsemble,it as createEnsembleFactory,Be as createEvent,pt as createFetchMachine,fe as createFlow,de as createFunctionalMachine,p as createMachine,Ve as createMachineBuilder,et as createMachineContext,He as createMachineFactory,C as createMiddleware,Ut as createMiddlewareFactory,Kt as createMiddlewareRegistry,ct as createMultiMachine,dt as createMutableMachine,Q as createParallelMachine,Nt as createPipeline,je as createRunner,ze as createTransition,ce as createTransitionExtender,Ge as createTransitionFactory,ht as delegateToChild,be as describe,V as extendTransitions,R as guard,j as guardAsync,we as guarded,Le as hasState,Bt as inDevelopment,Ee as invoke,Gt as isConditionalMiddleware,Ht as isMiddlewareContext,$t as isMiddlewareError,ae as isMiddlewareFn,Dt as isMiddlewareHooks,Vt as isMiddlewareOptions,Wt as isMiddlewareResult,It as isNamedMiddleware,Lt as isPipelineConfig,Oe as isState,Ne as logState,Ie as matchMachine,ke as mergeContext,Re as metadata,ve as middlewareBuilder,Ue as next,$e as overrideTransitions,Ke as pipeTransitions,q as run,ge as runAsync,I as runMachine,he as runSequence,pe as runWithDebug,st as runWithEnsemble,at as runWithRunner,A as setContext,We as state,le as step,Ce as stepAsync,ft as toggle,Te as transitionTo,tt as useActor,nt as useActorSelector,Ze as useEnsemble,Xe as useMachine,ye as useMachineSelector,$ as when,kt as whenContext,Se as whenGuard,Fe as whenGuardAsync,ee as withAnalytics,Pe as withDebugging,re as withErrorReporting,N as withHistory,Z as withLogging,oe as withPerformanceMonitoring,ne as withPermissions,ie as withRetry,z as withSnapshot,_ as withTimeTravel,te as withValidation,xe as yieldMachine};
1
+ var Q=Symbol.for("__machine_transitions__");function S(e,t){return Object.defineProperty(e,Q,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[Q]}function R(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function X(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function pe(e){return function*(){return yield e}()}function ge(e){return e}function Ce(e,t){return t.reduce((n,r)=>X(r,n),e)}function me(e){return e}function Te(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 be(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*we(e){return yield e}var Ee=Symbol("MachineMeta"),Z=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[Z]||{},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,Z,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ae(e,t){return w(t,{target:e.name||e.toString()}),t}function Se(e,t){return w(t,{description:e}),t}function Fe(e,t){return w(t,{guards:[e]}),t}function Re(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 je(e,t){return w(t,{actions:[e]}),t}function P(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 O(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 ve(e){return{do(t){let n=P(e,t);return n.else=function(r){return P(e,t,{onFail:r})},n}}}function Pe(e){return{do(t){let n=O(e,t);return n.else=function(r){return O(e,t,{onFail:r})},n}}}function Oe(e,t){return t}function Be(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 B(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 Mt(e,t){return function(r){return B(e,r,t)}}function yt(e,t){let n=Be(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function lt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var ee=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function xt(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 ht(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 bt(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 wt(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 k=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new N(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 K(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new z(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new _(this.config));this.execute()}async execute(){}},K=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},N=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},z=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},_=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function Et(e){return new k(e)}function te(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 te(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return te(e,c)}}return{context:n,...i}}var ne=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 g=t.after({transitionName:d,prevContext:l,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"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===ne?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===ne)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 re(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 oe(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 ie(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ae(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function se(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 ce(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 de(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 g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,g))}else throw M}throw M})}return s}function St(e,t){return n=>C(n,e,t)}function G(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 W(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 H(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 g;if(y<0||y>=i.length)throw new Error(`Invalid replay start index: ${y}`);let M=(g=a[y])==null?void 0:g.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 J=f[b.transitionName];J&&(f=J.apply(f,b.args))}return f}})}function _t(e,...t){return t.reduce((n,r)=>r(n),e)}function $(e,...t){return t.reduce((n,r)=>r(n),e)}var D=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function Gt(e){return new D(e)}function V(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Wt(e){return V(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Ht(e,t,n){return V(n,r=>r.context[e]===t)}function $t(){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 $(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return $(t,...n.map(r=>r.middleware))}}}function Dt(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 It(...e){return t=>$(t,...e)}function Vt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ue(e){return typeof e=="function"&&e.length===1}function Lt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ue(e.middleware)&&typeof e.when=="function"}function Ut(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||j(e.prevContext,t)&&j(e.nextContext,t))}function qt(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||j(e.context,t))}function Yt(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||j(e.context,t))}function Jt(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 Qt(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 j(e,t){return e!==null&&typeof e=="object"}function Xt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ue(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 Zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var I=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>re(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>oe(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ie(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ae(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>se(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ce(r,t)),this}withRetry(t){return this.middlewares.push(n=>de(n,t)),this}withHistory(t){return this.middlewares.push(n=>G(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>W(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>H(n,t)),this}withDebugging(){return this.middlewares.push(t=>Ke(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(V(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 ke(e){return new I(e)}function en(e={}){return{create:t=>{let n=ke(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 Ke(e){return H(W(G(e)))}function Ne(e,t){return e instanceof t}function ze(e,...t){return{type:e,args:t}}function _e(e,t){return A(e,n=>({...n,...t}))}async function Ge(e,...t){let n=e;for(let r of t)n=await r(n);return n}function We(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 p(r,e())}}function $e(e,t,...n){return e.apply(t,n)}function Me(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?Me(i):i}:r}})}var L=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 De(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function ye(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=U(e,{[t]:r});return ye(o)}}}function le(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 Ie(e,t){return t!==void 0?p(e,t):le(e)}function p(e,t){if(typeof t=="function"){let i;return i=t(s=>p(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function xe(e,t){if(typeof t=="function"){let i;return i=t(s=>xe(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function Ve(){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 A(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:R(e),o=typeof t=="function"?t(n):t;return p(o,r)}function Le(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function U(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function Ue(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 qe(e){let{context:t,...n}=e;return r=>p(r,n)}function Ye(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 Je(e,t,n){return e.context[t]===n}function q(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Qe(e,t){return A(e,n=>t(n))}import{useState as v,useRef as Y,useEffect as he,useMemo as T,createContext as Xe,useContext as Ze,createElement as et,useSyncExternalStore as tt}from"react";function nt(e){let[t,n]=v(e),r=T(()=>q(t,i=>{n(i)}),[]),o=T(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function fe(e,t,n=Object.is){let[r,o]=v(()=>t(e)),i=Y(t),a=Y(n);return i.current=t,a.current=n,he(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function rt(e,t,n){let[r,o]=v(e),i=Y(r);i.current=r;let a=T(()=>({getContext:()=>i.current,setContext:u=>{o(u)}}),[]);return T(()=>B(a,t,n),[a,t,n])}function ot(){let e=Xe(null),t=({machine:a,actions:s,children:u})=>{let c=T(()=>[a,s],[a,s]);return et(e.Provider,{value:c},u)},n=()=>{let a=Ze(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 fe(u,a,s)}}}function it(e){let t=T(()=>e.subscribe.bind(e),[e]),n=T(()=>e.getSnapshot.bind(e),[e]);return tt(t,n)}function at(e,t,n=Object.is){let r=T(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=v(o);return he(()=>{let s=()=>{let u=t(e.getSnapshot());a(c=>n(c,u)?c:u)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}export{L as BoundMachine,ne as CANCEL,Ee as META_KEY,m as MachineBase,I as MiddlewareBuilder,ee as MultiMachineBase,je as action,Me as bindTransitions,Vt as branch,$e as call,Gt as chain,It as combine,Ue as combineFactories,_t as compose,$ as composeTyped,xe as createAsyncMachine,St as createCustomMiddleware,B as createEnsemble,Mt as createEnsembleFactory,ze as createEvent,Et as createFetchMachine,me as createFlow,le as createFunctionalMachine,p as createMachine,qe as createMachineBuilder,ot as createMachineContext,Ve as createMachineFactory,C as createMiddleware,en as createMiddlewareFactory,$t as createMiddlewareRegistry,xt as createMultiMachine,ht as createMutableMachine,te as createParallelMachine,Dt as createPipeline,Be as createRunner,He as createTransition,ye as createTransitionExtender,De as createTransitionFactory,bt as delegateToChild,Se as describe,U as extendTransitions,P as guard,O as guardAsync,Fe as guarded,Je as hasState,Wt as inDevelopment,Re as invoke,Lt as isConditionalMiddleware,qt as isMiddlewareContext,Yt as isMiddlewareError,ue as isMiddlewareFn,Jt as isMiddlewareHooks,Qt as isMiddlewareOptions,Ut as isMiddlewareResult,Xt as isNamedMiddleware,Zt as isPipelineConfig,Ne as isState,We as logState,Ye as matchMachine,_e as mergeContext,Oe as metadata,ke as middlewareBuilder,Qe as next,Le as overrideTransitions,Ge as pipeTransitions,X as run,be as runAsync,q as runMachine,Ce as runSequence,Te as runWithDebug,lt as runWithEnsemble,yt as runWithRunner,A as setContext,Ie as state,pe as step,we as stepAsync,wt as toggle,Ae as transitionTo,it as useActor,at as useActorSelector,rt as useEnsemble,nt as useMachine,fe as useMachineSelector,V as when,Ht as whenContext,ve as whenGuard,Pe as whenGuardAsync,oe as withAnalytics,Ke as withDebugging,se as withErrorReporting,G as withHistory,re as withLogging,ce as withPerformanceMonitoring,ae as withPermissions,de as withRetry,W as withSnapshot,H as withTimeTravel,ie as withValidation,ge as yieldMachine};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @file Base class for machine implementations
3
+ * @description This file contains the MachineBase class, which is the foundation
4
+ * for creating state machines using an Object-Oriented style. This is separated
5
+ * to avoid circular dependencies with higher-order abstractions.
6
+ */
7
+ /**
8
+ * An optional base class for creating machines using an Object-Oriented style.
9
+ *
10
+ * This class provides the fundamental structure required by the library: a `context`
11
+ * property to hold the state. By extending `MachineBase`, you get a clear and
12
+ * type-safe starting point for defining states and transitions as classes and methods.
13
+ *
14
+ * Transitions should be implemented as methods that return a new instance of a
15
+ * state machine class (often `new MyClass(...)` or by using a `createMachineBuilder`).
16
+ * The `context` is marked `readonly` to enforce the immutable update pattern.
17
+ *
18
+ * @template C - The context object type that defines the state for this machine.
19
+ *
20
+ * @example
21
+ * // Define a simple counter state
22
+ * class Counter extends MachineBase<{ readonly count: number }> {
23
+ * constructor(count = 0) {
24
+ * super({ count });
25
+ * }
26
+ *
27
+ * increment(): Counter {
28
+ * // Return a new instance for the next state
29
+ * return new Counter(this.context.count + 1);
30
+ * }
31
+ *
32
+ * add(n: number): Counter {
33
+ * return new Counter(this.context.count + n);
34
+ * }
35
+ * }
36
+ *
37
+ * const machine = new Counter(5);
38
+ * const nextState = machine.increment(); // Returns a new Counter instance
39
+ *
40
+ * console.log(machine.context.count); // 5 (original is unchanged)
41
+ * console.log(nextState.context.count); // 6 (new state)
42
+ */
43
+ export declare class MachineBase<C extends object> {
44
+ /**
45
+ * The immutable state of the machine.
46
+ * To change the state, a transition method must return a new machine instance
47
+ * with a new context object.
48
+ */
49
+ readonly context: C;
50
+ /**
51
+ * Initializes a new machine instance with its starting context.
52
+ * @param context - The initial state of the machine.
53
+ */
54
+ constructor(context: C);
55
+ }
56
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM;IACvC;;;;OAIG;IACH,SAAgB,OAAO,EAAE,CAAC,CAAC;IAE3B;;;OAGG;gBACS,OAAO,EAAE,CAAC;CAMvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"context-bound.d.ts","sourceRoot":"","sources":["../../src/context-bound.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,yBAAyB,CACvC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI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AAC,CAAC,CA+B3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAC3B,OAAO,CACT,CAAC,EACD;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CACd,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KACtB,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC;CAC/B,CACF,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EACpD,OAAO,EAAE,CAAC,EACV,cAAc,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EACpC,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,GAAG,CAIL;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAQ7D"}
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * Think of this as the "standard library" of common machine patterns.
10
10
  */
11
- import { MachineBase, Machine, Transitions, Context } from './index';
11
+ import { MachineBase } from './base';
12
+ import { Machine, Transitions, Context } from './index';
12
13
  /**
13
14
  * A type utility to infer the child machine type from a parent.
14
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"higher-order.d.ts","sourceRoot":"","sources":["../../src/higher-order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,WAAW,EACX,OAAO,EACP,WAAW,EAGX,OAAO,EAER,MAAM,SAAS,CAAC;AAMjB;;GAEG;AACH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;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