@doeixd/machine 1.0.3 → 1.2.0

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