@doeixd/machine 0.0.22 → 0.0.23
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.
- package/README.md +2 -0
- package/dist/cjs/development/react.js +1969 -0
- package/dist/cjs/development/react.js.map +7 -0
- package/dist/cjs/production/react.js +1 -0
- package/dist/esm/development/react.js +1955 -0
- package/dist/esm/development/react.js.map +7 -0
- package/dist/esm/production/react.js +1 -0
- package/dist/types/entry-react.d.ts +6 -0
- package/dist/types/entry-react.d.ts.map +1 -0
- package/dist/types/react.d.ts +133 -0
- package/dist/types/react.d.ts.map +1 -0
- package/package.json +13 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var G=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Ye=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ue(t))!qe.call(e,o)&&o!==n&&G(e,o,{get:()=>t[o],enumerable:!(r=Le(t,o))||r.enumerable});return e};var Qe=e=>Je(G({},"__esModule",{value:!0}),e);var jt={};Ye(jt,{BoundMachine:()=>N,CANCEL:()=>q,META_KEY:()=>pe,MachineBase:()=>T,MiddlewareBuilder:()=>k,MultiMachineBase:()=>H,action:()=>be,bindTransitions:()=>oe,branch:()=>xt,call:()=>Ke,chain:()=>ct,combine:()=>Mt,combineFactories:()=>We,compose:()=>st,composeTyped:()=>P,createAsyncMachine:()=>se,createCustomMiddleware:()=>at,createEnsemble:()=>R,createEnsembleFactory:()=>Xe,createEvent:()=>ve,createFetchMachine:()=>it,createFlow:()=>le,createFunctionalMachine:()=>ae,createMachine:()=>g,createMachineBuilder:()=>He,createMachineContext:()=>Ft,createMachineFactory:()=>_e,createMiddleware:()=>C,createMiddlewareFactory:()=>wt,createMiddlewareRegistry:()=>yt,createMultiMachine:()=>tt,createMutableMachine:()=>nt,createParallelMachine:()=>U,createPipeline:()=>lt,createRunner:()=>Fe,createTransition:()=>ke,createTransitionExtender:()=>ie,createTransitionFactory:()=>Ne,delegateToChild:()=>rt,describe:()=>Ce,extendTransitions:()=>z,guard:()=>F,guardAsync:()=>S,guarded:()=>me,hasState:()=>De,inDevelopment:()=>dt,invoke:()=>Te,isConditionalMiddleware:()=>ht,isMiddlewareContext:()=>pt,isMiddlewareError:()=>gt,isMiddlewareFn:()=>re,isMiddlewareHooks:()=>Ct,isMiddlewareOptions:()=>mt,isMiddlewareResult:()=>ft,isNamedMiddleware:()=>Tt,isPipelineConfig:()=>bt,isState:()=>je,logState:()=>Be,matchMachine:()=>$e,mergeContext:()=>Oe,metadata:()=>Ae,middlewareBuilder:()=>Se,next:()=>Ve,overrideTransitions:()=>Ge,pipeTransitions:()=>Pe,run:()=>W,runAsync:()=>xe,runMachine:()=>_,runSequence:()=>ye,runWithDebug:()=>Me,runWithEnsemble:()=>et,runWithRunner:()=>Ze,setContext:()=>A,state:()=>ze,step:()=>de,stepAsync:()=>he,toggle:()=>ot,transitionTo:()=>ge,useActor:()=>St,useActorSelector:()=>Rt,useEnsemble:()=>At,useMachine:()=>Et,useMachineSelector:()=>Ie,when:()=>K,whenContext:()=>ut,whenGuard:()=>we,whenGuardAsync:()=>Ee,withAnalytics:()=>J,withDebugging:()=>Re,withErrorReporting:()=>Z,withHistory:()=>j,withLogging:()=>Y,withPerformanceMonitoring:()=>ee,withPermissions:()=>X,withRetry:()=>te,withSnapshot:()=>v,withTimeTravel:()=>O,withValidation:()=>Q,yieldMachine:()=>ue});module.exports=Qe(jt);function W(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function de(e){return function*(){return yield e}()}function ue(e){return e}function ye(e,t){return t.reduce((n,r)=>W(r,n),e)}function le(e){return e}function Me(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function xe(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*he(e){return yield e}var pe=Symbol("MachineMeta"),fe=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[fe]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,fe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,t){return w(t,{target:e.name||e.toString()}),t}function Ce(e,t){return w(t,{description:e}),t}function me(e,t){return w(t,{guards:[e]}),t}function Te(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function be(e,t){return w(t,{actions:[e]}),t}function F(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(e(u,...d)){let M=c?this.context:this;return t.apply(M,d)}else if(r==="throw"){let M=o||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function S(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(await Promise.resolve(e(u,...d))){let M=c?this.context:this;return t.apply(M,d)}else if(r==="throw"){let M=o||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function we(e){return{do(t){let n=F(e,t);return n.else=function(r){return F(e,t,{onFail:r})},n}}}function Ee(e){return{do(t){let n=S(e,t);return n.else=function(r){return S(e,t,{onFail:r})},n}}}function Ae(e,t){return t}function Fe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,d){let c=n[d];if(typeof c=="function")return(...u)=>{let l=c.apply(n.context,u),M=Object.assign({context:l.context},i);return r(M),M}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function R(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),d=s[a];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>d.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Xe(e,t){return function(r){return R(e,r,t)}}function Ze(e,t){let n=Fe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function et(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var H=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function tt(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function nt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),d=s[i];if(typeof d=="function")return(...c)=>{let u=d.apply(s.context,c);if(typeof u!="object"||u===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(l=>delete o[l]),Object.assign(o,u)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function rt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return A(this,{...this.context,child:r})}return this}}function ot(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),A(this,{...this.context,[e]:!this.context[e]})}}var $=class extends T{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends T{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new V(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new D(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new I(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new L(this.config));this.execute()}async execute(){}},D=class extends T{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},V=class extends T{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},I=class extends T{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},L=class extends T{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function it(e){return new $(e)}function U(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...d)=>{let c=s.apply(e.context,d);return U(c,t)}}for(let a in o){let s=o[a];i[a]=(...d)=>{let c=s.apply(t.context,d);return U(e,c)}}return{context:n,...i}}var q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(a[s]=function(...c){let u=s,l=a.context,M=()=>{let y;try{y=d.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:u,context:l,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${u}:`,f),i==null||i(f,"error",{transitionName:u,context:l,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(y&&typeof y.then=="function")return y.then(f=>{if(x(f),t.after)try{let m=t.after({transitionName:u,prevContext:l,nextContext:f.context,args:[...c]});if(m&&typeof m.then=="function")return m.then(()=>f)}catch(m){if(!r)throw m;o&&console.error(`Middleware after hook error for ${u}:`,m),i==null||i(m,"after",{transitionName:u,prevContext:l,nextContext:f.context,args:c})}return f});if(x(y),t.after)try{let h=t.after({transitionName:u,prevContext:l,nextContext:y.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>y).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${u}:`,f),i==null||i(f,"after",{transitionName:u,prevContext:l,nextContext:y.context,args:c}),y})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${u}:`,h),i==null||i(h,"after",{transitionName:u,prevContext:l,nextContext:y.context,args:c})}return y};if(t.before)try{let y=t.before({transitionName:u,context:l,args:[...c]});if(y&&typeof y=="object"&&y&&"then"in y)return y.then(x=>x===q?a:M()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${u}:`,x),i==null||i(x,"before",{transitionName:u,context:l,args:c}),M()});if(y===q)return a}catch(y){if(!r)throw y;o&&console.error(`Middleware before hook error for ${u}:`,y),i==null||i(y,"before",{transitionName:u,context:l,args:c})}return M()})}return a}function Y(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function J(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:d,args:c})=>{let u=`${r}.${a}`,l={transition:a};o&&(l.from=s),l.to=d,i&&(l.args=c),t(u,l)}})}function Q(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function X(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function Z(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function ee(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function te(e,t={}){var d,c;let{maxAttempts:n=(d=t.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let u in e){if(!Object.prototype.hasOwnProperty.call(e,u))continue;let l=e[u];typeof l=="function"&&u!=="context"&&(s[u]=async function(...M){let y,x=0;for(;x<n;)try{return await l.apply(this,M)}catch(h){if(y=h,x++,x<n&&r(y,x)){a==null||a(y,x);let m=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,m))}else throw y}throw y})}return s}function at(e,t){return n=>C(n,e,t)}function j(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:d,args:c})=>{let u={id:`entry-${a++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{u.serializedArgs=r.serialize(c)}catch(l){console.error("Failed to serialize history args:",l)}i.push(u),n&&i.length>n&&i.shift(),o==null||o(u)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function v(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,d=C(e,{after:({transitionName:u,prevContext:l,nextContext:M})=>{if(i&&JSON.stringify(l)===JSON.stringify(M))return;let y={id:`snapshot-${s++}`,transitionName:u,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{y.serializedBefore=r.serialize(l),y.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{y.diff=o(l,M)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(y),n&&a.length>n&&a.shift()}});return Object.assign(d,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:u=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:u},l)}})}function O(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,d=0,c=C(e,{before:({transitionName:M,args:y})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...y],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(y)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:M,prevContext:y,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:M,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(y),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,d=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,d=0},restoreSnapshot:M=>{let y=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:M},y)},replayFrom:M=>{var m;if(M<0||M>=i.length)throw new Error(`Invalid replay start index: ${M}`);let y=(m=a[M])==null?void 0:m.before;if(!y)throw new Error(`No snapshot available for index ${M}`);let x=i.slice(M),f=Object.assign({context:y},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let ce=f[b.transitionName];ce&&(f=ce.apply(f.context,b.args))}return f}})}function st(e,...t){return t.reduce((n,r)=>r(n),e)}function P(e,...t){return t.reduce((n,r)=>r(n),e)}var ne=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function ct(e){return new ne(e)}function K(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function dt(e){return K(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function ut(e,t,n){return K(n,r=>r.context[e]===t)}function yt(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return P(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return P(t,...n.map(r=>r.middleware))}}}function lt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],d=!0;for(let c=0;c<i.length;c++){let u=i[c];try{if("middleware"in u&&"when"in u){if(!u.when(a))continue;a=u.middleware(a)}else a=u(a)}catch(l){if(d=!1,!t)throw l;s.push({error:l,middlewareIndex:c,middlewareName:u.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,l),r==null||r(l,c,u.name)}}return{machine:a,errors:s,success:d}}}function Mt(...e){return t=>P(t,...e)}function xt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function re(e){return typeof e=="function"&&e.length===1}function ht(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&re(e.middleware)&&typeof e.when=="function"}function ft(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||B(e.prevContext,t)&&B(e.nextContext,t))}function pt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||B(e.context,t))}function gt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||B(e.context,t))}function Ct(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function mt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function B(e,t){return e!==null&&typeof e=="object"}function Tt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&re(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function bt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var k=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>Y(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>J(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>Q(r,t)),this}withPermissions(t){return this.middlewares.push(n=>X(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ee(r,t)),this}withRetry(t){return this.middlewares.push(n=>te(n,t)),this}withHistory(t){return this.middlewares.push(n=>j(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>v(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>O(n,t)),this}withDebugging(){return this.middlewares.push(t=>Re(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(K(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Se(e){return new k(e)}function wt(e={}){return{create:t=>{let n=Se(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function Re(e){return O(v(j(e)))}function je(e,t){return e instanceof t}function ve(e,...t){return{type:e,args:t}}function Oe(e,t){return A(e,n=>({...n,...t}))}async function Pe(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Be(e,t){return t?console.log(t,e.context):console.log(e.context),e}function ke(e,t){return function(...n){let r=t(this.context,...n);return g(r,e())}}function Ke(e,t,...n){return e.apply(t,n)}function oe(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t.context,o);return i&&typeof i=="object"&&"context"in i?oe(i):i}:r}})}var N=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...i)=>{let a=o.apply(this.wrappedMachine.context,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function Ne(){return function(t){return function(...n){let r=t(this.context,...n);return g(r,this)}}}function ie(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return g(a,this)},o=z(e,{[t]:r});return ie(o)}}}function ae(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let d=a(this.context,...s);return g(d,r)}]));return Object.assign(r,o),g(e,r)}}function ze(e,t){return t!==void 0?g(e,t):ae(e)}function g(e,t){if(typeof t=="function"){let o;o=t(s=>{let d=g(s,o),c=Object.fromEntries(Object.entries(o).map(([u,l])=>[u,l.bind(s)]));return Object.assign(d,c)});let a=Object.fromEntries(Object.entries(o).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function se(e,t){if(typeof t=="function"){let o;o=t(s=>{let d=se(s,o),c=Object.fromEntries(Object.entries(o).map(([u,l])=>[u,l.bind(s)]));return Object.assign(d,c)});let a=Object.fromEntries(Object.entries(o).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function _e(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return g(i,t)}]));return n=>g(n,t)}}function A(e,t){let{context:n,...r}=e,o=typeof t=="function"?t(n):t;return g(o,r)}function Ge(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function z(e,t){let{context:n,...r}=e,o={...r,...t};return g(n,o)}function We(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:d,...c}=o,u={...s,...c};return g(i,u)}}function He(e){let{context:t,...n}=e;return r=>g(r,n)}function $e(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function De(e,t,n){return e.context[t]===n}function _(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n.context,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}var T=class{constructor(t){this.context=t}};function Ve(e,t){let{context:n,...r}=e;return g(t(n),r)}var p=require("react");function Et(e){let[t,n]=(0,p.useState)(e),r=(0,p.useMemo)(()=>_(t,i=>{n(i)}),[]),o=(0,p.useMemo)(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function Ie(e,t,n=Object.is){let[r,o]=(0,p.useState)(()=>t(e)),i=(0,p.useRef)(t),a=(0,p.useRef)(n);return i.current=t,a.current=n,(0,p.useEffect)(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function At(e,t,n){let[r,o]=(0,p.useState)(e),i=(0,p.useRef)(r);i.current=r;let a=(0,p.useMemo)(()=>({getContext:()=>i.current,setContext:d=>{o(d)}}),[]);return(0,p.useMemo)(()=>R(a,t,n),[a,t,n])}function Ft(){let e=(0,p.createContext)(null),t=({machine:a,actions:s,children:d})=>{let c=(0,p.useMemo)(()=>[a,s],[a,s]);return(0,p.createElement)(e.Provider,{value:c},d)},n=()=>{let a=(0,p.useContext)(e);if(!a)throw new Error("useMachineContext must be used within a Machine.Provider");return a},r=()=>n()[0];return{Provider:t,useMachineContext:n,useMachineState:r,useMachineActions:()=>n()[1],useSelector:(a,s)=>{let d=r();return Ie(d,a,s)}}}function St(e){let t=(0,p.useMemo)(()=>e.subscribe.bind(e),[e]),n=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]);return(0,p.useSyncExternalStore)(t,n)}function Rt(e,t,n=Object.is){let r=(0,p.useMemo)(()=>e.subscribe.bind(e),[e]),o=(0,p.useMemo)(()=>e.getSnapshot.bind(e),[e]),i=()=>t(o()),[a,s]=(0,p.useState)(i);return(0,p.useEffect)(()=>{let d=()=>{let c=t(e.getSnapshot());s(u=>n(u,c)?u:c)};return d(),e.subscribe(()=>{d()})},[e,t,n]),a}
|